]> git.proxmox.com Git - mirror_lxc.git/blame - src/lxc/raw_syscalls.h
spelling: timeout
[mirror_lxc.git] / src / lxc / raw_syscalls.h
CommitLineData
13be2733
CB
1/* liblxcapi
2 *
3 * Copyright © 2018 Christian Brauner <christian.brauner@ubuntu.com>.
4 * Copyright © 2018 Canonical Ltd.
5 *
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.
9 *
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.
14 *
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.
18 */
19
20#ifndef __LXC_RAW_SYSCALL_H
21#define __LXC_RAW_SYSCALL_H
22
23#ifndef _GNU_SOURCE
24#define _GNU_SOURCE 1
25#endif
38e5c2db 26#include <sched.h>
13be2733
CB
27#include <stdio.h>
28#include <stdlib.h>
38e5c2db 29#include <sys/syscall.h>
d7b58715 30#include <unistd.h>
38e5c2db
CB
31
32/*
33 * lxc_raw_clone() - create a new process
34 *
35 * - fork() behavior:
36 * This function returns 0 in the child and > 0 in the parent.
37 *
38 * - copy-on-write:
39 * This function does not allocate a new stack and relies on copy-on-write
40 * semantics.
41 *
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.
49 *
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
54 * function.
55 *
56 * - must call lxc_raw_getpid():
57 * The child must use lxc_raw_getpid() to retrieve its pid.
58 */
59extern pid_t lxc_raw_clone(unsigned long flags);
60
61/*
62 * lxc_raw_clone_cb() - create a new process
63 *
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".
68 *
69 * All other comments that apply to lxc_raw_clone() apply to lxc_raw_clone_cb()
70 * as well.
71 */
72extern pid_t lxc_raw_clone_cb(int (*fn)(void *), void *args, unsigned long flags);
13be2733
CB
73
74extern int lxc_raw_execveat(int dirfd, const char *pathname, char *const argv[],
75 char *const envp[], int flags);
76
d7b58715
CB
77/*
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().
80 */
81static inline pid_t lxc_raw_getpid(void)
82{
83 return (pid_t)syscall(SYS_getpid);
84}
85
07a50156
CB
86static inline pid_t lxc_raw_gettid(void)
87{
88#ifdef __NR_gettid
89 return syscall(__NR_gettid);
90#else
91 return lxc_raw_getpid();
92#endif
93}
94
13be2733 95#endif /* __LXC_RAW_SYSCALL_H */