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.
This commit is contained in:
Danny Canter
2025-07-01 02:16:17 -07:00
committed by GitHub
parent bdba5b5740
commit 61b01cc1ee
4 changed files with 33 additions and 11 deletions
@@ -14,13 +14,25 @@
* limitations under the License.
*/
//
#ifndef __SYSCALL_H
#define __SYSCALL_H
#ifndef __SYSCALL2_H
#define __SYSCALL2_H
#include <sys/types.h>
int syscall2(long number, void *arg1, void *arg2);
int CZ_pivot_root(const char *new_root, const char *put_old);
int set_sub_reaper();
int CZ_set_sub_reaper();
#ifndef SYS_pidfd_open
#define SYS_pidfd_open 434
#endif
int CZ_pidfd_open(pid_t pid, unsigned int flags);
#ifndef SYS_pidfd_getfd
#define SYS_pidfd_getfd 438
#endif
int CZ_pidfd_getfd(int pidfd, int targetfd, unsigned int flags);
#endif
@@ -18,10 +18,20 @@
#include <sys/syscall.h>
#include <unistd.h>
#include "syscall2.h"
#include "syscall.h"
int syscall2(long number, void *arg1, void *arg2) {
return syscall(number, arg1, arg2);
int CZ_pivot_root(const char *new_root, const char *put_old) {
return syscall(SYS_pivot_root, new_root, put_old);
}
int set_sub_reaper() { return prctl(PR_SET_CHILD_SUBREAPER, 1); }
int CZ_set_sub_reaper() { return prctl(PR_SET_CHILD_SUBREAPER, 1); }
int CZ_pidfd_open(pid_t pid, unsigned int flags) {
// Musl doesn't have pidfd_open.
return syscall(SYS_pidfd_open, pid, flags);
}
int CZ_pidfd_getfd(int pidfd, int targetfd, unsigned int flags) {
// Musl doesn't have pidfd_getfd.
return syscall(SYS_pidfd_getfd, pidfd, targetfd, flags);
}
+1 -1
View File
@@ -228,7 +228,7 @@ struct RunCommand: ParsableCommand {
guard fchdir(newRoot) == 0 else {
throw App.Errno(stage: "fchdir(newroot)")
}
guard syscall2(Int(SYS_pivot_root), toCString("."), toCString(".")) == 0 else {
guard CZ_pivot_root(toCString("."), toCString(".")) == 0 else {
throw App.Errno(stage: "pivot_root()")
}
// change cwd to the old root
+1 -1
View File
@@ -88,7 +88,7 @@ struct Application {
// since we are not running as pid1 in this mode we must set ourselves
// as a subpreaper so that all child processes are reaped by us and not
// passed onto our parent.
set_sub_reaper()
CZ_set_sub_reaper()
#endif
signal(SIGPIPE, SIG_IGN)