Skip to content

Commit 11dc95e

Browse files
committed
Merge pull request #2705 from lubinszARM:pr_sigfp_nested
PiperOrigin-RevId: 315979564
2 parents 13f2664 + 0b26f9a commit 11dc95e

File tree

3 files changed

+45
-15
lines changed

3 files changed

+45
-15
lines changed

test/syscalls/linux/BUILD

+1-4
Original file line numberDiff line numberDiff line change
@@ -852,10 +852,7 @@ cc_binary(
852852
cc_binary(
853853
name = "fpsig_nested_test",
854854
testonly = 1,
855-
srcs = select_arch(
856-
amd64 = ["fpsig_nested.cc"],
857-
arm64 = [],
858-
),
855+
srcs = ["fpsig_nested.cc"],
859856
linkstatic = 1,
860857
deps = [
861858
gtest,

test/syscalls/linux/fpsig_fork.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ namespace {
3737
#define __stringify_1(x...) #x
3838
#define __stringify(x...) __stringify_1(x)
3939
#define GET_FPREG(var, regname) \
40-
asm volatile("str "__stringify(regname) ", %0" : "=m"(var))
40+
asm volatile("str " __stringify(regname) ", %0" : "=m"(var))
4141
#define SET_FPREG(var, regname) \
42-
asm volatile("ldr "__stringify(regname) ", %0" : "=m"(var))
42+
asm volatile("ldr " __stringify(regname) ", %0" : "=m"(var))
4343
#define GET_FP0(var) GET_FPREG(var, d0)
44-
#define SET_FP0(var) GET_FPREG(var, d0)
44+
#define SET_FP0(var) SET_FPREG(var, d0)
4545
#endif
4646

4747
int parent, child;

test/syscalls/linux/fpsig_nested.cc

+41-8
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,22 @@ namespace testing {
2626

2727
namespace {
2828

29+
#ifdef __x86_64__
2930
#define GET_XMM(__var, __xmm) \
3031
asm volatile("movq %%" #__xmm ", %0" : "=r"(__var))
3132
#define SET_XMM(__var, __xmm) asm volatile("movq %0, %%" #__xmm : : "r"(__var))
33+
#define GET_FP0(__var) GET_XMM(__var, xmm0)
34+
#define SET_FP0(__var) SET_XMM(__var, xmm0)
35+
#elif __aarch64__
36+
#define __stringify_1(x...) #x
37+
#define __stringify(x...) __stringify_1(x)
38+
#define GET_FPREG(var, regname) \
39+
asm volatile("str " __stringify(regname) ", %0" : "=m"(var))
40+
#define SET_FPREG(var, regname) \
41+
asm volatile("ldr " __stringify(regname) ", %0" : "=m"(var))
42+
#define GET_FP0(var) GET_FPREG(var, d0)
43+
#define SET_FP0(var) SET_FPREG(var, d0)
44+
#endif
3245

3346
int pid;
3447
int tid;
@@ -40,20 +53,21 @@ void sigusr2(int s, siginfo_t* siginfo, void* _uc) {
4053
uint64_t val = SIGUSR2;
4154

4255
// Record the value of %xmm0 on entry and then clobber it.
43-
GET_XMM(entryxmm[1], xmm0);
44-
SET_XMM(val, xmm0);
45-
GET_XMM(exitxmm[1], xmm0);
56+
GET_FP0(entryxmm[1]);
57+
SET_FP0(val);
58+
GET_FP0(exitxmm[1]);
4659
}
4760

4861
void sigusr1(int s, siginfo_t* siginfo, void* _uc) {
4962
uint64_t val = SIGUSR1;
5063

5164
// Record the value of %xmm0 on entry and then clobber it.
52-
GET_XMM(entryxmm[0], xmm0);
53-
SET_XMM(val, xmm0);
65+
GET_FP0(entryxmm[0]);
66+
SET_FP0(val);
5467

5568
// Send a SIGUSR2 to ourself. The signal mask is configured such that
5669
// the SIGUSR2 handler will run before this handler returns.
70+
#ifdef __x86_64__
5771
asm volatile(
5872
"movl %[killnr], %%eax;"
5973
"movl %[pid], %%edi;"
@@ -66,10 +80,19 @@ void sigusr1(int s, siginfo_t* siginfo, void* _uc) {
6680
: "rax", "rdi", "rsi", "rdx",
6781
// Clobbered by syscall.
6882
"rcx", "r11");
83+
#elif __aarch64__
84+
asm volatile(
85+
"mov x8, %0\n"
86+
"mov x0, %1\n"
87+
"mov x1, %2\n"
88+
"mov x2, %3\n"
89+
"svc #0\n" ::"r"(__NR_tgkill),
90+
"r"(pid), "r"(tid), "r"(SIGUSR2));
91+
#endif
6992

7093
// Record value of %xmm0 again to verify that the nested signal handler
7194
// does not clobber it.
72-
GET_XMM(exitxmm[0], xmm0);
95+
GET_FP0(exitxmm[0]);
7396
}
7497

7598
TEST(FPSigTest, NestedSignals) {
@@ -98,8 +121,9 @@ TEST(FPSigTest, NestedSignals) {
98121
// to signal the current thread ensures that this is the clobbered thread.
99122

100123
uint64_t expected = 0xdeadbeeffacefeed;
101-
SET_XMM(expected, xmm0);
124+
SET_FP0(expected);
102125

126+
#ifdef __x86_64__
103127
asm volatile(
104128
"movl %[killnr], %%eax;"
105129
"movl %[pid], %%edi;"
@@ -112,9 +136,18 @@ TEST(FPSigTest, NestedSignals) {
112136
: "rax", "rdi", "rsi", "rdx",
113137
// Clobbered by syscall.
114138
"rcx", "r11");
139+
#elif __aarch64__
140+
asm volatile(
141+
"mov x8, %0\n"
142+
"mov x0, %1\n"
143+
"mov x1, %2\n"
144+
"mov x2, %3\n"
145+
"svc #0\n" ::"r"(__NR_tgkill),
146+
"r"(pid), "r"(tid), "r"(SIGUSR1));
147+
#endif
115148

116149
uint64_t got;
117-
GET_XMM(got, xmm0);
150+
GET_FP0(got);
118151

119152
//
120153
// The checks below verifies the following:

0 commit comments

Comments
 (0)