From 97e394ba1805fbe394a5704de660403901559e54 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 29 May 2018 15:02:51 -0300 Subject: [PATCH] macro 'luai_makeseed' now controls the whole process of making the seed --- lstate.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lstate.c b/lstate.c index 6c92f2f0..5a2c3577 100644 --- a/lstate.c +++ b/lstate.c @@ -1,5 +1,5 @@ /* -** $Id: lstate.c,v 2.150 2018/01/28 15:13:26 roberto Exp roberto $ +** $Id: lstate.c,v 2.151 2018/02/05 17:11:37 roberto Exp roberto $ ** Global State ** See Copyright Notice in lua.h */ @@ -29,17 +29,6 @@ -/* -** a macro to help the creation of a unique random seed when a state is -** created; the seed is used to randomize hashes. -*/ -#if !defined(luai_makeseed) -#include -#define luai_makeseed() cast_uint(time(NULL)) -#endif - - - /* ** thread state + extra space */ @@ -63,16 +52,25 @@ typedef struct LG { /* -** Compute an initial seed as random as possible. Rely on Address Space -** Layout Randomization (if present) to increase randomness.. +** A macro to create a "random" seed when a state is created; +** the seed is used to randomize string hashes. +*/ +#if !defined(luai_makeseed) + +#include + +/* +** Compute an initial seed with some level of randomness. +** Rely on Address Space Layout Randomization (if present) and +** current time. */ #define addbuff(b,p,e) \ { size_t t = cast_sizet(e); \ memcpy(b + p, &t, sizeof(t)); p += sizeof(t); } -static unsigned int makeseed (lua_State *L) { +static unsigned int luai_makeseed (lua_State *L) { char buff[4 * sizeof(size_t)]; - unsigned int h = luai_makeseed(); + unsigned int h = cast_uint(time(NULL)); int p = 0; addbuff(buff, p, L); /* heap variable */ addbuff(buff, p, &h); /* local variable */ @@ -82,6 +80,8 @@ static unsigned int makeseed (lua_State *L) { return luaS_hash(buff, p, h); } +#endif + /* ** set GCdebt to a new value keeping the value (totalbytes + GCdebt) @@ -327,7 +327,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { g->frealloc = f; g->ud = ud; g->mainthread = L; - g->seed = makeseed(L); + g->seed = luai_makeseed(L); g->gcrunning = 0; /* no GC while building state */ g->strt.size = g->strt.nuse = 0; g->strt.hash = NULL;