diff options
| author | Mike Pall <mike> | 2010-01-18 01:32:33 +0100 |
|---|---|---|
| committer | Mike Pall <mike> | 2010-01-18 01:32:33 +0100 |
| commit | 4e39597ba63bb0ad2065c92b7508ac17ae53f297 (patch) | |
| tree | fa4448ecf27cd78892ad38b2f5a23986c93d6271 /src | |
| parent | 32969abe404b99c05c745695c1e6d6bab3565cd5 (diff) | |
| download | luajit-4e39597ba63bb0ad2065c92b7508ac17ae53f297.tar.gz luajit-4e39597ba63bb0ad2065c92b7508ac17ae53f297.tar.bz2 luajit-4e39597ba63bb0ad2065c92b7508ac17ae53f297.zip | |
Add some sanity checks for allocator in 64 bit mode.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib_aux.c | 4 | ||||
| -rw-r--r-- | src/lj_def.h | 1 | ||||
| -rw-r--r-- | src/lj_gc.c | 2 | ||||
| -rw-r--r-- | src/lj_state.c | 2 |
4 files changed, 8 insertions, 1 deletions
diff --git a/src/lib_aux.c b/src/lib_aux.c index 5f4e3e8c..419650a9 100644 --- a/src/lib_aux.c +++ b/src/lib_aux.c | |||
| @@ -313,6 +313,10 @@ LUALIB_API int luaL_loadstring(lua_State *L, const char *s) | |||
| 313 | 313 | ||
| 314 | #ifdef LUAJIT_USE_SYSMALLOC | 314 | #ifdef LUAJIT_USE_SYSMALLOC |
| 315 | 315 | ||
| 316 | #if LJ_64 | ||
| 317 | #error "Must use builtin allocator for 64 bit target" | ||
| 318 | #endif | ||
| 319 | |||
| 316 | static void *mem_alloc(void *ud, void *ptr, size_t osize, size_t nsize) | 320 | static void *mem_alloc(void *ud, void *ptr, size_t osize, size_t nsize) |
| 317 | { | 321 | { |
| 318 | (void)ud; | 322 | (void)ud; |
diff --git a/src/lj_def.h b/src/lj_def.h index 8128aa21..872a7830 100644 --- a/src/lj_def.h +++ b/src/lj_def.h | |||
| @@ -89,6 +89,7 @@ typedef unsigned __int32 uintptr_t; | |||
| 89 | #define checku8(x) ((x) == (int32_t)(uint8_t)(x)) | 89 | #define checku8(x) ((x) == (int32_t)(uint8_t)(x)) |
| 90 | #define checki16(x) ((x) == (int32_t)(int16_t)(x)) | 90 | #define checki16(x) ((x) == (int32_t)(int16_t)(x)) |
| 91 | #define checku16(x) ((x) == (int32_t)(uint16_t)(x)) | 91 | #define checku16(x) ((x) == (int32_t)(uint16_t)(x)) |
| 92 | #define checkptr32(x) ((uintptr_t)(x) == (uint32_t)(uintptr_t)(x)) | ||
| 92 | 93 | ||
| 93 | /* Every half-decent C compiler transforms this into a rotate instruction. */ | 94 | /* Every half-decent C compiler transforms this into a rotate instruction. */ |
| 94 | #define lj_rol(x, n) (((x)<<(n)) | ((x)>>(32-(n)))) | 95 | #define lj_rol(x, n) (((x)<<(n)) | ((x)>>(32-(n)))) |
diff --git a/src/lj_gc.c b/src/lj_gc.c index cd99f249..764d74a8 100644 --- a/src/lj_gc.c +++ b/src/lj_gc.c | |||
| @@ -764,6 +764,7 @@ void *lj_mem_realloc(lua_State *L, void *p, MSize osz, MSize nsz) | |||
| 764 | if (p == NULL && nsz > 0) | 764 | if (p == NULL && nsz > 0) |
| 765 | lj_err_throw(L, LUA_ERRMEM); | 765 | lj_err_throw(L, LUA_ERRMEM); |
| 766 | lua_assert((nsz == 0) == (p == NULL)); | 766 | lua_assert((nsz == 0) == (p == NULL)); |
| 767 | lua_assert(checkptr32(p)); | ||
| 767 | g->gc.total = (g->gc.total - osz) + nsz; | 768 | g->gc.total = (g->gc.total - osz) + nsz; |
| 768 | return p; | 769 | return p; |
| 769 | } | 770 | } |
| @@ -775,6 +776,7 @@ void *lj_mem_newgco(lua_State *L, MSize size) | |||
| 775 | GCobj *o = (GCobj *)g->allocf(g->allocd, NULL, 0, size); | 776 | GCobj *o = (GCobj *)g->allocf(g->allocd, NULL, 0, size); |
| 776 | if (o == NULL) | 777 | if (o == NULL) |
| 777 | lj_err_throw(L, LUA_ERRMEM); | 778 | lj_err_throw(L, LUA_ERRMEM); |
| 779 | lua_assert(checkptr32(o)); | ||
| 778 | g->gc.total += size; | 780 | g->gc.total += size; |
| 779 | setgcrefr(o->gch.nextgc, g->gc.root); | 781 | setgcrefr(o->gch.nextgc, g->gc.root); |
| 780 | setgcref(g->gc.root, o); | 782 | setgcref(g->gc.root, o); |
diff --git a/src/lj_state.c b/src/lj_state.c index e1b9021e..f7f30117 100644 --- a/src/lj_state.c +++ b/src/lj_state.c | |||
| @@ -163,7 +163,7 @@ LUA_API lua_State *lua_newstate(lua_Alloc f, void *ud) | |||
| 163 | GG_State *GG = cast(GG_State *, f(ud, NULL, 0, sizeof(GG_State))); | 163 | GG_State *GG = cast(GG_State *, f(ud, NULL, 0, sizeof(GG_State))); |
| 164 | lua_State *L = &GG->L; | 164 | lua_State *L = &GG->L; |
| 165 | global_State *g = &GG->g; | 165 | global_State *g = &GG->g; |
| 166 | if (GG == NULL) return NULL; | 166 | if (GG == NULL || !checkptr32(GG)) return NULL; |
| 167 | memset(GG, 0, sizeof(GG_State)); | 167 | memset(GG, 0, sizeof(GG_State)); |
| 168 | L->gct = ~LJ_TTHREAD; | 168 | L->gct = ~LJ_TTHREAD; |
| 169 | L->marked = LJ_GC_WHITE0 | LJ_GC_FIXED | LJ_GC_SFIXED; /* Prevent free. */ | 169 | L->marked = LJ_GC_WHITE0 | LJ_GC_FIXED | LJ_GC_SFIXED; /* Prevent free. */ |
