[GR-75238] [GR-76153] Correctly capture errno.#992
Open
graalvmbot wants to merge 7 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 fixes a known issue with
errnohandling.When calling native functions that set
errno(i.e. most of the POSIX functions), we read theerrnovalue after the downcall returned. However, at that time,errnomay already have been clobbered by, e.g., the GC.Therefore, Java's FFM API provides a mechanism to capture the value of
errnobefore actually returning to Java (i.e. before the thread-state transition).In this PR, I'm adding support for that. I've extended annotation
@DowncallSignaturesuch that one can specify if the call state should be captured. The captured state will be stored in a thread-local variable inNativeContext.With
NativeContext.getErrno()andNativeContext.getLastError(), one can access those values.However, I also had a look at the hosted compiler graphs of the
NativePosixSupport.PosixNativeFunctionInvoker.call_*methods and it turns out that those look not very good.Further, FFM API call state capturing is unconditional but in case of a POSIX function returned w/o an error,
errnodoes not need to be captured.Since POSIX performance is crucial, I decided to do a custom solution for it.
Hence, in
NativePosixSupport, we allocate a thread-local buffer where we store the capturederrnovalue. The pointer to the buffer is passed as argument (nameerrno_out) to eachcall_*function. Our POSIX function wrappers then capture the value but only if needed (usually in the error case indicated by the return value). That should be even better than what we did before because we save additional downcalls to readerrno.