Skip to content

Commit 3fc931b

Browse files
[GR-18215] Uninterruptible stack walk
PullRequest: graal/10980
2 parents 63f1a04 + 2a4ad2e commit 3fc931b

File tree

17 files changed

+148
-20
lines changed

17 files changed

+148
-20
lines changed

substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/UContextRegisterDumper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,13 @@ default PointerBase getThreadPointer(Context context) {
6060
}
6161

6262
@Override
63+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
6364
default PointerBase getSP(Context context) {
6465
return getSP((ucontext_t) context);
6566
}
6667

6768
@Override
69+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
6870
default PointerBase getIP(Context context) {
6971
return getIP((ucontext_t) context);
7072
}

substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/aarch64/AArch64DarwinUContextRegisterDumper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,14 @@ public PointerBase getThreadPointer(Signal.ucontext_t uContext) {
110110
}
111111

112112
@Override
113+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
113114
public PointerBase getSP(Signal.ucontext_t uContext) {
114115
Signal.AArch64DarwinMContext64 sigcontext = uContext.uc_mcontext_darwin_aarch64();
115116
return WordFactory.pointer(sigcontext.sp());
116117
}
117118

118119
@Override
120+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
119121
public PointerBase getIP(Signal.ucontext_t uContext) {
120122
Signal.AArch64DarwinMContext64 sigcontext = uContext.uc_mcontext_darwin_aarch64();
121123
return WordFactory.pointer(sigcontext.pc());

substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/aarch64/AArch64LinuxUContextRegisterDumper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,14 @@ public PointerBase getThreadPointer(ucontext_t uContext) {
112112
}
113113

114114
@Override
115+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
115116
public PointerBase getSP(ucontext_t uContext) {
116117
mcontext_linux_aarch64_t sigcontext = uContext.uc_mcontext_linux_aarch64();
117118
return WordFactory.pointer(sigcontext.sp());
118119
}
119120

120121
@Override
122+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
121123
public PointerBase getIP(ucontext_t uContext) {
122124
mcontext_linux_aarch64_t sigcontext = uContext.uc_mcontext_linux_aarch64();
123125
return WordFactory.pointer(sigcontext.pc());

substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/amd64/AMD64DarwinUContextRegisterDumper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,14 @@ public PointerBase getThreadPointer(ucontext_t uContext) {
9595
}
9696

9797
@Override
98+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
9899
public PointerBase getSP(ucontext_t uContext) {
99100
Signal.AMD64DarwinMContext64 sigcontext = uContext.uc_mcontext_darwin_amd64();
100101
return ((Pointer) sigcontext).readWord(sigcontext.rsp_offset());
101102
}
102103

103104
@Override
105+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
104106
public PointerBase getIP(ucontext_t uContext) {
105107
Signal.AMD64DarwinMContext64 sigcontext = uContext.uc_mcontext_darwin_amd64();
106108
return ((Pointer) sigcontext).readWord(sigcontext.rip_offset());

substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/amd64/AMD64LinuxUContextRegisterDumper.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,26 +82,28 @@ public void dumpRegisters(Log log, ucontext_t uContext, boolean printLocationInf
8282
}
8383

8484
@Override
85-
@Uninterruptible(reason = "Called from uninterruptible code", mayBeInlined = true, calleeMustBe = false)
85+
@Uninterruptible(reason = "Called from uninterruptible code", mayBeInlined = true)
8686
public PointerBase getHeapBase(ucontext_t uContext) {
8787
GregsPointer gregs = uContext.uc_mcontext_linux_amd64_gregs();
8888
return WordFactory.pointer(gregs.read(GregEnumLinuxAMD64.REG_R14()));
8989
}
9090

9191
@Override
92-
@Uninterruptible(reason = "Called from uninterruptible code", mayBeInlined = true, calleeMustBe = false)
92+
@Uninterruptible(reason = "Called from uninterruptible code", mayBeInlined = true)
9393
public PointerBase getThreadPointer(ucontext_t uContext) {
9494
GregsPointer gregs = uContext.uc_mcontext_linux_amd64_gregs();
9595
return WordFactory.pointer(gregs.read(GregEnumLinuxAMD64.REG_R15()));
9696
}
9797

9898
@Override
99+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
99100
public PointerBase getSP(ucontext_t uContext) {
100101
GregsPointer gregs = uContext.uc_mcontext_linux_amd64_gregs();
101102
return WordFactory.pointer(gregs.read(GregEnumLinuxAMD64.REG_RSP()));
102103
}
103104

104105
@Override
106+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
105107
public PointerBase getIP(ucontext_t uContext) {
106108
GregsPointer gregs = uContext.uc_mcontext_linux_amd64_gregs();
107109
return WordFactory.pointer(gregs.read(GregEnumLinuxAMD64.REG_RIP()));

substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Errno.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ public class Errno {
5858
@CConstant
5959
public static native int ETIMEDOUT();
6060

61+
@CConstant
62+
public static native int EFAULT();
63+
64+
@CConstant
65+
public static native int EINVAL();
66+
67+
@CConstant
68+
public static native int EAGAIN();
69+
70+
@CConstant
71+
public static native int ENOMEM();
72+
6173
@CFunction
6274
public static native CCharPointer strerror(int errnum);
6375
}

substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Pthread.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.graalvm.nativeimage.c.function.CLibrary;
3232
import org.graalvm.nativeimage.c.struct.CPointerTo;
3333
import org.graalvm.nativeimage.c.struct.CStruct;
34+
import org.graalvm.nativeimage.c.type.VoidPointer;
3435
import org.graalvm.nativeimage.c.type.WordPointer;
3536
import org.graalvm.word.PointerBase;
3637
import org.graalvm.word.UnsignedWord;
@@ -77,6 +78,17 @@ public interface pthread_cond_t extends PointerBase {
7778
public interface pthread_condattr_t extends PointerBase {
7879
}
7980

81+
public interface pthread_key_t extends UnsignedWord {
82+
}
83+
84+
@CPointerTo(nameOfCType = "size_t")
85+
public interface pthread_key_tPointer extends PointerBase {
86+
pthread_key_t read();
87+
}
88+
89+
@CConstant
90+
public static native int PTHREAD_KEYS_MAX();
91+
8092
@CConstant
8193
public static native int PTHREAD_CREATE_JOINABLE();
8294

@@ -161,4 +173,13 @@ public interface pthread_condattr_t extends PointerBase {
161173

162174
@CFunction
163175
public static native int pthread_kill(pthread_t thread, Signal.SignalEnum sig);
176+
177+
@CFunction(transition = Transition.NO_TRANSITION)
178+
public static native int pthread_key_create(pthread_key_tPointer key, PointerBase keyDestructor);
179+
180+
@CFunction(transition = Transition.NO_TRANSITION)
181+
public static native int pthread_setspecific(pthread_key_t key, VoidPointer value);
182+
183+
@CFunction(transition = Transition.NO_TRANSITION)
184+
public static native VoidPointer pthread_getspecific(pthread_key_t key);
164185
}

substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Time.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@
2525
package com.oracle.svm.core.posix.headers;
2626

2727
import org.graalvm.nativeimage.c.CContext;
28+
import org.graalvm.nativeimage.c.constant.CEnum;
29+
import org.graalvm.nativeimage.c.constant.CEnumValue;
2830
import org.graalvm.nativeimage.c.function.CFunction;
2931
import org.graalvm.nativeimage.c.function.CFunction.Transition;
3032
import org.graalvm.nativeimage.c.struct.AllowNarrowingCast;
3133
import org.graalvm.nativeimage.c.struct.AllowWideningCast;
3234
import org.graalvm.nativeimage.c.struct.CField;
35+
import org.graalvm.nativeimage.c.struct.CFieldAddress;
3336
import org.graalvm.nativeimage.c.struct.CStruct;
3437
import org.graalvm.word.PointerBase;
3538

@@ -78,7 +81,33 @@ public interface timespec extends PointerBase {
7881
void set_tv_nsec(long value);
7982
}
8083

84+
@CStruct(addStructKeyword = true)
85+
public interface itimerval extends PointerBase {
86+
@CFieldAddress
87+
timeval it_interval();
88+
89+
@CFieldAddress
90+
timeval it_value();
91+
}
92+
93+
@CEnum
94+
@CContext(PosixDirectives.class)
95+
public enum TimerTypeEnum {
96+
ITIMER_REAL,
97+
ITIMER_VIRTUAL,
98+
ITIMER_PROF;
99+
100+
@CEnumValue
101+
public native int getCValue();
102+
}
103+
81104
public static class NoTransitions {
105+
/**
106+
* @param which from {@link TimerTypeEnum#getCValue()}
107+
*/
108+
@CFunction(transition = CFunction.Transition.NO_TRANSITION)
109+
public static native int setitimer(TimerTypeEnum which, itimerval newValue, itimerval oldValue);
110+
82111
@CFunction(transition = CFunction.Transition.NO_TRANSITION)
83112
public static native int gettimeofday(timeval tv, timezone tz);
84113

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,13 @@ public PointerBase getThreadPointer(Context context) {
9191
}
9292

9393
@Override
94+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
9495
public PointerBase getSP(Context context) {
9596
return WordFactory.pointer(((CONTEXT) context).Rsp());
9697
}
9798

9899
@Override
100+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
99101
public PointerBase getIP(Context context) {
100102
return WordFactory.pointer(((CONTEXT) context).Rip());
101103
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/c/NonmovableArrays.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,6 @@ public static <T> void setObject(NonmovableObjectArray<T> array, int index, T va
443443
/**
444444
* Visits all array elements with the provided {@link ObjectReferenceVisitor}.
445445
*/
446-
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true, calleeMustBe = false)
447446
public static boolean walkUnmanagedObjectArray(NonmovableObjectArray<?> array, ObjectReferenceVisitor visitor) {
448447
if (array.isNonNull()) {
449448
return walkUnmanagedObjectArray(array, visitor, 0, lengthOf(array));
@@ -454,7 +453,6 @@ public static boolean walkUnmanagedObjectArray(NonmovableObjectArray<?> array, O
454453
/**
455454
* Visits all array elements with the provided {@link ObjectReferenceVisitor}.
456455
*/
457-
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true, calleeMustBe = false)
458456
public static boolean walkUnmanagedObjectArray(NonmovableObjectArray<?> array, ObjectReferenceVisitor visitor, int startIndex, int count) {
459457
if (array.isNonNull()) {
460458
assert startIndex >= 0 && count <= lengthOf(array) - startIndex;

0 commit comments

Comments
 (0)