Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix runtime segfault #4294

Merged
merged 1 commit into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .release-notes/fix-4284.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Fix runtime segfault

A segfault was introduced in ["Fix segfault caused by unsafe garbage collection optimization"](https://github.com/ponylang/ponyc/pull/4256). `tag` objects were being incorrectly traced which could eventually result in a segfault.

If you are using Pony version 0.52.3 to 0.52.5, we recommend upgrading as soon as possible.
6 changes: 6 additions & 0 deletions src/libponyrt/gc/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@ static void send_remote_object(pony_ctx_t* ctx, pony_actor_t* actor,
obj->rc--;
}

if(mutability == PONY_TRACE_OPAQUE)
return;

if(mutability == PONY_TRACE_MUTABLE || might_reference_actor(t))
recurse(ctx, p, t->trace);
}
Expand Down Expand Up @@ -443,6 +446,9 @@ static void mark_remote_object(pony_ctx_t* ctx, pony_actor_t* actor,
acquire_object(ctx, actor, p, obj->immutable);
}

if(mutability == PONY_TRACE_OPAQUE)
return;

if(mutability == PONY_TRACE_MUTABLE || might_reference_actor(t))
recurse(ctx, p, t->trace);
}
Expand Down
45 changes: 45 additions & 0 deletions test/libponyc-run/regression-4284/main.pony
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use "pony_test"


// As long as #4284 is fixed, this program will run to completion and
// _TestIssue4284 will pass. If a regression is introduced, this
// program will crash.

actor Main is TestList
new create(env: Env) =>
PonyTest(env, this)

fun tag tests(test: PonyTest) =>
test(_TestIssue4284)

class iso _TestIssue4284 is UnitTest
fun name(): String => "_TestIssue4284"

fun apply(h: TestHelper) =>
let mutable = MutableState

var i: USize = 0
while i < 10 do i = i + 1
SomeActor.trace(HasOpaqueReferenceToMutableState(mutable), 100_000)
end

h.long_test(1_000_000_000)
h.complete(true)

class MutableState
let _inner: ImmutableStateInner = ImmutableStateInner
new create() => None

class val ImmutableStateInner
let _data: Array[String] = []
new val create() => None

class val HasOpaqueReferenceToMutableState
let _opaque: MutableState tag
new val create(opaque: MutableState tag) => _opaque = opaque

actor SomeActor
be trace(immutable: HasOpaqueReferenceToMutableState, count: USize) =>
if count > 1 then
trace(immutable, count - 1)
end