Skip to content

Commit 38b6fcf

Browse files
committed
fix: syscalls
1 parent 19966b9 commit 38b6fcf

File tree

4 files changed

+78
-78
lines changed

4 files changed

+78
-78
lines changed

packages/std/packages/stub/include/aarch64/debug.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#pragma once
2-
#ifdef SOFTWARE_BREAKPOINTS
2+
#ifdef BREAKPOINTS
33
#define BREAK do { asm volatile ("brk #0"); } while (0)
44
#else
55
#define BREAK
Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
#pragma once
22

3-
static long syscall1 (
3+
static inline long syscall1 (
44
long nr,
55
long arg1
66
) {
77
register long x8 asm("x8") = nr;
88
register long x0 asm("x0") = arg1;
99
asm volatile (
10-
"svc #0;"
11-
"ret;"
12-
:
10+
"svc #0"
11+
: "=r"(x0)
1312
: "r"(x8), "r"(x0)
1413
: "memory"
1514
);
15+
return x0;
1616
}
1717

18-
static long syscall2 (
18+
static inline long syscall2 (
1919
long nr,
2020
long arg1,
2121
long arg2
@@ -24,15 +24,15 @@ static long syscall2 (
2424
register long x0 asm("x0") = arg1;
2525
register long x1 asm("x1") = arg2;
2626
asm volatile (
27-
"svc #0;"
28-
"ret;"
29-
:
27+
"svc #0"
28+
: "=r"(x0)
3029
: "r"(x8), "r"(x0), "r"(x1)
3130
: "memory"
3231
);
32+
return x0;
3333
}
3434

35-
static long syscall3 (
35+
static inline long syscall3 (
3636
long nr,
3737
long arg1,
3838
long arg2,
@@ -43,15 +43,15 @@ static long syscall3 (
4343
register long x1 asm("x1") = arg2;
4444
register long x2 asm("x2") = arg3;
4545
asm volatile (
46-
"svc #0;"
47-
"ret;"
48-
:
46+
"svc #0"
47+
: "=r"(x0)
4948
: "r"(x8), "r"(x0), "r"(x1), "r"(x2)
5049
: "memory"
5150
);
51+
return x0;
5252
}
5353

54-
static long syscall4 (
54+
static inline long syscall4 (
5555
long nr,
5656
long arg1,
5757
long arg2,
@@ -64,15 +64,15 @@ static long syscall4 (
6464
register long x2 asm("x2") = arg3;
6565
register long x3 asm("x3") = arg4;
6666
asm volatile (
67-
"svc #0;"
68-
"ret;"
69-
:
67+
"svc #0"
68+
: "=r"(x0)
7069
: "r"(x8), "r"(x0), "r"(x1), "r"(x2), "r"(x3)
7170
: "memory"
7271
);
72+
return x0;
7373
}
7474

75-
static long syscall5 (
75+
static inline long syscall5 (
7676
long nr,
7777
long arg1,
7878
long arg2,
@@ -87,15 +87,15 @@ static long syscall5 (
8787
register long x3 asm("x3") = arg4;
8888
register long x4 asm("x4") = arg5;
8989
asm volatile (
90-
"svc #0;"
91-
"ret;"
92-
:
90+
"svc #0"
91+
: "=r"(x0)
9392
: "r"(x8), "r"(x0), "r"(x1), "r"(x2), "r"(x3), "r"(x4)
9493
: "memory"
9594
);
95+
return x0;
9696
}
9797

98-
static long syscall6 (
98+
static inline long syscall6 (
9999
long nr,
100100
long arg1,
101101
long arg2,
@@ -112,10 +112,10 @@ static long syscall6 (
112112
register long x4 asm("x4") = arg5;
113113
register long x5 asm("x5") = arg6;
114114
asm volatile (
115-
"svc #0;"
116-
"ret;"
117-
:
115+
"svc #0"
116+
: "=r"(x0)
118117
: "r"(x8), "r"(x0), "r"(x1), "r"(x2), "r"(x3), "r"(x4), "r"(x5)
119118
: "memory"
120119
);
121-
}
120+
return x0;
121+
}

packages/std/packages/stub/include/syscall.h

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,12 @@ static inline int close (int fd) {
8181
return (int)syscall1(__NR_close, (long)fd);
8282
}
8383

84-
static inline long lseek (int fd, off_t offset, int whence) {
85-
return syscall3(__NR_lseek, (long)fd, (long)offset, (long)whence);
86-
}
87-
88-
static inline int getrlimit (int resource, rlimit_t* rlim) {
89-
return (int)syscall2(__NR_getrlimit, (long)resource, (long)rlim);
90-
}
91-
92-
static inline int pread64 (int fd, void* buf, size_t count, off_t offset) {
93-
return (int)syscall4(__NR_pread64, (long)fd, (long)buf, (long)count, (long)offset);
84+
static inline int stat (const char* pathname, stat_t* statbuf) {
85+
return (int)syscall2(__NR_stat, (long)pathname, (long)statbuf);
9486
}
9587

96-
static inline void exit (int status)
97-
{
98-
syscall1(__NR_exit, (long)status);
99-
__builtin_unreachable();
88+
static inline long lseek (int fd, off_t offset, int whence) {
89+
return syscall3(__NR_lseek, (long)fd, (long)offset, (long)whence);
10090
}
10191

10292
static inline void* mmap(
@@ -122,22 +112,31 @@ static inline int munmap(void* addr, uint64_t len) {
122112
return (int)syscall2(__NR_munmap, (long)addr, (long)len);
123113
}
124114

125-
static inline int getcwd(char* buf, size_t size) {
126-
return (int)syscall2(__NR_getcwd, (long)buf, (long)size);
115+
static inline int pread64 (int fd, void* buf, size_t count, off_t offset) {
116+
return (int)syscall4(__NR_pread64, (long)fd, (long)buf, (long)count, (long)offset);
127117
}
128118

129-
static inline int stat (const char* pathname, stat_t* statbuf) {
130-
return (int)syscall2(__NR_stat, (long)pathname, (long)statbuf);
119+
static inline int execve (char* pathname, char** argv, char** envp) {
120+
return (int)syscall3(__NR_execve, (long)pathname, (long)argv, (long)envp);
131121
}
132122

133-
static inline long getrandom (void *buf, size_t buflen, unsigned int flags) {
134-
return (long)syscall3(__NR_getrandom, (long)buf, (long)buflen, (long)flags);
123+
static inline void exit (int status) {
124+
syscall1(__NR_exit, (long)status);
125+
__builtin_unreachable();
135126
}
136127

137-
static inline int execve (char* pathname, char** argv, char** envp) {
138-
return (int)syscall3(__NR_execve, (long)pathname, (long)argv, (long)envp);
128+
static inline int getcwd(char* buf, size_t size) {
129+
return (int)syscall2(__NR_getcwd, (long)buf, (long)size);
139130
}
140131

141132
static inline long readlink (const char* pathname, char* buf, size_t bufsiz) {
142133
return syscall3(__NR_readlink, (long)pathname, (long)buf, (long)bufsiz);
143134
}
135+
136+
static inline int getrlimit (int resource, rlimit_t* rlim) {
137+
return (int)syscall2(__NR_getrlimit, (long)resource, (long)rlim);
138+
}
139+
140+
static inline long getrandom (void *buf, size_t buflen, unsigned int flags) {
141+
return (long)syscall3(__NR_getrandom, (long)buf, (long)buflen, (long)flags);
142+
}
Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,106 @@
11
#pragma once
2-
__attribute__((naked))
3-
static long syscall1 (
2+
3+
static inline long syscall1 (
44
long nr,
55
long arg1
66
) {
7+
long ret;
78
register long rax asm("rax") = nr;
89
register long rdi asm("rdi") = arg1;
910
asm volatile (
10-
"syscall;"
11-
"ret;"
12-
:
11+
"syscall"
12+
: "=a"(ret)
1313
: "a"(rax), "D"(rdi)
1414
: "rcx", "r11", "memory"
1515
);
16+
return ret;
1617
}
1718

18-
__attribute__((naked))
19-
static long syscall2 (
19+
static inline long syscall2 (
2020
long nr,
2121
long arg1,
2222
long arg2
2323
) {
24+
long ret;
2425
register long rax asm("rax") = nr;
2526
register long rdi asm("rdi") = arg1;
2627
register long rsi asm("rsi") = arg2;
2728
asm volatile (
28-
"syscall;"
29-
"ret;"
30-
:
29+
"syscall"
30+
: "=a"(ret)
3131
: "a"(rax), "D"(rdi), "S"(rsi)
3232
: "rcx", "r11", "memory"
3333
);
34+
return ret;
3435
}
3536

36-
__attribute__((naked))
37-
static long syscall3 (
37+
static inline long syscall3 (
3838
long nr,
3939
long arg1,
4040
long arg2,
4141
long arg3
4242
) {
43+
long ret;
4344
register long rax asm("rax") = nr;
4445
register long rdi asm("rdi") = arg1;
4546
register long rsi asm("rsi") = arg2;
4647
register long rdx asm("rdx") = arg3;
4748
asm volatile (
48-
"syscall;"
49-
"ret;"
50-
:
49+
"syscall"
50+
: "=a"(ret)
5151
: "a"(rax), "D"(rdi), "S"(rsi), "d"(rdx)
5252
: "rcx", "r11", "memory"
5353
);
54+
return ret;
5455
}
5556

56-
__attribute__((naked))
57-
static long syscall4 (
57+
static inline long syscall4 (
5858
long nr,
5959
long arg1,
6060
long arg2,
6161
long arg3,
6262
long arg4
6363
) {
64+
long ret;
6465
register long rax asm("rax") = nr;
6566
register long rdi asm("rdi") = arg1;
6667
register long rsi asm("rsi") = arg2;
6768
register long rdx asm("rdx") = arg3;
6869
register long r10 asm("r10") = arg4;
6970
asm volatile (
70-
"syscall;"
71-
"ret;"
72-
:
71+
"syscall"
72+
: "=a"(ret)
7373
: "a"(rax), "D"(rdi), "S"(rsi), "d"(rdx), "r"(r10)
7474
: "rcx", "r11", "memory"
7575
);
76+
return ret;
7677
}
7778

78-
__attribute__((naked))
79-
static long syscall5 (
79+
static inline long syscall5 (
8080
long nr,
8181
long arg1,
8282
long arg2,
8383
long arg3,
8484
long arg4,
8585
long arg5
8686
) {
87+
long ret;
8788
register long rax asm("rax") = nr;
8889
register long rdi asm("rdi") = arg1;
8990
register long rsi asm("rsi") = arg2;
9091
register long rdx asm("rdx") = arg3;
9192
register long r10 asm("r10") = arg4;
9293
register long r8 asm("r8") = arg5;
9394
asm volatile (
94-
"syscall;"
95-
"ret;"
96-
:
95+
"syscall"
96+
: "=a"(ret)
9797
: "a"(rax), "D"(rdi), "S"(rsi), "d"(rdx), "r"(r10), "r"(r8)
9898
: "rcx", "r11", "memory"
9999
);
100+
return ret;
100101
}
101102

102-
__attribute__((naked))
103-
static long syscall6 (
103+
static inline long syscall6 (
104104
long nr,
105105
long arg1,
106106
long arg2,
@@ -109,6 +109,7 @@ static long syscall6 (
109109
long arg5,
110110
long arg6
111111
) {
112+
long ret;
112113
register long rax asm("rax") = nr;
113114
register long rdi asm("rdi") = arg1;
114115
register long rsi asm("rsi") = arg2;
@@ -117,10 +118,10 @@ static long syscall6 (
117118
register long r8 asm("r8") = arg5;
118119
register long r9 asm("r9") = arg6;
119120
asm volatile (
120-
"syscall;"
121-
"ret;"
122-
:
121+
"syscall"
122+
: "=a"(ret)
123123
: "a"(rax), "D"(rdi), "S"(rsi), "d"(rdx), "r"(r10), "r"(r8), "r"(r9)
124124
: "rcx", "r11", "memory"
125125
);
126+
return ret;
126127
}

0 commit comments

Comments
 (0)