]>
git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/raw_syscalls.h
3 * Copyright © 2018 Christian Brauner <christian.brauner@ubuntu.com>.
4 * Copyright © 2018 Canonical Ltd.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2, as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #ifndef __LXC_RAW_SYSCALL_H
21 #define __LXC_RAW_SYSCALL_H
29 #include <sys/syscall.h>
33 * lxc_raw_clone() - create a new process
36 * This function returns 0 in the child and > 0 in the parent.
39 * This function does not allocate a new stack and relies on copy-on-write
42 * - supports subset of ClONE_* flags:
43 * lxc_raw_clone() intentionally only supports a subset of the flags available
44 * to the actual system call. Please refer to the implementation what flags
45 * cannot be used. Also, please don't assume that just because a flag isn't
46 * explicitly checked for as being unsupported that it is supported. If in
47 * doubt or not sufficiently familiar with process creation in the kernel and
48 * interactions with libcs this function should be used.
50 * - no pthread_atfork() handlers:
51 * This function circumvents - as much as this this is possible - any libc
52 * wrappers and thus does not run any pthread_atfork() handlers. Make sure
53 * that this is safe to do in the context you are trying to call this
56 * - must call lxc_raw_getpid():
57 * The child must use lxc_raw_getpid() to retrieve its pid.
59 extern pid_t
lxc_raw_clone(unsigned long flags
);
62 * lxc_raw_clone_cb() - create a new process
64 * - non-fork() behavior:
65 * Function does return pid of the child or -1 on error. Pass in a callback
66 * function via the "fn" argument that gets executed in the child process.
67 * The "args" argument is passed to "fn".
69 * All other comments that apply to lxc_raw_clone() apply to lxc_raw_clone_cb()
72 extern pid_t
lxc_raw_clone_cb(int (*fn
)(void *), void *args
, unsigned long flags
);
74 extern int lxc_raw_execveat(int dirfd
, const char *pathname
, char *const argv
[],
75 char *const envp
[], int flags
);
78 * Because of older glibc's pid cache (up to 2.25) whenever clone() is called
79 * the child must must retrieve it's own pid via lxc_raw_getpid().
81 static inline pid_t
lxc_raw_getpid(void)
83 return (pid_t
)syscall(SYS_getpid
);
86 static inline pid_t
lxc_raw_gettid(void)
89 return syscall(__NR_gettid
);
91 return lxc_raw_getpid();
95 #endif /* __LXC_RAW_SYSCALL_H */