Phase 4 D3: alloc gate shape (env-gated)
This commit is contained in:
@ -31,6 +31,7 @@
|
||||
#include "../tiny_region_id.h" // Header 読み出し
|
||||
#include "../front/malloc_tiny_fast.h" // 既存 Tiny Fast Path
|
||||
#include "tiny_route_box.h" // Tiny Front Routing Policy
|
||||
#include "tiny_alloc_gate_shape_env_box.h" // Phase 4 D3: alloc gate shape (ENV)
|
||||
|
||||
// 将来の拡張用コンテキスト:
|
||||
// - size : 要求サイズ
|
||||
@ -144,6 +145,44 @@ static inline void* tiny_alloc_gate_fast(size_t size)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Phase 4 D3: Alloc Gate Shape(MIXED 向けの分岐形)
|
||||
// - tiny_route_get()(release の logging branch)を避ける
|
||||
// - ROUTE_POOL_ONLY は必ず尊重(HAKMEM_TINY_PROFILE=hot/off を壊さない)
|
||||
if (__builtin_expect(alloc_gate_shape_enabled(), 0)) {
|
||||
if (__builtin_expect(g_tiny_route[class_idx & 7] == ROUTE_POOL_ONLY, 0)) {
|
||||
return NULL;
|
||||
}
|
||||
void* user_ptr = malloc_tiny_fast_for_class(size, class_idx);
|
||||
#if !HAKMEM_BUILD_RELEASE
|
||||
// Layer 3a(alloc 側): 明らかに異常なポインタは debug ビルドで早期検出
|
||||
if (user_ptr) {
|
||||
uintptr_t addr = (uintptr_t)user_ptr;
|
||||
if (__builtin_expect(addr < 4096, 0)) {
|
||||
fprintf(stderr,
|
||||
"[TINY_ALLOC_GATE_RANGE_INVALID] size=%zu user=%p\n",
|
||||
size, user_ptr);
|
||||
fflush(stderr);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
if (__builtin_expect(tiny_alloc_gate_diag_enabled(), 0) && user_ptr) {
|
||||
TinyAllocGateContext ctx;
|
||||
ctx.size = size;
|
||||
ctx.user = HAK_USER_FROM_RAW(user_ptr);
|
||||
ctx.class_idx = class_idx;
|
||||
ctx.base = HAK_BASE_FROM_RAW(NULL);
|
||||
ctx.bridge.ss = NULL;
|
||||
ctx.bridge.meta = NULL;
|
||||
ctx.bridge.slab_idx = -1;
|
||||
ctx.bridge.meta_cls = 0xffu;
|
||||
|
||||
(void)tiny_alloc_gate_validate(&ctx);
|
||||
}
|
||||
#endif
|
||||
return user_ptr;
|
||||
}
|
||||
|
||||
TinyRoutePolicy route = tiny_route_get(class_idx);
|
||||
|
||||
// Pool-only: Tiny front は完全スキップ(Gate から見ると「Tiny では取れなかった」扱い)
|
||||
|
||||
Reference in New Issue
Block a user