jit_stream_flash.c
Include dependency graph for jit_stream_flash.c:
Defines
-
JIT_ENTRY_MAGIC 0x4A74
Functions
- struct JITEntry __attribute__ ((packed))
- _Static_assert (sizeof(struct JITEntry)==16, "sizeof(struct JITEntry) must be 16")
-
static void jit_stream_flash_dtor(ErlNifEnv *caller_env, void *obj)
-
static bool jit_stream_flash_replace_at_addr(struct JSFlashPlatformContext *pf_ctx, uintptr_t addr, const uint8_t *data, size_t len)
-
static bool jit_stream_flash_sector_needs_erase(uintptr_t sector_addr)
Check if a sector needs to be erased.
Scans the entire sector to check if it contains any non-0xFF bytes. Uses word-by-word comparison for efficiency since sectors are aligned.
- Parameters:
sector_addr – Address of the sector (must be sector-aligned)
- Returns:
true if sector needs erasing, false if already erased
-
static struct JITEntry *globalcontext_find_first_jit_entry(GlobalContext *global, bool *is_valid)
-
static void globalcontext_set_cache_valid(GlobalContext *global)
-
static struct JITEntry *globalcontext_find_last_jit_entry(GlobalContext *global)
-
static bool jit_stream_flash_flush_page(struct JITStreamFlash *js)
-
static bool jit_stream_flash_finalize_entry(struct JSFlashPlatformContext *pf_ctx, struct JITEntry *jit_entry, uint16_t magic, uint16_t version, uint32_t code, uint32_t labels)
-
static bool jit_stream_flash_append(struct JITStreamFlash *js, const uint8_t *buffer, size_t count)
-
ModuleNativeEntryPoint jit_stream_flash_entry_point(Context *ctx, term jit_stream)
Get entry point from jit_stream_flash. Called by
jit_stream_entry_point- Parameters:
ctx – Context
jit_stream – JIT stream term
- Returns:
Entry point or NULL
-
const struct Nif *jit_stream_flash_get_nif(const char *nifname)
Get NIF for jit_stream_flash operations.
- Parameters:
nifname – NIF name
- Returns:
NIF pointer or NULL
-
void jit_stream_flash_init(GlobalContext *global)
Initialize JIT stream flash subsystem.
- Parameters:
global – Global context
-
void globalcontext_set_cache_native_code(GlobalContext *global, Module *mod, uint16_t version, ModuleNativeEntryPoint entry_point, uint32_t labels)
Finalize flash operation by marking an entry point as valid for a given module. This is called by
sys_set_cache_native_code.
-
ModuleNativeEntryPoint jit_stream_entry_point(Context *ctx, term jit_stream)
Return the entry point from a given jit stream.
Platform implementing JIT must provide this function which is called by code_server:set_native_code/2
- Parameters:
ctx – the current context (code_server)
jit_stream – the jit stream term
- Returns:
the pointer to the first function
-
bool sys_get_cache_native_code(GlobalContext *global, Module *mod, uint16_t *version, ModuleNativeEntryPoint *entry_point, uint32_t *labels)
Get the cache (typically on flash) of native code for a given module.
If module is found in cache, return a pointer to the entry point. Only implemented on platforms with JIT. Implementations on flash typically check if the jit cache is valid (for lib or for app) and use the pointer to code as a key.
- Parameters:
global – the global context
mod – module to return the cache native code for
version – version of the cache entry (for compatibility with the VM)
entry_point – entry point to the module, if found
labels – number of labels
- Returns:
trueif the cache entry was found
-
void sys_set_cache_native_code(GlobalContext *global, Module *mod, uint16_t version, ModuleNativeEntryPoint entry_point, uint32_t labels)
Add native code to cache for a given module.
- Parameters:
global – the global context
mod – module to add the native code for
version – version of the native code
entry_point – entry point to the module
labels – number of labels
Variables
-
uint16_t magic
Magic number (JIT_ENTRY_MAGIC) or 0xFFFF for free space.
-
uint32_t code
Pointer to original BEAM code (32-bit for flash storage)
-
uint32_t labels
Number of labels.
-
uint32_t size
Size of native code in bytes.
- struct JITStreamFlash __attribute__
-
static ErlNifResourceType *jit_stream_flash_resource_type
-
const ErlNifResourceTypeInit jit_stream_flash_resource_type_init = {.members = 1, .dtor = jit_stream_flash_dtor}
-
static const struct Nif jit_stream_module_nif = {.base.type = NIFFunctionType, .nif_ptr = nif_jit_stream_module}
-
static const struct Nif jit_stream_flash_new_nif = {.base.type = NIFFunctionType, .nif_ptr = nif_jit_stream_flash_new}
-
static const struct Nif jit_stream_flash_offset_nif = {.base.type = NIFFunctionType, .nif_ptr = nif_jit_stream_flash_offset}
-
static const struct Nif jit_stream_flash_append_nif = {.base.type = NIFFunctionType, .nif_ptr = nif_jit_stream_flash_append}
-
static const struct Nif jit_stream_flash_replace_nif = {.base.type = NIFFunctionType, .nif_ptr = nif_jit_stream_flash_replace}
-
static const struct Nif jit_stream_flash_read_nif = {.base.type = NIFFunctionType, .nif_ptr = nif_jit_stream_flash_read}
-
static const struct Nif jit_stream_flash_flush_nif = {.base.type = NIFFunctionType, .nif_ptr = nif_jit_stream_flash_flush}
-
struct JITEntry
JIT entry header stored in flash.
Each compiled module has an entry with this header followed by the native code.
-
struct JITStreamFlash
Collaboration diagram for JITStreamFlash:
JIT stream flash state.
Maintains the state for writing JIT code to flash with page buffering.