diff options
| author | Mike Pall <mike> | 2026-05-25 01:23:26 +0200 |
|---|---|---|
| committer | Mike Pall <mike> | 2026-05-25 01:23:26 +0200 |
| commit | 75abb0d934fef3e3d5aab46e60e34059ac8a1c08 (patch) | |
| tree | 136333fa8c3628e7e99e3b58d23efd0263bd9b99 /src/lj_dispatch.c | |
| parent | 64b1f10835acc18bf8923adf248dce4894867882 (diff) | |
| download | luajit-75abb0d934fef3e3d5aab46e60e34059ac8a1c08.tar.gz luajit-75abb0d934fef3e3d5aab46e60e34059ac8a1c08.tar.bz2 luajit-75abb0d934fef3e3d5aab46e60e34059ac8a1c08.zip | |
Avoid race condition with profiler thread during dispatch table update.
Reported by artemking4. #1460
Diffstat (limited to 'src/lj_dispatch.c')
| -rw-r--r-- | src/lj_dispatch.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/lj_dispatch.c b/src/lj_dispatch.c index 636fb0338..9879a95b9 100644 --- a/src/lj_dispatch.c +++ b/src/lj_dispatch.c | |||
| @@ -103,8 +103,11 @@ void lj_dispatch_init_hotcount(global_State *g) | |||
| 103 | #define DISPMODE_PROF 0x40 /* Profiling active. */ | 103 | #define DISPMODE_PROF 0x40 /* Profiling active. */ |
| 104 | 104 | ||
| 105 | /* Update dispatch table depending on various flags. */ | 105 | /* Update dispatch table depending on various flags. */ |
| 106 | void lj_dispatch_update(global_State *g) | 106 | void LJ_FASTCALL lj_dispatch_update(global_State *g, int nolock) |
| 107 | { | 107 | { |
| 108 | #if LJ_HASPROFILE && !LJ_PROFILE_SIGPROF | ||
| 109 | int profile_locked = nolock ? 0 : lj_profile_lock(); | ||
| 110 | #endif | ||
| 108 | uint8_t oldmode = g->dispatchmode; | 111 | uint8_t oldmode = g->dispatchmode; |
| 109 | uint8_t mode = 0; | 112 | uint8_t mode = 0; |
| 110 | #if LJ_HASJIT | 113 | #if LJ_HASJIT |
| @@ -208,6 +211,11 @@ void lj_dispatch_update(global_State *g) | |||
| 208 | lj_dispatch_init_hotcount(g); | 211 | lj_dispatch_init_hotcount(g); |
| 209 | #endif | 212 | #endif |
| 210 | } | 213 | } |
| 214 | #if LJ_HASPROFILE && !LJ_PROFILE_SIGPROF | ||
| 215 | if (profile_locked) lj_profile_unlock(); | ||
| 216 | #else | ||
| 217 | UNUSED(nolock); | ||
| 218 | #endif | ||
| 211 | } | 219 | } |
| 212 | 220 | ||
| 213 | /* -- JIT mode setting ---------------------------------------------------- */ | 221 | /* -- JIT mode setting ---------------------------------------------------- */ |
| @@ -260,7 +268,7 @@ int luaJIT_setmode(lua_State *L, int idx, int mode) | |||
| 260 | G2J(g)->flags &= ~(uint32_t)JIT_F_ON; | 268 | G2J(g)->flags &= ~(uint32_t)JIT_F_ON; |
| 261 | else | 269 | else |
| 262 | G2J(g)->flags |= (uint32_t)JIT_F_ON; | 270 | G2J(g)->flags |= (uint32_t)JIT_F_ON; |
| 263 | lj_dispatch_update(g); | 271 | lj_dispatch_update(g, 0); |
| 264 | } | 272 | } |
| 265 | break; | 273 | break; |
| 266 | case LUAJIT_MODE_FUNC: | 274 | case LUAJIT_MODE_FUNC: |
| @@ -335,7 +343,7 @@ LUA_API int lua_sethook(lua_State *L, lua_Hook func, int mask, int count) | |||
| 335 | g->hookcount = g->hookcstart = (int32_t)count; | 343 | g->hookcount = g->hookcstart = (int32_t)count; |
| 336 | g->hookmask = (uint8_t)((g->hookmask & ~HOOK_EVENTMASK) | mask); | 344 | g->hookmask = (uint8_t)((g->hookmask & ~HOOK_EVENTMASK) | mask); |
| 337 | lj_trace_abort(g); /* Abort recording on any hook change. */ | 345 | lj_trace_abort(g); /* Abort recording on any hook change. */ |
| 338 | lj_dispatch_update(g); | 346 | lj_dispatch_update(g, 0); |
| 339 | return 1; | 347 | return 1; |
| 340 | } | 348 | } |
| 341 | 349 | ||
