]>
git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/raw_syscalls.c
9 #include <sys/syscall.h>
14 #include "raw_syscalls.h"
16 int lxc_raw_execveat(int dirfd
, const char *pathname
, char *const argv
[],
17 char *const envp
[], int flags
)
20 syscall(__NR_execveat
, dirfd
, pathname
, argv
, envp
, flags
);
28 * This is based on raw_clone in systemd but adapted to our needs. This uses
29 * copy on write semantics and doesn't pass a stack. CLONE_VM is tricky and
30 * doesn't really matter to us so disallow it.
32 * The nice thing about this is that we get fork() behavior. That is
33 * lxc_raw_clone() returns 0 in the child and the child pid in the parent.
35 pid_t
lxc_raw_clone(unsigned long flags
)
39 * These flags don't interest at all so we don't jump through any hoopes
40 * of retrieving them and passing them to the kernel.
43 if ((flags
& (CLONE_VM
| CLONE_PARENT_SETTID
| CLONE_CHILD_SETTID
|
44 CLONE_CHILD_CLEARTID
| CLONE_SETTLS
)))
47 #if defined(__s390x__) || defined(__s390__) || defined(__CRIS__)
48 /* On s390/s390x and cris the order of the first and second arguments
49 * of the system call is reversed.
51 return (int)syscall(__NR_clone
, NULL
, flags
| SIGCHLD
);
52 #elif defined(__sparc__) && defined(__arch64__)
55 * sparc64 always returns the other process id in %o0, and a
56 * boolean flag whether this is the child or the parent in %o1.
57 * Inline assembly is needed to get the flag returned in %o1.
61 asm volatile("mov %2, %%g1\n\t"
67 : "=r"(in_child
), "=r"(child_pid
)
68 : "i"(__NR_clone
), "r"(flags
| SIGCHLD
)
69 : "%o1", "%o0", "%g1");
76 #elif defined(__ia64__)
77 /* On ia64 the stack and stack size are passed as separate arguments. */
78 return (int)syscall(__NR_clone
, flags
| SIGCHLD
, NULL
, prctl_arg(0));
80 return (int)syscall(__NR_clone
, flags
| SIGCHLD
, NULL
);
84 pid_t
lxc_raw_clone_cb(int (*fn
)(void *), void *args
, unsigned long flags
)
88 pid
= lxc_raw_clone(flags
);
93 * exit() is not thread-safe and might mess with the parent's signal
94 * handlers and other stuff when exec() fails.