1 /* 2 * Copyright (c) International Business Machines Corp., 2007 3 * This program is free software; you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published by 5 * the Free Software Foundation; either version 2 of the License, or 6 * (at your option) any later version. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 11 * the GNU General Public License for more details. 12 * You should have received a copy of the GNU General Public License 13 * along with this program; if not, write to the Free Software 14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 * 16 ***************************************************************************/ 17 #ifndef __LIBCLONE_H 18 #define __LIBCLONE_H 19 20 #include <stdio.h> 21 #include <stdlib.h> 22 #include <sched.h> 23 #include <unistd.h> 24 #include <string.h> 25 #include <errno.h> 26 #include <libgen.h> 27 #include <sys/syscall.h> 28 #include <signal.h> 29 #include "linux_syscall_numbers.h" 30 #include "test.h" 31 #include "lapi/namespaces_constants.h" 32 33 #define T_UNSHARE 0 34 #define T_CLONE 1 35 #define T_NONE 2 36 37 #ifndef SYS_unshare 38 #ifdef __NR_unshare 39 #define SYS_unshare __NR_unshare 40 #elif __i386__ 41 #define SYS_unshare 310 42 #elif __ia64__ 43 #define SYS_unshare 1296 44 #elif __x86_64__ 45 #define SYS_unshare 272 46 #elif __s390x__ || __s390__ 47 #define SYS_unshare 303 48 #elif __powerpc__ 49 #define SYS_unshare 282 50 #else 51 #error "unshare not supported on this architecure." 52 #endif 53 #endif 54 55 #ifndef __NR_unshare 56 #define __NR_unshare SYS_unshare 57 #endif 58 59 /* 60 * Run fn1 in a unshared environmnent, and fn2 in the original context 61 * Fn2 may be NULL. 62 */ 63 64 int do_clone_tests(unsigned long clone_flags, 65 int(*fn1)(void *arg), void *arg1, 66 int(*fn2)(void *arg), void *arg2); 67 68 int do_unshare_tests(unsigned long clone_flags, 69 int (*fn1)(void *arg), void *arg1, 70 int (*fn2)(void *arg), void *arg2); 71 72 int do_fork_tests(int (*fn1)(void *arg), void *arg1, 73 int (*fn2)(void *arg), void *arg2); 74 75 int do_clone_unshare_test(int use_clone, unsigned long clone_flags, 76 int (*fn1)(void *arg), void *arg1); 77 78 int do_clone_unshare_tests(int use_clone, unsigned long clone_flags, 79 int (*fn1)(void *arg), void *arg1, 80 int (*fn2)(void *arg), void *arg2); 81 82 #endif 83