Skip to content

Commit c77628e

Browse files
committed
Fix Win32 API error handling in WindowsVMSemaphore
1 parent 91037ef commit c77628e

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsVMLockSupport.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import static com.oracle.svm.core.heap.RestrictHeapAccess.Access.NO_ALLOCATION;
2828

29-
import jdk.graal.compiler.word.Word;
3029
import org.graalvm.nativeimage.ImageSingletons;
3130
import org.graalvm.nativeimage.LogHandler;
3231
import org.graalvm.nativeimage.Platform;
@@ -48,6 +47,8 @@
4847
import com.oracle.svm.core.windows.headers.SynchAPI;
4948
import com.oracle.svm.core.windows.headers.WinBase;
5049

50+
import jdk.graal.compiler.word.Word;
51+
5152
@AutomaticallyRegisteredImageSingleton(VMLockSupport.class)
5253
public final class WindowsVMLockSupport extends VMLockSupport {
5354

@@ -78,7 +79,7 @@ static void checkResult(int result, String functionName) {
7879

7980
@Uninterruptible(reason = "Error handling is interruptible.", calleeMustBe = false)
8081
@RestrictHeapAccess(access = NO_ALLOCATION, reason = "Must not allocate in fatal error handling.")
81-
private static void fatalError(String functionName) {
82+
static void fatalError(String functionName) {
8283
/*
8384
* Functions are called very early and late during our execution, so there is not much we
8485
* can do when they fail.
@@ -296,14 +297,18 @@ public int initialize() {
296297
@Override
297298
@Uninterruptible(reason = "The isolate teardown is in progress.")
298299
public int destroy() {
299-
int errorCode = WinBase.CloseHandle(hSemaphore);
300+
int result = WinBase.CloseHandle(hSemaphore);
300301
hSemaphore = Word.nullPointer();
301-
return errorCode;
302+
return result != 0 ? 0 : 1;
302303
}
303304

304305
@Override
305306
public void await() {
306-
WindowsVMLockSupport.checkResult(SynchAPI.WaitForSingleObject(hSemaphore, SynchAPI.INFINITE()), "WaitForSingleObject");
307+
int result = SynchAPI.WaitForSingleObject(hSemaphore, SynchAPI.INFINITE());
308+
if (result != SynchAPI.WAIT_OBJECT_0()) {
309+
assert result == SynchAPI.WAIT_FAILED() : result;
310+
WindowsVMLockSupport.fatalError("WaitForSingleObject");
311+
}
307312
}
308313

309314
@Override

0 commit comments

Comments
 (0)