-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Ensure LibUnwind::Exception struct is not atomic #8728
Conversation
On the arm code there is another |
fbde9a8
to
c48484e
Compare
Good point, so this PR might not compile in arm, right? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the test code need to be in a separate file? It would be more clear to have the code directly in the spec.
Also is it on purpose that the file has no extension?
The spec should also be disabled for win32 because Process.run
does not yet work.
Another possibility is always doing malloc instead of malloc_atomic because others might be storing addresses like that. I know malloc_atomic is supposedly faster or easier for the GC but in my benchmarks that was never the case. Maybe it only matters for really big objects. |
I mean, anyone can use UInt64 as an address and we shouldn't just work in a wrong way. Prove me. wrong and I'll change my mind. |
|
All I'm saying is this:
So if we want to keep |
While it certainly is good practice to use Pointer, there are also cases when interacting C libraries where structs can have fields defined as UInt64, but where that size where chosen INTENTIONALLY so that the user should be free to put a pointer there. Do we want to force people that implement bindings for such cases to use I suppose an alternative solution would be to add some sort of directive that tells the compiler to treat it as a pointer. That way open-ended C bindings could be handled. Of course, this may also be nice to have in the very related area of precise GC. Example: The user_data fields in liburing. https://github.com/axboe/liburing/blob/master/src/include/liburing/io_uring.h#L41. It works by submitting events on one queue and getting back the result on a different queue, with user_data being the way to connect the result to where it came from. In the particular case of liburing it would probably not matter how it is allocated though - there still needs to be something else preventing things from being removed as the events may be hidden away in private copies in kernel memory while the event is being processed. (liburing is also fun to make bindings for in that it is a heavy user of |
The "Windows CI" failure is real, btw |
As @bcardiff said, I wouldn't relay on the conservative feature of the GC when writing bindings and other low level code. All we need to do is write proper documentation. I'll check the tests running in Windows and ARM and update the PR. |
TBH, just because there was other tests doing the same thing :). We can refactor later all these tests and replace with something more elegant. The file has no extension to avoid being picked up as a spec file. |
For the record, |
Note that a semi-precise GC will skip all attributes (including UInt64) and only follow actual pointers, so this patch is needed nonetheless. |
Currently any structure not containing any pointer is allocated with
GC.malloc_atomic
. This makes the GC faster by avoiding scan some memory regions unnecessary.LibUnwind::Exception
actually contains a pointer but it was being casted toUInt64
hidding it from the compiler.When the
ensure
block for example, contains calls that ends running the GC, the exception object would be cleaned. Later the exception is re-raised but now with a dangling pointer.The problem was easily reproduced running this code in release mode: