#ifndef __SPL_ASP_H__ #define __SPL_ASP_H__ /* spl_asp.h - 地址空间抽象(Address SPace) * * SPL 侧指针语义由 spl_asp_t 统一描述: * - native(编译器自身):identity,指针就是宿主地址。 * - VM:句柄/偏移,offset = (handle<<32) | 区内字节偏移,0 为 null。 * * runtime(spl_rt_core.h)的解引用/分配一律经此接口,从而同一份 SPL * 源的 Vec/Map/mem 在两种后端下都自洽。 */ #include #include #ifndef SPL_USIZE_TYPEDEF #define SPL_USIZE_TYPEDEF typedef uintptr_t usize; #endif typedef struct spl_asp spl_asp_t; struct spl_asp { void *ctx; /* offset -> 宿主地址;size>0 时做边界检查;失败返回 NULL。 */ unsigned char *(*xlate)(void *ctx, uintptr_t off, uintptr_t size); /* 分配 size 字节,返回 offset(0=失败)。 */ uintptr_t (*alloc)(void *ctx, uintptr_t size); /* 重新分配 offset@old,返回新 offset(0=失败)。 */ uintptr_t (*realloc)(void *ctx, uintptr_t off, uintptr_t size); /* 释放 offset。 */ void (*free)(void *ctx, uintptr_t off); /* 宿主地址 -> offset;size>0 时校验范围。不属于该空间返回 0。 */ uintptr_t (*to_off)(void *ctx, const void *host, uintptr_t size); }; #endif /* __SPL_ASP_H__ */