Skip to content

Commit 61b01cc

Browse files
authored
LCShim: Add CZ prefixes/pidfd wrappers (#189)
We should namespace these a bit, and we need pidfd for some upcoming terminal work. This also just gets rid of syscall2 and replaces with a pivot_root wrapper.
1 parent bdba5b5 commit 61b01cc

File tree

4 files changed

+33
-11
lines changed

4 files changed

+33
-11
lines changed
Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,25 @@
1414
* limitations under the License.
1515
*/
1616

17-
//
17+
#ifndef __SYSCALL_H
18+
#define __SYSCALL_H
1819

19-
#ifndef __SYSCALL2_H
20-
#define __SYSCALL2_H
20+
#include <sys/types.h>
2121

22-
int syscall2(long number, void *arg1, void *arg2);
22+
int CZ_pivot_root(const char *new_root, const char *put_old);
2323

24-
int set_sub_reaper();
24+
int CZ_set_sub_reaper();
25+
26+
#ifndef SYS_pidfd_open
27+
#define SYS_pidfd_open 434
28+
#endif
29+
30+
int CZ_pidfd_open(pid_t pid, unsigned int flags);
31+
32+
#ifndef SYS_pidfd_getfd
33+
#define SYS_pidfd_getfd 438
34+
#endif
35+
36+
int CZ_pidfd_getfd(int pidfd, int targetfd, unsigned int flags);
2537

2638
#endif
Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,20 @@
1818
#include <sys/syscall.h>
1919
#include <unistd.h>
2020

21-
#include "syscall2.h"
21+
#include "syscall.h"
2222

23-
int syscall2(long number, void *arg1, void *arg2) {
24-
return syscall(number, arg1, arg2);
23+
int CZ_pivot_root(const char *new_root, const char *put_old) {
24+
return syscall(SYS_pivot_root, new_root, put_old);
2525
}
2626

27-
int set_sub_reaper() { return prctl(PR_SET_CHILD_SUBREAPER, 1); }
27+
int CZ_set_sub_reaper() { return prctl(PR_SET_CHILD_SUBREAPER, 1); }
28+
29+
int CZ_pidfd_open(pid_t pid, unsigned int flags) {
30+
// Musl doesn't have pidfd_open.
31+
return syscall(SYS_pidfd_open, pid, flags);
32+
}
33+
34+
int CZ_pidfd_getfd(int pidfd, int targetfd, unsigned int flags) {
35+
// Musl doesn't have pidfd_getfd.
36+
return syscall(SYS_pidfd_getfd, pidfd, targetfd, flags);
37+
}

vminitd/Sources/vmexec/RunCommand.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ struct RunCommand: ParsableCommand {
228228
guard fchdir(newRoot) == 0 else {
229229
throw App.Errno(stage: "fchdir(newroot)")
230230
}
231-
guard syscall2(Int(SYS_pivot_root), toCString("."), toCString(".")) == 0 else {
231+
guard CZ_pivot_root(toCString("."), toCString(".")) == 0 else {
232232
throw App.Errno(stage: "pivot_root()")
233233
}
234234
// change cwd to the old root

vminitd/Sources/vminitd/Application.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ struct Application {
8888
// since we are not running as pid1 in this mode we must set ourselves
8989
// as a subpreaper so that all child processes are reaped by us and not
9090
// passed onto our parent.
91-
set_sub_reaper()
91+
CZ_set_sub_reaper()
9292
#endif
9393

9494
signal(SIGPIPE, SIG_IGN)

0 commit comments

Comments
 (0)