Commit 8ceab588 authored by Laurent Dufour's avatar Laurent Dufour Committed by Pavel Emelyanov

crtools: no more linked with builtin syscall

crtools binary is linked with the C library and could rely on all the
services this library is providing, including system calls.

Thus it doesn't need to be linked with the builtin system calls code
made for the parasite/restorer binaries.

This patch does:
 - remove the inclusion of syscall.h
 - replace all call to sys_<syscall>() by C library <syscall>()
 - replace unwrapped system calls by syscall(SYS_<syscall>,...)
 - fix the generated compiler's issues.

There should not be any functional changes. The only 'code' changes is
appearing in locks.h when futex is called through the C library, the
errno value is fetched from errno variable instead of the return
value.
Signed-off-by: 's avatarLaurent Dufour <ldufour@linux.vnet.ibm.com>
Reviewed-by: 's avatarChristopher Covington <cov@codeaurora.org>
Reviewed-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent 34faa89b
......@@ -245,7 +245,7 @@ PROGRAM-BUILTINS += built-in.o
$(SYSCALL-LIB) $(ARCH-LIB) $(PROGRAM-BUILTINS): config
$(PROGRAM): $(SYSCALL-LIB) $(ARCH-LIB) $(PROGRAM-BUILTINS)
$(PROGRAM): $(ARCH-LIB) $(PROGRAM-BUILTINS)
$(E) " LINK " $@
$(Q) $(CC) $(CFLAGS) $^ $(LIBS) $(LDFLAGS) $(GMONLDOPT) -rdynamic -o $@
......
......@@ -12,7 +12,6 @@
#include "protobuf/core.pb-c.h"
#include "protobuf/creds.pb-c.h"
#include "parasite-syscall.h"
#include "syscall.h"
#include "log.h"
#include "util.h"
#include "cpu.h"
......
......@@ -10,7 +10,6 @@
#include "protobuf/core.pb-c.h"
#include "protobuf/creds.pb-c.h"
#include "parasite-syscall.h"
#include "syscall.h"
#include "log.h"
#include "util.h"
#include "cpu.h"
......
......@@ -2,6 +2,7 @@
#include <unistd.h>
#include <elf.h>
#include <sys/user.h>
#include <asm/unistd.h>
#include "asm/types.h"
#include "asm/fpu.h"
......@@ -11,7 +12,6 @@
#include "compiler.h"
#include "ptrace.h"
#include "parasite-syscall.h"
#include "syscall.h"
#include "log.h"
#include "util.h"
#include "cpu.h"
......
......@@ -19,6 +19,9 @@ gen_asm() {
echo "/* Autogenerated, don't edit */" > $protosout
echo "#ifndef $protosdef" >> $protosout
echo "#define $protosdef" >> $protosout
echo "#ifndef CR_NOGLIBC" >> $protosout
echo "#error This file should only be used in the parasite code" >> $protosout
echo "#endif" >> $protosout
echo "#include \"$prototypes\"" >> $protosout
echo "#include \"$codesinc\"" >> $protosout
......
......@@ -52,6 +52,9 @@ $(obj)/$(SYS-PROTO): $(obj)/syscalls/$(SYS-DEF)
$(Q) echo "/* Autogenerated, don't edit */" > $@
$(Q) echo "#ifndef __ASM_CR_SYSCALL_PROTO_H__" >> $@
$(Q) echo "#define __ASM_CR_SYSCALL_PROTO_H__" >> $@
$(Q) echo "#ifndef CR_NOGLIBC" >> $@
$(Q) echo "#error This file should only be used in the parasite code" >> $@
$(Q) echo "#endif" >> $@
$(Q) echo "#include \"syscall-codes.h\"" >> $@
$(Q) echo "#include \"syscall-types.h\"" >> $@
ifneq ($(ARCH),x86_64)
......
......@@ -14,7 +14,6 @@
#include "ptrace.h"
#include "parasite-syscall.h"
#include "restorer.h"
#include "syscall.h"
#include "log.h"
#include "util.h"
#include "cpu.h"
......
......@@ -7,7 +7,6 @@
#include "asm/prlimit.h"
#include "compiler.h"
#include "syscall.h"
#include "config.h"
#ifndef CONFIG_HAS_PRLIMIT
......
......@@ -17,13 +17,16 @@
#include <sys/ioctl.h>
#include <termios.h>
#include <sys/mman.h>
#include <netinet/in.h>
#include <sys/prctl.h>
#include <sched.h>
#include <linux/aio_abi.h>
#include "proc_parse.h"
#include "sockets.h"
#include "crtools.h"
#include "log.h"
#include "util-pie.h"
#include "syscall.h"
#include "prctl.h"
#include "files.h"
#include "sk-inet.h"
......@@ -156,7 +159,7 @@ static int check_sock_peek_off(void)
static int check_kcmp(void)
{
int ret = sys_kcmp(getpid(), -1, -1, -1, -1);
int ret = syscall(SYS_kcmp, getpid(), -1, -1, -1, -1);
if (ret != -ENOSYS)
return 0;
......@@ -173,7 +176,7 @@ static int check_prctl(void)
unsigned int size = 0;
int ret;
ret = sys_prctl(PR_GET_TID_ADDRESS, (unsigned long)&tid_addr, 0, 0, 0);
ret = prctl(PR_GET_TID_ADDRESS, (unsigned long)&tid_addr, 0, 0, 0);
if (ret) {
pr_msg("prctl: PR_GET_TID_ADDRESS is not supported");
return -1;
......@@ -182,7 +185,7 @@ static int check_prctl(void)
/*
* Either new or old interface must be supported in the kernel.
*/
ret = sys_prctl(PR_SET_MM, PR_SET_MM_MAP_SIZE, (unsigned long)&size, 0, 0);
ret = prctl(PR_SET_MM, PR_SET_MM_MAP_SIZE, (unsigned long)&size, 0, 0);
if (ret) {
if (!opts.check_ms_kernel) {
pr_msg("prctl: PR_SET_MM_MAP is not supported, which "
......@@ -191,7 +194,7 @@ static int check_prctl(void)
} else
pr_warn("Skipping unssuported PR_SET_MM_MAP\n");
ret = sys_prctl(PR_SET_MM, PR_SET_MM_BRK, sys_brk(0), 0, 0);
ret = prctl(PR_SET_MM, PR_SET_MM_BRK, brk(0), 0, 0);
if (ret) {
if (ret == -EPERM)
pr_msg("prctl: One needs CAP_SYS_RESOURCE capability to perform testing\n");
......@@ -200,13 +203,13 @@ static int check_prctl(void)
return -1;
}
ret = sys_prctl(PR_SET_MM, PR_SET_MM_EXE_FILE, -1, 0, 0);
ret = prctl(PR_SET_MM, PR_SET_MM_EXE_FILE, -1, 0, 0);
if (ret != -EBADF) {
pr_msg("prctl: PR_SET_MM_EXE_FILE is not supported (%d)\n", ret);
return -1;
}
ret = sys_prctl(PR_SET_MM, PR_SET_MM_AUXV, (long)&user_auxv, sizeof(user_auxv), 0);
ret = prctl(PR_SET_MM, PR_SET_MM_AUXV, (long)&user_auxv, sizeof(user_auxv), 0);
if (ret) {
pr_msg("prctl: PR_SET_MM_AUXV is not supported\n");
return -1;
......@@ -516,14 +519,11 @@ static int check_ipc(void)
static int check_sigqueuinfo()
{
int ret;
siginfo_t info = { .si_code = 1 };
signal(SIGUSR1, SIG_IGN);
ret = sys_rt_sigqueueinfo(getpid(), SIGUSR1, &info);
if (ret < 0) {
errno = -ret;
if (syscall(SYS_rt_sigqueueinfo, getpid(), SIGUSR1, &info)) {
pr_perror("Unable to send siginfo with positive si_code to itself");
return -1;
}
......@@ -657,7 +657,7 @@ static int setup_seccomp_filter(void)
.filter = filter,
};
if (sys_prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, (long) &bpf_prog, 0, 0) < 0)
if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, (long) &bpf_prog, 0, 0) < 0)
return -1;
return 0;
......@@ -753,7 +753,7 @@ static int check_aio_remap(void)
void *naddr;
int r;
if (sys_io_setup(16, &ctx) < 0) {
if (syscall(SYS_io_setup, 16, &ctx) < 0) {
pr_err("No AIO syscall\n");
return -1;
}
......@@ -774,7 +774,7 @@ static int check_aio_remap(void)
}
ctx = (aio_context_t)naddr;
r = sys_io_getevents(ctx, 0, 1, NULL, NULL);
r = syscall(SYS_io_getevents, ctx, 0, 1, NULL, NULL);
if (r < 0) {
if (!opts.check_ms_kernel) {
pr_err("AIO remap doesn't work properly\n");
......@@ -916,7 +916,7 @@ static int check_userns(void)
return -1;
}
ret = sys_prctl(PR_SET_MM, PR_SET_MM_MAP_SIZE, (unsigned long)&size, 0, 0);
ret = prctl(PR_SET_MM, PR_SET_MM_MAP_SIZE, (unsigned long)&size, 0, 0);
if (ret) {
errno = -ret;
pr_perror("No new prctl API");
......
......@@ -42,7 +42,6 @@
#include "cr_options.h"
#include "servicefd.h"
#include "string.h"
#include "syscall.h"
#include "ptrace.h"
#include "util.h"
#include "namespaces.h"
......@@ -522,7 +521,7 @@ static int get_task_futex_robust_list(pid_t pid, ThreadCoreEntry *info)
size_t len = 0;
int ret;
ret = sys_get_robust_list(pid, &head, &len);
ret = syscall(SYS_get_robust_list, pid, &head, &len);
if (ret == -ENOSYS) {
/*
* If the kernel says get_robust_list is not implemented, then
......@@ -535,7 +534,7 @@ static int get_task_futex_robust_list(pid_t pid, ThreadCoreEntry *info)
* implemented, in which case it will return -EINVAL because
* len should be greater than zero.
*/
if (sys_set_robust_list(NULL, 0) != -ENOSYS)
if (syscall(SYS_set_robust_list, NULL, 0) != -ENOSYS)
goto err;
head = NULL;
......
......@@ -35,7 +35,6 @@
#include "util.h"
#include "util-pie.h"
#include "log.h"
#include "syscall.h"
#include "restorer.h"
#include "sockets.h"
#include "sk-packet.h"
......@@ -746,7 +745,7 @@ static int prepare_sigactions(void)
* A pure syscall is used, because glibc
* sigaction overwrites se_restorer.
*/
ret = sys_sigaction(sig, &act, NULL, sizeof(k_rtsigset_t));
ret = syscall(SYS_rt_sigaction, sig, &act, NULL, sizeof(k_rtsigset_t));
if (ret < 0) {
errno = -ret;
pr_perror("Can't restore sigaction");
......@@ -982,7 +981,7 @@ static int restore_one_zombie(CoreEntry *core)
if (inherit_fd_fini() < 0)
return -1;
sys_prctl(PR_SET_NAME, (long)(void *)core->tc->comm, 0, 0, 0);
prctl(PR_SET_NAME, (long)(void *)core->tc->comm, 0, 0, 0);
if (task_entries != NULL) {
restore_finish_stage(CR_STATE_RESTORE);
......
......@@ -12,6 +12,7 @@
#include <sys/un.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <arpa/inet.h>
#include "crtools.h"
#include "cr_options.h"
......
......@@ -6,6 +6,7 @@
#include <getopt.h>
#include <string.h>
#include <ctype.h>
#include <sched.h>
#include <fcntl.h>
......@@ -24,7 +25,6 @@
#include "crtools.h"
#include "cr_options.h"
#include "sockets.h"
#include "syscall.h"
#include "files.h"
#include "sk-inet.h"
#include "net.h"
......
......@@ -14,7 +14,6 @@
#include "rbtree.h"
#include "kcmp-ids.h"
#include "compiler.h"
#include "syscall.h"
#include "image.h"
#include "util.h"
#include "irmap.h"
......
......@@ -9,6 +9,7 @@
#include <sys/vfs.h>
#include <sys/prctl.h>
#include <ctype.h>
#include <sched.h>
/* Stolen from kernel/fs/nfs/unlink.c */
#define SILLYNAME_PREF ".nfs"
......
......@@ -20,14 +20,13 @@
#include <sys/mount.h>
#include <aio.h>
#include <linux/fanotify.h>
#include <sys/fanotify.h>
#include "compiler.h"
#include "asm/types.h"
#include "imgset.h"
#include "fsnotify.h"
#include "proc_parse.h"
#include "syscall.h"
#include "mount.h"
#include "image.h"
#include "util.h"
......@@ -104,7 +103,7 @@ static void decode_handle(fh_t *handle, FhEntry *img)
static int open_by_handle(void *arg, int fd, int pid)
{
return sys_open_by_handle_at(fd, arg, O_PATH);
return open_by_handle_at(fd, arg, O_PATH);
}
static char *alloc_openable(unsigned int s_dev, unsigned long i_ino, FhEntry *f_handle)
......@@ -648,7 +647,7 @@ static int restore_one_fanotify(int fd, struct fsnotify_mark_info *mark)
flags |= fme->mflags;
if (mark->fme->mask) {
ret = sys_fanotify_mark(fd, flags, fme->mask, AT_FDCWD, path);
ret = fanotify_mark(fd, flags, fme->mask, AT_FDCWD, path);
if (ret) {
pr_err("Adding fanotify mask 0x%x on 0x%x/%s failed (%d)\n",
fme->mask, fme->id, path, ret);
......@@ -657,8 +656,8 @@ static int restore_one_fanotify(int fd, struct fsnotify_mark_info *mark)
}
if (fme->ignored_mask) {
ret = sys_fanotify_mark(fd, flags | FAN_MARK_IGNORED_MASK,
fme->ignored_mask, AT_FDCWD, path);
ret = fanotify_mark(fd, flags | FAN_MARK_IGNORED_MASK,
fme->ignored_mask, AT_FDCWD, path);
if (ret) {
pr_err("Adding fanotify ignored-mask 0x%x on 0x%x/%s failed (%d)\n",
fme->ignored_mask, fme->id, path, ret);
......@@ -717,7 +716,7 @@ static int open_fanotify_fd(struct file_desc *d)
if (info->ffe->flags & O_NONBLOCK)
flags |= FAN_NONBLOCK;
ret = sys_fanotify_init(flags, info->ffe->evflags);
ret = fanotify_init(flags, info->ffe->evflags);
if (ret < 0) {
errno = -ret;
pr_perror("Can't init fanotify mark (%d)", ret);
......
......@@ -8,9 +8,21 @@
#include "asm/types.h"
#include "asm/atomic.h"
#include "syscall.h"
#include "bug.h"
#ifdef CR_NOGLIBC
# include "syscall.h"
#else
# include <sys/syscall.h>
static inline long sys_futex(void *addr1, int op, int val1,
struct timespec *timeout, void *addr2, int val3)
{
int rc = syscall(SYS_futex, addr1, op, val1, timeout, addr2, val3);
if (rc == -1) rc = -errno;
return rc;
}
#endif
typedef struct {
atomic_t raw;
} futex_t;
......
......@@ -52,11 +52,14 @@ struct inet_sk_info {
extern int inet_bind(int sk, struct inet_sk_info *);
extern int inet_connect(int sk, struct inet_sk_info *);
#ifdef CR_NOGLIBC
#define setsockopt sys_setsockopt
#endif
static inline void tcp_repair_off(int fd)
{
int aux = 0, ret;
ret = sys_setsockopt(fd, SOL_TCP, TCP_REPAIR, &aux, sizeof(aux));
ret = setsockopt(fd, SOL_TCP, TCP_REPAIR, &aux, sizeof(aux));
if (ret < 0)
pr_err("Failed to turn off repair mode on socket (%d)\n", ret);
}
......
......@@ -2,6 +2,7 @@
#define __CR_SOCKETS_H__
#include <stdbool.h>
#include <sys/socket.h>
#include "asm/types.h"
......
......@@ -6,11 +6,11 @@
#include <sys/msg.h>
#include <sys/sem.h>
#include <sys/shm.h>
#include <sched.h>
#include "util.h"
#include "cr_options.h"
#include "imgset.h"
#include "syscall.h"
#include "namespaces.h"
#include "sysctl.h"
#include "ipc_ns.h"
......
#include <unistd.h>
#include <stdlib.h>
#include <sys/syscall.h>
#include "asm/types.h"
#include "rbtree.h"
#include "util.h"
#include "syscall.h"
#include "kcmp-ids.h"
/*
......@@ -92,7 +93,7 @@ static u32 kid_generate_sub(struct kid_tree *tree, struct kid_entry *e,
while (node) {
struct kid_entry *this = rb_entry(node, struct kid_entry, subtree_node);
int ret = sys_kcmp(this->elem.pid, elem->pid, tree->kcmp_type,
int ret = syscall(SYS_kcmp, this->elem.pid, elem->pid, tree->kcmp_type,
this->elem.idx, elem->idx);
parent = *new;
......@@ -103,9 +104,9 @@ static u32 kid_generate_sub(struct kid_tree *tree, struct kid_entry *e,
else if (ret == 0)
return this->subid;
else {
pr_err("kcmp failed: pid (%d %d) type %u idx (%u %u) ret %d\n",
this->elem.pid, elem->pid, tree->kcmp_type,
this->elem.idx, elem->idx, ret);
pr_perror("kcmp failed: pid (%d %d) type %u idx (%u %u)",
this->elem.pid, elem->pid, tree->kcmp_type,
this->elem.idx, elem->idx);
return 0;
}
}
......
......@@ -6,6 +6,7 @@
#include <sys/types.h>
#include <sys/mman.h>
#include <errno.h>
#include <sys/syscall.h>
#include "log.h"
#include "bug.h"
......@@ -14,7 +15,6 @@
#include "mem.h"
#include "compiler.h"
#include "sysctl.h"
#include "syscall.h"
#include "asm/types.h"
#include "cr_options.h"
#include "util.h"
......@@ -385,11 +385,11 @@ static bool kerndat_has_memfd_create(void)
{
int ret;
ret = sys_memfd_create(NULL, 0);
ret = syscall(SYS_memfd_create, NULL, 0);
if (ret == -ENOSYS)
if (ret == -1 && errno == ENOSYS)
kdat.has_memfd = false;
else if (ret == -EFAULT)
else if (ret == -1 && errno == EFAULT)
kdat.has_memfd = true;
else {
pr_err("Unexpected error %d from memfd_create(NULL, 0)\n", ret);
......
......@@ -11,6 +11,7 @@
#include <sys/mount.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sched.h>
#include "cr_options.h"
#include "asm/types.h"
......
......@@ -8,11 +8,11 @@
#include <sys/un.h>
#include <stdarg.h>
#include <signal.h>
#include <sched.h>
#include "cr-show.h"
#include "util.h"
#include "imgset.h"
#include "syscall.h"
#include "uts_ns.h"
#include "ipc_ns.h"
#include "mount.h"
......
......@@ -11,7 +11,6 @@
#include <linux/sockios.h>
#include "imgset.h"
#include "syscall-types.h"
#include "namespaces.h"
#include "net.h"
#include "libnetlink.h"
......
......@@ -13,7 +13,6 @@
#include "protobuf/pagemap.pb-c.h"
#include "imgset.h"
#include "syscall.h"
#include "ptrace.h"
#include "asm/processor-flags.h"
#include "parasite-syscall.h"
......
......@@ -12,7 +12,6 @@
#include "asm/string.h"
#include "asm/types.h"
#include "syscall.h"
#include "image.h"
#include "util-vdso.h"
#include "vma.h"
......
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/mount.h>
#include <unistd.h>
#include <errno.h>
#include "compiler.h"
#include "asm/string.h"
#include "asm/types.h"
#include "syscall.h"
#include "fcntl.h"
#include "log.h"
#include "util-pie.h"
#ifdef CR_NOGLIBC
# include "syscall.h"
# define __sys(foo) sys_##foo
#else
# define __sys(foo) foo
#endif
int open_detach_mount(char *dir)
{
int fd, ret;
fd = sys_open(dir, O_RDONLY | O_DIRECTORY, 0);
fd = __sys(open)(dir, O_RDONLY | O_DIRECTORY, 0);
if (fd < 0)
pr_err("Can't open directory %s: %d\n", dir, fd);
ret = sys_umount2(dir, MNT_DETACH);
ret = __sys(umount2)(dir, MNT_DETACH);
if (ret) {
pr_err("Can't detach mount %s: %d\n", dir, ret);
goto err_close;
}
ret = sys_rmdir(dir);
ret = __sys(rmdir)(dir);
if (ret) {
pr_err("Can't remove tmp dir %s: %d\n", dir, ret);
goto err_close;
......@@ -36,6 +42,6 @@ int open_detach_mount(char *dir)
err_close:
if (fd >= 0)
sys_close(fd);
__sys(close)(fd);
return -1;
}
#include <sys/mman.h>
#include <unistd.h>
#include <stdlib.h>
#include <sched.h>
#include "cr_options.h"
#include "pstree.h"
......@@ -17,6 +18,8 @@
struct pstree_item *root_item;
#define CLONE_ALLNS (CLONE_NEWPID | CLONE_NEWNET | CLONE_NEWIPC | CLONE_NEWUTS | CLONE_NEWNS | CLONE_NEWUSER)
void core_entry_free(CoreEntry *core)
{
if (core->tc && core->tc->timers)
......
......@@ -216,7 +216,7 @@ int get_shmem_fd(int pid, VmaEntry *vi)
flags = MAP_SHARED;
if (kdat.has_memfd) {
f = sys_memfd_create("", 0);
f = syscall(SYS_memfd_create, "", 0);
if (f < 0) {
pr_perror("Unable to create memfd");
goto err;
......
......@@ -12,6 +12,7 @@
#include "sk-packet.h"
#include "packet_diag.h"
#include "vma.h"
#include <arpa/inet.h>
#include "protobuf.h"
#include "protobuf/packet-sock.pb-c.h"
......
......@@ -5,6 +5,8 @@
#include <stdlib.h>
#include <sys/mman.h>
#include <string.h>
#include <sched.h>
#include <netinet/in.h>
#include "cr_options.h"
#include "util.h"
......
......@@ -7,6 +7,7 @@
#include <linux/if.h>
#include <linux/filter.h>
#include <string.h>
#include <netinet/in.h>
#include "libnetlink.h"
#include "sockets.h"
......
......@@ -5,6 +5,7 @@
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sched.h>
#include "asm/types.h"
#include "namespaces.h"
......
......@@ -15,7 +15,6 @@
#include "compiler.h"
#include "asm/types.h"
#include "syscall.h"
#include "files.h"
#include "cr_options.h"
#include "imgset.h"
......
......@@ -3,6 +3,7 @@
#include <linux/if.h>
#include <linux/if_tun.h>
#include <sys/ioctl.h>
#include <sched.h>
// MAO required on Centos 6 (linux-3.18.1 kernel)
#include <linux/filter.h>
......
......@@ -31,6 +31,7 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <sched.h>
#include "compiler.h"
#include "asm/types.h"
......
......@@ -2,9 +2,9 @@
#include <fcntl.h>
#include <sys/utsname.h>
#include <string.h>
#include <sched.h>
#include "util.h"
#include "syscall.h"
#include "namespaces.h"
#include "sysctl.h"
#include "uts_ns.h"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment