fix segfault related to #128 #129
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This needs some more (independent) validation, but this should fix the (long standing) segfault that previously was solved with the repeated
km_init
hack.Essentially, the previous code was handing out multiple references (including a mutable one) to the underlying thread local buffer at the same time. This voilates the rust shared xor mutable rules and, recalling that
unsafe
doesn't disable the rules and that we are still responsible for upholding them, I believe that opened us up to undefined behavior ultimately resulting in the segfault.This PR applies an easy fix. It simply moves the acquisition of the mutable pointer to the
km
object until after the call tomm_map
, so that we only acquire the mutable reference after the lifetime of themm_map
call is finished with it. In my testing, this seems to resolve the segfaults that were previously occurring.