diff options
| author | Mike Pall <mike> | 2016-05-03 18:30:01 +0200 |
|---|---|---|
| committer | Mike Pall <mike> | 2016-05-03 18:31:29 +0200 |
| commit | 221268b17d950d1cdfc36ee85b82c89c83a974fb (patch) | |
| tree | 0c5835fe49ec2bcac936fe0608e8e6e48038940a /src | |
| parent | ac42037db0ea0e0c8f4934b5103db522ab405129 (diff) | |
| download | luajit-221268b17d950d1cdfc36ee85b82c89c83a974fb.tar.gz luajit-221268b17d950d1cdfc36ee85b82c89c83a974fb.tar.bz2 luajit-221268b17d950d1cdfc36ee85b82c89c83a974fb.zip | |
Use the GDB JIT API in a thread-safe manner.
Thanks to Peter Cawley.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lj_gdbjit.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/lj_gdbjit.c b/src/lj_gdbjit.c index f2bd865e..8b72be7d 100644 --- a/src/lj_gdbjit.c +++ b/src/lj_gdbjit.c | |||
| @@ -719,6 +719,20 @@ static void gdbjit_buildobj(GDBJITctx *ctx) | |||
| 719 | 719 | ||
| 720 | /* -- Interface to GDB JIT API -------------------------------------------- */ | 720 | /* -- Interface to GDB JIT API -------------------------------------------- */ |
| 721 | 721 | ||
| 722 | static int gdbjit_lock; | ||
| 723 | |||
| 724 | static void gdbjit_lock_acquire() | ||
| 725 | { | ||
| 726 | while (__sync_lock_test_and_set(&gdbjit_lock, 1)) { | ||
| 727 | /* Just spin; futexes or pthreads aren't worth the portability cost. */ | ||
| 728 | } | ||
| 729 | } | ||
| 730 | |||
| 731 | static void gdbjit_lock_release() | ||
| 732 | { | ||
| 733 | __sync_lock_release(&gdbjit_lock); | ||
| 734 | } | ||
| 735 | |||
| 722 | /* Add new entry to GDB JIT symbol chain. */ | 736 | /* Add new entry to GDB JIT symbol chain. */ |
| 723 | static void gdbjit_newentry(lua_State *L, GDBJITctx *ctx) | 737 | static void gdbjit_newentry(lua_State *L, GDBJITctx *ctx) |
| 724 | { | 738 | { |
| @@ -730,6 +744,7 @@ static void gdbjit_newentry(lua_State *L, GDBJITctx *ctx) | |||
| 730 | ctx->T->gdbjit_entry = (void *)eo; | 744 | ctx->T->gdbjit_entry = (void *)eo; |
| 731 | /* Link new entry to chain and register it. */ | 745 | /* Link new entry to chain and register it. */ |
| 732 | eo->entry.prev_entry = NULL; | 746 | eo->entry.prev_entry = NULL; |
| 747 | gdbjit_lock_acquire(); | ||
| 733 | eo->entry.next_entry = __jit_debug_descriptor.first_entry; | 748 | eo->entry.next_entry = __jit_debug_descriptor.first_entry; |
| 734 | if (eo->entry.next_entry) | 749 | if (eo->entry.next_entry) |
| 735 | eo->entry.next_entry->prev_entry = &eo->entry; | 750 | eo->entry.next_entry->prev_entry = &eo->entry; |
| @@ -739,6 +754,7 @@ static void gdbjit_newentry(lua_State *L, GDBJITctx *ctx) | |||
| 739 | __jit_debug_descriptor.relevant_entry = &eo->entry; | 754 | __jit_debug_descriptor.relevant_entry = &eo->entry; |
| 740 | __jit_debug_descriptor.action_flag = GDBJIT_REGISTER; | 755 | __jit_debug_descriptor.action_flag = GDBJIT_REGISTER; |
| 741 | __jit_debug_register_code(); | 756 | __jit_debug_register_code(); |
| 757 | gdbjit_lock_release(); | ||
| 742 | } | 758 | } |
| 743 | 759 | ||
| 744 | /* Add debug info for newly compiled trace and notify GDB. */ | 760 | /* Add debug info for newly compiled trace and notify GDB. */ |
| @@ -770,6 +786,7 @@ void lj_gdbjit_deltrace(jit_State *J, GCtrace *T) | |||
| 770 | { | 786 | { |
| 771 | GDBJITentryobj *eo = (GDBJITentryobj *)T->gdbjit_entry; | 787 | GDBJITentryobj *eo = (GDBJITentryobj *)T->gdbjit_entry; |
| 772 | if (eo) { | 788 | if (eo) { |
| 789 | gdbjit_lock_acquire(); | ||
| 773 | if (eo->entry.prev_entry) | 790 | if (eo->entry.prev_entry) |
| 774 | eo->entry.prev_entry->next_entry = eo->entry.next_entry; | 791 | eo->entry.prev_entry->next_entry = eo->entry.next_entry; |
| 775 | else | 792 | else |
| @@ -779,6 +796,7 @@ void lj_gdbjit_deltrace(jit_State *J, GCtrace *T) | |||
| 779 | __jit_debug_descriptor.relevant_entry = &eo->entry; | 796 | __jit_debug_descriptor.relevant_entry = &eo->entry; |
| 780 | __jit_debug_descriptor.action_flag = GDBJIT_UNREGISTER; | 797 | __jit_debug_descriptor.action_flag = GDBJIT_UNREGISTER; |
| 781 | __jit_debug_register_code(); | 798 | __jit_debug_register_code(); |
| 799 | gdbjit_lock_release(); | ||
| 782 | lj_mem_free(J2G(J), eo, eo->sz); | 800 | lj_mem_free(J2G(J), eo, eo->sz); |
| 783 | } | 801 | } |
| 784 | } | 802 | } |
