| 3041 | #endif |
| 3042 | |
| 3043 | staticfn lua_State * |
| 3044 | nhlL_newstate(nhl_sandbox_info *sbi, const char *name) |
| 3045 | { |
| 3046 | nhl_user_data *nud = 0; |
| 3047 | |
| 3048 | if (sbi->memlimit || sbi->steps || sbi->perpcall) { |
| 3049 | nud = nhl_alloc(NULL, NULL, 0, sizeof (struct nhl_user_data)); |
| 3050 | if (!nud) |
| 3051 | return 0; |
| 3052 | nud->L = NULL; |
| 3053 | nud->memlimit = sbi->memlimit; |
| 3054 | nud->perpcall = 0; /* set up below, if needed */ |
| 3055 | nud->steps = 0; |
| 3056 | nud->osteps = 0; |
| 3057 | nud->flags = sbi->flags; /* save reporting flags */ |
| 3058 | nud->statctr = 0; |
| 3059 | |
| 3060 | if (name) { |
| 3061 | nud->name = name; |
| 3062 | } |
| 3063 | nud->sid = ++gl.lua_sid; |
| 3064 | } |
| 3065 | |
| 3066 | lua_State *L = lua_newstate(nhl_alloc, nud |
| 3067 | #if LUA_VERSION_NUM >= 505 |
| 3068 | , 0 |
| 3069 | #endif |
| 3070 | ); |
| 3071 | if (!L) |
| 3072 | panic("NULL lua_newstate"); |
| 3073 | |
| 3074 | if(nud) nud->L = L; |
| 3075 | lua_atpanic(L, nhl_panic); |
| 3076 | #if LUA_VERSION_NUM == 504 |
| 3077 | lua_setwarnf(L, nhl_warn, L); |
| 3078 | #endif |
| 3079 | |
| 3080 | #ifdef NHL_SANDBOX |
| 3081 | if (nud && (sbi->steps || sbi->perpcall)) { |
| 3082 | if (sbi->steps && sbi->perpcall) |
| 3083 | impossible("steps and perpcall both non-zero"); |
| 3084 | if (sbi->perpcall) { |
| 3085 | nud->perpcall = sbi->perpcall; |
| 3086 | } else { |
| 3087 | nud->steps = sbi->steps; |
| 3088 | nud->osteps = sbi->steps; |
| 3089 | } |
| 3090 | lua_sethook(L, nhl_hookfn, LUA_MASKCOUNT, NHL_SB_STEPSIZE); |
| 3091 | } |
| 3092 | #endif |
| 3093 | |
| 3094 | return L; |
| 3095 | } |
| 3096 | |
| 3097 | #endif /* !SFCTOOL */ |
| 3098 |
no test coverage detected