@@ -2603,6 +2603,59 @@ enum retro_mod
26032603*/
26042604#define RETRO_ENVIRONMENT_GET_NETPLAY_CLIENT_INDEX (82 | RETRO_ENVIRONMENT_EXPERIMENTAL)
26052605
2606+ /**
2607+ * Allocates a region of executable memory, optionally dual-mapped.
2608+ *
2609+ * The frontend allocates memory suitable for JIT code generation and returns
2610+ * it to the core. The returned mode tells the core how to use the memory:
2611+ *
2612+ * - \c RETRO_EXEC_MEM_MODE_UNRESTRICTED: The platform has no restrictions
2613+ * on executable memory. The core should self-allocate. Do not call
2614+ * this environment with a non-zero size in this mode.
2615+ * - \c RETRO_EXEC_MEM_MODE_RWX: Single mapping, read-write-execute.
2616+ * \c rx and \c rw point to the same region.
2617+ * - \c RETRO_EXEC_MEM_MODE_WX_TOGGLE: Single mapping, write XOR execute.
2618+ * \c rx and \c rw point to the same region; the core must toggle
2619+ * protections itself (e.g. mprotect) before writing or executing.
2620+ * - \c RETRO_EXEC_MEM_MODE_DUAL_MAP: Separate read-execute and read-write
2621+ * mappings of the same physical pages. The core writes through \c rw
2622+ * and executes from \c rx.
2623+ *
2624+ * Returned memory is page-aligned. The frontend tracks all allocations
2625+ * and frees any outstanding ones when the core is unloaded.
2626+ *
2627+ * The core sets \c version and \c size before calling. The frontend fills
2628+ * in \c mode, \c rx, and \c rw on success.
2629+ *
2630+ * If \c size is 0, this is a probe: the frontend returns \c true and sets
2631+ * \c mode to indicate what kind of memory it would provide, but does not
2632+ * allocate. \c rx and \c rw will be NULL. Cores can use this to decide
2633+ * whether to take a JIT code path before committing to an allocation.
2634+ *
2635+ * @param[in,out] data <tt>struct retro_exec_mem_alloc *</tt>.
2636+ * @return \c true if the allocation succeeded, \c false otherwise.
2637+ * If the frontend does not support this call, returns \c false
2638+ * and the core should fall back to managing its own executable memory.
2639+ * @see retro_exec_mem_alloc
2640+ * @see RETRO_ENVIRONMENT_EXEC_MEM_FREE
2641+ */
2642+ #define RETRO_ENVIRONMENT_EXEC_MEM_ALLOC 83
2643+
2644+ /**
2645+ * Frees a region of executable memory previously allocated with
2646+ * \c RETRO_ENVIRONMENT_EXEC_MEM_ALLOC.
2647+ *
2648+ * This is optional; the frontend will free all outstanding allocations
2649+ * when the core is unloaded. Cores that never need to release memory
2650+ * mid-session need not call this.
2651+ *
2652+ * @param[in] data <tt>struct retro_exec_mem_free *</tt>.
2653+ * @return \c true if the memory was freed, \c false otherwise.
2654+ * @see retro_exec_mem_free
2655+ * @see RETRO_ENVIRONMENT_EXEC_MEM_ALLOC
2656+ */
2657+ #define RETRO_ENVIRONMENT_EXEC_MEM_FREE 84
2658+
26062659/**@}*/
26072660
26082661/**
@@ -7435,6 +7488,45 @@ struct retro_device_power
74357488
74367489/** @} */
74377490
7491+ /** @defgroup Executable Memory Modes
7492+ * Describes how the frontend provisions executable memory.
7493+ * @{
7494+ */
7495+
7496+ #define RETRO_EXEC_MEM_MODE_UNAVAILABLE 0 /**< No executable memory available */
7497+ #define RETRO_EXEC_MEM_MODE_UNRESTRICTED 1 /**< No restrictions; core should self-allocate */
7498+ #define RETRO_EXEC_MEM_MODE_RWX 2 /**< Single mapping, read-write-execute */
7499+ #define RETRO_EXEC_MEM_MODE_WX_TOGGLE 3 /**< Single mapping, write XOR execute (core toggles) */
7500+ #define RETRO_EXEC_MEM_MODE_DUAL_MAP 4 /**< Separate R-X and R-W mappings of same pages */
7501+
7502+ /**
7503+ * Parameters for \c RETRO_ENVIRONMENT_EXEC_MEM_ALLOC.
7504+ *
7505+ * The core fills in \c version and \c size before calling.
7506+ * The frontend fills in \c mode, \c rx, and \c rw on success.
7507+ * @see RETRO_ENVIRONMENT_EXEC_MEM_ALLOC
7508+ */
7509+ struct retro_exec_mem_alloc
7510+ {
7511+ unsigned version ; /**< Set by core (currently 1). */
7512+ size_t size ; /**< Set by core: requested bytes. */
7513+ unsigned mode ; /**< Set by frontend: one of \c RETRO_EXEC_MEM_MODE_*. */
7514+ void * rx ; /**< Set by frontend: execute from this pointer. */
7515+ void * rw ; /**< Set by frontend: write through this pointer.
7516+ Equal to \c rx when mode is RWX or WX_TOGGLE. */
7517+ };
7518+
7519+ /**
7520+ * Parameters for \c RETRO_ENVIRONMENT_EXEC_MEM_FREE.
7521+ * @see RETRO_ENVIRONMENT_EXEC_MEM_FREE
7522+ */
7523+ struct retro_exec_mem_free
7524+ {
7525+ void * rx ; /**< The \c rx pointer returned by a previous alloc call. */
7526+ };
7527+
7528+ /** @} */
7529+
74387530/**
74397531 * @defgroup Callbacks
74407532 * @{
0 commit comments