part of Issue#994

mcexec: open syscall moves to arch_dep
do_fork: don't use __NR_fork. use __NR_clone
vfork: moves to arch_dep
This commit is contained in:
Tomoki Shirasawa
2017-12-26 10:30:33 +09:00
parent 9a5d5feb9c
commit d209c00a30
10 changed files with 99 additions and 61 deletions

View File

@ -144,5 +144,3 @@ SYSCALL_HANDLED(1045, signalfd)
SYSCALL_DELEGATED(1049, stat)
SYSCALL_DELEGATED(1060, getpgrp)
SYSCALL_DELEGATED(1062, time)
SYSCALL_HANDLED(1071, vfork)
SYSCALL_DELEGATED(1079, fork)

View File

@ -56,7 +56,7 @@ SYSCALL_HANDLED(36, getitimer)
SYSCALL_HANDLED(38, setitimer)
SYSCALL_HANDLED(39, getpid)
SYSCALL_HANDLED(56, clone)
SYSCALL_DELEGATED(57, fork)
SYSCALL_HANDLED(57, fork)
SYSCALL_HANDLED(58, vfork)
SYSCALL_HANDLED(59, execve)
SYSCALL_HANDLED(60, exit)

View File

@ -1487,6 +1487,16 @@ SYSCALL_DECLARE(clone)
ihk_mc_syscall_sp(ctx));
}
SYSCALL_DECLARE(fork)
{
return do_fork(SIGCHLD, 0, 0, 0, 0, ihk_mc_syscall_pc(ctx), ihk_mc_syscall_sp(ctx));
}
SYSCALL_DECLARE(vfork)
{
return do_fork(CLONE_VFORK|SIGCHLD, 0, 0, 0, 0, ihk_mc_syscall_pc(ctx), ihk_mc_syscall_sp(ctx));
}
SYSCALL_DECLARE(shmget)
{
const key_t key = ihk_mc_syscall_arg0(ctx);

View File

@ -9,12 +9,15 @@ LIBS=@LIBS@
all: $(TARGET)
../../libmcexec.a: archdep.o
$(AR) cr ../../libmcexec.a archdep.o
../../libmcexec.a: archdep.o arch_syscall.o
$(AR) cr ../../libmcexec.a archdep.o arch_syscall.o
archdep.o: archdep.S
$(CC) -c -I${KDIR} $(CFLAGS) $(EXTRA_CFLAGS) -fPIE -pie -pthread $<
arch_syscall.o: arch_syscall.c
$(CC) -c -I${KDIR} $(CFLAGS) $(EXTRA_CFLAGS) -fPIE -pie -pthread $<
clean:
$(RM) $(TARGET) *.o

View File

@ -0,0 +1,7 @@
struct syscall_wait_desc;
int
archdep_syscall(struct syscall_wait_desc *w, long *ret)
{
return -1;
}

View File

@ -9,12 +9,15 @@ LIBS=@LIBS@
all: $(TARGET)
../../libmcexec.a: archdep.o
$(AR) cr ../../libmcexec.a archdep.o
../../libmcexec.a: archdep.o arch_syscall.o
$(AR) cr ../../libmcexec.a archdep.o arch_syscall.o
archdep.o: archdep.S
$(CC) -c -I${KDIR} $(CFLAGS) $(EXTRA_CFLAGS) -fPIE -pie -pthread $<
arch_syscall.o: arch_syscall.c
$(CC) -c -I${KDIR} $(CFLAGS) $(EXTRA_CFLAGS) -fPIE -pie -pthread $<
clean:
$(RM) $(TARGET) *.o

View File

@ -0,0 +1,63 @@
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <sys/resource.h>
#include <sys/syscall.h>
#include <elf.h>
#include <dirent.h>
#include "../../../include/uprotocol.h"
#include "../../archdep.h"
//#define DEBUG
#ifndef DEBUG
#define __dprint(msg, ...)
#define __dprintf(arg, ...)
#define __eprint(msg, ...)
#define __eprintf(format, ...)
#else
#define __dprint(msg, ...) {printf("%s: " msg, __FUNCTION__);fflush(stdout);}
#define __dprintf(format, ...) {printf("%s: " format, __FUNCTION__, \
__VA_ARGS__);fflush(stdout);}
#define __eprint(msg, ...) {fprintf(stderr, "%s: " msg, __FUNCTION__);\
fflush(stderr);}
#define __eprintf(format, ...) {fprintf(stderr, "%s: " format, __FUNCTION__, \
__VA_ARGS__);fflush(stderr);}
#endif
extern char *chgpath(char *, char *);
extern long do_strncpy_from_user(int, void *, void *, unsigned long);
extern int fd;
#define SET_ERR(ret) if (ret == -1) ret = -errno
int
archdep_syscall(struct syscall_wait_desc *w, long *ret)
{
char *fn;
char pathbuf[PATH_MAX];
char tmpbuf[PATH_MAX];
switch (w->sr.number) {
case __NR_open:
*ret = do_strncpy_from_user(fd, pathbuf,
(void *)w->sr.args[0], PATH_MAX);
if (*ret >= PATH_MAX) {
*ret = -ENAMETOOLONG;
}
if (ret < 0) {
return 0;
}
__dprintf("open: %s\n", pathbuf);
fn = chgpath(pathbuf, tmpbuf);
*ret = open(fn, w->sr.args[1], w->sr.args[2]);
SET_ERR(*ret);
return 0;
}
return -1;
}

View File

@ -1,3 +1,4 @@
extern int switch_ctx(int fd, unsigned long cmd, void **param, void *lctx, void *rctx);
extern unsigned long compare_and_swap(unsigned long *addr, unsigned long old, unsigned long new);
extern unsigned int compare_and_swap_int(unsigned int *addr, unsigned int old, unsigned int new);
extern int archdep_syscall(struct syscall_wait_desc *w, long *ret);

View File

@ -206,7 +206,7 @@ struct thread_data_s;
int main_loop(struct thread_data_s *);
static int mcosid;
static int fd;
int fd;
static char *exec_path = NULL;
static char *altroot;
static const char rlimit_stack_envname[] = "MCKERNEL_RLIMIT_STACK";
@ -2993,7 +2993,7 @@ out:
return rc;
}
static long do_strncpy_from_user(int fd, void *dest, void *src, unsigned long n)
long do_strncpy_from_user(int fd, void *dest, void *src, unsigned long n)
{
struct strncpy_from_user_desc desc;
int ret;
@ -3207,8 +3207,6 @@ int main_loop(struct thread_data_s *my_thread)
my_thread->remote_cpu = w.cpu;
switch (w.sr.number) {
#ifdef POSTK_DEBUG_ARCH_DEP_13 /* arch depend hide */
#ifdef __aarch64__
case __NR_openat:
/* initialize buffer */
memset(tmpbuf, '\0', sizeof(tmpbuf));
@ -3255,44 +3253,6 @@ int main_loop(struct thread_data_s *my_thread)
SET_ERR(ret);
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
break;
#else /* __aarch64__ */
case __NR_open:
ret = do_strncpy_from_user(fd, pathbuf, (void *)w.sr.args[0], PATH_MAX);
if (ret >= PATH_MAX) {
ret = -ENAMETOOLONG;
}
if (ret < 0) {
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
break;
}
__dprintf("open: %s\n", pathbuf);
fn = chgpath(pathbuf, tmpbuf);
ret = open(fn, w.sr.args[1], w.sr.args[2]);
SET_ERR(ret);
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
break;
#endif /* __aarch64__ */
#else /* POSTK_DEBUG_ARCH_DEP_13 */
case __NR_open:
ret = do_strncpy_from_user(fd, pathbuf, (void *)w.sr.args[0], PATH_MAX);
if (ret >= PATH_MAX) {
ret = -ENAMETOOLONG;
}
if (ret < 0) {
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
break;
}
__dprintf("open: %s\n", pathbuf);
fn = chgpath(pathbuf, tmpbuf);
ret = open(fn, w.sr.args[1], w.sr.args[2]);
SET_ERR(ret);
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
break;
#endif /* POSTK_DEBUG_ARCH_DEP_13 */
case __NR_futex:
ret = clock_gettime(w.sr.args[1], &tv);
@ -3413,11 +3373,7 @@ gettid_out:
break;
}
#ifdef POSTK_DEBUG_ARCH_DEP_13 /* arch depend hide */
case 1079: {
#else /* POSTK_DEBUG_ARCH_DEP_13 */
case __NR_fork: {
#endif /* POSTK_DEBUG_ARCH_DEP_13 */
case __NR_clone: {
struct fork_sync *fs;
struct fork_sync_container *fsc;
struct fork_sync_container *fp;
@ -4285,7 +4241,9 @@ return_linux_spawn:
}
default:
ret = do_generic_syscall(&w);
if (archdep_syscall(&w, &ret)) {
ret = do_generic_syscall(&w);
}
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
break;

View File

@ -2450,7 +2450,7 @@ retry_tid:
}
/* fork() a new process on the host */
else {
request1.number = __NR_fork;
request1.number = __NR_clone;
request1.args[0] = 0;
if(clone_flags & CLONE_PARENT){
if(oldproc->ppid_parent->pid != 1)
@ -2614,11 +2614,6 @@ retry_tid:
return new->tid;
}
SYSCALL_DECLARE(vfork)
{
return do_fork(CLONE_VFORK|SIGCHLD, 0, 0, 0, 0, ihk_mc_syscall_pc(ctx), ihk_mc_syscall_sp(ctx));
}
SYSCALL_DECLARE(set_tid_address)
{
cpu_local_var(current)->clear_child_tid =