Skip to content

Commit

Permalink
Fix: segfault with next boehm gc (after v8.2.4) (#14130)
Browse files Browse the repository at this point in the history
Co-authored-by: Johannes Müller <[email protected]>
  • Loading branch information
ysbaddaden and straight-shoota authored Jan 3, 2024
1 parent 8be53a4 commit 382041c
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/gc/boehm.cr
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@
{% if flag?(:freebsd) || flag?(:dragonfly) %}
@[Link("gc-threaded")]
{% else %}
@[Link("gc")]
@[Link("gc", pkg_config: "bdw-gc")]
{% end %}

{% if compare_versions(Crystal::VERSION, "1.11.0-dev") >= 0 %}
@[Link(dll: "gc.dll")]
{% end %}
lib LibGC
{% unless flag?(:win32) %}
VERSION = {{ `pkg-config bdw-gc --silence-errors --modversion || printf "0.0.0"`.chomp.stringify }}
{% end %}

alias Int = LibC::Int
alias SizeT = LibC::SizeT
{% if flag?(:win32) && flag?(:bits64) %}
Expand Down Expand Up @@ -96,7 +100,7 @@ lib LibGC

fun push_all_eager = GC_push_all_eager(bottom : Void*, top : Void*)

{% if flag?(:preview_mt) || flag?(:win32) %}
{% if flag?(:preview_mt) || flag?(:win32) || compare_versions(VERSION, "8.2.0") >= 0 %}
fun get_my_stackbottom = GC_get_my_stackbottom(sb : StackBase*) : ThreadHandle
fun set_stackbottom = GC_set_stackbottom(th : ThreadHandle, sb : StackBase*) : ThreadHandle
{% else %}
Expand Down Expand Up @@ -277,10 +281,11 @@ module GC

# :nodoc:
def self.current_thread_stack_bottom
{% if flag?(:preview_mt) || flag?(:win32) %}
{% if LibGC.has_method?(:get_my_stackbottom) %}
th = LibGC.get_my_stackbottom(out sb)
{th, sb.mem_base}
{% else %}
# support for legacy gc releases
{Pointer(Void).null, LibGC.stackbottom}
{% end %}
end
Expand All @@ -292,17 +297,19 @@ module GC
sb.mem_base = stack_bottom
LibGC.set_stackbottom(thread_handle, pointerof(sb))
end
{% elsif flag?(:win32) %}
{% elsif LibGC.has_method?(:set_stackbottom) %}
# this is necessary because Boehm GC does _not_ use `GC_stackbottom` on
# Windows when pushing all threads' stacks; instead `GC_set_stackbottom`
# must be used to associate the new bottom with the running thread
# Windows when pushing all threads' stacks; it also started crashing on
# Linux with libgc after v8.2.4; instead `GC_set_stackbottom` must be used
# to associate the new bottom with the running thread
def self.set_stackbottom(stack_bottom : Void*)
sb = LibGC::StackBase.new
sb.mem_base = stack_bottom
# `nil` represents the current thread (i.e. the only one)
LibGC.set_stackbottom(nil, pointerof(sb))
end
{% else %}
# support for legacy gc releases
def self.set_stackbottom(stack_bottom : Void*)
LibGC.stackbottom = stack_bottom
end
Expand Down

0 comments on commit 382041c

Please sign in to comment.