aboutsummaryrefslogtreecommitdiff
path: root/lstate.c
diff options
context:
space:
mode:
Diffstat (limited to 'lstate.c')
-rw-r--r--lstate.c35
1 files changed, 2 insertions, 33 deletions
diff --git a/lstate.c b/lstate.c
index bee3bf66..1ce6b9a1 100644
--- a/lstate.c
+++ b/lstate.c
@@ -52,37 +52,6 @@ typedef struct LG {
52 52
53 53
54/* 54/*
55** A macro to create a "random" seed when a state is created;
56** the seed is used to randomize string hashes.
57*/
58#if !defined(luai_makeseed)
59
60#include <time.h>
61
62/*
63** Compute an initial seed with some level of randomness.
64** Rely on Address Space Layout Randomization (if present) and
65** current time.
66*/
67#define addbuff(b,p,e) \
68 { size_t t = cast_sizet(e); \
69 memcpy(b + p, &t, sizeof(t)); p += sizeof(t); }
70
71static unsigned int luai_makeseed (lua_State *L) {
72 char buff[3 * sizeof(size_t)];
73 unsigned int h = cast_uint(time(NULL));
74 int p = 0;
75 addbuff(buff, p, L); /* heap variable */
76 addbuff(buff, p, &h); /* local variable */
77 addbuff(buff, p, &lua_newstate); /* public function */
78 lua_assert(p == sizeof(buff));
79 return luaS_hash(buff, p, h);
80}
81
82#endif
83
84
85/*
86** set GCdebt to a new value keeping the value (totalobjs + GCdebt) 55** set GCdebt to a new value keeping the value (totalobjs + GCdebt)
87** invariant (and avoiding underflows in 'totalobjs') 56** invariant (and avoiding underflows in 'totalobjs')
88*/ 57*/
@@ -350,7 +319,7 @@ LUA_API int lua_resetthread (lua_State *L, lua_State *from) {
350} 319}
351 320
352 321
353LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { 322LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud, unsigned int seed) {
354 int i; 323 int i;
355 lua_State *L; 324 lua_State *L;
356 global_State *g; 325 global_State *g;
@@ -370,7 +339,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
370 g->warnf = NULL; 339 g->warnf = NULL;
371 g->ud_warn = NULL; 340 g->ud_warn = NULL;
372 g->mainthread = L; 341 g->mainthread = L;
373 g->seed = luai_makeseed(L); 342 g->seed = seed;
374 g->gcstp = GCSTPGC; /* no GC while building state */ 343 g->gcstp = GCSTPGC; /* no GC while building state */
375 g->strt.size = g->strt.nuse = 0; 344 g->strt.size = g->strt.nuse = 0;
376 g->strt.hash = NULL; 345 g->strt.hash = NULL;