summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Bentele2020-09-11 11:48:48 +0200
committerManuel Bentele2020-09-16 07:37:56 +0200
commita4215c3632c13218bb389d1f066549ab783028e3 (patch)
tree0468836ef5303f6eb94b876189ccaa60a7a2b453
parentUpdated README with documentation of general information and build options (diff)
downloadxloop-a4215c3632c13218bb389d1f066549ab783028e3.tar.gz
xloop-a4215c3632c13218bb389d1f066549ab783028e3.tar.xz
xloop-a4215c3632c13218bb389d1f066549ab783028e3.zip
Added testcases from the Linux testing project (LTP)
-rw-r--r--CMakeLists.txt2
-rw-r--r--kernel/CMakeLists.txt4
-rw-r--r--kernel/tests/CMakeLists.txt13
-rw-r--r--kernel/tests/include/config.h.in591
-rw-r--r--kernel/tests/include/ipcmsg.h68
-rw-r--r--kernel/tests/include/ipcsem.h55
-rw-r--r--kernel/tests/include/ipcshm.h54
-rw-r--r--kernel/tests/include/lapi/abisize.h31
-rw-r--r--kernel/tests/include/lapi/acct.h74
-rw-r--r--kernel/tests/include/lapi/bpf.h591
-rw-r--r--kernel/tests/include/lapi/capability.h51
-rw-r--r--kernel/tests/include/lapi/clone.h49
-rw-r--r--kernel/tests/include/lapi/common_timers.h81
-rw-r--r--kernel/tests/include/lapi/cpuset.h51
-rw-r--r--kernel/tests/include/lapi/cryptouser.h182
-rw-r--r--kernel/tests/include/lapi/dccp.h17
-rw-r--r--kernel/tests/include/lapi/epoll.h13
-rw-r--r--kernel/tests/include/lapi/execveat.h22
-rw-r--r--kernel/tests/include/lapi/fallocate.h60
-rw-r--r--kernel/tests/include/lapi/fcntl.h139
-rw-r--r--kernel/tests/include/lapi/fnmatch.h14
-rw-r--r--kernel/tests/include/lapi/fs.h66
-rw-r--r--kernel/tests/include/lapi/fsmount.h145
-rw-r--r--kernel/tests/include/lapi/futex.h13
-rw-r--r--kernel/tests/include/lapi/getrandom.h30
-rw-r--r--kernel/tests/include/lapi/if_alg.h59
-rw-r--r--kernel/tests/include/lapi/if_ether.h19
-rw-r--r--kernel/tests/include/lapi/if_packet.h50
-rw-r--r--kernel/tests/include/lapi/io_pgetevents.h35
-rw-r--r--kernel/tests/include/lapi/io_uring.h299
-rw-r--r--kernel/tests/include/lapi/ioctl.h40
-rw-r--r--kernel/tests/include/lapi/ioctl_ns.h28
-rw-r--r--kernel/tests/include/lapi/iovec.h20
-rw-r--r--kernel/tests/include/lapi/ipcbuf.h195
-rw-r--r--kernel/tests/include/lapi/keyctl.h178
-rw-r--r--kernel/tests/include/lapi/loop.h55
-rw-r--r--kernel/tests/include/lapi/membarrier.h30
-rw-r--r--kernel/tests/include/lapi/memfd.h50
-rw-r--r--kernel/tests/include/lapi/mkdirat.h20
-rw-r--r--kernel/tests/include/lapi/mlock2.h16
-rw-r--r--kernel/tests/include/lapi/mmap.h87
-rw-r--r--kernel/tests/include/lapi/mount.h33
-rw-r--r--kernel/tests/include/lapi/msg.h15
-rw-r--r--kernel/tests/include/lapi/msgbuf.h306
-rw-r--r--kernel/tests/include/lapi/namespaces_constants.h31
-rw-r--r--kernel/tests/include/lapi/netinet_in.h23
-rw-r--r--kernel/tests/include/lapi/openat2.h72
-rw-r--r--kernel/tests/include/lapi/personality.h23
-rw-r--r--kernel/tests/include/lapi/pidfd_open.h24
-rw-r--r--kernel/tests/include/lapi/pidfd_send_signal.h27
-rw-r--r--kernel/tests/include/lapi/posix_clocks.h42
-rw-r--r--kernel/tests/include/lapi/posix_types.h21
-rw-r--r--kernel/tests/include/lapi/prctl.h55
-rw-r--r--kernel/tests/include/lapi/preadv2.h30
-rw-r--r--kernel/tests/include/lapi/pwritev2.h26
-rw-r--r--kernel/tests/include/lapi/quotactl.h78
-rw-r--r--kernel/tests/include/lapi/readdir.h19
-rw-r--r--kernel/tests/include/lapi/readlinkat.h20
-rw-r--r--kernel/tests/include/lapi/renameat.h23
-rw-r--r--kernel/tests/include/lapi/rt_sigaction.h245
-rw-r--r--kernel/tests/include/lapi/safe_rt_signal.h50
-rw-r--r--kernel/tests/include/lapi/sched.h62
-rw-r--r--kernel/tests/include/lapi/sctp.h17
-rw-r--r--kernel/tests/include/lapi/seccomp.h40
-rw-r--r--kernel/tests/include/lapi/securebits.h17
-rw-r--r--kernel/tests/include/lapi/seek.h19
-rw-r--r--kernel/tests/include/lapi/sembuf.h234
-rw-r--r--kernel/tests/include/lapi/semun.h22
-rw-r--r--kernel/tests/include/lapi/setns.h20
-rw-r--r--kernel/tests/include/lapi/shm.h13
-rw-r--r--kernel/tests/include/lapi/shmbuf.h273
-rw-r--r--kernel/tests/include/lapi/signal.h24
-rw-r--r--kernel/tests/include/lapi/socket.h72
-rw-r--r--kernel/tests/include/lapi/splice.h22
-rw-r--r--kernel/tests/include/lapi/stat.h257
-rw-r--r--kernel/tests/include/lapi/sync_file_range.h58
-rw-r--r--kernel/tests/include/lapi/syncfs.h21
-rw-r--r--kernel/tests/include/lapi/syscalls.h19964
-rw-r--r--kernel/tests/include/lapi/tcp.h19
-rw-r--r--kernel/tests/include/lapi/tee.h20
-rw-r--r--kernel/tests/include/lapi/termbits.h13
-rw-r--r--kernel/tests/include/lapi/timerfd.h41
-rw-r--r--kernel/tests/include/lapi/timex.h30
-rw-r--r--kernel/tests/include/lapi/tty.h21
-rw-r--r--kernel/tests/include/lapi/udp.h18
-rw-r--r--kernel/tests/include/lapi/ustat.h22
-rw-r--r--kernel/tests/include/lapi/utime.h16
-rw-r--r--kernel/tests/include/lapi/utsname.h16
-rw-r--r--kernel/tests/include/lapi/vmsplice.h23
-rw-r--r--kernel/tests/include/lapi/xfrm.h17
-rw-r--r--kernel/tests/include/libmsgctl.h39
-rw-r--r--kernel/tests/include/libnewipc.h59
-rw-r--r--kernel/tests/include/libsigwait.h44
-rw-r--r--kernel/tests/include/old/cleanup.c47
-rw-r--r--kernel/tests/include/old/ltp_cpuid.h35
-rw-r--r--kernel/tests/include/old/ltp_priv.h74
-rw-r--r--kernel/tests/include/old/ltp_signal.h56
-rw-r--r--kernel/tests/include/old/old_checkpoint.h59
-rw-r--r--kernel/tests/include/old/old_device.h84
-rw-r--r--kernel/tests/include/old/old_module.h72
-rw-r--r--kernel/tests/include/old/old_resource.h55
-rw-r--r--kernel/tests/include/old/old_safe_file_ops.h64
-rw-r--r--kernel/tests/include/old/old_safe_net.h50
-rw-r--r--kernel/tests/include/old/old_safe_stdio.h37
-rw-r--r--kernel/tests/include/old/old_tmpdir.h56
-rw-r--r--kernel/tests/include/old/random_range.h45
-rw-r--r--kernel/tests/include/old/safe_macros.h340
-rw-r--r--kernel/tests/include/old/test.h214
-rw-r--r--kernel/tests/include/old/tlibio.h161
-rw-r--r--kernel/tests/include/old/usctest.h105
-rw-r--r--kernel/tests/include/parse_vdso.h41
-rw-r--r--kernel/tests/include/safe_file_ops_fn.h83
-rw-r--r--kernel/tests/include/safe_macros_fn.h187
-rw-r--r--kernel/tests/include/safe_net_fn.h81
-rw-r--r--kernel/tests/include/safe_stdio_fn.h35
-rw-r--r--kernel/tests/include/tst_af_alg.h168
-rw-r--r--kernel/tests/include/tst_ansi_color.h22
-rw-r--r--kernel/tests/include/tst_assert.h65
-rw-r--r--kernel/tests/include/tst_atomic.h334
-rw-r--r--kernel/tests/include/tst_buffers.h63
-rw-r--r--kernel/tests/include/tst_capability.h83
-rw-r--r--kernel/tests/include/tst_cgroup.h45
-rw-r--r--kernel/tests/include/tst_checkpoint.h28
-rw-r--r--kernel/tests/include/tst_checkpoint_fn.h42
-rw-r--r--kernel/tests/include/tst_checksum.h16
-rw-r--r--kernel/tests/include/tst_clocks.h23
-rw-r--r--kernel/tests/include/tst_clone.h21
-rw-r--r--kernel/tests/include/tst_cmd.h94
-rw-r--r--kernel/tests/include/tst_common.h86
-rw-r--r--kernel/tests/include/tst_coredump.h18
-rw-r--r--kernel/tests/include/tst_cpu.h19
-rw-r--r--kernel/tests/include/tst_crypto.h112
-rw-r--r--kernel/tests/include/tst_device.h108
-rw-r--r--kernel/tests/include/tst_fs.h246
-rw-r--r--kernel/tests/include/tst_fuzzy_sync.h776
-rw-r--r--kernel/tests/include/tst_get_bad_addr.h12
-rw-r--r--kernel/tests/include/tst_hugepage.h37
-rw-r--r--kernel/tests/include/tst_kconfig.h56
-rw-r--r--kernel/tests/include/tst_kernel.h21
-rw-r--r--kernel/tests/include/tst_kvercmp.h44
-rw-r--r--kernel/tests/include/tst_lockdown.h10
-rw-r--r--kernel/tests/include/tst_memutils.h22
-rw-r--r--kernel/tests/include/tst_minmax.h24
-rw-r--r--kernel/tests/include/tst_mkfs.h22
-rw-r--r--kernel/tests/include/tst_net.h35
-rw-r--r--kernel/tests/include/tst_netlink.h88
-rw-r--r--kernel/tests/include/tst_numa.h112
-rw-r--r--kernel/tests/include/tst_path_has_mnt_flags.h29
-rw-r--r--kernel/tests/include/tst_pid.h43
-rw-r--r--kernel/tests/include/tst_private.h32
-rw-r--r--kernel/tests/include/tst_process_state.h53
-rw-r--r--kernel/tests/include/tst_res_flags.h23
-rw-r--r--kernel/tests/include/tst_safe_clocks.h157
-rw-r--r--kernel/tests/include/tst_safe_file_ops.h49
-rw-r--r--kernel/tests/include/tst_safe_macros.h606
-rw-r--r--kernel/tests/include/tst_safe_net.h79
-rw-r--r--kernel/tests/include/tst_safe_posix_ipc.h47
-rw-r--r--kernel/tests/include/tst_safe_prw.h47
-rw-r--r--kernel/tests/include/tst_safe_pthread.h33
-rw-r--r--kernel/tests/include/tst_safe_stdio.h24
-rw-r--r--kernel/tests/include/tst_safe_sysv_ipc.h54
-rw-r--r--kernel/tests/include/tst_safe_timerfd.h32
-rw-r--r--kernel/tests/include/tst_sig_proc.h12
-rw-r--r--kernel/tests/include/tst_sys_conf.h19
-rw-r--r--kernel/tests/include/tst_taint.h98
-rw-r--r--kernel/tests/include/tst_test.h335
-rw-r--r--kernel/tests/include/tst_timer.h1055
-rw-r--r--kernel/tests/include/tst_timer_test.h45
-rw-r--r--kernel/tests/include/tst_uinput.h47
-rw-r--r--kernel/tests/include/tst_wallclock.h15
-rw-r--r--kernel/tests/lib/CMakeLists.txt69
-rw-r--r--kernel/tests/lib/cloner.c175
-rw-r--r--kernel/tests/lib/errnos.h186
-rw-r--r--kernel/tests/lib/get_path.c103
-rw-r--r--kernel/tests/lib/parse_opts.c621
-rw-r--r--kernel/tests/lib/random_range.c892
-rw-r--r--kernel/tests/lib/safe_file_ops.c422
-rw-r--r--kernel/tests/lib/safe_macros.c1109
-rw-r--r--kernel/tests/lib/safe_net.c459
-rw-r--r--kernel/tests/lib/safe_pthread.c43
-rw-r--r--kernel/tests/lib/safe_stdio.c97
-rw-r--r--kernel/tests/lib/self_exec.c225
-rw-r--r--kernel/tests/lib/signame.h106
-rw-r--r--kernel/tests/lib/tlibio.c2161
-rw-r--r--kernel/tests/lib/tst_af_alg.c212
-rw-r--r--kernel/tests/lib/tst_ansi_color.c64
-rw-r--r--kernel/tests/lib/tst_assert.c83
-rw-r--r--kernel/tests/lib/tst_buffers.c143
-rw-r--r--kernel/tests/lib/tst_capability.c90
-rw-r--r--kernel/tests/lib/tst_cgroup.c452
-rw-r--r--kernel/tests/lib/tst_checkpoint.c164
-rw-r--r--kernel/tests/lib/tst_checksum.c81
-rw-r--r--kernel/tests/lib/tst_clocks.c144
-rw-r--r--kernel/tests/lib/tst_cmd.c178
-rw-r--r--kernel/tests/lib/tst_coredump.c35
-rw-r--r--kernel/tests/lib/tst_cpu.c73
-rw-r--r--kernel/tests/lib/tst_crypto.c110
-rw-r--r--kernel/tests/lib/tst_device.c531
-rw-r--r--kernel/tests/lib/tst_dir_is_empty.c49
-rw-r--r--kernel/tests/lib/tst_fill_file.c118
-rw-r--r--kernel/tests/lib/tst_fill_fs.c68
-rw-r--r--kernel/tests/lib/tst_fs_has_free.c44
-rw-r--r--kernel/tests/lib/tst_fs_link_count.c183
-rw-r--r--kernel/tests/lib/tst_fs_setup.c49
-rw-r--r--kernel/tests/lib/tst_fs_type.c90
-rw-r--r--kernel/tests/lib/tst_get_bad_addr.c31
-rw-r--r--kernel/tests/lib/tst_hugepage.c61
-rw-r--r--kernel/tests/lib/tst_ioctl.c37
-rw-r--r--kernel/tests/lib/tst_kconfig.c285
-rw-r--r--kernel/tests/lib/tst_kernel.c100
-rw-r--r--kernel/tests/lib/tst_kvercmp.c195
-rw-r--r--kernel/tests/lib/tst_lockdown.c30
-rw-r--r--kernel/tests/lib/tst_memutils.c62
-rw-r--r--kernel/tests/lib/tst_mkfs.c117
-rw-r--r--kernel/tests/lib/tst_module.c124
-rw-r--r--kernel/tests/lib/tst_net.c221
-rw-r--r--kernel/tests/lib/tst_parse_opts.c36
-rw-r--r--kernel/tests/lib/tst_path_has_mnt_flags.c83
-rw-r--r--kernel/tests/lib/tst_pid.c64
-rw-r--r--kernel/tests/lib/tst_process_state.c86
-rw-r--r--kernel/tests/lib/tst_res.c606
-rw-r--r--kernel/tests/lib/tst_resource.c138
-rw-r--r--kernel/tests/lib/tst_safe_macros.c333
-rw-r--r--kernel/tests/lib/tst_safe_sysv_ipc.c145
-rw-r--r--kernel/tests/lib/tst_safe_timerfd.c56
-rw-r--r--kernel/tests/lib/tst_sig.c255
-rw-r--r--kernel/tests/lib/tst_sig_proc.c31
-rw-r--r--kernel/tests/lib/tst_status.c50
-rw-r--r--kernel/tests/lib/tst_supported_fs_types.c111
-rw-r--r--kernel/tests/lib/tst_sys_conf.c105
-rw-r--r--kernel/tests/lib/tst_taint.c107
-rw-r--r--kernel/tests/lib/tst_test.c1387
-rw-r--r--kernel/tests/lib/tst_timer.c59
-rw-r--r--kernel/tests/lib/tst_timer_test.c472
-rw-r--r--kernel/tests/lib/tst_tmpdir.c347
-rw-r--r--kernel/tests/lib/tst_virt.c132
-rw-r--r--kernel/tests/lib/tst_wallclock.c60
-rw-r--r--kernel/tests/testcases/kernel/syscalls/ioctl/CMakeLists.txt32
-rw-r--r--kernel/tests/testcases/kernel/syscalls/ioctl/ioctl_loop01.c155
-rw-r--r--kernel/tests/testcases/kernel/syscalls/ioctl/ioctl_loop02.c164
-rw-r--r--kernel/tests/testcases/kernel/syscalls/ioctl/ioctl_loop03.c75
-rw-r--r--kernel/tests/testcases/kernel/syscalls/ioctl/ioctl_loop04.c98
-rw-r--r--kernel/tests/testcases/kernel/syscalls/ioctl/ioctl_loop05.c155
-rw-r--r--kernel/tests/testcases/kernel/syscalls/ioctl/ioctl_loop06.c143
-rw-r--r--kernel/tests/testcases/kernel/syscalls/ioctl/ioctl_loop07.c95
-rw-r--r--utils/lib/CMakeLists.txt1
246 files changed, 50531 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 53def2a..560cb71 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -52,7 +52,7 @@ if(${CMAKE_BUILD_TYPE} MATCHES Release)
set(CPACK_SET_DESTDIR True)
set(CMAKE_INSTALL_PREFIX /usr)
# set DEB generator specific packaging options
- set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6")
+ set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc-bin")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/package/deb/postinst "depmod -a\n")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/package/deb/postrm "depmod -a\n")
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA ${CMAKE_CURRENT_BINARY_DIR}/package/deb/postinst
diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt
index 8d08c15..752a645 100644
--- a/kernel/CMakeLists.txt
+++ b/kernel/CMakeLists.txt
@@ -68,3 +68,7 @@ add_kernel_module(xloop_file_fmt_qcow "${KERNEL_DIR}"
"${KERNEL_MODULE_XLOOP_QCOW_HEADER_FILES}"
${CMAKE_CURRENT_BINARY_DIR}/Kbuild
xloop)
+
+if(${CMAKE_BUILD_TYPE} MATCHES Debug)
+ add_subdirectory(tests)
+endif()
diff --git a/kernel/tests/CMakeLists.txt b/kernel/tests/CMakeLists.txt
new file mode 100644
index 0000000..551a2fe
--- /dev/null
+++ b/kernel/tests/CMakeLists.txt
@@ -0,0 +1,13 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(xloop-kernel-test)
+
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/old)
+
+# configure configuration config.h and add it to the include directories
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+
+add_subdirectory(lib)
+add_subdirectory(testcases/kernel/syscalls/ioctl) \ No newline at end of file
diff --git a/kernel/tests/include/config.h.in b/kernel/tests/include/config.h.in
new file mode 100644
index 0000000..2d59b1c
--- /dev/null
+++ b/kernel/tests/include/config.h.in
@@ -0,0 +1,591 @@
+/* include/config.h. Generated from config.h.in by configure. */
+/* include/config.h.in. Generated from configure.ac by autoheader. */
+
+/* Define to 1 if clone() supports 7 arguments. */
+#define CLONE_SUPPORTS_7_ARGS 1
+
+/* Define to 1 if you have the <asm/ldt.h> header file. */
+#define HAVE_ASM_LDT_H 1
+
+/* Define to 1 if you have the <asm/ptrace.h> header file. */
+#define HAVE_ASM_PTRACE_H 1
+
+/* Define to 1 if you have the __atomic_* compiler builtins */
+#define HAVE_ATOMIC_MEMORY_MODEL 1
+
+/* Define to 1 if you have __builtin___clear_cache */
+#define HAVE_BUILTIN_CLEAR_CACHE 1
+
+/* Define to 1 if you have the `clnttcp_create' function. */
+/* #undef HAVE_CLNTTCP_CREATE */
+
+/* Define to 1 if you have the `clone3' function. */
+/* #undef HAVE_CLONE3 */
+
+/* Define to 1 if you have the `copy_file_range' function. */
+#define HAVE_COPY_FILE_RANGE 1
+
+/* Define to 1 if you have the `daemon' function. */
+#define HAVE_DAEMON 1
+
+/* Define to 1 if you have the declaration of `IFLA_NET_NS_PID', and to 0 if
+ you don't. */
+#define HAVE_DECL_IFLA_NET_NS_PID 1
+
+/* Define to 1 if you have the declaration of `MADV_MERGEABLE', and to 0 if
+ you don't. */
+#define HAVE_DECL_MADV_MERGEABLE 1
+
+/* Define to 1 if you have the declaration of `PR_CAPBSET_DROP', and to 0 if
+ you don't. */
+#define HAVE_DECL_PR_CAPBSET_DROP 1
+
+/* Define to 1 if you have the declaration of `PR_CAPBSET_READ', and to 0 if
+ you don't. */
+#define HAVE_DECL_PR_CAPBSET_READ 1
+
+/* Define to 1 if you have the declaration of `PTRACE_GETSIGINFO', and to 0 if
+ you don't. */
+#define HAVE_DECL_PTRACE_GETSIGINFO 1
+
+/* Define to 1 if you have the declaration of `PTRACE_O_TRACEVFORKDONE', and
+ to 0 if you don't. */
+#define HAVE_DECL_PTRACE_O_TRACEVFORKDONE 1
+
+/* Define to 1 if you have the declaration of `PTRACE_SETOPTIONS', and to 0 if
+ you don't. */
+#define HAVE_DECL_PTRACE_SETOPTIONS 1
+
+/* Define to 1 if the system has the type `enum kcmp_type'. */
+#define HAVE_ENUM_KCMP_TYPE 1
+
+/* Define to 1 if you have the `epoll_pwait' function. */
+#define HAVE_EPOLL_PWAIT 1
+
+/* Define to 1 if you have the `execveat' function. */
+/* #undef HAVE_EXECVEAT */
+
+/* Define to 1 if you have the `fallocate' function. */
+#define HAVE_FALLOCATE 1
+
+/* Define to 1 if you have the `fchownat' function. */
+#define HAVE_FCHOWNAT 1
+
+/* Define to 1 if you have the `fork' function. */
+#define HAVE_FORK 1
+
+/* Define to 1 if you have the `fsconfig' function. */
+/* #undef HAVE_FSCONFIG */
+
+/* Define to 1 if you have the `fsmount' function. */
+/* #undef HAVE_FSMOUNT */
+
+/* Define to 1 if you have the `fsopen' function. */
+/* #undef HAVE_FSOPEN */
+
+/* Define to 1 if you have the `fspick' function. */
+/* #undef HAVE_FSPICK */
+
+/* Define to 1 if you have the `fstatat' function. */
+#define HAVE_FSTATAT 1
+
+/* Define to 1 if you have the <fts.h> header file. */
+#define HAVE_FTS_H 1
+
+/* Define to 1 if you have the `getauxval' function. */
+#define HAVE_GETAUXVAL 1
+
+/* Define to 1 if you have the `getdents' function. */
+/* #undef HAVE_GETDENTS */
+
+/* Define to 1 if you have the `getdents64' function. */
+#define HAVE_GETDENTS64 1
+
+/* Define to 1 if you have the <ifaddrs.h> header file. */
+#define HAVE_IFADDRS_H 1
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#define HAVE_INTTYPES_H 1
+
+/* Define to 1 if you have the `io_pgetevents' function. */
+/* #undef HAVE_IO_PGETEVENTS */
+
+/* Define to 1 if you have `io_set_eventfd' function. */
+#define HAVE_IO_SET_EVENTFD 1
+
+/* Define to 1 if you have the `io_uring_enter' function. */
+/* #undef HAVE_IO_URING_ENTER */
+
+/* Define to 1 if you have the `io_uring_register' function. */
+/* #undef HAVE_IO_URING_REGISTER */
+
+/* Define to 1 if you have the `io_uring_setup' function. */
+/* #undef HAVE_IO_URING_SETUP */
+
+/* Define to 1 if you have the `kcmp' function. */
+/* #undef HAVE_KCMP */
+
+/* Define to 1 if you have the <keyutils.h> header file. */
+#define HAVE_KEYUTILS_H 1
+
+/* Define to 1 if you have libacl and it's headers installed */
+#define HAVE_LIBACL 1
+
+/* Define to 1 if you have libaio and it's headers installed. */
+#define HAVE_LIBAIO 1
+
+/* Define to 1 if you have the <libaio.h> header file. */
+#define HAVE_LIBAIO_H 1
+
+/* Define to 1 if you have libcap-2 installed. */
+#define HAVE_LIBCAP 1
+
+/* Define whether libcrypto and openssl headers are installed */
+#define HAVE_LIBCRYPTO 1
+
+/* Define to 1 if you have libkeyutils installed. */
+#define HAVE_LIBKEYUTILS 1
+
+/* Define to 1 if you have libmnl library and headers */
+#define HAVE_LIBMNL 1
+
+/* Define to 1 if you have both SELinux libraries and headers. */
+/* #undef HAVE_LIBSELINUX_DEVEL */
+
+/* Define to 1 if you have the <linux/can.h> header file. */
+#define HAVE_LINUX_CAN_H 1
+
+/* Define to 1 if you have the <linux/cgroupstats.h> header file. */
+#define HAVE_LINUX_CGROUPSTATS_H 1
+
+/* Define to 1 if you have the <linux/cryptouser.h> header file. */
+#define HAVE_LINUX_CRYPTOUSER_H 1
+
+/* Define to 1 if you have the <linux/dccp.h> header file. */
+#define HAVE_LINUX_DCCP_H 1
+
+/* Define to 1 if you have the <linux/fs.h> header file. */
+#define HAVE_LINUX_FS_H 1
+
+/* Define to 1 if you have the <linux/genetlink.h> header file. */
+#define HAVE_LINUX_GENETLINK_H 1
+
+/* Define to 1 if you have the <linux/if_alg.h> header file. */
+#define HAVE_LINUX_IF_ALG_H 1
+
+/* Define to 1 if you have the <linux/if_ether.h> header file. */
+#define HAVE_LINUX_IF_ETHER_H 1
+
+/* Define to 1 if you have the <linux/if_packet.h> header file. */
+#define HAVE_LINUX_IF_PACKET_H 1
+
+/* Define to 1 if you have the <linux/keyctl.h> header file. */
+#define HAVE_LINUX_KEYCTL_H 1
+
+/* Define to 1 if you have the <linux/mempolicy.h> header file. */
+#define HAVE_LINUX_MEMPOLICY_H 1
+
+/* Define to 1 if you have the <linux/module.h> header file. */
+#define HAVE_LINUX_MODULE_H 1
+
+/* Define to 1 if you have the <linux/netlink.h> header file. */
+#define HAVE_LINUX_NETLINK_H 1
+
+/* Define to 1 if you have the <linux/ptrace.h> header file. */
+#define HAVE_LINUX_PTRACE_H 1
+
+/* Define to 1 if having a valid linux/random.h */
+#define HAVE_LINUX_RANDOM_H 1
+
+/* Define to 1 if you have the <linux/seccomp.h> header file. */
+#define HAVE_LINUX_SECCOMP_H 1
+
+/* Define to 1 if you have the <linux/securebits.h> header file. */
+#define HAVE_LINUX_SECUREBITS_H 1
+
+/* Define to 1 if you have the <linux/signalfd.h> header file. */
+#define HAVE_LINUX_SIGNALFD_H 1
+
+/* Define to 1 if you have the <linux/taskstats.h> header file. */
+#define HAVE_LINUX_TASKSTATS_H 1
+
+/* Define to 1 if you have the <linux/tty.h> header file. */
+#define HAVE_LINUX_TTY_H 1
+
+/* Define to 1 if you have the <linux/types.h> header file. */
+#define HAVE_LINUX_TYPES_H 1
+
+/* Define to 1 if you have the <linux/userfaultfd.h> header file. */
+#define HAVE_LINUX_USERFAULTFD_H 1
+
+/* Define to 1 if you have the <memory.h> header file. */
+#define HAVE_MEMORY_H 1
+
+/* Define to 1 if you have the `mkdirat' function. */
+#define HAVE_MKDIRAT 1
+
+/* Define to 1 if you have the `mkdtemp' function. */
+#define HAVE_MKDTEMP 1
+
+/* Define to 1 if you have the `mknodat' function. */
+#define HAVE_MKNODAT 1
+
+/* Define to 1 if you have the `modify_ldt' function. */
+#define HAVE_MODIFY_LDT 1
+
+/* Define to 1 if you have the `move_mount' function. */
+/* #undef HAVE_MOVE_MOUNT */
+
+/* Define to 1 if you have MREMAP_FIXED in <sys/mman.h>. */
+#define HAVE_MREMAP_FIXED 1
+
+/* Define to 1 if you have the `name_to_handle_at' function. */
+#define HAVE_NAME_TO_HANDLE_AT 1
+
+/* Define to 1 if you have the <netinet/sctp.h> header file. */
+/* #undef HAVE_NETINET_SCTP_H */
+
+/* Define to 1 if you have newer libcap-2 installed. */
+#define HAVE_NEWER_LIBCAP 1
+
+/* Define to 1 if you have the <numaif.h> header file. */
+#define HAVE_NUMAIF_H 1
+
+/* Define to 1 if you have the <numa.h> header file. */
+#define HAVE_NUMA_H 1
+
+/* Define to 1 if you have libnuma and it's headers version >= 2 installed. */
+#define HAVE_NUMA_V2 1
+
+/* Define to 1 if you have the `openat' function. */
+#define HAVE_OPENAT 1
+
+/* Define to 1 if you have the `openat2' function. */
+/* #undef HAVE_OPENAT2 */
+
+/* Define to 1 if you have the <openssl/sha.h> header file. */
+#define HAVE_OPENSSL_SHA_H 1
+
+/* Define to 1 if you have the `open_tree' function. */
+/* #undef HAVE_OPEN_TREE */
+
+/* Define to 1 if you have struct perf_event_attr */
+#define HAVE_PERF_EVENT_ATTR 1
+
+/* Define to 1 if you have the `pidfd_open' function. */
+/* #undef HAVE_PIDFD_OPEN */
+
+/* Define to 1 if you have the `pidfd_send_signal' function. */
+/* #undef HAVE_PIDFD_SEND_SIGNAL */
+
+/* Define to 1 if you have the `pkey_mprotect' function. */
+#define HAVE_PKEY_MPROTECT 1
+
+/* Define to 1 if you have the `preadv' function. */
+#define HAVE_PREADV 1
+
+/* Define to 1 if you have the `preadv2' function. */
+#define HAVE_PREADV2 1
+
+/* Define to 1 if you have the `profil' function. */
+#define HAVE_PROFIL 1
+
+/* Define to 1 if you have the <pthread.h> header file. */
+#define HAVE_PTHREAD_H 1
+
+/* Define to 1 if you have the `pwritev' function. */
+#define HAVE_PWRITEV 1
+
+/* Define to 1 if you have the `pwritev2' function. */
+#define HAVE_PWRITEV2 1
+
+/* Define to 1 if you have the `readlinkat' function. */
+#define HAVE_READLINKAT 1
+
+/* Define to 1 if you have the `recvmmsg' function. */
+#define HAVE_RECVMMSG 1
+
+/* Define to 1 if you have the `renameat' function. */
+#define HAVE_RENAMEAT 1
+
+/* Define to 1 if you have the `renameat2' function. */
+#define HAVE_RENAMEAT2 1
+
+/* Define to 1 if you have the `sched_getcpu' function. */
+#define HAVE_SCHED_GETCPU 1
+
+/* Define to 1 if you have the <selinux/selinux.h> header file. */
+/* #undef HAVE_SELINUX_SELINUX_H */
+
+/* Define to 1 if you have the `sendmmsg' function. */
+#define HAVE_SENDMMSG 1
+
+/* Define to 1 if you have the `setns' function. */
+#define HAVE_SETNS 1
+
+/* Define to 1 if you have the `signalfd' function. */
+#define HAVE_SIGNALFD 1
+
+/* Define to 1 if you have the `sigpending' function. */
+#define HAVE_SIGPENDING 1
+
+/* Define to 1 if you have the `splice' function. */
+#define HAVE_SPLICE 1
+
+/* Define to 1 if you have the `statx' function. */
+#define HAVE_STATX 1
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the `stime' function. */
+/* #undef HAVE_STIME */
+
+/* Define to 1 if you have the <strings.h> header file. */
+#define HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if the system has the type `struct acct_v3'. */
+#define HAVE_STRUCT_ACCT_V3 1
+
+/* Define to 1 if the system has the type `struct af_alg_iv'. */
+#define HAVE_STRUCT_AF_ALG_IV 1
+
+/* Define to 1 if the system has the type `struct fanotify_event_info_fid'. */
+#define HAVE_STRUCT_FANOTIFY_EVENT_INFO_FID 1
+
+/* Define to 1 if `fsid.__val' is a member of `struct
+ fanotify_event_info_fid'. */
+/* #undef HAVE_STRUCT_FANOTIFY_EVENT_INFO_FID_FSID___VAL */
+
+/* Define to 1 if the system has the type `struct fanotify_event_info_header'.
+ */
+#define HAVE_STRUCT_FANOTIFY_EVENT_INFO_HEADER 1
+
+/* Define to 1 if the system has the type `struct file_dedupe_range'. */
+#define HAVE_STRUCT_FILE_DEDUPE_RANGE 1
+
+/* Define to 1 if the system has the type `struct fs_quota_statv'. */
+#define HAVE_STRUCT_FS_QUOTA_STATV 1
+
+/* Define to 1 if you have struct f_owner_ex */
+#define HAVE_STRUCT_F_OWNER_EX 1
+
+/* Define to 1 if the system has the type `struct if_nextdqblk'. */
+#define HAVE_STRUCT_IF_NEXTDQBLK 1
+
+/* Define to 1 if the system has the type `struct iovec'. */
+#define HAVE_STRUCT_IOVEC 1
+
+/* Define to 1 if the system has the type `struct ipc64_perm'. */
+/* #undef HAVE_STRUCT_IPC64_PERM */
+
+/* Define to 1 if the system has the type `struct loop_config'. */
+#define HAVE_STRUCT_LOOP_CONFIG 1
+
+/* Define to 1 if the system has the type `struct mmsghdr'. */
+#define HAVE_STRUCT_MMSGHDR 1
+
+/* Define to 1 if the system has the type `struct modify_ldt_ldt_s'. */
+/* #undef HAVE_STRUCT_MODIFY_LDT_LDT_S */
+
+/* Define to 1 if the system has the type `struct msqid64_ds'. */
+/* #undef HAVE_STRUCT_MSQID64_DS */
+
+/* Define to 1 if `aux_head' is a member of `struct perf_event_mmap_page'. */
+#define HAVE_STRUCT_PERF_EVENT_MMAP_PAGE_AUX_HEAD 1
+
+/* Define to 1 if the system has the type `struct ptrace_peeksiginfo_args'. */
+/* #undef HAVE_STRUCT_PTRACE_PEEKSIGINFO_ARGS */
+
+/* Define to 1 if the system has the type `struct pt_regs'. */
+#define HAVE_STRUCT_PT_REGS 1
+
+/* Define to 1 if the system has the type `struct rlimit64'. */
+#define HAVE_STRUCT_RLIMIT64 1
+
+/* Define to 1 if the system has the type `struct semid64_ds'. */
+/* #undef HAVE_STRUCT_SEMID64_DS */
+
+/* Define to 1 if the system has the type `struct shmid64_ds'. */
+/* #undef HAVE_STRUCT_SHMID64_DS */
+
+/* Define to 1 if `sa_sigaction' is a member of `struct sigaction'. */
+#define HAVE_STRUCT_SIGACTION_SA_SIGACTION 1
+
+/* Define to 1 if `ssi_signo' is a member of `struct signalfd_siginfo'. */
+#define HAVE_STRUCT_SIGNALFD_SIGINFO_SSI_SIGNO 1
+
+/* Define to 1 if the system has the type `struct sockaddr_alg'. */
+#define HAVE_STRUCT_SOCKADDR_ALG 1
+
+/* Define to 1 if the system has the type `struct statx'. */
+#define HAVE_STRUCT_STATX 1
+
+/* Define to 1 if the system has the type `struct statx_timestamp'. */
+#define HAVE_STRUCT_STATX_TIMESTAMP 1
+
+/* Define to 1 if `freepages_count' is a member of `struct taskstats'. */
+#define HAVE_STRUCT_TASKSTATS_FREEPAGES_COUNT 1
+
+/* Define to 1 if `nvcsw' is a member of `struct taskstats'. */
+#define HAVE_STRUCT_TASKSTATS_NVCSW 1
+
+/* Define to 1 if `read_bytes' is a member of `struct taskstats'. */
+#define HAVE_STRUCT_TASKSTATS_READ_BYTES 1
+
+/* Define to 1 if the system has the type `struct termio'. */
+#define HAVE_STRUCT_TERMIO 1
+
+/* Define to 1 if the system has the type `struct tpacket_req3'. */
+#define HAVE_STRUCT_TPACKET_REQ3 1
+
+/* Define to 1 if the system has the type `struct user_desc'. */
+#define HAVE_STRUCT_USER_DESC 1
+
+/* Define to 1 if the system has the type `struct user_regs_struct'. */
+/* #undef HAVE_STRUCT_USER_REGS_STRUCT */
+
+/* Define to 1 if `domainname' is a member of `struct utsname'. */
+#define HAVE_STRUCT_UTSNAME_DOMAINNAME 1
+
+/* Define to 1 if the system has the type `struct xt_entry_match'. */
+#define HAVE_STRUCT_XT_ENTRY_MATCH 1
+
+/* Define to 1 if the system has the type `struct xt_entry_target'. */
+#define HAVE_STRUCT_XT_ENTRY_TARGET 1
+
+/* Define to 1 if you have the `syncfs' function. */
+#define HAVE_SYNCFS 1
+
+/* Define to 1 if you have __sync_add_and_fetch */
+#define HAVE_SYNC_ADD_AND_FETCH 1
+
+/* Define to 1 if you have the `sync_file_range' function. */
+#define HAVE_SYNC_FILE_RANGE 1
+
+/* Define to 1 if you have the <sys/acl.h> header file. */
+#define HAVE_SYS_ACL_H 1
+
+/* Define to 1 if you have the <sys/capability.h> header file. */
+#define HAVE_SYS_CAPABILITY_H 1
+
+/* Define to 1 if you have the <sys/epoll.h> header file. */
+#define HAVE_SYS_EPOLL_H 1
+
+/* Define to 1 if you have the <sys/fanotify.h> header file. */
+#define HAVE_SYS_FANOTIFY_H 1
+
+/* Define to 1 if you have the <sys/inotify.h> header file. */
+#define HAVE_SYS_INOTIFY_H 1
+
+/* Define to 1 if you have the <sys/prctl.h> header file. */
+#define HAVE_SYS_PRCTL_H 1
+
+/* Define to 1 if you have the <sys/ptrace.h> header file. */
+#define HAVE_SYS_PTRACE_H 1
+
+/* Define to 1 if you have the <sys/reg.h> header file. */
+#define HAVE_SYS_REG_H 1
+
+/* Define to 1 if you have the <sys/shm.h> header file. */
+#define HAVE_SYS_SHM_H 1
+
+/* Define to 1 if you have the <sys/signalfd.h> header file. */
+#define HAVE_SYS_SIGNALFD_H 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/timerfd.h> header file. */
+#define HAVE_SYS_TIMERFD_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <sys/ustat.h> header file. */
+/* #undef HAVE_SYS_USTAT_H */
+
+/* Define to 1 if you have the <sys/utsname.h> header file. */
+#define HAVE_SYS_UTSNAME_H 1
+
+/* Define to 1 if you have the <sys/xattr.h> header file. */
+#define HAVE_SYS_XATTR_H 1
+
+/* Define to 1 if you have the `tee' function. */
+#define HAVE_TEE 1
+
+/* Define to 1 if you have the `timerfd_create' function. */
+#define HAVE_TIMERFD_CREATE 1
+
+/* Define to 1 if you have the `timerfd_gettime' function. */
+#define HAVE_TIMERFD_GETTIME 1
+
+/* Define to 1 if you have the `timerfd_settime' function. */
+#define HAVE_TIMERFD_SETTIME 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#define HAVE_UNISTD_H 1
+
+/* Define to 1 if you have the `unshare' function. */
+#define HAVE_UNSHARE 1
+
+/* Define to 1 if you have the `ustat' function. */
+/* #undef HAVE_USTAT */
+
+/* Define to 1 if you have utimensat(2) */
+#define HAVE_UTIMENSAT 1
+
+/* Define to 1 if you have the `vfork' function. */
+#define HAVE_VFORK 1
+
+/* Define to 1 if you have the `vmsplice' function. */
+#define HAVE_VMSPLICE 1
+
+/* Define to 1 if you have the `xdr_char' function. */
+/* #undef HAVE_XDR_CHAR */
+
+/* Define to 1 if you have the <xfs/xqm.h> header file. */
+#define HAVE_XFS_XQM_H 1
+
+/* Error message when no NUMA support */
+#define NUMA_ERROR_MSG "test requires libnuma >= 2 and it's development packages"
+
+/* Name of package */
+#define PACKAGE "ltp"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT "ltp@lists.linux.it"
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "ltp"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "ltp @VERSION@"
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "ltp"
+
+/* Define to the home page for this package. */
+#define PACKAGE_URL ""
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "@VERSION@"
+
+/* Define to 1 if you have the ANSI C header files. */
+#define STDC_HEADERS 1
+
+/* Target is running Linux w/out an MMU */
+/* #undef UCLINUX */
+
+/* Version number of package */
+#define VERSION "@VERSION@"
+
+/* Define to 1 if `lex' declares `yytext' as a `char *' by default, not a
+ `char[]'. */
+#define YYTEXT_POINTER 1
diff --git a/kernel/tests/include/ipcmsg.h b/kernel/tests/include/ipcmsg.h
new file mode 100644
index 0000000..d89894b
--- /dev/null
+++ b/kernel/tests/include/ipcmsg.h
@@ -0,0 +1,68 @@
+/*
+ *
+ * Copyright (c) International Business Machines Corp., 2001
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/*
+ * ipcmsg.h - common definitions for the IPC message tests.
+ */
+
+#ifndef __IPCMSG_H
+#define __IPCMSG_H 1
+
+#include <errno.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <sys/types.h>
+
+#include "test.h"
+
+void cleanup(void);
+void setup(void);
+
+#define MSG_RD 0400 /* read permission for the queue */
+#define MSG_WR 0200 /* write permission for the queue */
+#define MSG_RW MSG_RD | MSG_WR
+
+#define MSGSIZE 1024 /* a resonable size for a message */
+#define MSGTYPE 1 /* a type ID for a message */
+
+#define NR_MSGQUEUES 16 /* MSGMNI as defined in linux/msg.h */
+
+#define min(a, b) (((a) < (b)) ? (a) : (b))
+
+typedef struct mbuf { /* a generic message structure */
+ long mtype;
+ char mtext[MSGSIZE + 1]; /* add 1 here so the message can be 1024 */
+} MSGBUF; /* characters long with a '\0' termination */
+
+#ifdef LIBIPC
+key_t msgkey; /* the ftok() generated message key */
+#else
+extern key_t msgkey; /* the ftok() generated message key */
+#endif
+
+void init_buf(MSGBUF *, int, int);
+void rm_queue(int);
+
+key_t getipckey();
+int getuserid(char *);
+
+int get_max_msgqueues(void);
+int get_used_msgqueues(void);
+
+#endif /* ipcmsg.h */
diff --git a/kernel/tests/include/ipcsem.h b/kernel/tests/include/ipcsem.h
new file mode 100644
index 0000000..6a37672
--- /dev/null
+++ b/kernel/tests/include/ipcsem.h
@@ -0,0 +1,55 @@
+/*
+ *
+ * Copyright (c) International Business Machines Corp., 2001
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/*
+ * ipcsem.h - common definitions for the IPC semaphore tests
+ */
+
+#ifndef __IPCSEM_H
+#define __IPCSEM_H
+
+#include <errno.h>
+#include <sys/ipc.h>
+#include <sys/sem.h>
+
+#include "test.h"
+#include "lapi/semun.h"
+
+void cleanup(void);
+void setup(void);
+
+#define SEM_RD 0400
+#define SEM_ALT 0200
+#define SEM_RA SEM_RD | SEM_ALT
+
+#define PSEMS 10 /* a reasonable value for the number of */
+ /* "primitive semaphores" per ID */
+
+#ifdef LIBIPC
+key_t semkey; /* an IPC key generated by ftok() */
+#else
+extern key_t semkey; /* an IPC key generated by ftok() */
+#endif
+
+void rm_sema(int sem_id);
+
+int getipckey();
+int getuserid(char *);
+
+#endif /* ipcsem.h */
diff --git a/kernel/tests/include/ipcshm.h b/kernel/tests/include/ipcshm.h
new file mode 100644
index 0000000..08307d4
--- /dev/null
+++ b/kernel/tests/include/ipcshm.h
@@ -0,0 +1,54 @@
+/*
+ *
+ * Copyright (c) International Business Machines Corp., 2001
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/*
+ * ipcshm.h - common definitions for the IPC shared memory tests
+ */
+
+#ifndef __IPCSHM_H
+#define __IPCSHM_H
+
+#include <errno.h>
+#include <sys/wait.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+
+#include "test.h"
+
+void cleanup(void);
+void setup(void);
+
+#define SHM_RD 0400
+#define SHM_WR 0200
+#define SHM_RW SHM_RD | SHM_WR
+
+#define SHM_SIZE 2048 /* a resonable size for a memory segment */
+#define INT_SIZE 4 /* instead of sizeof(int) */
+
+#define MODE_MASK 0x01FF /* to get the lower nine permission bits */
+ /* from shmid_ds.ipc_perm.mode */
+
+key_t shmkey; /* an IPC key generated by ftok() */
+
+void rm_shm(int shm_id);
+
+int getipckey();
+int getuserid(char*);
+
+#endif /* ipcshm.h */
diff --git a/kernel/tests/include/lapi/abisize.h b/kernel/tests/include/lapi/abisize.h
new file mode 100644
index 0000000..9e6622c
--- /dev/null
+++ b/kernel/tests/include/lapi/abisize.h
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2014-2019 Linux Test Project
+ * Cyril Hrubis <chrubis@suse.cz>
+ * Petr Vorel <petr.vorel@gmail.com>
+ */
+
+#ifndef ABISIZE_H__
+#define ABISIZE_H__
+
+/* __WORDSIZE replacement */
+#if defined(__LP64__) || defined(_LP64)
+# define TST_ABI64
+# define TST_ABI 64
+#else
+# define TST_ABI32
+# define TST_ABI 32
+#endif
+
+/*
+ * Determines if we have to split up 64 bit arguments or not
+ *
+ * Deals with 32bit ABIs that have 64bit syscalls
+ */
+#define LTP_USE_64_ABI \
+ (defined(__mips__) && _MIPS_SIM == _ABIN32) || \
+ (defined(__x86_64__) && defined(__ILP32__)) || \
+ (defined(__aarch64__) && defined(__ILP32__)) || \
+ defined(TST_ABI64)
+
+#endif /* ABISIZE_H__ */
diff --git a/kernel/tests/include/lapi/acct.h b/kernel/tests/include/lapi/acct.h
new file mode 100644
index 0000000..c81b78b
--- /dev/null
+++ b/kernel/tests/include/lapi/acct.h
@@ -0,0 +1,74 @@
+//SPDX-License-Identifier: GPL-2.0-or-later
+
+#ifndef LAPI_ACCT_H
+#define LAPI_ACCT_H
+
+#include <sys/types.h>
+#include "config.h"
+
+#ifdef HAVE_STRUCT_ACCT_V3
+#include <sys/acct.h>
+#else
+
+#define ACCT_COMM 16
+
+typedef uint16_t comp_t;
+
+/* Fallback structures to parse the process accounting file */
+struct acct {
+ char ac_flag;
+ uint16_t ac_uid;
+ uint16_t ac_gid;
+ uint16_t ac_tty;
+ uint32_t ac_btime;
+ comp_t ac_utime;
+ comp_t ac_stime;
+ comp_t ac_etime;
+ comp_t ac_mem;
+ comp_t ac_io;
+ comp_t ac_rw;
+ comp_t ac_minflt;
+ comp_t ac_majflt;
+ comp_t ac_swaps;
+ uint32_t ac_exitcode;
+ char ac_comm[ACCT_COMM+1];
+ char ac_pad[10];
+};
+
+struct acct_v3 {
+ char ac_flag;
+ char ac_version;
+ uint16_t ac_tty;
+ uint32_t ac_exitcode;
+ uint32_t ac_uid;
+ uint32_t ac_gid;
+ uint32_t ac_pid;
+ uint32_t ac_ppid;
+ uint32_t ac_btime;
+ float ac_etime;
+ comp_t ac_utime;
+ comp_t ac_stime;
+ comp_t ac_mem;
+ comp_t ac_io;
+ comp_t ac_rw;
+ comp_t ac_minflt;
+ comp_t ac_majflt;
+ comp_t ac_swaps;
+ char ac_comm[ACCT_COMM];
+};
+
+/* Possible values for the ac_flag member */
+enum {
+ AFORK = 0x01,
+ ASU = 0x02,
+ ACORE = 0x08,
+ AXSIG = 0x10
+};
+# if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+# define ACCT_BYTEORDER 0x80
+# elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+# define ACCT_BYTEORDER 0x00
+# endif
+#endif /* HAVE_STRUCT_ACCT_V3 */
+
+#endif /* LAPI_ACCT_H */
diff --git a/kernel/tests/include/lapi/bpf.h b/kernel/tests/include/lapi/bpf.h
new file mode 100644
index 0000000..f27a921
--- /dev/null
+++ b/kernel/tests/include/lapi/bpf.h
@@ -0,0 +1,591 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Richard Palethorpe <rpalethorpe@suse.com>
+ *
+ * Essential Extended Berkeley Packet Filter (eBPF) headers
+ *
+ * Mostly copied/adapted from linux/bpf.h and libbpf so that we can perform
+ * some eBPF testing without any external dependencies.
+ */
+
+#ifndef BPF_H
+# define BPF_H
+
+#include <stdint.h>
+
+#include "lapi/syscalls.h"
+
+/* Start copy from linux/bpf_(common).h */
+#define BPF_CLASS(code) ((code) & 0x07)
+#define BPF_LD 0x00
+#define BPF_LDX 0x01
+#define BPF_ST 0x02
+#define BPF_STX 0x03
+#define BPF_ALU 0x04
+#define BPF_JMP 0x05
+
+#define BPF_JNE 0x50 /* jump != */
+
+#define BPF_SIZE(code) ((code) & 0x18)
+#define BPF_W 0x00 /* 32-bit */
+#define BPF_DW 0x18 /* double word (64-bit) */
+
+#define BPF_MODE(code) ((code) & 0xe0)
+#define BPF_IMM 0x00
+#define BPF_MEM 0x60
+
+#define BPF_OP(code) ((code) & 0xf0)
+#define BPF_ADD 0x00
+#define BPF_SUB 0x10
+#define BPF_LSH 0x60
+#define BPF_RSH 0x70
+
+#define BPF_JEQ 0x10
+
+#define BPF_SRC(code) ((code) & 0x08)
+#define BPF_K 0x00
+#define BPF_X 0x08
+
+#define BPF_ALU64 0x07 /* alu mode in double word width */
+#define BPF_MOV 0xb0 /* mov reg to reg */
+#define BPF_CALL 0x80 /* function call */
+#define BPF_EXIT 0x90 /* function return */
+
+/* Register numbers */
+enum {
+ BPF_REG_0 = 0,
+ BPF_REG_1,
+ BPF_REG_2,
+ BPF_REG_3,
+ BPF_REG_4,
+ BPF_REG_5,
+ BPF_REG_6,
+ BPF_REG_7,
+ BPF_REG_8,
+ BPF_REG_9,
+ BPF_REG_10,
+ MAX_BPF_REG,
+};
+
+struct bpf_insn {
+ uint8_t code; /* opcode */
+ uint8_t dst_reg:4; /* dest register */
+ uint8_t src_reg:4; /* source register */
+ int16_t off; /* signed offset */
+ int32_t imm; /* signed immediate constant */
+};
+
+enum bpf_cmd {
+ BPF_MAP_CREATE,
+ BPF_MAP_LOOKUP_ELEM,
+ BPF_MAP_UPDATE_ELEM,
+ BPF_MAP_DELETE_ELEM,
+ BPF_MAP_GET_NEXT_KEY,
+ BPF_PROG_LOAD,
+ BPF_OBJ_PIN,
+ BPF_OBJ_GET,
+ BPF_PROG_ATTACH,
+ BPF_PROG_DETACH,
+ BPF_PROG_TEST_RUN,
+ BPF_PROG_GET_NEXT_ID,
+ BPF_MAP_GET_NEXT_ID,
+ BPF_PROG_GET_FD_BY_ID,
+ BPF_MAP_GET_FD_BY_ID,
+ BPF_OBJ_GET_INFO_BY_FD,
+ BPF_PROG_QUERY,
+ BPF_RAW_TRACEPOINT_OPEN,
+ BPF_BTF_LOAD,
+ BPF_BTF_GET_FD_BY_ID,
+ BPF_TASK_FD_QUERY,
+ BPF_MAP_LOOKUP_AND_DELETE_ELEM,
+ BPF_MAP_FREEZE,
+};
+
+enum bpf_map_type {
+ BPF_MAP_TYPE_UNSPEC,
+ BPF_MAP_TYPE_HASH,
+ BPF_MAP_TYPE_ARRAY,
+ BPF_MAP_TYPE_PROG_ARRAY,
+ BPF_MAP_TYPE_PERF_EVENT_ARRAY,
+ BPF_MAP_TYPE_PERCPU_HASH,
+ BPF_MAP_TYPE_PERCPU_ARRAY,
+ BPF_MAP_TYPE_STACK_TRACE,
+ BPF_MAP_TYPE_CGROUP_ARRAY,
+ BPF_MAP_TYPE_LRU_HASH,
+ BPF_MAP_TYPE_LRU_PERCPU_HASH,
+ BPF_MAP_TYPE_LPM_TRIE,
+ BPF_MAP_TYPE_ARRAY_OF_MAPS,
+ BPF_MAP_TYPE_HASH_OF_MAPS,
+ BPF_MAP_TYPE_DEVMAP,
+ BPF_MAP_TYPE_SOCKMAP,
+ BPF_MAP_TYPE_CPUMAP,
+ BPF_MAP_TYPE_XSKMAP,
+ BPF_MAP_TYPE_SOCKHASH,
+ BPF_MAP_TYPE_CGROUP_STORAGE,
+ BPF_MAP_TYPE_REUSEPORT_SOCKARRAY,
+ BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE,
+ BPF_MAP_TYPE_QUEUE,
+ BPF_MAP_TYPE_STACK,
+ BPF_MAP_TYPE_SK_STORAGE,
+};
+
+enum bpf_prog_type {
+ BPF_PROG_TYPE_UNSPEC,
+ BPF_PROG_TYPE_SOCKET_FILTER,
+ BPF_PROG_TYPE_KPROBE,
+ BPF_PROG_TYPE_SCHED_CLS,
+ BPF_PROG_TYPE_SCHED_ACT,
+ BPF_PROG_TYPE_TRACEPOINT,
+ BPF_PROG_TYPE_XDP,
+ BPF_PROG_TYPE_PERF_EVENT,
+ BPF_PROG_TYPE_CGROUP_SKB,
+ BPF_PROG_TYPE_CGROUP_SOCK,
+ BPF_PROG_TYPE_LWT_IN,
+ BPF_PROG_TYPE_LWT_OUT,
+ BPF_PROG_TYPE_LWT_XMIT,
+ BPF_PROG_TYPE_SOCK_OPS,
+ BPF_PROG_TYPE_SK_SKB,
+ BPF_PROG_TYPE_CGROUP_DEVICE,
+ BPF_PROG_TYPE_SK_MSG,
+ BPF_PROG_TYPE_RAW_TRACEPOINT,
+ BPF_PROG_TYPE_CGROUP_SOCK_ADDR,
+ BPF_PROG_TYPE_LWT_SEG6LOCAL,
+ BPF_PROG_TYPE_LIRC_MODE2,
+ BPF_PROG_TYPE_SK_REUSEPORT,
+ BPF_PROG_TYPE_FLOW_DISSECTOR,
+ BPF_PROG_TYPE_CGROUP_SYSCTL,
+ BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE,
+ BPF_PROG_TYPE_CGROUP_SOCKOPT,
+};
+
+#define BPF_PSEUDO_MAP_FD 1
+
+#define BPF_OBJ_NAME_LEN 16U
+
+#define BPF_ANY 0 /* create new element or update existing */
+#define BPF_NOEXIST 1 /* create new element if it didn't exist */
+#define BPF_EXIST 2 /* update existing element */
+#define BPF_F_LOCK 4 /* spin_lock-ed map_lookup/map_update */
+
+#define aligned_uint64_t uint64_t __attribute__((aligned(8)))
+
+union bpf_attr {
+ struct { /* anonymous struct used by BPF_MAP_CREATE command */
+ uint32_t map_type; /* one of enum bpf_map_type */
+ uint32_t key_size; /* size of key in bytes */
+ uint32_t value_size; /* size of value in bytes */
+ uint32_t max_entries; /* max number of entries in a map */
+ uint32_t map_flags; /* BPF_MAP_CREATE related
+ * flags defined above.
+ */
+ uint32_t inner_map_fd; /* fd pointing to the inner map */
+ uint32_t numa_node; /* numa node (effective only if
+ * BPF_F_NUMA_NODE is set).
+ */
+ char map_name[BPF_OBJ_NAME_LEN];
+ uint32_t map_ifindex; /* ifindex of netdev to create on */
+ uint32_t btf_fd; /* fd pointing to a BTF type data */
+ uint32_t btf_key_type_id; /* BTF type_id of the key */
+ uint32_t btf_value_type_id; /* BTF type_id of the value */
+ };
+
+ struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */
+ uint32_t map_fd;
+ aligned_uint64_t key;
+ union {
+ aligned_uint64_t value;
+ aligned_uint64_t next_key;
+ };
+ uint64_t flags;
+ };
+
+ struct { /* anonymous struct used by BPF_PROG_LOAD command */
+ uint32_t prog_type; /* one of enum bpf_prog_type */
+ uint32_t insn_cnt;
+ aligned_uint64_t insns;
+ aligned_uint64_t license;
+ uint32_t log_level; /* verbosity level of verifier */
+ uint32_t log_size; /* size of user buffer */
+ aligned_uint64_t log_buf; /* user supplied buffer */
+ uint32_t kern_version; /* not used */
+ uint32_t prog_flags;
+ char prog_name[BPF_OBJ_NAME_LEN];
+ uint32_t prog_ifindex; /* ifindex of netdev to prep for */
+ /* For some prog types expected attach type must be known at
+ * load time to verify attach type specific parts of prog
+ * (context accesses, allowed helpers, etc).
+ */
+ uint32_t expected_attach_type;
+ uint32_t prog_btf_fd; /* fd pointing to BTF type data */
+ uint32_t func_info_rec_size; /* userspace bpf_func_info size */
+ aligned_uint64_t func_info; /* func info */
+ uint32_t func_info_cnt; /* number of bpf_func_info records */
+ uint32_t line_info_rec_size; /* userspace bpf_line_info size */
+ aligned_uint64_t line_info; /* line info */
+ uint32_t line_info_cnt; /* number of bpf_line_info records */
+ };
+
+ struct { /* anonymous struct used by BPF_OBJ_* commands */
+ aligned_uint64_t pathname;
+ uint32_t bpf_fd;
+ uint32_t file_flags;
+ };
+
+ struct { /* anonymous struct used by BPF_PROG_ATTACH/DETACH commands */
+ uint32_t target_fd; /* container object to attach to */
+ uint32_t attach_bpf_fd; /* eBPF program to attach */
+ uint32_t attach_type;
+ uint32_t attach_flags;
+ };
+
+ struct { /* anonymous struct used by BPF_PROG_TEST_RUN command */
+ uint32_t prog_fd;
+ uint32_t retval;
+ uint32_t data_size_in; /* input: len of data_in */
+ uint32_t data_size_out; /* input/output: len of data_out
+ * returns ENOSPC if data_out
+ * is too small.
+ */
+ aligned_uint64_t data_in;
+ aligned_uint64_t data_out;
+ uint32_t repeat;
+ uint32_t duration;
+ uint32_t ctx_size_in; /* input: len of ctx_in */
+ uint32_t ctx_size_out; /* input/output: len of ctx_out
+ * returns ENOSPC if ctx_out
+ * is too small.
+ */
+ aligned_uint64_t ctx_in;
+ aligned_uint64_t ctx_out;
+ } test;
+
+ struct { /* anonymous struct used by BPF_*_GET_*_ID */
+ union {
+ uint32_t start_id;
+ uint32_t prog_id;
+ uint32_t map_id;
+ uint32_t btf_id;
+ };
+ uint32_t next_id;
+ uint32_t open_flags;
+ };
+
+ struct { /* anonymous struct used by BPF_OBJ_GET_INFO_BY_FD */
+ uint32_t bpf_fd;
+ uint32_t info_len;
+ aligned_uint64_t info;
+ } info;
+
+ struct { /* anonymous struct used by BPF_PROG_QUERY command */
+ uint32_t target_fd; /* container object to query */
+ uint32_t attach_type;
+ uint32_t query_flags;
+ uint32_t attach_flags;
+ aligned_uint64_t prog_ids;
+ uint32_t prog_cnt;
+ } query;
+
+ struct {
+ uint64_t name;
+ uint32_t prog_fd;
+ } raw_tracepoint;
+
+ struct { /* anonymous struct for BPF_BTF_LOAD */
+ aligned_uint64_t btf;
+ aligned_uint64_t btf_log_buf;
+ uint32_t btf_size;
+ uint32_t btf_log_size;
+ uint32_t btf_log_level;
+ };
+
+ struct {
+ uint32_t pid; /* input: pid */
+ uint32_t fd; /* input: fd */
+ uint32_t flags; /* input: flags */
+ uint32_t buf_len; /* input/output: buf len */
+ aligned_uint64_t buf; /* input/output:
+ * tp_name for tracepoint
+ * symbol for kprobe
+ * filename for uprobe
+ */
+ uint32_t prog_id; /* output: prod_id */
+ uint32_t fd_type; /* output: BPF_FD_TYPE_* */
+ uint64_t probe_offset; /* output: probe_offset */
+ uint64_t probe_addr; /* output: probe_addr */
+ } task_fd_query;
+} __attribute__((aligned(8)));
+
+#define __BPF_FUNC_MAPPER(FN) \
+ FN(unspec), \
+ FN(map_lookup_elem), \
+ FN(map_update_elem), \
+ FN(map_delete_elem), \
+ FN(probe_read), \
+ FN(ktime_get_ns), \
+ FN(trace_printk), \
+ FN(get_prandom_u32), \
+ FN(get_smp_processor_id), \
+ FN(skb_store_bytes), \
+ FN(l3_csum_replace), \
+ FN(l4_csum_replace), \
+ FN(tail_call), \
+ FN(clone_redirect), \
+ FN(get_current_pid_tgid), \
+ FN(get_current_uid_gid), \
+ FN(get_current_comm), \
+ FN(get_cgroup_classid), \
+ FN(skb_vlan_push), \
+ FN(skb_vlan_pop), \
+ FN(skb_get_tunnel_key), \
+ FN(skb_set_tunnel_key), \
+ FN(perf_event_read), \
+ FN(redirect), \
+ FN(get_route_realm), \
+ FN(perf_event_output), \
+ FN(skb_load_bytes), \
+ FN(get_stackid), \
+ FN(csum_diff), \
+ FN(skb_get_tunnel_opt), \
+ FN(skb_set_tunnel_opt), \
+ FN(skb_change_proto), \
+ FN(skb_change_type), \
+ FN(skb_under_cgroup), \
+ FN(get_hash_recalc), \
+ FN(get_current_task), \
+ FN(probe_write_user), \
+ FN(current_task_under_cgroup), \
+ FN(skb_change_tail), \
+ FN(skb_pull_data), \
+ FN(csum_update), \
+ FN(set_hash_invalid), \
+ FN(get_numa_node_id), \
+ FN(skb_change_head), \
+ FN(xdp_adjust_head), \
+ FN(probe_read_str), \
+ FN(get_socket_cookie), \
+ FN(get_socket_uid), \
+ FN(set_hash), \
+ FN(setsockopt), \
+ FN(skb_adjust_room), \
+ FN(redirect_map), \
+ FN(sk_redirect_map), \
+ FN(sock_map_update), \
+ FN(xdp_adjust_meta), \
+ FN(perf_event_read_value), \
+ FN(perf_prog_read_value), \
+ FN(getsockopt), \
+ FN(override_return), \
+ FN(sock_ops_cb_flags_set), \
+ FN(msg_redirect_map), \
+ FN(msg_apply_bytes), \
+ FN(msg_cork_bytes), \
+ FN(msg_pull_data), \
+ FN(bind), \
+ FN(xdp_adjust_tail), \
+ FN(skb_get_xfrm_state), \
+ FN(get_stack), \
+ FN(skb_load_bytes_relative), \
+ FN(fib_lookup), \
+ FN(sock_hash_update), \
+ FN(msg_redirect_hash), \
+ FN(sk_redirect_hash), \
+ FN(lwt_push_encap), \
+ FN(lwt_seg6_store_bytes), \
+ FN(lwt_seg6_adjust_srh), \
+ FN(lwt_seg6_action), \
+ FN(rc_repeat), \
+ FN(rc_keydown), \
+ FN(skb_cgroup_id), \
+ FN(get_current_cgroup_id), \
+ FN(get_local_storage), \
+ FN(sk_select_reuseport), \
+ FN(skb_ancestor_cgroup_id), \
+ FN(sk_lookup_tcp), \
+ FN(sk_lookup_udp), \
+ FN(sk_release), \
+ FN(map_push_elem), \
+ FN(map_pop_elem), \
+ FN(map_peek_elem), \
+ FN(msg_push_data), \
+ FN(msg_pop_data), \
+ FN(rc_pointer_rel), \
+ FN(spin_lock), \
+ FN(spin_unlock), \
+ FN(sk_fullsock), \
+ FN(tcp_sock), \
+ FN(skb_ecn_set_ce), \
+ FN(get_listener_sock), \
+ FN(skc_lookup_tcp), \
+ FN(tcp_check_syncookie), \
+ FN(sysctl_get_name), \
+ FN(sysctl_get_current_value), \
+ FN(sysctl_get_new_value), \
+ FN(sysctl_set_new_value), \
+ FN(strtol), \
+ FN(strtoul), \
+ FN(sk_storage_get), \
+ FN(sk_storage_delete), \
+ FN(send_signal),
+
+/* integer value in 'imm' field of BPF_CALL instruction selects which helper
+ * function eBPF program intends to call
+ */
+#define __BPF_ENUM_FN(x) BPF_FUNC_ ## x
+enum bpf_func_id {
+ __BPF_FUNC_MAPPER(__BPF_ENUM_FN)
+ __BPF_FUNC_MAX_ID,
+};
+#undef __BPF_ENUM_FN
+
+/* End copy from linux/bpf.h */
+
+/* Start copy from tools/include/filter.h */
+
+#define BPF_ALU64_REG(OP, DST, SRC) \
+ ((struct bpf_insn) { \
+ .code = BPF_ALU64 | BPF_OP(OP) | BPF_X, \
+ .dst_reg = DST, \
+ .src_reg = SRC, \
+ .off = 0, \
+ .imm = 0 })
+
+#define BPF_ALU32_REG(OP, DST, SRC) \
+ ((struct bpf_insn) { \
+ .code = BPF_ALU | BPF_OP(OP) | BPF_X, \
+ .dst_reg = DST, \
+ .src_reg = SRC, \
+ .off = 0, \
+ .imm = 0 })
+
+#define BPF_ALU64_IMM(OP, DST, IMM) \
+ ((struct bpf_insn) { \
+ .code = BPF_ALU64 | BPF_OP(OP) | BPF_K, \
+ .dst_reg = DST, \
+ .src_reg = 0, \
+ .off = 0, \
+ .imm = IMM })
+
+#define BPF_ALU32_IMM(OP, DST, IMM) \
+ ((struct bpf_insn) { \
+ .code = BPF_ALU | BPF_OP(OP) | BPF_K, \
+ .dst_reg = DST, \
+ .src_reg = 0, \
+ .off = 0, \
+ .imm = IMM })
+
+#define BPF_MOV64_REG(DST, SRC) \
+ ((struct bpf_insn) { \
+ .code = BPF_ALU64 | BPF_MOV | BPF_X, \
+ .dst_reg = DST, \
+ .src_reg = SRC, \
+ .off = 0, \
+ .imm = 0 })
+
+#define BPF_MOV32_REG(DST, SRC) \
+ ((struct bpf_insn) { \
+ .code = BPF_ALU | BPF_MOV | BPF_X, \
+ .dst_reg = DST, \
+ .src_reg = SRC, \
+ .off = 0, \
+ .imm = 0 })
+
+#define BPF_LD_IMM64(DST, IMM) \
+ BPF_LD_IMM64_RAW(DST, 0, IMM)
+
+#define BPF_LD_IMM64_RAW(DST, SRC, IMM) \
+ ((struct bpf_insn) { \
+ .code = BPF_LD | BPF_DW | BPF_IMM, \
+ .dst_reg = DST, \
+ .src_reg = SRC, \
+ .off = 0, \
+ .imm = (uint32_t) (IMM) }), \
+ ((struct bpf_insn) { \
+ .code = 0, /* zero is reserved opcode */ \
+ .dst_reg = 0, \
+ .src_reg = 0, \
+ .off = 0, \
+ .imm = ((uint64_t) (IMM)) >> 32 })
+
+/* pseudo BPF_LD_IMM64 insn used to refer to process-local map_fd */
+#define BPF_LD_MAP_FD(DST, MAP_FD) \
+ BPF_LD_IMM64_RAW(DST, BPF_PSEUDO_MAP_FD, MAP_FD)
+
+#define BPF_ST_MEM(SIZE, DST, OFF, IMM) \
+ ((struct bpf_insn) { \
+ .code = BPF_ST | BPF_SIZE(SIZE) | BPF_MEM, \
+ .dst_reg = DST, \
+ .src_reg = 0, \
+ .off = OFF, \
+ .imm = IMM })
+
+#define BPF_LDX_MEM(SIZE, DST, SRC, OFF) \
+ ((struct bpf_insn) { \
+ .code = BPF_LDX | BPF_SIZE(SIZE) | BPF_MEM, \
+ .dst_reg = DST, \
+ .src_reg = SRC, \
+ .off = OFF, \
+ .imm = 0 })
+
+#define BPF_STX_MEM(SIZE, DST, SRC, OFF) \
+ ((struct bpf_insn) { \
+ .code = BPF_STX | BPF_SIZE(SIZE) | BPF_MEM, \
+ .dst_reg = DST, \
+ .src_reg = SRC, \
+ .off = OFF, \
+ .imm = 0 })
+
+#define BPF_JMP_IMM(OP, DST, IMM, OFF) \
+ ((struct bpf_insn) { \
+ .code = BPF_JMP | BPF_OP(OP) | BPF_K, \
+ .dst_reg = DST, \
+ .src_reg = 0, \
+ .off = OFF, \
+ .imm = IMM })
+
+#define BPF_MOV64_IMM(DST, IMM) \
+ ((struct bpf_insn) { \
+ .code = BPF_ALU64 | BPF_MOV | BPF_K, \
+ .dst_reg = DST, \
+ .src_reg = 0, \
+ .off = 0, \
+ .imm = IMM })
+
+#define BPF_MOV32_IMM(DST, IMM) \
+ ((struct bpf_insn) { \
+ .code = BPF_ALU | BPF_MOV | BPF_K, \
+ .dst_reg = DST, \
+ .src_reg = 0, \
+ .off = 0, \
+ .imm = IMM })
+
+#define BPF_EMIT_CALL(FUNC) \
+ ((struct bpf_insn) { \
+ .code = BPF_JMP | BPF_CALL, \
+ .dst_reg = 0, \
+ .src_reg = 0, \
+ .off = 0, \
+ .imm = ((FUNC) - BPF_FUNC_unspec) })
+
+#define BPF_EXIT_INSN() \
+ ((struct bpf_insn) { \
+ .code = BPF_JMP | BPF_EXIT, \
+ .dst_reg = 0, \
+ .src_reg = 0, \
+ .off = 0, \
+ .imm = 0 })
+
+/* End copy from tools/include/filter.h */
+
+/* Start copy from tools/lib/bpf */
+static inline uint64_t ptr_to_u64(const void *ptr)
+{
+ return (uint64_t) (unsigned long) ptr;
+}
+
+static inline int bpf(enum bpf_cmd cmd, union bpf_attr *attr, unsigned int size)
+{
+ return tst_syscall(__NR_bpf, cmd, attr, size);
+}
+/* End copy from tools/lib/bpf */
+
+#endif /* BPF_H */
diff --git a/kernel/tests/include/lapi/capability.h b/kernel/tests/include/lapi/capability.h
new file mode 100644
index 0000000..fde27ef
--- /dev/null
+++ b/kernel/tests/include/lapi/capability.h
@@ -0,0 +1,51 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (c) 2019 Richard Palethorpe <rpalethorpe@suse.com>
+ */
+
+#ifndef LAPI_CAPABILITY_H
+#define LAPI_CAPABILITY_H
+
+#include "config.h"
+
+#ifdef HAVE_SYS_CAPABILITY_H
+# include <sys/capability.h>
+/**
+ * Some old libcap-devel(1.96~2.16) define _LINUX_TYPES_H in
+ * sys/capability.h that makes ltp-lib cann't include linux/types.h
+ * essentially. Here undefine it if include such old header-file.
+ */
+# ifndef HAVE_NEWER_LIBCAP
+# undef _LINUX_TYPES_H
+# endif
+#endif
+
+#ifndef CAP_NET_RAW
+# define CAP_NET_RAW 13
+#endif
+
+#ifndef CAP_SYS_ADMIN
+# define CAP_SYS_ADMIN 21
+#endif
+
+#ifndef CAP_SYS_TIME
+# define CAP_SYS_TIME 25
+#endif
+
+#ifndef CAP_AUDIT_READ
+# define CAP_AUDIT_READ 37
+#endif
+
+#ifndef CAP_SYS_RESOURCE
+# define CAP_SYS_RESOURCE 24
+#endif
+
+#ifndef CAP_TO_INDEX
+# define CAP_TO_INDEX(x) ((x) >> 5)
+#endif
+
+#ifndef CAP_TO_MASK
+# define CAP_TO_MASK(x) (1 << ((x) & 31))
+#endif
+
+#endif
diff --git a/kernel/tests/include/lapi/clone.h b/kernel/tests/include/lapi/clone.h
new file mode 100644
index 0000000..2b8cbdb
--- /dev/null
+++ b/kernel/tests/include/lapi/clone.h
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Linaro Limited. All rights reserved.
+ * Author: Viresh Kumar <viresh.kumar@linaro.org>
+ */
+
+#ifndef LAPI_CLONE_H__
+#define LAPI_CLONE_H__
+
+#include <sys/syscall.h>
+#include <linux/types.h>
+#include <sched.h>
+
+#include "config.h"
+#include "lapi/syscalls.h"
+
+#ifndef HAVE_CLONE3
+struct clone_args {
+ uint64_t __attribute__((aligned(8))) flags;
+ uint64_t __attribute__((aligned(8))) pidfd;
+ uint64_t __attribute__((aligned(8))) child_tid;
+ uint64_t __attribute__((aligned(8))) parent_tid;
+ uint64_t __attribute__((aligned(8))) exit_signal;
+ uint64_t __attribute__((aligned(8))) stack;
+ uint64_t __attribute__((aligned(8))) stack_size;
+ uint64_t __attribute__((aligned(8))) tls;
+};
+
+int clone3(struct clone_args *args, size_t size)
+{
+ return tst_syscall(__NR_clone3, args, size);
+}
+#endif
+
+#ifndef CLONE_PIDFD
+#define CLONE_PIDFD 0x00001000 /* set if a pidfd should be placed in parent */
+#endif
+
+void clone3_supported_by_kernel(void)
+{
+ if ((tst_kvercmp(5, 3, 0)) < 0) {
+ /* Check if the syscall is backported on an older kernel */
+ TEST(syscall(__NR_clone3, NULL, 0));
+ if (TST_RET == -1 && TST_ERR == ENOSYS)
+ tst_brk(TCONF, "Test not supported on kernel version < v5.3");
+ }
+}
+
+#endif /* LAPI_CLONE_H__ */
diff --git a/kernel/tests/include/lapi/common_timers.h b/kernel/tests/include/lapi/common_timers.h
new file mode 100644
index 0000000..b783bef
--- /dev/null
+++ b/kernel/tests/include/lapi/common_timers.h
@@ -0,0 +1,81 @@
+/*
+ * File: common_timers.h
+ *
+ * Keep all the common defines/checks for the timer tests here
+ */
+
+#ifndef __COMMON_TIMERS_H__
+#define __COMMON_TIMERS_H__
+
+#include "config.h"
+#include "lapi/syscalls.h"
+#include "lapi/posix_clocks.h"
+
+#ifndef NSEC_PER_SEC
+#define NSEC_PER_SEC (1000000000L)
+#endif
+
+static const clock_t clock_list[] = {
+ CLOCK_REALTIME,
+ CLOCK_MONOTONIC,
+ CLOCK_PROCESS_CPUTIME_ID,
+ CLOCK_THREAD_CPUTIME_ID,
+ CLOCK_BOOTTIME,
+ CLOCK_BOOTTIME_ALARM,
+ CLOCK_REALTIME_ALARM,
+ CLOCK_TAI,
+};
+/* CLOCKS_DEFINED is the number of clock sources defined for sure */
+#define CLOCKS_DEFINED (sizeof(clock_list) / sizeof(*clock_list))
+/* MAX_CLOCKS is the maximum number of clock sources supported by kernel */
+#define MAX_CLOCKS 16
+
+#define CLOCK_TO_STR(def_name) \
+ case def_name: \
+ return #def_name;
+
+static inline const char *get_clock_str(const int clock_id)
+{
+ switch (clock_id) {
+ CLOCK_TO_STR(CLOCK_REALTIME);
+ CLOCK_TO_STR(CLOCK_MONOTONIC);
+ CLOCK_TO_STR(CLOCK_PROCESS_CPUTIME_ID);
+ CLOCK_TO_STR(CLOCK_THREAD_CPUTIME_ID);
+ CLOCK_TO_STR(CLOCK_BOOTTIME);
+ CLOCK_TO_STR(CLOCK_BOOTTIME_ALARM);
+ CLOCK_TO_STR(CLOCK_REALTIME_ALARM);
+ CLOCK_TO_STR(CLOCK_TAI);
+ default:
+ return "CLOCK_!?!?!?";
+ }
+}
+
+static inline int possibly_unsupported(clock_t clock)
+{
+ switch (clock) {
+ case CLOCK_BOOTTIME:
+ case CLOCK_BOOTTIME_ALARM:
+ case CLOCK_REALTIME_ALARM:
+ case CLOCK_TAI:
+ return 1;
+ default:
+ return 0;
+ }
+}
+
+static inline int have_cputime_timers(void)
+{
+ return tst_kvercmp(2, 6, 12) >= 0;
+}
+
+#include "lapi/syscalls.h"
+
+#include <time.h>
+#include <unistd.h>
+
+/* timer_t in kernel(int) is different from Glibc definition(void*).
+ * Use the kernel definition for syscall tests
+ */
+typedef int kernel_timer_t;
+
+#endif
diff --git a/kernel/tests/include/lapi/cpuset.h b/kernel/tests/include/lapi/cpuset.h
new file mode 100644
index 0000000..8f7136c
--- /dev/null
+++ b/kernel/tests/include/lapi/cpuset.h
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2014 Oracle and/or its affiliates. All Rights Reserved.
+ */
+
+/*
+ * Some old libcs (like glibc < 2.7) do not provide interfaces for
+ * dynamically sized cpu sets, but provide only static cpu_set_t type
+ * with no more than CPU_SETSIZE cpus in it.
+ *
+ * This file is a wrapper of the dynamic interfaces using the static ones.
+ *
+ * If the number of cpus available on the system is greater than
+ * CPU_SETSIZE, this interface will not work. Update libc in this case :)
+ */
+
+#define _GNU_SOURCE
+#include <sched.h>
+
+#ifndef LTP_CPUSET_H
+#define LTP_CPUSET_H
+
+#ifndef CPU_ALLOC
+#define CPU_ALLOC(ncpus) malloc(sizeof(cpu_set_t)); \
+if (ncpus > CPU_SETSIZE) { \
+ tst_brk(TCONF, \
+ "Your libc does not support masks with %ld cpus", (long)ncpus); \
+}
+#endif
+
+#ifndef CPU_FREE
+#define CPU_FREE(ptr) free(ptr)
+#endif
+
+#ifndef CPU_ALLOC_SIZE
+#define CPU_ALLOC_SIZE(size) sizeof(cpu_set_t)
+#endif
+
+#ifndef CPU_ZERO_S
+#define CPU_ZERO_S(size, mask) CPU_ZERO(mask)
+#endif
+
+#ifndef CPU_SET_S
+#define CPU_SET_S(cpu, size, mask) CPU_SET(cpu, mask)
+#endif
+
+#ifndef CPU_ISSET_S
+#define CPU_ISSET_S(cpu, size, mask) CPU_ISSET(cpu, mask)
+#endif
+
+#endif /* LTP_CPUSET_H */
diff --git a/kernel/tests/include/lapi/cryptouser.h b/kernel/tests/include/lapi/cryptouser.h
new file mode 100644
index 0000000..e92fe96
--- /dev/null
+++ b/kernel/tests/include/lapi/cryptouser.h
@@ -0,0 +1,182 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2018 Richard Palethorpe <rpalethorpe@suse.com>
+ */
+
+#ifndef CRYPTOUSER_H__
+#define CRYPTOUSER_H__
+
+#ifdef HAVE_LINUX_CRYPTOUSER_H
+# include <linux/cryptouser.h>
+#else
+# include <stdint.h>
+# define CRYPTO_MAX_NAME 64
+
+enum {
+ CRYPTO_MSG_BASE = 0x10,
+ CRYPTO_MSG_NEWALG = 0x10,
+ CRYPTO_MSG_DELALG,
+ CRYPTO_MSG_UPDATEALG,
+ CRYPTO_MSG_GETALG,
+ CRYPTO_MSG_DELRNG,
+ __CRYPTO_MSG_MAX
+};
+
+enum crypto_attr_type_t {
+ CRYPTOCFGA_UNSPEC,
+ CRYPTOCFGA_PRIORITY_VAL, /* uint32_t */
+ CRYPTOCFGA_REPORT_LARVAL, /* struct crypto_report_larval */
+ CRYPTOCFGA_REPORT_HASH, /* struct crypto_report_hash */
+ CRYPTOCFGA_REPORT_BLKCIPHER, /* struct crypto_report_blkcipher */
+ CRYPTOCFGA_REPORT_AEAD, /* struct crypto_report_aead */
+ CRYPTOCFGA_REPORT_COMPRESS, /* struct crypto_report_comp */
+ CRYPTOCFGA_REPORT_RNG, /* struct crypto_report_rng */
+ CRYPTOCFGA_REPORT_CIPHER, /* struct crypto_report_cipher */
+ CRYPTOCFGA_REPORT_AKCIPHER, /* struct crypto_report_akcipher */
+ CRYPTOCFGA_REPORT_KPP, /* struct crypto_report_kpp */
+ CRYPTOCFGA_REPORT_ACOMP, /* struct crypto_report_acomp */
+ __CRYPTOCFGA_MAX
+
+#define CRYPTOCFGA_MAX (__CRYPTOCFGA_MAX - 1)
+};
+
+struct crypto_user_alg {
+ char cru_name[CRYPTO_MAX_NAME];
+ char cru_driver_name[CRYPTO_MAX_NAME];
+ char cru_module_name[CRYPTO_MAX_NAME];
+ uint32_t cru_type;
+ uint32_t cru_mask;
+ uint32_t cru_refcnt;
+ uint32_t cru_flags;
+};
+
+struct crypto_report_larval {
+ char type[CRYPTO_MAX_NAME];
+};
+
+struct crypto_report_hash {
+ char type[CRYPTO_MAX_NAME];
+ unsigned int blocksize;
+ unsigned int digestsize;
+};
+
+struct crypto_report_cipher {
+ char type[CRYPTO_MAX_NAME];
+ unsigned int blocksize;
+ unsigned int min_keysize;
+ unsigned int max_keysize;
+};
+
+struct crypto_report_blkcipher {
+ char type[CRYPTO_MAX_NAME];
+ char geniv[CRYPTO_MAX_NAME];
+ unsigned int blocksize;
+ unsigned int min_keysize;
+ unsigned int max_keysize;
+ unsigned int ivsize;
+};
+
+struct crypto_report_aead {
+ char type[CRYPTO_MAX_NAME];
+ char geniv[CRYPTO_MAX_NAME];
+ unsigned int blocksize;
+ unsigned int maxauthsize;
+ unsigned int ivsize;
+};
+
+struct crypto_report_comp {
+ char type[CRYPTO_MAX_NAME];
+};
+
+struct crypto_report_rng {
+ char type[CRYPTO_MAX_NAME];
+ unsigned int seedsize;
+};
+
+struct crypto_report_akcipher {
+ char type[CRYPTO_MAX_NAME];
+};
+
+struct crypto_report_kpp {
+ char type[CRYPTO_MAX_NAME];
+};
+
+struct crypto_report_acomp {
+ char type[CRYPTO_MAX_NAME];
+};
+
+#endif /* HAVE_LINUX_CRYPTOUSER_H */
+
+/* These are taken from include/crypto.h in the kernel tree. They are not
+ * currently included in the user API.
+ */
+#ifndef CRYPTO_MAX_ALG_NAME
+# define CRYPTO_MAX_ALG_NAME 128
+#endif
+
+#ifndef CRYPTO_ALG_TYPE_MASK
+# define CRYPTO_ALG_TYPE_MASK 0x0000000f
+#endif
+#ifndef CRYPTO_ALG_TYPE_CIPHER
+# define CRYPTO_ALG_TYPE_CIPHER 0x00000001
+#endif
+#ifndef CRYPTO_ALG_TYPE_COMPRESS
+# define CRYPTO_ALG_TYPE_COMPRESS 0x00000002
+#endif
+#ifndef CRYPTO_ALG_TYPE_AEAD
+# define CRYPTO_ALG_TYPE_AEAD 0x00000003
+#endif
+#ifndef CRYPTO_ALG_TYPE_BLKCIPHER
+# define CRYPTO_ALG_TYPE_BLKCIPHER 0x00000004
+#endif
+#ifndef CRYPTO_ALG_TYPE_ABLKCIPHER
+# define CRYPTO_ALG_TYPE_ABLKCIPHER 0x00000005
+#endif
+#ifndef CRYPTO_ALG_TYPE_SKCIPHER
+# define CRYPTO_ALG_TYPE_SKCIPHER 0x00000005
+#endif
+#ifndef CRYPTO_ALG_TYPE_GIVCIPHER
+# define CRYPTO_ALG_TYPE_GIVCIPHER 0x00000006
+#endif
+#ifndef CRYPTO_ALG_TYPE_KPP
+# define CRYPTO_ALG_TYPE_KPP 0x00000008
+#endif
+#ifndef CRYPTO_ALG_TYPE_ACOMPRESS
+# define CRYPTO_ALG_TYPE_ACOMPRESS 0x0000000a
+#endif
+#ifndef CRYPTO_ALG_TYPE_SCOMPRESS
+# define CRYPTO_ALG_TYPE_SCOMPRESS 0x0000000b
+#endif
+#ifndef CRYPTO_ALG_TYPE_RNG
+# define CRYPTO_ALG_TYPE_RNG 0x0000000c
+#endif
+#ifndef CRYPTO_ALG_TYPE_AKCIPHER
+# define CRYPTO_ALG_TYPE_AKCIPHER 0x0000000d
+#endif
+#ifndef CRYPTO_ALG_TYPE_DIGEST
+# define CRYPTO_ALG_TYPE_DIGEST 0x0000000e
+#endif
+#ifndef CRYPTO_ALG_TYPE_HASH
+# define CRYPTO_ALG_TYPE_HASH 0x0000000e
+#endif
+#ifndef CRYPTO_ALG_TYPE_SHASH
+# define CRYPTO_ALG_TYPE_SHASH 0x0000000e
+#endif
+#ifndef CRYPTO_ALG_TYPE_AHASH
+# define CRYPTO_ALG_TYPE_AHASH 0x0000000f
+#endif
+
+#ifndef CRYPTO_ALG_TYPE_HASH_MASK
+# define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e
+#endif
+#ifndef CRYPTO_ALG_TYPE_AHASH_MASK
+# define CRYPTO_ALG_TYPE_AHASH_MASK 0x0000000e
+#endif
+#ifndef CRYPTO_ALG_TYPE_BLKCIPHER_MASK
+# define CRYPTO_ALG_TYPE_BLKCIPHER_MASK 0x0000000c
+#endif
+#ifndef CRYPTO_ALG_TYPE_ACOMPRESS_MASK
+# define CRYPTO_ALG_TYPE_ACOMPRESS_MASK 0x0000000e
+#endif
+
+#endif /* CRYPTOUSER_H__ */
diff --git a/kernel/tests/include/lapi/dccp.h b/kernel/tests/include/lapi/dccp.h
new file mode 100644
index 0000000..a0f0148
--- /dev/null
+++ b/kernel/tests/include/lapi/dccp.h
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
+ */
+
+#ifndef LAPI_DCCP_H__
+#define LAPI_DCCP_H__
+
+#ifdef HAVE_LINUX_DCCP_H
+# include <linux/dccp.h>
+#endif
+
+#ifndef DCCP_SOCKOPT_SERVICE
+# define DCCP_SOCKOPT_SERVICE 2
+#endif
+
+#endif /* LAPI_DCCP_H__ */
diff --git a/kernel/tests/include/lapi/epoll.h b/kernel/tests/include/lapi/epoll.h
new file mode 100644
index 0000000..899eeb9
--- /dev/null
+++ b/kernel/tests/include/lapi/epoll.h
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#ifndef LAPI_EPOLL_H__
+#define LAPI_EPOLL_H__
+
+#ifndef EPOLL_CLOEXEC
+# define EPOLL_CLOEXEC 02000000
+#endif
+
+#endif /* LAPI_EPOLL_H__ */
diff --git a/kernel/tests/include/lapi/execveat.h b/kernel/tests/include/lapi/execveat.h
new file mode 100644
index 0000000..a7406f7
--- /dev/null
+++ b/kernel/tests/include/lapi/execveat.h
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2018 MediaTek Inc. All Rights Reserved.
+ */
+
+#ifndef EXECVEAT_H
+#define EXECVEAT_H
+
+#include <sys/types.h>
+#include "config.h"
+#include "lapi/syscalls.h"
+
+#if !defined(HAVE_EXECVEAT)
+int execveat(int dirfd, const char *pathname,
+ char *const argv[], char *const envp[],
+ int flags)
+{
+ return tst_syscall(__NR_execveat, dirfd, pathname, argv, envp, flags);
+}
+#endif
+
+#endif /* EXECVEAT_H */
diff --git a/kernel/tests/include/lapi/fallocate.h b/kernel/tests/include/lapi/fallocate.h
new file mode 100644
index 0000000..72f52c7
--- /dev/null
+++ b/kernel/tests/include/lapi/fallocate.h
@@ -0,0 +1,60 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) International Business Machines Corp., 2007
+ * Copyright (c) 2014 Fujitsu Ltd.
+ */
+
+#ifndef FALLOCATE_H
+#define FALLOCATE_H
+
+#include <sys/types.h>
+#include <endian.h>
+#include "config.h"
+#include "lapi/abisize.h"
+#include "lapi/seek.h"
+#include "lapi/syscalls.h"
+
+#ifndef FALLOC_FL_KEEP_SIZE
+# define FALLOC_FL_KEEP_SIZE 0x01
+#endif
+
+#ifndef FALLOC_FL_PUNCH_HOLE
+# define FALLOC_FL_PUNCH_HOLE 0x02
+#endif
+
+#ifndef FALLOC_FL_COLLAPSE_RANGE
+# define FALLOC_FL_COLLAPSE_RANGE 0x08
+#endif
+
+#ifndef FALLOC_FL_ZERO_RANGE
+# define FALLOC_FL_ZERO_RANGE 0x10
+#endif
+
+#ifndef FALLOC_FL_INSERT_RANGE
+# define FALLOC_FL_INSERT_RANGE 0x20
+#endif
+
+#if !defined(HAVE_FALLOCATE)
+
+# ifdef __TEST_H__
+# define TST_SYSCALL_WRAPPER ltp_syscall
+# else
+# define TST_SYSCALL_WRAPPER tst_syscall
+# endif /* __TEST_H__ */
+
+static inline long fallocate(int fd, int mode, loff_t offset, loff_t len)
+{
+ /* Deal with 32bit ABIs that have 64bit syscalls. */
+# if LTP_USE_64_ABI
+ return TST_SYSCALL_WRAPPER(__NR_fallocate, fd, mode, offset, len);
+# else
+ return (long)TST_SYSCALL_WRAPPER(__NR_fallocate, fd, mode,
+ __LONG_LONG_PAIR((off_t) (offset >> 32),
+ (off_t) offset),
+ __LONG_LONG_PAIR((off_t) (len >> 32),
+ (off_t) len));
+# endif
+}
+#endif
+
+#endif /* FALLOCATE_H */
diff --git a/kernel/tests/include/lapi/fcntl.h b/kernel/tests/include/lapi/fcntl.h
new file mode 100644
index 0000000..576a18d
--- /dev/null
+++ b/kernel/tests/include/lapi/fcntl.h
@@ -0,0 +1,139 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2014 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#ifndef __LAPI_FCNTL_H__
+#define __LAPI_FCNTL_H__
+
+#include <fcntl.h>
+#include <sys/socket.h>
+
+#ifndef O_DIRECT
+# define O_DIRECT 040000
+#endif
+
+#ifndef O_CLOEXEC
+# define O_CLOEXEC 02000000
+#endif
+
+#ifndef SOCK_CLOEXEC
+# define SOCK_CLOEXEC O_CLOEXEC
+#endif
+
+#ifndef SOCK_NONBLOCK
+# define SOCK_NONBLOCK O_NONBLOCK
+#endif
+
+#ifndef O_TMPFILE
+# define O_TMPFILE (020000000 | O_DIRECTORY)
+#endif
+
+#ifndef F_DUPFD_CLOEXEC
+# define F_DUPFD_CLOEXEC 1030
+#endif
+
+#ifndef F_SETPIPE_SZ
+# define F_SETPIPE_SZ 1031
+#endif
+
+#ifndef F_GETPIPE_SZ
+# define F_GETPIPE_SZ 1032
+#endif
+
+/*
+ * Set/Get seals
+ */
+#ifndef F_ADD_SEALS
+# define F_ADD_SEALS (1033)
+#endif
+
+#ifndef F_GET_SEALS
+# define F_GET_SEALS (1034)
+#endif
+
+#ifndef F_SEAL_SEAL
+# define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */
+#endif
+
+#ifndef F_SEAL_SHRINK
+# define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */
+#endif
+#ifndef F_SEAL_GROW
+# define F_SEAL_GROW 0x0004 /* prevent file from growing */
+#endif
+#ifndef F_SEAL_WRITE
+# define F_SEAL_WRITE 0x0008 /* prevent writes */
+#endif
+
+#ifndef F_OWNER_PGRP
+# define F_OWNER_PGRP 2
+#endif
+
+#ifndef F_OFD_GETLK
+# define F_OFD_GETLK 36
+#endif
+
+#ifndef F_OFD_SETLK
+# define F_OFD_SETLK 37
+#endif
+
+#ifndef F_OFD_SETLKW
+# define F_OFD_SETLKW 38
+#endif
+
+#ifndef AT_FDCWD
+# define AT_FDCWD -100
+#endif
+
+#ifndef AT_SYMLINK_FOLLOW
+# define AT_SYMLINK_FOLLOW 0x400
+#endif
+
+#ifndef AT_SYMLINK_NOFOLLOW
+# define AT_SYMLINK_NOFOLLOW 0x100
+#endif
+
+#ifndef AT_EMPTY_PATH
+# define AT_EMPTY_PATH 0x1000
+#endif
+
+#ifndef AT_REMOVEDIR
+# define AT_REMOVEDIR 0x200
+#endif
+
+#ifndef O_NOATIME
+# define O_NOATIME 01000000
+#endif
+
+#ifndef O_PATH
+# ifdef __sparc__
+# define O_PATH 0x1000000
+# else
+# define O_PATH 010000000
+# endif
+#endif
+
+#ifndef FALLOC_FL_KEEP_SIZE
+# define FALLOC_FL_KEEP_SIZE 1
+#endif
+
+#ifndef RENAME_NOREPLACE
+# define RENAME_NOREPLACE (1 << 0)
+#endif
+
+#ifndef RENAME_EXCHANGE
+# define RENAME_EXCHANGE (1 << 1)
+#endif
+
+#ifndef RENAME_WHITEOUT
+# define RENAME_WHITEOUT (1 << 2)
+#endif
+
+/* splice, vmsplice, tee */
+
+#ifndef SPLICE_F_NONBLOCK
+# define SPLICE_F_NONBLOCK 2
+#endif
+
+#endif /* __LAPI_FCNTL_H__ */
diff --git a/kernel/tests/include/lapi/fnmatch.h b/kernel/tests/include/lapi/fnmatch.h
new file mode 100644
index 0000000..9628ac4
--- /dev/null
+++ b/kernel/tests/include/lapi/fnmatch.h
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2018 Linaro Limited. All rights reserved.
+ * Author: Rafael David Tinoco <rafael.tinoco@linaro.org>
+ */
+
+#ifndef FNMATCH_H__
+#define FNMATCH_H__
+
+#ifndef FNM_EXTMATCH
+#define FNM_EXTMATCH 0
+#endif
+
+#endif
diff --git a/kernel/tests/include/lapi/fs.h b/kernel/tests/include/lapi/fs.h
new file mode 100644
index 0000000..430d21f
--- /dev/null
+++ b/kernel/tests/include/lapi/fs.h
@@ -0,0 +1,66 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Referred from linux kernel include/uapi/linux/fs.h
+ * Copyright (c) 2019 Petr Vorel <pvorel@suse.cz>
+ * Copyright (c) Zilogic Systems Pvt. Ltd., 2018
+ * Email: code@zilogic.com
+ */
+
+#ifdef HAVE_LINUX_FS_H
+# include <linux/fs.h>
+#endif
+
+#include <sys/user.h>
+#include <limits.h>
+#include "lapi/abisize.h"
+
+#ifndef LAPI_FS_H
+#define LAPI_FS_H
+
+#ifndef FS_IOC_GETFLAGS
+#define FS_IOC_GETFLAGS _IOR('f', 1, long)
+#endif
+
+#ifndef FS_IOC_SETFLAGS
+#define FS_IOC_SETFLAGS _IOW('f', 2, long)
+#endif
+
+#ifndef FS_COMPR_FL
+#define FS_COMPR_FL 0x00000004 /* Compress file */
+#endif
+
+#ifndef FS_IMMUTABLE_FL
+#define FS_IMMUTABLE_FL 0x00000010 /* Immutable file */
+#endif
+
+#ifndef FS_APPEND_FL
+#define FS_APPEND_FL 0x00000020 /* writes to file may only append */
+#endif
+
+#ifndef FS_NODUMP_FL
+#define FS_NODUMP_FL 0x00000040 /* do not dump file */
+#endif
+
+/*
+ * Helper function to get MAX_LFS_FILESIZE.
+ * Missing PAGE_SHIFT on some libc prevents defining MAX_LFS_FILESIZE.
+ *
+ * 64 bit: macro taken from kernel from include/linux/fs.h
+ * 32 bit: own implementation
+ */
+static inline loff_t tst_max_lfs_filesize(void)
+{
+#ifdef TST_ABI64
+ return (loff_t)LLONG_MAX;
+#else
+ long page_size = getpagesize();
+ loff_t ret = ULONG_MAX;
+
+ while (page_size >>= 1)
+ ret <<= 1;
+
+ return ret;
+#endif
+}
+
+#endif
diff --git a/kernel/tests/include/lapi/fsmount.h b/kernel/tests/include/lapi/fsmount.h
new file mode 100644
index 0000000..09a2c16
--- /dev/null
+++ b/kernel/tests/include/lapi/fsmount.h
@@ -0,0 +1,145 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Linaro Limited. All rights reserved.
+ * Author: Viresh Kumar <viresh.kumar@linaro.org>
+ */
+
+#ifndef FSMOUNT_H__
+#define FSMOUNT_H__
+
+#include <sys/mount.h>
+#include <sys/syscall.h>
+#include <sys/types.h>
+
+#include "config.h"
+#include "lapi/fcntl.h"
+#include "lapi/syscalls.h"
+
+#ifndef HAVE_FSOPEN
+int fsopen(const char *fsname, unsigned int flags)
+{
+ return tst_syscall(__NR_fsopen, fsname, flags);
+}
+#endif /* HAVE_FSOPEN */
+
+#ifndef HAVE_FSCONFIG
+int fsconfig(int fd, unsigned int cmd, const char *key,
+ const void *value, int aux)
+{
+ return tst_syscall(__NR_fsconfig, fd, cmd, key, value, aux);
+}
+#endif /* HAVE_FSCONFIG */
+
+#ifndef HAVE_FSMOUNT
+int fsmount(int fd, unsigned int flags, unsigned int mount_attrs)
+{
+ return tst_syscall(__NR_fsmount, fd, flags, mount_attrs);
+}
+#endif /* HAVE_FSMOUNT */
+
+#ifndef HAVE_FSPICK
+int fspick(int dirfd, const char *pathname, unsigned int flags)
+{
+ return tst_syscall(__NR_fspick, dirfd, pathname, flags);
+}
+#endif /* HAVE_FSPICK */
+
+#ifndef HAVE_MOVE_MOUNT
+int move_mount(int from_dirfd, const char *from_pathname, int to_dirfd,
+ const char *to_pathname, unsigned int flags)
+{
+ return tst_syscall(__NR_move_mount, from_dirfd, from_pathname, to_dirfd,
+ to_pathname, flags);
+}
+#endif /* HAVE_MOVE_MOUNT */
+
+#ifndef HAVE_OPEN_TREE
+int open_tree(int dirfd, const char *pathname, unsigned int flags)
+{
+ return tst_syscall(__NR_open_tree, dirfd, pathname, flags);
+}
+#endif /* HAVE_OPEN_TREE */
+
+/*
+ * New headers added in kernel after 5.2 release, create them for old userspace.
+*/
+
+#ifndef OPEN_TREE_CLONE
+
+/*
+ * open_tree() flags.
+ */
+#define OPEN_TREE_CLONE 1 /* Clone the target tree and attach the clone */
+#define OPEN_TREE_CLOEXEC O_CLOEXEC /* Close the file on execve() */
+
+/*
+ * move_mount() flags.
+ */
+#define MOVE_MOUNT_F_SYMLINKS 0x00000001 /* Follow symlinks on from path */
+#define MOVE_MOUNT_F_AUTOMOUNTS 0x00000002 /* Follow automounts on from path */
+#define MOVE_MOUNT_F_EMPTY_PATH 0x00000004 /* Empty from path permitted */
+#define MOVE_MOUNT_T_SYMLINKS 0x00000010 /* Follow symlinks on to path */
+#define MOVE_MOUNT_T_AUTOMOUNTS 0x00000020 /* Follow automounts on to path */
+#define MOVE_MOUNT_T_EMPTY_PATH 0x00000040 /* Empty to path permitted */
+#define MOVE_MOUNT__MASK 0x00000077
+
+/*
+ * fsopen() flags.
+ */
+#define FSOPEN_CLOEXEC 0x00000001
+
+/*
+ * fspick() flags.
+ */
+#define FSPICK_CLOEXEC 0x00000001
+#define FSPICK_SYMLINK_NOFOLLOW 0x00000002
+#define FSPICK_NO_AUTOMOUNT 0x00000004
+#define FSPICK_EMPTY_PATH 0x00000008
+
+/*
+ * The type of fsconfig() call made.
+ */
+enum fsconfig_command {
+ FSCONFIG_SET_FLAG = 0, /* Set parameter, supplying no value */
+ FSCONFIG_SET_STRING = 1, /* Set parameter, supplying a string value */
+ FSCONFIG_SET_BINARY = 2, /* Set parameter, supplying a binary blob value */
+ FSCONFIG_SET_PATH = 3, /* Set parameter, supplying an object by path */
+ FSCONFIG_SET_PATH_EMPTY = 4, /* Set parameter, supplying an object by (empty) path */
+ FSCONFIG_SET_FD = 5, /* Set parameter, supplying an object by fd */
+ FSCONFIG_CMD_CREATE = 6, /* Invoke superblock creation */
+ FSCONFIG_CMD_RECONFIGURE = 7, /* Invoke superblock reconfiguration */
+};
+
+/*
+ * fsmount() flags.
+ */
+#define FSMOUNT_CLOEXEC 0x00000001
+
+/*
+ * Mount attributes.
+ */
+#define MOUNT_ATTR_RDONLY 0x00000001 /* Mount read-only */
+#define MOUNT_ATTR_NOSUID 0x00000002 /* Ignore suid and sgid bits */
+#define MOUNT_ATTR_NODEV 0x00000004 /* Disallow access to device special files */
+#define MOUNT_ATTR_NOEXEC 0x00000008 /* Disallow program execution */
+#define MOUNT_ATTR__ATIME 0x00000070 /* Setting on how atime should be updated */
+#define MOUNT_ATTR_RELATIME 0x00000000 /* - Update atime relative to mtime/ctime. */
+#define MOUNT_ATTR_NOATIME 0x00000010 /* - Do not update access times. */
+#define MOUNT_ATTR_STRICTATIME 0x00000020 /* - Always perform atime updates */
+#define MOUNT_ATTR_NODIRATIME 0x00000080 /* Do not update directory access times */
+
+#endif /* OPEN_TREE_CLONE */
+
+void fsopen_supported_by_kernel(void)
+{
+ if ((tst_kvercmp(5, 2, 0)) < 0) {
+ /* Check if the syscall is backported on an older kernel */
+ TEST(syscall(__NR_fsopen, NULL, 0));
+ if (TST_RET != -1)
+ SAFE_CLOSE(TST_RET);
+ else if (TST_ERR == ENOSYS)
+ tst_brk(TCONF, "Test not supported on kernel version < v5.2");
+ }
+}
+
+#endif /* FSMOUNT_H__ */
diff --git a/kernel/tests/include/lapi/futex.h b/kernel/tests/include/lapi/futex.h
new file mode 100644
index 0000000..72209e4
--- /dev/null
+++ b/kernel/tests/include/lapi/futex.h
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2015 Linux Test Project
+ */
+
+#ifndef LAPI_FUTEX_H__
+#define LAPI_FUTEX_H__
+
+#include <stdint.h>
+
+typedef volatile uint32_t futex_t;
+
+#endif /* LAPI_FUTEX_H__ */
diff --git a/kernel/tests/include/lapi/getrandom.h b/kernel/tests/include/lapi/getrandom.h
new file mode 100644
index 0000000..83e0a0e
--- /dev/null
+++ b/kernel/tests/include/lapi/getrandom.h
@@ -0,0 +1,30 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2015 Linux Test Project
+ */
+
+#ifndef __GETRANDOM_H__
+#define __GETRANDOM_H__
+
+#include "config.h"
+
+#if HAVE_LINUX_RANDOM_H
+#include <linux/random.h>
+#endif
+
+/*
+ * Flags for getrandom(2)
+ *
+ * GRND_NONBLOCK Don't block and return EAGAIN instead
+ * GRND_RANDOM Use the /dev/random pool instead of /dev/urandom
+ */
+
+#ifndef GRND_NONBLOCK
+# define GRND_NONBLOCK 0x0001
+#endif
+
+#ifndef GRND_RANDOM
+# define GRND_RANDOM 0x0002
+#endif
+
+#endif /* __GETRANDOM_H__ */
diff --git a/kernel/tests/include/lapi/if_alg.h b/kernel/tests/include/lapi/if_alg.h
new file mode 100644
index 0000000..9c04a44
--- /dev/null
+++ b/kernel/tests/include/lapi/if_alg.h
@@ -0,0 +1,59 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright 2019 Google LLC
+ */
+
+#ifndef IF_ALG_H__
+#define IF_ALG_H__
+
+#ifdef HAVE_LINUX_IF_ALG_H
+# include <linux/if_alg.h>
+#endif
+# include <stdint.h>
+
+#ifndef HAVE_STRUCT_SOCKADDR_ALG
+struct sockaddr_alg {
+ uint16_t salg_family;
+ uint8_t salg_type[14];
+ uint32_t salg_feat;
+ uint32_t salg_mask;
+ uint8_t salg_name[64];
+};
+#endif
+
+#ifndef HAVE_STRUCT_AF_ALG_IV
+struct af_alg_iv {
+ uint32_t ivlen;
+ uint8_t iv[0];
+};
+#endif
+
+#ifndef ALG_SET_KEY
+# define ALG_SET_KEY 1
+#endif
+
+#ifndef ALG_SET_IV
+# define ALG_SET_IV 2
+#endif
+
+#ifndef ALG_SET_OP
+# define ALG_SET_OP 3
+#endif
+
+#ifndef ALG_SET_AEAD_ASSOCLEN
+# define ALG_SET_AEAD_ASSOCLEN 4
+#endif
+
+#ifndef ALG_SET_AEAD_AUTHSIZE
+# define ALG_SET_AEAD_AUTHSIZE 5
+#endif
+
+#ifndef ALG_OP_DECRYPT
+# define ALG_OP_DECRYPT 0
+#endif
+
+#ifndef ALG_OP_ENCRYPT
+# define ALG_OP_ENCRYPT 1
+#endif
+
+#endif /* IF_ALG_H__ */
diff --git a/kernel/tests/include/lapi/if_ether.h b/kernel/tests/include/lapi/if_ether.h
new file mode 100644
index 0000000..0e9a4fc
--- /dev/null
+++ b/kernel/tests/include/lapi/if_ether.h
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 SUSE LLC <mdoucha@suse.cz>
+ */
+
+#ifndef __LAPI_IF_ETHER_H__
+#define __LAPI_IF_ETHER_H__
+
+#include "config.h"
+
+#ifdef HAVE_LINUX_IF_ETHER_H
+# include <linux/if_ether.h>
+#endif
+
+#ifndef ETH_P_ALL
+# define ETH_P_ALL 0x0003
+#endif
+
+#endif /* __LAPI_IF_ETHER_H__ */
diff --git a/kernel/tests/include/lapi/if_packet.h b/kernel/tests/include/lapi/if_packet.h
new file mode 100644
index 0000000..8111021
--- /dev/null
+++ b/kernel/tests/include/lapi/if_packet.h
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
+ * Author: Jinhui huang <huangjh.jy@cn.fujitsu.com>
+ */
+
+#ifndef __LAPI_IF_PACKET_H__
+#define __LAPI_IF_PACKET_H__
+
+#include "config.h"
+
+#ifdef HAVE_LINUX_IF_PACKET_H
+# include <linux/if_packet.h>
+#endif
+
+#ifndef PACKET_RX_RING
+# define PACKET_RX_RING 5
+#endif
+
+#ifndef PACKET_VERSION
+# define PACKET_VERSION 10
+#endif
+
+#ifndef PACKET_RESERVE
+# define PACKET_RESERVE 12
+#endif
+
+#ifndef PACKET_FANOUT
+#define PACKET_FANOUT 18
+#endif
+
+#ifndef PACKET_FANOUT_ROLLOVER
+#define PACKET_FANOUT_ROLLOVER 3
+#endif
+
+#ifndef HAVE_STRUCT_TPACKET_REQ3
+# define TPACKET_V3 2
+
+struct tpacket_req3 {
+ unsigned int tp_block_size;
+ unsigned int tp_block_nr;
+ unsigned int tp_frame_size;
+ unsigned int tp_frame_nr;
+ unsigned int tp_retire_blk_tov;
+ unsigned int tp_sizeof_priv;
+ unsigned int tp_feature_req_word;
+};
+#endif
+
+#endif /* __LAPI_IF_PACKET_H__ */
diff --git a/kernel/tests/include/lapi/io_pgetevents.h b/kernel/tests/include/lapi/io_pgetevents.h
new file mode 100644
index 0000000..5bb9a60
--- /dev/null
+++ b/kernel/tests/include/lapi/io_pgetevents.h
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Linaro Limited. All rights reserved.
+ * Author: Viresh Kumar <viresh.kumar@linaro.org>
+ */
+
+#ifndef IO_PGETEVENTS_H
+#define IO_PGETEVENTS_H
+
+#include <sys/syscall.h>
+#include <sys/types.h>
+
+#include "config.h"
+#include "lapi/syscalls.h"
+
+#ifdef HAVE_LIBAIO
+#include <libaio.h>
+
+static inline int sys_io_pgetevents(io_context_t ctx, long min_nr, long max_nr,
+ struct io_event *events, void *timeout, sigset_t *sigmask)
+{
+ return tst_syscall(__NR_io_pgetevents, ctx, min_nr, max_nr, events,
+ timeout, sigmask);
+}
+
+static inline int sys_io_pgetevents_time64(io_context_t ctx, long min_nr, long max_nr,
+ struct io_event *events, void *timeout, sigset_t *sigmask)
+{
+ return tst_syscall(__NR_io_pgetevents_time64, ctx, min_nr, max_nr,
+ events, timeout, sigmask);
+}
+
+#endif /* HAVE_LIBAIO */
+
+#endif /* IO_PGETEVENTS_H */
diff --git a/kernel/tests/include/lapi/io_uring.h b/kernel/tests/include/lapi/io_uring.h
new file mode 100644
index 0000000..174e81e
--- /dev/null
+++ b/kernel/tests/include/lapi/io_uring.h
@@ -0,0 +1,299 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 ARM. All rights reserved.
+ * Copyright (c) 2020 Petr Vorel <pvorel@suse.cz>
+ *
+ * Mostly copied/adapted from <linux/io_uring.h>
+ */
+
+#ifndef IO_URING_H__
+#define IO_URING_H__
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/uio.h>
+#include <stdlib.h>
+#include <linux/fs.h>
+
+#include "lapi/syscalls.h"
+
+#ifndef IOSQE_FIXED_FILE
+
+#ifndef __kernel_rwf_t
+typedef int __kernel_rwf_t;
+#endif
+
+/*
+ * IO submission data structure (Submission Queue Entry)
+ */
+struct io_uring_sqe {
+ uint8_t opcode; /* type of operation for this sqe */
+ uint8_t flags; /* IOSQE_ flags */
+ uint16_t ioprio; /* ioprio for the request */
+ int32_t fd; /* file descriptor to do IO on */
+ union {
+ uint64_t off; /* offset into file */
+ uint64_t addr2;
+ };
+ uint64_t addr; /* pointer to buffer or iovecs */
+ uint32_t len; /* buffer size or number of iovecs */
+ union {
+ __kernel_rwf_t rw_flags;
+ uint32_t fsync_flags;
+ uint16_t poll_events;
+ uint32_t sync_range_flags;
+ uint32_t msg_flags;
+ uint32_t timeout_flags;
+ uint32_t accept_flags;
+ uint32_t cancel_flags;
+ uint32_t open_flags;
+ uint32_t statx_flags;
+ uint32_t fadvise_advice;
+ };
+ uint64_t user_data; /* data to be passed back at completion time */
+ union {
+ struct {
+ /* index into fixed buffers, if used */
+ uint16_t buf_index;
+ /* personality to use, if used */
+ uint16_t personality;
+ };
+ uint64_t __pad2[3];
+ };
+};
+
+enum {
+ IOSQE_FIXED_FILE_BIT,
+ IOSQE_IO_DRAIN_BIT,
+ IOSQE_IO_LINK_BIT,
+ IOSQE_IO_HARDLINK_BIT,
+ IOSQE_ASYNC_BIT,
+};
+
+/*
+ * sqe->flags
+ */
+/* use fixed fileset */
+#define IOSQE_FIXED_FILE (1U << IOSQE_FIXED_FILE_BIT)
+/* issue after inflight IO */
+#define IOSQE_IO_DRAIN (1U << IOSQE_IO_DRAIN_BIT)
+/* links next sqe */
+#define IOSQE_IO_LINK (1U << IOSQE_IO_LINK_BIT)
+/* like LINK, but stronger */
+#define IOSQE_IO_HARDLINK (1U << IOSQE_IO_HARDLINK_BIT)
+/* always go async */
+#define IOSQE_ASYNC (1U << IOSQE_ASYNC_BIT)
+
+/*
+ * io_uring_setup() flags
+ */
+#define IORING_SETUP_IOPOLL (1U << 0) /* io_context is polled */
+#define IORING_SETUP_SQPOLL (1U << 1) /* SQ poll thread */
+#define IORING_SETUP_SQ_AFF (1U << 2) /* sq_thread_cpu is valid */
+#define IORING_SETUP_CQSIZE (1U << 3) /* app defines CQ size */
+#define IORING_SETUP_CLAMP (1U << 4) /* clamp SQ/CQ ring sizes */
+#define IORING_SETUP_ATTACH_WQ (1U << 5) /* attach to existing wq */
+
+enum {
+ IORING_OP_NOP,
+ IORING_OP_READV,
+ IORING_OP_WRITEV,
+ IORING_OP_FSYNC,
+ IORING_OP_READ_FIXED,
+ IORING_OP_WRITE_FIXED,
+ IORING_OP_POLL_ADD,
+ IORING_OP_POLL_REMOVE,
+ IORING_OP_SYNC_FILE_RANGE,
+ IORING_OP_SENDMSG,
+ IORING_OP_RECVMSG,
+ IORING_OP_TIMEOUT,
+ IORING_OP_TIMEOUT_REMOVE,
+ IORING_OP_ACCEPT,
+ IORING_OP_ASYNC_CANCEL,
+ IORING_OP_LINK_TIMEOUT,
+ IORING_OP_CONNECT,
+ IORING_OP_FALLOCATE,
+ IORING_OP_OPENAT,
+ IORING_OP_CLOSE,
+ IORING_OP_FILES_UPDATE,
+ IORING_OP_STATX,
+ IORING_OP_READ,
+ IORING_OP_WRITE,
+ IORING_OP_FADVISE,
+ IORING_OP_MADVISE,
+ IORING_OP_SEND,
+ IORING_OP_RECV,
+ IORING_OP_OPENAT2,
+ IORING_OP_EPOLL_CTL,
+
+ /* this goes last, obviously */
+ IORING_OP_LAST,
+};
+
+/*
+ * sqe->fsync_flags
+ */
+#define IORING_FSYNC_DATASYNC (1U << 0)
+
+/*
+ * sqe->timeout_flags
+ */
+#define IORING_TIMEOUT_ABS (1U << 0)
+
+/*
+ * IO completion data structure (Completion Queue Entry)
+ */
+struct io_uring_cqe {
+ uint64_t user_data; /* sqe->data submission passed back */
+ int32_t res; /* result code for this event */
+ uint32_t flags;
+};
+
+/*
+ * Magic offsets for the application to mmap the data it needs
+ */
+#define IORING_OFF_SQ_RING 0ULL
+#define IORING_OFF_CQ_RING 0x8000000ULL
+#define IORING_OFF_SQES 0x10000000ULL
+
+/*
+ * Filled with the offset for mmap(2)
+ */
+struct io_sqring_offsets {
+ uint32_t head;
+ uint32_t tail;
+ uint32_t ring_mask;
+ uint32_t ring_entries;
+ uint32_t flags;
+ uint32_t dropped;
+ uint32_t array;
+ uint32_t resv1;
+ uint64_t resv2;
+};
+
+/*
+ * sq_ring->flags
+ */
+#define IORING_SQ_NEED_WAKEUP (1U << 0) /* needs io_uring_enter wakeup */
+
+struct io_cqring_offsets {
+ uint32_t head;
+ uint32_t tail;
+ uint32_t ring_mask;
+ uint32_t ring_entries;
+ uint32_t overflow;
+ uint32_t cqes;
+ uint64_t resv[2];
+};
+
+/*
+ * io_uring_enter(2) flags
+ */
+#define IORING_ENTER_GETEVENTS (1U << 0)
+#define IORING_ENTER_SQ_WAKEUP (1U << 1)
+
+/*
+ * Passed in for io_uring_setup(2). Copied back with updated info on success
+ */
+struct io_uring_params {
+ uint32_t sq_entries;
+ uint32_t cq_entries;
+ uint32_t flags;
+ uint32_t sq_thread_cpu;
+ uint32_t sq_thread_idle;
+ uint32_t features;
+ uint32_t wq_fd;
+ uint32_t resv[3];
+ struct io_sqring_offsets sq_off;
+ struct io_cqring_offsets cq_off;
+};
+
+/*
+ * io_uring_params->features flags
+ */
+#define IORING_FEAT_SINGLE_MMAP (1U << 0)
+#define IORING_FEAT_NODROP (1U << 1)
+#define IORING_FEAT_SUBMIT_STABLE (1U << 2)
+#define IORING_FEAT_RW_CUR_POS (1U << 3)
+#define IORING_FEAT_CUR_PERSONALITY (1U << 4)
+
+/*
+ * io_uring_register(2) opcodes and arguments
+ */
+#define IORING_REGISTER_BUFFERS 0
+#define IORING_UNREGISTER_BUFFERS 1
+#define IORING_REGISTER_FILES 2
+#define IORING_UNREGISTER_FILES 3
+#define IORING_REGISTER_EVENTFD 4
+#define IORING_UNREGISTER_EVENTFD 5
+#define IORING_REGISTER_FILES_UPDATE 6
+#define IORING_REGISTER_EVENTFD_ASYNC 7
+#define IORING_REGISTER_PROBE 8
+#define IORING_REGISTER_PERSONALITY 9
+#define IORING_UNREGISTER_PERSONALITY 10
+
+struct io_uring_files_update {
+ uint32_t offset;
+ uint32_t resv;
+ uint64_t __attribute__((aligned(8))) fds;
+};
+
+#define IO_URING_OP_SUPPORTED (1U << 0)
+
+struct io_uring_probe_op {
+ uint8_t op;
+ uint8_t resv;
+ uint16_t flags; /* IO_URING_OP_* flags */
+ uint32_t resv2;
+};
+
+struct io_uring_probe {
+ uint8_t last_op; /* last opcode supported */
+ uint8_t ops_len; /* length of ops[] array below */
+ uint16_t resv;
+ uint32_t resv2[3];
+ struct io_uring_probe_op ops[0];
+};
+
+#endif /* IOSQE_FIXED_FILE */
+
+
+#ifndef HAVE_IO_URING_REGISTER
+int io_uring_register(int fd, unsigned int opcode, void *arg,
+ unsigned int nr_args)
+{
+ return tst_syscall(__NR_io_uring_register, fd, opcode, arg, nr_args);
+}
+#endif /* HAVE_IO_URING_REGISTER */
+
+
+#ifndef HAVE_IO_URING_SETUP
+int io_uring_setup(unsigned int entries, struct io_uring_params *p)
+{
+ return tst_syscall(__NR_io_uring_setup, entries, p);
+}
+#endif /* HAVE_IO_URING_SETUP */
+
+#ifndef HAVE_IO_URING_ENTER
+int io_uring_enter(int fd, unsigned int to_submit, unsigned int min_complete,
+ unsigned int flags, sigset_t *sig)
+{
+ return tst_syscall(__NR_io_uring_enter, fd, to_submit, min_complete,
+ flags, sig, _NSIG / 8);
+}
+#endif /* HAVE_IO_URING_ENTER */
+
+void io_uring_setup_supported_by_kernel(void)
+{
+ if ((tst_kvercmp(5, 1, 0)) < 0) {
+ TEST(syscall(__NR_io_uring_setup, NULL, 0));
+ if (TST_RET != -1)
+ SAFE_CLOSE(TST_RET);
+ else if (TST_ERR == ENOSYS)
+ tst_brk(TCONF,
+ "Test not supported on kernel version < v5.1");
+ }
+}
+
+#endif /* IO_URING_H__ */
diff --git a/kernel/tests/include/lapi/ioctl.h b/kernel/tests/include/lapi/ioctl.h
new file mode 100644
index 0000000..ecd2502
--- /dev/null
+++ b/kernel/tests/include/lapi/ioctl.h
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Cyril Hrubis <chrubis@suse.cz>
+ * Copyright (c) 2020 Petr Vorel <pvorel@suse.cz>
+ */
+
+#ifndef IOCTL_H__
+#define IOCTL_H__
+
+#include "config.h"
+#include <sys/ioctl.h>
+
+/* musl not including it in <sys/ioctl.h> */
+#include <sys/ttydefaults.h>
+
+#ifndef TIOCVHANGUP
+# define TIOCVHANGUP 0x5437
+#endif
+
+#ifndef HAVE_STRUCT_TERMIO
+# ifndef NCC
+# ifdef __powerpc__
+# define NCC 10
+# else
+# define NCC 8
+# endif
+# endif /* NCC */
+
+struct termio
+ {
+ unsigned short int c_iflag; /* input mode flags */
+ unsigned short int c_oflag; /* output mode flags */
+ unsigned short int c_cflag; /* control mode flags */
+ unsigned short int c_lflag; /* local mode flags */
+ unsigned char c_line; /* line discipline */
+ unsigned char c_cc[NCC]; /* control characters */
+};
+#endif /* HAVE_STRUCT_TERMIO */
+
+#endif /* IOCTL_H__ */
diff --git a/kernel/tests/include/lapi/ioctl_ns.h b/kernel/tests/include/lapi/ioctl_ns.h
new file mode 100644
index 0000000..2fb4f4c
--- /dev/null
+++ b/kernel/tests/include/lapi/ioctl_ns.h
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Federico Bonfiglio fedebonfi95@gmail.com
+ */
+
+#ifndef IOCTL_NS_H__
+#define IOCTL_NS_H__
+
+#include <asm-generic/ioctl.h>
+
+#ifndef NSIO
+#define NSIO 0xb7
+#endif
+#ifndef NS_GET_PARENT
+#define NS_GET_PARENT _IO(NSIO, 0x2)
+#endif
+#ifndef NS_GET_OWNER_UID
+#define NS_GET_OWNER_UID _IO(NSIO, 0x4)
+#endif
+#ifndef NS_GET_USERNS
+#define NS_GET_USERNS _IO(NSIO, 0x1)
+#endif
+#ifndef NS_GET_NSTYPE
+#define NS_GET_NSTYPE _IO(NSIO, 0x3)
+#endif
+
+
+#endif /* IOCTL_NS_H__ */
diff --git a/kernel/tests/include/lapi/iovec.h b/kernel/tests/include/lapi/iovec.h
new file mode 100644
index 0000000..d479e9f
--- /dev/null
+++ b/kernel/tests/include/lapi/iovec.h
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2014 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#ifndef IOVEC_H
+#define IOVEC_H
+
+#include "config.h"
+
+#if !defined(HAVE_STRUCT_IOVEC)
+struct iovec {
+ void *iov_base;
+ size_t iov_len;
+};
+#else
+# include <sys/uio.h>
+#endif
+
+#endif /* IOVEC_H */
diff --git a/kernel/tests/include/lapi/ipcbuf.h b/kernel/tests/include/lapi/ipcbuf.h
new file mode 100644
index 0000000..a0b8e3c
--- /dev/null
+++ b/kernel/tests/include/lapi/ipcbuf.h
@@ -0,0 +1,195 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Linaro Limited. All rights reserved.
+ * Author: Viresh Kumar <viresh.kumar@linaro.org>
+ */
+
+#ifndef IPCBUF_H
+#define IPCBUF_H
+
+#include "config.h"
+#include "lapi/posix_types.h"
+
+#ifndef HAVE_IPC64_PERM
+
+#if defined(__hppa__)
+#define HAVE_IPC64_PERM
+/*
+ * The ipc64_perm structure for PA-RISC is almost identical to
+ * kern_ipc_perm as we have always had 32-bit UIDs and GIDs in the kernel.
+ * 'seq' has been changed from long to int so that it's the same size
+ * on 64-bit kernels as on 32-bit ones.
+ */
+
+struct ipc64_perm
+{
+ __kernel_key_t key;
+ __kernel_uid_t uid;
+ __kernel_gid_t gid;
+ __kernel_uid_t cuid;
+ __kernel_gid_t cgid;
+#if __BITS_PER_LONG != 64
+ unsigned short int __pad1;
+#endif
+ __kernel_mode_t mode;
+ unsigned short int __pad2;
+ unsigned short int seq;
+ unsigned int __pad3;
+ unsigned long long int __unused1;
+ unsigned long long int __unused2;
+};
+#endif /* __hppa__ */
+
+#if defined(__powerpc__) || defined(__powerpc64__)
+#define HAVE_IPC64_PERM
+/*
+ * The ipc64_perm structure for the powerpc is identical to
+ * kern_ipc_perm as we have always had 32-bit UIDs and GIDs in the
+ * kernel. Note extra padding because this structure is passed back
+ * and forth between kernel and user space. Pad space is left for:
+ * - 1 32-bit value to fill up for 8-byte alignment
+ * - 2 miscellaneous 64-bit values
+ */
+
+struct ipc64_perm
+{
+ __kernel_key_t key;
+ __kernel_uid_t uid;
+ __kernel_gid_t gid;
+ __kernel_uid_t cuid;
+ __kernel_gid_t cgid;
+ __kernel_mode_t mode;
+ unsigned int seq;
+ unsigned int __pad1;
+ unsigned long long __unused1;
+ unsigned long long __unused2;
+};
+
+#endif /* defined(__powerpc__) || defined(__powerpc64__) */
+
+#if defined(__s390__)
+#define HAVE_IPC64_PERM
+/*
+ * The user_ipc_perm structure for S/390 architecture.
+ * Note extra padding because this structure is passed back and forth
+ * between kernel and user space.
+ *
+ * Pad space is left for:
+ * - 32-bit mode_t and seq
+ * - 2 miscellaneous 32-bit values
+ */
+
+struct ipc64_perm
+{
+ __kernel_key_t key;
+ __kernel_uid32_t uid;
+ __kernel_gid32_t gid;
+ __kernel_uid32_t cuid;
+ __kernel_gid32_t cgid;
+ __kernel_mode_t mode;
+ unsigned short __pad1;
+ unsigned short seq;
+#ifndef __s390x__
+ unsigned short __pad2;
+#endif /* ! __s390x__ */
+ unsigned long __unused1;
+ unsigned long __unused2;
+};
+
+#endif /* defined(__powerpc__) || defined(__powerpc64__) */
+
+#if defined(__sparc__)
+#define HAVE_IPC64_PERM
+/*
+ * The ipc64_perm structure for sparc/sparc64 architecture.
+ * Note extra padding because this structure is passed back and forth
+ * between kernel and user space.
+ *
+ * Pad space is left for:
+ * - 32-bit seq
+ * - on sparc for 32 bit mode (it is 32 bit on sparc64)
+ * - 2 miscellaneous 64-bit values
+ */
+
+struct ipc64_perm
+{
+ __kernel_key_t key;
+ __kernel_uid32_t uid;
+ __kernel_gid32_t gid;
+ __kernel_uid32_t cuid;
+ __kernel_gid32_t cgid;
+#ifndef __arch64__
+ unsigned short __pad0;
+#endif
+ __kernel_mode_t mode;
+ unsigned short __pad1;
+ unsigned short seq;
+ unsigned long long __unused1;
+ unsigned long long __unused2;
+};
+
+#endif /* __sparc__ */
+
+#if defined(__xtensa__)
+#define HAVE_IPC64_PERM
+/*
+ * Pad space is left for:
+ * - 32-bit mode_t and seq
+ * - 2 miscellaneous 32-bit values
+ *
+ * This file is subject to the terms and conditions of the GNU General
+ * Public License. See the file "COPYING" in the main directory of
+ * this archive for more details.
+ */
+
+struct ipc64_perm
+{
+ __kernel_key_t key;
+ __kernel_uid32_t uid;
+ __kernel_gid32_t gid;
+ __kernel_uid32_t cuid;
+ __kernel_gid32_t cgid;
+ __kernel_mode_t mode;
+ unsigned long seq;
+ unsigned long __unused1;
+ unsigned long __unused2;
+};
+
+#endif /* __xtensa__ */
+
+#ifndef HAVE_IPC64_PERM
+/*
+ * The generic ipc64_perm structure:
+ * Note extra padding because this structure is passed back and forth
+ * between kernel and user space.
+ *
+ * ipc64_perm was originally meant to be architecture specific, but
+ * everyone just ended up making identical copies without specific
+ * optimizations, so we may just as well all use the same one.
+ *
+ * Pad space is left for:
+ * - 32-bit mode_t on architectures that only had 16 bit
+ * - 32-bit seq
+ * - 2 miscellaneous 32-bit values
+ */
+
+struct ipc64_perm {
+ __kernel_key_t key;
+ __kernel_uid32_t uid;
+ __kernel_gid32_t gid;
+ __kernel_uid32_t cuid;
+ __kernel_gid32_t cgid;
+ __kernel_mode_t mode;
+ /* pad if mode_t is u16: */
+ unsigned char __pad1[4 - sizeof(__kernel_mode_t)];
+ unsigned short seq;
+ unsigned short __pad2;
+ __kernel_ulong_t __unused1;
+ __kernel_ulong_t __unused2;
+};
+
+#endif /* ipc64_perm */
+
+#endif /* HAVE_IPC64_PERM */
+
+#endif /* IPCBUF_H */
diff --git a/kernel/tests/include/lapi/keyctl.h b/kernel/tests/include/lapi/keyctl.h
new file mode 100644
index 0000000..c53876e
--- /dev/null
+++ b/kernel/tests/include/lapi/keyctl.h
@@ -0,0 +1,178 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#ifndef KEYCTL_H__
+#define KEYCTL_H__
+
+#include "config.h"
+
+#if defined(HAVE_KEYUTILS_H) && defined(HAVE_LIBKEYUTILS)
+# include <keyutils.h>
+#else
+# ifdef HAVE_LINUX_KEYCTL_H
+# include <linux/keyctl.h>
+# endif /* HAVE_LINUX_KEYCTL_H */
+
+# include <stdarg.h>
+# include <stdint.h>
+# include "lapi/syscalls.h"
+typedef int32_t key_serial_t;
+
+static inline key_serial_t add_key(const char *type,
+ const char *description,
+ const void *payload,
+ size_t plen,
+ key_serial_t ringid)
+{
+ return tst_syscall(__NR_add_key,
+ type, description, payload, plen, ringid);
+}
+
+static inline key_serial_t request_key(const char *type,
+ const char *description,
+ const char *callout_info,
+ key_serial_t destringid)
+{
+ return tst_syscall(__NR_request_key,
+ type, description, callout_info, destringid);
+}
+
+static inline long keyctl(int cmd, ...)
+{
+ va_list va;
+ unsigned long arg2, arg3, arg4, arg5;
+
+ va_start(va, cmd);
+ arg2 = va_arg(va, unsigned long);
+ arg3 = va_arg(va, unsigned long);
+ arg4 = va_arg(va, unsigned long);
+ arg5 = va_arg(va, unsigned long);
+ va_end(va);
+
+ return tst_syscall(__NR_keyctl, cmd, arg2, arg3, arg4, arg5);
+}
+
+static inline key_serial_t keyctl_join_session_keyring(const char *name) {
+ return keyctl(KEYCTL_JOIN_SESSION_KEYRING, name);
+}
+
+#endif /* defined(HAVE_KEYUTILS_H) && defined(HAVE_LIBKEYUTILS) */
+
+/* special process keyring shortcut IDs */
+#ifndef KEY_SPEC_THREAD_KEYRING
+# define KEY_SPEC_THREAD_KEYRING -1
+#endif
+
+#ifndef KEY_SPEC_PROCESS_KEYRING
+# define KEY_SPEC_PROCESS_KEYRING -2
+#endif
+
+#ifndef KEY_SPEC_SESSION_KEYRING
+# define KEY_SPEC_SESSION_KEYRING -3
+#endif
+
+#ifndef KEY_SPEC_USER_KEYRING
+# define KEY_SPEC_USER_KEYRING -4
+#endif
+
+
+#ifndef KEY_SPEC_USER_SESSION_KEYRING
+# define KEY_SPEC_USER_SESSION_KEYRING -5
+#endif
+
+/* request-key default keyrings */
+#ifndef KEY_REQKEY_DEFL_THREAD_KEYRING
+# define KEY_REQKEY_DEFL_THREAD_KEYRING 1
+#endif
+
+#ifndef KEY_REQKEY_DEFL_SESSION_KEYRING
+# define KEY_REQKEY_DEFL_SESSION_KEYRING 3
+#endif
+
+#ifndef KEY_REQKEY_DEFL_DEFAULT
+# define KEY_REQKEY_DEFL_DEFAULT 0
+#endif
+
+/* keyctl commands */
+#ifndef KEYCTL_GET_KEYRING_ID
+# define KEYCTL_GET_KEYRING_ID 0
+#endif
+
+#ifndef KEYCTL_JOIN_SESSION_KEYRING
+# define KEYCTL_JOIN_SESSION_KEYRING 1
+#endif
+
+#ifndef KEYCTL_UPDATE
+# define KEYCTL_UPDATE 2
+#endif
+
+#ifndef KEYCTL_REVOKE
+# define KEYCTL_REVOKE 3
+#endif
+
+#ifndef KEYCTL_SETPERM
+# define KEYCTL_SETPERM 5
+#endif
+
+#ifndef KEYCTL_CLEAR
+# define KEYCTL_CLEAR 7
+#endif
+
+#ifndef KEYCTL_UNLINK
+# define KEYCTL_UNLINK 9
+#endif
+
+#ifndef KEYCTL_READ
+# define KEYCTL_READ 11
+#endif
+
+#ifndef KEYCTL_SET_REQKEY_KEYRING
+# define KEYCTL_SET_REQKEY_KEYRING 14
+#endif
+
+#ifndef KEYCTL_SET_TIMEOUT
+# define KEYCTL_SET_TIMEOUT 15
+#endif
+
+#ifndef KEYCTL_INVALIDATE
+# define KEYCTL_INVALIDATE 21
+#endif
+
+/* key permissions */
+#ifndef KEY_POS_VIEW
+# define KEY_POS_VIEW 0x01000000
+# define KEY_POS_READ 0x02000000
+# define KEY_POS_WRITE 0x04000000
+# define KEY_POS_SEARCH 0x08000000
+# define KEY_POS_LINK 0x10000000
+# define KEY_POS_SETATTR 0x20000000
+# define KEY_POS_ALL 0x3f000000
+
+# define KEY_USR_VIEW 0x00010000
+# define KEY_USR_READ 0x00020000
+# define KEY_USR_WRITE 0x00040000
+# define KEY_USR_SEARCH 0x00080000
+# define KEY_USR_LINK 0x00100000
+# define KEY_USR_SETATTR 0x00200000
+# define KEY_USR_ALL 0x003f0000
+
+# define KEY_GRP_VIEW 0x00000100
+# define KEY_GRP_READ 0x00000200
+# define KEY_GRP_WRITE 0x00000400
+# define KEY_GRP_SEARCH 0x00000800
+# define KEY_GRP_LINK 0x00001000
+# define KEY_GRP_SETATTR 0x00002000
+# define KEY_GRP_ALL 0x00003f00
+
+# define KEY_OTH_VIEW 0x00000001
+# define KEY_OTH_READ 0x00000002
+# define KEY_OTH_WRITE 0x00000004
+# define KEY_OTH_SEARCH 0x00000008
+# define KEY_OTH_LINK 0x00000010
+# define KEY_OTH_SETATTR 0x00000020
+# define KEY_OTH_ALL 0x0000003f
+#endif /* !KEY_POS_VIEW */
+
+#endif /* KEYCTL_H__ */
diff --git a/kernel/tests/include/lapi/loop.h b/kernel/tests/include/lapi/loop.h
new file mode 100644
index 0000000..87a9023
--- /dev/null
+++ b/kernel/tests/include/lapi/loop.h
@@ -0,0 +1,55 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
+ */
+#ifndef LAPI_LOOP_H
+#define LAPI_LOOP_H
+
+#include "config.h"
+#include <linux/types.h>
+#include <linux/loop.h>
+
+#ifndef LO_FLAGS_PARTSCAN
+# define LO_FLAGS_PARTSCAN 8
+#endif
+
+#ifndef LO_FLAGS_DIRECT_IO
+# define LO_FLAGS_DIRECT_IO 16
+#endif
+
+#ifndef LOOP_SET_CAPACITY
+# define LOOP_SET_CAPACITY 0x4C07
+#endif
+
+#ifndef LOOP_SET_DIRECT_IO
+# define LOOP_SET_DIRECT_IO 0x4C08
+#endif
+
+#ifndef LOOP_SET_BLOCK_SIZE
+# define LOOP_SET_BLOCK_SIZE 0x4C09
+#endif
+
+#ifndef LOOP_CONFIGURE
+# define LOOP_CONFIGURE 0x4C0A
+#endif
+
+#ifndef HAVE_STRUCT_LOOP_CONFIG
+/*
+ * struct loop_config - Complete configuration for a loop device.
+ * @fd: fd of the file to be used as a backing file for the loop device.
+ * @block_size: block size to use; ignored if 0.
+ * @info: struct loop_info64 to configure the loop device with.
+ *
+ * This structure is used with the LOOP_CONFIGURE ioctl, and can be used to
+ * atomically setup and configure all loop device parameters at once.
+ */
+struct loop_config {
+ __u32 fd;
+ __u32 block_size;
+ struct loop_info64 info;
+ __u64 __reserved[8];
+};
+#endif
+
+#endif
diff --git a/kernel/tests/include/lapi/membarrier.h b/kernel/tests/include/lapi/membarrier.h
new file mode 100644
index 0000000..2b6c57f
--- /dev/null
+++ b/kernel/tests/include/lapi/membarrier.h
@@ -0,0 +1,30 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2018 Linaro Limited. All rights reserved.
+ * Author: Rafael David Tinoco <rafael.tinoco@linaro.org>
+ */
+
+#ifndef LAPI_MEMBARRIER_H
+#define LAPI_MEMBARRIER_H
+
+/*
+ * Having <linux/membarrier.h> is enough to know if the test should run or
+ * not, but it might not define all needed MEMBARRIER_CMD_* being tested,
+ * since its first versions included just a few commands.
+ */
+
+enum membarrier_cmd {
+ MEMBARRIER_CMD_QUERY = 0,
+ MEMBARRIER_CMD_GLOBAL = (1 << 0),
+ MEMBARRIER_CMD_GLOBAL_EXPEDITED = (1 << 1),
+ MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED = (1 << 2),
+ MEMBARRIER_CMD_PRIVATE_EXPEDITED = (1 << 3),
+ MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED = (1 << 4),
+ MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE = (1 << 5),
+ MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE = (1 << 6),
+
+ /* Alias for header backward compatibility. */
+ MEMBARRIER_CMD_SHARED = MEMBARRIER_CMD_GLOBAL,
+};
+
+#endif
diff --git a/kernel/tests/include/lapi/memfd.h b/kernel/tests/include/lapi/memfd.h
new file mode 100644
index 0000000..e38e671
--- /dev/null
+++ b/kernel/tests/include/lapi/memfd.h
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2017 Red Hat, Inc.
+ */
+
+#ifndef LAPI_MEMFD_H
+#define LAPI_MEMFD_H
+
+/* flags for memfd_create(2) (unsigned int) */
+#ifndef MFD_CLOEXEC
+# define MFD_CLOEXEC 0x0001U
+#endif
+#ifndef MFD_ALLOW_SEALING
+# define MFD_ALLOW_SEALING 0x0002U
+#endif
+
+/* flags for memfd_create(3) and memfd_create(4) */
+#ifndef MFD_HUGETLB
+#define MFD_HUGETLB 0x0004U
+#endif
+
+#ifndef MFD_HUGE_64KB
+#define MFD_HUGE_64KB (16 << 26)
+#endif
+#ifndef MFD_HUGE_512KB
+#define MFD_HUGE_512KB (19 << 26)
+#endif
+#ifndef MFD_HUGE_2MB
+#define MFD_HUGE_2MB (21 << 26)
+#endif
+#ifndef MFD_HUGE_8MB
+#define MFD_HUGE_8MB (23 << 26)
+#endif
+#ifndef MFD_HUGE_16MB
+#define MFD_HUGE_16MB (24 << 26)
+#endif
+#ifndef MFD_HUGE_256MB
+#define MFD_HUGE_256MB (28 << 26)
+#endif
+#ifndef MFD_HUGE_1GB
+#define MFD_HUGE_1GB (30 << 26)
+#endif
+#ifndef MFD_HUGE_2GB
+#define MFD_HUGE_2GB (31 << 26)
+#endif
+#ifndef MFD_HUGE_16GB
+#define MFD_HUGE_16GB (34 << 26)
+#endif
+
+#endif
diff --git a/kernel/tests/include/lapi/mkdirat.h b/kernel/tests/include/lapi/mkdirat.h
new file mode 100644
index 0000000..bb8c6d8
--- /dev/null
+++ b/kernel/tests/include/lapi/mkdirat.h
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2014 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#ifndef __MKDIRAT_H__
+#define __MKDIRAT_H__
+
+#include "config.h"
+#include "lapi/syscalls.h"
+#include "lapi/fcntl.h"
+
+#ifndef HAVE_MKDIRAT
+int mkdirat(int dirfd, const char *dirname, int mode)
+{
+ return ltp_syscall(__NR_mkdirat, dirfd, dirname, mode);
+}
+#endif
+
+#endif /* __MKDIRAT_H__ */
diff --git a/kernel/tests/include/lapi/mlock2.h b/kernel/tests/include/lapi/mlock2.h
new file mode 100644
index 0000000..fa2b2de
--- /dev/null
+++ b/kernel/tests/include/lapi/mlock2.h
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
+ * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
+ */
+
+#ifndef LAPI_MLOCK2_H__
+# define LAPI_MLOCK2_H__
+
+#include <linux/mman.h>
+
+#ifndef MLOCK_ONFAULT
+# define MLOCK_ONFAULT 0x01
+#endif
+
+#endif /* LAPI_MLOCK2_H__ */
diff --git a/kernel/tests/include/lapi/mmap.h b/kernel/tests/include/lapi/mmap.h
new file mode 100644
index 0000000..12845b7
--- /dev/null
+++ b/kernel/tests/include/lapi/mmap.h
@@ -0,0 +1,87 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2015 Fujitsu Ltd.
+ * Author: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
+ */
+
+#ifndef LAPI_MMAP_H__
+#define LAPI_MMAP_H__
+
+#include "config.h"
+
+#ifndef MAP_HUGETLB
+# define MAP_HUGETLB 0x40000
+#endif
+
+#ifndef MADV_REMOVE
+# define MADV_REMOVE 9
+#endif
+
+#ifndef MADV_DONTFORK
+# define MADV_DONTFORK 10
+#endif
+
+#ifndef MADV_DOFORK
+# define MADV_DOFORK 11
+#endif
+
+#ifndef MADV_HWPOISON
+# define MADV_HWPOISON 100
+#endif
+
+#ifndef MADV_SOFT_OFFLINE
+# define MADV_SOFT_OFFLINE 101
+#endif
+
+#ifndef MADV_MERGEABLE
+# define MADV_MERGEABLE 12
+#endif
+
+#ifndef MADV_UNMERGEABLE
+# define MADV_UNMERGEABLE 13
+#endif
+
+#ifndef MADV_HUGEPAGE
+# define MADV_HUGEPAGE 14
+#endif
+
+#ifndef MADV_NOHUGEPAGE
+# define MADV_NOHUGEPAGE 15
+#endif
+
+#ifndef MADV_DONTDUMP
+# define MADV_DONTDUMP 16
+#endif
+
+#ifndef MADV_DODUMP
+# define MADV_DODUMP 17
+#endif
+
+#ifndef MADV_FREE
+# define MADV_FREE 8
+#endif
+
+#ifndef MADV_WIPEONFORK
+# define MADV_WIPEONFORK 18
+# define MADV_KEEPONFORK 19
+#endif
+
+#ifndef MAP_FIXED_NOREPLACE
+
+#ifdef __alpha__
+# define MAP_FIXED_NOREPLACE 0x200000
+#else
+# define MAP_FIXED_NOREPLACE 0x100000
+#endif
+
+#endif /* MAP_FIXED_NOREPLACE */
+
+#ifdef HAVE_SYS_SHM_H
+# include <sys/shm.h>
+# define MMAP_GRANULARITY SHMLBA
+#else
+# include <unistd.h>
+# define MMAP_GRANULARITY getpagesize()
+#endif /* HAVE_SYS_SHM_H */
+
+#endif /* LAPI_MMAP_H__ */
diff --git a/kernel/tests/include/lapi/mount.h b/kernel/tests/include/lapi/mount.h
new file mode 100644
index 0000000..b8ae1f5
--- /dev/null
+++ b/kernel/tests/include/lapi/mount.h
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2015 Cui Bixuan <cuibixuan@huawei.com>
+ */
+
+#ifndef __MOUNT_H__
+#define __MOUNT_H__
+
+#ifndef MS_REC
+#define MS_REC 16384
+#endif
+
+#ifndef MS_PRIVATE
+#define MS_PRIVATE (1<<18)
+#endif
+
+#ifndef MS_STRICTATIME
+#define MS_STRICTATIME (1 << 24)
+#endif
+
+#ifndef MNT_DETACH
+#define MNT_DETACH 2
+#endif
+
+#ifndef MNT_EXPIRE
+#define MNT_EXPIRE 4
+#endif
+
+#ifndef UMOUNT_NOFOLLOW
+#define UMOUNT_NOFOLLOW 8
+#endif
+
+#endif /* __MOUNT_H__ */
diff --git a/kernel/tests/include/lapi/msg.h b/kernel/tests/include/lapi/msg.h
new file mode 100644
index 0000000..d649f33
--- /dev/null
+++ b/kernel/tests/include/lapi/msg.h
@@ -0,0 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
+ */
+#ifndef LAPI_MSG_H
+#define LAPI_MSG_H
+
+#include <sys/msg.h>
+
+#ifndef MSG_COPY
+# define MSG_COPY 040000 /* copy (not remove) all queue messages */
+#endif
+
+#endif
diff --git a/kernel/tests/include/lapi/msgbuf.h b/kernel/tests/include/lapi/msgbuf.h
new file mode 100644
index 0000000..f327727
--- /dev/null
+++ b/kernel/tests/include/lapi/msgbuf.h
@@ -0,0 +1,306 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Linaro Limited. All rights reserved.
+ * Author: Viresh Kumar <viresh.kumar@linaro.org>
+ */
+
+#ifndef IPC_MSGBUF_H
+#define IPC_MSGBUF_H
+
+#include "lapi/posix_types.h"
+#include <sys/sem.h>
+#include "tst_timer.h"
+#include "ipcbuf.h"
+
+#ifndef HAVE_MSQID64_DS
+
+#if defined(__mips__)
+#define HAVE_MSQID64_DS
+
+#if defined(__arch64__)
+/*
+ * The msqid64_ds structure for the MIPS architecture.
+ * Note extra padding because this structure is passed back and forth
+ * between kernel and user space.
+ *
+ * Pad space is left for:
+ * - 2 miscellaneous unsigned long values
+ */
+
+struct msqid64_ds {
+ struct ipc64_perm msg_perm;
+ long msg_stime; /* last msgsnd time */
+ long msg_rtime; /* last msgrcv time */
+ long msg_ctime; /* last change time */
+ unsigned long msg_cbytes; /* current number of bytes on queue */
+ unsigned long msg_qnum; /* number of messages in queue */
+ unsigned long msg_qbytes; /* max number of bytes on queue */
+ __kernel_pid_t msg_lspid; /* pid of last msgsnd */
+ __kernel_pid_t msg_lrpid; /* last receive pid */
+ unsigned long __unused4;
+ unsigned long __unused5;
+};
+#elif defined (__MIPSEB__)
+#define HAVE_MSQID64_DS_TIME_HIGH
+struct msqid64_ds {
+ struct ipc64_perm msg_perm;
+ unsigned long msg_stime_high;
+ unsigned long msg_stime; /* last msgsnd time */
+ unsigned long msg_rtime_high;
+ unsigned long msg_rtime; /* last msgrcv time */
+ unsigned long msg_ctime_high;
+ unsigned long msg_ctime; /* last change time */
+ unsigned long msg_cbytes; /* current number of bytes on queue */
+ unsigned long msg_qnum; /* number of messages in queue */
+ unsigned long msg_qbytes; /* max number of bytes on queue */
+ __kernel_pid_t msg_lspid; /* pid of last msgsnd */
+ __kernel_pid_t msg_lrpid; /* last receive pid */
+ unsigned long __unused4;
+ unsigned long __unused5;
+};
+#elif defined (__MIPSEL__)
+#define HAVE_MSQID64_DS_TIME_HIGH
+struct msqid64_ds {
+ struct ipc64_perm msg_perm;
+ unsigned long msg_stime; /* last msgsnd time */
+ unsigned long msg_stime_high;
+ unsigned long msg_rtime; /* last msgrcv time */
+ unsigned long msg_rtime_high;
+ unsigned long msg_ctime; /* last change time */
+ unsigned long msg_ctime_high;
+ unsigned long msg_cbytes; /* current number of bytes on queue */
+ unsigned long msg_qnum; /* number of messages in queue */
+ unsigned long msg_qbytes; /* max number of bytes on queue */
+ __kernel_pid_t msg_lspid; /* pid of last msgsnd */
+ __kernel_pid_t msg_lrpid; /* last receive pid */
+ unsigned long __unused4;
+ unsigned long __unused5;
+};
+#endif
+
+#endif /* __mips__ */
+
+#if defined(__hppa__)
+#define HAVE_MSQID64_DS
+/*
+ * The msqid64_ds structure for parisc architecture, copied from sparc.
+ * Note extra padding because this structure is passed back and forth
+ * between kernel and user space.
+ *
+ * Pad space is left for:
+ * - 2 miscellaneous 32-bit values
+ */
+
+struct msqid64_ds {
+ struct ipc64_perm msg_perm;
+#if __BITS_PER_LONG == 64
+ long msg_stime; /* last msgsnd time */
+ long msg_rtime; /* last msgrcv time */
+ long msg_ctime; /* last change time */
+#else
+#define HAVE_MSQID64_DS_TIME_HIGH
+ unsigned long msg_stime_high;
+ unsigned long msg_stime; /* last msgsnd time */
+ unsigned long msg_rtime_high;
+ unsigned long msg_rtime; /* last msgrcv time */
+ unsigned long msg_ctime_high;
+ unsigned long msg_ctime; /* last change time */
+#endif
+ unsigned long msg_cbytes; /* current number of bytes on queue */
+ unsigned long msg_qnum; /* number of messages in queue */
+ unsigned long msg_qbytes; /* max number of bytes on queue */
+ __kernel_pid_t msg_lspid; /* pid of last msgsnd */
+ __kernel_pid_t msg_lrpid; /* last receive pid */
+ unsigned long __unused1;
+ unsigned long __unused2;
+};
+
+#endif /* __hppa__ */
+
+#if defined(__powerpc__) || defined(__powerpc64__)
+#define HAVE_MSQID64_DS
+/*
+ * The msqid64_ds structure for the PowerPC architecture.
+ * Note extra padding because this structure is passed back and forth
+ * between kernel and user space.
+ */
+
+struct msqid64_ds {
+ struct ipc64_perm msg_perm;
+#ifdef __powerpc64__
+ long msg_stime; /* last msgsnd time */
+ long msg_rtime; /* last msgrcv time */
+ long msg_ctime; /* last change time */
+#else
+#define HAVE_MSQID64_DS_TIME_HIGH
+ unsigned long msg_stime_high;
+ unsigned long msg_stime; /* last msgsnd time */
+ unsigned long msg_rtime_high;
+ unsigned long msg_rtime; /* last msgrcv time */
+ unsigned long msg_ctime_high;
+ unsigned long msg_ctime; /* last change time */
+#endif
+ unsigned long msg_cbytes; /* current number of bytes on queue */
+ unsigned long msg_qnum; /* number of messages in queue */
+ unsigned long msg_qbytes; /* max number of bytes on queue */
+ __kernel_pid_t msg_lspid; /* pid of last msgsnd */
+ __kernel_pid_t msg_lrpid; /* last receive pid */
+ unsigned long __unused4;
+ unsigned long __unused5;
+};
+
+#endif /* defined(__powerpc__) || defined(__powerpc64__) */
+
+#if defined(__sparc__)
+#define HAVE_MSQID64_DS
+/*
+ * The msqid64_ds structure for sparc64 architecture.
+ * Note extra padding because this structure is passed back and forth
+ * between kernel and user space.
+ *
+ * Pad space is left for:
+ * - 2 miscellaneous 32-bit values
+ */
+struct msqid64_ds {
+ struct ipc64_perm msg_perm;
+#if defined(__arch64__)
+ long msg_stime; /* last msgsnd time */
+ long msg_rtime; /* last msgrcv time */
+ long msg_ctime; /* last change time */
+#else
+#define HAVE_MSQID64_DS_TIME_HIGH
+ unsigned long msg_stime_high;
+ unsigned long msg_stime; /* last msgsnd time */
+ unsigned long msg_rtime_high;
+ unsigned long msg_rtime; /* last msgrcv time */
+ unsigned long msg_ctime_high;
+ unsigned long msg_ctime; /* last change time */
+#endif
+ unsigned long msg_cbytes; /* current number of bytes on queue */
+ unsigned long msg_qnum; /* number of messages in queue */
+ unsigned long msg_qbytes; /* max number of bytes on queue */
+ __kernel_pid_t msg_lspid; /* pid of last msgsnd */
+ __kernel_pid_t msg_lrpid; /* last receive pid */
+ unsigned long __unused1;
+ unsigned long __unused2;
+};
+
+#endif /* __sparc__ */
+
+#if defined(__x86_64__) && defined(__ILP32__)
+#define HAVE_MSQID64_DS
+/*
+ * The msqid64_ds structure for x86 architecture with x32 ABI.
+ *
+ * On x86-32 and x86-64 we can just use the generic definition, but
+ * x32 uses the same binary layout as x86_64, which is differnet
+ * from other 32-bit architectures.
+ */
+
+struct msqid64_ds {
+ struct ipc64_perm msg_perm;
+ __kernel_long_t msg_stime; /* last msgsnd time */
+ __kernel_long_t msg_rtime; /* last msgrcv time */
+ __kernel_long_t msg_ctime; /* last change time */
+ __kernel_ulong_t msg_cbytes; /* current number of bytes on queue */
+ __kernel_ulong_t msg_qnum; /* number of messages in queue */
+ __kernel_ulong_t msg_qbytes; /* max number of bytes on queue */
+ __kernel_pid_t msg_lspid; /* pid of last msgsnd */
+ __kernel_pid_t msg_lrpid; /* last receive pid */
+ __kernel_ulong_t __unused4;
+ __kernel_ulong_t __unused5;
+};
+
+#endif /* defined(__x86_64__) && defined(__ILP32__) */
+
+#if defined(__xtensa__)
+#define HAVE_MSQID64_DS
+/*
+ * The msqid64_ds structure for the Xtensa architecture.
+ * Note extra padding because this structure is passed back and forth
+ * between kernel and user space.
+ *
+ * Pad space is left for:
+ * - 2 miscellaneous 32-bit values
+ */
+
+struct msqid64_ds {
+ struct ipc64_perm msg_perm;
+#ifdef __XTENSA_EB__
+#define HAVE_MSQID64_DS_TIME_HIGH
+ unsigned long msg_stime_high;
+ unsigned long msg_stime; /* last msgsnd time */
+ unsigned long msg_rtime_high;
+ unsigned long msg_rtime; /* last msgrcv time */
+ unsigned long msg_ctime_high;
+ unsigned long msg_ctime; /* last change time */
+#elif defined(__XTENSA_EL__)
+#define HAVE_MSQID64_DS_TIME_HIGH
+ unsigned long msg_stime; /* last msgsnd time */
+ unsigned long msg_stime_high;
+ unsigned long msg_rtime; /* last msgrcv time */
+ unsigned long msg_rtime_high;
+ unsigned long msg_ctime; /* last change time */
+ unsigned long msg_ctime_high;
+#else
+# error processor byte order undefined!
+#endif
+ unsigned long msg_cbytes; /* current number of bytes on queue */
+ unsigned long msg_qnum; /* number of messages in queue */
+ unsigned long msg_qbytes; /* max number of bytes on queue */
+ __kernel_pid_t msg_lspid; /* pid of last msgsnd */
+ __kernel_pid_t msg_lrpid; /* last receive pid */
+ unsigned long __unused4;
+ unsigned long __unused5;
+};
+
+#endif /* __xtensa__ */
+
+#ifndef HAVE_MSQID64_DS
+/*
+ * generic msqid64_ds structure.
+ *
+ * Note extra padding because this structure is passed back and forth
+ * between kernel and user space.
+ *
+ * msqid64_ds was originally meant to be architecture specific, but
+ * everyone just ended up making identical copies without specific
+ * optimizations, so we may just as well all use the same one.
+ *
+ * 64 bit architectures use a 64-bit long time field here, while
+ * 32 bit architectures have a pair of unsigned long values.
+ * On big-endian systems, the lower half is in the wrong place.
+ *
+ * Pad space is left for:
+ * - 2 miscellaneous 32-bit values
+ */
+
+struct msqid64_ds {
+ struct ipc64_perm msg_perm;
+#if __BITS_PER_LONG == 64
+ long msg_stime; /* last msgsnd time */
+ long msg_rtime; /* last msgrcv time */
+ long msg_ctime; /* last change time */
+#else
+#define HAVE_MSQID64_DS_TIME_HIGH
+ unsigned long msg_stime; /* last msgsnd time */
+ unsigned long msg_stime_high;
+ unsigned long msg_rtime; /* last msgrcv time */
+ unsigned long msg_rtime_high;
+ unsigned long msg_ctime; /* last change time */
+ unsigned long msg_ctime_high;
+#endif
+ unsigned long msg_cbytes; /* current number of bytes on queue */
+ unsigned long msg_qnum; /* number of messages in queue */
+ unsigned long msg_qbytes; /* max number of bytes on queue */
+ __kernel_pid_t msg_lspid; /* pid of last msgsnd */
+ __kernel_pid_t msg_lrpid; /* last receive pid */
+ unsigned long __unused4;
+ unsigned long __unused5;
+};
+
+#endif /* msqid64_ds */
+
+#endif /* HAVE_MSQID64_DS */
+
+#endif /* IPC_MSGBUF_H */
diff --git a/kernel/tests/include/lapi/namespaces_constants.h b/kernel/tests/include/lapi/namespaces_constants.h
new file mode 100644
index 0000000..8f73c43
--- /dev/null
+++ b/kernel/tests/include/lapi/namespaces_constants.h
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2015 Red Hat, Inc.
+ */
+
+#ifndef __NAMESPACES_CONSTANTS_H__
+#define __NAMESPACES_CONSTANTS_H__
+
+#ifndef CLONE_NEWIPC
+# define CLONE_NEWIPC 0x08000000
+#endif
+#ifndef CLONE_NEWNS
+# define CLONE_NEWNS 0x00020000
+#endif
+#ifndef CLONE_NEWNET
+# define CLONE_NEWNET 0x40000000
+#endif
+#ifndef CLONE_NEWPID
+# define CLONE_NEWPID 0x20000000
+#endif
+#ifndef CLONE_NEWUSER
+# define CLONE_NEWUSER 0x10000000
+#endif
+#ifndef CLONE_NEWUTS
+# define CLONE_NEWUTS 0x04000000
+#endif
+#ifndef CLONE_NEWTIME
+# define CLONE_NEWTIME 0x00000080
+#endif
+
+#endif /* __NAMESPACES_CONSTANTS_H__ */
diff --git a/kernel/tests/include/lapi/netinet_in.h b/kernel/tests/include/lapi/netinet_in.h
new file mode 100644
index 0000000..e88485c
--- /dev/null
+++ b/kernel/tests/include/lapi/netinet_in.h
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
+ */
+
+#ifndef LAPI_IN_H__
+#define LAPI_IN_H__
+
+#include <netinet/in.h>
+
+#ifndef IPPROTO_DCCP
+#define IPPROTO_DCCP 33
+#endif
+
+#ifndef IPPROTO_UDPLITE
+# define IPPROTO_UDPLITE 136 /* UDP-Lite (RFC 3828) */
+#endif
+
+#ifndef IP_BIND_ADDRESS_NO_PORT
+# define IP_BIND_ADDRESS_NO_PORT 24
+#endif
+
+#endif /* LAPI_IN_H__ */
diff --git a/kernel/tests/include/lapi/openat2.h b/kernel/tests/include/lapi/openat2.h
new file mode 100644
index 0000000..62da1a0
--- /dev/null
+++ b/kernel/tests/include/lapi/openat2.h
@@ -0,0 +1,72 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Linaro Limited. All rights reserved.
+ * Author: Viresh Kumar <viresh.kumar@linaro.org>
+ */
+
+#ifndef OPENAT2_H
+#define OPENAT2_H
+
+#include <sys/syscall.h>
+#include <linux/types.h>
+
+#include "lapi/syscalls.h"
+
+#include "config.h"
+
+#ifndef HAVE_OPENAT2
+/*
+ * Arguments for how openat2(2) should open the target path. If only @flags and
+ * @mode are non-zero, then openat2(2) operates very similarly to openat(2).
+ *
+ * However, unlike openat(2), unknown or invalid bits in @flags result in
+ * -EINVAL rather than being silently ignored. @mode must be zero unless one of
+ * {O_CREAT, O_TMPFILE} are set.
+ *
+ * @flags: O_* flags.
+ * @mode: O_CREAT/O_TMPFILE file mode.
+ * @resolve: RESOLVE_* flags.
+ */
+struct open_how {
+ uint64_t flags;
+ uint64_t mode;
+ uint64_t resolve;
+};
+
+/* how->resolve flags for openat2(2). */
+#define RESOLVE_NO_XDEV 0x01 /* Block mount-point crossings
+ (includes bind-mounts). */
+#define RESOLVE_NO_MAGICLINKS 0x02 /* Block traversal through procfs-style
+ "magic-links". */
+#define RESOLVE_NO_SYMLINKS 0x04 /* Block traversal through all symlinks
+ (implies OEXT_NO_MAGICLINKS) */
+#define RESOLVE_BENEATH 0x08 /* Block "lexical" trickery like
+ "..", symlinks, and absolute
+ paths which escape the dirfd. */
+#define RESOLVE_IN_ROOT 0x10 /* Make all jumps to "/" and ".."
+ be scoped inside the dirfd
+ (similar to chroot(2)). */
+
+int openat2(int dfd, const char *pathname, struct open_how *how, size_t size)
+{
+ return tst_syscall(__NR_openat2, dfd, pathname, how, size);
+}
+#endif
+
+struct open_how_pad {
+ /* how should be kept as the first entry here */
+ struct open_how how;
+ uint64_t pad;
+};
+
+void openat2_supported_by_kernel(void)
+{
+ if ((tst_kvercmp(5, 6, 0)) < 0) {
+ /* Check if the syscall is backported on an older kernel */
+ TEST(syscall(__NR_openat2, -1, NULL, NULL, 0));
+ if (TST_RET == -1 && TST_ERR == ENOSYS)
+ tst_brk(TCONF, "Test not supported on kernel version < v5.6");
+ }
+}
+
+#endif /* OPENAT2_H */
diff --git a/kernel/tests/include/lapi/personality.h b/kernel/tests/include/lapi/personality.h
new file mode 100644
index 0000000..6b4b7eb
--- /dev/null
+++ b/kernel/tests/include/lapi/personality.h
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2017 Richard Palethorpe <rpalethorpe@suse.com>
+ */
+
+/* In the Linux kernel and glibc enums are (mostly) used for the constants,
+ * but in musl macros are used.
+ */
+
+#ifndef PERSONALITY_H
+#define PERSONALITY_H
+
+#include <sys/personality.h>
+
+#ifndef UNAME26
+# define UNAME26 0x0020000
+#endif
+
+#ifndef READ_IMPLIES_EXEC
+# define READ_IMPLIES_EXEC 0x0400000
+#endif
+
+#endif /* PERSONALITY_H */
diff --git a/kernel/tests/include/lapi/pidfd_open.h b/kernel/tests/include/lapi/pidfd_open.h
new file mode 100644
index 0000000..9f532f8
--- /dev/null
+++ b/kernel/tests/include/lapi/pidfd_open.h
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Linaro Limited. All rights reserved.
+ * Author: Viresh Kumar <viresh.kumar@linaro.org>
+ */
+
+#ifndef PIDFD_OPEN_H
+#define PIDFD_OPEN_H
+
+#include <sys/syscall.h>
+#include <sys/types.h>
+
+#include "lapi/syscalls.h"
+
+#include "config.h"
+
+#ifndef HAVE_PIDFD_OPEN
+int pidfd_open(pid_t pid, unsigned int flags)
+{
+ return tst_syscall(__NR_pidfd_open, pid, flags);
+}
+#endif
+
+#endif /* PIDFD_OPEN_H */
diff --git a/kernel/tests/include/lapi/pidfd_send_signal.h b/kernel/tests/include/lapi/pidfd_send_signal.h
new file mode 100644
index 0000000..8352d2a
--- /dev/null
+++ b/kernel/tests/include/lapi/pidfd_send_signal.h
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 SUSE LLC
+ * Author: Christian Amann <camann@suse.com>
+ */
+
+#ifndef PIDFD_SEND_SIGNAL_H
+#define PIDFD_SEND_SIGNAL_H
+
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+
+static inline void pidfd_send_signal_supported(void)
+{
+ /* allow the tests to fail early */
+ tst_syscall(__NR_pidfd_send_signal);
+}
+
+#ifndef HAVE_PIDFD_SEND_SIGNAL
+static int pidfd_send_signal(int pidfd, int sig, siginfo_t *info,
+ unsigned int flags)
+{
+ return tst_syscall(__NR_pidfd_send_signal, pidfd, sig, info, flags);
+}
+#endif /* HAVE_PIDFD_SEND_SIGNAL */
+
+#endif /* PIDFD_SEND_SIGNAL_H */
diff --git a/kernel/tests/include/lapi/posix_clocks.h b/kernel/tests/include/lapi/posix_clocks.h
new file mode 100644
index 0000000..ae2139f
--- /dev/null
+++ b/kernel/tests/include/lapi/posix_clocks.h
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019, Linux Test Project
+ * Copyright (c) 2013 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#include <time.h>
+
+#ifndef POSIX_CLOCKS_H__
+#define POSIX_CLOCKS_H__
+
+#define MAX_CLOCKS 16
+
+#ifndef CLOCK_MONOTONIC_RAW
+# define CLOCK_MONOTONIC_RAW 4
+#endif
+
+#ifndef CLOCK_REALTIME_COARSE
+# define CLOCK_REALTIME_COARSE 5
+#endif
+
+#ifndef CLOCK_MONOTONIC_COARSE
+# define CLOCK_MONOTONIC_COARSE 6
+#endif
+
+#ifndef CLOCK_BOOTTIME
+# define CLOCK_BOOTTIME 7
+#endif
+
+#ifndef CLOCK_REALTIME_ALARM
+# define CLOCK_REALTIME_ALARM 8
+#endif
+
+#ifndef CLOCK_BOOTTIME_ALARM
+# define CLOCK_BOOTTIME_ALARM 9
+#endif
+
+#ifndef CLOCK_TAI
+#define CLOCK_TAI 11
+#endif
+
+#endif /* POSIX_CLOCKS_H__ */
diff --git a/kernel/tests/include/lapi/posix_types.h b/kernel/tests/include/lapi/posix_types.h
new file mode 100644
index 0000000..9c0947c
--- /dev/null
+++ b/kernel/tests/include/lapi/posix_types.h
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Linux Test Project, 2014-2019
+ */
+
+#ifndef POSIX_TYPES_H__
+#define POSIX_TYPES_H__
+
+#include <linux/posix_types.h>
+
+#ifndef __kernel_long_t
+# if defined(__x86_64__) && defined(__ILP32__)
+typedef long long __kernel_long_t;
+typedef unsigned long long __kernel_ulong_t;
+# else
+typedef long __kernel_long_t;
+typedef unsigned long __kernel_ulong_t;
+# endif
+#endif
+
+#endif /* POSIX_TYPES_H__ */
diff --git a/kernel/tests/include/lapi/prctl.h b/kernel/tests/include/lapi/prctl.h
new file mode 100644
index 0000000..4499df0
--- /dev/null
+++ b/kernel/tests/include/lapi/prctl.h
@@ -0,0 +1,55 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
+ * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
+ */
+
+#ifndef LAPI_PRCTL_H__
+# define LAPI_PRCTL_H__
+
+#include <sys/prctl.h>
+
+#ifndef PR_SET_NAME
+# define PR_SET_NAME 15
+# define PR_GET_NAME 16
+#endif
+
+#ifndef PR_SET_SECCOMP
+# define PR_GET_SECCOMP 21
+# define PR_SET_SECCOMP 22
+#endif
+
+#ifndef PR_SET_TIMERSLACK
+# define PR_SET_TIMERSLACK 29
+# define PR_GET_TIMERSLACK 30
+#endif
+
+#ifndef PR_SET_CHILD_SUBREAPER
+# define PR_SET_CHILD_SUBREAPER 36
+# define PR_GET_CHILD_SUBREAPER 37
+#endif
+
+#ifndef PR_SET_NO_NEW_PRIVS
+# define PR_SET_NO_NEW_PRIVS 38
+# define PR_GET_NO_NEW_PRIVS 39
+#endif
+
+#ifndef PR_SET_THP_DISABLE
+# define PR_SET_THP_DISABLE 41
+# define PR_GET_THP_DISABLE 42
+#endif
+
+#ifndef PR_CAP_AMBIENT
+# define PR_CAP_AMBIENT 47
+# define PR_CAP_AMBIENT_IS_SET 1
+# define PR_CAP_AMBIENT_RAISE 2
+# define PR_CAP_AMBIENT_LOWER 3
+# define PR_CAP_AMBIENT_CLEAR_ALL 4
+#endif
+
+#ifndef PR_GET_SPECULATION_CTRL
+# define PR_GET_SPECULATION_CTRL 52
+# define PR_SET_SPECULATION_CTRL 53
+#endif
+
+#endif /* LAPI_PRCTL_H__ */
diff --git a/kernel/tests/include/lapi/preadv2.h b/kernel/tests/include/lapi/preadv2.h
new file mode 100644
index 0000000..538ed72
--- /dev/null
+++ b/kernel/tests/include/lapi/preadv2.h
@@ -0,0 +1,30 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
+ * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
+ */
+
+#ifndef PREADV2_H
+#define PREADV2_H
+
+#include "config.h"
+#include "lapi/syscalls.h"
+
+#ifndef RWF_NOWAIT
+# define RWF_NOWAIT 0x00000008
+#endif
+
+#if !defined(HAVE_PREADV2)
+
+/* LO_HI_LONG taken from glibc */
+# define LO_HI_LONG(val) (long) (val), (long) (((uint64_t) (val)) >> 32)
+
+ssize_t preadv2(int fd, const struct iovec *iov, int iovcnt, off_t offset,
+ int flags)
+{
+ return tst_syscall(__NR_preadv2, fd, iov, iovcnt,
+ LO_HI_LONG(offset), flags);
+}
+#endif
+
+#endif /* PREADV2_H */
diff --git a/kernel/tests/include/lapi/pwritev2.h b/kernel/tests/include/lapi/pwritev2.h
new file mode 100644
index 0000000..305e48e
--- /dev/null
+++ b/kernel/tests/include/lapi/pwritev2.h
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
+ * Author: Jinhui Huang <huangjh.jy@cn.fujitsu.com>
+ */
+
+#ifndef PWRITEV2_H
+#define PWRITEV2_H
+
+#include "config.h"
+#include "lapi/syscalls.h"
+
+#if !defined(HAVE_PWRITEV2)
+
+/* LO_HI_LONG taken from glibc */
+# define LO_HI_LONG(val) (long) (val), (long) (((uint64_t) (val)) >> 32)
+
+ssize_t pwritev2(int fd, const struct iovec *iov, int iovcnt, off_t offset,
+ int flags)
+{
+ return tst_syscall(__NR_pwritev2, fd, iov, iovcnt,
+ LO_HI_LONG(offset), flags);
+}
+#endif
+
+#endif /* PWRITEV2_H */
diff --git a/kernel/tests/include/lapi/quotactl.h b/kernel/tests/include/lapi/quotactl.h
new file mode 100644
index 0000000..c1ec9d6
--- /dev/null
+++ b/kernel/tests/include/lapi/quotactl.h
@@ -0,0 +1,78 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2017-2019 Fujitsu Ltd.
+ * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
+ * Author: Yang Xu <xuyang2018.jy@cn.jujitsu.com>
+ */
+
+#ifndef LAPI_QUOTACTL_H__
+#define LAPI_QUOTACTL_H__
+
+#include <sys/quota.h>
+
+#ifdef HAVE_STRUCT_IF_NEXTDQBLK
+# include <linux/quota.h>
+#else
+# include <stdint.h>
+struct if_nextdqblk {
+ uint64_t dqb_bhardlimit;
+ uint64_t dqb_bsoftlimit;
+ uint64_t dqb_curspace;
+ uint64_t dqb_ihardlimit;
+ uint64_t dqb_isoftlimit;
+ uint64_t dqb_curinodes;
+ uint64_t dqb_btime;
+ uint64_t dqb_itime;
+ uint32_t dqb_valid;
+ uint32_t dqb_id;
+};
+#endif /* HAVE_STRUCT_IF_NEXTDQBLK */
+
+#ifndef HAVE_STRUCT_FS_QUOTA_STATV
+# include <stdint.h>
+struct fs_qfilestatv {
+ uint64_t qfs_ino;
+ uint64_t qfs_nblks;
+ uint32_t qfs_nextents;
+ uint32_t qfs_pad;
+};
+
+struct fs_quota_statv {
+ int8_t qs_version;
+ uint8_t qs_pad1;
+ uint16_t qs_flags;
+ uint32_t qs_incoredqs;
+ struct fs_qfilestatv qs_uquota;
+ struct fs_qfilestatv qs_gquota;
+ struct fs_qfilestatv qs_pquota;
+ int32_t qs_btimelimit;
+ int32_t qs_itimelimit;
+ int32_t qs_rtbtimelimit;
+ uint16_t qs_bwarnlimit;
+ uint16_t qs_iwarnlimit;
+ uint64_t qs_pad2[8];
+};
+# define FS_QSTATV_VERSION1 1
+#endif /* HAVE_STRUCT_FS_QUOTA_STATV */
+
+#ifndef PRJQUOTA
+# define PRJQUOTA 2
+#endif
+
+#ifndef Q_XQUOTARM
+# define Q_XQUOTARM XQM_CMD(6)
+#endif
+
+#ifndef Q_XGETQSTATV
+# define Q_XGETQSTATV XQM_CMD(8)
+#endif
+
+#ifndef Q_XGETNEXTQUOTA
+# define Q_XGETNEXTQUOTA XQM_CMD(9)
+#endif
+
+#ifndef Q_GETNEXTQUOTA
+# define Q_GETNEXTQUOTA 0x800009 /* get disk limits and usage >= ID */
+#endif
+
+#endif /* LAPI_QUOTACTL_H__ */
diff --git a/kernel/tests/include/lapi/readdir.h b/kernel/tests/include/lapi/readdir.h
new file mode 100644
index 0000000..84e77ae
--- /dev/null
+++ b/kernel/tests/include/lapi/readdir.h
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2014 Fujitsu Ltd.
+ * Author: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
+ */
+
+#ifndef READDIR_H
+#define READDIR_H
+
+#include <limits.h>
+
+struct old_linux_dirent {
+ long d_ino; /* inode number */
+ off_t d_off; /* offset to this old_linux_dirent */
+ unsigned short d_reclen; /* length of this d_name */
+ char d_name[NAME_MAX+1]; /* filename (null-terminated) */
+};
+
+#endif /* READDIR_H */
diff --git a/kernel/tests/include/lapi/readlinkat.h b/kernel/tests/include/lapi/readlinkat.h
new file mode 100644
index 0000000..5a3a7b2
--- /dev/null
+++ b/kernel/tests/include/lapi/readlinkat.h
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2014 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#ifndef __READLINKAT_H__
+#define __READLINKAT_H__
+
+#include "config.h"
+#include "lapi/syscalls.h"
+#include "lapi/fcntl.h"
+
+#ifndef HAVE_READLINKAT
+int readlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz)
+{
+ return ltp_syscall(__NR_readlinkat, dirfd, pathname, buf, bufsiz);
+}
+#endif
+
+#endif /* __READLINKAT_H__ */
diff --git a/kernel/tests/include/lapi/renameat.h b/kernel/tests/include/lapi/renameat.h
new file mode 100644
index 0000000..66d3e21
--- /dev/null
+++ b/kernel/tests/include/lapi/renameat.h
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) International Business Machines Corp., 2007
+ * Copyright (c) 2014 Fujitsu Ltd.
+ */
+
+#ifndef RENAMEAT_H
+#define RENAMEAT_H
+
+#include <sys/types.h>
+#include "config.h"
+#include "lapi/syscalls.h"
+
+#if !defined(HAVE_RENAMEAT)
+int renameat(int olddirfd, const char *oldpath, int newdirfd,
+ const char *newpath)
+{
+ return ltp_syscall(__NR_renameat, olddirfd, oldpath, newdirfd,
+ newpath);
+}
+#endif
+
+#endif /* RENAMEAT_H */
diff --git a/kernel/tests/include/lapi/rt_sigaction.h b/kernel/tests/include/lapi/rt_sigaction.h
new file mode 100644
index 0000000..3af9136
--- /dev/null
+++ b/kernel/tests/include/lapi/rt_sigaction.h
@@ -0,0 +1,245 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2009 Cisco Systems, Inc. All Rights Reserved.
+ * Copyright (c) 2009 FUJITSU LIMITED. All Rights Reserved.
+ * Author: Liu Bo <liubo2009@cn.fujitsu.com>
+ * Author: Ngie Cooper <yaneurabeya@gmail.com>
+ */
+
+#ifndef LTP_RT_SIGACTION_H
+#define LTP_RT_SIGACTION_H
+
+#include "ltp_signal.h"
+
+#define INVAL_SA_PTR ((void *)-1)
+
+#if defined(__mips__)
+struct kernel_sigaction {
+ unsigned int sa_flags;
+ void (* k_sa_handler)(int);
+ sigset_t sa_mask;
+};
+#else
+struct kernel_sigaction {
+ void (* k_sa_handler)(int);
+ unsigned long sa_flags;
+ void (*sa_restorer) (void);
+ sigset_t sa_mask;
+};
+#endif
+
+/* This macro marks if (struct sigaction) has .sa_restorer member */
+#if !defined(__ia64__) && !defined(__alpha__) && !defined(__hppa__) && !defined(__mips__)
+# define HAVE_SA_RESTORER
+#endif
+
+#ifdef __x86_64__
+
+/*
+ * From asm/signal.h -- this value isn't exported anywhere outside of glibc and
+ * asm/signal.h and is only required for the rt_sig* function family because
+ * sigaction(2), et all, appends this if necessary to
+ * (struct sigaction).sa_flags. HEH.
+ *
+ * I do #undef though, just in case...
+ *
+ * Also, from .../arch/x86/kernel/signal.c:448 for v2.6.30 (something or
+ * other):
+ *
+ * x86-64 should always use SA_RESTORER.
+ *
+ * -- thus SA_RESTORER must always be defined along with
+ * (struct sigaction).sa_restorer for this architecture.
+ */
+#undef SA_RESTORER
+#define SA_RESTORER 0x04000000
+
+void (*restore_rt)(void);
+
+static void handler_h(int signal)
+{
+ return;
+}
+
+/* Setup an initial signal handler for signal number = sig for x86_64. */
+static inline int sig_initial(int sig)
+{
+ int ret_code = -1;
+ struct sigaction act, oact;
+
+ act.sa_handler = handler_h;
+ act.sa_flags = 0;
+ /* Clear out the signal set. */
+ if (sigemptyset(&act.sa_mask) < 0) {
+ /* Add the signal to the mask set. */
+ } else if (sigaddset(&act.sa_mask, sig) < 0) {
+ /* Set act.sa_restorer via syscall(2) */
+ } else if (sigaction(sig, &act, &oact) < 0) {
+ /* Copy oact.sa_restorer via syscall(2) */
+ } else if (sigaction(sig, &act, &oact) < 0) {
+ /* And voila -- we just tricked the kernel into giving us our
+ * restorer function! */
+ } else {
+ restore_rt = oact.sa_restorer;
+ ret_code = 0;
+ }
+
+ return ret_code;
+}
+
+#endif /* __x86_64__ */
+
+#ifdef __sparc__
+# if defined __arch64__ || defined __sparcv9
+
+/*
+ * Based on glibc/sysdeps/unix/sysv/linux/sparc/sparc64/sigaction.c
+ */
+
+extern char *__rt_sig_stub;
+
+static void __attribute__((used)) __rt_sigreturn_stub(void)
+{
+ __asm__ ("__rt_sig_stub: mov %0, %%g1\n\t"
+ "ta 0x6d\n\t"
+ : /* no outputs */
+ : "i" (__NR_rt_sigreturn));
+}
+
+# else /* sparc32 */
+
+/*
+ * Based on glibc/sysdeps/unix/sysv/linux/sparc/sparc32/sigaction.c
+ */
+
+extern char *__rt_sig_stub, *__sig_stub;
+
+static void __attribute__((used)) __rt_sigreturn_stub(void)
+{
+ __asm__ ("__rt_sig_stub: mov %0, %%g1\n\t"
+ "ta 0x10\n\t"
+ : /* no outputs */
+ : "i" (__NR_rt_sigreturn));
+}
+
+static void __attribute__((used)) __sigreturn_stub(void)
+{
+ __asm__ ("__sig_stub: mov %0, %%g1\n\t"
+ "ta 0x10\n\t"
+ : /* no outputs */
+ : "i" (__NR_sigreturn));
+}
+
+# endif
+#endif /* __sparc__ */
+
+#ifdef __arc__
+
+#undef SA_RESTORER
+#define SA_RESTORER 0x04000000
+
+/*
+ * based on uClibc/libc/sysdeps/linux/arc/sigaction.c
+ */
+static void
+__attribute__ ((optimize("Os"))) __attribute__((used)) restore_rt(void)
+{
+ __asm__ (
+ "mov r8, %0 \n\t"
+#ifdef __ARCHS__
+ "trap_s 0 \n\t"
+#else
+ "trap0 \n\t"
+#endif
+ : /* no outputs */
+ : "i" (__NR_rt_sigreturn)
+ : "r8");
+}
+#endif
+
+#ifdef TST_TEST_H__
+# define TST_SYSCALL tst_syscall
+#else
+# define TST_SYSCALL ltp_syscall
+#endif
+
+/* This is a wrapper for __NR_rt_sigaction syscall.
+ * act/oact values of INVAL_SA_PTR is used to pass
+ * an invalid pointer to syscall(__NR_rt_sigaction)
+ *
+ * Based on glibc/sysdeps/unix/sysv/linux/{...}/sigaction.c
+ */
+
+static int ltp_rt_sigaction(int signum, const struct sigaction *act,
+ struct sigaction *oact, size_t sigsetsize)
+{
+ int ret;
+ struct kernel_sigaction kact, koact;
+ struct kernel_sigaction *kact_p = NULL;
+ struct kernel_sigaction *koact_p = NULL;
+
+ if (act == INVAL_SA_PTR) {
+ kact_p = INVAL_SA_PTR;
+ } else if (act) {
+ kact.k_sa_handler = act->sa_handler;
+ memcpy(&kact.sa_mask, &act->sa_mask, sizeof(sigset_t));
+ kact.sa_flags = act->sa_flags;
+#ifndef __mips__
+ kact.sa_restorer = NULL;
+#endif
+ kact_p = &kact;
+ }
+
+ if (oact == INVAL_SA_PTR)
+ koact_p = INVAL_SA_PTR;
+ else if (oact)
+ koact_p = &koact;
+
+#ifdef __x86_64__
+ sig_initial(signum);
+#endif
+
+#if defined __x86_64__ || defined __arc__
+ kact.sa_flags |= SA_RESTORER;
+ kact.sa_restorer = restore_rt;
+#endif
+
+#ifdef __sparc__
+ unsigned long stub = 0;
+# if defined __arch64__ || defined __sparcv9
+ stub = ((unsigned long) &__rt_sig_stub) - 8;
+# else /* sparc32 */
+ if ((kact.sa_flags & SA_SIGINFO) != 0)
+ stub = ((unsigned long) &__rt_sig_stub) - 8;
+ else
+ stub = ((unsigned long) &__sig_stub) - 8;
+# endif
+#endif
+
+
+#ifdef __sparc__
+ ret = TST_SYSCALL(__NR_rt_sigaction, signum,
+ kact_p, koact_p,
+ stub, sigsetsize);
+#else
+ ret = TST_SYSCALL(__NR_rt_sigaction, signum,
+ kact_p, koact_p,
+ sigsetsize);
+#endif
+
+ if (ret >= 0) {
+ if (oact && (oact != INVAL_SA_PTR)) {
+ oact->sa_handler = koact.k_sa_handler;
+ memcpy(&oact->sa_mask, &koact.sa_mask,
+ sizeof(sigset_t));
+ oact->sa_flags = koact.sa_flags;
+#ifdef HAVE_SA_RESTORER
+ oact->sa_restorer = koact.sa_restorer;
+#endif
+ }
+ }
+
+ return ret;
+}
+
+#endif /* LTP_RT_SIGACTION_H */
diff --git a/kernel/tests/include/lapi/safe_rt_signal.h b/kernel/tests/include/lapi/safe_rt_signal.h
new file mode 100644
index 0000000..67fa444
--- /dev/null
+++ b/kernel/tests/include/lapi/safe_rt_signal.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2018 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#ifndef SAFE_RT_SIGNAL_H__
+#define SAFE_RT_SIGNAL_H__
+
+#include <signal.h>
+#include "lapi/rt_sigaction.h"
+
+static inline int safe_rt_sigaction(const char *file, const int lineno,
+ int signum, const struct sigaction *act,
+ struct sigaction *oact, size_t sigsetsize)
+{
+ int ret;
+
+ ret = ltp_rt_sigaction(signum, act, oact, sigsetsize);
+ if (ret < 0) {
+ tst_brk(TBROK | TERRNO,
+ "%s:%d: ltp_rt_sigaction(%i, %p, %p, %zu) failed",
+ file, lineno, signum, act, oact, sigsetsize);
+ }
+
+ return ret;
+}
+
+#define SAFE_RT_SIGACTION(signum, act, oldact, sigsetsize) \
+ safe_rt_sigaction(__FILE__, __LINE__, signum, act, oldact, sigsetsize)
+
+
+static inline int safe_rt_sigprocmask(const char *file, const int lineno,
+ int how, const sigset_t *set,
+ sigset_t *oldset, size_t sigsetsize)
+{
+ int ret;
+
+ ret = tst_syscall(__NR_rt_sigprocmask, how, set, oldset, sigsetsize);
+ if (ret < 0) {
+ tst_brk(TBROK | TERRNO,
+ "%s:%d: rt_sigprocmask(%i, %p, %p, %zu) failed",
+ file, lineno, how, set, oldset, sigsetsize);
+ }
+
+ return ret;
+}
+
+#define SAFE_RT_SIGPROCMASK(how, set, oldset, sigsetsize) \
+ safe_rt_sigprocmask(__FILE__, __LINE__, how, set, oldset, sigsetsize)
+
+#endif /* SAFE_RT_SIGNAL_H__ */
diff --git a/kernel/tests/include/lapi/sched.h b/kernel/tests/include/lapi/sched.h
new file mode 100644
index 0000000..26fe445
--- /dev/null
+++ b/kernel/tests/include/lapi/sched.h
@@ -0,0 +1,62 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2015 Cui Bixuan <cuibixuan@huawei.com>
+ */
+
+#ifndef __SCHED_H__
+#define __SCHED_H__
+
+#include "lapi/syscalls.h"
+#include <stdint.h>
+#include <inttypes.h>
+
+struct sched_attr {
+ uint32_t size;
+
+ uint32_t sched_policy;
+ uint64_t sched_flags;
+
+ /* SCHED_NORMAL, SCHED_BATCH */
+ int32_t sched_nice;
+
+ /* SCHED_FIFO, SCHED_RR */
+ uint32_t sched_priority;
+
+ /* SCHED_DEADLINE (nsec) */
+ uint64_t sched_runtime;
+ uint64_t sched_deadline;
+ uint64_t sched_period;
+};
+
+int sched_setattr(pid_t pid,
+ const struct sched_attr *attr,
+ unsigned int flags)
+{
+ return syscall(__NR_sched_setattr, pid, attr, flags);
+}
+
+int sched_getattr(pid_t pid,
+ struct sched_attr *attr,
+ unsigned int size,
+ unsigned int flags)
+{
+ return syscall(__NR_sched_getattr, pid, attr, size, flags);
+}
+
+#ifndef CLONE_VM
+#define CLONE_VM 0x00000100
+#endif
+
+#ifndef CLONE_FS
+#define CLONE_FS 0x00000200
+#endif
+
+#ifndef CLONE_SYSVSEM
+#define CLONE_SYSVSEM 0x00040000
+#endif
+
+#ifndef CLONE_IO
+#define CLONE_IO 0x80000000
+#endif
+
+#endif /* __SCHED_H__ */
diff --git a/kernel/tests/include/lapi/sctp.h b/kernel/tests/include/lapi/sctp.h
new file mode 100644
index 0000000..c4c1cc9
--- /dev/null
+++ b/kernel/tests/include/lapi/sctp.h
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2018 Oracle and/or its affiliates.
+ */
+
+#ifndef LAPI_SCTP_H__
+#define LAPI_SCTP_H__
+
+#ifdef HAVE_NETINET_SCTP_H
+# include <netinet/sctp.h>
+#endif
+
+#ifndef SCTP_SOCKOPT_BINDX_ADD
+# define SCTP_SOCKOPT_BINDX_ADD 100
+#endif
+
+#endif /* LAPI_SCTP_H__ */
diff --git a/kernel/tests/include/lapi/seccomp.h b/kernel/tests/include/lapi/seccomp.h
new file mode 100644
index 0000000..fe95cab
--- /dev/null
+++ b/kernel/tests/include/lapi/seccomp.h
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
+ */
+#ifndef LAPI_SECCOMP_H
+#define LAPI_SECCOMP_H
+
+#include <stdint.h>
+
+#ifdef HAVE_LINUX_SECCOMP_H
+# include <linux/seccomp.h>
+#else
+/* Valid values for seccomp.mode and prctl(PR_SET_SECCOMP, <mode>) */
+# define SECCOMP_MODE_DISABLED 0
+# define SECCOMP_MODE_STRICT 1
+# define SECCOMP_MODE_FILTER 2
+
+# define SECCOMP_RET_KILL_THREAD 0x00000000U /* kill the thread */
+# define SECCOMP_RET_KILL SECCOMP_RET_KILL_THREAD
+# define SECCOMP_RET_ALLOW 0x7fff0000U /* allow */
+
+/**
+ * struct seccomp_data - the format the BPF program executes over.
+ * @nr: the system call number
+ * @arch: indicates system call convention as an AUDIT_ARCH_* value
+ * as defined in <linux/audit.h>.
+ * @instruction_pointer: at the time of the system call.
+ * @args: up to 6 system call arguments always stored as 64-bit values
+ * regardless of the architecture.
+ */
+struct seccomp_data {
+ int nr;
+ uint32_t arch;
+ uint64_t instruction_pointer;
+ uint64_t args[6];
+};
+
+#endif /* HAVE_LINUX_SECCOMP_H*/
+#endif /* LAPI_SECCOMP_H */
diff --git a/kernel/tests/include/lapi/securebits.h b/kernel/tests/include/lapi/securebits.h
new file mode 100644
index 0000000..2da137c
--- /dev/null
+++ b/kernel/tests/include/lapi/securebits.h
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
+ */
+#ifndef LAPI_SECUREBITS_H
+#define LAPI_SECUREBITS_H
+
+# ifdef HAVE_LINUX_SECUREBITS_H
+# include <linux/securebits.h>
+# endif
+
+# ifndef SECBIT_NO_CAP_AMBIENT_RAISE
+# define SECBIT_NO_CAP_AMBIENT_RAISE 6
+# endif
+
+#endif /* LAPI_SECUREBITS_H */
diff --git a/kernel/tests/include/lapi/seek.h b/kernel/tests/include/lapi/seek.h
new file mode 100644
index 0000000..1a29ba4
--- /dev/null
+++ b/kernel/tests/include/lapi/seek.h
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#ifndef SEEK_H__
+#define SEEK_H__
+
+#include <unistd.h>
+
+#ifndef SEEK_DATA
+# define SEEK_DATA 3
+#endif
+
+#ifndef SEEK_HOLE
+# define SEEK_HOLE 4
+#endif
+
+#endif /* SEEK_H__ */
diff --git a/kernel/tests/include/lapi/sembuf.h b/kernel/tests/include/lapi/sembuf.h
new file mode 100644
index 0000000..4ef0483
--- /dev/null
+++ b/kernel/tests/include/lapi/sembuf.h
@@ -0,0 +1,234 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Linaro Limited. All rights reserved.
+ * Author: Viresh Kumar <viresh.kumar@linaro.org>
+ */
+
+#ifndef IPC_SEMBUF_H
+#define IPC_SEMBUF_H
+
+#include "lapi/posix_types.h"
+#include <sys/sem.h>
+#include "tst_timer.h"
+#include "ipcbuf.h"
+
+#ifndef HAVE_SEMID64_DS
+
+#if defined(__mips__)
+#define HAVE_SEMID64_DS
+/*
+ * The semid64_ds structure for the MIPS architecture.
+ * Note extra padding because this structure is passed back and forth
+ * between kernel and user space.
+ *
+ * Pad space is left for 2 miscellaneous 64-bit values on mips64,
+ * but used for the upper 32 bit of the time values on mips32.
+ */
+#if defined(__arch64__)
+struct semid64_ds {
+ struct ipc64_perm sem_perm; /* permissions .. see ipc.h */
+ long sem_otime; /* last semop time */
+ long sem_ctime; /* last change time */
+ unsigned long sem_nsems; /* no. of semaphores in array */
+ unsigned long __unused1;
+ unsigned long __unused2;
+};
+#else
+#define HAVE_SEMID64_DS_TIME_HIGH
+struct semid64_ds {
+ struct ipc64_perm sem_perm; /* permissions .. see ipc.h */
+ unsigned long sem_otime; /* last semop time */
+ unsigned long sem_ctime; /* last change time */
+ unsigned long sem_nsems; /* no. of semaphores in array */
+ unsigned long sem_otime_high;
+ unsigned long sem_ctime_high;
+};
+#endif
+#endif /* __mips__ */
+
+#if defined(__hppa__)
+#define HAVE_SEMID64_DS
+/*
+ * The semid64_ds structure for parisc architecture.
+ * Note extra padding because this structure is passed back and forth
+ * between kernel and user space.
+ *
+ * Pad space is left for:
+ * - 2 miscellaneous 32-bit values
+ */
+struct semid64_ds {
+ struct ipc64_perm sem_perm; /* permissions .. see ipc.h */
+#if __BITS_PER_LONG == 64
+ long sem_otime; /* last semop time */
+ long sem_ctime; /* last change time */
+#else
+#define HAVE_SEMID64_DS_TIME_HIGH
+ unsigned long sem_otime_high;
+ unsigned long sem_otime; /* last semop time */
+ unsigned long sem_ctime_high;
+ unsigned long sem_ctime; /* last change time */
+#endif
+ unsigned long sem_nsems; /* no. of semaphores in array */
+ unsigned long __unused1;
+ unsigned long __unused2;
+};
+#endif /* __hppa__ */
+
+#if defined(__powerpc__) || defined(__powerpc64__)
+#define HAVE_SEMID64_DS
+/*
+ * The semid64_ds structure for PPC architecture.
+ * Note extra padding because this structure is passed back and forth
+ * between kernel and user space.
+ *
+ * Pad space is left for:
+ * - 2 miscellaneous 32/64-bit values
+ */
+
+struct semid64_ds {
+ struct ipc64_perm sem_perm; /* permissions .. see ipc.h */
+#ifndef __powerpc64__
+#define HAVE_SEMID64_DS_TIME_HIGH
+ unsigned long sem_otime_high;
+ unsigned long sem_otime; /* last semop time */
+ unsigned long sem_ctime_high;
+ unsigned long sem_ctime; /* last change time */
+#else
+ long sem_otime; /* last semop time */
+ long sem_ctime; /* last change time */
+#endif
+ unsigned long sem_nsems; /* no. of semaphores in array */
+ unsigned long __unused3;
+ unsigned long __unused4;
+};
+#endif /* defined(__powerpc__) || defined(__powerpc64__) */
+
+#if defined(__sparc__)
+#define HAVE_SEMID64_DS
+/*
+ * The semid64_ds structure for sparc architecture.
+ * Note extra padding because this structure is passed back and forth
+ * between kernel and user space.
+ *
+ * Pad space is left for:
+ * - 2 miscellaneous 32-bit values
+ */
+
+struct semid64_ds {
+ struct ipc64_perm sem_perm; /* permissions .. see ipc.h */
+#if defined(__arch64__)
+ long sem_otime; /* last semop time */
+ long sem_ctime; /* last change time */
+#else
+#define HAVE_SEMID64_DS_TIME_HIGH
+ unsigned long sem_otime_high;
+ unsigned long sem_otime; /* last semop time */
+ unsigned long sem_ctime_high;
+ unsigned long sem_ctime; /* last change time */
+#endif
+ unsigned long sem_nsems; /* no. of semaphores in array */
+ unsigned long __unused1;
+ unsigned long __unused2;
+};
+#endif /* __sparc__ */
+
+#if defined(__x86_64__)
+#define HAVE_SEMID64_DS
+/*
+ * The semid64_ds structure for x86 architecture.
+ * Note extra padding because this structure is passed back and forth
+ * between kernel and user space.
+ *
+ * Pad space is left for:
+ * - 2 miscellaneous 32-bit values
+ *
+ * x86_64 and x32 incorrectly added padding here, so the structures
+ * are still incompatible with the padding on x86.
+ */
+struct semid64_ds {
+ struct ipc64_perm sem_perm; /* permissions .. see ipc.h */
+#ifdef __i386__
+#define HAVE_SEMID64_DS_TIME_HIGH
+ unsigned long sem_otime; /* last semop time */
+ unsigned long sem_otime_high;
+ unsigned long sem_ctime; /* last change time */
+ unsigned long sem_ctime_high;
+#else
+ __kernel_long_t sem_otime; /* last semop time */
+ __kernel_ulong_t __unused1;
+ __kernel_long_t sem_ctime; /* last change time */
+ __kernel_ulong_t __unused2;
+#endif
+ __kernel_ulong_t sem_nsems; /* no. of semaphores in array */
+ __kernel_ulong_t __unused3;
+ __kernel_ulong_t __unused4;
+};
+#endif /* defined(__x86_64__) */
+
+#if defined(__xtensa__)
+#define HAVE_SEMID64_DS
+#define HAVE_SEMID64_DS_TIME_HIGH
+
+struct semid64_ds {
+ struct ipc64_perm sem_perm; /* permissions .. see ipc.h */
+#ifdef __XTENSA_EL__
+ unsigned long sem_otime; /* last semop time */
+ unsigned long sem_otime_high;
+ unsigned long sem_ctime; /* last change time */
+ unsigned long sem_ctime_high;
+#else
+ unsigned long sem_otime_high;
+ unsigned long sem_otime; /* last semop time */
+ unsigned long sem_ctime_high;
+ unsigned long sem_ctime; /* last change time */
+#endif
+ unsigned long sem_nsems; /* no. of semaphores in array */
+ unsigned long __unused3;
+ unsigned long __unused4;
+};
+
+#endif /* __xtensa__ */
+
+#ifndef HAVE_SEMID64_DS
+/*
+ * The semid64_ds structure for most architectures (though it came
+ * from x86_32 originally). Note extra padding because this structure
+ * is passed back and forth between kernel and user space.
+ *
+ * semid64_ds was originally meant to be architecture specific, but
+ * everyone just ended up making identical copies without specific
+ * optimizations, so we may just as well all use the same one.
+ *
+ * 64 bit architectures use a 64-bit long time field here, while
+ * 32 bit architectures have a pair of unsigned long values.
+ *
+ * On big-endian systems, the padding is in the wrong place for
+ * historic reasons, so user space has to reconstruct a time_t
+ * value using
+ *
+ * user_semid_ds.sem_otime = kernel_semid64_ds.sem_otime +
+ * ((long long)kernel_semid64_ds.sem_otime_high << 32)
+ *
+ * Pad space is left for 2 miscellaneous 32-bit values
+ */
+struct semid64_ds {
+ struct ipc64_perm sem_perm; /* permissions .. see ipc.h */
+#if __BITS_PER_LONG == 64
+ long sem_otime; /* last semop time */
+ long sem_ctime; /* last change time */
+#else
+#define HAVE_SEMID64_DS_TIME_HIGH
+ unsigned long sem_otime; /* last semop time */
+ unsigned long sem_otime_high;
+ unsigned long sem_ctime; /* last change time */
+ unsigned long sem_ctime_high;
+#endif
+ unsigned long sem_nsems; /* no. of semaphores in array */
+ unsigned long __unused3;
+ unsigned long __unused4;
+};
+#endif /* semid64_ds */
+
+#endif /* HAVE_SEMID64_DS */
+
+#endif /* IPC_SEMBUF_H */
diff --git a/kernel/tests/include/lapi/semun.h b/kernel/tests/include/lapi/semun.h
new file mode 100644
index 0000000..1a9dc98
--- /dev/null
+++ b/kernel/tests/include/lapi/semun.h
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2015 Linux Test Project
+ */
+
+#ifndef SEMUN_H__
+#define SEMUN_H__
+
+#if defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)
+/* union semun is defined by including <sys/sem.h> */
+#else
+/* according to X/OPEN we have to define it ourselves */
+union semun {
+ int val; /* value for SETVAL */
+ struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */
+ unsigned short *array; /* array for GETALL, SETALL */
+ /* Linux specific part: */
+ struct seminfo *__buf; /* buffer for IPC_INFO */
+};
+#endif
+
+#endif /* SEMUN_H__ */
diff --git a/kernel/tests/include/lapi/setns.h b/kernel/tests/include/lapi/setns.h
new file mode 100644
index 0000000..7b0a7af
--- /dev/null
+++ b/kernel/tests/include/lapi/setns.h
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ Copyright (c) 2020 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#ifndef LAPI_SETNS_H__
+#define LAPI_SETNS_H__
+
+#include "config.h"
+#include "lapi/syscalls.h"
+#include <sched.h>
+
+#ifndef HAVE_SETNS
+int setns(int fd, int nstype)
+{
+ return tst_syscall(__NR_setns, fd, nstype);
+}
+#endif
+
+#endif /* LAPI_SETNS_H__ */
diff --git a/kernel/tests/include/lapi/shm.h b/kernel/tests/include/lapi/shm.h
new file mode 100644
index 0000000..61c4e37
--- /dev/null
+++ b/kernel/tests/include/lapi/shm.h
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#ifndef LAPI_SHM_H__
+#define LAPI_SHM_H__
+
+#ifndef SHM_STAT_ANY
+# define SHM_STAT_ANY 15
+#endif
+
+#endif /* LAPI_SHM_H__ */
diff --git a/kernel/tests/include/lapi/shmbuf.h b/kernel/tests/include/lapi/shmbuf.h
new file mode 100644
index 0000000..28ee336
--- /dev/null
+++ b/kernel/tests/include/lapi/shmbuf.h
@@ -0,0 +1,273 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Linaro Limited. All rights reserved.
+ * Author: Viresh Kumar <viresh.kumar@linaro.org>
+ */
+
+#ifndef IPC_SHMBUF_H
+#define IPC_SHMBUF_H
+
+#include "lapi/posix_types.h"
+#include <sys/sem.h>
+#include "tst_timer.h"
+#include "ipcbuf.h"
+
+#ifndef HAVE_SHMID64_DS
+
+#if defined(__mips__)
+#define HAVE_SHMID64_DS
+/*
+ * The shmid64_ds structure for the MIPS architecture.
+ * Note extra padding because this structure is passed back and forth
+ * between kernel and user space.
+ *
+ * As MIPS was lacking proper padding after shm_?time, we use 48 bits
+ * of the padding at the end to store a few additional bits of the time.
+ * libc implementations need to take care to convert this into a proper
+ * data structure when moving to 64-bit time_t.
+ */
+
+#if defined(__arch64__)
+struct shmid64_ds {
+ struct ipc64_perm shm_perm; /* operation perms */
+ size_t shm_segsz; /* size of segment (bytes) */
+ long shm_atime; /* last attach time */
+ long shm_dtime; /* last detach time */
+ long shm_ctime; /* last change time */
+ __kernel_pid_t shm_cpid; /* pid of creator */
+ __kernel_pid_t shm_lpid; /* pid of last operator */
+ unsigned long shm_nattch; /* no. of current attaches */
+ unsigned long __unused1;
+ unsigned long __unused2;
+};
+#else
+#define HAVE_SHMID64_DS_TIME_HIGH
+struct shmid64_ds {
+ struct ipc64_perm shm_perm; /* operation perms */
+ size_t shm_segsz; /* size of segment (bytes) */
+ unsigned long shm_atime; /* last attach time */
+ unsigned long shm_dtime; /* last detach time */
+ unsigned long shm_ctime; /* last change time */
+ __kernel_pid_t shm_cpid; /* pid of creator */
+ __kernel_pid_t shm_lpid; /* pid of last operator */
+ unsigned long shm_nattch; /* no. of current attaches */
+ unsigned short shm_atime_high;
+ unsigned short shm_dtime_high;
+ unsigned short shm_ctime_high;
+ unsigned short __unused1;
+};
+#endif
+
+#endif /* __mips__ */
+
+#if defined(__hppa__)
+#define HAVE_SHMID64_DS
+/*
+ * The shmid64_ds structure for parisc architecture.
+ * Note extra padding because this structure is passed back and forth
+ * between kernel and user space.
+ *
+ * Pad space is left for:
+ * - 2 miscellaneous 32-bit values
+ */
+
+struct shmid64_ds {
+ struct ipc64_perm shm_perm; /* operation perms */
+#if __BITS_PER_LONG == 64
+ long shm_atime; /* last attach time */
+ long shm_dtime; /* last detach time */
+ long shm_ctime; /* last change time */
+#else
+#define HAVE_SHMID64_DS_TIME_HIGH
+ unsigned long shm_atime_high;
+ unsigned long shm_atime; /* last attach time */
+ unsigned long shm_dtime_high;
+ unsigned long shm_dtime; /* last detach time */
+ unsigned long shm_ctime_high;
+ unsigned long shm_ctime; /* last change time */
+ unsigned int __pad4;
+#endif
+ __kernel_size_t shm_segsz; /* size of segment (bytes) */
+ __kernel_pid_t shm_cpid; /* pid of creator */
+ __kernel_pid_t shm_lpid; /* pid of last operator */
+ unsigned long shm_nattch; /* no. of current attaches */
+ unsigned long __unused1;
+ unsigned long __unused2;
+};
+#endif /* __hppa__ */
+
+#if defined(__powerpc__) || defined(__powerpc64__)
+#define HAVE_SHMID64_DS
+/*
+ * The shmid64_ds structure for PPC architecture.
+ *
+ * Note extra padding because this structure is passed back and forth
+ * between kernel and user space.
+ *
+ * Pad space is left for:
+ * - 2 miscellaneous 32-bit values
+ */
+
+struct shmid64_ds {
+ struct ipc64_perm shm_perm; /* operation perms */
+#ifdef __powerpc64__
+ long shm_atime; /* last attach time */
+ long shm_dtime; /* last detach time */
+ long shm_ctime; /* last change time */
+#else
+#define HAVE_SHMID64_DS_TIME_HIGH
+ unsigned long shm_atime_high;
+ unsigned long shm_atime; /* last attach time */
+ unsigned long shm_dtime_high;
+ unsigned long shm_dtime; /* last detach time */
+ unsigned long shm_ctime_high;
+ unsigned long shm_ctime; /* last change time */
+ unsigned long __unused4;
+#endif
+ size_t shm_segsz; /* size of segment (bytes) */
+ __kernel_pid_t shm_cpid; /* pid of creator */
+ __kernel_pid_t shm_lpid; /* pid of last operator */
+ unsigned long shm_nattch; /* no. of current attaches */
+ unsigned long __unused5;
+ unsigned long __unused6;
+};
+
+#endif /* defined(__powerpc__) || defined(__powerpc64__) */
+
+#if defined(__sparc__)
+#define HAVE_SHMID64_DS
+/*
+ * The shmid64_ds structure for sparc architecture.
+ * Note extra padding because this structure is passed back and forth
+ * between kernel and user space.
+ *
+ * Pad space is left for:
+ * - 2 miscellaneous 32-bit values
+ */
+
+struct shmid64_ds {
+ struct ipc64_perm shm_perm; /* operation perms */
+#if defined(__arch64__)
+ long shm_atime; /* last attach time */
+ long shm_dtime; /* last detach time */
+ long shm_ctime; /* last change time */
+#else
+#define HAVE_SHMID64_DS_TIME_HIGH
+ unsigned long shm_atime_high;
+ unsigned long shm_atime; /* last attach time */
+ unsigned long shm_dtime_high;
+ unsigned long shm_dtime; /* last detach time */
+ unsigned long shm_ctime_high;
+ unsigned long shm_ctime; /* last change time */
+#endif
+ size_t shm_segsz; /* size of segment (bytes) */
+ __kernel_pid_t shm_cpid; /* pid of creator */
+ __kernel_pid_t shm_lpid; /* pid of last operator */
+ unsigned long shm_nattch; /* no. of current attaches */
+ unsigned long __unused1;
+ unsigned long __unused2;
+};
+
+#endif /* __sparc__ */
+
+#if defined(__x86_64__) && defined(__ILP32__)
+#define HAVE_SHMID64_DS
+/*
+ * The shmid64_ds structure for x86 architecture with x32 ABI.
+ *
+ * On x86-32 and x86-64 we can just use the generic definition, but
+ * x32 uses the same binary layout as x86_64, which is differnet
+ * from other 32-bit architectures.
+ */
+
+struct shmid64_ds {
+ struct ipc64_perm shm_perm; /* operation perms */
+ size_t shm_segsz; /* size of segment (bytes) */
+ __kernel_long_t shm_atime; /* last attach time */
+ __kernel_long_t shm_dtime; /* last detach time */
+ __kernel_long_t shm_ctime; /* last change time */
+ __kernel_pid_t shm_cpid; /* pid of creator */
+ __kernel_pid_t shm_lpid; /* pid of last operator */
+ __kernel_ulong_t shm_nattch; /* no. of current attaches */
+ __kernel_ulong_t __unused4;
+ __kernel_ulong_t __unused5;
+};
+#endif /* defined(__x86_64__) && defined(__ILP32__) */
+
+#if defined(__xtensa__)
+#define HAVE_SHMID64_DS
+#define HAVE_SHMID64_DS_TIME_HIGH
+/*
+ * The shmid64_ds structure for Xtensa architecture.
+ * Note extra padding because this structure is passed back and forth
+ * between kernel and user space, but the padding is on the wrong
+ * side for big-endian xtensa, for historic reasons.
+ *
+ * Pad space is left for:
+ * - 2 miscellaneous 32-bit values
+ */
+
+struct shmid64_ds {
+ struct ipc64_perm shm_perm; /* operation perms */
+ size_t shm_segsz; /* size of segment (bytes) */
+ unsigned long shm_atime; /* last attach time */
+ unsigned long shm_atime_high;
+ unsigned long shm_dtime; /* last detach time */
+ unsigned long shm_dtime_high;
+ unsigned long shm_ctime; /* last change time */
+ unsigned long shm_ctime_high;
+ __kernel_pid_t shm_cpid; /* pid of creator */
+ __kernel_pid_t shm_lpid; /* pid of last operator */
+ unsigned long shm_nattch; /* no. of current attaches */
+ unsigned long __unused4;
+ unsigned long __unused5;
+};
+
+#endif /* __xtensa__ */
+
+#ifndef HAVE_SHMID64_DS
+/*
+ * The shmid64_ds structure for most architectures (though it came
+ * from x86_32 originally). Note extra padding because this structure
+ * is passed back and forth between kernel and user space.
+ *
+ * shmid64_ds was originally meant to be architecture specific, but
+ * everyone just ended up making identical copies without specific
+ * optimizations, so we may just as well all use the same one.
+ *
+ * 64 bit architectures use a 64-bit long time field here, while
+ * 32 bit architectures have a pair of unsigned long values.
+ * On big-endian systems, the lower half is in the wrong place.
+ *
+ *
+ * Pad space is left for:
+ * - 2 miscellaneous 32-bit values
+ */
+
+struct shmid64_ds {
+ struct ipc64_perm shm_perm; /* operation perms */
+ size_t shm_segsz; /* size of segment (bytes) */
+#if __BITS_PER_LONG == 64
+ long shm_atime; /* last attach time */
+ long shm_dtime; /* last detach time */
+ long shm_ctime; /* last change time */
+#else
+#define HAVE_SHMID64_DS_TIME_HIGH
+ unsigned long shm_atime; /* last attach time */
+ unsigned long shm_atime_high;
+ unsigned long shm_dtime; /* last detach time */
+ unsigned long shm_dtime_high;
+ unsigned long shm_ctime; /* last change time */
+ unsigned long shm_ctime_high;
+#endif
+ __kernel_pid_t shm_cpid; /* pid of creator */
+ __kernel_pid_t shm_lpid; /* pid of last operator */
+ unsigned long shm_nattch; /* no. of current attaches */
+ unsigned long __unused4;
+ unsigned long __unused5;
+};
+#endif /* shmid64_ds */
+
+#endif /* HAVE_SHMID64_DS */
+
+#endif /* IPC_SHMBUF_H */
diff --git a/kernel/tests/include/lapi/signal.h b/kernel/tests/include/lapi/signal.h
new file mode 100644
index 0000000..d22965a
--- /dev/null
+++ b/kernel/tests/include/lapi/signal.h
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Linaro Limited. All rights reserved.
+ * Author: Daniel Díaz <daniel.diaz@linaro.org>
+ */
+
+#ifndef LAPI_SIGNAL_H
+#define LAPI_SIGNAL_H
+
+#include <signal.h>
+
+/*
+ * Some libc implementations might differ in the definitions they include. This
+ * covers those differences for all tests to successfully build.
+ */
+
+#ifndef __SIGRTMIN
+# define __SIGRTMIN 32
+#endif
+#ifndef __SIGRTMAX
+# define __SIGRTMAX (_NSIG - 1)
+#endif
+
+#endif
diff --git a/kernel/tests/include/lapi/socket.h b/kernel/tests/include/lapi/socket.h
new file mode 100644
index 0000000..d6389e5
--- /dev/null
+++ b/kernel/tests/include/lapi/socket.h
@@ -0,0 +1,72 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+* Copyright (c) 2016 Fujitsu Ltd.
+* Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
+*/
+
+#ifndef __LAPI_SOCKET_H__
+#define __LAPI_SOCKET_H__
+
+#include "config.h"
+#include <sys/socket.h>
+
+#ifndef MSG_ZEROCOPY
+# define MSG_ZEROCOPY 0x4000000 /* Use user data in kernel path */
+#endif
+
+#ifndef MSG_FASTOPEN
+# define MSG_FASTOPEN 0x20000000 /* Send data in TCP SYN */
+#endif
+
+#ifndef SO_REUSEPORT
+# define SO_REUSEPORT 15
+#endif
+
+#ifndef SO_BUSY_POLL
+# define SO_BUSY_POLL 46
+#endif
+
+#ifndef SO_ATTACH_BPF
+# define SO_ATTACH_BPF 50
+#endif
+
+#ifndef SO_ZEROCOPY
+# define SO_ZEROCOPY 60
+#endif
+
+#ifndef SOCK_DCCP
+# define SOCK_DCCP 6
+#endif
+
+#ifndef SOCK_CLOEXEC
+# define SOCK_CLOEXEC 02000000
+#endif
+
+#ifndef AF_ALG
+# define AF_ALG 38
+#endif
+
+#ifndef SOL_SCTP
+# define SOL_SCTP 132
+#endif
+
+#ifndef SOL_UDPLITE
+# define SOL_UDPLITE 136 /* UDP-Lite (RFC 3828) */
+#endif
+
+#ifndef SOL_DCCP
+# define SOL_DCCP 269
+#endif
+
+#ifndef SOL_ALG
+# define SOL_ALG 279
+#endif
+
+#ifndef HAVE_STRUCT_MMSGHDR
+struct mmsghdr {
+ struct msghdr msg_hdr;
+ unsigned int msg_len;
+};
+#endif
+
+#endif /* __LAPI_SOCKET_H__ */
diff --git a/kernel/tests/include/lapi/splice.h b/kernel/tests/include/lapi/splice.h
new file mode 100644
index 0000000..0cd6f55
--- /dev/null
+++ b/kernel/tests/include/lapi/splice.h
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) International Business Machines Corp., 2007
+ * Copyright (c) 2014 Fujitsu Ltd.
+ */
+
+#ifndef SPLICE_H
+#define SPLICE_H
+
+#include "config.h"
+#include "lapi/syscalls.h"
+
+#if !defined(HAVE_SPLICE)
+ssize_t splice(int fd_in, loff_t *off_in, int fd_out,
+ loff_t *off_out, size_t len, unsigned int flags)
+{
+ return tst_syscall(__NR_splice, fd_in, off_in,
+ fd_out, off_out, len, flags);
+}
+#endif
+
+#endif /* SPLICE_H */
diff --git a/kernel/tests/include/lapi/stat.h b/kernel/tests/include/lapi/stat.h
new file mode 100644
index 0000000..979e42d
--- /dev/null
+++ b/kernel/tests/include/lapi/stat.h
@@ -0,0 +1,257 @@
+//SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Referred from linux kernel -github/torvalds/linux/include/uapi/linux/fcntl.h
+ * Copyright (c) Zilogic Systems Pvt. Ltd., 2018
+ * Email: code@zilogic.com
+ */
+#ifndef LAPI_STAT_H
+#define LAPI_STAT_H
+
+#include <stdint.h>
+#include <unistd.h>
+#include "lapi/syscalls.h"
+/*
+ * Timestamp structure for the timestamps in struct statx.
+ *
+ * tv_sec holds the number of seconds before (negative) or after (positive)
+ * 00:00:00 1st January 1970 UTC.
+ *
+ * tv_nsec holds a number of nanoseconds (0..999,999,999) after the tv_sec time.
+ *
+ * __reserved is held in case we need a yet finer resolution.
+ */
+#if defined(HAVE_STRUCT_STATX_TIMESTAMP)
+#include <sys/stat.h>
+#else
+struct statx_timestamp {
+ int64_t tv_sec;
+ uint32_t tv_nsec;
+ int32_t __reserved;
+};
+#endif
+/*
+ * Structures for the extended file attribute retrieval system call
+ * (statx()).
+ *
+ * The caller passes a mask of what they're specifically interested in as a
+ * parameter to statx(). What statx() actually got will be indicated in
+ * st_mask upon return.
+ *
+ * For each bit in the mask argument:
+ *
+ * - if the datum is not supported:
+ *
+ * - the bit will be cleared, and
+ *
+ * - the datum will be set to an appropriate fabricated value if one is
+ * available (eg. CIFS can take a default uid and gid), otherwise
+ *
+ * - the field will be cleared;
+ *
+ * - otherwise, if explicitly requested:
+ *
+ * - the datum will be synchronised to the server if AT_STATX_FORCE_SYNC is
+ * set or if the datum is considered out of date, and
+ *
+ * - the field will be filled in and the bit will be set;
+ *
+ * - otherwise, if not requested, but available in approximate form without any
+ * effort, it will be filled in anyway, and the bit will be set upon return
+ * (it might not be up to date, however, and no attempt will be made to
+ * synchronise the internal state first);
+ *
+ * - otherwise the field and the bit will be cleared before returning.
+ *
+ * Items in STATX_BASIC_STATS may be marked unavailable on return, but they
+ * will have values installed for compatibility purposes so that stat() and
+ * co. can be emulated in userspace.
+ */
+#if defined(HAVE_STRUCT_STATX)
+#include <sys/stat.h>
+#else
+struct statx {
+ /* 0x00 */
+ uint32_t stx_mask;
+ uint32_t stx_blksize;
+ uint64_t stx_attributes;
+ /* 0x10 */
+ uint32_t stx_nlink;
+ uint32_t stx_uid;
+ uint32_t stx_gid;
+ uint16_t stx_mode;
+ uint16_t __spare0[1];
+ /* 0x20 */
+ uint64_t stx_ino;
+ uint64_t stx_size;
+ uint64_t stx_blocks;
+ uint64_t stx_attributes_mask;
+ /* 0x40 */
+ const struct statx_timestamp stx_atime;
+ const struct statx_timestamp stx_btime;
+ const struct statx_timestamp stx_ctime;
+ const struct statx_timestamp stx_mtime;
+ /* 0x80 */
+ uint32_t stx_rdev_major;
+ uint32_t stx_rdev_minor;
+ uint32_t stx_dev_major;
+ uint32_t stx_dev_minor;
+ /* 0x90 */
+ uint64_t __spare2[14];
+ /* 0x100 */
+};
+#endif
+
+#if !defined(HAVE_STATX)
+
+/*
+ * statx: wrapper function of statx
+ *
+ * Returns: It returns status of statx syscall
+ */
+static inline int statx(int dirfd, const char *pathname, unsigned int flags,
+ unsigned int mask, struct statx *statxbuf)
+{
+ return tst_syscall(__NR_statx, dirfd, pathname, flags, mask, statxbuf);
+}
+#endif
+
+/*
+ * Flags to be stx_mask
+ *
+ * Query request/result mask for statx() and struct statx::stx_mask.
+ *
+ * These bits should be set in the mask argument of statx() to request
+ * particular items when calling statx().
+ */
+#ifndef STATX_TYPE
+# define STATX_TYPE 0x00000001U
+#endif
+
+#ifndef STATX_MODE
+# define STATX_MODE 0x00000002U
+#endif
+
+#ifndef STATX_NLINK
+# define STATX_NLINK 0x00000004U
+#endif
+
+#ifndef STATX_UID
+# define STATX_UID 0x00000008U
+#endif
+
+#ifndef STATX_GID
+# define STATX_GID 0x00000010U
+#endif
+
+#ifndef STATX_ATIME
+# define STATX_ATIME 0x00000020U
+#endif
+
+#ifndef STATX_MTIME
+# define STATX_MTIME 0x00000040U
+#endif
+
+#ifndef STATX_CTIME
+# define STATX_CTIME 0x00000080U
+#endif
+
+#ifndef STATX_INO
+# define STATX_INO 0x00000100U
+#endif
+
+#ifndef STATX_SIZE
+# define STATX_SIZE 0x00000200U
+#endif
+
+#ifndef STATX_BLOCKS
+# define STATX_BLOCKS 0x00000400U
+#endif
+
+#ifndef STATX_BASIC_STATS
+# define STATX_BASIC_STATS 0x000007ffU
+#endif
+
+#ifndef STATX_BTIME
+# define STATX_BTIME 0x00000800U
+#endif
+
+#ifndef STATX_ALL
+# define STATX_ALL 0x00000fffU
+#endif
+
+#ifndef STATX__RESERVED
+# define STATX__RESERVED 0x80000000U
+#endif
+
+/*
+ * Attributes to be found in stx_attributes and masked in stx_attributes_mask.
+ *
+ * These give information about the features or the state of a file that might
+ * be of use to ordinary userspace programs such as GUIs or ls rather than
+ * specialised tools.
+ *
+ * Note that the flags marked [I] correspond to generic FS_IOC_FLAGS
+ * semantically. Where possible, the numerical value is picked to correspond
+ * also.
+ */
+#ifndef STATX_ATTR_COMPRESSED
+# define STATX_ATTR_COMPRESSED 0x00000004
+#endif
+
+#ifndef STATX_ATTR_IMMUTABLE
+# define STATX_ATTR_IMMUTABLE 0x00000010
+#endif
+
+#ifndef STATX_ATTR_APPEND
+# define STATX_ATTR_APPEND 0x00000020
+#endif
+
+#ifndef STATX_ATTR_NODUMP
+# define STATX_ATTR_NODUMP 0x00000040
+#endif
+
+#ifndef STATX_ATTR_ENCRYPTED
+# define STATX_ATTR_ENCRYPTED 0x00000800
+#endif
+
+#ifndef STATX_ATTR_AUTOMOUNT
+# define STATX_ATTR_AUTOMOUNT 0x00001000
+#endif
+
+#ifndef AT_SYMLINK_NOFOLLOW
+# define AT_SYMLINK_NOFOLLOW 0x100
+#endif
+
+#ifndef AT_REMOVEDIR
+# define AT_REMOVEDIR 0x200
+#endif
+
+#ifndef AT_SYMLINK_FOLLOW
+# define AT_SYMLINK_FOLLOW 0x400
+#endif
+
+#ifndef AT_NO_AUTOMOUNT
+# define AT_NO_AUTOMOUNT 0x800
+#endif
+
+#ifndef AT_EMPTY_PATH
+# define AT_EMPTY_PATH 0x1000
+#endif
+
+#ifndef AT_STATX_SYNC_TYPE
+# define AT_STATX_SYNC_TYPE 0x6000
+#endif
+
+#ifndef AT_STATX_SYNC_AS_STAT
+# define AT_STATX_SYNC_AS_STAT 0x0000
+#endif
+
+#ifndef AT_STATX_FORCE_SYNC
+# define AT_STATX_FORCE_SYNC 0x2000
+#endif
+
+#ifndef AT_STATX_DONT_SYNC
+# define AT_STATX_DONT_SYNC 0x4000
+#endif
+
+#endif
diff --git a/kernel/tests/include/lapi/sync_file_range.h b/kernel/tests/include/lapi/sync_file_range.h
new file mode 100644
index 0000000..86bfe5d
--- /dev/null
+++ b/kernel/tests/include/lapi/sync_file_range.h
@@ -0,0 +1,58 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) International Business Machines Corp., 2008
+ */
+
+#ifndef SYNC_FILE_RANGE_H
+#define SYNC_FILE_RANGE_H
+
+#include <sys/types.h>
+#include "config.h"
+#include "lapi/syscalls.h"
+#include "lapi/abisize.h"
+
+#if !defined(HAVE_SYNC_FILE_RANGE)
+
+#ifdef TST_TEST_H__
+# define TST_SYSCALL tst_syscall
+#else
+# define TST_SYSCALL ltp_syscall
+#endif
+
+/*****************************************************************************
+ * Wraper function to call sync_file_range system call
+ ******************************************************************************/
+static inline long sync_file_range(int fd, off64_t offset, off64_t nbytes,
+ unsigned int flags)
+{
+#if (defined(__arm__) || defined(__powerpc__) || defined(__powerpc64__))
+# ifdef TST_ABI32
+# if __BYTE_ORDER == __BIG_ENDIAN
+ return TST_SYSCALL(__NR_sync_file_range2, fd, flags,
+ (int)(offset >> 32), (int)offset, (int)(nbytes >> 32),
+ (int)nbytes);
+# elif __BYTE_ORDER == __LITTLE_ENDIAN
+ return TST_SYSCALL(__NR_sync_file_range2, fd, flags, (int)offset,
+ (int)(offset >> 32), nbytes, (int)(nbytes >> 32));
+# endif
+# else
+ return TST_SYSCALL(__NR_sync_file_range2, fd, flags, offset, nbytes);
+# endif
+#elif (defined(__s390__) || defined(__s390x__)) && defined(TST_ABI32)
+ return TST_SYSCALL(__NR_sync_file_range, fd, (int)(offset >> 32),
+ (int)offset, (int)(nbytes >> 32), (int)nbytes, flags);
+#elif defined(__mips__) && defined(TST_ABI32)
+# if __BYTE_ORDER == __BIG_ENDIAN
+ return TST_SYSCALL(__NR_sync_file_range, fd, 0, (int)(offset >> 32),
+ (int)offset, (int)(nbytes >> 32), (int)nbytes, flags);
+# elif __BYTE_ORDER == __LITTLE_ENDIAN
+ return TST_SYSCALL(__NR_sync_file_range, fd, 0, (int)offset,
+ (int)(offset >> 32), (int)nbytes, (int)(nbytes >> 32), flags);
+# endif
+#else
+ return TST_SYSCALL(__NR_sync_file_range, fd, offset, nbytes, flags);
+#endif
+}
+#endif
+
+#endif /* SYNC_FILE_RANGE_H */
diff --git a/kernel/tests/include/lapi/syncfs.h b/kernel/tests/include/lapi/syncfs.h
new file mode 100644
index 0000000..e5d29fa
--- /dev/null
+++ b/kernel/tests/include/lapi/syncfs.h
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Linaro Limited. All rights reserved.
+ * Author: Sumit Garg <sumit.garg@linaro.org>
+ */
+
+#ifndef SYNCFS_H
+#define SYNCFS_H
+
+#include "config.h"
+#include <sys/types.h>
+#include "lapi/syscalls.h"
+
+#if !defined(HAVE_SYNCFS)
+int syncfs(int fd)
+{
+ return tst_syscall(__NR_syncfs, fd);
+}
+#endif
+
+#endif /* SYNCFS_H */
diff --git a/kernel/tests/include/lapi/syscalls.h b/kernel/tests/include/lapi/syscalls.h
new file mode 100644
index 0000000..251d0ed
--- /dev/null
+++ b/kernel/tests/include/lapi/syscalls.h
@@ -0,0 +1,19964 @@
+/************************************************
+ * GENERATED FILE: DO NOT EDIT/PATCH THIS FILE *
+ * change your arch specific .in file instead *
+ ************************************************/
+
+/*
+ * Here we stick all the ugly *fallback* logic for linux
+ * system call numbers (those __NR_ thingies).
+ *
+ * Licensed under the GPLv2 or later, see the COPYING file.
+ */
+
+#ifndef __LAPI_SYSCALLS_H__
+#define __LAPI_SYSCALLS_H__
+
+#include <errno.h>
+#include <sys/syscall.h>
+#include <asm/unistd.h>
+#include "cleanup.c"
+
+#define ltp_syscall(NR, ...) ({ \
+ int __ret; \
+ if (NR == __LTP__NR_INVALID_SYSCALL) { \
+ errno = ENOSYS; \
+ __ret = -1; \
+ } else { \
+ __ret = syscall(NR, ##__VA_ARGS__); \
+ } \
+ if (__ret == -1 && errno == ENOSYS) { \
+ tst_brkm(TCONF, CLEANUP, \
+ "syscall(%d) " #NR " not supported on your arch", \
+ NR); \
+ } \
+ __ret; \
+})
+
+#define tst_syscall(NR, ...) ({ \
+ int tst_ret; \
+ if (NR == __LTP__NR_INVALID_SYSCALL) { \
+ errno = ENOSYS; \
+ tst_ret = -1; \
+ } else { \
+ tst_ret = syscall(NR, ##__VA_ARGS__); \
+ } \
+ if (tst_ret == -1 && errno == ENOSYS) { \
+ tst_brk(TCONF, "syscall(%d) " #NR " not supported", NR); \
+ } \
+ tst_ret; \
+})
+
+#define __LTP__NR_INVALID_SYSCALL -1
+
+#ifdef __aarch64__
+# ifndef __NR_io_setup
+# define __NR_io_setup 0
+# endif
+# ifndef __NR_io_destroy
+# define __NR_io_destroy 1
+# endif
+# ifndef __NR_io_submit
+# define __NR_io_submit 2
+# endif
+# ifndef __NR_io_cancel
+# define __NR_io_cancel 3
+# endif
+# ifndef __NR_io_getevents
+# define __NR_io_getevents 4
+# endif
+# ifndef __NR_setxattr
+# define __NR_setxattr 5
+# endif
+# ifndef __NR_lsetxattr
+# define __NR_lsetxattr 6
+# endif
+# ifndef __NR_fsetxattr
+# define __NR_fsetxattr 7
+# endif
+# ifndef __NR_getxattr
+# define __NR_getxattr 8
+# endif
+# ifndef __NR_lgetxattr
+# define __NR_lgetxattr 9
+# endif
+# ifndef __NR_fgetxattr
+# define __NR_fgetxattr 10
+# endif
+# ifndef __NR_listxattr
+# define __NR_listxattr 11
+# endif
+# ifndef __NR_llistxattr
+# define __NR_llistxattr 12
+# endif
+# ifndef __NR_flistxattr
+# define __NR_flistxattr 13
+# endif
+# ifndef __NR_removexattr
+# define __NR_removexattr 14
+# endif
+# ifndef __NR_lremovexattr
+# define __NR_lremovexattr 15
+# endif
+# ifndef __NR_fremovexattr
+# define __NR_fremovexattr 16
+# endif
+# ifndef __NR_getcwd
+# define __NR_getcwd 17
+# endif
+# ifndef __NR_lookup_dcookie
+# define __NR_lookup_dcookie 18
+# endif
+# ifndef __NR_eventfd2
+# define __NR_eventfd2 19
+# endif
+# ifndef __NR_epoll_create1
+# define __NR_epoll_create1 20
+# endif
+# ifndef __NR_epoll_ctl
+# define __NR_epoll_ctl 21
+# endif
+# ifndef __NR_epoll_pwait
+# define __NR_epoll_pwait 22
+# endif
+# ifndef __NR_dup
+# define __NR_dup 23
+# endif
+# ifndef __NR_dup3
+# define __NR_dup3 24
+# endif
+# ifndef __NR_fcntl
+# define __NR_fcntl 25
+# endif
+# ifndef __NR_inotify_init1
+# define __NR_inotify_init1 26
+# endif
+# ifndef __NR_inotify_add_watch
+# define __NR_inotify_add_watch 27
+# endif
+# ifndef __NR_inotify_rm_watch
+# define __NR_inotify_rm_watch 28
+# endif
+# ifndef __NR_ioctl
+# define __NR_ioctl 29
+# endif
+# ifndef __NR_ioprio_set
+# define __NR_ioprio_set 30
+# endif
+# ifndef __NR_ioprio_get
+# define __NR_ioprio_get 31
+# endif
+# ifndef __NR_flock
+# define __NR_flock 32
+# endif
+# ifndef __NR_mknodat
+# define __NR_mknodat 33
+# endif
+# ifndef __NR_mkdirat
+# define __NR_mkdirat 34
+# endif
+# ifndef __NR_unlinkat
+# define __NR_unlinkat 35
+# endif
+# ifndef __NR_symlinkat
+# define __NR_symlinkat 36
+# endif
+# ifndef __NR_linkat
+# define __NR_linkat 37
+# endif
+# ifndef __NR_renameat
+# define __NR_renameat 38
+# endif
+# ifndef __NR_umount2
+# define __NR_umount2 39
+# endif
+# ifndef __NR_mount
+# define __NR_mount 40
+# endif
+# ifndef __NR_pivot_root
+# define __NR_pivot_root 41
+# endif
+# ifndef __NR_nfsservctl
+# define __NR_nfsservctl 42
+# endif
+# ifndef __NR_statfs
+# define __NR_statfs 43
+# endif
+# ifndef __NR_fstatfs
+# define __NR_fstatfs 44
+# endif
+# ifndef __NR_truncate
+# define __NR_truncate 45
+# endif
+# ifndef __NR_ftruncate
+# define __NR_ftruncate 46
+# endif
+# ifndef __NR_fallocate
+# define __NR_fallocate 47
+# endif
+# ifndef __NR_faccessat
+# define __NR_faccessat 48
+# endif
+# ifndef __NR_chdir
+# define __NR_chdir 49
+# endif
+# ifndef __NR_fchdir
+# define __NR_fchdir 50
+# endif
+# ifndef __NR_chroot
+# define __NR_chroot 51
+# endif
+# ifndef __NR_fchmod
+# define __NR_fchmod 52
+# endif
+# ifndef __NR_fchmodat
+# define __NR_fchmodat 53
+# endif
+# ifndef __NR_fchownat
+# define __NR_fchownat 54
+# endif
+# ifndef __NR_fchown
+# define __NR_fchown 55
+# endif
+# ifndef __NR_openat
+# define __NR_openat 56
+# endif
+# ifndef __NR_close
+# define __NR_close 57
+# endif
+# ifndef __NR_vhangup
+# define __NR_vhangup 58
+# endif
+# ifndef __NR_pipe2
+# define __NR_pipe2 59
+# endif
+# ifndef __NR_quotactl
+# define __NR_quotactl 60
+# endif
+# ifndef __NR_getdents64
+# define __NR_getdents64 61
+# endif
+# ifndef __NR_lseek
+# define __NR_lseek 62
+# endif
+# ifndef __NR_read
+# define __NR_read 63
+# endif
+# ifndef __NR_write
+# define __NR_write 64
+# endif
+# ifndef __NR_readv
+# define __NR_readv 65
+# endif
+# ifndef __NR_writev
+# define __NR_writev 66
+# endif
+# ifndef __NR_pread64
+# define __NR_pread64 67
+# endif
+# ifndef __NR_pwrite64
+# define __NR_pwrite64 68
+# endif
+# ifndef __NR_preadv
+# define __NR_preadv 69
+# endif
+# ifndef __NR_pwritev
+# define __NR_pwritev 70
+# endif
+# ifndef __NR_sendfile
+# define __NR_sendfile 71
+# endif
+# ifndef __NR_pselect6
+# define __NR_pselect6 72
+# endif
+# ifndef __NR_ppoll
+# define __NR_ppoll 73
+# endif
+# ifndef __NR_signalfd4
+# define __NR_signalfd4 74
+# endif
+# ifndef __NR_vmsplice
+# define __NR_vmsplice 75
+# endif
+# ifndef __NR_splice
+# define __NR_splice 76
+# endif
+# ifndef __NR_tee
+# define __NR_tee 77
+# endif
+# ifndef __NR_readlinkat
+# define __NR_readlinkat 78
+# endif
+# ifndef __NR_fstatat
+# define __NR_fstatat 79
+# endif
+# ifndef __NR_fstat
+# define __NR_fstat 80
+# endif
+# ifndef __NR_sync
+# define __NR_sync 81
+# endif
+# ifndef __NR_fsync
+# define __NR_fsync 82
+# endif
+# ifndef __NR_fdatasync
+# define __NR_fdatasync 83
+# endif
+# ifndef __NR_sync_file_range2
+# define __NR_sync_file_range2 84
+# endif
+# ifndef __NR_sync_file_range
+# define __NR_sync_file_range 84
+# endif
+# ifndef __NR_timerfd_create
+# define __NR_timerfd_create 85
+# endif
+# ifndef __NR_timerfd_settime
+# define __NR_timerfd_settime 86
+# endif
+# ifndef __NR_timerfd_gettime
+# define __NR_timerfd_gettime 87
+# endif
+# ifndef __NR_utimensat
+# define __NR_utimensat 88
+# endif
+# ifndef __NR_acct
+# define __NR_acct 89
+# endif
+# ifndef __NR_capget
+# define __NR_capget 90
+# endif
+# ifndef __NR_capset
+# define __NR_capset 91
+# endif
+# ifndef __NR_personality
+# define __NR_personality 92
+# endif
+# ifndef __NR_exit
+# define __NR_exit 93
+# endif
+# ifndef __NR_exit_group
+# define __NR_exit_group 94
+# endif
+# ifndef __NR_waitid
+# define __NR_waitid 95
+# endif
+# ifndef __NR_set_tid_address
+# define __NR_set_tid_address 96
+# endif
+# ifndef __NR_unshare
+# define __NR_unshare 97
+# endif
+# ifndef __NR_futex
+# define __NR_futex 98
+# endif
+# ifndef __NR_set_robust_list
+# define __NR_set_robust_list 99
+# endif
+# ifndef __NR_get_robust_list
+# define __NR_get_robust_list 100
+# endif
+# ifndef __NR_nanosleep
+# define __NR_nanosleep 101
+# endif
+# ifndef __NR_getitimer
+# define __NR_getitimer 102
+# endif
+# ifndef __NR_setitimer
+# define __NR_setitimer 103
+# endif
+# ifndef __NR_kexec_load
+# define __NR_kexec_load 104
+# endif
+# ifndef __NR_init_module
+# define __NR_init_module 105
+# endif
+# ifndef __NR_delete_module
+# define __NR_delete_module 106
+# endif
+# ifndef __NR_timer_create
+# define __NR_timer_create 107
+# endif
+# ifndef __NR_timer_gettime
+# define __NR_timer_gettime 108
+# endif
+# ifndef __NR_timer_getoverrun
+# define __NR_timer_getoverrun 109
+# endif
+# ifndef __NR_timer_settime
+# define __NR_timer_settime 110
+# endif
+# ifndef __NR_timer_delete
+# define __NR_timer_delete 111
+# endif
+# ifndef __NR_clock_settime
+# define __NR_clock_settime 112
+# endif
+# ifndef __NR_clock_gettime
+# define __NR_clock_gettime 113
+# endif
+# ifndef __NR_clock_getres
+# define __NR_clock_getres 114
+# endif
+# ifndef __NR_clock_nanosleep
+# define __NR_clock_nanosleep 115
+# endif
+# ifndef __NR_syslog
+# define __NR_syslog 116
+# endif
+# ifndef __NR_ptrace
+# define __NR_ptrace 117
+# endif
+# ifndef __NR_sched_setparam
+# define __NR_sched_setparam 118
+# endif
+# ifndef __NR_sched_setscheduler
+# define __NR_sched_setscheduler 119
+# endif
+# ifndef __NR_sched_getscheduler
+# define __NR_sched_getscheduler 120
+# endif
+# ifndef __NR_sched_getparam
+# define __NR_sched_getparam 121
+# endif
+# ifndef __NR_sched_setaffinity
+# define __NR_sched_setaffinity 122
+# endif
+# ifndef __NR_sched_getaffinity
+# define __NR_sched_getaffinity 123
+# endif
+# ifndef __NR_sched_yield
+# define __NR_sched_yield 124
+# endif
+# ifndef __NR_sched_get_priority_max
+# define __NR_sched_get_priority_max 125
+# endif
+# ifndef __NR_sched_get_priority_min
+# define __NR_sched_get_priority_min 126
+# endif
+# ifndef __NR_sched_rr_get_interval
+# define __NR_sched_rr_get_interval 127
+# endif
+# ifndef __NR_restart_syscall
+# define __NR_restart_syscall 128
+# endif
+# ifndef __NR_kill
+# define __NR_kill 129
+# endif
+# ifndef __NR_tkill
+# define __NR_tkill 130
+# endif
+# ifndef __NR_tgkill
+# define __NR_tgkill 131
+# endif
+# ifndef __NR_sigaltstack
+# define __NR_sigaltstack 132
+# endif
+# ifndef __NR_rt_sigsuspend
+# define __NR_rt_sigsuspend 133
+# endif
+# ifndef __NR_rt_sigaction
+# define __NR_rt_sigaction 134
+# endif
+# ifndef __NR_rt_sigprocmask
+# define __NR_rt_sigprocmask 135
+# endif
+# ifndef __NR_rt_sigpending
+# define __NR_rt_sigpending 136
+# endif
+# ifndef __NR_rt_sigtimedwait
+# define __NR_rt_sigtimedwait 137
+# endif
+# ifndef __NR_rt_sigqueueinfo
+# define __NR_rt_sigqueueinfo 138
+# endif
+# ifndef __NR_rt_sigreturn
+# define __NR_rt_sigreturn 139
+# endif
+# ifndef __NR_setpriority
+# define __NR_setpriority 140
+# endif
+# ifndef __NR_getpriority
+# define __NR_getpriority 141
+# endif
+# ifndef __NR_reboot
+# define __NR_reboot 142
+# endif
+# ifndef __NR_setregid
+# define __NR_setregid 143
+# endif
+# ifndef __NR_setgid
+# define __NR_setgid 144
+# endif
+# ifndef __NR_setreuid
+# define __NR_setreuid 145
+# endif
+# ifndef __NR_setuid
+# define __NR_setuid 146
+# endif
+# ifndef __NR_setresuid
+# define __NR_setresuid 147
+# endif
+# ifndef __NR_getresuid
+# define __NR_getresuid 148
+# endif
+# ifndef __NR_setresgid
+# define __NR_setresgid 149
+# endif
+# ifndef __NR_getresgid
+# define __NR_getresgid 150
+# endif
+# ifndef __NR_setfsuid
+# define __NR_setfsuid 151
+# endif
+# ifndef __NR_setfsgid
+# define __NR_setfsgid 152
+# endif
+# ifndef __NR_times
+# define __NR_times 153
+# endif
+# ifndef __NR_setpgid
+# define __NR_setpgid 154
+# endif
+# ifndef __NR_getpgid
+# define __NR_getpgid 155
+# endif
+# ifndef __NR_getsid
+# define __NR_getsid 156
+# endif
+# ifndef __NR_setsid
+# define __NR_setsid 157
+# endif
+# ifndef __NR_getgroups
+# define __NR_getgroups 158
+# endif
+# ifndef __NR_setgroups
+# define __NR_setgroups 159
+# endif
+# ifndef __NR_uname
+# define __NR_uname 160
+# endif
+# ifndef __NR_sethostname
+# define __NR_sethostname 161
+# endif
+# ifndef __NR_setdomainname
+# define __NR_setdomainname 162
+# endif
+# ifndef __NR_getrlimit
+# define __NR_getrlimit 163
+# endif
+# ifndef __NR_setrlimit
+# define __NR_setrlimit 164
+# endif
+# ifndef __NR_getrusage
+# define __NR_getrusage 165
+# endif
+# ifndef __NR_umask
+# define __NR_umask 166
+# endif
+# ifndef __NR_prctl
+# define __NR_prctl 167
+# endif
+# ifndef __NR_getcpu
+# define __NR_getcpu 168
+# endif
+# ifndef __NR_gettimeofday
+# define __NR_gettimeofday 169
+# endif
+# ifndef __NR_settimeofday
+# define __NR_settimeofday 170
+# endif
+# ifndef __NR_adjtimex
+# define __NR_adjtimex 171
+# endif
+# ifndef __NR_getpid
+# define __NR_getpid 172
+# endif
+# ifndef __NR_getppid
+# define __NR_getppid 173
+# endif
+# ifndef __NR_getuid
+# define __NR_getuid 174
+# endif
+# ifndef __NR_geteuid
+# define __NR_geteuid 175
+# endif
+# ifndef __NR_getgid
+# define __NR_getgid 176
+# endif
+# ifndef __NR_getegid
+# define __NR_getegid 177
+# endif
+# ifndef __NR_gettid
+# define __NR_gettid 178
+# endif
+# ifndef __NR_sysinfo
+# define __NR_sysinfo 179
+# endif
+# ifndef __NR_mq_open
+# define __NR_mq_open 180
+# endif
+# ifndef __NR_mq_unlink
+# define __NR_mq_unlink 181
+# endif
+# ifndef __NR_mq_timedsend
+# define __NR_mq_timedsend 182
+# endif
+# ifndef __NR_mq_timedreceive
+# define __NR_mq_timedreceive 183
+# endif
+# ifndef __NR_mq_notify
+# define __NR_mq_notify 184
+# endif
+# ifndef __NR_mq_getsetattr
+# define __NR_mq_getsetattr 185
+# endif
+# ifndef __NR_msgget
+# define __NR_msgget 186
+# endif
+# ifndef __NR_msgctl
+# define __NR_msgctl 187
+# endif
+# ifndef __NR_msgrcv
+# define __NR_msgrcv 188
+# endif
+# ifndef __NR_msgsnd
+# define __NR_msgsnd 189
+# endif
+# ifndef __NR_semget
+# define __NR_semget 190
+# endif
+# ifndef __NR_semctl
+# define __NR_semctl 191
+# endif
+# ifndef __NR_semtimedop
+# define __NR_semtimedop 192
+# endif
+# ifndef __NR_semop
+# define __NR_semop 193
+# endif
+# ifndef __NR_shmget
+# define __NR_shmget 194
+# endif
+# ifndef __NR_shmctl
+# define __NR_shmctl 195
+# endif
+# ifndef __NR_shmat
+# define __NR_shmat 196
+# endif
+# ifndef __NR_shmdt
+# define __NR_shmdt 197
+# endif
+# ifndef __NR_socket
+# define __NR_socket 198
+# endif
+# ifndef __NR_socketpair
+# define __NR_socketpair 199
+# endif
+# ifndef __NR_bind
+# define __NR_bind 200
+# endif
+# ifndef __NR_listen
+# define __NR_listen 201
+# endif
+# ifndef __NR_accept
+# define __NR_accept 202
+# endif
+# ifndef __NR_connect
+# define __NR_connect 203
+# endif
+# ifndef __NR_getsockname
+# define __NR_getsockname 204
+# endif
+# ifndef __NR_getpeername
+# define __NR_getpeername 205
+# endif
+# ifndef __NR_sendto
+# define __NR_sendto 206
+# endif
+# ifndef __NR_recvfrom
+# define __NR_recvfrom 207
+# endif
+# ifndef __NR_setsockopt
+# define __NR_setsockopt 208
+# endif
+# ifndef __NR_getsockopt
+# define __NR_getsockopt 209
+# endif
+# ifndef __NR_shutdown
+# define __NR_shutdown 210
+# endif
+# ifndef __NR_sendmsg
+# define __NR_sendmsg 211
+# endif
+# ifndef __NR_recvmsg
+# define __NR_recvmsg 212
+# endif
+# ifndef __NR_readahead
+# define __NR_readahead 213
+# endif
+# ifndef __NR_brk
+# define __NR_brk 214
+# endif
+# ifndef __NR_munmap
+# define __NR_munmap 215
+# endif
+# ifndef __NR_mremap
+# define __NR_mremap 216
+# endif
+# ifndef __NR_add_key
+# define __NR_add_key 217
+# endif
+# ifndef __NR_request_key
+# define __NR_request_key 218
+# endif
+# ifndef __NR_keyctl
+# define __NR_keyctl 219
+# endif
+# ifndef __NR_clone
+# define __NR_clone 220
+# endif
+# ifndef __NR_execve
+# define __NR_execve 221
+# endif
+# ifndef __NR_mmap
+# define __NR_mmap 222
+# endif
+# ifndef __NR_fadvise64
+# define __NR_fadvise64 223
+# endif
+# ifndef __NR_swapon
+# define __NR_swapon 224
+# endif
+# ifndef __NR_swapoff
+# define __NR_swapoff 225
+# endif
+# ifndef __NR_mprotect
+# define __NR_mprotect 226
+# endif
+# ifndef __NR_msync
+# define __NR_msync 227
+# endif
+# ifndef __NR_mlock
+# define __NR_mlock 228
+# endif
+# ifndef __NR_munlock
+# define __NR_munlock 229
+# endif
+# ifndef __NR_mlockall
+# define __NR_mlockall 230
+# endif
+# ifndef __NR_munlockall
+# define __NR_munlockall 231
+# endif
+# ifndef __NR_mincore
+# define __NR_mincore 232
+# endif
+# ifndef __NR_madvise
+# define __NR_madvise 233
+# endif
+# ifndef __NR_remap_file_pages
+# define __NR_remap_file_pages 234
+# endif
+# ifndef __NR_mbind
+# define __NR_mbind 235
+# endif
+# ifndef __NR_get_mempolicy
+# define __NR_get_mempolicy 236
+# endif
+# ifndef __NR_set_mempolicy
+# define __NR_set_mempolicy 237
+# endif
+# ifndef __NR_migrate_pages
+# define __NR_migrate_pages 238
+# endif
+# ifndef __NR_move_pages
+# define __NR_move_pages 239
+# endif
+# ifndef __NR_rt_tgsigqueueinfo
+# define __NR_rt_tgsigqueueinfo 240
+# endif
+# ifndef __NR_perf_event_open
+# define __NR_perf_event_open 241
+# endif
+# ifndef __NR_accept4
+# define __NR_accept4 242
+# endif
+# ifndef __NR_recvmmsg
+# define __NR_recvmmsg 243
+# endif
+# ifndef __NR_wait4
+# define __NR_wait4 260
+# endif
+# ifndef __NR_prlimit64
+# define __NR_prlimit64 261
+# endif
+# ifndef __NR_fanotify_init
+# define __NR_fanotify_init 262
+# endif
+# ifndef __NR_fanotify_mark
+# define __NR_fanotify_mark 263
+# endif
+# ifndef __NR_name_to_handle_at
+# define __NR_name_to_handle_at 264
+# endif
+# ifndef __NR_open_by_handle_at
+# define __NR_open_by_handle_at 265
+# endif
+# ifndef __NR_clock_adjtime
+# define __NR_clock_adjtime 266
+# endif
+# ifndef __NR_syncfs
+# define __NR_syncfs 267
+# endif
+# ifndef __NR_setns
+# define __NR_setns 268
+# endif
+# ifndef __NR_sendmmsg
+# define __NR_sendmmsg 269
+# endif
+# ifndef __NR_process_vm_readv
+# define __NR_process_vm_readv 270
+# endif
+# ifndef __NR_process_vm_writev
+# define __NR_process_vm_writev 271
+# endif
+# ifndef __NR_kcmp
+# define __NR_kcmp 272
+# endif
+# ifndef __NR_finit_module
+# define __NR_finit_module 273
+# endif
+# ifndef __NR_sched_setattr
+# define __NR_sched_setattr 274
+# endif
+# ifndef __NR_sched_getattr
+# define __NR_sched_getattr 275
+# endif
+# ifndef __NR_renameat2
+# define __NR_renameat2 276
+# endif
+# ifndef __NR_seccomp
+# define __NR_seccomp 277
+# endif
+# ifndef __NR_getrandom
+# define __NR_getrandom 278
+# endif
+# ifndef __NR_memfd_create
+# define __NR_memfd_create 279
+# endif
+# ifndef __NR_bpf
+# define __NR_bpf 280
+# endif
+# ifndef __NR_execveat
+# define __NR_execveat 281
+# endif
+# ifndef __NR_userfaultfd
+# define __NR_userfaultfd 282
+# endif
+# ifndef __NR_membarrier
+# define __NR_membarrier 283
+# endif
+# ifndef __NR_mlock2
+# define __NR_mlock2 284
+# endif
+# ifndef __NR_copy_file_range
+# define __NR_copy_file_range 285
+# endif
+# ifndef __NR_preadv2
+# define __NR_preadv2 286
+# endif
+# ifndef __NR_pwritev2
+# define __NR_pwritev2 287
+# endif
+# ifndef __NR_pkey_mprotect
+# define __NR_pkey_mprotect 288
+# endif
+# ifndef __NR_pkey_alloc
+# define __NR_pkey_alloc 289
+# endif
+# ifndef __NR_pkey_free
+# define __NR_pkey_free 290
+# endif
+# ifndef __NR_statx
+# define __NR_statx 291
+# endif
+# ifndef __NR_io_pgetevents
+# define __NR_io_pgetevents 292
+# endif
+# ifndef __NR_rseq
+# define __NR_rseq 293
+# endif
+# ifndef __NR_kexec_file_load
+# define __NR_kexec_file_load 294
+# endif
+# ifndef __NR_clock_gettime64
+# define __NR_clock_gettime64 403
+# endif
+# ifndef __NR_clock_settime64
+# define __NR_clock_settime64 404
+# endif
+# ifndef __NR_clock_adjtime64
+# define __NR_clock_adjtime64 405
+# endif
+# ifndef __NR_clock_getres_time64
+# define __NR_clock_getres_time64 406
+# endif
+# ifndef __NR_clock_nanosleep_time64
+# define __NR_clock_nanosleep_time64 407
+# endif
+# ifndef __NR_timer_gettime64
+# define __NR_timer_gettime64 408
+# endif
+# ifndef __NR_timer_settime64
+# define __NR_timer_settime64 409
+# endif
+# ifndef __NR_timerfd_gettime64
+# define __NR_timerfd_gettime64 410
+# endif
+# ifndef __NR_timerfd_settime64
+# define __NR_timerfd_settime64 411
+# endif
+# ifndef __NR_utimensat_time64
+# define __NR_utimensat_time64 412
+# endif
+# ifndef __NR_pselect6_time64
+# define __NR_pselect6_time64 413
+# endif
+# ifndef __NR_ppoll_time64
+# define __NR_ppoll_time64 414
+# endif
+# ifndef __NR_io_pgetevents_time64
+# define __NR_io_pgetevents_time64 416
+# endif
+# ifndef __NR_recvmmsg_time64
+# define __NR_recvmmsg_time64 417
+# endif
+# ifndef __NR_mq_timedsend_time64
+# define __NR_mq_timedsend_time64 418
+# endif
+# ifndef __NR_mq_timedreceive_time64
+# define __NR_mq_timedreceive_time64 419
+# endif
+# ifndef __NR_semtimedop_time64
+# define __NR_semtimedop_time64 420
+# endif
+# ifndef __NR_rt_sigtimedwait_time64
+# define __NR_rt_sigtimedwait_time64 421
+# endif
+# ifndef __NR_futex_time64
+# define __NR_futex_time64 422
+# endif
+# ifndef __NR_sched_rr_get_interval_time64
+# define __NR_sched_rr_get_interval_time64 423
+# endif
+# ifndef __NR_pidfd_send_signal
+# define __NR_pidfd_send_signal 424
+# endif
+# ifndef __NR_io_uring_setup
+# define __NR_io_uring_setup 425
+# endif
+# ifndef __NR_io_uring_enter
+# define __NR_io_uring_enter 426
+# endif
+# ifndef __NR_io_uring_register
+# define __NR_io_uring_register 427
+# endif
+# ifndef __NR_open_tree
+# define __NR_open_tree 428
+# endif
+# ifndef __NR_move_mount
+# define __NR_move_mount 429
+# endif
+# ifndef __NR_fsopen
+# define __NR_fsopen 430
+# endif
+# ifndef __NR_fsconfig
+# define __NR_fsconfig 431
+# endif
+# ifndef __NR_fsmount
+# define __NR_fsmount 432
+# endif
+# ifndef __NR_fspick
+# define __NR_fspick 433
+# endif
+# ifndef __NR_pidfd_open
+# define __NR_pidfd_open 434
+# endif
+# ifndef __NR_clone3
+# define __NR_clone3 435
+# endif
+# ifndef __NR_openat2
+# define __NR_openat2 437
+# endif
+# ifndef __NR_pidfd_getfd
+# define __NR_pidfd_getfd 438
+# endif
+# ifndef __NR__sysctl
+# define __NR__sysctl 1078
+# endif
+#endif
+
+
+#ifdef __arc__
+# ifndef __NR_io_setup
+# define __NR_io_setup 0
+# endif
+# ifndef __NR_io_destroy
+# define __NR_io_destroy 1
+# endif
+# ifndef __NR_io_submit
+# define __NR_io_submit 2
+# endif
+# ifndef __NR_io_cancel
+# define __NR_io_cancel 3
+# endif
+# ifndef __NR_io_getevents
+# define __NR_io_getevents 4
+# endif
+# ifndef __NR_setxattr
+# define __NR_setxattr 5
+# endif
+# ifndef __NR_lsetxattr
+# define __NR_lsetxattr 6
+# endif
+# ifndef __NR_fsetxattr
+# define __NR_fsetxattr 7
+# endif
+# ifndef __NR_getxattr
+# define __NR_getxattr 8
+# endif
+# ifndef __NR_lgetxattr
+# define __NR_lgetxattr 9
+# endif
+# ifndef __NR_fgetxattr
+# define __NR_fgetxattr 10
+# endif
+# ifndef __NR_listxattr
+# define __NR_listxattr 11
+# endif
+# ifndef __NR_llistxattr
+# define __NR_llistxattr 12
+# endif
+# ifndef __NR_flistxattr
+# define __NR_flistxattr 13
+# endif
+# ifndef __NR_removexattr
+# define __NR_removexattr 14
+# endif
+# ifndef __NR_lremovexattr
+# define __NR_lremovexattr 15
+# endif
+# ifndef __NR_fremovexattr
+# define __NR_fremovexattr 16
+# endif
+# ifndef __NR_getcwd
+# define __NR_getcwd 17
+# endif
+# ifndef __NR_lookup_dcookie
+# define __NR_lookup_dcookie 18
+# endif
+# ifndef __NR_eventfd2
+# define __NR_eventfd2 19
+# endif
+# ifndef __NR_epoll_create1
+# define __NR_epoll_create1 20
+# endif
+# ifndef __NR_epoll_ctl
+# define __NR_epoll_ctl 21
+# endif
+# ifndef __NR_epoll_pwait
+# define __NR_epoll_pwait 22
+# endif
+# ifndef __NR_dup
+# define __NR_dup 23
+# endif
+# ifndef __NR_dup3
+# define __NR_dup3 24
+# endif
+# ifndef __NR_fcntl
+# define __NR_fcntl 25
+# endif
+# ifndef __NR_inotify_init1
+# define __NR_inotify_init1 26
+# endif
+# ifndef __NR_inotify_add_watch
+# define __NR_inotify_add_watch 27
+# endif
+# ifndef __NR_inotify_rm_watch
+# define __NR_inotify_rm_watch 28
+# endif
+# ifndef __NR_ioctl
+# define __NR_ioctl 29
+# endif
+# ifndef __NR_ioprio_set
+# define __NR_ioprio_set 30
+# endif
+# ifndef __NR_ioprio_get
+# define __NR_ioprio_get 31
+# endif
+# ifndef __NR_flock
+# define __NR_flock 32
+# endif
+# ifndef __NR_mknodat
+# define __NR_mknodat 33
+# endif
+# ifndef __NR_mkdirat
+# define __NR_mkdirat 34
+# endif
+# ifndef __NR_unlinkat
+# define __NR_unlinkat 35
+# endif
+# ifndef __NR_symlinkat
+# define __NR_symlinkat 36
+# endif
+# ifndef __NR_linkat
+# define __NR_linkat 37
+# endif
+# ifndef __NR_renameat
+# define __NR_renameat 38
+# endif
+# ifndef __NR_umount2
+# define __NR_umount2 39
+# endif
+# ifndef __NR_mount
+# define __NR_mount 40
+# endif
+# ifndef __NR_pivot_root
+# define __NR_pivot_root 41
+# endif
+# ifndef __NR_nfsservctl
+# define __NR_nfsservctl 42
+# endif
+# ifndef __NR_statfs
+# define __NR_statfs 43
+# endif
+# ifndef __NR_fstatfs
+# define __NR_fstatfs 44
+# endif
+# ifndef __NR_truncate
+# define __NR_truncate 45
+# endif
+# ifndef __NR_ftruncate
+# define __NR_ftruncate 46
+# endif
+# ifndef __NR_fallocate
+# define __NR_fallocate 47
+# endif
+# ifndef __NR_faccessat
+# define __NR_faccessat 48
+# endif
+# ifndef __NR_chdir
+# define __NR_chdir 49
+# endif
+# ifndef __NR_fchdir
+# define __NR_fchdir 50
+# endif
+# ifndef __NR_chroot
+# define __NR_chroot 51
+# endif
+# ifndef __NR_fchmod
+# define __NR_fchmod 52
+# endif
+# ifndef __NR_fchmodat
+# define __NR_fchmodat 53
+# endif
+# ifndef __NR_fchownat
+# define __NR_fchownat 54
+# endif
+# ifndef __NR_fchown
+# define __NR_fchown 55
+# endif
+# ifndef __NR_openat
+# define __NR_openat 56
+# endif
+# ifndef __NR_close
+# define __NR_close 57
+# endif
+# ifndef __NR_vhangup
+# define __NR_vhangup 58
+# endif
+# ifndef __NR_pipe2
+# define __NR_pipe2 59
+# endif
+# ifndef __NR_quotactl
+# define __NR_quotactl 60
+# endif
+# ifndef __NR_getdents64
+# define __NR_getdents64 61
+# endif
+# ifndef __NR_lseek
+# define __NR_lseek 62
+# endif
+# ifndef __NR_read
+# define __NR_read 63
+# endif
+# ifndef __NR_write
+# define __NR_write 64
+# endif
+# ifndef __NR_readv
+# define __NR_readv 65
+# endif
+# ifndef __NR_writev
+# define __NR_writev 66
+# endif
+# ifndef __NR_pread64
+# define __NR_pread64 67
+# endif
+# ifndef __NR_pwrite64
+# define __NR_pwrite64 68
+# endif
+# ifndef __NR_preadv
+# define __NR_preadv 69
+# endif
+# ifndef __NR_pwritev
+# define __NR_pwritev 70
+# endif
+# ifndef __NR_sendfile
+# define __NR_sendfile 71
+# endif
+# ifndef __NR_pselect6
+# define __NR_pselect6 72
+# endif
+# ifndef __NR_ppoll
+# define __NR_ppoll 73
+# endif
+# ifndef __NR_signalfd4
+# define __NR_signalfd4 74
+# endif
+# ifndef __NR_vmsplice
+# define __NR_vmsplice 75
+# endif
+# ifndef __NR_splice
+# define __NR_splice 76
+# endif
+# ifndef __NR_tee
+# define __NR_tee 77
+# endif
+# ifndef __NR_readlinkat
+# define __NR_readlinkat 78
+# endif
+# ifndef __NR_fstatat
+# define __NR_fstatat 79
+# endif
+# ifndef __NR_fstat
+# define __NR_fstat 80
+# endif
+# ifndef __NR_sync
+# define __NR_sync 81
+# endif
+# ifndef __NR_fsync
+# define __NR_fsync 82
+# endif
+# ifndef __NR_fdatasync
+# define __NR_fdatasync 83
+# endif
+# ifndef __NR_sync_file_range2
+# define __NR_sync_file_range2 84
+# endif
+# ifndef __NR_sync_file_range
+# define __NR_sync_file_range 84
+# endif
+# ifndef __NR_timerfd_create
+# define __NR_timerfd_create 85
+# endif
+# ifndef __NR_timerfd_settime
+# define __NR_timerfd_settime 86
+# endif
+# ifndef __NR_timerfd_gettime
+# define __NR_timerfd_gettime 87
+# endif
+# ifndef __NR_utimensat
+# define __NR_utimensat 88
+# endif
+# ifndef __NR_acct
+# define __NR_acct 89
+# endif
+# ifndef __NR_capget
+# define __NR_capget 90
+# endif
+# ifndef __NR_capset
+# define __NR_capset 91
+# endif
+# ifndef __NR_personality
+# define __NR_personality 92
+# endif
+# ifndef __NR_exit
+# define __NR_exit 93
+# endif
+# ifndef __NR_exit_group
+# define __NR_exit_group 94
+# endif
+# ifndef __NR_waitid
+# define __NR_waitid 95
+# endif
+# ifndef __NR_set_tid_address
+# define __NR_set_tid_address 96
+# endif
+# ifndef __NR_unshare
+# define __NR_unshare 97
+# endif
+# ifndef __NR_futex
+# define __NR_futex 98
+# endif
+# ifndef __NR_set_robust_list
+# define __NR_set_robust_list 99
+# endif
+# ifndef __NR_get_robust_list
+# define __NR_get_robust_list 100
+# endif
+# ifndef __NR_nanosleep
+# define __NR_nanosleep 101
+# endif
+# ifndef __NR_getitimer
+# define __NR_getitimer 102
+# endif
+# ifndef __NR_setitimer
+# define __NR_setitimer 103
+# endif
+# ifndef __NR_kexec_load
+# define __NR_kexec_load 104
+# endif
+# ifndef __NR_init_module
+# define __NR_init_module 105
+# endif
+# ifndef __NR_delete_module
+# define __NR_delete_module 106
+# endif
+# ifndef __NR_timer_create
+# define __NR_timer_create 107
+# endif
+# ifndef __NR_timer_gettime
+# define __NR_timer_gettime 108
+# endif
+# ifndef __NR_timer_getoverrun
+# define __NR_timer_getoverrun 109
+# endif
+# ifndef __NR_timer_settime
+# define __NR_timer_settime 110
+# endif
+# ifndef __NR_timer_delete
+# define __NR_timer_delete 111
+# endif
+# ifndef __NR_clock_settime
+# define __NR_clock_settime 112
+# endif
+# ifndef __NR_clock_gettime
+# define __NR_clock_gettime 113
+# endif
+# ifndef __NR_clock_getres
+# define __NR_clock_getres 114
+# endif
+# ifndef __NR_clock_nanosleep
+# define __NR_clock_nanosleep 115
+# endif
+# ifndef __NR_syslog
+# define __NR_syslog 116
+# endif
+# ifndef __NR_ptrace
+# define __NR_ptrace 117
+# endif
+# ifndef __NR_sched_setparam
+# define __NR_sched_setparam 118
+# endif
+# ifndef __NR_sched_setscheduler
+# define __NR_sched_setscheduler 119
+# endif
+# ifndef __NR_sched_getscheduler
+# define __NR_sched_getscheduler 120
+# endif
+# ifndef __NR_sched_getparam
+# define __NR_sched_getparam 121
+# endif
+# ifndef __NR_sched_setaffinity
+# define __NR_sched_setaffinity 122
+# endif
+# ifndef __NR_sched_getaffinity
+# define __NR_sched_getaffinity 123
+# endif
+# ifndef __NR_sched_yield
+# define __NR_sched_yield 124
+# endif
+# ifndef __NR_sched_get_priority_max
+# define __NR_sched_get_priority_max 125
+# endif
+# ifndef __NR_sched_get_priority_min
+# define __NR_sched_get_priority_min 126
+# endif
+# ifndef __NR_sched_rr_get_interval
+# define __NR_sched_rr_get_interval 127
+# endif
+# ifndef __NR_restart_syscall
+# define __NR_restart_syscall 128
+# endif
+# ifndef __NR_kill
+# define __NR_kill 129
+# endif
+# ifndef __NR_tkill
+# define __NR_tkill 130
+# endif
+# ifndef __NR_tgkill
+# define __NR_tgkill 131
+# endif
+# ifndef __NR_sigaltstack
+# define __NR_sigaltstack 132
+# endif
+# ifndef __NR_rt_sigsuspend
+# define __NR_rt_sigsuspend 133
+# endif
+# ifndef __NR_rt_sigaction
+# define __NR_rt_sigaction 134
+# endif
+# ifndef __NR_rt_sigprocmask
+# define __NR_rt_sigprocmask 135
+# endif
+# ifndef __NR_rt_sigpending
+# define __NR_rt_sigpending 136
+# endif
+# ifndef __NR_rt_sigtimedwait
+# define __NR_rt_sigtimedwait 137
+# endif
+# ifndef __NR_rt_sigqueueinfo
+# define __NR_rt_sigqueueinfo 138
+# endif
+# ifndef __NR_rt_sigreturn
+# define __NR_rt_sigreturn 139
+# endif
+# ifndef __NR_setpriority
+# define __NR_setpriority 140
+# endif
+# ifndef __NR_getpriority
+# define __NR_getpriority 141
+# endif
+# ifndef __NR_reboot
+# define __NR_reboot 142
+# endif
+# ifndef __NR_setregid
+# define __NR_setregid 143
+# endif
+# ifndef __NR_setgid
+# define __NR_setgid 144
+# endif
+# ifndef __NR_setreuid
+# define __NR_setreuid 145
+# endif
+# ifndef __NR_setuid
+# define __NR_setuid 146
+# endif
+# ifndef __NR_setresuid
+# define __NR_setresuid 147
+# endif
+# ifndef __NR_getresuid
+# define __NR_getresuid 148
+# endif
+# ifndef __NR_setresgid
+# define __NR_setresgid 149
+# endif
+# ifndef __NR_getresgid
+# define __NR_getresgid 150
+# endif
+# ifndef __NR_setfsuid
+# define __NR_setfsuid 151
+# endif
+# ifndef __NR_setfsgid
+# define __NR_setfsgid 152
+# endif
+# ifndef __NR_times
+# define __NR_times 153
+# endif
+# ifndef __NR_setpgid
+# define __NR_setpgid 154
+# endif
+# ifndef __NR_getpgid
+# define __NR_getpgid 155
+# endif
+# ifndef __NR_getsid
+# define __NR_getsid 156
+# endif
+# ifndef __NR_setsid
+# define __NR_setsid 157
+# endif
+# ifndef __NR_getgroups
+# define __NR_getgroups 158
+# endif
+# ifndef __NR_setgroups
+# define __NR_setgroups 159
+# endif
+# ifndef __NR_uname
+# define __NR_uname 160
+# endif
+# ifndef __NR_sethostname
+# define __NR_sethostname 161
+# endif
+# ifndef __NR_setdomainname
+# define __NR_setdomainname 162
+# endif
+# ifndef __NR_getrlimit
+# define __NR_getrlimit 163
+# endif
+# ifndef __NR_setrlimit
+# define __NR_setrlimit 164
+# endif
+# ifndef __NR_getrusage
+# define __NR_getrusage 165
+# endif
+# ifndef __NR_umask
+# define __NR_umask 166
+# endif
+# ifndef __NR_prctl
+# define __NR_prctl 167
+# endif
+# ifndef __NR_getcpu
+# define __NR_getcpu 168
+# endif
+# ifndef __NR_gettimeofday
+# define __NR_gettimeofday 169
+# endif
+# ifndef __NR_settimeofday
+# define __NR_settimeofday 170
+# endif
+# ifndef __NR_adjtimex
+# define __NR_adjtimex 171
+# endif
+# ifndef __NR_getpid
+# define __NR_getpid 172
+# endif
+# ifndef __NR_getppid
+# define __NR_getppid 173
+# endif
+# ifndef __NR_getuid
+# define __NR_getuid 174
+# endif
+# ifndef __NR_geteuid
+# define __NR_geteuid 175
+# endif
+# ifndef __NR_getgid
+# define __NR_getgid 176
+# endif
+# ifndef __NR_getegid
+# define __NR_getegid 177
+# endif
+# ifndef __NR_gettid
+# define __NR_gettid 178
+# endif
+# ifndef __NR_sysinfo
+# define __NR_sysinfo 179
+# endif
+# ifndef __NR_mq_open
+# define __NR_mq_open 180
+# endif
+# ifndef __NR_mq_unlink
+# define __NR_mq_unlink 181
+# endif
+# ifndef __NR_mq_timedsend
+# define __NR_mq_timedsend 182
+# endif
+# ifndef __NR_mq_timedreceive
+# define __NR_mq_timedreceive 183
+# endif
+# ifndef __NR_mq_notify
+# define __NR_mq_notify 184
+# endif
+# ifndef __NR_mq_getsetattr
+# define __NR_mq_getsetattr 185
+# endif
+# ifndef __NR_msgget
+# define __NR_msgget 186
+# endif
+# ifndef __NR_msgctl
+# define __NR_msgctl 187
+# endif
+# ifndef __NR_msgrcv
+# define __NR_msgrcv 188
+# endif
+# ifndef __NR_msgsnd
+# define __NR_msgsnd 189
+# endif
+# ifndef __NR_semget
+# define __NR_semget 190
+# endif
+# ifndef __NR_semctl
+# define __NR_semctl 191
+# endif
+# ifndef __NR_semtimedop
+# define __NR_semtimedop 192
+# endif
+# ifndef __NR_semop
+# define __NR_semop 193
+# endif
+# ifndef __NR_shmget
+# define __NR_shmget 194
+# endif
+# ifndef __NR_shmctl
+# define __NR_shmctl 195
+# endif
+# ifndef __NR_shmat
+# define __NR_shmat 196
+# endif
+# ifndef __NR_shmdt
+# define __NR_shmdt 197
+# endif
+# ifndef __NR_socket
+# define __NR_socket 198
+# endif
+# ifndef __NR_socketpair
+# define __NR_socketpair 199
+# endif
+# ifndef __NR_bind
+# define __NR_bind 200
+# endif
+# ifndef __NR_listen
+# define __NR_listen 201
+# endif
+# ifndef __NR_accept
+# define __NR_accept 202
+# endif
+# ifndef __NR_connect
+# define __NR_connect 203
+# endif
+# ifndef __NR_getsockname
+# define __NR_getsockname 204
+# endif
+# ifndef __NR_getpeername
+# define __NR_getpeername 205
+# endif
+# ifndef __NR_sendto
+# define __NR_sendto 206
+# endif
+# ifndef __NR_recvfrom
+# define __NR_recvfrom 207
+# endif
+# ifndef __NR_setsockopt
+# define __NR_setsockopt 208
+# endif
+# ifndef __NR_getsockopt
+# define __NR_getsockopt 209
+# endif
+# ifndef __NR_shutdown
+# define __NR_shutdown 210
+# endif
+# ifndef __NR_sendmsg
+# define __NR_sendmsg 211
+# endif
+# ifndef __NR_recvmsg
+# define __NR_recvmsg 212
+# endif
+# ifndef __NR_readahead
+# define __NR_readahead 213
+# endif
+# ifndef __NR_brk
+# define __NR_brk 214
+# endif
+# ifndef __NR_munmap
+# define __NR_munmap 215
+# endif
+# ifndef __NR_mremap
+# define __NR_mremap 216
+# endif
+# ifndef __NR_add_key
+# define __NR_add_key 217
+# endif
+# ifndef __NR_request_key
+# define __NR_request_key 218
+# endif
+# ifndef __NR_keyctl
+# define __NR_keyctl 219
+# endif
+# ifndef __NR_clone
+# define __NR_clone 220
+# endif
+# ifndef __NR_execve
+# define __NR_execve 221
+# endif
+# ifndef __NR_mmap
+# define __NR_mmap 222
+# endif
+# ifndef __NR_fadvise64
+# define __NR_fadvise64 223
+# endif
+# ifndef __NR_swapon
+# define __NR_swapon 224
+# endif
+# ifndef __NR_swapoff
+# define __NR_swapoff 225
+# endif
+# ifndef __NR_mprotect
+# define __NR_mprotect 226
+# endif
+# ifndef __NR_msync
+# define __NR_msync 227
+# endif
+# ifndef __NR_mlock
+# define __NR_mlock 228
+# endif
+# ifndef __NR_munlock
+# define __NR_munlock 229
+# endif
+# ifndef __NR_mlockall
+# define __NR_mlockall 230
+# endif
+# ifndef __NR_munlockall
+# define __NR_munlockall 231
+# endif
+# ifndef __NR_mincore
+# define __NR_mincore 232
+# endif
+# ifndef __NR_madvise
+# define __NR_madvise 233
+# endif
+# ifndef __NR_remap_file_pages
+# define __NR_remap_file_pages 234
+# endif
+# ifndef __NR_mbind
+# define __NR_mbind 235
+# endif
+# ifndef __NR_get_mempolicy
+# define __NR_get_mempolicy 236
+# endif
+# ifndef __NR_set_mempolicy
+# define __NR_set_mempolicy 237
+# endif
+# ifndef __NR_migrate_pages
+# define __NR_migrate_pages 238
+# endif
+# ifndef __NR_move_pages
+# define __NR_move_pages 239
+# endif
+# ifndef __NR_rt_tgsigqueueinfo
+# define __NR_rt_tgsigqueueinfo 240
+# endif
+# ifndef __NR_perf_event_open
+# define __NR_perf_event_open 241
+# endif
+# ifndef __NR_accept4
+# define __NR_accept4 242
+# endif
+# ifndef __NR_recvmmsg
+# define __NR_recvmmsg 243
+# endif
+# ifndef __NR_cacheflush
+# define __NR_cacheflush 244
+# endif
+# ifndef __NR_arc_settls
+# define __NR_arc_settls 245
+# endif
+# ifndef __NR_arc_gettls
+# define __NR_arc_gettls 246
+# endif
+# ifndef __NR_sysfs
+# define __NR_sysfs 247
+# endif
+# ifndef __NR_arc_usr_cmpxchg
+# define __NR_arc_usr_cmpxchg 248
+# endif
+# ifndef __NR_wait4
+# define __NR_wait4 260
+# endif
+# ifndef __NR_prlimit64
+# define __NR_prlimit64 261
+# endif
+# ifndef __NR_fanotify_init
+# define __NR_fanotify_init 262
+# endif
+# ifndef __NR_fanotify_mark
+# define __NR_fanotify_mark 263
+# endif
+# ifndef __NR_name_to_handle_at
+# define __NR_name_to_handle_at 264
+# endif
+# ifndef __NR_open_by_handle_at
+# define __NR_open_by_handle_at 265
+# endif
+# ifndef __NR_clock_adjtime
+# define __NR_clock_adjtime 266
+# endif
+# ifndef __NR_syncfs
+# define __NR_syncfs 267
+# endif
+# ifndef __NR_setns
+# define __NR_setns 268
+# endif
+# ifndef __NR_sendmmsg
+# define __NR_sendmmsg 269
+# endif
+# ifndef __NR_process_vm_readv
+# define __NR_process_vm_readv 270
+# endif
+# ifndef __NR_process_vm_writev
+# define __NR_process_vm_writev 271
+# endif
+# ifndef __NR_kcmp
+# define __NR_kcmp 272
+# endif
+# ifndef __NR_getrandom
+# define __NR_getrandom 278
+# endif
+# ifndef __NR_memfd_create
+# define __NR_memfd_create 279
+# endif
+# ifndef __NR_bpf
+# define __NR_bpf 280
+# endif
+# ifndef __NR_execveat
+# define __NR_execveat 281
+# endif
+# ifndef __NR_userfaultfd
+# define __NR_userfaultfd 282
+# endif
+# ifndef __NR_membarrier
+# define __NR_membarrier 283
+# endif
+# ifndef __NR_mlock2
+# define __NR_mlock2 284
+# endif
+# ifndef __NR_copy_file_range
+# define __NR_copy_file_range 285
+# endif
+# ifndef __NR_preadv2
+# define __NR_preadv2 286
+# endif
+# ifndef __NR_pwritev2
+# define __NR_pwritev2 287
+# endif
+# ifndef __NR_pkey_mprotect
+# define __NR_pkey_mprotect 288
+# endif
+# ifndef __NR_pkey_alloc
+# define __NR_pkey_alloc 289
+# endif
+# ifndef __NR_pkey_free
+# define __NR_pkey_free 290
+# endif
+# ifndef __NR_statx
+# define __NR_statx 291
+# endif
+# ifndef __NR_io_pgetevents
+# define __NR_io_pgetevents 292
+# endif
+# ifndef __NR_rseq
+# define __NR_rseq 293
+# endif
+# ifndef __NR_kexec_file_load
+# define __NR_kexec_file_load 294
+# endif
+# ifndef __NR_clock_gettime64
+# define __NR_clock_gettime64 403
+# endif
+# ifndef __NR_clock_settime64
+# define __NR_clock_settime64 404
+# endif
+# ifndef __NR_clock_adjtime64
+# define __NR_clock_adjtime64 405
+# endif
+# ifndef __NR_clock_getres_time64
+# define __NR_clock_getres_time64 406
+# endif
+# ifndef __NR_clock_nanosleep_time64
+# define __NR_clock_nanosleep_time64 407
+# endif
+# ifndef __NR_timer_gettime64
+# define __NR_timer_gettime64 408
+# endif
+# ifndef __NR_timer_settime64
+# define __NR_timer_settime64 409
+# endif
+# ifndef __NR_timerfd_gettime64
+# define __NR_timerfd_gettime64 410
+# endif
+# ifndef __NR_timerfd_settime64
+# define __NR_timerfd_settime64 411
+# endif
+# ifndef __NR_utimensat_time64
+# define __NR_utimensat_time64 412
+# endif
+# ifndef __NR_pselect6_time64
+# define __NR_pselect6_time64 413
+# endif
+# ifndef __NR_ppoll_time64
+# define __NR_ppoll_time64 414
+# endif
+# ifndef __NR_io_pgetevents_time64
+# define __NR_io_pgetevents_time64 416
+# endif
+# ifndef __NR_recvmmsg_time64
+# define __NR_recvmmsg_time64 417
+# endif
+# ifndef __NR_mq_timedsend_time64
+# define __NR_mq_timedsend_time64 418
+# endif
+# ifndef __NR_mq_timedreceive_time64
+# define __NR_mq_timedreceive_time64 419
+# endif
+# ifndef __NR_semtimedop_time64
+# define __NR_semtimedop_time64 420
+# endif
+# ifndef __NR_rt_sigtimedwait_time64
+# define __NR_rt_sigtimedwait_time64 421
+# endif
+# ifndef __NR_futex_time64
+# define __NR_futex_time64 422
+# endif
+# ifndef __NR_sched_rr_get_interval_time64
+# define __NR_sched_rr_get_interval_time64 423
+# endif
+# ifndef __NR_pidfd_send_signal
+# define __NR_pidfd_send_signal 424
+# endif
+# ifndef __NR_io_uring_setup
+# define __NR_io_uring_setup 425
+# endif
+# ifndef __NR_io_uring_enter
+# define __NR_io_uring_enter 426
+# endif
+# ifndef __NR_io_uring_register
+# define __NR_io_uring_register 427
+# endif
+# ifndef __NR_open_tree
+# define __NR_open_tree 428
+# endif
+# ifndef __NR_move_mount
+# define __NR_move_mount 429
+# endif
+# ifndef __NR_fsopen
+# define __NR_fsopen 430
+# endif
+# ifndef __NR_fsconfig
+# define __NR_fsconfig 431
+# endif
+# ifndef __NR_fsmount
+# define __NR_fsmount 432
+# endif
+# ifndef __NR_fspick
+# define __NR_fspick 433
+# endif
+# ifndef __NR_pidfd_open
+# define __NR_pidfd_open 434
+# endif
+# ifndef __NR_clone3
+# define __NR_clone3 435
+# endif
+# ifndef __NR_openat2
+# define __NR_openat2 437
+# endif
+# ifndef __NR_pidfd_getfd
+# define __NR_pidfd_getfd 438
+# endif
+#endif
+
+
+#ifdef __arm__
+# ifndef __NR_restart_syscall
+# define __NR_restart_syscall (__NR_SYSCALL_BASE+ 0)
+# endif
+# ifndef __NR_exit
+# define __NR_exit (__NR_SYSCALL_BASE+ 1)
+# endif
+# ifndef __NR_fork
+# define __NR_fork (__NR_SYSCALL_BASE+ 2)
+# endif
+# ifndef __NR_read
+# define __NR_read (__NR_SYSCALL_BASE+ 3)
+# endif
+# ifndef __NR_write
+# define __NR_write (__NR_SYSCALL_BASE+ 4)
+# endif
+# ifndef __NR_open
+# define __NR_open (__NR_SYSCALL_BASE+ 5)
+# endif
+# ifndef __NR_close
+# define __NR_close (__NR_SYSCALL_BASE+ 6)
+# endif
+# ifndef __NR_creat
+# define __NR_creat (__NR_SYSCALL_BASE+ 8)
+# endif
+# ifndef __NR_link
+# define __NR_link (__NR_SYSCALL_BASE+ 9)
+# endif
+# ifndef __NR_unlink
+# define __NR_unlink (__NR_SYSCALL_BASE+ 10)
+# endif
+# ifndef __NR_execve
+# define __NR_execve (__NR_SYSCALL_BASE+ 11)
+# endif
+# ifndef __NR_chdir
+# define __NR_chdir (__NR_SYSCALL_BASE+ 12)
+# endif
+# ifndef __NR_mknod
+# define __NR_mknod (__NR_SYSCALL_BASE+ 14)
+# endif
+# ifndef __NR_chmod
+# define __NR_chmod (__NR_SYSCALL_BASE+ 15)
+# endif
+# ifndef __NR_lchown
+# define __NR_lchown (__NR_SYSCALL_BASE+ 16)
+# endif
+# ifndef __NR_lseek
+# define __NR_lseek (__NR_SYSCALL_BASE+ 19)
+# endif
+# ifndef __NR_getpid
+# define __NR_getpid (__NR_SYSCALL_BASE+ 20)
+# endif
+# ifndef __NR_mount
+# define __NR_mount (__NR_SYSCALL_BASE+ 21)
+# endif
+# ifndef __NR_setuid
+# define __NR_setuid (__NR_SYSCALL_BASE+ 23)
+# endif
+# ifndef __NR_getuid
+# define __NR_getuid (__NR_SYSCALL_BASE+ 24)
+# endif
+# ifndef __NR_ptrace
+# define __NR_ptrace (__NR_SYSCALL_BASE+ 26)
+# endif
+# ifndef __NR_pause
+# define __NR_pause (__NR_SYSCALL_BASE+ 29)
+# endif
+# ifndef __NR_access
+# define __NR_access (__NR_SYSCALL_BASE+ 33)
+# endif
+# ifndef __NR_nice
+# define __NR_nice (__NR_SYSCALL_BASE+ 34)
+# endif
+# ifndef __NR_sync
+# define __NR_sync (__NR_SYSCALL_BASE+ 36)
+# endif
+# ifndef __NR_kill
+# define __NR_kill (__NR_SYSCALL_BASE+ 37)
+# endif
+# ifndef __NR_rename
+# define __NR_rename (__NR_SYSCALL_BASE+ 38)
+# endif
+# ifndef __NR_mkdir
+# define __NR_mkdir (__NR_SYSCALL_BASE+ 39)
+# endif
+# ifndef __NR_rmdir
+# define __NR_rmdir (__NR_SYSCALL_BASE+ 40)
+# endif
+# ifndef __NR_dup
+# define __NR_dup (__NR_SYSCALL_BASE+ 41)
+# endif
+# ifndef __NR_pipe
+# define __NR_pipe (__NR_SYSCALL_BASE+ 42)
+# endif
+# ifndef __NR_times
+# define __NR_times (__NR_SYSCALL_BASE+ 43)
+# endif
+# ifndef __NR_brk
+# define __NR_brk (__NR_SYSCALL_BASE+ 45)
+# endif
+# ifndef __NR_setgid
+# define __NR_setgid (__NR_SYSCALL_BASE+ 46)
+# endif
+# ifndef __NR_getgid
+# define __NR_getgid (__NR_SYSCALL_BASE+ 47)
+# endif
+# ifndef __NR_geteuid
+# define __NR_geteuid (__NR_SYSCALL_BASE+ 49)
+# endif
+# ifndef __NR_getegid
+# define __NR_getegid (__NR_SYSCALL_BASE+ 50)
+# endif
+# ifndef __NR_acct
+# define __NR_acct (__NR_SYSCALL_BASE+ 51)
+# endif
+# ifndef __NR_umount2
+# define __NR_umount2 (__NR_SYSCALL_BASE+ 52)
+# endif
+# ifndef __NR_ioctl
+# define __NR_ioctl (__NR_SYSCALL_BASE+ 54)
+# endif
+# ifndef __NR_fcntl
+# define __NR_fcntl (__NR_SYSCALL_BASE+ 55)
+# endif
+# ifndef __NR_setpgid
+# define __NR_setpgid (__NR_SYSCALL_BASE+ 57)
+# endif
+# ifndef __NR_umask
+# define __NR_umask (__NR_SYSCALL_BASE+ 60)
+# endif
+# ifndef __NR_chroot
+# define __NR_chroot (__NR_SYSCALL_BASE+ 61)
+# endif
+# ifndef __NR_ustat
+# define __NR_ustat (__NR_SYSCALL_BASE+ 62)
+# endif
+# ifndef __NR_dup2
+# define __NR_dup2 (__NR_SYSCALL_BASE+ 63)
+# endif
+# ifndef __NR_getppid
+# define __NR_getppid (__NR_SYSCALL_BASE+ 64)
+# endif
+# ifndef __NR_getpgrp
+# define __NR_getpgrp (__NR_SYSCALL_BASE+ 65)
+# endif
+# ifndef __NR_setsid
+# define __NR_setsid (__NR_SYSCALL_BASE+ 66)
+# endif
+# ifndef __NR_sigaction
+# define __NR_sigaction (__NR_SYSCALL_BASE+ 67)
+# endif
+# ifndef __NR_setreuid
+# define __NR_setreuid (__NR_SYSCALL_BASE+ 70)
+# endif
+# ifndef __NR_setregid
+# define __NR_setregid (__NR_SYSCALL_BASE+ 71)
+# endif
+# ifndef __NR_sigsuspend
+# define __NR_sigsuspend (__NR_SYSCALL_BASE+ 72)
+# endif
+# ifndef __NR_sigpending
+# define __NR_sigpending (__NR_SYSCALL_BASE+ 73)
+# endif
+# ifndef __NR_sethostname
+# define __NR_sethostname (__NR_SYSCALL_BASE+ 74)
+# endif
+# ifndef __NR_setrlimit
+# define __NR_setrlimit (__NR_SYSCALL_BASE+ 75)
+# endif
+# ifndef __NR_getrusage
+# define __NR_getrusage (__NR_SYSCALL_BASE+ 77)
+# endif
+# ifndef __NR_gettimeofday
+# define __NR_gettimeofday (__NR_SYSCALL_BASE+ 78)
+# endif
+# ifndef __NR_settimeofday
+# define __NR_settimeofday (__NR_SYSCALL_BASE+ 79)
+# endif
+# ifndef __NR_getgroups
+# define __NR_getgroups (__NR_SYSCALL_BASE+ 80)
+# endif
+# ifndef __NR_setgroups
+# define __NR_setgroups (__NR_SYSCALL_BASE+ 81)
+# endif
+# ifndef __NR_symlink
+# define __NR_symlink (__NR_SYSCALL_BASE+ 83)
+# endif
+# ifndef __NR_readlink
+# define __NR_readlink (__NR_SYSCALL_BASE+ 85)
+# endif
+# ifndef __NR_uselib
+# define __NR_uselib (__NR_SYSCALL_BASE+ 86)
+# endif
+# ifndef __NR_swapon
+# define __NR_swapon (__NR_SYSCALL_BASE+ 87)
+# endif
+# ifndef __NR_reboot
+# define __NR_reboot (__NR_SYSCALL_BASE+ 88)
+# endif
+# ifndef __NR_munmap
+# define __NR_munmap (__NR_SYSCALL_BASE+ 91)
+# endif
+# ifndef __NR_truncate
+# define __NR_truncate (__NR_SYSCALL_BASE+ 92)
+# endif
+# ifndef __NR_ftruncate
+# define __NR_ftruncate (__NR_SYSCALL_BASE+ 93)
+# endif
+# ifndef __NR_fchmod
+# define __NR_fchmod (__NR_SYSCALL_BASE+ 94)
+# endif
+# ifndef __NR_fchown
+# define __NR_fchown (__NR_SYSCALL_BASE+ 95)
+# endif
+# ifndef __NR_getpriority
+# define __NR_getpriority (__NR_SYSCALL_BASE+ 96)
+# endif
+# ifndef __NR_setpriority
+# define __NR_setpriority (__NR_SYSCALL_BASE+ 97)
+# endif
+# ifndef __NR_statfs
+# define __NR_statfs (__NR_SYSCALL_BASE+ 99)
+# endif
+# ifndef __NR_fstatfs
+# define __NR_fstatfs (__NR_SYSCALL_BASE+100)
+# endif
+# ifndef __NR_syslog
+# define __NR_syslog (__NR_SYSCALL_BASE+103)
+# endif
+# ifndef __NR_setitimer
+# define __NR_setitimer (__NR_SYSCALL_BASE+104)
+# endif
+# ifndef __NR_getitimer
+# define __NR_getitimer (__NR_SYSCALL_BASE+105)
+# endif
+# ifndef __NR_stat
+# define __NR_stat (__NR_SYSCALL_BASE+106)
+# endif
+# ifndef __NR_lstat
+# define __NR_lstat (__NR_SYSCALL_BASE+107)
+# endif
+# ifndef __NR_fstat
+# define __NR_fstat (__NR_SYSCALL_BASE+108)
+# endif
+# ifndef __NR_vhangup
+# define __NR_vhangup (__NR_SYSCALL_BASE+111)
+# endif
+# ifndef __NR_wait4
+# define __NR_wait4 (__NR_SYSCALL_BASE+114)
+# endif
+# ifndef __NR_swapoff
+# define __NR_swapoff (__NR_SYSCALL_BASE+115)
+# endif
+# ifndef __NR_sysinfo
+# define __NR_sysinfo (__NR_SYSCALL_BASE+116)
+# endif
+# ifndef __NR_fsync
+# define __NR_fsync (__NR_SYSCALL_BASE+118)
+# endif
+# ifndef __NR_sigreturn
+# define __NR_sigreturn (__NR_SYSCALL_BASE+119)
+# endif
+# ifndef __NR_clone
+# define __NR_clone (__NR_SYSCALL_BASE+120)
+# endif
+# ifndef __NR_setdomainname
+# define __NR_setdomainname (__NR_SYSCALL_BASE+121)
+# endif
+# ifndef __NR_uname
+# define __NR_uname (__NR_SYSCALL_BASE+122)
+# endif
+# ifndef __NR_adjtimex
+# define __NR_adjtimex (__NR_SYSCALL_BASE+124)
+# endif
+# ifndef __NR_mprotect
+# define __NR_mprotect (__NR_SYSCALL_BASE+125)
+# endif
+# ifndef __NR_sigprocmask
+# define __NR_sigprocmask (__NR_SYSCALL_BASE+126)
+# endif
+# ifndef __NR_init_module
+# define __NR_init_module (__NR_SYSCALL_BASE+128)
+# endif
+# ifndef __NR_delete_module
+# define __NR_delete_module (__NR_SYSCALL_BASE+129)
+# endif
+# ifndef __NR_quotactl
+# define __NR_quotactl (__NR_SYSCALL_BASE+131)
+# endif
+# ifndef __NR_getpgid
+# define __NR_getpgid (__NR_SYSCALL_BASE+132)
+# endif
+# ifndef __NR_fchdir
+# define __NR_fchdir (__NR_SYSCALL_BASE+133)
+# endif
+# ifndef __NR_bdflush
+# define __NR_bdflush (__NR_SYSCALL_BASE+134)
+# endif
+# ifndef __NR_sysfs
+# define __NR_sysfs (__NR_SYSCALL_BASE+135)
+# endif
+# ifndef __NR_personality
+# define __NR_personality (__NR_SYSCALL_BASE+136)
+# endif
+# ifndef __NR_setfsuid
+# define __NR_setfsuid (__NR_SYSCALL_BASE+138)
+# endif
+# ifndef __NR_setfsgid
+# define __NR_setfsgid (__NR_SYSCALL_BASE+139)
+# endif
+# ifndef __NR__llseek
+# define __NR__llseek (__NR_SYSCALL_BASE+140)
+# endif
+# ifndef __NR_getdents
+# define __NR_getdents (__NR_SYSCALL_BASE+141)
+# endif
+# ifndef __NR__newselect
+# define __NR__newselect (__NR_SYSCALL_BASE+142)
+# endif
+# ifndef __NR_flock
+# define __NR_flock (__NR_SYSCALL_BASE+143)
+# endif
+# ifndef __NR_msync
+# define __NR_msync (__NR_SYSCALL_BASE+144)
+# endif
+# ifndef __NR_readv
+# define __NR_readv (__NR_SYSCALL_BASE+145)
+# endif
+# ifndef __NR_writev
+# define __NR_writev (__NR_SYSCALL_BASE+146)
+# endif
+# ifndef __NR_getsid
+# define __NR_getsid (__NR_SYSCALL_BASE+147)
+# endif
+# ifndef __NR_fdatasync
+# define __NR_fdatasync (__NR_SYSCALL_BASE+148)
+# endif
+# ifndef __NR__sysctl
+# define __NR__sysctl (__NR_SYSCALL_BASE+149)
+# endif
+# ifndef __NR_mlock
+# define __NR_mlock (__NR_SYSCALL_BASE+150)
+# endif
+# ifndef __NR_munlock
+# define __NR_munlock (__NR_SYSCALL_BASE+151)
+# endif
+# ifndef __NR_mlockall
+# define __NR_mlockall (__NR_SYSCALL_BASE+152)
+# endif
+# ifndef __NR_munlockall
+# define __NR_munlockall (__NR_SYSCALL_BASE+153)
+# endif
+# ifndef __NR_sched_setparam
+# define __NR_sched_setparam (__NR_SYSCALL_BASE+154)
+# endif
+# ifndef __NR_sched_getparam
+# define __NR_sched_getparam (__NR_SYSCALL_BASE+155)
+# endif
+# ifndef __NR_sched_setscheduler
+# define __NR_sched_setscheduler (__NR_SYSCALL_BASE+156)
+# endif
+# ifndef __NR_sched_getscheduler
+# define __NR_sched_getscheduler (__NR_SYSCALL_BASE+157)
+# endif
+# ifndef __NR_sched_yield
+# define __NR_sched_yield (__NR_SYSCALL_BASE+158)
+# endif
+# ifndef __NR_sched_get_priority_max
+# define __NR_sched_get_priority_max (__NR_SYSCALL_BASE+159)
+# endif
+# ifndef __NR_sched_get_priority_min
+# define __NR_sched_get_priority_min (__NR_SYSCALL_BASE+160)
+# endif
+# ifndef __NR_sched_rr_get_interval
+# define __NR_sched_rr_get_interval (__NR_SYSCALL_BASE+161)
+# endif
+# ifndef __NR_nanosleep
+# define __NR_nanosleep (__NR_SYSCALL_BASE+162)
+# endif
+# ifndef __NR_mremap
+# define __NR_mremap (__NR_SYSCALL_BASE+163)
+# endif
+# ifndef __NR_setresuid
+# define __NR_setresuid (__NR_SYSCALL_BASE+164)
+# endif
+# ifndef __NR_getresuid
+# define __NR_getresuid (__NR_SYSCALL_BASE+165)
+# endif
+# ifndef __NR_poll
+# define __NR_poll (__NR_SYSCALL_BASE+168)
+# endif
+# ifndef __NR_nfsservctl
+# define __NR_nfsservctl (__NR_SYSCALL_BASE+169)
+# endif
+# ifndef __NR_setresgid
+# define __NR_setresgid (__NR_SYSCALL_BASE+170)
+# endif
+# ifndef __NR_getresgid
+# define __NR_getresgid (__NR_SYSCALL_BASE+171)
+# endif
+# ifndef __NR_prctl
+# define __NR_prctl (__NR_SYSCALL_BASE+172)
+# endif
+# ifndef __NR_rt_sigreturn
+# define __NR_rt_sigreturn (__NR_SYSCALL_BASE+173)
+# endif
+# ifndef __NR_rt_sigaction
+# define __NR_rt_sigaction (__NR_SYSCALL_BASE+174)
+# endif
+# ifndef __NR_rt_sigprocmask
+# define __NR_rt_sigprocmask (__NR_SYSCALL_BASE+175)
+# endif
+# ifndef __NR_rt_sigpending
+# define __NR_rt_sigpending (__NR_SYSCALL_BASE+176)
+# endif
+# ifndef __NR_rt_sigtimedwait
+# define __NR_rt_sigtimedwait (__NR_SYSCALL_BASE+177)
+# endif
+# ifndef __NR_rt_sigqueueinfo
+# define __NR_rt_sigqueueinfo (__NR_SYSCALL_BASE+178)
+# endif
+# ifndef __NR_rt_sigsuspend
+# define __NR_rt_sigsuspend (__NR_SYSCALL_BASE+179)
+# endif
+# ifndef __NR_pread64
+# define __NR_pread64 (__NR_SYSCALL_BASE+180)
+# endif
+# ifndef __NR_pwrite64
+# define __NR_pwrite64 (__NR_SYSCALL_BASE+181)
+# endif
+# ifndef __NR_chown
+# define __NR_chown (__NR_SYSCALL_BASE+182)
+# endif
+# ifndef __NR_getcwd
+# define __NR_getcwd (__NR_SYSCALL_BASE+183)
+# endif
+# ifndef __NR_capget
+# define __NR_capget (__NR_SYSCALL_BASE+184)
+# endif
+# ifndef __NR_capset
+# define __NR_capset (__NR_SYSCALL_BASE+185)
+# endif
+# ifndef __NR_sigaltstack
+# define __NR_sigaltstack (__NR_SYSCALL_BASE+186)
+# endif
+# ifndef __NR_sendfile
+# define __NR_sendfile (__NR_SYSCALL_BASE+187)
+# endif
+# ifndef __NR_vfork
+# define __NR_vfork (__NR_SYSCALL_BASE+190)
+# endif
+# ifndef __NR_ugetrlimit
+# define __NR_ugetrlimit (__NR_SYSCALL_BASE+191)
+# endif
+# ifndef __NR_mmap2
+# define __NR_mmap2 (__NR_SYSCALL_BASE+192)
+# endif
+# ifndef __NR_truncate64
+# define __NR_truncate64 (__NR_SYSCALL_BASE+193)
+# endif
+# ifndef __NR_ftruncate64
+# define __NR_ftruncate64 (__NR_SYSCALL_BASE+194)
+# endif
+# ifndef __NR_stat64
+# define __NR_stat64 (__NR_SYSCALL_BASE+195)
+# endif
+# ifndef __NR_lstat64
+# define __NR_lstat64 (__NR_SYSCALL_BASE+196)
+# endif
+# ifndef __NR_fstat64
+# define __NR_fstat64 (__NR_SYSCALL_BASE+197)
+# endif
+# ifndef __NR_lchown32
+# define __NR_lchown32 (__NR_SYSCALL_BASE+198)
+# endif
+# ifndef __NR_getuid32
+# define __NR_getuid32 (__NR_SYSCALL_BASE+199)
+# endif
+# ifndef __NR_getgid32
+# define __NR_getgid32 (__NR_SYSCALL_BASE+200)
+# endif
+# ifndef __NR_geteuid32
+# define __NR_geteuid32 (__NR_SYSCALL_BASE+201)
+# endif
+# ifndef __NR_getegid32
+# define __NR_getegid32 (__NR_SYSCALL_BASE+202)
+# endif
+# ifndef __NR_setreuid32
+# define __NR_setreuid32 (__NR_SYSCALL_BASE+203)
+# endif
+# ifndef __NR_setregid32
+# define __NR_setregid32 (__NR_SYSCALL_BASE+204)
+# endif
+# ifndef __NR_getgroups32
+# define __NR_getgroups32 (__NR_SYSCALL_BASE+205)
+# endif
+# ifndef __NR_setgroups32
+# define __NR_setgroups32 (__NR_SYSCALL_BASE+206)
+# endif
+# ifndef __NR_fchown32
+# define __NR_fchown32 (__NR_SYSCALL_BASE+207)
+# endif
+# ifndef __NR_setresuid32
+# define __NR_setresuid32 (__NR_SYSCALL_BASE+208)
+# endif
+# ifndef __NR_getresuid32
+# define __NR_getresuid32 (__NR_SYSCALL_BASE+209)
+# endif
+# ifndef __NR_setresgid32
+# define __NR_setresgid32 (__NR_SYSCALL_BASE+210)
+# endif
+# ifndef __NR_getresgid32
+# define __NR_getresgid32 (__NR_SYSCALL_BASE+211)
+# endif
+# ifndef __NR_chown32
+# define __NR_chown32 (__NR_SYSCALL_BASE+212)
+# endif
+# ifndef __NR_setuid32
+# define __NR_setuid32 (__NR_SYSCALL_BASE+213)
+# endif
+# ifndef __NR_setgid32
+# define __NR_setgid32 (__NR_SYSCALL_BASE+214)
+# endif
+# ifndef __NR_setfsuid32
+# define __NR_setfsuid32 (__NR_SYSCALL_BASE+215)
+# endif
+# ifndef __NR_setfsgid32
+# define __NR_setfsgid32 (__NR_SYSCALL_BASE+216)
+# endif
+# ifndef __NR_getdents64
+# define __NR_getdents64 (__NR_SYSCALL_BASE+217)
+# endif
+# ifndef __NR_pivot_root
+# define __NR_pivot_root (__NR_SYSCALL_BASE+218)
+# endif
+# ifndef __NR_mincore
+# define __NR_mincore (__NR_SYSCALL_BASE+219)
+# endif
+# ifndef __NR_madvise
+# define __NR_madvise (__NR_SYSCALL_BASE+220)
+# endif
+# ifndef __NR_fcntl64
+# define __NR_fcntl64 (__NR_SYSCALL_BASE+221)
+# endif
+# ifndef __NR_gettid
+# define __NR_gettid (__NR_SYSCALL_BASE+224)
+# endif
+# ifndef __NR_readahead
+# define __NR_readahead (__NR_SYSCALL_BASE+225)
+# endif
+# ifndef __NR_setxattr
+# define __NR_setxattr (__NR_SYSCALL_BASE+226)
+# endif
+# ifndef __NR_lsetxattr
+# define __NR_lsetxattr (__NR_SYSCALL_BASE+227)
+# endif
+# ifndef __NR_fsetxattr
+# define __NR_fsetxattr (__NR_SYSCALL_BASE+228)
+# endif
+# ifndef __NR_getxattr
+# define __NR_getxattr (__NR_SYSCALL_BASE+229)
+# endif
+# ifndef __NR_lgetxattr
+# define __NR_lgetxattr (__NR_SYSCALL_BASE+230)
+# endif
+# ifndef __NR_fgetxattr
+# define __NR_fgetxattr (__NR_SYSCALL_BASE+231)
+# endif
+# ifndef __NR_listxattr
+# define __NR_listxattr (__NR_SYSCALL_BASE+232)
+# endif
+# ifndef __NR_llistxattr
+# define __NR_llistxattr (__NR_SYSCALL_BASE+233)
+# endif
+# ifndef __NR_flistxattr
+# define __NR_flistxattr (__NR_SYSCALL_BASE+234)
+# endif
+# ifndef __NR_removexattr
+# define __NR_removexattr (__NR_SYSCALL_BASE+235)
+# endif
+# ifndef __NR_lremovexattr
+# define __NR_lremovexattr (__NR_SYSCALL_BASE+236)
+# endif
+# ifndef __NR_fremovexattr
+# define __NR_fremovexattr (__NR_SYSCALL_BASE+237)
+# endif
+# ifndef __NR_tkill
+# define __NR_tkill (__NR_SYSCALL_BASE+238)
+# endif
+# ifndef __NR_sendfile64
+# define __NR_sendfile64 (__NR_SYSCALL_BASE+239)
+# endif
+# ifndef __NR_futex
+# define __NR_futex (__NR_SYSCALL_BASE+240)
+# endif
+# ifndef __NR_sched_setaffinity
+# define __NR_sched_setaffinity (__NR_SYSCALL_BASE+241)
+# endif
+# ifndef __NR_sched_getaffinity
+# define __NR_sched_getaffinity (__NR_SYSCALL_BASE+242)
+# endif
+# ifndef __NR_io_setup
+# define __NR_io_setup (__NR_SYSCALL_BASE+243)
+# endif
+# ifndef __NR_io_destroy
+# define __NR_io_destroy (__NR_SYSCALL_BASE+244)
+# endif
+# ifndef __NR_io_getevents
+# define __NR_io_getevents (__NR_SYSCALL_BASE+245)
+# endif
+# ifndef __NR_io_submit
+# define __NR_io_submit (__NR_SYSCALL_BASE+246)
+# endif
+# ifndef __NR_io_cancel
+# define __NR_io_cancel (__NR_SYSCALL_BASE+247)
+# endif
+# ifndef __NR_exit_group
+# define __NR_exit_group (__NR_SYSCALL_BASE+248)
+# endif
+# ifndef __NR_lookup_dcookie
+# define __NR_lookup_dcookie (__NR_SYSCALL_BASE+249)
+# endif
+# ifndef __NR_epoll_create
+# define __NR_epoll_create (__NR_SYSCALL_BASE+250)
+# endif
+# ifndef __NR_epoll_ctl
+# define __NR_epoll_ctl (__NR_SYSCALL_BASE+251)
+# endif
+# ifndef __NR_epoll_wait
+# define __NR_epoll_wait (__NR_SYSCALL_BASE+252)
+# endif
+# ifndef __NR_remap_file_pages
+# define __NR_remap_file_pages (__NR_SYSCALL_BASE+253)
+# endif
+# ifndef __NR_set_tid_address
+# define __NR_set_tid_address (__NR_SYSCALL_BASE+256)
+# endif
+# ifndef __NR_timer_create
+# define __NR_timer_create (__NR_SYSCALL_BASE+257)
+# endif
+# ifndef __NR_timer_settime
+# define __NR_timer_settime (__NR_SYSCALL_BASE+258)
+# endif
+# ifndef __NR_timer_gettime
+# define __NR_timer_gettime (__NR_SYSCALL_BASE+259)
+# endif
+# ifndef __NR_timer_getoverrun
+# define __NR_timer_getoverrun (__NR_SYSCALL_BASE+260)
+# endif
+# ifndef __NR_timer_delete
+# define __NR_timer_delete (__NR_SYSCALL_BASE+261)
+# endif
+# ifndef __NR_clock_settime
+# define __NR_clock_settime (__NR_SYSCALL_BASE+262)
+# endif
+# ifndef __NR_clock_gettime
+# define __NR_clock_gettime (__NR_SYSCALL_BASE+263)
+# endif
+# ifndef __NR_clock_getres
+# define __NR_clock_getres (__NR_SYSCALL_BASE+264)
+# endif
+# ifndef __NR_clock_nanosleep
+# define __NR_clock_nanosleep (__NR_SYSCALL_BASE+265)
+# endif
+# ifndef __NR_statfs64
+# define __NR_statfs64 (__NR_SYSCALL_BASE+266)
+# endif
+# ifndef __NR_fstatfs64
+# define __NR_fstatfs64 (__NR_SYSCALL_BASE+267)
+# endif
+# ifndef __NR_tgkill
+# define __NR_tgkill (__NR_SYSCALL_BASE+268)
+# endif
+# ifndef __NR_utimes
+# define __NR_utimes (__NR_SYSCALL_BASE+269)
+# endif
+# ifndef __NR_arm_fadvise64_64
+# define __NR_arm_fadvise64_64 (__NR_SYSCALL_BASE+270)
+# endif
+# ifndef __NR_pciconfig_iobase
+# define __NR_pciconfig_iobase (__NR_SYSCALL_BASE+271)
+# endif
+# ifndef __NR_pciconfig_read
+# define __NR_pciconfig_read (__NR_SYSCALL_BASE+272)
+# endif
+# ifndef __NR_pciconfig_write
+# define __NR_pciconfig_write (__NR_SYSCALL_BASE+273)
+# endif
+# ifndef __NR_mq_open
+# define __NR_mq_open (__NR_SYSCALL_BASE+274)
+# endif
+# ifndef __NR_mq_unlink
+# define __NR_mq_unlink (__NR_SYSCALL_BASE+275)
+# endif
+# ifndef __NR_mq_timedsend
+# define __NR_mq_timedsend (__NR_SYSCALL_BASE+276)
+# endif
+# ifndef __NR_mq_timedreceive
+# define __NR_mq_timedreceive (__NR_SYSCALL_BASE+277)
+# endif
+# ifndef __NR_mq_notify
+# define __NR_mq_notify (__NR_SYSCALL_BASE+278)
+# endif
+# ifndef __NR_mq_getsetattr
+# define __NR_mq_getsetattr (__NR_SYSCALL_BASE+279)
+# endif
+# ifndef __NR_waitid
+# define __NR_waitid (__NR_SYSCALL_BASE+280)
+# endif
+# ifndef __NR_socket
+# define __NR_socket (__NR_SYSCALL_BASE+281)
+# endif
+# ifndef __NR_bind
+# define __NR_bind (__NR_SYSCALL_BASE+282)
+# endif
+# ifndef __NR_connect
+# define __NR_connect (__NR_SYSCALL_BASE+283)
+# endif
+# ifndef __NR_listen
+# define __NR_listen (__NR_SYSCALL_BASE+284)
+# endif
+# ifndef __NR_accept
+# define __NR_accept (__NR_SYSCALL_BASE+285)
+# endif
+# ifndef __NR_getsockname
+# define __NR_getsockname (__NR_SYSCALL_BASE+286)
+# endif
+# ifndef __NR_getpeername
+# define __NR_getpeername (__NR_SYSCALL_BASE+287)
+# endif
+# ifndef __NR_socketpair
+# define __NR_socketpair (__NR_SYSCALL_BASE+288)
+# endif
+# ifndef __NR_send
+# define __NR_send (__NR_SYSCALL_BASE+289)
+# endif
+# ifndef __NR_sendto
+# define __NR_sendto (__NR_SYSCALL_BASE+290)
+# endif
+# ifndef __NR_recv
+# define __NR_recv (__NR_SYSCALL_BASE+291)
+# endif
+# ifndef __NR_recvfrom
+# define __NR_recvfrom (__NR_SYSCALL_BASE+292)
+# endif
+# ifndef __NR_shutdown
+# define __NR_shutdown (__NR_SYSCALL_BASE+293)
+# endif
+# ifndef __NR_setsockopt
+# define __NR_setsockopt (__NR_SYSCALL_BASE+294)
+# endif
+# ifndef __NR_getsockopt
+# define __NR_getsockopt (__NR_SYSCALL_BASE+295)
+# endif
+# ifndef __NR_sendmsg
+# define __NR_sendmsg (__NR_SYSCALL_BASE+296)
+# endif
+# ifndef __NR_recvmsg
+# define __NR_recvmsg (__NR_SYSCALL_BASE+297)
+# endif
+# ifndef __NR_semop
+# define __NR_semop (__NR_SYSCALL_BASE+298)
+# endif
+# ifndef __NR_semget
+# define __NR_semget (__NR_SYSCALL_BASE+299)
+# endif
+# ifndef __NR_semctl
+# define __NR_semctl (__NR_SYSCALL_BASE+300)
+# endif
+# ifndef __NR_msgsnd
+# define __NR_msgsnd (__NR_SYSCALL_BASE+301)
+# endif
+# ifndef __NR_msgrcv
+# define __NR_msgrcv (__NR_SYSCALL_BASE+302)
+# endif
+# ifndef __NR_msgget
+# define __NR_msgget (__NR_SYSCALL_BASE+303)
+# endif
+# ifndef __NR_msgctl
+# define __NR_msgctl (__NR_SYSCALL_BASE+304)
+# endif
+# ifndef __NR_shmat
+# define __NR_shmat (__NR_SYSCALL_BASE+305)
+# endif
+# ifndef __NR_shmdt
+# define __NR_shmdt (__NR_SYSCALL_BASE+306)
+# endif
+# ifndef __NR_shmget
+# define __NR_shmget (__NR_SYSCALL_BASE+307)
+# endif
+# ifndef __NR_shmctl
+# define __NR_shmctl (__NR_SYSCALL_BASE+308)
+# endif
+# ifndef __NR_add_key
+# define __NR_add_key (__NR_SYSCALL_BASE+309)
+# endif
+# ifndef __NR_request_key
+# define __NR_request_key (__NR_SYSCALL_BASE+310)
+# endif
+# ifndef __NR_keyctl
+# define __NR_keyctl (__NR_SYSCALL_BASE+311)
+# endif
+# ifndef __NR_semtimedop
+# define __NR_semtimedop (__NR_SYSCALL_BASE+312)
+# endif
+# ifndef __NR_vserver
+# define __NR_vserver (__NR_SYSCALL_BASE+313)
+# endif
+# ifndef __NR_ioprio_set
+# define __NR_ioprio_set (__NR_SYSCALL_BASE+314)
+# endif
+# ifndef __NR_ioprio_get
+# define __NR_ioprio_get (__NR_SYSCALL_BASE+315)
+# endif
+# ifndef __NR_inotify_init
+# define __NR_inotify_init (__NR_SYSCALL_BASE+316)
+# endif
+# ifndef __NR_inotify_add_watch
+# define __NR_inotify_add_watch (__NR_SYSCALL_BASE+317)
+# endif
+# ifndef __NR_inotify_rm_watch
+# define __NR_inotify_rm_watch (__NR_SYSCALL_BASE+318)
+# endif
+# ifndef __NR_mbind
+# define __NR_mbind (__NR_SYSCALL_BASE+319)
+# endif
+# ifndef __NR_get_mempolicy
+# define __NR_get_mempolicy (__NR_SYSCALL_BASE+320)
+# endif
+# ifndef __NR_set_mempolicy
+# define __NR_set_mempolicy (__NR_SYSCALL_BASE+321)
+# endif
+# ifndef __NR_openat
+# define __NR_openat (__NR_SYSCALL_BASE+322)
+# endif
+# ifndef __NR_mkdirat
+# define __NR_mkdirat (__NR_SYSCALL_BASE+323)
+# endif
+# ifndef __NR_mknodat
+# define __NR_mknodat (__NR_SYSCALL_BASE+324)
+# endif
+# ifndef __NR_fchownat
+# define __NR_fchownat (__NR_SYSCALL_BASE+325)
+# endif
+# ifndef __NR_futimesat
+# define __NR_futimesat (__NR_SYSCALL_BASE+326)
+# endif
+# ifndef __NR_fstatat64
+# define __NR_fstatat64 (__NR_SYSCALL_BASE+327)
+# endif
+# ifndef __NR_unlinkat
+# define __NR_unlinkat (__NR_SYSCALL_BASE+328)
+# endif
+# ifndef __NR_renameat
+# define __NR_renameat (__NR_SYSCALL_BASE+329)
+# endif
+# ifndef __NR_linkat
+# define __NR_linkat (__NR_SYSCALL_BASE+330)
+# endif
+# ifndef __NR_symlinkat
+# define __NR_symlinkat (__NR_SYSCALL_BASE+331)
+# endif
+# ifndef __NR_readlinkat
+# define __NR_readlinkat (__NR_SYSCALL_BASE+332)
+# endif
+# ifndef __NR_fchmodat
+# define __NR_fchmodat (__NR_SYSCALL_BASE+333)
+# endif
+# ifndef __NR_faccessat
+# define __NR_faccessat (__NR_SYSCALL_BASE+334)
+# endif
+# ifndef __NR_pselect6
+# define __NR_pselect6 (__NR_SYSCALL_BASE+335)
+# endif
+# ifndef __NR_ppoll
+# define __NR_ppoll (__NR_SYSCALL_BASE+336)
+# endif
+# ifndef __NR_unshare
+# define __NR_unshare (__NR_SYSCALL_BASE+337)
+# endif
+# ifndef __NR_set_robust_list
+# define __NR_set_robust_list (__NR_SYSCALL_BASE+338)
+# endif
+# ifndef __NR_get_robust_list
+# define __NR_get_robust_list (__NR_SYSCALL_BASE+339)
+# endif
+# ifndef __NR_splice
+# define __NR_splice (__NR_SYSCALL_BASE+340)
+# endif
+# ifndef __NR_arm_sync_file_range
+# define __NR_arm_sync_file_range (__NR_SYSCALL_BASE+341)
+# endif
+# ifndef __NR_sync_file_range2
+# define __NR_sync_file_range2 __NR_arm_sync_file_range
+# endif
+# ifndef __NR_tee
+# define __NR_tee (__NR_SYSCALL_BASE+342)
+# endif
+# ifndef __NR_vmsplice
+# define __NR_vmsplice (__NR_SYSCALL_BASE+343)
+# endif
+# ifndef __NR_move_pages
+# define __NR_move_pages (__NR_SYSCALL_BASE+344)
+# endif
+# ifndef __NR_getcpu
+# define __NR_getcpu (__NR_SYSCALL_BASE+345)
+# endif
+# ifndef __NR_epoll_pwait
+# define __NR_epoll_pwait (__NR_SYSCALL_BASE+346)
+# endif
+# ifndef __NR_kexec_load
+# define __NR_kexec_load (__NR_SYSCALL_BASE+347)
+# endif
+# ifndef __NR_utimensat
+# define __NR_utimensat (__NR_SYSCALL_BASE+348)
+# endif
+# ifndef __NR_signalfd
+# define __NR_signalfd (__NR_SYSCALL_BASE+349)
+# endif
+# ifndef __NR_timerfd_create
+# define __NR_timerfd_create (__NR_SYSCALL_BASE+350)
+# endif
+# ifndef __NR_eventfd
+# define __NR_eventfd (__NR_SYSCALL_BASE+351)
+# endif
+# ifndef __NR_fallocate
+# define __NR_fallocate (__NR_SYSCALL_BASE+352)
+# endif
+# ifndef __NR_timerfd_settime
+# define __NR_timerfd_settime (__NR_SYSCALL_BASE+353)
+# endif
+# ifndef __NR_timerfd_gettime
+# define __NR_timerfd_gettime (__NR_SYSCALL_BASE+354)
+# endif
+# ifndef __NR_signalfd4
+# define __NR_signalfd4 (__NR_SYSCALL_BASE+355)
+# endif
+# ifndef __NR_eventfd2
+# define __NR_eventfd2 (__NR_SYSCALL_BASE+356)
+# endif
+# ifndef __NR_epoll_create1
+# define __NR_epoll_create1 (__NR_SYSCALL_BASE+357)
+# endif
+# ifndef __NR_dup3
+# define __NR_dup3 (__NR_SYSCALL_BASE+358)
+# endif
+# ifndef __NR_pipe2
+# define __NR_pipe2 (__NR_SYSCALL_BASE+359)
+# endif
+# ifndef __NR_inotify_init1
+# define __NR_inotify_init1 (__NR_SYSCALL_BASE+360)
+# endif
+# ifndef __NR_preadv
+# define __NR_preadv (__NR_SYSCALL_BASE+361)
+# endif
+# ifndef __NR_pwritev
+# define __NR_pwritev (__NR_SYSCALL_BASE+362)
+# endif
+# ifndef __NR_rt_tgsigqueueinfo
+# define __NR_rt_tgsigqueueinfo (__NR_SYSCALL_BASE+363)
+# endif
+# ifndef __NR_perf_event_open
+# define __NR_perf_event_open (__NR_SYSCALL_BASE+364)
+# endif
+# ifndef __NR_recvmmsg
+# define __NR_recvmmsg (__NR_SYSCALL_BASE+365)
+# endif
+# ifndef __NR_accept4
+# define __NR_accept4 (__NR_SYSCALL_BASE+366)
+# endif
+# ifndef __NR_fanotify_init
+# define __NR_fanotify_init (__NR_SYSCALL_BASE+367)
+# endif
+# ifndef __NR_fanotify_mark
+# define __NR_fanotify_mark (__NR_SYSCALL_BASE+368)
+# endif
+# ifndef __NR_prlimit64
+# define __NR_prlimit64 (__NR_SYSCALL_BASE+369)
+# endif
+# ifndef __NR_name_to_handle_at
+# define __NR_name_to_handle_at (__NR_SYSCALL_BASE+370)
+# endif
+# ifndef __NR_open_by_handle_at
+# define __NR_open_by_handle_at (__NR_SYSCALL_BASE+371)
+# endif
+# ifndef __NR_clock_adjtime
+# define __NR_clock_adjtime (__NR_SYSCALL_BASE+372)
+# endif
+# ifndef __NR_syncfs
+# define __NR_syncfs (__NR_SYSCALL_BASE+373)
+# endif
+# ifndef __NR_sendmmsg
+# define __NR_sendmmsg (__NR_SYSCALL_BASE+374)
+# endif
+# ifndef __NR_setns
+# define __NR_setns (__NR_SYSCALL_BASE+375)
+# endif
+# ifndef __NR_process_vm_readv
+# define __NR_process_vm_readv (__NR_SYSCALL_BASE+376)
+# endif
+# ifndef __NR_process_vm_writev
+# define __NR_process_vm_writev (__NR_SYSCALL_BASE+377)
+# endif
+# ifndef __NR_kcmp
+# define __NR_kcmp (__NR_SYSCALL_BASE+378)
+# endif
+# ifndef __NR_finit_module
+# define __NR_finit_module (__NR_SYSCALL_BASE+379)
+# endif
+# ifndef __NR_sched_setattr
+# define __NR_sched_setattr (__NR_SYSCALL_BASE+380)
+# endif
+# ifndef __NR_sched_getattr
+# define __NR_sched_getattr (__NR_SYSCALL_BASE+381)
+# endif
+# ifndef __NR_renameat2
+# define __NR_renameat2 (__NR_SYSCALL_BASE+382)
+# endif
+# ifndef __NR_seccomp
+# define __NR_seccomp (__NR_SYSCALL_BASE+383)
+# endif
+# ifndef __NR_getrandom
+# define __NR_getrandom (__NR_SYSCALL_BASE+384)
+# endif
+# ifndef __NR_memfd_create
+# define __NR_memfd_create (__NR_SYSCALL_BASE+385)
+# endif
+# ifndef __NR_bpf
+# define __NR_bpf (__NR_SYSCALL_BASE+386)
+# endif
+# ifndef __NR_execveat
+# define __NR_execveat (__NR_SYSCALL_BASE+387)
+# endif
+# ifndef __NR_userfaultfd
+# define __NR_userfaultfd (__NR_SYSCALL_BASE+388)
+# endif
+# ifndef __NR_membarrier
+# define __NR_membarrier (__NR_SYSCALL_BASE+389)
+# endif
+# ifndef __NR_mlock2
+# define __NR_mlock2 (__NR_SYSCALL_BASE+390)
+# endif
+# ifndef __NR_copy_file_range
+# define __NR_copy_file_range (__NR_SYSCALL_BASE+391)
+# endif
+# ifndef __NR_preadv2
+# define __NR_preadv2 (__NR_SYSCALL_BASE+392)
+# endif
+# ifndef __NR_pwritev2
+# define __NR_pwritev2 (__NR_SYSCALL_BASE+393)
+# endif
+# ifndef __NR_pkey_mprotect
+# define __NR_pkey_mprotect (__NR_SYSCALL_BASE+394)
+# endif
+# ifndef __NR_pkey_alloc
+# define __NR_pkey_alloc (__NR_SYSCALL_BASE+395)
+# endif
+# ifndef __NR_pkey_free
+# define __NR_pkey_free (__NR_SYSCALL_BASE+396)
+# endif
+# ifndef __NR_statx
+# define __NR_statx (__NR_SYSCALL_BASE+397)
+# endif
+# ifndef __NR_rseq
+# define __NR_rseq (__NR_SYSCALL_BASE+398)
+# endif
+# ifndef __NR_io_pgetevents
+# define __NR_io_pgetevents (__NR_SYSCALL_BASE+399)
+# endif
+# ifndef __NR_migrate_pages
+# define __NR_migrate_pages (__NR_SYSCALL_BASE+400)
+# endif
+# ifndef __NR_kexec_file_load
+# define __NR_kexec_file_load (__NR_SYSCALL_BASE+401)
+# endif
+# ifndef __NR_clock_gettime64
+# define __NR_clock_gettime64 (__NR_SYSCALL_BASE+403)
+# endif
+# ifndef __NR_clock_settime64
+# define __NR_clock_settime64 (__NR_SYSCALL_BASE+404)
+# endif
+# ifndef __NR_clock_adjtime64
+# define __NR_clock_adjtime64 (__NR_SYSCALL_BASE+405)
+# endif
+# ifndef __NR_clock_getres_time64
+# define __NR_clock_getres_time64 (__NR_SYSCALL_BASE+406)
+# endif
+# ifndef __NR_clock_nanosleep_time64
+# define __NR_clock_nanosleep_time64 (__NR_SYSCALL_BASE+407)
+# endif
+# ifndef __NR_timer_gettime64
+# define __NR_timer_gettime64 (__NR_SYSCALL_BASE+408)
+# endif
+# ifndef __NR_timer_settime64
+# define __NR_timer_settime64 (__NR_SYSCALL_BASE+409)
+# endif
+# ifndef __NR_timerfd_gettime64
+# define __NR_timerfd_gettime64 (__NR_SYSCALL_BASE+410)
+# endif
+# ifndef __NR_timerfd_settime64
+# define __NR_timerfd_settime64 (__NR_SYSCALL_BASE+411)
+# endif
+# ifndef __NR_utimensat_time64
+# define __NR_utimensat_time64 (__NR_SYSCALL_BASE+412)
+# endif
+# ifndef __NR_pselect6_time64
+# define __NR_pselect6_time64 (__NR_SYSCALL_BASE+413)
+# endif
+# ifndef __NR_ppoll_time64
+# define __NR_ppoll_time64 (__NR_SYSCALL_BASE+414)
+# endif
+# ifndef __NR_io_pgetevents_time64
+# define __NR_io_pgetevents_time64 (__NR_SYSCALL_BASE+416)
+# endif
+# ifndef __NR_recvmmsg_time64
+# define __NR_recvmmsg_time64 (__NR_SYSCALL_BASE+417)
+# endif
+# ifndef __NR_mq_timedsend_time64
+# define __NR_mq_timedsend_time64 (__NR_SYSCALL_BASE+418)
+# endif
+# ifndef __NR_mq_timedreceive_time64
+# define __NR_mq_timedreceive_time64 (__NR_SYSCALL_BASE+419)
+# endif
+# ifndef __NR_semtimedop_time64
+# define __NR_semtimedop_time64 (__NR_SYSCALL_BASE+420)
+# endif
+# ifndef __NR_rt_sigtimedwait_time64
+# define __NR_rt_sigtimedwait_time64 (__NR_SYSCALL_BASE+421)
+# endif
+# ifndef __NR_futex_time64
+# define __NR_futex_time64 (__NR_SYSCALL_BASE+422)
+# endif
+# ifndef __NR_sched_rr_get_interval_time64
+# define __NR_sched_rr_get_interval_time64 (__NR_SYSCALL_BASE+423)
+# endif
+# ifndef __NR_pidfd_send_signal
+# define __NR_pidfd_send_signal (__NR_SYSCALL_BASE+424)
+# endif
+# ifndef __NR_io_uring_setup
+# define __NR_io_uring_setup (__NR_SYSCALL_BASE+425)
+# endif
+# ifndef __NR_io_uring_enter
+# define __NR_io_uring_enter (__NR_SYSCALL_BASE+426)
+# endif
+# ifndef __NR_io_uring_register
+# define __NR_io_uring_register (__NR_SYSCALL_BASE+427)
+# endif
+# ifndef __NR_open_tree
+# define __NR_open_tree (__NR_SYSCALL_BASE+428)
+# endif
+# ifndef __NR_move_mount
+# define __NR_move_mount (__NR_SYSCALL_BASE+429)
+# endif
+# ifndef __NR_fsopen
+# define __NR_fsopen (__NR_SYSCALL_BASE+430)
+# endif
+# ifndef __NR_fsconfig
+# define __NR_fsconfig (__NR_SYSCALL_BASE+431)
+# endif
+# ifndef __NR_fsmount
+# define __NR_fsmount (__NR_SYSCALL_BASE+432)
+# endif
+# ifndef __NR_fspick
+# define __NR_fspick (__NR_SYSCALL_BASE+433)
+# endif
+# ifndef __NR_pidfd_open
+# define __NR_pidfd_open (__NR_SYSCALL_BASE+434)
+# endif
+# ifndef __NR_clone3
+# define __NR_clone3 (__NR_SYSCALL_BASE+435)
+# endif
+# ifndef __NR_openat2
+# define __NR_openat2 (__NR_SYSCALL_BASE+437)
+# endif
+# ifndef __NR_pidfd_getfd
+# define __NR_pidfd_getfd (__NR_SYSCALL_BASE+438)
+# endif
+#endif
+
+
+#ifdef __hppa__
+# ifndef __NR__sysctl
+# define __NR__sysctl 149
+# endif
+# ifndef __NR_openat
+# define __NR_openat 275
+# endif
+# ifndef __NR_mkdirat
+# define __NR_mkdirat (__NR_openat + 1)
+# endif
+# ifndef __NR_mknodat
+# define __NR_mknodat (__NR_openat + 2)
+# endif
+# ifndef __NR_fchownat
+# define __NR_fchownat (__NR_openat + 3)
+# endif
+# ifndef __NR_futimesat
+# define __NR_futimesat (__NR_openat + 4)
+# endif
+# ifndef __NR_newfstatat
+# define __NR_newfstatat (__NR_openat + 5)
+# endif
+# ifndef __NR_fstatat64
+# define __NR_fstatat64 (__NR_openat + 5)
+# endif
+# ifndef __NR_unlinkat
+# define __NR_unlinkat (__NR_openat + 6)
+# endif
+# ifndef __NR_renameat
+# define __NR_renameat (__NR_openat + 7)
+# endif
+# ifndef __NR_linkat
+# define __NR_linkat (__NR_openat + 8)
+# endif
+# ifndef __NR_symlinkat
+# define __NR_symlinkat (__NR_openat + 9)
+# endif
+# ifndef __NR_readlinkat
+# define __NR_readlinkat (__NR_openat + 10)
+# endif
+# ifndef __NR_fchmodat
+# define __NR_fchmodat (__NR_openat + 11)
+# endif
+# ifndef __NR_faccessat
+# define __NR_faccessat (__NR_openat + 12)
+# endif
+# ifndef __NR_splice
+# define __NR_splice 291
+# endif
+# ifndef __NR_tee
+# define __NR_tee 293
+# endif
+# ifndef __NR_vmsplice
+# define __NR_vmsplice 294
+# endif
+# ifndef __NR_syncfs
+# define __NR_syncfs 327
+# endif
+# ifndef __NR_setns
+# define __NR_setns 328
+# endif
+# ifndef __NR_process_vm_readv
+# define __NR_process_vm_readv 330
+# endif
+# ifndef __NR_process_vm_writev
+# define __NR_process_vm_writev 331
+# endif
+# ifndef __NR_memfd_create
+# define __NR_memfd_create 340
+# endif
+# ifndef __NR_membarrier
+# define __NR_membarrier 343
+# endif
+# ifndef __NR_execveat
+# define __NR_execveat 342
+# endif
+# ifndef __NR_mlock2
+# define __NR_mlock2 345
+# endif
+# ifndef __NR_copy_file_range
+# define __NR_copy_file_range 346
+# endif
+# ifndef __NR_preadv2
+# define __NR_preadv2 347
+# endif
+# ifndef __NR_pwritev2
+# define __NR_pwritev2 348
+# endif
+# ifndef __NR_io_pgetevents
+# define __NR_io_pgetevents 350
+# endif
+# ifndef __NR_pidfd_send_signal
+# define __NR_pidfd_send_signal 424
+# endif
+# ifndef __NR_io_uring_setup
+# define __NR_io_uring_setup 425
+# endif
+# ifndef __NR_io_uring_enter
+# define __NR_io_uring_enter 426
+# endif
+# ifndef __NR_io_uring_register
+# define __NR_io_uring_register 427
+# endif
+# ifndef __NR_open_tree
+# define __NR_open_tree 428
+# endif
+# ifndef __NR_move_mount
+# define __NR_move_mount 429
+# endif
+# ifndef __NR_fsopen
+# define __NR_fsopen 430
+# endif
+# ifndef __NR_fsconfig
+# define __NR_fsconfig 431
+# endif
+# ifndef __NR_fsmount
+# define __NR_fsmount 432
+# endif
+# ifndef __NR_fspick
+# define __NR_fspick 433
+# endif
+# ifndef __NR_pidfd_open
+# define __NR_pidfd_open 434
+# endif
+#endif
+
+
+#ifdef __i386__
+# ifndef __NR_restart_syscall
+# define __NR_restart_syscall 0
+# endif
+# ifndef __NR_exit
+# define __NR_exit 1
+# endif
+# ifndef __NR_fork
+# define __NR_fork 2
+# endif
+# ifndef __NR_read
+# define __NR_read 3
+# endif
+# ifndef __NR_write
+# define __NR_write 4
+# endif
+# ifndef __NR_open
+# define __NR_open 5
+# endif
+# ifndef __NR_close
+# define __NR_close 6
+# endif
+# ifndef __NR_waitpid
+# define __NR_waitpid 7
+# endif
+# ifndef __NR_creat
+# define __NR_creat 8
+# endif
+# ifndef __NR_link
+# define __NR_link 9
+# endif
+# ifndef __NR_unlink
+# define __NR_unlink 10
+# endif
+# ifndef __NR_execve
+# define __NR_execve 11
+# endif
+# ifndef __NR_chdir
+# define __NR_chdir 12
+# endif
+# ifndef __NR_time
+# define __NR_time 13
+# endif
+# ifndef __NR_mknod
+# define __NR_mknod 14
+# endif
+# ifndef __NR_chmod
+# define __NR_chmod 15
+# endif
+# ifndef __NR_lchown
+# define __NR_lchown 16
+# endif
+# ifndef __NR_break
+# define __NR_break 17
+# endif
+# ifndef __NR_oldstat
+# define __NR_oldstat 18
+# endif
+# ifndef __NR_lseek
+# define __NR_lseek 19
+# endif
+# ifndef __NR_getpid
+# define __NR_getpid 20
+# endif
+# ifndef __NR_mount
+# define __NR_mount 21
+# endif
+# ifndef __NR_umount
+# define __NR_umount 22
+# endif
+# ifndef __NR_setuid
+# define __NR_setuid 23
+# endif
+# ifndef __NR_getuid
+# define __NR_getuid 24
+# endif
+# ifndef __NR_stime
+# define __NR_stime 25
+# endif
+# ifndef __NR_ptrace
+# define __NR_ptrace 26
+# endif
+# ifndef __NR_alarm
+# define __NR_alarm 27
+# endif
+# ifndef __NR_oldfstat
+# define __NR_oldfstat 28
+# endif
+# ifndef __NR_pause
+# define __NR_pause 29
+# endif
+# ifndef __NR_utime
+# define __NR_utime 30
+# endif
+# ifndef __NR_stty
+# define __NR_stty 31
+# endif
+# ifndef __NR_gtty
+# define __NR_gtty 32
+# endif
+# ifndef __NR_access
+# define __NR_access 33
+# endif
+# ifndef __NR_nice
+# define __NR_nice 34
+# endif
+# ifndef __NR_ftime
+# define __NR_ftime 35
+# endif
+# ifndef __NR_sync
+# define __NR_sync 36
+# endif
+# ifndef __NR_kill
+# define __NR_kill 37
+# endif
+# ifndef __NR_rename
+# define __NR_rename 38
+# endif
+# ifndef __NR_mkdir
+# define __NR_mkdir 39
+# endif
+# ifndef __NR_rmdir
+# define __NR_rmdir 40
+# endif
+# ifndef __NR_dup
+# define __NR_dup 41
+# endif
+# ifndef __NR_pipe
+# define __NR_pipe 42
+# endif
+# ifndef __NR_times
+# define __NR_times 43
+# endif
+# ifndef __NR_prof
+# define __NR_prof 44
+# endif
+# ifndef __NR_brk
+# define __NR_brk 45
+# endif
+# ifndef __NR_setgid
+# define __NR_setgid 46
+# endif
+# ifndef __NR_getgid
+# define __NR_getgid 47
+# endif
+# ifndef __NR_signal
+# define __NR_signal 48
+# endif
+# ifndef __NR_geteuid
+# define __NR_geteuid 49
+# endif
+# ifndef __NR_getegid
+# define __NR_getegid 50
+# endif
+# ifndef __NR_acct
+# define __NR_acct 51
+# endif
+# ifndef __NR_umount2
+# define __NR_umount2 52
+# endif
+# ifndef __NR_lock
+# define __NR_lock 53
+# endif
+# ifndef __NR_ioctl
+# define __NR_ioctl 54
+# endif
+# ifndef __NR_fcntl
+# define __NR_fcntl 55
+# endif
+# ifndef __NR_mpx
+# define __NR_mpx 56
+# endif
+# ifndef __NR_setpgid
+# define __NR_setpgid 57
+# endif
+# ifndef __NR_ulimit
+# define __NR_ulimit 58
+# endif
+# ifndef __NR_oldolduname
+# define __NR_oldolduname 59
+# endif
+# ifndef __NR_umask
+# define __NR_umask 60
+# endif
+# ifndef __NR_chroot
+# define __NR_chroot 61
+# endif
+# ifndef __NR_ustat
+# define __NR_ustat 62
+# endif
+# ifndef __NR_dup2
+# define __NR_dup2 63
+# endif
+# ifndef __NR_getppid
+# define __NR_getppid 64
+# endif
+# ifndef __NR_getpgrp
+# define __NR_getpgrp 65
+# endif
+# ifndef __NR_setsid
+# define __NR_setsid 66
+# endif
+# ifndef __NR_sigaction
+# define __NR_sigaction 67
+# endif
+# ifndef __NR_sgetmask
+# define __NR_sgetmask 68
+# endif
+# ifndef __NR_ssetmask
+# define __NR_ssetmask 69
+# endif
+# ifndef __NR_setreuid
+# define __NR_setreuid 70
+# endif
+# ifndef __NR_setregid
+# define __NR_setregid 71
+# endif
+# ifndef __NR_sigsuspend
+# define __NR_sigsuspend 72
+# endif
+# ifndef __NR_sigpending
+# define __NR_sigpending 73
+# endif
+# ifndef __NR_sethostname
+# define __NR_sethostname 74
+# endif
+# ifndef __NR_setrlimit
+# define __NR_setrlimit 75
+# endif
+# ifndef __NR_getrlimit
+# define __NR_getrlimit 76
+# endif
+# ifndef __NR_getrusage
+# define __NR_getrusage 77
+# endif
+# ifndef __NR_gettimeofday
+# define __NR_gettimeofday 78
+# endif
+# ifndef __NR_settimeofday
+# define __NR_settimeofday 79
+# endif
+# ifndef __NR_getgroups
+# define __NR_getgroups 80
+# endif
+# ifndef __NR_setgroups
+# define __NR_setgroups 81
+# endif
+# ifndef __NR_select
+# define __NR_select 82
+# endif
+# ifndef __NR_symlink
+# define __NR_symlink 83
+# endif
+# ifndef __NR_oldlstat
+# define __NR_oldlstat 84
+# endif
+# ifndef __NR_readlink
+# define __NR_readlink 85
+# endif
+# ifndef __NR_uselib
+# define __NR_uselib 86
+# endif
+# ifndef __NR_swapon
+# define __NR_swapon 87
+# endif
+# ifndef __NR_reboot
+# define __NR_reboot 88
+# endif
+# ifndef __NR_readdir
+# define __NR_readdir 89
+# endif
+# ifndef __NR_mmap
+# define __NR_mmap 90
+# endif
+# ifndef __NR_munmap
+# define __NR_munmap 91
+# endif
+# ifndef __NR_truncate
+# define __NR_truncate 92
+# endif
+# ifndef __NR_ftruncate
+# define __NR_ftruncate 93
+# endif
+# ifndef __NR_fchmod
+# define __NR_fchmod 94
+# endif
+# ifndef __NR_fchown
+# define __NR_fchown 95
+# endif
+# ifndef __NR_getpriority
+# define __NR_getpriority 96
+# endif
+# ifndef __NR_setpriority
+# define __NR_setpriority 97
+# endif
+# ifndef __NR_profil
+# define __NR_profil 98
+# endif
+# ifndef __NR_statfs
+# define __NR_statfs 99
+# endif
+# ifndef __NR_fstatfs
+# define __NR_fstatfs 100
+# endif
+# ifndef __NR_ioperm
+# define __NR_ioperm 101
+# endif
+# ifndef __NR_socketcall
+# define __NR_socketcall 102
+# endif
+# ifndef __NR_syslog
+# define __NR_syslog 103
+# endif
+# ifndef __NR_setitimer
+# define __NR_setitimer 104
+# endif
+# ifndef __NR_getitimer
+# define __NR_getitimer 105
+# endif
+# ifndef __NR_stat
+# define __NR_stat 106
+# endif
+# ifndef __NR_lstat
+# define __NR_lstat 107
+# endif
+# ifndef __NR_fstat
+# define __NR_fstat 108
+# endif
+# ifndef __NR_olduname
+# define __NR_olduname 109
+# endif
+# ifndef __NR_iopl
+# define __NR_iopl 110
+# endif
+# ifndef __NR_vhangup
+# define __NR_vhangup 111
+# endif
+# ifndef __NR_idle
+# define __NR_idle 112
+# endif
+# ifndef __NR_vm86old
+# define __NR_vm86old 113
+# endif
+# ifndef __NR_wait4
+# define __NR_wait4 114
+# endif
+# ifndef __NR_swapoff
+# define __NR_swapoff 115
+# endif
+# ifndef __NR_sysinfo
+# define __NR_sysinfo 116
+# endif
+# ifndef __NR_ipc
+# define __NR_ipc 117
+# endif
+# ifndef __NR_fsync
+# define __NR_fsync 118
+# endif
+# ifndef __NR_sigreturn
+# define __NR_sigreturn 119
+# endif
+# ifndef __NR_clone
+# define __NR_clone 120
+# endif
+# ifndef __NR_setdomainname
+# define __NR_setdomainname 121
+# endif
+# ifndef __NR_uname
+# define __NR_uname 122
+# endif
+# ifndef __NR_modify_ldt
+# define __NR_modify_ldt 123
+# endif
+# ifndef __NR_adjtimex
+# define __NR_adjtimex 124
+# endif
+# ifndef __NR_mprotect
+# define __NR_mprotect 125
+# endif
+# ifndef __NR_sigprocmask
+# define __NR_sigprocmask 126
+# endif
+# ifndef __NR_create_module
+# define __NR_create_module 127
+# endif
+# ifndef __NR_init_module
+# define __NR_init_module 128
+# endif
+# ifndef __NR_delete_module
+# define __NR_delete_module 129
+# endif
+# ifndef __NR_get_kernel_syms
+# define __NR_get_kernel_syms 130
+# endif
+# ifndef __NR_quotactl
+# define __NR_quotactl 131
+# endif
+# ifndef __NR_getpgid
+# define __NR_getpgid 132
+# endif
+# ifndef __NR_fchdir
+# define __NR_fchdir 133
+# endif
+# ifndef __NR_bdflush
+# define __NR_bdflush 134
+# endif
+# ifndef __NR_sysfs
+# define __NR_sysfs 135
+# endif
+# ifndef __NR_personality
+# define __NR_personality 136
+# endif
+# ifndef __NR_afs_syscall
+# define __NR_afs_syscall 137
+# endif
+# ifndef __NR_setfsuid
+# define __NR_setfsuid 138
+# endif
+# ifndef __NR_setfsgid
+# define __NR_setfsgid 139
+# endif
+# ifndef __NR__llseek
+# define __NR__llseek 140
+# endif
+# ifndef __NR_getdents
+# define __NR_getdents 141
+# endif
+# ifndef __NR__newselect
+# define __NR__newselect 142
+# endif
+# ifndef __NR_flock
+# define __NR_flock 143
+# endif
+# ifndef __NR_msync
+# define __NR_msync 144
+# endif
+# ifndef __NR_readv
+# define __NR_readv 145
+# endif
+# ifndef __NR_writev
+# define __NR_writev 146
+# endif
+# ifndef __NR_getsid
+# define __NR_getsid 147
+# endif
+# ifndef __NR_fdatasync
+# define __NR_fdatasync 148
+# endif
+# ifndef __NR__sysctl
+# define __NR__sysctl 149
+# endif
+# ifndef __NR_mlock
+# define __NR_mlock 150
+# endif
+# ifndef __NR_munlock
+# define __NR_munlock 151
+# endif
+# ifndef __NR_mlockall
+# define __NR_mlockall 152
+# endif
+# ifndef __NR_munlockall
+# define __NR_munlockall 153
+# endif
+# ifndef __NR_sched_setparam
+# define __NR_sched_setparam 154
+# endif
+# ifndef __NR_sched_getparam
+# define __NR_sched_getparam 155
+# endif
+# ifndef __NR_sched_setscheduler
+# define __NR_sched_setscheduler 156
+# endif
+# ifndef __NR_sched_getscheduler
+# define __NR_sched_getscheduler 157
+# endif
+# ifndef __NR_sched_yield
+# define __NR_sched_yield 158
+# endif
+# ifndef __NR_sched_get_priority_max
+# define __NR_sched_get_priority_max 159
+# endif
+# ifndef __NR_sched_get_priority_min
+# define __NR_sched_get_priority_min 160
+# endif
+# ifndef __NR_sched_rr_get_interval
+# define __NR_sched_rr_get_interval 161
+# endif
+# ifndef __NR_nanosleep
+# define __NR_nanosleep 162
+# endif
+# ifndef __NR_mremap
+# define __NR_mremap 163
+# endif
+# ifndef __NR_setresuid
+# define __NR_setresuid 164
+# endif
+# ifndef __NR_getresuid
+# define __NR_getresuid 165
+# endif
+# ifndef __NR_vm86
+# define __NR_vm86 166
+# endif
+# ifndef __NR_query_module
+# define __NR_query_module 167
+# endif
+# ifndef __NR_poll
+# define __NR_poll 168
+# endif
+# ifndef __NR_nfsservctl
+# define __NR_nfsservctl 169
+# endif
+# ifndef __NR_setresgid
+# define __NR_setresgid 170
+# endif
+# ifndef __NR_getresgid
+# define __NR_getresgid 171
+# endif
+# ifndef __NR_prctl
+# define __NR_prctl 172
+# endif
+# ifndef __NR_rt_sigreturn
+# define __NR_rt_sigreturn 173
+# endif
+# ifndef __NR_rt_sigaction
+# define __NR_rt_sigaction 174
+# endif
+# ifndef __NR_rt_sigprocmask
+# define __NR_rt_sigprocmask 175
+# endif
+# ifndef __NR_rt_sigpending
+# define __NR_rt_sigpending 176
+# endif
+# ifndef __NR_rt_sigtimedwait
+# define __NR_rt_sigtimedwait 177
+# endif
+# ifndef __NR_rt_sigqueueinfo
+# define __NR_rt_sigqueueinfo 178
+# endif
+# ifndef __NR_rt_sigsuspend
+# define __NR_rt_sigsuspend 179
+# endif
+# ifndef __NR_pread64
+# define __NR_pread64 180
+# endif
+# ifndef __NR_pwrite64
+# define __NR_pwrite64 181
+# endif
+# ifndef __NR_chown
+# define __NR_chown 182
+# endif
+# ifndef __NR_getcwd
+# define __NR_getcwd 183
+# endif
+# ifndef __NR_capget
+# define __NR_capget 184
+# endif
+# ifndef __NR_capset
+# define __NR_capset 185
+# endif
+# ifndef __NR_sigaltstack
+# define __NR_sigaltstack 186
+# endif
+# ifndef __NR_sendfile
+# define __NR_sendfile 187
+# endif
+# ifndef __NR_getpmsg
+# define __NR_getpmsg 188
+# endif
+# ifndef __NR_putpmsg
+# define __NR_putpmsg 189
+# endif
+# ifndef __NR_vfork
+# define __NR_vfork 190
+# endif
+# ifndef __NR_ugetrlimit
+# define __NR_ugetrlimit 191
+# endif
+# ifndef __NR_mmap2
+# define __NR_mmap2 192
+# endif
+# ifndef __NR_truncate64
+# define __NR_truncate64 193
+# endif
+# ifndef __NR_ftruncate64
+# define __NR_ftruncate64 194
+# endif
+# ifndef __NR_stat64
+# define __NR_stat64 195
+# endif
+# ifndef __NR_lstat64
+# define __NR_lstat64 196
+# endif
+# ifndef __NR_fstat64
+# define __NR_fstat64 197
+# endif
+# ifndef __NR_lchown32
+# define __NR_lchown32 198
+# endif
+# ifndef __NR_getuid32
+# define __NR_getuid32 199
+# endif
+# ifndef __NR_getgid32
+# define __NR_getgid32 200
+# endif
+# ifndef __NR_geteuid32
+# define __NR_geteuid32 201
+# endif
+# ifndef __NR_getegid32
+# define __NR_getegid32 202
+# endif
+# ifndef __NR_setreuid32
+# define __NR_setreuid32 203
+# endif
+# ifndef __NR_setregid32
+# define __NR_setregid32 204
+# endif
+# ifndef __NR_getgroups32
+# define __NR_getgroups32 205
+# endif
+# ifndef __NR_setgroups32
+# define __NR_setgroups32 206
+# endif
+# ifndef __NR_fchown32
+# define __NR_fchown32 207
+# endif
+# ifndef __NR_setresuid32
+# define __NR_setresuid32 208
+# endif
+# ifndef __NR_getresuid32
+# define __NR_getresuid32 209
+# endif
+# ifndef __NR_setresgid32
+# define __NR_setresgid32 210
+# endif
+# ifndef __NR_getresgid32
+# define __NR_getresgid32 211
+# endif
+# ifndef __NR_chown32
+# define __NR_chown32 212
+# endif
+# ifndef __NR_setuid32
+# define __NR_setuid32 213
+# endif
+# ifndef __NR_setgid32
+# define __NR_setgid32 214
+# endif
+# ifndef __NR_setfsuid32
+# define __NR_setfsuid32 215
+# endif
+# ifndef __NR_setfsgid32
+# define __NR_setfsgid32 216
+# endif
+# ifndef __NR_pivot_root
+# define __NR_pivot_root 217
+# endif
+# ifndef __NR_mincore
+# define __NR_mincore 218
+# endif
+# ifndef __NR_madvise
+# define __NR_madvise 219
+# endif
+# ifndef __NR_madvise1
+# define __NR_madvise1 219
+# endif
+# ifndef __NR_getdents64
+# define __NR_getdents64 220
+# endif
+# ifndef __NR_fcntl64
+# define __NR_fcntl64 221
+# endif
+# ifndef __NR_gettid
+# define __NR_gettid 224
+# endif
+# ifndef __NR_readahead
+# define __NR_readahead 225
+# endif
+# ifndef __NR_setxattr
+# define __NR_setxattr 226
+# endif
+# ifndef __NR_lsetxattr
+# define __NR_lsetxattr 227
+# endif
+# ifndef __NR_fsetxattr
+# define __NR_fsetxattr 228
+# endif
+# ifndef __NR_getxattr
+# define __NR_getxattr 229
+# endif
+# ifndef __NR_lgetxattr
+# define __NR_lgetxattr 230
+# endif
+# ifndef __NR_fgetxattr
+# define __NR_fgetxattr 231
+# endif
+# ifndef __NR_listxattr
+# define __NR_listxattr 232
+# endif
+# ifndef __NR_llistxattr
+# define __NR_llistxattr 233
+# endif
+# ifndef __NR_flistxattr
+# define __NR_flistxattr 234
+# endif
+# ifndef __NR_removexattr
+# define __NR_removexattr 235
+# endif
+# ifndef __NR_lremovexattr
+# define __NR_lremovexattr 236
+# endif
+# ifndef __NR_fremovexattr
+# define __NR_fremovexattr 237
+# endif
+# ifndef __NR_tkill
+# define __NR_tkill 238
+# endif
+# ifndef __NR_sendfile64
+# define __NR_sendfile64 239
+# endif
+# ifndef __NR_futex
+# define __NR_futex 240
+# endif
+# ifndef __NR_sched_setaffinity
+# define __NR_sched_setaffinity 241
+# endif
+# ifndef __NR_sched_getaffinity
+# define __NR_sched_getaffinity 242
+# endif
+# ifndef __NR_set_thread_area
+# define __NR_set_thread_area 243
+# endif
+# ifndef __NR_get_thread_area
+# define __NR_get_thread_area 244
+# endif
+# ifndef __NR_io_setup
+# define __NR_io_setup 245
+# endif
+# ifndef __NR_io_destroy
+# define __NR_io_destroy 246
+# endif
+# ifndef __NR_io_getevents
+# define __NR_io_getevents 247
+# endif
+# ifndef __NR_io_submit
+# define __NR_io_submit 248
+# endif
+# ifndef __NR_io_cancel
+# define __NR_io_cancel 249
+# endif
+# ifndef __NR_fadvise64
+# define __NR_fadvise64 250
+# endif
+# ifndef __NR_exit_group
+# define __NR_exit_group 252
+# endif
+# ifndef __NR_lookup_dcookie
+# define __NR_lookup_dcookie 253
+# endif
+# ifndef __NR_epoll_create
+# define __NR_epoll_create 254
+# endif
+# ifndef __NR_epoll_ctl
+# define __NR_epoll_ctl 255
+# endif
+# ifndef __NR_epoll_wait
+# define __NR_epoll_wait 256
+# endif
+# ifndef __NR_remap_file_pages
+# define __NR_remap_file_pages 257
+# endif
+# ifndef __NR_set_tid_address
+# define __NR_set_tid_address 258
+# endif
+# ifndef __NR_timer_create
+# define __NR_timer_create 259
+# endif
+# ifndef __NR_timer_settime
+# define __NR_timer_settime 260
+# endif
+# ifndef __NR_timer_gettime
+# define __NR_timer_gettime 261
+# endif
+# ifndef __NR_timer_getoverrun
+# define __NR_timer_getoverrun 262
+# endif
+# ifndef __NR_timer_delete
+# define __NR_timer_delete 263
+# endif
+# ifndef __NR_clock_settime
+# define __NR_clock_settime 264
+# endif
+# ifndef __NR_clock_gettime
+# define __NR_clock_gettime 265
+# endif
+# ifndef __NR_clock_getres
+# define __NR_clock_getres 266
+# endif
+# ifndef __NR_clock_nanosleep
+# define __NR_clock_nanosleep 267
+# endif
+# ifndef __NR_statfs64
+# define __NR_statfs64 268
+# endif
+# ifndef __NR_fstatfs64
+# define __NR_fstatfs64 269
+# endif
+# ifndef __NR_tgkill
+# define __NR_tgkill 270
+# endif
+# ifndef __NR_utimes
+# define __NR_utimes 271
+# endif
+# ifndef __NR_fadvise64_64
+# define __NR_fadvise64_64 272
+# endif
+# ifndef __NR_vserver
+# define __NR_vserver 273
+# endif
+# ifndef __NR_mbind
+# define __NR_mbind 274
+# endif
+# ifndef __NR_get_mempolicy
+# define __NR_get_mempolicy 275
+# endif
+# ifndef __NR_set_mempolicy
+# define __NR_set_mempolicy 276
+# endif
+# ifndef __NR_mq_open
+# define __NR_mq_open 277
+# endif
+# ifndef __NR_mq_unlink
+# define __NR_mq_unlink 278
+# endif
+# ifndef __NR_mq_timedsend
+# define __NR_mq_timedsend 279
+# endif
+# ifndef __NR_mq_timedreceive
+# define __NR_mq_timedreceive 280
+# endif
+# ifndef __NR_mq_notify
+# define __NR_mq_notify 281
+# endif
+# ifndef __NR_mq_getsetattr
+# define __NR_mq_getsetattr 282
+# endif
+# ifndef __NR_kexec_load
+# define __NR_kexec_load 283
+# endif
+# ifndef __NR_waitid
+# define __NR_waitid 284
+# endif
+# ifndef __NR_add_key
+# define __NR_add_key 286
+# endif
+# ifndef __NR_request_key
+# define __NR_request_key 287
+# endif
+# ifndef __NR_keyctl
+# define __NR_keyctl 288
+# endif
+# ifndef __NR_ioprio_set
+# define __NR_ioprio_set 289
+# endif
+# ifndef __NR_ioprio_get
+# define __NR_ioprio_get 290
+# endif
+# ifndef __NR_inotify_init
+# define __NR_inotify_init 291
+# endif
+# ifndef __NR_inotify_add_watch
+# define __NR_inotify_add_watch 292
+# endif
+# ifndef __NR_inotify_rm_watch
+# define __NR_inotify_rm_watch 293
+# endif
+# ifndef __NR_migrate_pages
+# define __NR_migrate_pages 294
+# endif
+# ifndef __NR_openat
+# define __NR_openat 295
+# endif
+# ifndef __NR_mkdirat
+# define __NR_mkdirat 296
+# endif
+# ifndef __NR_mknodat
+# define __NR_mknodat 297
+# endif
+# ifndef __NR_fchownat
+# define __NR_fchownat 298
+# endif
+# ifndef __NR_futimesat
+# define __NR_futimesat 299
+# endif
+# ifndef __NR_fstatat64
+# define __NR_fstatat64 300
+# endif
+# ifndef __NR_unlinkat
+# define __NR_unlinkat 301
+# endif
+# ifndef __NR_renameat
+# define __NR_renameat 302
+# endif
+# ifndef __NR_linkat
+# define __NR_linkat 303
+# endif
+# ifndef __NR_symlinkat
+# define __NR_symlinkat 304
+# endif
+# ifndef __NR_readlinkat
+# define __NR_readlinkat 305
+# endif
+# ifndef __NR_fchmodat
+# define __NR_fchmodat 306
+# endif
+# ifndef __NR_faccessat
+# define __NR_faccessat 307
+# endif
+# ifndef __NR_pselect6
+# define __NR_pselect6 308
+# endif
+# ifndef __NR_ppoll
+# define __NR_ppoll 309
+# endif
+# ifndef __NR_unshare
+# define __NR_unshare 310
+# endif
+# ifndef __NR_set_robust_list
+# define __NR_set_robust_list 311
+# endif
+# ifndef __NR_get_robust_list
+# define __NR_get_robust_list 312
+# endif
+# ifndef __NR_splice
+# define __NR_splice 313
+# endif
+# ifndef __NR_sync_file_range
+# define __NR_sync_file_range 314
+# endif
+# ifndef __NR_tee
+# define __NR_tee 315
+# endif
+# ifndef __NR_vmsplice
+# define __NR_vmsplice 316
+# endif
+# ifndef __NR_move_pages
+# define __NR_move_pages 317
+# endif
+# ifndef __NR_getcpu
+# define __NR_getcpu 318
+# endif
+# ifndef __NR_epoll_pwait
+# define __NR_epoll_pwait 319
+# endif
+# ifndef __NR_utimensat
+# define __NR_utimensat 320
+# endif
+# ifndef __NR_signalfd
+# define __NR_signalfd 321
+# endif
+# ifndef __NR_timerfd_create
+# define __NR_timerfd_create 322
+# endif
+# ifndef __NR_eventfd
+# define __NR_eventfd 323
+# endif
+# ifndef __NR_fallocate
+# define __NR_fallocate 324
+# endif
+# ifndef __NR_timerfd_settime
+# define __NR_timerfd_settime 325
+# endif
+# ifndef __NR_timerfd_gettime
+# define __NR_timerfd_gettime 326
+# endif
+# ifndef __NR_signalfd4
+# define __NR_signalfd4 327
+# endif
+# ifndef __NR_eventfd2
+# define __NR_eventfd2 328
+# endif
+# ifndef __NR_epoll_create1
+# define __NR_epoll_create1 329
+# endif
+# ifndef __NR_dup3
+# define __NR_dup3 330
+# endif
+# ifndef __NR_pipe2
+# define __NR_pipe2 331
+# endif
+# ifndef __NR_inotify_init1
+# define __NR_inotify_init1 332
+# endif
+# ifndef __NR_preadv
+# define __NR_preadv 333
+# endif
+# ifndef __NR_pwritev
+# define __NR_pwritev 334
+# endif
+# ifndef __NR_rt_tgsigqueueinfo
+# define __NR_rt_tgsigqueueinfo 335
+# endif
+# ifndef __NR_perf_event_open
+# define __NR_perf_event_open 336
+# endif
+# ifndef __NR_recvmmsg
+# define __NR_recvmmsg 337
+# endif
+# ifndef __NR_fanotify_init
+# define __NR_fanotify_init 338
+# endif
+# ifndef __NR_fanotify_mark
+# define __NR_fanotify_mark 339
+# endif
+# ifndef __NR_prlimit64
+# define __NR_prlimit64 340
+# endif
+# ifndef __NR_name_to_handle_at
+# define __NR_name_to_handle_at 341
+# endif
+# ifndef __NR_open_by_handle_at
+# define __NR_open_by_handle_at 342
+# endif
+# ifndef __NR_clock_adjtime
+# define __NR_clock_adjtime 343
+# endif
+# ifndef __NR_syncfs
+# define __NR_syncfs 344
+# endif
+# ifndef __NR_sendmmsg
+# define __NR_sendmmsg 345
+# endif
+# ifndef __NR_setns
+# define __NR_setns 346
+# endif
+# ifndef __NR_process_vm_readv
+# define __NR_process_vm_readv 347
+# endif
+# ifndef __NR_process_vm_writev
+# define __NR_process_vm_writev 348
+# endif
+# ifndef __NR_kcmp
+# define __NR_kcmp 349
+# endif
+# ifndef __NR_finit_module
+# define __NR_finit_module 350
+# endif
+# ifndef __NR_sched_setattr
+# define __NR_sched_setattr 351
+# endif
+# ifndef __NR_sched_getattr
+# define __NR_sched_getattr 352
+# endif
+# ifndef __NR_renameat2
+# define __NR_renameat2 353
+# endif
+# ifndef __NR_seccomp
+# define __NR_seccomp 354
+# endif
+# ifndef __NR_getrandom
+# define __NR_getrandom 355
+# endif
+# ifndef __NR_memfd_create
+# define __NR_memfd_create 356
+# endif
+# ifndef __NR_bpf
+# define __NR_bpf 357
+# endif
+# ifndef __NR_execveat
+# define __NR_execveat 358
+# endif
+# ifndef __NR_socket
+# define __NR_socket 359
+# endif
+# ifndef __NR_socketpair
+# define __NR_socketpair 360
+# endif
+# ifndef __NR_bind
+# define __NR_bind 361
+# endif
+# ifndef __NR_connect
+# define __NR_connect 362
+# endif
+# ifndef __NR_listen
+# define __NR_listen 363
+# endif
+# ifndef __NR_accept4
+# define __NR_accept4 364
+# endif
+# ifndef __NR_getsockopt
+# define __NR_getsockopt 365
+# endif
+# ifndef __NR_setsockopt
+# define __NR_setsockopt 366
+# endif
+# ifndef __NR_getsockname
+# define __NR_getsockname 367
+# endif
+# ifndef __NR_getpeername
+# define __NR_getpeername 368
+# endif
+# ifndef __NR_sendto
+# define __NR_sendto 369
+# endif
+# ifndef __NR_sendmsg
+# define __NR_sendmsg 370
+# endif
+# ifndef __NR_recvfrom
+# define __NR_recvfrom 371
+# endif
+# ifndef __NR_recvmsg
+# define __NR_recvmsg 372
+# endif
+# ifndef __NR_shutdown
+# define __NR_shutdown 373
+# endif
+# ifndef __NR_userfaultfd
+# define __NR_userfaultfd 374
+# endif
+# ifndef __NR_membarrier
+# define __NR_membarrier 375
+# endif
+# ifndef __NR_mlock2
+# define __NR_mlock2 376
+# endif
+# ifndef __NR_copy_file_range
+# define __NR_copy_file_range 377
+# endif
+# ifndef __NR_preadv2
+# define __NR_preadv2 378
+# endif
+# ifndef __NR_pwritev2
+# define __NR_pwritev2 379
+# endif
+# ifndef __NR_pkey_mprotect
+# define __NR_pkey_mprotect 380
+# endif
+# ifndef __NR_pkey_alloc
+# define __NR_pkey_alloc 381
+# endif
+# ifndef __NR_pkey_free
+# define __NR_pkey_free 382
+# endif
+# ifndef __NR_statx
+# define __NR_statx 383
+# endif
+# ifndef __NR_arch_prctl
+# define __NR_arch_prctl 384
+# endif
+# ifndef __NR_io_pgetevents
+# define __NR_io_pgetevents 385
+# endif
+# ifndef __NR_rseq
+# define __NR_rseq 386
+# endif
+# ifndef __NR_semget
+# define __NR_semget 393
+# endif
+# ifndef __NR_semctl
+# define __NR_semctl 394
+# endif
+# ifndef __NR_shmget
+# define __NR_shmget 395
+# endif
+# ifndef __NR_shmctl
+# define __NR_shmctl 396
+# endif
+# ifndef __NR_shmat
+# define __NR_shmat 397
+# endif
+# ifndef __NR_shmdt
+# define __NR_shmdt 398
+# endif
+# ifndef __NR_msgget
+# define __NR_msgget 399
+# endif
+# ifndef __NR_msgsnd
+# define __NR_msgsnd 400
+# endif
+# ifndef __NR_msgrcv
+# define __NR_msgrcv 401
+# endif
+# ifndef __NR_msgctl
+# define __NR_msgctl 402
+# endif
+# ifndef __NR_clock_gettime64
+# define __NR_clock_gettime64 403
+# endif
+# ifndef __NR_clock_settime64
+# define __NR_clock_settime64 404
+# endif
+# ifndef __NR_clock_adjtime64
+# define __NR_clock_adjtime64 405
+# endif
+# ifndef __NR_clock_getres_time64
+# define __NR_clock_getres_time64 406
+# endif
+# ifndef __NR_clock_nanosleep_time64
+# define __NR_clock_nanosleep_time64 407
+# endif
+# ifndef __NR_timer_gettime64
+# define __NR_timer_gettime64 408
+# endif
+# ifndef __NR_timer_settime64
+# define __NR_timer_settime64 409
+# endif
+# ifndef __NR_timerfd_gettime64
+# define __NR_timerfd_gettime64 410
+# endif
+# ifndef __NR_timerfd_settime64
+# define __NR_timerfd_settime64 411
+# endif
+# ifndef __NR_utimensat_time64
+# define __NR_utimensat_time64 412
+# endif
+# ifndef __NR_pselect6_time64
+# define __NR_pselect6_time64 413
+# endif
+# ifndef __NR_ppoll_time64
+# define __NR_ppoll_time64 414
+# endif
+# ifndef __NR_io_pgetevents_time64
+# define __NR_io_pgetevents_time64 416
+# endif
+# ifndef __NR_recvmmsg_time64
+# define __NR_recvmmsg_time64 417
+# endif
+# ifndef __NR_mq_timedsend_time64
+# define __NR_mq_timedsend_time64 418
+# endif
+# ifndef __NR_mq_timedreceive_time64
+# define __NR_mq_timedreceive_time64 419
+# endif
+# ifndef __NR_semtimedop_time64
+# define __NR_semtimedop_time64 420
+# endif
+# ifndef __NR_rt_sigtimedwait_time64
+# define __NR_rt_sigtimedwait_time64 421
+# endif
+# ifndef __NR_futex_time64
+# define __NR_futex_time64 422
+# endif
+# ifndef __NR_sched_rr_get_interval_time64
+# define __NR_sched_rr_get_interval_time64 423
+# endif
+# ifndef __NR_pidfd_send_signal
+# define __NR_pidfd_send_signal 424
+# endif
+# ifndef __NR_io_uring_setup
+# define __NR_io_uring_setup 425
+# endif
+# ifndef __NR_io_uring_enter
+# define __NR_io_uring_enter 426
+# endif
+# ifndef __NR_io_uring_register
+# define __NR_io_uring_register 427
+# endif
+# ifndef __NR_open_tree
+# define __NR_open_tree 428
+# endif
+# ifndef __NR_move_mount
+# define __NR_move_mount 429
+# endif
+# ifndef __NR_fsopen
+# define __NR_fsopen 430
+# endif
+# ifndef __NR_fsconfig
+# define __NR_fsconfig 431
+# endif
+# ifndef __NR_fsmount
+# define __NR_fsmount 432
+# endif
+# ifndef __NR_fspick
+# define __NR_fspick 433
+# endif
+# ifndef __NR_pidfd_open
+# define __NR_pidfd_open 434
+# endif
+# ifndef __NR_clone3
+# define __NR_clone3 435
+# endif
+# ifndef __NR_openat2
+# define __NR_openat2 437
+# endif
+# ifndef __NR_pidfd_getfd
+# define __NR_pidfd_getfd 438
+# endif
+#endif
+
+
+#ifdef __ia64__
+# ifndef __NR_ni_syscall
+# define __NR_ni_syscall 1024
+# endif
+# ifndef __NR_exit
+# define __NR_exit 1025
+# endif
+# ifndef __NR_read
+# define __NR_read 1026
+# endif
+# ifndef __NR_write
+# define __NR_write 1027
+# endif
+# ifndef __NR_open
+# define __NR_open 1028
+# endif
+# ifndef __NR_close
+# define __NR_close 1029
+# endif
+# ifndef __NR_creat
+# define __NR_creat 1030
+# endif
+# ifndef __NR_link
+# define __NR_link 1031
+# endif
+# ifndef __NR_unlink
+# define __NR_unlink 1032
+# endif
+# ifndef __NR_execve
+# define __NR_execve 1033
+# endif
+# ifndef __NR_chdir
+# define __NR_chdir 1034
+# endif
+# ifndef __NR_fchdir
+# define __NR_fchdir 1035
+# endif
+# ifndef __NR_utimes
+# define __NR_utimes 1036
+# endif
+# ifndef __NR_mknod
+# define __NR_mknod 1037
+# endif
+# ifndef __NR_chmod
+# define __NR_chmod 1038
+# endif
+# ifndef __NR_chown
+# define __NR_chown 1039
+# endif
+# ifndef __NR_lseek
+# define __NR_lseek 1040
+# endif
+# ifndef __NR_getpid
+# define __NR_getpid 1041
+# endif
+# ifndef __NR_getppid
+# define __NR_getppid 1042
+# endif
+# ifndef __NR_mount
+# define __NR_mount 1043
+# endif
+# ifndef __NR_umount2
+# define __NR_umount2 1044
+# endif
+# ifndef __NR_setuid
+# define __NR_setuid 1045
+# endif
+# ifndef __NR_getuid
+# define __NR_getuid 1046
+# endif
+# ifndef __NR_geteuid
+# define __NR_geteuid 1047
+# endif
+# ifndef __NR_ptrace
+# define __NR_ptrace 1048
+# endif
+# ifndef __NR_access
+# define __NR_access 1049
+# endif
+# ifndef __NR_sync
+# define __NR_sync 1050
+# endif
+# ifndef __NR_fsync
+# define __NR_fsync 1051
+# endif
+# ifndef __NR_fdatasync
+# define __NR_fdatasync 1052
+# endif
+# ifndef __NR_kill
+# define __NR_kill 1053
+# endif
+# ifndef __NR_rename
+# define __NR_rename 1054
+# endif
+# ifndef __NR_mkdir
+# define __NR_mkdir 1055
+# endif
+# ifndef __NR_rmdir
+# define __NR_rmdir 1056
+# endif
+# ifndef __NR_dup
+# define __NR_dup 1057
+# endif
+# ifndef __NR_pipe
+# define __NR_pipe 1058
+# endif
+# ifndef __NR_times
+# define __NR_times 1059
+# endif
+# ifndef __NR_brk
+# define __NR_brk 1060
+# endif
+# ifndef __NR_setgid
+# define __NR_setgid 1061
+# endif
+# ifndef __NR_getgid
+# define __NR_getgid 1062
+# endif
+# ifndef __NR_getegid
+# define __NR_getegid 1063
+# endif
+# ifndef __NR_acct
+# define __NR_acct 1064
+# endif
+# ifndef __NR_ioctl
+# define __NR_ioctl 1065
+# endif
+# ifndef __NR_fcntl
+# define __NR_fcntl 1066
+# endif
+# ifndef __NR_umask
+# define __NR_umask 1067
+# endif
+# ifndef __NR_chroot
+# define __NR_chroot 1068
+# endif
+# ifndef __NR_ustat
+# define __NR_ustat 1069
+# endif
+# ifndef __NR_dup2
+# define __NR_dup2 1070
+# endif
+# ifndef __NR_setreuid
+# define __NR_setreuid 1071
+# endif
+# ifndef __NR_setregid
+# define __NR_setregid 1072
+# endif
+# ifndef __NR_getresuid
+# define __NR_getresuid 1073
+# endif
+# ifndef __NR_setresuid
+# define __NR_setresuid 1074
+# endif
+# ifndef __NR_getresgid
+# define __NR_getresgid 1075
+# endif
+# ifndef __NR_setresgid
+# define __NR_setresgid 1076
+# endif
+# ifndef __NR_getgroups
+# define __NR_getgroups 1077
+# endif
+# ifndef __NR_setgroups
+# define __NR_setgroups 1078
+# endif
+# ifndef __NR_getpgid
+# define __NR_getpgid 1079
+# endif
+# ifndef __NR_setpgid
+# define __NR_setpgid 1080
+# endif
+# ifndef __NR_setsid
+# define __NR_setsid 1081
+# endif
+# ifndef __NR_getsid
+# define __NR_getsid 1082
+# endif
+# ifndef __NR_sethostname
+# define __NR_sethostname 1083
+# endif
+# ifndef __NR_setrlimit
+# define __NR_setrlimit 1084
+# endif
+# ifndef __NR_getrlimit
+# define __NR_getrlimit 1085
+# endif
+# ifndef __NR_getrusage
+# define __NR_getrusage 1086
+# endif
+# ifndef __NR_gettimeofday
+# define __NR_gettimeofday 1087
+# endif
+# ifndef __NR_settimeofday
+# define __NR_settimeofday 1088
+# endif
+# ifndef __NR_select
+# define __NR_select 1089
+# endif
+# ifndef __NR_poll
+# define __NR_poll 1090
+# endif
+# ifndef __NR_symlink
+# define __NR_symlink 1091
+# endif
+# ifndef __NR_readlink
+# define __NR_readlink 1092
+# endif
+# ifndef __NR_uselib
+# define __NR_uselib 1093
+# endif
+# ifndef __NR_swapon
+# define __NR_swapon 1094
+# endif
+# ifndef __NR_swapoff
+# define __NR_swapoff 1095
+# endif
+# ifndef __NR_reboot
+# define __NR_reboot 1096
+# endif
+# ifndef __NR_truncate
+# define __NR_truncate 1097
+# endif
+# ifndef __NR_ftruncate
+# define __NR_ftruncate 1098
+# endif
+# ifndef __NR_fchmod
+# define __NR_fchmod 1099
+# endif
+# ifndef __NR_fchown
+# define __NR_fchown 1100
+# endif
+# ifndef __NR_getpriority
+# define __NR_getpriority 1101
+# endif
+# ifndef __NR_setpriority
+# define __NR_setpriority 1102
+# endif
+# ifndef __NR_statfs
+# define __NR_statfs 1103
+# endif
+# ifndef __NR_fstatfs
+# define __NR_fstatfs 1104
+# endif
+# ifndef __NR_gettid
+# define __NR_gettid 1105
+# endif
+# ifndef __NR_semget
+# define __NR_semget 1106
+# endif
+# ifndef __NR_semop
+# define __NR_semop 1107
+# endif
+# ifndef __NR_semctl
+# define __NR_semctl 1108
+# endif
+# ifndef __NR_msgget
+# define __NR_msgget 1109
+# endif
+# ifndef __NR_msgsnd
+# define __NR_msgsnd 1110
+# endif
+# ifndef __NR_msgrcv
+# define __NR_msgrcv 1111
+# endif
+# ifndef __NR_msgctl
+# define __NR_msgctl 1112
+# endif
+# ifndef __NR_shmget
+# define __NR_shmget 1113
+# endif
+# ifndef __NR_shmat
+# define __NR_shmat 1114
+# endif
+# ifndef __NR_shmdt
+# define __NR_shmdt 1115
+# endif
+# ifndef __NR_shmctl
+# define __NR_shmctl 1116
+# endif
+# ifndef __NR_syslog
+# define __NR_syslog 1117
+# endif
+# ifndef __NR_setitimer
+# define __NR_setitimer 1118
+# endif
+# ifndef __NR_getitimer
+# define __NR_getitimer 1119
+# endif
+# ifndef __NR_vhangup
+# define __NR_vhangup 1123
+# endif
+# ifndef __NR_lchown
+# define __NR_lchown 1124
+# endif
+# ifndef __NR_remap_file_pages
+# define __NR_remap_file_pages 1125
+# endif
+# ifndef __NR_wait4
+# define __NR_wait4 1126
+# endif
+# ifndef __NR_sysinfo
+# define __NR_sysinfo 1127
+# endif
+# ifndef __NR_clone
+# define __NR_clone 1128
+# endif
+# ifndef __NR_setdomainname
+# define __NR_setdomainname 1129
+# endif
+# ifndef __NR_uname
+# define __NR_uname 1130
+# endif
+# ifndef __NR_adjtimex
+# define __NR_adjtimex 1131
+# endif
+# ifndef __NR_init_module
+# define __NR_init_module 1133
+# endif
+# ifndef __NR_delete_module
+# define __NR_delete_module 1134
+# endif
+# ifndef __NR_quotactl
+# define __NR_quotactl 1137
+# endif
+# ifndef __NR_bdflush
+# define __NR_bdflush 1138
+# endif
+# ifndef __NR_sysfs
+# define __NR_sysfs 1139
+# endif
+# ifndef __NR_personality
+# define __NR_personality 1140
+# endif
+# ifndef __NR_afs_syscall
+# define __NR_afs_syscall 1141
+# endif
+# ifndef __NR_setfsuid
+# define __NR_setfsuid 1142
+# endif
+# ifndef __NR_setfsgid
+# define __NR_setfsgid 1143
+# endif
+# ifndef __NR_getdents
+# define __NR_getdents 1144
+# endif
+# ifndef __NR_flock
+# define __NR_flock 1145
+# endif
+# ifndef __NR_readv
+# define __NR_readv 1146
+# endif
+# ifndef __NR_writev
+# define __NR_writev 1147
+# endif
+# ifndef __NR_pread64
+# define __NR_pread64 1148
+# endif
+# ifndef __NR_pwrite64
+# define __NR_pwrite64 1149
+# endif
+# ifndef __NR__sysctl
+# define __NR__sysctl 1150
+# endif
+# ifndef __NR_mmap
+# define __NR_mmap 1151
+# endif
+# ifndef __NR_munmap
+# define __NR_munmap 1152
+# endif
+# ifndef __NR_mlock
+# define __NR_mlock 1153
+# endif
+# ifndef __NR_mlockall
+# define __NR_mlockall 1154
+# endif
+# ifndef __NR_mprotect
+# define __NR_mprotect 1155
+# endif
+# ifndef __NR_mremap
+# define __NR_mremap 1156
+# endif
+# ifndef __NR_msync
+# define __NR_msync 1157
+# endif
+# ifndef __NR_munlock
+# define __NR_munlock 1158
+# endif
+# ifndef __NR_munlockall
+# define __NR_munlockall 1159
+# endif
+# ifndef __NR_sched_getparam
+# define __NR_sched_getparam 1160
+# endif
+# ifndef __NR_sched_setparam
+# define __NR_sched_setparam 1161
+# endif
+# ifndef __NR_sched_getscheduler
+# define __NR_sched_getscheduler 1162
+# endif
+# ifndef __NR_sched_setscheduler
+# define __NR_sched_setscheduler 1163
+# endif
+# ifndef __NR_sched_yield
+# define __NR_sched_yield 1164
+# endif
+# ifndef __NR_sched_get_priority_max
+# define __NR_sched_get_priority_max 1165
+# endif
+# ifndef __NR_sched_get_priority_min
+# define __NR_sched_get_priority_min 1166
+# endif
+# ifndef __NR_sched_rr_get_interval
+# define __NR_sched_rr_get_interval 1167
+# endif
+# ifndef __NR_nanosleep
+# define __NR_nanosleep 1168
+# endif
+# ifndef __NR_nfsservctl
+# define __NR_nfsservctl 1169
+# endif
+# ifndef __NR_prctl
+# define __NR_prctl 1170
+# endif
+# ifndef __NR_old_getpagesize
+# define __NR_old_getpagesize 1171
+# endif
+# ifndef __NR_mmap2
+# define __NR_mmap2 1172
+# endif
+# ifndef __NR_pciconfig_read
+# define __NR_pciconfig_read 1173
+# endif
+# ifndef __NR_pciconfig_write
+# define __NR_pciconfig_write 1174
+# endif
+# ifndef __NR_perfmonctl
+# define __NR_perfmonctl 1175
+# endif
+# ifndef __NR_sigaltstack
+# define __NR_sigaltstack 1176
+# endif
+# ifndef __NR_rt_sigaction
+# define __NR_rt_sigaction 1177
+# endif
+# ifndef __NR_rt_sigpending
+# define __NR_rt_sigpending 1178
+# endif
+# ifndef __NR_rt_sigprocmask
+# define __NR_rt_sigprocmask 1179
+# endif
+# ifndef __NR_rt_sigqueueinfo
+# define __NR_rt_sigqueueinfo 1180
+# endif
+# ifndef __NR_rt_sigreturn
+# define __NR_rt_sigreturn 1181
+# endif
+# ifndef __NR_rt_sigsuspend
+# define __NR_rt_sigsuspend 1182
+# endif
+# ifndef __NR_rt_sigtimedwait
+# define __NR_rt_sigtimedwait 1183
+# endif
+# ifndef __NR_getcwd
+# define __NR_getcwd 1184
+# endif
+# ifndef __NR_capget
+# define __NR_capget 1185
+# endif
+# ifndef __NR_capset
+# define __NR_capset 1186
+# endif
+# ifndef __NR_sendfile
+# define __NR_sendfile 1187
+# endif
+# ifndef __NR_getpmsg
+# define __NR_getpmsg 1188
+# endif
+# ifndef __NR_putpmsg
+# define __NR_putpmsg 1189
+# endif
+# ifndef __NR_socket
+# define __NR_socket 1190
+# endif
+# ifndef __NR_bind
+# define __NR_bind 1191
+# endif
+# ifndef __NR_connect
+# define __NR_connect 1192
+# endif
+# ifndef __NR_listen
+# define __NR_listen 1193
+# endif
+# ifndef __NR_accept
+# define __NR_accept 1194
+# endif
+# ifndef __NR_getsockname
+# define __NR_getsockname 1195
+# endif
+# ifndef __NR_getpeername
+# define __NR_getpeername 1196
+# endif
+# ifndef __NR_socketpair
+# define __NR_socketpair 1197
+# endif
+# ifndef __NR_send
+# define __NR_send 1198
+# endif
+# ifndef __NR_sendto
+# define __NR_sendto 1199
+# endif
+# ifndef __NR_recv
+# define __NR_recv 1200
+# endif
+# ifndef __NR_recvfrom
+# define __NR_recvfrom 1201
+# endif
+# ifndef __NR_shutdown
+# define __NR_shutdown 1202
+# endif
+# ifndef __NR_setsockopt
+# define __NR_setsockopt 1203
+# endif
+# ifndef __NR_getsockopt
+# define __NR_getsockopt 1204
+# endif
+# ifndef __NR_sendmsg
+# define __NR_sendmsg 1205
+# endif
+# ifndef __NR_recvmsg
+# define __NR_recvmsg 1206
+# endif
+# ifndef __NR_pivot_root
+# define __NR_pivot_root 1207
+# endif
+# ifndef __NR_mincore
+# define __NR_mincore 1208
+# endif
+# ifndef __NR_madvise
+# define __NR_madvise 1209
+# endif
+# ifndef __NR_stat
+# define __NR_stat 1210
+# endif
+# ifndef __NR_lstat
+# define __NR_lstat 1211
+# endif
+# ifndef __NR_fstat
+# define __NR_fstat 1212
+# endif
+# ifndef __NR_clone2
+# define __NR_clone2 1213
+# endif
+# ifndef __NR_getdents64
+# define __NR_getdents64 1214
+# endif
+# ifndef __NR_getunwind
+# define __NR_getunwind 1215
+# endif
+# ifndef __NR_readahead
+# define __NR_readahead 1216
+# endif
+# ifndef __NR_setxattr
+# define __NR_setxattr 1217
+# endif
+# ifndef __NR_lsetxattr
+# define __NR_lsetxattr 1218
+# endif
+# ifndef __NR_fsetxattr
+# define __NR_fsetxattr 1219
+# endif
+# ifndef __NR_getxattr
+# define __NR_getxattr 1220
+# endif
+# ifndef __NR_lgetxattr
+# define __NR_lgetxattr 1221
+# endif
+# ifndef __NR_fgetxattr
+# define __NR_fgetxattr 1222
+# endif
+# ifndef __NR_listxattr
+# define __NR_listxattr 1223
+# endif
+# ifndef __NR_llistxattr
+# define __NR_llistxattr 1224
+# endif
+# ifndef __NR_flistxattr
+# define __NR_flistxattr 1225
+# endif
+# ifndef __NR_removexattr
+# define __NR_removexattr 1226
+# endif
+# ifndef __NR_lremovexattr
+# define __NR_lremovexattr 1227
+# endif
+# ifndef __NR_fremovexattr
+# define __NR_fremovexattr 1228
+# endif
+# ifndef __NR_tkill
+# define __NR_tkill 1229
+# endif
+# ifndef __NR_futex
+# define __NR_futex 1230
+# endif
+# ifndef __NR_sched_setaffinity
+# define __NR_sched_setaffinity 1231
+# endif
+# ifndef __NR_sched_getaffinity
+# define __NR_sched_getaffinity 1232
+# endif
+# ifndef __NR_set_tid_address
+# define __NR_set_tid_address 1233
+# endif
+# ifndef __NR_fadvise64
+# define __NR_fadvise64 1234
+# endif
+# ifndef __NR_tgkill
+# define __NR_tgkill 1235
+# endif
+# ifndef __NR_exit_group
+# define __NR_exit_group 1236
+# endif
+# ifndef __NR_lookup_dcookie
+# define __NR_lookup_dcookie 1237
+# endif
+# ifndef __NR_io_setup
+# define __NR_io_setup 1238
+# endif
+# ifndef __NR_io_destroy
+# define __NR_io_destroy 1239
+# endif
+# ifndef __NR_io_getevents
+# define __NR_io_getevents 1240
+# endif
+# ifndef __NR_io_submit
+# define __NR_io_submit 1241
+# endif
+# ifndef __NR_io_cancel
+# define __NR_io_cancel 1242
+# endif
+# ifndef __NR_epoll_create
+# define __NR_epoll_create 1243
+# endif
+# ifndef __NR_epoll_ctl
+# define __NR_epoll_ctl 1244
+# endif
+# ifndef __NR_epoll_wait
+# define __NR_epoll_wait 1245
+# endif
+# ifndef __NR_restart_syscall
+# define __NR_restart_syscall 1246
+# endif
+# ifndef __NR_semtimedop
+# define __NR_semtimedop 1247
+# endif
+# ifndef __NR_timer_create
+# define __NR_timer_create 1248
+# endif
+# ifndef __NR_timer_settime
+# define __NR_timer_settime 1249
+# endif
+# ifndef __NR_timer_gettime
+# define __NR_timer_gettime 1250
+# endif
+# ifndef __NR_timer_getoverrun
+# define __NR_timer_getoverrun 1251
+# endif
+# ifndef __NR_timer_delete
+# define __NR_timer_delete 1252
+# endif
+# ifndef __NR_clock_settime
+# define __NR_clock_settime 1253
+# endif
+# ifndef __NR_clock_gettime
+# define __NR_clock_gettime 1254
+# endif
+# ifndef __NR_clock_getres
+# define __NR_clock_getres 1255
+# endif
+# ifndef __NR_clock_nanosleep
+# define __NR_clock_nanosleep 1256
+# endif
+# ifndef __NR_fstatfs64
+# define __NR_fstatfs64 1257
+# endif
+# ifndef __NR_statfs64
+# define __NR_statfs64 1258
+# endif
+# ifndef __NR_mbind
+# define __NR_mbind 1259
+# endif
+# ifndef __NR_get_mempolicy
+# define __NR_get_mempolicy 1260
+# endif
+# ifndef __NR_set_mempolicy
+# define __NR_set_mempolicy 1261
+# endif
+# ifndef __NR_mq_open
+# define __NR_mq_open 1262
+# endif
+# ifndef __NR_mq_unlink
+# define __NR_mq_unlink 1263
+# endif
+# ifndef __NR_mq_timedsend
+# define __NR_mq_timedsend 1264
+# endif
+# ifndef __NR_mq_timedreceive
+# define __NR_mq_timedreceive 1265
+# endif
+# ifndef __NR_mq_notify
+# define __NR_mq_notify 1266
+# endif
+# ifndef __NR_mq_getsetattr
+# define __NR_mq_getsetattr 1267
+# endif
+# ifndef __NR_kexec_load
+# define __NR_kexec_load 1268
+# endif
+# ifndef __NR_vserver
+# define __NR_vserver 1269
+# endif
+# ifndef __NR_waitid
+# define __NR_waitid 1270
+# endif
+# ifndef __NR_add_key
+# define __NR_add_key 1271
+# endif
+# ifndef __NR_request_key
+# define __NR_request_key 1272
+# endif
+# ifndef __NR_keyctl
+# define __NR_keyctl 1273
+# endif
+# ifndef __NR_ioprio_set
+# define __NR_ioprio_set 1274
+# endif
+# ifndef __NR_ioprio_get
+# define __NR_ioprio_get 1275
+# endif
+# ifndef __NR_move_pages
+# define __NR_move_pages 1276
+# endif
+# ifndef __NR_inotify_init
+# define __NR_inotify_init 1277
+# endif
+# ifndef __NR_inotify_add_watch
+# define __NR_inotify_add_watch 1278
+# endif
+# ifndef __NR_inotify_rm_watch
+# define __NR_inotify_rm_watch 1279
+# endif
+# ifndef __NR_migrate_pages
+# define __NR_migrate_pages 1280
+# endif
+# ifndef __NR_openat
+# define __NR_openat 1281
+# endif
+# ifndef __NR_mkdirat
+# define __NR_mkdirat 1282
+# endif
+# ifndef __NR_mknodat
+# define __NR_mknodat 1283
+# endif
+# ifndef __NR_fchownat
+# define __NR_fchownat 1284
+# endif
+# ifndef __NR_futimesat
+# define __NR_futimesat 1285
+# endif
+# ifndef __NR_newfstatat
+# define __NR_newfstatat 1286
+# endif
+# ifndef __NR_unlinkat
+# define __NR_unlinkat 1287
+# endif
+# ifndef __NR_renameat
+# define __NR_renameat 1288
+# endif
+# ifndef __NR_linkat
+# define __NR_linkat 1289
+# endif
+# ifndef __NR_symlinkat
+# define __NR_symlinkat 1290
+# endif
+# ifndef __NR_readlinkat
+# define __NR_readlinkat 1291
+# endif
+# ifndef __NR_fchmodat
+# define __NR_fchmodat 1292
+# endif
+# ifndef __NR_faccessat
+# define __NR_faccessat 1293
+# endif
+# ifndef __NR_pselect6
+# define __NR_pselect6 1294
+# endif
+# ifndef __NR_ppoll
+# define __NR_ppoll 1295
+# endif
+# ifndef __NR_unshare
+# define __NR_unshare 1296
+# endif
+# ifndef __NR_splice
+# define __NR_splice 1297
+# endif
+# ifndef __NR_set_robust_list
+# define __NR_set_robust_list 1298
+# endif
+# ifndef __NR_get_robust_list
+# define __NR_get_robust_list 1299
+# endif
+# ifndef __NR_sync_file_range
+# define __NR_sync_file_range 1300
+# endif
+# ifndef __NR_tee
+# define __NR_tee 1301
+# endif
+# ifndef __NR_vmsplice
+# define __NR_vmsplice 1302
+# endif
+# ifndef __NR_fallocate
+# define __NR_fallocate 1303
+# endif
+# ifndef __NR_getcpu
+# define __NR_getcpu 1304
+# endif
+# ifndef __NR_epoll_pwait
+# define __NR_epoll_pwait 1305
+# endif
+# ifndef __NR_utimensat
+# define __NR_utimensat 1306
+# endif
+# ifndef __NR_signalfd
+# define __NR_signalfd 1307
+# endif
+# ifndef __NR_timerfd
+# define __NR_timerfd 1308
+# endif
+# ifndef __NR_eventfd
+# define __NR_eventfd 1309
+# endif
+# ifndef __NR_timerfd_create
+# define __NR_timerfd_create 1310
+# endif
+# ifndef __NR_timerfd_settime
+# define __NR_timerfd_settime 1311
+# endif
+# ifndef __NR_timerfd_gettime
+# define __NR_timerfd_gettime 1312
+# endif
+# ifndef __NR_signalfd4
+# define __NR_signalfd4 1313
+# endif
+# ifndef __NR_eventfd2
+# define __NR_eventfd2 1314
+# endif
+# ifndef __NR_epoll_create1
+# define __NR_epoll_create1 1315
+# endif
+# ifndef __NR_dup3
+# define __NR_dup3 1316
+# endif
+# ifndef __NR_pipe2
+# define __NR_pipe2 1317
+# endif
+# ifndef __NR_inotify_init1
+# define __NR_inotify_init1 1318
+# endif
+# ifndef __NR_preadv
+# define __NR_preadv 1319
+# endif
+# ifndef __NR_pwritev
+# define __NR_pwritev 1320
+# endif
+# ifndef __NR_rt_tgsigqueueinfo
+# define __NR_rt_tgsigqueueinfo 1321
+# endif
+# ifndef __NR_recvmmsg
+# define __NR_recvmmsg 1322
+# endif
+# ifndef __NR_fanotify_init
+# define __NR_fanotify_init 1323
+# endif
+# ifndef __NR_fanotify_mark
+# define __NR_fanotify_mark 1324
+# endif
+# ifndef __NR_prlimit64
+# define __NR_prlimit64 1325
+# endif
+# ifndef __NR_name_to_handle_at
+# define __NR_name_to_handle_at 1326
+# endif
+# ifndef __NR_open_by_handle_at
+# define __NR_open_by_handle_at 1327
+# endif
+# ifndef __NR_clock_adjtime
+# define __NR_clock_adjtime 1328
+# endif
+# ifndef __NR_syncfs
+# define __NR_syncfs 1329
+# endif
+# ifndef __NR_setns
+# define __NR_setns 1330
+# endif
+# ifndef __NR_sendmmsg
+# define __NR_sendmmsg 1331
+# endif
+# ifndef __NR_process_vm_readv
+# define __NR_process_vm_readv 1332
+# endif
+# ifndef __NR_process_vm_writev
+# define __NR_process_vm_writev 1333
+# endif
+# ifndef __NR_accept4
+# define __NR_accept4 1334
+# endif
+# ifndef __NR_finit_module
+# define __NR_finit_module 1335
+# endif
+# ifndef __NR_sched_setattr
+# define __NR_sched_setattr 1336
+# endif
+# ifndef __NR_sched_getattr
+# define __NR_sched_getattr 1337
+# endif
+# ifndef __NR_renameat2
+# define __NR_renameat2 1338
+# endif
+# ifndef __NR_getrandom
+# define __NR_getrandom 1339
+# endif
+# ifndef __NR_memfd_create
+# define __NR_memfd_create 1340
+# endif
+# ifndef __NR_bpf
+# define __NR_bpf 1341
+# endif
+# ifndef __NR_execveat
+# define __NR_execveat 1342
+# endif
+# ifndef __NR_userfaultfd
+# define __NR_userfaultfd 1343
+# endif
+# ifndef __NR_membarrier
+# define __NR_membarrier 1344
+# endif
+# ifndef __NR_kcmp
+# define __NR_kcmp 1345
+# endif
+# ifndef __NR_mlock2
+# define __NR_mlock2 1346
+# endif
+# ifndef __NR_copy_file_range
+# define __NR_copy_file_range 1347
+# endif
+# ifndef __NR_preadv2
+# define __NR_preadv2 1348
+# endif
+# ifndef __NR_pwritev2
+# define __NR_pwritev2 1349
+# endif
+# ifndef __NR_statx
+# define __NR_statx 1350
+# endif
+# ifndef __NR_io_pgetevents
+# define __NR_io_pgetevents 1351
+# endif
+# ifndef __NR_perf_event_open
+# define __NR_perf_event_open 1352
+# endif
+# ifndef __NR_seccomp
+# define __NR_seccomp 1353
+# endif
+# ifndef __NR_pkey_mprotect
+# define __NR_pkey_mprotect 1354
+# endif
+# ifndef __NR_pkey_alloc
+# define __NR_pkey_alloc 1355
+# endif
+# ifndef __NR_pkey_free
+# define __NR_pkey_free 1356
+# endif
+# ifndef __NR_rseq
+# define __NR_rseq 1357
+# endif
+# ifndef __NR_pidfd_send_signal
+# define __NR_pidfd_send_signal 1448
+# endif
+# ifndef __NR_io_uring_setup
+# define __NR_io_uring_setup 1449
+# endif
+# ifndef __NR_io_uring_enter
+# define __NR_io_uring_enter 1450
+# endif
+# ifndef __NR_io_uring_register
+# define __NR_io_uring_register 1451
+# endif
+# ifndef __NR_open_tree
+# define __NR_open_tree 1452
+# endif
+# ifndef __NR_move_mount
+# define __NR_move_mount 1453
+# endif
+# ifndef __NR_fsopen
+# define __NR_fsopen 1454
+# endif
+# ifndef __NR_fsconfig
+# define __NR_fsconfig 1455
+# endif
+# ifndef __NR_fsmount
+# define __NR_fsmount 1456
+# endif
+# ifndef __NR_fspick
+# define __NR_fspick 1457
+# endif
+# ifndef __NR_pidfd_open
+# define __NR_pidfd_open 1458
+# endif
+# ifndef __NR_openat2
+# define __NR_openat2 1461
+# endif
+# ifndef __NR_pidfd_getfd
+# define __NR_pidfd_getfd 1462
+# endif
+#endif
+
+
+#if defined(__mips__) && defined(_ABIN32)
+# ifndef __NR_read
+# define __NR_read 0
+# endif
+# ifndef __NR_write
+# define __NR_write 1
+# endif
+# ifndef __NR_open
+# define __NR_open 2
+# endif
+# ifndef __NR_close
+# define __NR_close 3
+# endif
+# ifndef __NR_stat
+# define __NR_stat 4
+# endif
+# ifndef __NR_fstat
+# define __NR_fstat 5
+# endif
+# ifndef __NR_lstat
+# define __NR_lstat 6
+# endif
+# ifndef __NR_poll
+# define __NR_poll 7
+# endif
+# ifndef __NR_lseek
+# define __NR_lseek 8
+# endif
+# ifndef __NR_mmap
+# define __NR_mmap 9
+# endif
+# ifndef __NR_mprotect
+# define __NR_mprotect 10
+# endif
+# ifndef __NR_munmap
+# define __NR_munmap 11
+# endif
+# ifndef __NR_brk
+# define __NR_brk 12
+# endif
+# ifndef __NR_rt_sigaction
+# define __NR_rt_sigaction 13
+# endif
+# ifndef __NR_rt_sigprocmask
+# define __NR_rt_sigprocmask 14
+# endif
+# ifndef __NR_ioctl
+# define __NR_ioctl 15
+# endif
+# ifndef __NR_pread64
+# define __NR_pread64 16
+# endif
+# ifndef __NR_pwrite64
+# define __NR_pwrite64 17
+# endif
+# ifndef __NR_readv
+# define __NR_readv 18
+# endif
+# ifndef __NR_writev
+# define __NR_writev 19
+# endif
+# ifndef __NR_access
+# define __NR_access 20
+# endif
+# ifndef __NR_pipe
+# define __NR_pipe 21
+# endif
+# ifndef __NR__newselect
+# define __NR__newselect 22
+# endif
+# ifndef __NR_sched_yield
+# define __NR_sched_yield 23
+# endif
+# ifndef __NR_mremap
+# define __NR_mremap 24
+# endif
+# ifndef __NR_msync
+# define __NR_msync 25
+# endif
+# ifndef __NR_mincore
+# define __NR_mincore 26
+# endif
+# ifndef __NR_madvise
+# define __NR_madvise 27
+# endif
+# ifndef __NR_shmget
+# define __NR_shmget 28
+# endif
+# ifndef __NR_shmat
+# define __NR_shmat 29
+# endif
+# ifndef __NR_shmctl
+# define __NR_shmctl 30
+# endif
+# ifndef __NR_dup
+# define __NR_dup 31
+# endif
+# ifndef __NR_dup2
+# define __NR_dup2 32
+# endif
+# ifndef __NR_pause
+# define __NR_pause 33
+# endif
+# ifndef __NR_nanosleep
+# define __NR_nanosleep 34
+# endif
+# ifndef __NR_getitimer
+# define __NR_getitimer 35
+# endif
+# ifndef __NR_setitimer
+# define __NR_setitimer 36
+# endif
+# ifndef __NR_alarm
+# define __NR_alarm 37
+# endif
+# ifndef __NR_getpid
+# define __NR_getpid 38
+# endif
+# ifndef __NR_sendfile
+# define __NR_sendfile 39
+# endif
+# ifndef __NR_socket
+# define __NR_socket 40
+# endif
+# ifndef __NR_connect
+# define __NR_connect 41
+# endif
+# ifndef __NR_accept
+# define __NR_accept 42
+# endif
+# ifndef __NR_sendto
+# define __NR_sendto 43
+# endif
+# ifndef __NR_recvfrom
+# define __NR_recvfrom 44
+# endif
+# ifndef __NR_sendmsg
+# define __NR_sendmsg 45
+# endif
+# ifndef __NR_recvmsg
+# define __NR_recvmsg 46
+# endif
+# ifndef __NR_shutdown
+# define __NR_shutdown 47
+# endif
+# ifndef __NR_bind
+# define __NR_bind 48
+# endif
+# ifndef __NR_listen
+# define __NR_listen 49
+# endif
+# ifndef __NR_getsockname
+# define __NR_getsockname 50
+# endif
+# ifndef __NR_getpeername
+# define __NR_getpeername 51
+# endif
+# ifndef __NR_socketpair
+# define __NR_socketpair 52
+# endif
+# ifndef __NR_setsockopt
+# define __NR_setsockopt 53
+# endif
+# ifndef __NR_getsockopt
+# define __NR_getsockopt 54
+# endif
+# ifndef __NR_clone
+# define __NR_clone 55
+# endif
+# ifndef __NR_fork
+# define __NR_fork 56
+# endif
+# ifndef __NR_execve
+# define __NR_execve 57
+# endif
+# ifndef __NR_exit
+# define __NR_exit 58
+# endif
+# ifndef __NR_wait4
+# define __NR_wait4 59
+# endif
+# ifndef __NR_kill
+# define __NR_kill 60
+# endif
+# ifndef __NR_uname
+# define __NR_uname 61
+# endif
+# ifndef __NR_semget
+# define __NR_semget 62
+# endif
+# ifndef __NR_semop
+# define __NR_semop 63
+# endif
+# ifndef __NR_semctl
+# define __NR_semctl 64
+# endif
+# ifndef __NR_shmdt
+# define __NR_shmdt 65
+# endif
+# ifndef __NR_msgget
+# define __NR_msgget 66
+# endif
+# ifndef __NR_msgsnd
+# define __NR_msgsnd 67
+# endif
+# ifndef __NR_msgrcv
+# define __NR_msgrcv 68
+# endif
+# ifndef __NR_msgctl
+# define __NR_msgctl 69
+# endif
+# ifndef __NR_fcntl
+# define __NR_fcntl 70
+# endif
+# ifndef __NR_flock
+# define __NR_flock 71
+# endif
+# ifndef __NR_fsync
+# define __NR_fsync 72
+# endif
+# ifndef __NR_fdatasync
+# define __NR_fdatasync 73
+# endif
+# ifndef __NR_truncate
+# define __NR_truncate 74
+# endif
+# ifndef __NR_ftruncate
+# define __NR_ftruncate 75
+# endif
+# ifndef __NR_getdents
+# define __NR_getdents 76
+# endif
+# ifndef __NR_getcwd
+# define __NR_getcwd 77
+# endif
+# ifndef __NR_chdir
+# define __NR_chdir 78
+# endif
+# ifndef __NR_fchdir
+# define __NR_fchdir 79
+# endif
+# ifndef __NR_rename
+# define __NR_rename 80
+# endif
+# ifndef __NR_mkdir
+# define __NR_mkdir 81
+# endif
+# ifndef __NR_rmdir
+# define __NR_rmdir 82
+# endif
+# ifndef __NR_creat
+# define __NR_creat 83
+# endif
+# ifndef __NR_link
+# define __NR_link 84
+# endif
+# ifndef __NR_unlink
+# define __NR_unlink 85
+# endif
+# ifndef __NR_symlink
+# define __NR_symlink 86
+# endif
+# ifndef __NR_readlink
+# define __NR_readlink 87
+# endif
+# ifndef __NR_chmod
+# define __NR_chmod 88
+# endif
+# ifndef __NR_fchmod
+# define __NR_fchmod 89
+# endif
+# ifndef __NR_chown
+# define __NR_chown 90
+# endif
+# ifndef __NR_fchown
+# define __NR_fchown 91
+# endif
+# ifndef __NR_lchown
+# define __NR_lchown 92
+# endif
+# ifndef __NR_umask
+# define __NR_umask 93
+# endif
+# ifndef __NR_gettimeofday
+# define __NR_gettimeofday 94
+# endif
+# ifndef __NR_getrlimit
+# define __NR_getrlimit 95
+# endif
+# ifndef __NR_getrusage
+# define __NR_getrusage 96
+# endif
+# ifndef __NR_sysinfo
+# define __NR_sysinfo 97
+# endif
+# ifndef __NR_times
+# define __NR_times 98
+# endif
+# ifndef __NR_ptrace
+# define __NR_ptrace 99
+# endif
+# ifndef __NR_getuid
+# define __NR_getuid 100
+# endif
+# ifndef __NR_syslog
+# define __NR_syslog 101
+# endif
+# ifndef __NR_getgid
+# define __NR_getgid 102
+# endif
+# ifndef __NR_setuid
+# define __NR_setuid 103
+# endif
+# ifndef __NR_setgid
+# define __NR_setgid 104
+# endif
+# ifndef __NR_geteuid
+# define __NR_geteuid 105
+# endif
+# ifndef __NR_getegid
+# define __NR_getegid 106
+# endif
+# ifndef __NR_setpgid
+# define __NR_setpgid 107
+# endif
+# ifndef __NR_getppid
+# define __NR_getppid 108
+# endif
+# ifndef __NR_getpgrp
+# define __NR_getpgrp 109
+# endif
+# ifndef __NR_setsid
+# define __NR_setsid 110
+# endif
+# ifndef __NR_setreuid
+# define __NR_setreuid 111
+# endif
+# ifndef __NR_setregid
+# define __NR_setregid 112
+# endif
+# ifndef __NR_getgroups
+# define __NR_getgroups 113
+# endif
+# ifndef __NR_setgroups
+# define __NR_setgroups 114
+# endif
+# ifndef __NR_setresuid
+# define __NR_setresuid 115
+# endif
+# ifndef __NR_getresuid
+# define __NR_getresuid 116
+# endif
+# ifndef __NR_setresgid
+# define __NR_setresgid 117
+# endif
+# ifndef __NR_getresgid
+# define __NR_getresgid 118
+# endif
+# ifndef __NR_getpgid
+# define __NR_getpgid 119
+# endif
+# ifndef __NR_setfsuid
+# define __NR_setfsuid 120
+# endif
+# ifndef __NR_setfsgid
+# define __NR_setfsgid 121
+# endif
+# ifndef __NR_getsid
+# define __NR_getsid 122
+# endif
+# ifndef __NR_capget
+# define __NR_capget 123
+# endif
+# ifndef __NR_capset
+# define __NR_capset 124
+# endif
+# ifndef __NR_rt_sigpending
+# define __NR_rt_sigpending 125
+# endif
+# ifndef __NR_rt_sigtimedwait
+# define __NR_rt_sigtimedwait 126
+# endif
+# ifndef __NR_rt_sigqueueinfo
+# define __NR_rt_sigqueueinfo 127
+# endif
+# ifndef __NR_rt_sigsuspend
+# define __NR_rt_sigsuspend 128
+# endif
+# ifndef __NR_sigaltstack
+# define __NR_sigaltstack 129
+# endif
+# ifndef __NR_utime
+# define __NR_utime 130
+# endif
+# ifndef __NR_mknod
+# define __NR_mknod 131
+# endif
+# ifndef __NR_personality
+# define __NR_personality 132
+# endif
+# ifndef __NR_ustat
+# define __NR_ustat 133
+# endif
+# ifndef __NR_statfs
+# define __NR_statfs 134
+# endif
+# ifndef __NR_fstatfs
+# define __NR_fstatfs 135
+# endif
+# ifndef __NR_sysfs
+# define __NR_sysfs 136
+# endif
+# ifndef __NR_getpriority
+# define __NR_getpriority 137
+# endif
+# ifndef __NR_setpriority
+# define __NR_setpriority 138
+# endif
+# ifndef __NR_sched_setparam
+# define __NR_sched_setparam 139
+# endif
+# ifndef __NR_sched_getparam
+# define __NR_sched_getparam 140
+# endif
+# ifndef __NR_sched_setscheduler
+# define __NR_sched_setscheduler 141
+# endif
+# ifndef __NR_sched_getscheduler
+# define __NR_sched_getscheduler 142
+# endif
+# ifndef __NR_sched_get_priority_max
+# define __NR_sched_get_priority_max 143
+# endif
+# ifndef __NR_sched_get_priority_min
+# define __NR_sched_get_priority_min 144
+# endif
+# ifndef __NR_sched_rr_get_interval
+# define __NR_sched_rr_get_interval 145
+# endif
+# ifndef __NR_mlock
+# define __NR_mlock 146
+# endif
+# ifndef __NR_munlock
+# define __NR_munlock 147
+# endif
+# ifndef __NR_mlockall
+# define __NR_mlockall 148
+# endif
+# ifndef __NR_munlockall
+# define __NR_munlockall 149
+# endif
+# ifndef __NR_vhangup
+# define __NR_vhangup 150
+# endif
+# ifndef __NR_pivot_root
+# define __NR_pivot_root 151
+# endif
+# ifndef __NR__sysctl
+# define __NR__sysctl 152
+# endif
+# ifndef __NR_prctl
+# define __NR_prctl 153
+# endif
+# ifndef __NR_adjtimex
+# define __NR_adjtimex 154
+# endif
+# ifndef __NR_setrlimit
+# define __NR_setrlimit 155
+# endif
+# ifndef __NR_chroot
+# define __NR_chroot 156
+# endif
+# ifndef __NR_sync
+# define __NR_sync 157
+# endif
+# ifndef __NR_acct
+# define __NR_acct 158
+# endif
+# ifndef __NR_settimeofday
+# define __NR_settimeofday 159
+# endif
+# ifndef __NR_mount
+# define __NR_mount 160
+# endif
+# ifndef __NR_umount2
+# define __NR_umount2 161
+# endif
+# ifndef __NR_swapon
+# define __NR_swapon 162
+# endif
+# ifndef __NR_swapoff
+# define __NR_swapoff 163
+# endif
+# ifndef __NR_reboot
+# define __NR_reboot 164
+# endif
+# ifndef __NR_sethostname
+# define __NR_sethostname 165
+# endif
+# ifndef __NR_setdomainname
+# define __NR_setdomainname 166
+# endif
+# ifndef __NR_create_module
+# define __NR_create_module 167
+# endif
+# ifndef __NR_init_module
+# define __NR_init_module 168
+# endif
+# ifndef __NR_delete_module
+# define __NR_delete_module 169
+# endif
+# ifndef __NR_get_kernel_syms
+# define __NR_get_kernel_syms 170
+# endif
+# ifndef __NR_query_module
+# define __NR_query_module 171
+# endif
+# ifndef __NR_quotactl
+# define __NR_quotactl 172
+# endif
+# ifndef __NR_nfsservctl
+# define __NR_nfsservctl 173
+# endif
+# ifndef __NR_getpmsg
+# define __NR_getpmsg 174
+# endif
+# ifndef __NR_putpmsg
+# define __NR_putpmsg 175
+# endif
+# ifndef __NR_afs_syscall
+# define __NR_afs_syscall 176
+# endif
+# ifndef __NR_reserved177
+# define __NR_reserved177 177
+# endif
+# ifndef __NR_gettid
+# define __NR_gettid 178
+# endif
+# ifndef __NR_readahead
+# define __NR_readahead 179
+# endif
+# ifndef __NR_setxattr
+# define __NR_setxattr 180
+# endif
+# ifndef __NR_lsetxattr
+# define __NR_lsetxattr 181
+# endif
+# ifndef __NR_fsetxattr
+# define __NR_fsetxattr 182
+# endif
+# ifndef __NR_getxattr
+# define __NR_getxattr 183
+# endif
+# ifndef __NR_lgetxattr
+# define __NR_lgetxattr 184
+# endif
+# ifndef __NR_fgetxattr
+# define __NR_fgetxattr 185
+# endif
+# ifndef __NR_listxattr
+# define __NR_listxattr 186
+# endif
+# ifndef __NR_llistxattr
+# define __NR_llistxattr 187
+# endif
+# ifndef __NR_flistxattr
+# define __NR_flistxattr 188
+# endif
+# ifndef __NR_removexattr
+# define __NR_removexattr 189
+# endif
+# ifndef __NR_lremovexattr
+# define __NR_lremovexattr 190
+# endif
+# ifndef __NR_fremovexattr
+# define __NR_fremovexattr 191
+# endif
+# ifndef __NR_tkill
+# define __NR_tkill 192
+# endif
+# ifndef __NR_reserved193
+# define __NR_reserved193 193
+# endif
+# ifndef __NR_futex
+# define __NR_futex 194
+# endif
+# ifndef __NR_sched_setaffinity
+# define __NR_sched_setaffinity 195
+# endif
+# ifndef __NR_sched_getaffinity
+# define __NR_sched_getaffinity 196
+# endif
+# ifndef __NR_cacheflush
+# define __NR_cacheflush 197
+# endif
+# ifndef __NR_cachectl
+# define __NR_cachectl 198
+# endif
+# ifndef __NR_sysmips
+# define __NR_sysmips 199
+# endif
+# ifndef __NR_io_setup
+# define __NR_io_setup 200
+# endif
+# ifndef __NR_io_destroy
+# define __NR_io_destroy 201
+# endif
+# ifndef __NR_io_getevents
+# define __NR_io_getevents 202
+# endif
+# ifndef __NR_io_submit
+# define __NR_io_submit 203
+# endif
+# ifndef __NR_io_cancel
+# define __NR_io_cancel 204
+# endif
+# ifndef __NR_exit_group
+# define __NR_exit_group 205
+# endif
+# ifndef __NR_lookup_dcookie
+# define __NR_lookup_dcookie 206
+# endif
+# ifndef __NR_epoll_create
+# define __NR_epoll_create 207
+# endif
+# ifndef __NR_epoll_ctl
+# define __NR_epoll_ctl 208
+# endif
+# ifndef __NR_epoll_wait
+# define __NR_epoll_wait 209
+# endif
+# ifndef __NR_remap_file_pages
+# define __NR_remap_file_pages 210
+# endif
+# ifndef __NR_rt_sigreturn
+# define __NR_rt_sigreturn 211
+# endif
+# ifndef __NR_fcntl64
+# define __NR_fcntl64 212
+# endif
+# ifndef __NR_set_tid_address
+# define __NR_set_tid_address 213
+# endif
+# ifndef __NR_restart_syscall
+# define __NR_restart_syscall 214
+# endif
+# ifndef __NR_semtimedop
+# define __NR_semtimedop 215
+# endif
+# ifndef __NR_fadvise64
+# define __NR_fadvise64 216
+# endif
+# ifndef __NR_statfs64
+# define __NR_statfs64 217
+# endif
+# ifndef __NR_fstatfs64
+# define __NR_fstatfs64 218
+# endif
+# ifndef __NR_sendfile64
+# define __NR_sendfile64 219
+# endif
+# ifndef __NR_timer_create
+# define __NR_timer_create 220
+# endif
+# ifndef __NR_timer_settime
+# define __NR_timer_settime 221
+# endif
+# ifndef __NR_timer_gettime
+# define __NR_timer_gettime 222
+# endif
+# ifndef __NR_timer_getoverrun
+# define __NR_timer_getoverrun 223
+# endif
+# ifndef __NR_timer_delete
+# define __NR_timer_delete 224
+# endif
+# ifndef __NR_clock_settime
+# define __NR_clock_settime 225
+# endif
+# ifndef __NR_clock_gettime
+# define __NR_clock_gettime 226
+# endif
+# ifndef __NR_clock_getres
+# define __NR_clock_getres 227
+# endif
+# ifndef __NR_clock_nanosleep
+# define __NR_clock_nanosleep 228
+# endif
+# ifndef __NR_tgkill
+# define __NR_tgkill 229
+# endif
+# ifndef __NR_utimes
+# define __NR_utimes 230
+# endif
+# ifndef __NR_mbind
+# define __NR_mbind 231
+# endif
+# ifndef __NR_get_mempolicy
+# define __NR_get_mempolicy 232
+# endif
+# ifndef __NR_set_mempolicy
+# define __NR_set_mempolicy 233
+# endif
+# ifndef __NR_mq_open
+# define __NR_mq_open 234
+# endif
+# ifndef __NR_mq_unlink
+# define __NR_mq_unlink 235
+# endif
+# ifndef __NR_mq_timedsend
+# define __NR_mq_timedsend 236
+# endif
+# ifndef __NR_mq_timedreceive
+# define __NR_mq_timedreceive 237
+# endif
+# ifndef __NR_mq_notify
+# define __NR_mq_notify 238
+# endif
+# ifndef __NR_mq_getsetattr
+# define __NR_mq_getsetattr 239
+# endif
+# ifndef __NR_vserver
+# define __NR_vserver 240
+# endif
+# ifndef __NR_waitid
+# define __NR_waitid 241
+# endif
+# ifndef __NR_add_key
+# define __NR_add_key 243
+# endif
+# ifndef __NR_request_key
+# define __NR_request_key 244
+# endif
+# ifndef __NR_keyctl
+# define __NR_keyctl 245
+# endif
+# ifndef __NR_set_thread_area
+# define __NR_set_thread_area 246
+# endif
+# ifndef __NR_inotify_init
+# define __NR_inotify_init 247
+# endif
+# ifndef __NR_inotify_add_watch
+# define __NR_inotify_add_watch 248
+# endif
+# ifndef __NR_inotify_rm_watch
+# define __NR_inotify_rm_watch 249
+# endif
+# ifndef __NR_migrate_pages
+# define __NR_migrate_pages 250
+# endif
+# ifndef __NR_openat
+# define __NR_openat 251
+# endif
+# ifndef __NR_mkdirat
+# define __NR_mkdirat 252
+# endif
+# ifndef __NR_mknodat
+# define __NR_mknodat 253
+# endif
+# ifndef __NR_fchownat
+# define __NR_fchownat 254
+# endif
+# ifndef __NR_futimesat
+# define __NR_futimesat 255
+# endif
+# ifndef __NR_newfstatat
+# define __NR_newfstatat 256
+# endif
+# ifndef __NR_unlinkat
+# define __NR_unlinkat 257
+# endif
+# ifndef __NR_renameat
+# define __NR_renameat 258
+# endif
+# ifndef __NR_linkat
+# define __NR_linkat 259
+# endif
+# ifndef __NR_symlinkat
+# define __NR_symlinkat 260
+# endif
+# ifndef __NR_readlinkat
+# define __NR_readlinkat 261
+# endif
+# ifndef __NR_fchmodat
+# define __NR_fchmodat 262
+# endif
+# ifndef __NR_faccessat
+# define __NR_faccessat 263
+# endif
+# ifndef __NR_pselect6
+# define __NR_pselect6 264
+# endif
+# ifndef __NR_ppoll
+# define __NR_ppoll 265
+# endif
+# ifndef __NR_unshare
+# define __NR_unshare 266
+# endif
+# ifndef __NR_splice
+# define __NR_splice 267
+# endif
+# ifndef __NR_sync_file_range
+# define __NR_sync_file_range 268
+# endif
+# ifndef __NR_tee
+# define __NR_tee 269
+# endif
+# ifndef __NR_vmsplice
+# define __NR_vmsplice 270
+# endif
+# ifndef __NR_move_pages
+# define __NR_move_pages 271
+# endif
+# ifndef __NR_set_robust_list
+# define __NR_set_robust_list 272
+# endif
+# ifndef __NR_get_robust_list
+# define __NR_get_robust_list 273
+# endif
+# ifndef __NR_kexec_load
+# define __NR_kexec_load 274
+# endif
+# ifndef __NR_getcpu
+# define __NR_getcpu 275
+# endif
+# ifndef __NR_epoll_pwait
+# define __NR_epoll_pwait 276
+# endif
+# ifndef __NR_ioprio_set
+# define __NR_ioprio_set 277
+# endif
+# ifndef __NR_ioprio_get
+# define __NR_ioprio_get 278
+# endif
+# ifndef __NR_utimensat
+# define __NR_utimensat 279
+# endif
+# ifndef __NR_signalfd
+# define __NR_signalfd 280
+# endif
+# ifndef __NR_timerfd
+# define __NR_timerfd 281
+# endif
+# ifndef __NR_eventfd
+# define __NR_eventfd 282
+# endif
+# ifndef __NR_fallocate
+# define __NR_fallocate 283
+# endif
+# ifndef __NR_timerfd_create
+# define __NR_timerfd_create 284
+# endif
+# ifndef __NR_timerfd_gettime
+# define __NR_timerfd_gettime 285
+# endif
+# ifndef __NR_timerfd_settime
+# define __NR_timerfd_settime 286
+# endif
+# ifndef __NR_signalfd4
+# define __NR_signalfd4 287
+# endif
+# ifndef __NR_eventfd2
+# define __NR_eventfd2 288
+# endif
+# ifndef __NR_epoll_create1
+# define __NR_epoll_create1 289
+# endif
+# ifndef __NR_dup3
+# define __NR_dup3 290
+# endif
+# ifndef __NR_pipe2
+# define __NR_pipe2 291
+# endif
+# ifndef __NR_inotify_init1
+# define __NR_inotify_init1 292
+# endif
+# ifndef __NR_preadv
+# define __NR_preadv 293
+# endif
+# ifndef __NR_pwritev
+# define __NR_pwritev 294
+# endif
+# ifndef __NR_rt_tgsigqueueinfo
+# define __NR_rt_tgsigqueueinfo 295
+# endif
+# ifndef __NR_perf_event_open
+# define __NR_perf_event_open 296
+# endif
+# ifndef __NR_accept4
+# define __NR_accept4 297
+# endif
+# ifndef __NR_recvmmsg
+# define __NR_recvmmsg 298
+# endif
+# ifndef __NR_getdents64
+# define __NR_getdents64 299
+# endif
+# ifndef __NR_fanotify_init
+# define __NR_fanotify_init 300
+# endif
+# ifndef __NR_fanotify_mark
+# define __NR_fanotify_mark 301
+# endif
+# ifndef __NR_prlimit64
+# define __NR_prlimit64 302
+# endif
+# ifndef __NR_name_to_handle_at
+# define __NR_name_to_handle_at 303
+# endif
+# ifndef __NR_open_by_handle_at
+# define __NR_open_by_handle_at 304
+# endif
+# ifndef __NR_clock_adjtime
+# define __NR_clock_adjtime 305
+# endif
+# ifndef __NR_syncfs
+# define __NR_syncfs 306
+# endif
+# ifndef __NR_sendmmsg
+# define __NR_sendmmsg 307
+# endif
+# ifndef __NR_setns
+# define __NR_setns 308
+# endif
+# ifndef __NR_process_vm_readv
+# define __NR_process_vm_readv 309
+# endif
+# ifndef __NR_process_vm_writev
+# define __NR_process_vm_writev 310
+# endif
+# ifndef __NR_kcmp
+# define __NR_kcmp 311
+# endif
+# ifndef __NR_finit_module
+# define __NR_finit_module 312
+# endif
+# ifndef __NR_sched_setattr
+# define __NR_sched_setattr 313
+# endif
+# ifndef __NR_sched_getattr
+# define __NR_sched_getattr 314
+# endif
+# ifndef __NR_renameat2
+# define __NR_renameat2 315
+# endif
+# ifndef __NR_seccomp
+# define __NR_seccomp 316
+# endif
+# ifndef __NR_getrandom
+# define __NR_getrandom 317
+# endif
+# ifndef __NR_memfd_create
+# define __NR_memfd_create 318
+# endif
+# ifndef __NR_bpf
+# define __NR_bpf 319
+# endif
+# ifndef __NR_execveat
+# define __NR_execveat 320
+# endif
+# ifndef __NR_userfaultfd
+# define __NR_userfaultfd 321
+# endif
+# ifndef __NR_membarrier
+# define __NR_membarrier 322
+# endif
+# ifndef __NR_mlock2
+# define __NR_mlock2 323
+# endif
+# ifndef __NR_copy_file_range
+# define __NR_copy_file_range 324
+# endif
+# ifndef __NR_preadv2
+# define __NR_preadv2 325
+# endif
+# ifndef __NR_pwritev2
+# define __NR_pwritev2 326
+# endif
+# ifndef __NR_pkey_mprotect
+# define __NR_pkey_mprotect 327
+# endif
+# ifndef __NR_pkey_alloc
+# define __NR_pkey_alloc 328
+# endif
+# ifndef __NR_pkey_free
+# define __NR_pkey_free 329
+# endif
+# ifndef __NR_statx
+# define __NR_statx 330
+# endif
+# ifndef __NR_rseq
+# define __NR_rseq 331
+# endif
+# ifndef __NR_io_pgetevents
+# define __NR_io_pgetevents 332
+# endif
+# ifndef __NR_clock_gettime64
+# define __NR_clock_gettime64 403
+# endif
+# ifndef __NR_clock_settime64
+# define __NR_clock_settime64 404
+# endif
+# ifndef __NR_clock_adjtime64
+# define __NR_clock_adjtime64 405
+# endif
+# ifndef __NR_clock_getres_time64
+# define __NR_clock_getres_time64 406
+# endif
+# ifndef __NR_clock_nanosleep_time64
+# define __NR_clock_nanosleep_time64 407
+# endif
+# ifndef __NR_timer_gettime64
+# define __NR_timer_gettime64 408
+# endif
+# ifndef __NR_timer_settime64
+# define __NR_timer_settime64 409
+# endif
+# ifndef __NR_timerfd_gettime64
+# define __NR_timerfd_gettime64 410
+# endif
+# ifndef __NR_timerfd_settime64
+# define __NR_timerfd_settime64 411
+# endif
+# ifndef __NR_utimensat_time64
+# define __NR_utimensat_time64 412
+# endif
+# ifndef __NR_pselect6_time64
+# define __NR_pselect6_time64 413
+# endif
+# ifndef __NR_ppoll_time64
+# define __NR_ppoll_time64 414
+# endif
+# ifndef __NR_io_pgetevents_time64
+# define __NR_io_pgetevents_time64 416
+# endif
+# ifndef __NR_recvmmsg_time64
+# define __NR_recvmmsg_time64 417
+# endif
+# ifndef __NR_mq_timedsend_time64
+# define __NR_mq_timedsend_time64 418
+# endif
+# ifndef __NR_mq_timedreceive_time64
+# define __NR_mq_timedreceive_time64 419
+# endif
+# ifndef __NR_semtimedop_time64
+# define __NR_semtimedop_time64 420
+# endif
+# ifndef __NR_rt_sigtimedwait_time64
+# define __NR_rt_sigtimedwait_time64 421
+# endif
+# ifndef __NR_futex_time64
+# define __NR_futex_time64 422
+# endif
+# ifndef __NR_sched_rr_get_interval_time64
+# define __NR_sched_rr_get_interval_time64 423
+# endif
+# ifndef __NR_pidfd_send_signal
+# define __NR_pidfd_send_signal 424
+# endif
+# ifndef __NR_io_uring_setup
+# define __NR_io_uring_setup 425
+# endif
+# ifndef __NR_io_uring_enter
+# define __NR_io_uring_enter 426
+# endif
+# ifndef __NR_io_uring_register
+# define __NR_io_uring_register 427
+# endif
+# ifndef __NR_open_tree
+# define __NR_open_tree 428
+# endif
+# ifndef __NR_move_mount
+# define __NR_move_mount 429
+# endif
+# ifndef __NR_fsopen
+# define __NR_fsopen 430
+# endif
+# ifndef __NR_fsconfig
+# define __NR_fsconfig 431
+# endif
+# ifndef __NR_fsmount
+# define __NR_fsmount 432
+# endif
+# ifndef __NR_fspick
+# define __NR_fspick 433
+# endif
+# ifndef __NR_pidfd_open
+# define __NR_pidfd_open 434
+# endif
+# ifndef __NR_clone3
+# define __NR_clone3 435
+# endif
+# ifndef __NR_openat2
+# define __NR_openat2 437
+# endif
+# ifndef __NR_pidfd_getfd
+# define __NR_pidfd_getfd 438
+# endif
+#endif
+
+
+#if defined(__mips__) && defined(_ABI64)
+# ifndef __NR_read
+# define __NR_read 0
+# endif
+# ifndef __NR_write
+# define __NR_write 1
+# endif
+# ifndef __NR_open
+# define __NR_open 2
+# endif
+# ifndef __NR_close
+# define __NR_close 3
+# endif
+# ifndef __NR_stat
+# define __NR_stat 4
+# endif
+# ifndef __NR_fstat
+# define __NR_fstat 5
+# endif
+# ifndef __NR_lstat
+# define __NR_lstat 6
+# endif
+# ifndef __NR_poll
+# define __NR_poll 7
+# endif
+# ifndef __NR_lseek
+# define __NR_lseek 8
+# endif
+# ifndef __NR_mmap
+# define __NR_mmap 9
+# endif
+# ifndef __NR_mprotect
+# define __NR_mprotect 10
+# endif
+# ifndef __NR_munmap
+# define __NR_munmap 11
+# endif
+# ifndef __NR_brk
+# define __NR_brk 12
+# endif
+# ifndef __NR_rt_sigaction
+# define __NR_rt_sigaction 13
+# endif
+# ifndef __NR_rt_sigprocmask
+# define __NR_rt_sigprocmask 14
+# endif
+# ifndef __NR_ioctl
+# define __NR_ioctl 15
+# endif
+# ifndef __NR_pread64
+# define __NR_pread64 16
+# endif
+# ifndef __NR_pwrite64
+# define __NR_pwrite64 17
+# endif
+# ifndef __NR_readv
+# define __NR_readv 18
+# endif
+# ifndef __NR_writev
+# define __NR_writev 19
+# endif
+# ifndef __NR_access
+# define __NR_access 20
+# endif
+# ifndef __NR_pipe
+# define __NR_pipe 21
+# endif
+# ifndef __NR__newselect
+# define __NR__newselect 22
+# endif
+# ifndef __NR_sched_yield
+# define __NR_sched_yield 23
+# endif
+# ifndef __NR_mremap
+# define __NR_mremap 24
+# endif
+# ifndef __NR_msync
+# define __NR_msync 25
+# endif
+# ifndef __NR_mincore
+# define __NR_mincore 26
+# endif
+# ifndef __NR_madvise
+# define __NR_madvise 27
+# endif
+# ifndef __NR_shmget
+# define __NR_shmget 28
+# endif
+# ifndef __NR_shmat
+# define __NR_shmat 29
+# endif
+# ifndef __NR_shmctl
+# define __NR_shmctl 30
+# endif
+# ifndef __NR_dup
+# define __NR_dup 31
+# endif
+# ifndef __NR_dup2
+# define __NR_dup2 32
+# endif
+# ifndef __NR_pause
+# define __NR_pause 33
+# endif
+# ifndef __NR_nanosleep
+# define __NR_nanosleep 34
+# endif
+# ifndef __NR_getitimer
+# define __NR_getitimer 35
+# endif
+# ifndef __NR_setitimer
+# define __NR_setitimer 36
+# endif
+# ifndef __NR_alarm
+# define __NR_alarm 37
+# endif
+# ifndef __NR_getpid
+# define __NR_getpid 38
+# endif
+# ifndef __NR_sendfile
+# define __NR_sendfile 39
+# endif
+# ifndef __NR_socket
+# define __NR_socket 40
+# endif
+# ifndef __NR_connect
+# define __NR_connect 41
+# endif
+# ifndef __NR_accept
+# define __NR_accept 42
+# endif
+# ifndef __NR_sendto
+# define __NR_sendto 43
+# endif
+# ifndef __NR_recvfrom
+# define __NR_recvfrom 44
+# endif
+# ifndef __NR_sendmsg
+# define __NR_sendmsg 45
+# endif
+# ifndef __NR_recvmsg
+# define __NR_recvmsg 46
+# endif
+# ifndef __NR_shutdown
+# define __NR_shutdown 47
+# endif
+# ifndef __NR_bind
+# define __NR_bind 48
+# endif
+# ifndef __NR_listen
+# define __NR_listen 49
+# endif
+# ifndef __NR_getsockname
+# define __NR_getsockname 50
+# endif
+# ifndef __NR_getpeername
+# define __NR_getpeername 51
+# endif
+# ifndef __NR_socketpair
+# define __NR_socketpair 52
+# endif
+# ifndef __NR_setsockopt
+# define __NR_setsockopt 53
+# endif
+# ifndef __NR_getsockopt
+# define __NR_getsockopt 54
+# endif
+# ifndef __NR_clone
+# define __NR_clone 55
+# endif
+# ifndef __NR_fork
+# define __NR_fork 56
+# endif
+# ifndef __NR_execve
+# define __NR_execve 57
+# endif
+# ifndef __NR_exit
+# define __NR_exit 58
+# endif
+# ifndef __NR_wait4
+# define __NR_wait4 59
+# endif
+# ifndef __NR_kill
+# define __NR_kill 60
+# endif
+# ifndef __NR_uname
+# define __NR_uname 61
+# endif
+# ifndef __NR_semget
+# define __NR_semget 62
+# endif
+# ifndef __NR_semop
+# define __NR_semop 63
+# endif
+# ifndef __NR_semctl
+# define __NR_semctl 64
+# endif
+# ifndef __NR_shmdt
+# define __NR_shmdt 65
+# endif
+# ifndef __NR_msgget
+# define __NR_msgget 66
+# endif
+# ifndef __NR_msgsnd
+# define __NR_msgsnd 67
+# endif
+# ifndef __NR_msgrcv
+# define __NR_msgrcv 68
+# endif
+# ifndef __NR_msgctl
+# define __NR_msgctl 69
+# endif
+# ifndef __NR_fcntl
+# define __NR_fcntl 70
+# endif
+# ifndef __NR_flock
+# define __NR_flock 71
+# endif
+# ifndef __NR_fsync
+# define __NR_fsync 72
+# endif
+# ifndef __NR_fdatasync
+# define __NR_fdatasync 73
+# endif
+# ifndef __NR_truncate
+# define __NR_truncate 74
+# endif
+# ifndef __NR_ftruncate
+# define __NR_ftruncate 75
+# endif
+# ifndef __NR_getdents
+# define __NR_getdents 76
+# endif
+# ifndef __NR_getcwd
+# define __NR_getcwd 77
+# endif
+# ifndef __NR_chdir
+# define __NR_chdir 78
+# endif
+# ifndef __NR_fchdir
+# define __NR_fchdir 79
+# endif
+# ifndef __NR_rename
+# define __NR_rename 80
+# endif
+# ifndef __NR_mkdir
+# define __NR_mkdir 81
+# endif
+# ifndef __NR_rmdir
+# define __NR_rmdir 82
+# endif
+# ifndef __NR_creat
+# define __NR_creat 83
+# endif
+# ifndef __NR_link
+# define __NR_link 84
+# endif
+# ifndef __NR_unlink
+# define __NR_unlink 85
+# endif
+# ifndef __NR_symlink
+# define __NR_symlink 86
+# endif
+# ifndef __NR_readlink
+# define __NR_readlink 87
+# endif
+# ifndef __NR_chmod
+# define __NR_chmod 88
+# endif
+# ifndef __NR_fchmod
+# define __NR_fchmod 89
+# endif
+# ifndef __NR_chown
+# define __NR_chown 90
+# endif
+# ifndef __NR_fchown
+# define __NR_fchown 91
+# endif
+# ifndef __NR_lchown
+# define __NR_lchown 92
+# endif
+# ifndef __NR_umask
+# define __NR_umask 93
+# endif
+# ifndef __NR_gettimeofday
+# define __NR_gettimeofday 94
+# endif
+# ifndef __NR_getrlimit
+# define __NR_getrlimit 95
+# endif
+# ifndef __NR_getrusage
+# define __NR_getrusage 96
+# endif
+# ifndef __NR_sysinfo
+# define __NR_sysinfo 97
+# endif
+# ifndef __NR_times
+# define __NR_times 98
+# endif
+# ifndef __NR_ptrace
+# define __NR_ptrace 99
+# endif
+# ifndef __NR_getuid
+# define __NR_getuid 100
+# endif
+# ifndef __NR_syslog
+# define __NR_syslog 101
+# endif
+# ifndef __NR_getgid
+# define __NR_getgid 102
+# endif
+# ifndef __NR_setuid
+# define __NR_setuid 103
+# endif
+# ifndef __NR_setgid
+# define __NR_setgid 104
+# endif
+# ifndef __NR_geteuid
+# define __NR_geteuid 105
+# endif
+# ifndef __NR_getegid
+# define __NR_getegid 106
+# endif
+# ifndef __NR_setpgid
+# define __NR_setpgid 107
+# endif
+# ifndef __NR_getppid
+# define __NR_getppid 108
+# endif
+# ifndef __NR_getpgrp
+# define __NR_getpgrp 109
+# endif
+# ifndef __NR_setsid
+# define __NR_setsid 110
+# endif
+# ifndef __NR_setreuid
+# define __NR_setreuid 111
+# endif
+# ifndef __NR_setregid
+# define __NR_setregid 112
+# endif
+# ifndef __NR_getgroups
+# define __NR_getgroups 113
+# endif
+# ifndef __NR_setgroups
+# define __NR_setgroups 114
+# endif
+# ifndef __NR_setresuid
+# define __NR_setresuid 115
+# endif
+# ifndef __NR_getresuid
+# define __NR_getresuid 116
+# endif
+# ifndef __NR_setresgid
+# define __NR_setresgid 117
+# endif
+# ifndef __NR_getresgid
+# define __NR_getresgid 118
+# endif
+# ifndef __NR_getpgid
+# define __NR_getpgid 119
+# endif
+# ifndef __NR_setfsuid
+# define __NR_setfsuid 120
+# endif
+# ifndef __NR_setfsgid
+# define __NR_setfsgid 121
+# endif
+# ifndef __NR_getsid
+# define __NR_getsid 122
+# endif
+# ifndef __NR_capget
+# define __NR_capget 123
+# endif
+# ifndef __NR_capset
+# define __NR_capset 124
+# endif
+# ifndef __NR_rt_sigpending
+# define __NR_rt_sigpending 125
+# endif
+# ifndef __NR_rt_sigtimedwait
+# define __NR_rt_sigtimedwait 126
+# endif
+# ifndef __NR_rt_sigqueueinfo
+# define __NR_rt_sigqueueinfo 127
+# endif
+# ifndef __NR_rt_sigsuspend
+# define __NR_rt_sigsuspend 128
+# endif
+# ifndef __NR_sigaltstack
+# define __NR_sigaltstack 129
+# endif
+# ifndef __NR_utime
+# define __NR_utime 130
+# endif
+# ifndef __NR_mknod
+# define __NR_mknod 131
+# endif
+# ifndef __NR_personality
+# define __NR_personality 132
+# endif
+# ifndef __NR_ustat
+# define __NR_ustat 133
+# endif
+# ifndef __NR_statfs
+# define __NR_statfs 134
+# endif
+# ifndef __NR_fstatfs
+# define __NR_fstatfs 135
+# endif
+# ifndef __NR_sysfs
+# define __NR_sysfs 136
+# endif
+# ifndef __NR_getpriority
+# define __NR_getpriority 137
+# endif
+# ifndef __NR_setpriority
+# define __NR_setpriority 138
+# endif
+# ifndef __NR_sched_setparam
+# define __NR_sched_setparam 139
+# endif
+# ifndef __NR_sched_getparam
+# define __NR_sched_getparam 140
+# endif
+# ifndef __NR_sched_setscheduler
+# define __NR_sched_setscheduler 141
+# endif
+# ifndef __NR_sched_getscheduler
+# define __NR_sched_getscheduler 142
+# endif
+# ifndef __NR_sched_get_priority_max
+# define __NR_sched_get_priority_max 143
+# endif
+# ifndef __NR_sched_get_priority_min
+# define __NR_sched_get_priority_min 144
+# endif
+# ifndef __NR_sched_rr_get_interval
+# define __NR_sched_rr_get_interval 145
+# endif
+# ifndef __NR_mlock
+# define __NR_mlock 146
+# endif
+# ifndef __NR_munlock
+# define __NR_munlock 147
+# endif
+# ifndef __NR_mlockall
+# define __NR_mlockall 148
+# endif
+# ifndef __NR_munlockall
+# define __NR_munlockall 149
+# endif
+# ifndef __NR_vhangup
+# define __NR_vhangup 150
+# endif
+# ifndef __NR_pivot_root
+# define __NR_pivot_root 151
+# endif
+# ifndef __NR__sysctl
+# define __NR__sysctl 152
+# endif
+# ifndef __NR_prctl
+# define __NR_prctl 153
+# endif
+# ifndef __NR_adjtimex
+# define __NR_adjtimex 154
+# endif
+# ifndef __NR_setrlimit
+# define __NR_setrlimit 155
+# endif
+# ifndef __NR_chroot
+# define __NR_chroot 156
+# endif
+# ifndef __NR_sync
+# define __NR_sync 157
+# endif
+# ifndef __NR_acct
+# define __NR_acct 158
+# endif
+# ifndef __NR_settimeofday
+# define __NR_settimeofday 159
+# endif
+# ifndef __NR_mount
+# define __NR_mount 160
+# endif
+# ifndef __NR_umount2
+# define __NR_umount2 161
+# endif
+# ifndef __NR_swapon
+# define __NR_swapon 162
+# endif
+# ifndef __NR_swapoff
+# define __NR_swapoff 163
+# endif
+# ifndef __NR_reboot
+# define __NR_reboot 164
+# endif
+# ifndef __NR_sethostname
+# define __NR_sethostname 165
+# endif
+# ifndef __NR_setdomainname
+# define __NR_setdomainname 166
+# endif
+# ifndef __NR_create_module
+# define __NR_create_module 167
+# endif
+# ifndef __NR_init_module
+# define __NR_init_module 168
+# endif
+# ifndef __NR_delete_module
+# define __NR_delete_module 169
+# endif
+# ifndef __NR_get_kernel_syms
+# define __NR_get_kernel_syms 170
+# endif
+# ifndef __NR_query_module
+# define __NR_query_module 171
+# endif
+# ifndef __NR_quotactl
+# define __NR_quotactl 172
+# endif
+# ifndef __NR_nfsservctl
+# define __NR_nfsservctl 173
+# endif
+# ifndef __NR_getpmsg
+# define __NR_getpmsg 174
+# endif
+# ifndef __NR_putpmsg
+# define __NR_putpmsg 175
+# endif
+# ifndef __NR_afs_syscall
+# define __NR_afs_syscall 176
+# endif
+# ifndef __NR_reserved177
+# define __NR_reserved177 177
+# endif
+# ifndef __NR_gettid
+# define __NR_gettid 178
+# endif
+# ifndef __NR_readahead
+# define __NR_readahead 179
+# endif
+# ifndef __NR_setxattr
+# define __NR_setxattr 180
+# endif
+# ifndef __NR_lsetxattr
+# define __NR_lsetxattr 181
+# endif
+# ifndef __NR_fsetxattr
+# define __NR_fsetxattr 182
+# endif
+# ifndef __NR_getxattr
+# define __NR_getxattr 183
+# endif
+# ifndef __NR_lgetxattr
+# define __NR_lgetxattr 184
+# endif
+# ifndef __NR_fgetxattr
+# define __NR_fgetxattr 185
+# endif
+# ifndef __NR_listxattr
+# define __NR_listxattr 186
+# endif
+# ifndef __NR_llistxattr
+# define __NR_llistxattr 187
+# endif
+# ifndef __NR_flistxattr
+# define __NR_flistxattr 188
+# endif
+# ifndef __NR_removexattr
+# define __NR_removexattr 189
+# endif
+# ifndef __NR_lremovexattr
+# define __NR_lremovexattr 190
+# endif
+# ifndef __NR_fremovexattr
+# define __NR_fremovexattr 191
+# endif
+# ifndef __NR_tkill
+# define __NR_tkill 192
+# endif
+# ifndef __NR_reserved193
+# define __NR_reserved193 193
+# endif
+# ifndef __NR_futex
+# define __NR_futex 194
+# endif
+# ifndef __NR_sched_setaffinity
+# define __NR_sched_setaffinity 195
+# endif
+# ifndef __NR_sched_getaffinity
+# define __NR_sched_getaffinity 196
+# endif
+# ifndef __NR_cacheflush
+# define __NR_cacheflush 197
+# endif
+# ifndef __NR_cachectl
+# define __NR_cachectl 198
+# endif
+# ifndef __NR_sysmips
+# define __NR_sysmips 199
+# endif
+# ifndef __NR_io_setup
+# define __NR_io_setup 200
+# endif
+# ifndef __NR_io_destroy
+# define __NR_io_destroy 201
+# endif
+# ifndef __NR_io_getevents
+# define __NR_io_getevents 202
+# endif
+# ifndef __NR_io_submit
+# define __NR_io_submit 203
+# endif
+# ifndef __NR_io_cancel
+# define __NR_io_cancel 204
+# endif
+# ifndef __NR_exit_group
+# define __NR_exit_group 205
+# endif
+# ifndef __NR_lookup_dcookie
+# define __NR_lookup_dcookie 206
+# endif
+# ifndef __NR_epoll_create
+# define __NR_epoll_create 207
+# endif
+# ifndef __NR_epoll_ctl
+# define __NR_epoll_ctl 208
+# endif
+# ifndef __NR_epoll_wait
+# define __NR_epoll_wait 209
+# endif
+# ifndef __NR_remap_file_pages
+# define __NR_remap_file_pages 210
+# endif
+# ifndef __NR_rt_sigreturn
+# define __NR_rt_sigreturn 211
+# endif
+# ifndef __NR_set_tid_address
+# define __NR_set_tid_address 212
+# endif
+# ifndef __NR_restart_syscall
+# define __NR_restart_syscall 213
+# endif
+# ifndef __NR_semtimedop
+# define __NR_semtimedop 214
+# endif
+# ifndef __NR_fadvise64
+# define __NR_fadvise64 215
+# endif
+# ifndef __NR_timer_create
+# define __NR_timer_create 216
+# endif
+# ifndef __NR_timer_settime
+# define __NR_timer_settime 217
+# endif
+# ifndef __NR_timer_gettime
+# define __NR_timer_gettime 218
+# endif
+# ifndef __NR_timer_getoverrun
+# define __NR_timer_getoverrun 219
+# endif
+# ifndef __NR_timer_delete
+# define __NR_timer_delete 220
+# endif
+# ifndef __NR_clock_settime
+# define __NR_clock_settime 221
+# endif
+# ifndef __NR_clock_gettime
+# define __NR_clock_gettime 222
+# endif
+# ifndef __NR_clock_getres
+# define __NR_clock_getres 223
+# endif
+# ifndef __NR_clock_nanosleep
+# define __NR_clock_nanosleep 224
+# endif
+# ifndef __NR_tgkill
+# define __NR_tgkill 225
+# endif
+# ifndef __NR_utimes
+# define __NR_utimes 226
+# endif
+# ifndef __NR_mbind
+# define __NR_mbind 227
+# endif
+# ifndef __NR_get_mempolicy
+# define __NR_get_mempolicy 228
+# endif
+# ifndef __NR_set_mempolicy
+# define __NR_set_mempolicy 229
+# endif
+# ifndef __NR_mq_open
+# define __NR_mq_open 230
+# endif
+# ifndef __NR_mq_unlink
+# define __NR_mq_unlink 231
+# endif
+# ifndef __NR_mq_timedsend
+# define __NR_mq_timedsend 232
+# endif
+# ifndef __NR_mq_timedreceive
+# define __NR_mq_timedreceive 233
+# endif
+# ifndef __NR_mq_notify
+# define __NR_mq_notify 234
+# endif
+# ifndef __NR_mq_getsetattr
+# define __NR_mq_getsetattr 235
+# endif
+# ifndef __NR_vserver
+# define __NR_vserver 236
+# endif
+# ifndef __NR_waitid
+# define __NR_waitid 237
+# endif
+# ifndef __NR_add_key
+# define __NR_add_key 239
+# endif
+# ifndef __NR_request_key
+# define __NR_request_key 240
+# endif
+# ifndef __NR_keyctl
+# define __NR_keyctl 241
+# endif
+# ifndef __NR_set_thread_area
+# define __NR_set_thread_area 242
+# endif
+# ifndef __NR_inotify_init
+# define __NR_inotify_init 243
+# endif
+# ifndef __NR_inotify_add_watch
+# define __NR_inotify_add_watch 244
+# endif
+# ifndef __NR_inotify_rm_watch
+# define __NR_inotify_rm_watch 245
+# endif
+# ifndef __NR_migrate_pages
+# define __NR_migrate_pages 246
+# endif
+# ifndef __NR_openat
+# define __NR_openat 247
+# endif
+# ifndef __NR_mkdirat
+# define __NR_mkdirat 248
+# endif
+# ifndef __NR_mknodat
+# define __NR_mknodat 249
+# endif
+# ifndef __NR_fchownat
+# define __NR_fchownat 250
+# endif
+# ifndef __NR_futimesat
+# define __NR_futimesat 251
+# endif
+# ifndef __NR_newfstatat
+# define __NR_newfstatat 252
+# endif
+# ifndef __NR_unlinkat
+# define __NR_unlinkat 253
+# endif
+# ifndef __NR_renameat
+# define __NR_renameat 254
+# endif
+# ifndef __NR_linkat
+# define __NR_linkat 255
+# endif
+# ifndef __NR_symlinkat
+# define __NR_symlinkat 256
+# endif
+# ifndef __NR_readlinkat
+# define __NR_readlinkat 257
+# endif
+# ifndef __NR_fchmodat
+# define __NR_fchmodat 258
+# endif
+# ifndef __NR_faccessat
+# define __NR_faccessat 259
+# endif
+# ifndef __NR_pselect6
+# define __NR_pselect6 260
+# endif
+# ifndef __NR_ppoll
+# define __NR_ppoll 261
+# endif
+# ifndef __NR_unshare
+# define __NR_unshare 262
+# endif
+# ifndef __NR_splice
+# define __NR_splice 263
+# endif
+# ifndef __NR_sync_file_range
+# define __NR_sync_file_range 264
+# endif
+# ifndef __NR_tee
+# define __NR_tee 265
+# endif
+# ifndef __NR_vmsplice
+# define __NR_vmsplice 266
+# endif
+# ifndef __NR_move_pages
+# define __NR_move_pages 267
+# endif
+# ifndef __NR_set_robust_list
+# define __NR_set_robust_list 268
+# endif
+# ifndef __NR_get_robust_list
+# define __NR_get_robust_list 269
+# endif
+# ifndef __NR_kexec_load
+# define __NR_kexec_load 270
+# endif
+# ifndef __NR_getcpu
+# define __NR_getcpu 271
+# endif
+# ifndef __NR_epoll_pwait
+# define __NR_epoll_pwait 272
+# endif
+# ifndef __NR_ioprio_set
+# define __NR_ioprio_set 273
+# endif
+# ifndef __NR_ioprio_get
+# define __NR_ioprio_get 274
+# endif
+# ifndef __NR_utimensat
+# define __NR_utimensat 275
+# endif
+# ifndef __NR_signalfd
+# define __NR_signalfd 276
+# endif
+# ifndef __NR_timerfd
+# define __NR_timerfd 277
+# endif
+# ifndef __NR_eventfd
+# define __NR_eventfd 278
+# endif
+# ifndef __NR_fallocate
+# define __NR_fallocate 279
+# endif
+# ifndef __NR_timerfd_create
+# define __NR_timerfd_create 280
+# endif
+# ifndef __NR_timerfd_gettime
+# define __NR_timerfd_gettime 281
+# endif
+# ifndef __NR_timerfd_settime
+# define __NR_timerfd_settime 282
+# endif
+# ifndef __NR_signalfd4
+# define __NR_signalfd4 283
+# endif
+# ifndef __NR_eventfd2
+# define __NR_eventfd2 284
+# endif
+# ifndef __NR_epoll_create1
+# define __NR_epoll_create1 285
+# endif
+# ifndef __NR_dup3
+# define __NR_dup3 286
+# endif
+# ifndef __NR_pipe2
+# define __NR_pipe2 287
+# endif
+# ifndef __NR_inotify_init1
+# define __NR_inotify_init1 288
+# endif
+# ifndef __NR_preadv
+# define __NR_preadv 289
+# endif
+# ifndef __NR_pwritev
+# define __NR_pwritev 290
+# endif
+# ifndef __NR_rt_tgsigqueueinfo
+# define __NR_rt_tgsigqueueinfo 291
+# endif
+# ifndef __NR_perf_event_open
+# define __NR_perf_event_open 292
+# endif
+# ifndef __NR_accept4
+# define __NR_accept4 293
+# endif
+# ifndef __NR_recvmmsg
+# define __NR_recvmmsg 294
+# endif
+# ifndef __NR_fanotify_init
+# define __NR_fanotify_init 295
+# endif
+# ifndef __NR_fanotify_mark
+# define __NR_fanotify_mark 296
+# endif
+# ifndef __NR_prlimit64
+# define __NR_prlimit64 297
+# endif
+# ifndef __NR_name_to_handle_at
+# define __NR_name_to_handle_at 298
+# endif
+# ifndef __NR_open_by_handle_at
+# define __NR_open_by_handle_at 299
+# endif
+# ifndef __NR_clock_adjtime
+# define __NR_clock_adjtime 300
+# endif
+# ifndef __NR_syncfs
+# define __NR_syncfs 301
+# endif
+# ifndef __NR_sendmmsg
+# define __NR_sendmmsg 302
+# endif
+# ifndef __NR_setns
+# define __NR_setns 303
+# endif
+# ifndef __NR_process_vm_readv
+# define __NR_process_vm_readv 304
+# endif
+# ifndef __NR_process_vm_writev
+# define __NR_process_vm_writev 305
+# endif
+# ifndef __NR_kcmp
+# define __NR_kcmp 306
+# endif
+# ifndef __NR_finit_module
+# define __NR_finit_module 307
+# endif
+# ifndef __NR_getdents64
+# define __NR_getdents64 308
+# endif
+# ifndef __NR_sched_setattr
+# define __NR_sched_setattr 309
+# endif
+# ifndef __NR_sched_getattr
+# define __NR_sched_getattr 310
+# endif
+# ifndef __NR_renameat2
+# define __NR_renameat2 311
+# endif
+# ifndef __NR_seccomp
+# define __NR_seccomp 312
+# endif
+# ifndef __NR_getrandom
+# define __NR_getrandom 313
+# endif
+# ifndef __NR_memfd_create
+# define __NR_memfd_create 314
+# endif
+# ifndef __NR_bpf
+# define __NR_bpf 315
+# endif
+# ifndef __NR_execveat
+# define __NR_execveat 316
+# endif
+# ifndef __NR_userfaultfd
+# define __NR_userfaultfd 317
+# endif
+# ifndef __NR_membarrier
+# define __NR_membarrier 318
+# endif
+# ifndef __NR_mlock2
+# define __NR_mlock2 319
+# endif
+# ifndef __NR_copy_file_range
+# define __NR_copy_file_range 320
+# endif
+# ifndef __NR_preadv2
+# define __NR_preadv2 321
+# endif
+# ifndef __NR_pwritev2
+# define __NR_pwritev2 322
+# endif
+# ifndef __NR_pkey_mprotect
+# define __NR_pkey_mprotect 323
+# endif
+# ifndef __NR_pkey_alloc
+# define __NR_pkey_alloc 324
+# endif
+# ifndef __NR_pkey_free
+# define __NR_pkey_free 325
+# endif
+# ifndef __NR_statx
+# define __NR_statx 326
+# endif
+# ifndef __NR_rseq
+# define __NR_rseq 327
+# endif
+# ifndef __NR_io_pgetevents
+# define __NR_io_pgetevents 328
+# endif
+# ifndef __NR_pidfd_send_signal
+# define __NR_pidfd_send_signal 424
+# endif
+# ifndef __NR_io_uring_setup
+# define __NR_io_uring_setup 425
+# endif
+# ifndef __NR_io_uring_enter
+# define __NR_io_uring_enter 426
+# endif
+# ifndef __NR_io_uring_register
+# define __NR_io_uring_register 427
+# endif
+# ifndef __NR_open_tree
+# define __NR_open_tree 428
+# endif
+# ifndef __NR_move_mount
+# define __NR_move_mount 429
+# endif
+# ifndef __NR_fsopen
+# define __NR_fsopen 430
+# endif
+# ifndef __NR_fsconfig
+# define __NR_fsconfig 431
+# endif
+# ifndef __NR_fsmount
+# define __NR_fsmount 432
+# endif
+# ifndef __NR_fspick
+# define __NR_fspick 433
+# endif
+# ifndef __NR_pidfd_open
+# define __NR_pidfd_open 434
+# endif
+# ifndef __NR_clone3
+# define __NR_clone3 435
+# endif
+# ifndef __NR_openat2
+# define __NR_openat2 437
+# endif
+# ifndef __NR_pidfd_getfd
+# define __NR_pidfd_getfd 438
+# endif
+#endif
+
+
+#if defined(__mips__) && defined(_ABIO32)
+# ifndef __NR_syscall
+# define __NR_syscall 0
+# endif
+# ifndef __NR_exit
+# define __NR_exit 1
+# endif
+# ifndef __NR_fork
+# define __NR_fork 2
+# endif
+# ifndef __NR_read
+# define __NR_read 3
+# endif
+# ifndef __NR_write
+# define __NR_write 4
+# endif
+# ifndef __NR_open
+# define __NR_open 5
+# endif
+# ifndef __NR_close
+# define __NR_close 6
+# endif
+# ifndef __NR_waitpid
+# define __NR_waitpid 7
+# endif
+# ifndef __NR_creat
+# define __NR_creat 8
+# endif
+# ifndef __NR_link
+# define __NR_link 9
+# endif
+# ifndef __NR_unlink
+# define __NR_unlink 10
+# endif
+# ifndef __NR_execve
+# define __NR_execve 11
+# endif
+# ifndef __NR_chdir
+# define __NR_chdir 12
+# endif
+# ifndef __NR_time
+# define __NR_time 13
+# endif
+# ifndef __NR_mknod
+# define __NR_mknod 14
+# endif
+# ifndef __NR_chmod
+# define __NR_chmod 15
+# endif
+# ifndef __NR_lchown
+# define __NR_lchown 16
+# endif
+# ifndef __NR_break
+# define __NR_break 17
+# endif
+# ifndef __NR_unused18
+# define __NR_unused18 18
+# endif
+# ifndef __NR_lseek
+# define __NR_lseek 19
+# endif
+# ifndef __NR_getpid
+# define __NR_getpid 20
+# endif
+# ifndef __NR_mount
+# define __NR_mount 21
+# endif
+# ifndef __NR_umount
+# define __NR_umount 22
+# endif
+# ifndef __NR_setuid
+# define __NR_setuid 23
+# endif
+# ifndef __NR_getuid
+# define __NR_getuid 24
+# endif
+# ifndef __NR_stime
+# define __NR_stime 25
+# endif
+# ifndef __NR_ptrace
+# define __NR_ptrace 26
+# endif
+# ifndef __NR_alarm
+# define __NR_alarm 27
+# endif
+# ifndef __NR_unused28
+# define __NR_unused28 28
+# endif
+# ifndef __NR_pause
+# define __NR_pause 29
+# endif
+# ifndef __NR_utime
+# define __NR_utime 30
+# endif
+# ifndef __NR_stty
+# define __NR_stty 31
+# endif
+# ifndef __NR_gtty
+# define __NR_gtty 32
+# endif
+# ifndef __NR_access
+# define __NR_access 33
+# endif
+# ifndef __NR_nice
+# define __NR_nice 34
+# endif
+# ifndef __NR_ftime
+# define __NR_ftime 35
+# endif
+# ifndef __NR_sync
+# define __NR_sync 36
+# endif
+# ifndef __NR_kill
+# define __NR_kill 37
+# endif
+# ifndef __NR_rename
+# define __NR_rename 38
+# endif
+# ifndef __NR_mkdir
+# define __NR_mkdir 39
+# endif
+# ifndef __NR_rmdir
+# define __NR_rmdir 40
+# endif
+# ifndef __NR_dup
+# define __NR_dup 41
+# endif
+# ifndef __NR_pipe
+# define __NR_pipe 42
+# endif
+# ifndef __NR_times
+# define __NR_times 43
+# endif
+# ifndef __NR_prof
+# define __NR_prof 44
+# endif
+# ifndef __NR_brk
+# define __NR_brk 45
+# endif
+# ifndef __NR_setgid
+# define __NR_setgid 46
+# endif
+# ifndef __NR_getgid
+# define __NR_getgid 47
+# endif
+# ifndef __NR_signal
+# define __NR_signal 48
+# endif
+# ifndef __NR_geteuid
+# define __NR_geteuid 49
+# endif
+# ifndef __NR_getegid
+# define __NR_getegid 50
+# endif
+# ifndef __NR_acct
+# define __NR_acct 51
+# endif
+# ifndef __NR_umount2
+# define __NR_umount2 52
+# endif
+# ifndef __NR_lock
+# define __NR_lock 53
+# endif
+# ifndef __NR_ioctl
+# define __NR_ioctl 54
+# endif
+# ifndef __NR_fcntl
+# define __NR_fcntl 55
+# endif
+# ifndef __NR_mpx
+# define __NR_mpx 56
+# endif
+# ifndef __NR_setpgid
+# define __NR_setpgid 57
+# endif
+# ifndef __NR_ulimit
+# define __NR_ulimit 58
+# endif
+# ifndef __NR_unused59
+# define __NR_unused59 59
+# endif
+# ifndef __NR_umask
+# define __NR_umask 60
+# endif
+# ifndef __NR_chroot
+# define __NR_chroot 61
+# endif
+# ifndef __NR_ustat
+# define __NR_ustat 62
+# endif
+# ifndef __NR_dup2
+# define __NR_dup2 63
+# endif
+# ifndef __NR_getppid
+# define __NR_getppid 64
+# endif
+# ifndef __NR_getpgrp
+# define __NR_getpgrp 65
+# endif
+# ifndef __NR_setsid
+# define __NR_setsid 66
+# endif
+# ifndef __NR_sigaction
+# define __NR_sigaction 67
+# endif
+# ifndef __NR_sgetmask
+# define __NR_sgetmask 68
+# endif
+# ifndef __NR_ssetmask
+# define __NR_ssetmask 69
+# endif
+# ifndef __NR_setreuid
+# define __NR_setreuid 70
+# endif
+# ifndef __NR_setregid
+# define __NR_setregid 71
+# endif
+# ifndef __NR_sigsuspend
+# define __NR_sigsuspend 72
+# endif
+# ifndef __NR_sigpending
+# define __NR_sigpending 73
+# endif
+# ifndef __NR_sethostname
+# define __NR_sethostname 74
+# endif
+# ifndef __NR_setrlimit
+# define __NR_setrlimit 75
+# endif
+# ifndef __NR_getrlimit
+# define __NR_getrlimit 76
+# endif
+# ifndef __NR_getrusage
+# define __NR_getrusage 77
+# endif
+# ifndef __NR_gettimeofday
+# define __NR_gettimeofday 78
+# endif
+# ifndef __NR_settimeofday
+# define __NR_settimeofday 79
+# endif
+# ifndef __NR_getgroups
+# define __NR_getgroups 80
+# endif
+# ifndef __NR_setgroups
+# define __NR_setgroups 81
+# endif
+# ifndef __NR_reserved82
+# define __NR_reserved82 82
+# endif
+# ifndef __NR_symlink
+# define __NR_symlink 83
+# endif
+# ifndef __NR_unused84
+# define __NR_unused84 84
+# endif
+# ifndef __NR_readlink
+# define __NR_readlink 85
+# endif
+# ifndef __NR_uselib
+# define __NR_uselib 86
+# endif
+# ifndef __NR_swapon
+# define __NR_swapon 87
+# endif
+# ifndef __NR_reboot
+# define __NR_reboot 88
+# endif
+# ifndef __NR_readdir
+# define __NR_readdir 89
+# endif
+# ifndef __NR_mmap
+# define __NR_mmap 90
+# endif
+# ifndef __NR_munmap
+# define __NR_munmap 91
+# endif
+# ifndef __NR_truncate
+# define __NR_truncate 92
+# endif
+# ifndef __NR_ftruncate
+# define __NR_ftruncate 93
+# endif
+# ifndef __NR_fchmod
+# define __NR_fchmod 94
+# endif
+# ifndef __NR_fchown
+# define __NR_fchown 95
+# endif
+# ifndef __NR_getpriority
+# define __NR_getpriority 96
+# endif
+# ifndef __NR_setpriority
+# define __NR_setpriority 97
+# endif
+# ifndef __NR_profil
+# define __NR_profil 98
+# endif
+# ifndef __NR_statfs
+# define __NR_statfs 99
+# endif
+# ifndef __NR_fstatfs
+# define __NR_fstatfs 100
+# endif
+# ifndef __NR_ioperm
+# define __NR_ioperm 101
+# endif
+# ifndef __NR_socketcall
+# define __NR_socketcall 102
+# endif
+# ifndef __NR_syslog
+# define __NR_syslog 103
+# endif
+# ifndef __NR_setitimer
+# define __NR_setitimer 104
+# endif
+# ifndef __NR_getitimer
+# define __NR_getitimer 105
+# endif
+# ifndef __NR_stat
+# define __NR_stat 106
+# endif
+# ifndef __NR_lstat
+# define __NR_lstat 107
+# endif
+# ifndef __NR_fstat
+# define __NR_fstat 108
+# endif
+# ifndef __NR_unused109
+# define __NR_unused109 109
+# endif
+# ifndef __NR_iopl
+# define __NR_iopl 110
+# endif
+# ifndef __NR_vhangup
+# define __NR_vhangup 111
+# endif
+# ifndef __NR_idle
+# define __NR_idle 112
+# endif
+# ifndef __NR_vm86
+# define __NR_vm86 113
+# endif
+# ifndef __NR_wait4
+# define __NR_wait4 114
+# endif
+# ifndef __NR_swapoff
+# define __NR_swapoff 115
+# endif
+# ifndef __NR_sysinfo
+# define __NR_sysinfo 116
+# endif
+# ifndef __NR_ipc
+# define __NR_ipc 117
+# endif
+# ifndef __NR_fsync
+# define __NR_fsync 118
+# endif
+# ifndef __NR_sigreturn
+# define __NR_sigreturn 119
+# endif
+# ifndef __NR_clone
+# define __NR_clone 120
+# endif
+# ifndef __NR_setdomainname
+# define __NR_setdomainname 121
+# endif
+# ifndef __NR_uname
+# define __NR_uname 122
+# endif
+# ifndef __NR_modify_ldt
+# define __NR_modify_ldt 123
+# endif
+# ifndef __NR_adjtimex
+# define __NR_adjtimex 124
+# endif
+# ifndef __NR_mprotect
+# define __NR_mprotect 125
+# endif
+# ifndef __NR_sigprocmask
+# define __NR_sigprocmask 126
+# endif
+# ifndef __NR_create_module
+# define __NR_create_module 127
+# endif
+# ifndef __NR_init_module
+# define __NR_init_module 128
+# endif
+# ifndef __NR_delete_module
+# define __NR_delete_module 129
+# endif
+# ifndef __NR_get_kernel_syms
+# define __NR_get_kernel_syms 130
+# endif
+# ifndef __NR_quotactl
+# define __NR_quotactl 131
+# endif
+# ifndef __NR_getpgid
+# define __NR_getpgid 132
+# endif
+# ifndef __NR_fchdir
+# define __NR_fchdir 133
+# endif
+# ifndef __NR_bdflush
+# define __NR_bdflush 134
+# endif
+# ifndef __NR_sysfs
+# define __NR_sysfs 135
+# endif
+# ifndef __NR_personality
+# define __NR_personality 136
+# endif
+# ifndef __NR_afs_syscall
+# define __NR_afs_syscall 137
+# endif
+# ifndef __NR_setfsuid
+# define __NR_setfsuid 138
+# endif
+# ifndef __NR_setfsgid
+# define __NR_setfsgid 139
+# endif
+# ifndef __NR__llseek
+# define __NR__llseek 140
+# endif
+# ifndef __NR_getdents
+# define __NR_getdents 141
+# endif
+# ifndef __NR__newselect
+# define __NR__newselect 142
+# endif
+# ifndef __NR_flock
+# define __NR_flock 143
+# endif
+# ifndef __NR_msync
+# define __NR_msync 144
+# endif
+# ifndef __NR_readv
+# define __NR_readv 145
+# endif
+# ifndef __NR_writev
+# define __NR_writev 146
+# endif
+# ifndef __NR_cacheflush
+# define __NR_cacheflush 147
+# endif
+# ifndef __NR_cachectl
+# define __NR_cachectl 148
+# endif
+# ifndef __NR_sysmips
+# define __NR_sysmips 149
+# endif
+# ifndef __NR_unused150
+# define __NR_unused150 150
+# endif
+# ifndef __NR_getsid
+# define __NR_getsid 151
+# endif
+# ifndef __NR_fdatasync
+# define __NR_fdatasync 152
+# endif
+# ifndef __NR__sysctl
+# define __NR__sysctl 153
+# endif
+# ifndef __NR_mlock
+# define __NR_mlock 154
+# endif
+# ifndef __NR_munlock
+# define __NR_munlock 155
+# endif
+# ifndef __NR_mlockall
+# define __NR_mlockall 156
+# endif
+# ifndef __NR_munlockall
+# define __NR_munlockall 157
+# endif
+# ifndef __NR_sched_setparam
+# define __NR_sched_setparam 158
+# endif
+# ifndef __NR_sched_getparam
+# define __NR_sched_getparam 159
+# endif
+# ifndef __NR_sched_setscheduler
+# define __NR_sched_setscheduler 160
+# endif
+# ifndef __NR_sched_getscheduler
+# define __NR_sched_getscheduler 161
+# endif
+# ifndef __NR_sched_yield
+# define __NR_sched_yield 162
+# endif
+# ifndef __NR_sched_get_priority_max
+# define __NR_sched_get_priority_max 163
+# endif
+# ifndef __NR_sched_get_priority_min
+# define __NR_sched_get_priority_min 164
+# endif
+# ifndef __NR_sched_rr_get_interval
+# define __NR_sched_rr_get_interval 165
+# endif
+# ifndef __NR_nanosleep
+# define __NR_nanosleep 166
+# endif
+# ifndef __NR_mremap
+# define __NR_mremap 167
+# endif
+# ifndef __NR_accept
+# define __NR_accept 168
+# endif
+# ifndef __NR_bind
+# define __NR_bind 169
+# endif
+# ifndef __NR_connect
+# define __NR_connect 170
+# endif
+# ifndef __NR_getpeername
+# define __NR_getpeername 171
+# endif
+# ifndef __NR_getsockname
+# define __NR_getsockname 172
+# endif
+# ifndef __NR_getsockopt
+# define __NR_getsockopt 173
+# endif
+# ifndef __NR_listen
+# define __NR_listen 174
+# endif
+# ifndef __NR_recv
+# define __NR_recv 175
+# endif
+# ifndef __NR_recvfrom
+# define __NR_recvfrom 176
+# endif
+# ifndef __NR_recvmsg
+# define __NR_recvmsg 177
+# endif
+# ifndef __NR_send
+# define __NR_send 178
+# endif
+# ifndef __NR_sendmsg
+# define __NR_sendmsg 179
+# endif
+# ifndef __NR_sendto
+# define __NR_sendto 180
+# endif
+# ifndef __NR_setsockopt
+# define __NR_setsockopt 181
+# endif
+# ifndef __NR_shutdown
+# define __NR_shutdown 182
+# endif
+# ifndef __NR_socket
+# define __NR_socket 183
+# endif
+# ifndef __NR_socketpair
+# define __NR_socketpair 184
+# endif
+# ifndef __NR_setresuid
+# define __NR_setresuid 185
+# endif
+# ifndef __NR_getresuid
+# define __NR_getresuid 186
+# endif
+# ifndef __NR_query_module
+# define __NR_query_module 187
+# endif
+# ifndef __NR_poll
+# define __NR_poll 188
+# endif
+# ifndef __NR_nfsservctl
+# define __NR_nfsservctl 189
+# endif
+# ifndef __NR_setresgid
+# define __NR_setresgid 190
+# endif
+# ifndef __NR_getresgid
+# define __NR_getresgid 191
+# endif
+# ifndef __NR_prctl
+# define __NR_prctl 192
+# endif
+# ifndef __NR_rt_sigreturn
+# define __NR_rt_sigreturn 193
+# endif
+# ifndef __NR_rt_sigaction
+# define __NR_rt_sigaction 194
+# endif
+# ifndef __NR_rt_sigprocmask
+# define __NR_rt_sigprocmask 195
+# endif
+# ifndef __NR_rt_sigpending
+# define __NR_rt_sigpending 196
+# endif
+# ifndef __NR_rt_sigtimedwait
+# define __NR_rt_sigtimedwait 197
+# endif
+# ifndef __NR_rt_sigqueueinfo
+# define __NR_rt_sigqueueinfo 198
+# endif
+# ifndef __NR_rt_sigsuspend
+# define __NR_rt_sigsuspend 199
+# endif
+# ifndef __NR_pread64
+# define __NR_pread64 200
+# endif
+# ifndef __NR_pwrite64
+# define __NR_pwrite64 201
+# endif
+# ifndef __NR_chown
+# define __NR_chown 202
+# endif
+# ifndef __NR_getcwd
+# define __NR_getcwd 203
+# endif
+# ifndef __NR_capget
+# define __NR_capget 204
+# endif
+# ifndef __NR_capset
+# define __NR_capset 205
+# endif
+# ifndef __NR_sigaltstack
+# define __NR_sigaltstack 206
+# endif
+# ifndef __NR_sendfile
+# define __NR_sendfile 207
+# endif
+# ifndef __NR_getpmsg
+# define __NR_getpmsg 208
+# endif
+# ifndef __NR_putpmsg
+# define __NR_putpmsg 209
+# endif
+# ifndef __NR_mmap2
+# define __NR_mmap2 210
+# endif
+# ifndef __NR_truncate64
+# define __NR_truncate64 211
+# endif
+# ifndef __NR_ftruncate64
+# define __NR_ftruncate64 212
+# endif
+# ifndef __NR_stat64
+# define __NR_stat64 213
+# endif
+# ifndef __NR_lstat64
+# define __NR_lstat64 214
+# endif
+# ifndef __NR_fstat64
+# define __NR_fstat64 215
+# endif
+# ifndef __NR_pivot_root
+# define __NR_pivot_root 216
+# endif
+# ifndef __NR_mincore
+# define __NR_mincore 217
+# endif
+# ifndef __NR_madvise
+# define __NR_madvise 218
+# endif
+# ifndef __NR_getdents64
+# define __NR_getdents64 219
+# endif
+# ifndef __NR_fcntl64
+# define __NR_fcntl64 220
+# endif
+# ifndef __NR_reserved221
+# define __NR_reserved221 221
+# endif
+# ifndef __NR_gettid
+# define __NR_gettid 222
+# endif
+# ifndef __NR_readahead
+# define __NR_readahead 223
+# endif
+# ifndef __NR_setxattr
+# define __NR_setxattr 224
+# endif
+# ifndef __NR_lsetxattr
+# define __NR_lsetxattr 225
+# endif
+# ifndef __NR_fsetxattr
+# define __NR_fsetxattr 226
+# endif
+# ifndef __NR_getxattr
+# define __NR_getxattr 227
+# endif
+# ifndef __NR_lgetxattr
+# define __NR_lgetxattr 228
+# endif
+# ifndef __NR_fgetxattr
+# define __NR_fgetxattr 229
+# endif
+# ifndef __NR_listxattr
+# define __NR_listxattr 230
+# endif
+# ifndef __NR_llistxattr
+# define __NR_llistxattr 231
+# endif
+# ifndef __NR_flistxattr
+# define __NR_flistxattr 232
+# endif
+# ifndef __NR_removexattr
+# define __NR_removexattr 233
+# endif
+# ifndef __NR_lremovexattr
+# define __NR_lremovexattr 234
+# endif
+# ifndef __NR_fremovexattr
+# define __NR_fremovexattr 235
+# endif
+# ifndef __NR_tkill
+# define __NR_tkill 236
+# endif
+# ifndef __NR_sendfile64
+# define __NR_sendfile64 237
+# endif
+# ifndef __NR_futex
+# define __NR_futex 238
+# endif
+# ifndef __NR_sched_setaffinity
+# define __NR_sched_setaffinity 239
+# endif
+# ifndef __NR_sched_getaffinity
+# define __NR_sched_getaffinity 240
+# endif
+# ifndef __NR_io_setup
+# define __NR_io_setup 241
+# endif
+# ifndef __NR_io_destroy
+# define __NR_io_destroy 242
+# endif
+# ifndef __NR_io_getevents
+# define __NR_io_getevents 243
+# endif
+# ifndef __NR_io_submit
+# define __NR_io_submit 244
+# endif
+# ifndef __NR_io_cancel
+# define __NR_io_cancel 245
+# endif
+# ifndef __NR_exit_group
+# define __NR_exit_group 246
+# endif
+# ifndef __NR_lookup_dcookie
+# define __NR_lookup_dcookie 247
+# endif
+# ifndef __NR_epoll_create
+# define __NR_epoll_create 248
+# endif
+# ifndef __NR_epoll_ctl
+# define __NR_epoll_ctl 249
+# endif
+# ifndef __NR_epoll_wait
+# define __NR_epoll_wait 250
+# endif
+# ifndef __NR_remap_file_pages
+# define __NR_remap_file_pages 251
+# endif
+# ifndef __NR_set_tid_address
+# define __NR_set_tid_address 252
+# endif
+# ifndef __NR_restart_syscall
+# define __NR_restart_syscall 253
+# endif
+# ifndef __NR_fadvise64
+# define __NR_fadvise64 254
+# endif
+# ifndef __NR_statfs64
+# define __NR_statfs64 255
+# endif
+# ifndef __NR_fstatfs64
+# define __NR_fstatfs64 256
+# endif
+# ifndef __NR_timer_create
+# define __NR_timer_create 257
+# endif
+# ifndef __NR_timer_settime
+# define __NR_timer_settime 258
+# endif
+# ifndef __NR_timer_gettime
+# define __NR_timer_gettime 259
+# endif
+# ifndef __NR_timer_getoverrun
+# define __NR_timer_getoverrun 260
+# endif
+# ifndef __NR_timer_delete
+# define __NR_timer_delete 261
+# endif
+# ifndef __NR_clock_settime
+# define __NR_clock_settime 262
+# endif
+# ifndef __NR_clock_gettime
+# define __NR_clock_gettime 263
+# endif
+# ifndef __NR_clock_getres
+# define __NR_clock_getres 264
+# endif
+# ifndef __NR_clock_nanosleep
+# define __NR_clock_nanosleep 265
+# endif
+# ifndef __NR_tgkill
+# define __NR_tgkill 266
+# endif
+# ifndef __NR_utimes
+# define __NR_utimes 267
+# endif
+# ifndef __NR_mbind
+# define __NR_mbind 268
+# endif
+# ifndef __NR_get_mempolicy
+# define __NR_get_mempolicy 269
+# endif
+# ifndef __NR_set_mempolicy
+# define __NR_set_mempolicy 270
+# endif
+# ifndef __NR_mq_open
+# define __NR_mq_open 271
+# endif
+# ifndef __NR_mq_unlink
+# define __NR_mq_unlink 272
+# endif
+# ifndef __NR_mq_timedsend
+# define __NR_mq_timedsend 273
+# endif
+# ifndef __NR_mq_timedreceive
+# define __NR_mq_timedreceive 274
+# endif
+# ifndef __NR_mq_notify
+# define __NR_mq_notify 275
+# endif
+# ifndef __NR_mq_getsetattr
+# define __NR_mq_getsetattr 276
+# endif
+# ifndef __NR_vserver
+# define __NR_vserver 277
+# endif
+# ifndef __NR_waitid
+# define __NR_waitid 278
+# endif
+# ifndef __NR_add_key
+# define __NR_add_key 280
+# endif
+# ifndef __NR_request_key
+# define __NR_request_key 281
+# endif
+# ifndef __NR_keyctl
+# define __NR_keyctl 282
+# endif
+# ifndef __NR_set_thread_area
+# define __NR_set_thread_area 283
+# endif
+# ifndef __NR_inotify_init
+# define __NR_inotify_init 284
+# endif
+# ifndef __NR_inotify_add_watch
+# define __NR_inotify_add_watch 285
+# endif
+# ifndef __NR_inotify_rm_watch
+# define __NR_inotify_rm_watch 286
+# endif
+# ifndef __NR_migrate_pages
+# define __NR_migrate_pages 287
+# endif
+# ifndef __NR_openat
+# define __NR_openat 288
+# endif
+# ifndef __NR_mkdirat
+# define __NR_mkdirat 289
+# endif
+# ifndef __NR_mknodat
+# define __NR_mknodat 290
+# endif
+# ifndef __NR_fchownat
+# define __NR_fchownat 291
+# endif
+# ifndef __NR_futimesat
+# define __NR_futimesat 292
+# endif
+# ifndef __NR_fstatat64
+# define __NR_fstatat64 293
+# endif
+# ifndef __NR_unlinkat
+# define __NR_unlinkat 294
+# endif
+# ifndef __NR_renameat
+# define __NR_renameat 295
+# endif
+# ifndef __NR_linkat
+# define __NR_linkat 296
+# endif
+# ifndef __NR_symlinkat
+# define __NR_symlinkat 297
+# endif
+# ifndef __NR_readlinkat
+# define __NR_readlinkat 298
+# endif
+# ifndef __NR_fchmodat
+# define __NR_fchmodat 299
+# endif
+# ifndef __NR_faccessat
+# define __NR_faccessat 300
+# endif
+# ifndef __NR_pselect6
+# define __NR_pselect6 301
+# endif
+# ifndef __NR_ppoll
+# define __NR_ppoll 302
+# endif
+# ifndef __NR_unshare
+# define __NR_unshare 303
+# endif
+# ifndef __NR_splice
+# define __NR_splice 304
+# endif
+# ifndef __NR_sync_file_range
+# define __NR_sync_file_range 305
+# endif
+# ifndef __NR_tee
+# define __NR_tee 306
+# endif
+# ifndef __NR_vmsplice
+# define __NR_vmsplice 307
+# endif
+# ifndef __NR_move_pages
+# define __NR_move_pages 308
+# endif
+# ifndef __NR_set_robust_list
+# define __NR_set_robust_list 309
+# endif
+# ifndef __NR_get_robust_list
+# define __NR_get_robust_list 310
+# endif
+# ifndef __NR_kexec_load
+# define __NR_kexec_load 311
+# endif
+# ifndef __NR_getcpu
+# define __NR_getcpu 312
+# endif
+# ifndef __NR_epoll_pwait
+# define __NR_epoll_pwait 313
+# endif
+# ifndef __NR_ioprio_set
+# define __NR_ioprio_set 314
+# endif
+# ifndef __NR_ioprio_get
+# define __NR_ioprio_get 315
+# endif
+# ifndef __NR_utimensat
+# define __NR_utimensat 316
+# endif
+# ifndef __NR_signalfd
+# define __NR_signalfd 317
+# endif
+# ifndef __NR_timerfd
+# define __NR_timerfd 318
+# endif
+# ifndef __NR_eventfd
+# define __NR_eventfd 319
+# endif
+# ifndef __NR_fallocate
+# define __NR_fallocate 320
+# endif
+# ifndef __NR_timerfd_create
+# define __NR_timerfd_create 321
+# endif
+# ifndef __NR_timerfd_gettime
+# define __NR_timerfd_gettime 322
+# endif
+# ifndef __NR_timerfd_settime
+# define __NR_timerfd_settime 323
+# endif
+# ifndef __NR_signalfd4
+# define __NR_signalfd4 324
+# endif
+# ifndef __NR_eventfd2
+# define __NR_eventfd2 325
+# endif
+# ifndef __NR_epoll_create1
+# define __NR_epoll_create1 326
+# endif
+# ifndef __NR_dup3
+# define __NR_dup3 327
+# endif
+# ifndef __NR_pipe2
+# define __NR_pipe2 328
+# endif
+# ifndef __NR_inotify_init1
+# define __NR_inotify_init1 329
+# endif
+# ifndef __NR_preadv
+# define __NR_preadv 330
+# endif
+# ifndef __NR_pwritev
+# define __NR_pwritev 331
+# endif
+# ifndef __NR_rt_tgsigqueueinfo
+# define __NR_rt_tgsigqueueinfo 332
+# endif
+# ifndef __NR_perf_event_open
+# define __NR_perf_event_open 333
+# endif
+# ifndef __NR_accept4
+# define __NR_accept4 334
+# endif
+# ifndef __NR_recvmmsg
+# define __NR_recvmmsg 335
+# endif
+# ifndef __NR_fanotify_init
+# define __NR_fanotify_init 336
+# endif
+# ifndef __NR_fanotify_mark
+# define __NR_fanotify_mark 337
+# endif
+# ifndef __NR_prlimit64
+# define __NR_prlimit64 338
+# endif
+# ifndef __NR_name_to_handle_at
+# define __NR_name_to_handle_at 339
+# endif
+# ifndef __NR_open_by_handle_at
+# define __NR_open_by_handle_at 340
+# endif
+# ifndef __NR_clock_adjtime
+# define __NR_clock_adjtime 341
+# endif
+# ifndef __NR_syncfs
+# define __NR_syncfs 342
+# endif
+# ifndef __NR_sendmmsg
+# define __NR_sendmmsg 343
+# endif
+# ifndef __NR_setns
+# define __NR_setns 344
+# endif
+# ifndef __NR_process_vm_readv
+# define __NR_process_vm_readv 345
+# endif
+# ifndef __NR_process_vm_writev
+# define __NR_process_vm_writev 346
+# endif
+# ifndef __NR_kcmp
+# define __NR_kcmp 347
+# endif
+# ifndef __NR_finit_module
+# define __NR_finit_module 348
+# endif
+# ifndef __NR_sched_setattr
+# define __NR_sched_setattr 349
+# endif
+# ifndef __NR_sched_getattr
+# define __NR_sched_getattr 350
+# endif
+# ifndef __NR_renameat2
+# define __NR_renameat2 351
+# endif
+# ifndef __NR_seccomp
+# define __NR_seccomp 352
+# endif
+# ifndef __NR_getrandom
+# define __NR_getrandom 353
+# endif
+# ifndef __NR_memfd_create
+# define __NR_memfd_create 354
+# endif
+# ifndef __NR_bpf
+# define __NR_bpf 355
+# endif
+# ifndef __NR_execveat
+# define __NR_execveat 356
+# endif
+# ifndef __NR_userfaultfd
+# define __NR_userfaultfd 357
+# endif
+# ifndef __NR_membarrier
+# define __NR_membarrier 358
+# endif
+# ifndef __NR_mlock2
+# define __NR_mlock2 359
+# endif
+# ifndef __NR_copy_file_range
+# define __NR_copy_file_range 360
+# endif
+# ifndef __NR_preadv2
+# define __NR_preadv2 361
+# endif
+# ifndef __NR_pwritev2
+# define __NR_pwritev2 362
+# endif
+# ifndef __NR_pkey_mprotect
+# define __NR_pkey_mprotect 363
+# endif
+# ifndef __NR_pkey_alloc
+# define __NR_pkey_alloc 364
+# endif
+# ifndef __NR_pkey_free
+# define __NR_pkey_free 365
+# endif
+# ifndef __NR_statx
+# define __NR_statx 366
+# endif
+# ifndef __NR_rseq
+# define __NR_rseq 367
+# endif
+# ifndef __NR_io_pgetevents
+# define __NR_io_pgetevents 368
+# endif
+# ifndef __NR_semget
+# define __NR_semget 393
+# endif
+# ifndef __NR_semctl
+# define __NR_semctl 394
+# endif
+# ifndef __NR_shmget
+# define __NR_shmget 395
+# endif
+# ifndef __NR_shmctl
+# define __NR_shmctl 396
+# endif
+# ifndef __NR_shmat
+# define __NR_shmat 397
+# endif
+# ifndef __NR_shmdt
+# define __NR_shmdt 398
+# endif
+# ifndef __NR_msgget
+# define __NR_msgget 399
+# endif
+# ifndef __NR_msgsnd
+# define __NR_msgsnd 400
+# endif
+# ifndef __NR_msgrcv
+# define __NR_msgrcv 401
+# endif
+# ifndef __NR_msgctl
+# define __NR_msgctl 402
+# endif
+# ifndef __NR_clock_gettime64
+# define __NR_clock_gettime64 403
+# endif
+# ifndef __NR_clock_settime64
+# define __NR_clock_settime64 404
+# endif
+# ifndef __NR_clock_adjtime64
+# define __NR_clock_adjtime64 405
+# endif
+# ifndef __NR_clock_getres_time64
+# define __NR_clock_getres_time64 406
+# endif
+# ifndef __NR_clock_nanosleep_time64
+# define __NR_clock_nanosleep_time64 407
+# endif
+# ifndef __NR_timer_gettime64
+# define __NR_timer_gettime64 408
+# endif
+# ifndef __NR_timer_settime64
+# define __NR_timer_settime64 409
+# endif
+# ifndef __NR_timerfd_gettime64
+# define __NR_timerfd_gettime64 410
+# endif
+# ifndef __NR_timerfd_settime64
+# define __NR_timerfd_settime64 411
+# endif
+# ifndef __NR_utimensat_time64
+# define __NR_utimensat_time64 412
+# endif
+# ifndef __NR_pselect6_time64
+# define __NR_pselect6_time64 413
+# endif
+# ifndef __NR_ppoll_time64
+# define __NR_ppoll_time64 414
+# endif
+# ifndef __NR_io_pgetevents_time64
+# define __NR_io_pgetevents_time64 416
+# endif
+# ifndef __NR_recvmmsg_time64
+# define __NR_recvmmsg_time64 417
+# endif
+# ifndef __NR_mq_timedsend_time64
+# define __NR_mq_timedsend_time64 418
+# endif
+# ifndef __NR_mq_timedreceive_time64
+# define __NR_mq_timedreceive_time64 419
+# endif
+# ifndef __NR_semtimedop_time64
+# define __NR_semtimedop_time64 420
+# endif
+# ifndef __NR_rt_sigtimedwait_time64
+# define __NR_rt_sigtimedwait_time64 421
+# endif
+# ifndef __NR_futex_time64
+# define __NR_futex_time64 422
+# endif
+# ifndef __NR_sched_rr_get_interval_time64
+# define __NR_sched_rr_get_interval_time64 423
+# endif
+# ifndef __NR_pidfd_send_signal
+# define __NR_pidfd_send_signal 424
+# endif
+# ifndef __NR_io_uring_setup
+# define __NR_io_uring_setup 425
+# endif
+# ifndef __NR_io_uring_enter
+# define __NR_io_uring_enter 426
+# endif
+# ifndef __NR_io_uring_register
+# define __NR_io_uring_register 427
+# endif
+# ifndef __NR_open_tree
+# define __NR_open_tree 428
+# endif
+# ifndef __NR_move_mount
+# define __NR_move_mount 429
+# endif
+# ifndef __NR_fsopen
+# define __NR_fsopen 430
+# endif
+# ifndef __NR_fsconfig
+# define __NR_fsconfig 431
+# endif
+# ifndef __NR_fsmount
+# define __NR_fsmount 432
+# endif
+# ifndef __NR_fspick
+# define __NR_fspick 433
+# endif
+# ifndef __NR_pidfd_open
+# define __NR_pidfd_open 434
+# endif
+# ifndef __NR_clone3
+# define __NR_clone3 435
+# endif
+# ifndef __NR_openat2
+# define __NR_openat2 437
+# endif
+# ifndef __NR_pidfd_getfd
+# define __NR_pidfd_getfd 438
+# endif
+#endif
+
+
+#ifdef __powerpc64__
+# ifndef __NR_restart_syscall
+# define __NR_restart_syscall 0
+# endif
+# ifndef __NR_exit
+# define __NR_exit 1
+# endif
+# ifndef __NR_fork
+# define __NR_fork 2
+# endif
+# ifndef __NR_read
+# define __NR_read 3
+# endif
+# ifndef __NR_write
+# define __NR_write 4
+# endif
+# ifndef __NR_open
+# define __NR_open 5
+# endif
+# ifndef __NR_close
+# define __NR_close 6
+# endif
+# ifndef __NR_waitpid
+# define __NR_waitpid 7
+# endif
+# ifndef __NR_creat
+# define __NR_creat 8
+# endif
+# ifndef __NR_link
+# define __NR_link 9
+# endif
+# ifndef __NR_unlink
+# define __NR_unlink 10
+# endif
+# ifndef __NR_execve
+# define __NR_execve 11
+# endif
+# ifndef __NR_chdir
+# define __NR_chdir 12
+# endif
+# ifndef __NR_time
+# define __NR_time 13
+# endif
+# ifndef __NR_mknod
+# define __NR_mknod 14
+# endif
+# ifndef __NR_chmod
+# define __NR_chmod 15
+# endif
+# ifndef __NR_lchown
+# define __NR_lchown 16
+# endif
+# ifndef __NR_break
+# define __NR_break 17
+# endif
+# ifndef __NR_oldstat
+# define __NR_oldstat 18
+# endif
+# ifndef __NR_lseek
+# define __NR_lseek 19
+# endif
+# ifndef __NR_getpid
+# define __NR_getpid 20
+# endif
+# ifndef __NR_mount
+# define __NR_mount 21
+# endif
+# ifndef __NR_umount
+# define __NR_umount 22
+# endif
+# ifndef __NR_setuid
+# define __NR_setuid 23
+# endif
+# ifndef __NR_getuid
+# define __NR_getuid 24
+# endif
+# ifndef __NR_stime
+# define __NR_stime 25
+# endif
+# ifndef __NR_ptrace
+# define __NR_ptrace 26
+# endif
+# ifndef __NR_alarm
+# define __NR_alarm 27
+# endif
+# ifndef __NR_oldfstat
+# define __NR_oldfstat 28
+# endif
+# ifndef __NR_pause
+# define __NR_pause 29
+# endif
+# ifndef __NR_utime
+# define __NR_utime 30
+# endif
+# ifndef __NR_stty
+# define __NR_stty 31
+# endif
+# ifndef __NR_gtty
+# define __NR_gtty 32
+# endif
+# ifndef __NR_access
+# define __NR_access 33
+# endif
+# ifndef __NR_nice
+# define __NR_nice 34
+# endif
+# ifndef __NR_ftime
+# define __NR_ftime 35
+# endif
+# ifndef __NR_sync
+# define __NR_sync 36
+# endif
+# ifndef __NR_kill
+# define __NR_kill 37
+# endif
+# ifndef __NR_rename
+# define __NR_rename 38
+# endif
+# ifndef __NR_mkdir
+# define __NR_mkdir 39
+# endif
+# ifndef __NR_rmdir
+# define __NR_rmdir 40
+# endif
+# ifndef __NR_dup
+# define __NR_dup 41
+# endif
+# ifndef __NR_pipe
+# define __NR_pipe 42
+# endif
+# ifndef __NR_times
+# define __NR_times 43
+# endif
+# ifndef __NR_prof
+# define __NR_prof 44
+# endif
+# ifndef __NR_brk
+# define __NR_brk 45
+# endif
+# ifndef __NR_setgid
+# define __NR_setgid 46
+# endif
+# ifndef __NR_getgid
+# define __NR_getgid 47
+# endif
+# ifndef __NR_signal
+# define __NR_signal 48
+# endif
+# ifndef __NR_geteuid
+# define __NR_geteuid 49
+# endif
+# ifndef __NR_getegid
+# define __NR_getegid 50
+# endif
+# ifndef __NR_acct
+# define __NR_acct 51
+# endif
+# ifndef __NR_umount2
+# define __NR_umount2 52
+# endif
+# ifndef __NR_lock
+# define __NR_lock 53
+# endif
+# ifndef __NR_ioctl
+# define __NR_ioctl 54
+# endif
+# ifndef __NR_fcntl
+# define __NR_fcntl 55
+# endif
+# ifndef __NR_mpx
+# define __NR_mpx 56
+# endif
+# ifndef __NR_setpgid
+# define __NR_setpgid 57
+# endif
+# ifndef __NR_ulimit
+# define __NR_ulimit 58
+# endif
+# ifndef __NR_oldolduname
+# define __NR_oldolduname 59
+# endif
+# ifndef __NR_umask
+# define __NR_umask 60
+# endif
+# ifndef __NR_chroot
+# define __NR_chroot 61
+# endif
+# ifndef __NR_ustat
+# define __NR_ustat 62
+# endif
+# ifndef __NR_dup2
+# define __NR_dup2 63
+# endif
+# ifndef __NR_getppid
+# define __NR_getppid 64
+# endif
+# ifndef __NR_getpgrp
+# define __NR_getpgrp 65
+# endif
+# ifndef __NR_setsid
+# define __NR_setsid 66
+# endif
+# ifndef __NR_sigaction
+# define __NR_sigaction 67
+# endif
+# ifndef __NR_sgetmask
+# define __NR_sgetmask 68
+# endif
+# ifndef __NR_ssetmask
+# define __NR_ssetmask 69
+# endif
+# ifndef __NR_setreuid
+# define __NR_setreuid 70
+# endif
+# ifndef __NR_setregid
+# define __NR_setregid 71
+# endif
+# ifndef __NR_sigsuspend
+# define __NR_sigsuspend 72
+# endif
+# ifndef __NR_sigpending
+# define __NR_sigpending 73
+# endif
+# ifndef __NR_sethostname
+# define __NR_sethostname 74
+# endif
+# ifndef __NR_setrlimit
+# define __NR_setrlimit 75
+# endif
+# ifndef __NR_getrlimit
+# define __NR_getrlimit 76
+# endif
+# ifndef __NR_getrusage
+# define __NR_getrusage 77
+# endif
+# ifndef __NR_gettimeofday
+# define __NR_gettimeofday 78
+# endif
+# ifndef __NR_settimeofday
+# define __NR_settimeofday 79
+# endif
+# ifndef __NR_getgroups
+# define __NR_getgroups 80
+# endif
+# ifndef __NR_setgroups
+# define __NR_setgroups 81
+# endif
+# ifndef __NR_select
+# define __NR_select 82
+# endif
+# ifndef __NR_symlink
+# define __NR_symlink 83
+# endif
+# ifndef __NR_oldlstat
+# define __NR_oldlstat 84
+# endif
+# ifndef __NR_readlink
+# define __NR_readlink 85
+# endif
+# ifndef __NR_uselib
+# define __NR_uselib 86
+# endif
+# ifndef __NR_swapon
+# define __NR_swapon 87
+# endif
+# ifndef __NR_reboot
+# define __NR_reboot 88
+# endif
+# ifndef __NR_readdir
+# define __NR_readdir 89
+# endif
+# ifndef __NR_mmap
+# define __NR_mmap 90
+# endif
+# ifndef __NR_munmap
+# define __NR_munmap 91
+# endif
+# ifndef __NR_truncate
+# define __NR_truncate 92
+# endif
+# ifndef __NR_ftruncate
+# define __NR_ftruncate 93
+# endif
+# ifndef __NR_fchmod
+# define __NR_fchmod 94
+# endif
+# ifndef __NR_fchown
+# define __NR_fchown 95
+# endif
+# ifndef __NR_getpriority
+# define __NR_getpriority 96
+# endif
+# ifndef __NR_setpriority
+# define __NR_setpriority 97
+# endif
+# ifndef __NR_profil
+# define __NR_profil 98
+# endif
+# ifndef __NR_statfs
+# define __NR_statfs 99
+# endif
+# ifndef __NR_fstatfs
+# define __NR_fstatfs 100
+# endif
+# ifndef __NR_ioperm
+# define __NR_ioperm 101
+# endif
+# ifndef __NR_socketcall
+# define __NR_socketcall 102
+# endif
+# ifndef __NR_syslog
+# define __NR_syslog 103
+# endif
+# ifndef __NR_setitimer
+# define __NR_setitimer 104
+# endif
+# ifndef __NR_getitimer
+# define __NR_getitimer 105
+# endif
+# ifndef __NR_stat
+# define __NR_stat 106
+# endif
+# ifndef __NR_lstat
+# define __NR_lstat 107
+# endif
+# ifndef __NR_fstat
+# define __NR_fstat 108
+# endif
+# ifndef __NR_olduname
+# define __NR_olduname 109
+# endif
+# ifndef __NR_iopl
+# define __NR_iopl 110
+# endif
+# ifndef __NR_vhangup
+# define __NR_vhangup 111
+# endif
+# ifndef __NR_idle
+# define __NR_idle 112
+# endif
+# ifndef __NR_vm86
+# define __NR_vm86 113
+# endif
+# ifndef __NR_wait4
+# define __NR_wait4 114
+# endif
+# ifndef __NR_swapoff
+# define __NR_swapoff 115
+# endif
+# ifndef __NR_sysinfo
+# define __NR_sysinfo 116
+# endif
+# ifndef __NR_ipc
+# define __NR_ipc 117
+# endif
+# ifndef __NR_fsync
+# define __NR_fsync 118
+# endif
+# ifndef __NR_sigreturn
+# define __NR_sigreturn 119
+# endif
+# ifndef __NR_clone
+# define __NR_clone 120
+# endif
+# ifndef __NR_setdomainname
+# define __NR_setdomainname 121
+# endif
+# ifndef __NR_uname
+# define __NR_uname 122
+# endif
+# ifndef __NR_modify_ldt
+# define __NR_modify_ldt 123
+# endif
+# ifndef __NR_adjtimex
+# define __NR_adjtimex 124
+# endif
+# ifndef __NR_mprotect
+# define __NR_mprotect 125
+# endif
+# ifndef __NR_sigprocmask
+# define __NR_sigprocmask 126
+# endif
+# ifndef __NR_create_module
+# define __NR_create_module 127
+# endif
+# ifndef __NR_init_module
+# define __NR_init_module 128
+# endif
+# ifndef __NR_delete_module
+# define __NR_delete_module 129
+# endif
+# ifndef __NR_get_kernel_syms
+# define __NR_get_kernel_syms 130
+# endif
+# ifndef __NR_quotactl
+# define __NR_quotactl 131
+# endif
+# ifndef __NR_getpgid
+# define __NR_getpgid 132
+# endif
+# ifndef __NR_fchdir
+# define __NR_fchdir 133
+# endif
+# ifndef __NR_bdflush
+# define __NR_bdflush 134
+# endif
+# ifndef __NR_sysfs
+# define __NR_sysfs 135
+# endif
+# ifndef __NR_personality
+# define __NR_personality 136
+# endif
+# ifndef __NR_afs_syscall
+# define __NR_afs_syscall 137
+# endif
+# ifndef __NR_setfsuid
+# define __NR_setfsuid 138
+# endif
+# ifndef __NR_setfsgid
+# define __NR_setfsgid 139
+# endif
+# ifndef __NR__llseek
+# define __NR__llseek 140
+# endif
+# ifndef __NR_getdents
+# define __NR_getdents 141
+# endif
+# ifndef __NR__newselect
+# define __NR__newselect 142
+# endif
+# ifndef __NR_flock
+# define __NR_flock 143
+# endif
+# ifndef __NR_msync
+# define __NR_msync 144
+# endif
+# ifndef __NR_readv
+# define __NR_readv 145
+# endif
+# ifndef __NR_writev
+# define __NR_writev 146
+# endif
+# ifndef __NR_getsid
+# define __NR_getsid 147
+# endif
+# ifndef __NR_fdatasync
+# define __NR_fdatasync 148
+# endif
+# ifndef __NR__sysctl
+# define __NR__sysctl 149
+# endif
+# ifndef __NR_mlock
+# define __NR_mlock 150
+# endif
+# ifndef __NR_munlock
+# define __NR_munlock 151
+# endif
+# ifndef __NR_mlockall
+# define __NR_mlockall 152
+# endif
+# ifndef __NR_munlockall
+# define __NR_munlockall 153
+# endif
+# ifndef __NR_sched_setparam
+# define __NR_sched_setparam 154
+# endif
+# ifndef __NR_sched_getparam
+# define __NR_sched_getparam 155
+# endif
+# ifndef __NR_sched_setscheduler
+# define __NR_sched_setscheduler 156
+# endif
+# ifndef __NR_sched_getscheduler
+# define __NR_sched_getscheduler 157
+# endif
+# ifndef __NR_sched_yield
+# define __NR_sched_yield 158
+# endif
+# ifndef __NR_sched_get_priority_max
+# define __NR_sched_get_priority_max 159
+# endif
+# ifndef __NR_sched_get_priority_min
+# define __NR_sched_get_priority_min 160
+# endif
+# ifndef __NR_sched_rr_get_interval
+# define __NR_sched_rr_get_interval 161
+# endif
+# ifndef __NR_nanosleep
+# define __NR_nanosleep 162
+# endif
+# ifndef __NR_mremap
+# define __NR_mremap 163
+# endif
+# ifndef __NR_setresuid
+# define __NR_setresuid 164
+# endif
+# ifndef __NR_getresuid
+# define __NR_getresuid 165
+# endif
+# ifndef __NR_query_module
+# define __NR_query_module 166
+# endif
+# ifndef __NR_poll
+# define __NR_poll 167
+# endif
+# ifndef __NR_nfsservctl
+# define __NR_nfsservctl 168
+# endif
+# ifndef __NR_setresgid
+# define __NR_setresgid 169
+# endif
+# ifndef __NR_getresgid
+# define __NR_getresgid 170
+# endif
+# ifndef __NR_prctl
+# define __NR_prctl 171
+# endif
+# ifndef __NR_rt_sigreturn
+# define __NR_rt_sigreturn 172
+# endif
+# ifndef __NR_rt_sigaction
+# define __NR_rt_sigaction 173
+# endif
+# ifndef __NR_rt_sigprocmask
+# define __NR_rt_sigprocmask 174
+# endif
+# ifndef __NR_rt_sigpending
+# define __NR_rt_sigpending 175
+# endif
+# ifndef __NR_rt_sigtimedwait
+# define __NR_rt_sigtimedwait 176
+# endif
+# ifndef __NR_rt_sigqueueinfo
+# define __NR_rt_sigqueueinfo 177
+# endif
+# ifndef __NR_rt_sigsuspend
+# define __NR_rt_sigsuspend 178
+# endif
+# ifndef __NR_pread64
+# define __NR_pread64 179
+# endif
+# ifndef __NR_pwrite64
+# define __NR_pwrite64 180
+# endif
+# ifndef __NR_chown
+# define __NR_chown 181
+# endif
+# ifndef __NR_getcwd
+# define __NR_getcwd 182
+# endif
+# ifndef __NR_capget
+# define __NR_capget 183
+# endif
+# ifndef __NR_capset
+# define __NR_capset 184
+# endif
+# ifndef __NR_sigaltstack
+# define __NR_sigaltstack 185
+# endif
+# ifndef __NR_sendfile
+# define __NR_sendfile 186
+# endif
+# ifndef __NR_getpmsg
+# define __NR_getpmsg 187
+# endif
+# ifndef __NR_putpmsg
+# define __NR_putpmsg 188
+# endif
+# ifndef __NR_vfork
+# define __NR_vfork 189
+# endif
+# ifndef __NR_ugetrlimit
+# define __NR_ugetrlimit 190
+# endif
+# ifndef __NR_readahead
+# define __NR_readahead 191
+# endif
+# ifndef __NR_mmap2
+# define __NR_mmap2 192
+# endif
+# ifndef __NR_truncate64
+# define __NR_truncate64 193
+# endif
+# ifndef __NR_ftruncate64
+# define __NR_ftruncate64 194
+# endif
+# ifndef __NR_stat64
+# define __NR_stat64 195
+# endif
+# ifndef __NR_lstat64
+# define __NR_lstat64 196
+# endif
+# ifndef __NR_fstat64
+# define __NR_fstat64 197
+# endif
+# ifndef __NR_pciconfig_read
+# define __NR_pciconfig_read 198
+# endif
+# ifndef __NR_pciconfig_write
+# define __NR_pciconfig_write 199
+# endif
+# ifndef __NR_pciconfig_iobase
+# define __NR_pciconfig_iobase 200
+# endif
+# ifndef __NR_multiplexer
+# define __NR_multiplexer 201
+# endif
+# ifndef __NR_getdents64
+# define __NR_getdents64 202
+# endif
+# ifndef __NR_pivot_root
+# define __NR_pivot_root 203
+# endif
+# ifndef __NR_fcntl64
+# define __NR_fcntl64 204
+# endif
+# ifndef __NR_madvise
+# define __NR_madvise 205
+# endif
+# ifndef __NR_mincore
+# define __NR_mincore 206
+# endif
+# ifndef __NR_gettid
+# define __NR_gettid 207
+# endif
+# ifndef __NR_tkill
+# define __NR_tkill 208
+# endif
+# ifndef __NR_setxattr
+# define __NR_setxattr 209
+# endif
+# ifndef __NR_lsetxattr
+# define __NR_lsetxattr 210
+# endif
+# ifndef __NR_fsetxattr
+# define __NR_fsetxattr 211
+# endif
+# ifndef __NR_getxattr
+# define __NR_getxattr 212
+# endif
+# ifndef __NR_lgetxattr
+# define __NR_lgetxattr 213
+# endif
+# ifndef __NR_fgetxattr
+# define __NR_fgetxattr 214
+# endif
+# ifndef __NR_listxattr
+# define __NR_listxattr 215
+# endif
+# ifndef __NR_llistxattr
+# define __NR_llistxattr 216
+# endif
+# ifndef __NR_flistxattr
+# define __NR_flistxattr 217
+# endif
+# ifndef __NR_removexattr
+# define __NR_removexattr 218
+# endif
+# ifndef __NR_lremovexattr
+# define __NR_lremovexattr 219
+# endif
+# ifndef __NR_fremovexattr
+# define __NR_fremovexattr 220
+# endif
+# ifndef __NR_futex
+# define __NR_futex 221
+# endif
+# ifndef __NR_sched_setaffinity
+# define __NR_sched_setaffinity 222
+# endif
+# ifndef __NR_sched_getaffinity
+# define __NR_sched_getaffinity 223
+# endif
+# ifndef __NR_tuxcall
+# define __NR_tuxcall 225
+# endif
+# ifndef __NR_sendfile64
+# define __NR_sendfile64 226
+# endif
+# ifndef __NR_io_setup
+# define __NR_io_setup 227
+# endif
+# ifndef __NR_io_destroy
+# define __NR_io_destroy 228
+# endif
+# ifndef __NR_io_getevents
+# define __NR_io_getevents 229
+# endif
+# ifndef __NR_io_submit
+# define __NR_io_submit 230
+# endif
+# ifndef __NR_io_cancel
+# define __NR_io_cancel 231
+# endif
+# ifndef __NR_set_tid_address
+# define __NR_set_tid_address 232
+# endif
+# ifndef __NR_fadvise64
+# define __NR_fadvise64 233
+# endif
+# ifndef __NR_exit_group
+# define __NR_exit_group 234
+# endif
+# ifndef __NR_lookup_dcookie
+# define __NR_lookup_dcookie 235
+# endif
+# ifndef __NR_epoll_create
+# define __NR_epoll_create 236
+# endif
+# ifndef __NR_epoll_ctl
+# define __NR_epoll_ctl 237
+# endif
+# ifndef __NR_epoll_wait
+# define __NR_epoll_wait 238
+# endif
+# ifndef __NR_remap_file_pages
+# define __NR_remap_file_pages 239
+# endif
+# ifndef __NR_timer_create
+# define __NR_timer_create 240
+# endif
+# ifndef __NR_timer_settime
+# define __NR_timer_settime 241
+# endif
+# ifndef __NR_timer_gettime
+# define __NR_timer_gettime 242
+# endif
+# ifndef __NR_timer_getoverrun
+# define __NR_timer_getoverrun 243
+# endif
+# ifndef __NR_timer_delete
+# define __NR_timer_delete 244
+# endif
+# ifndef __NR_clock_settime
+# define __NR_clock_settime 245
+# endif
+# ifndef __NR_clock_gettime
+# define __NR_clock_gettime 246
+# endif
+# ifndef __NR_clock_getres
+# define __NR_clock_getres 247
+# endif
+# ifndef __NR_clock_nanosleep
+# define __NR_clock_nanosleep 248
+# endif
+# ifndef __NR_swapcontext
+# define __NR_swapcontext 249
+# endif
+# ifndef __NR_tgkill
+# define __NR_tgkill 250
+# endif
+# ifndef __NR_utimes
+# define __NR_utimes 251
+# endif
+# ifndef __NR_statfs64
+# define __NR_statfs64 252
+# endif
+# ifndef __NR_fstatfs64
+# define __NR_fstatfs64 253
+# endif
+# ifndef __NR_fadvise64_64
+# define __NR_fadvise64_64 254
+# endif
+# ifndef __NR_rtas
+# define __NR_rtas 255
+# endif
+# ifndef __NR_sys_debug_setcontext
+# define __NR_sys_debug_setcontext 256
+# endif
+# ifndef __NR_migrate_pages
+# define __NR_migrate_pages 258
+# endif
+# ifndef __NR_mbind
+# define __NR_mbind 259
+# endif
+# ifndef __NR_get_mempolicy
+# define __NR_get_mempolicy 260
+# endif
+# ifndef __NR_set_mempolicy
+# define __NR_set_mempolicy 261
+# endif
+# ifndef __NR_mq_open
+# define __NR_mq_open 262
+# endif
+# ifndef __NR_mq_unlink
+# define __NR_mq_unlink 263
+# endif
+# ifndef __NR_mq_timedsend
+# define __NR_mq_timedsend 264
+# endif
+# ifndef __NR_mq_timedreceive
+# define __NR_mq_timedreceive 265
+# endif
+# ifndef __NR_mq_notify
+# define __NR_mq_notify 266
+# endif
+# ifndef __NR_mq_getsetattr
+# define __NR_mq_getsetattr 267
+# endif
+# ifndef __NR_kexec_load
+# define __NR_kexec_load 268
+# endif
+# ifndef __NR_add_key
+# define __NR_add_key 269
+# endif
+# ifndef __NR_request_key
+# define __NR_request_key 270
+# endif
+# ifndef __NR_keyctl
+# define __NR_keyctl 271
+# endif
+# ifndef __NR_waitid
+# define __NR_waitid 272
+# endif
+# ifndef __NR_ioprio_set
+# define __NR_ioprio_set 273
+# endif
+# ifndef __NR_ioprio_get
+# define __NR_ioprio_get 274
+# endif
+# ifndef __NR_inotify_init
+# define __NR_inotify_init 275
+# endif
+# ifndef __NR_inotify_add_watch
+# define __NR_inotify_add_watch 276
+# endif
+# ifndef __NR_inotify_rm_watch
+# define __NR_inotify_rm_watch 277
+# endif
+# ifndef __NR_spu_run
+# define __NR_spu_run 278
+# endif
+# ifndef __NR_spu_create
+# define __NR_spu_create 279
+# endif
+# ifndef __NR_pselect6
+# define __NR_pselect6 280
+# endif
+# ifndef __NR_ppoll
+# define __NR_ppoll 281
+# endif
+# ifndef __NR_unshare
+# define __NR_unshare 282
+# endif
+# ifndef __NR_splice
+# define __NR_splice 283
+# endif
+# ifndef __NR_tee
+# define __NR_tee 284
+# endif
+# ifndef __NR_vmsplice
+# define __NR_vmsplice 285
+# endif
+# ifndef __NR_openat
+# define __NR_openat 286
+# endif
+# ifndef __NR_mkdirat
+# define __NR_mkdirat 287
+# endif
+# ifndef __NR_mknodat
+# define __NR_mknodat 288
+# endif
+# ifndef __NR_fchownat
+# define __NR_fchownat 289
+# endif
+# ifndef __NR_futimesat
+# define __NR_futimesat 290
+# endif
+# ifndef __NR_newfstatat
+# define __NR_newfstatat 291
+# endif
+# ifndef __NR_fstatat64
+# define __NR_fstatat64 291
+# endif
+# ifndef __NR_unlinkat
+# define __NR_unlinkat 292
+# endif
+# ifndef __NR_renameat
+# define __NR_renameat 293
+# endif
+# ifndef __NR_linkat
+# define __NR_linkat 294
+# endif
+# ifndef __NR_symlinkat
+# define __NR_symlinkat 295
+# endif
+# ifndef __NR_readlinkat
+# define __NR_readlinkat 296
+# endif
+# ifndef __NR_fchmodat
+# define __NR_fchmodat 297
+# endif
+# ifndef __NR_faccessat
+# define __NR_faccessat 298
+# endif
+# ifndef __NR_get_robust_list
+# define __NR_get_robust_list 299
+# endif
+# ifndef __NR_set_robust_list
+# define __NR_set_robust_list 300
+# endif
+# ifndef __NR_move_pages
+# define __NR_move_pages 301
+# endif
+# ifndef __NR_getcpu
+# define __NR_getcpu 302
+# endif
+# ifndef __NR_epoll_pwait
+# define __NR_epoll_pwait 303
+# endif
+# ifndef __NR_utimensat
+# define __NR_utimensat 304
+# endif
+# ifndef __NR_signalfd
+# define __NR_signalfd 305
+# endif
+# ifndef __NR_timerfd_create
+# define __NR_timerfd_create 306
+# endif
+# ifndef __NR_eventfd
+# define __NR_eventfd 307
+# endif
+# ifndef __NR_sync_file_range2
+# define __NR_sync_file_range2 308
+# endif
+# ifndef __NR_fallocate
+# define __NR_fallocate 309
+# endif
+# ifndef __NR_subpage_prot
+# define __NR_subpage_prot 310
+# endif
+# ifndef __NR_timerfd_settime
+# define __NR_timerfd_settime 311
+# endif
+# ifndef __NR_timerfd_gettime
+# define __NR_timerfd_gettime 312
+# endif
+# ifndef __NR_signalfd4
+# define __NR_signalfd4 313
+# endif
+# ifndef __NR_eventfd2
+# define __NR_eventfd2 314
+# endif
+# ifndef __NR_epoll_create1
+# define __NR_epoll_create1 315
+# endif
+# ifndef __NR_dup3
+# define __NR_dup3 316
+# endif
+# ifndef __NR_pipe2
+# define __NR_pipe2 317
+# endif
+# ifndef __NR_inotify_init1
+# define __NR_inotify_init1 318
+# endif
+# ifndef __NR_perf_event_open
+# define __NR_perf_event_open 319
+# endif
+# ifndef __NR_preadv
+# define __NR_preadv 320
+# endif
+# ifndef __NR_pwritev
+# define __NR_pwritev 321
+# endif
+# ifndef __NR_rt_tgsigqueueinfo
+# define __NR_rt_tgsigqueueinfo 322
+# endif
+# ifndef __NR_fanotify_init
+# define __NR_fanotify_init 323
+# endif
+# ifndef __NR_fanotify_mark
+# define __NR_fanotify_mark 324
+# endif
+# ifndef __NR_prlimit64
+# define __NR_prlimit64 325
+# endif
+# ifndef __NR_socket
+# define __NR_socket 326
+# endif
+# ifndef __NR_bind
+# define __NR_bind 327
+# endif
+# ifndef __NR_connect
+# define __NR_connect 328
+# endif
+# ifndef __NR_listen
+# define __NR_listen 329
+# endif
+# ifndef __NR_accept
+# define __NR_accept 330
+# endif
+# ifndef __NR_getsockname
+# define __NR_getsockname 331
+# endif
+# ifndef __NR_getpeername
+# define __NR_getpeername 332
+# endif
+# ifndef __NR_socketpair
+# define __NR_socketpair 333
+# endif
+# ifndef __NR_send
+# define __NR_send 334
+# endif
+# ifndef __NR_sendto
+# define __NR_sendto 335
+# endif
+# ifndef __NR_recv
+# define __NR_recv 336
+# endif
+# ifndef __NR_recvfrom
+# define __NR_recvfrom 337
+# endif
+# ifndef __NR_shutdown
+# define __NR_shutdown 338
+# endif
+# ifndef __NR_setsockopt
+# define __NR_setsockopt 339
+# endif
+# ifndef __NR_getsockopt
+# define __NR_getsockopt 340
+# endif
+# ifndef __NR_sendmsg
+# define __NR_sendmsg 341
+# endif
+# ifndef __NR_recvmsg
+# define __NR_recvmsg 342
+# endif
+# ifndef __NR_recvmmsg
+# define __NR_recvmmsg 343
+# endif
+# ifndef __NR_accept4
+# define __NR_accept4 344
+# endif
+# ifndef __NR_name_to_handle_at
+# define __NR_name_to_handle_at 345
+# endif
+# ifndef __NR_open_by_handle_at
+# define __NR_open_by_handle_at 346
+# endif
+# ifndef __NR_clock_adjtime
+# define __NR_clock_adjtime 347
+# endif
+# ifndef __NR_syncfs
+# define __NR_syncfs 348
+# endif
+# ifndef __NR_sendmmsg
+# define __NR_sendmmsg 349
+# endif
+# ifndef __NR_setns
+# define __NR_setns 350
+# endif
+# ifndef __NR_process_vm_readv
+# define __NR_process_vm_readv 351
+# endif
+# ifndef __NR_process_vm_writev
+# define __NR_process_vm_writev 352
+# endif
+# ifndef __NR_finit_module
+# define __NR_finit_module 353
+# endif
+# ifndef __NR_kcmp
+# define __NR_kcmp 354
+# endif
+# ifndef __NR_sched_setattr
+# define __NR_sched_setattr 355
+# endif
+# ifndef __NR_sched_getattr
+# define __NR_sched_getattr 356
+# endif
+# ifndef __NR_renameat2
+# define __NR_renameat2 357
+# endif
+# ifndef __NR_seccomp
+# define __NR_seccomp 358
+# endif
+# ifndef __NR_getrandom
+# define __NR_getrandom 359
+# endif
+# ifndef __NR_memfd_create
+# define __NR_memfd_create 360
+# endif
+# ifndef __NR_bpf
+# define __NR_bpf 361
+# endif
+# ifndef __NR_execveat
+# define __NR_execveat 362
+# endif
+# ifndef __NR_switch_endian
+# define __NR_switch_endian 363
+# endif
+# ifndef __NR_userfaultfd
+# define __NR_userfaultfd 364
+# endif
+# ifndef __NR_membarrier
+# define __NR_membarrier 365
+# endif
+# ifndef __NR_mlock2
+# define __NR_mlock2 378
+# endif
+# ifndef __NR_copy_file_range
+# define __NR_copy_file_range 379
+# endif
+# ifndef __NR_preadv2
+# define __NR_preadv2 380
+# endif
+# ifndef __NR_pwritev2
+# define __NR_pwritev2 381
+# endif
+# ifndef __NR_kexec_file_load
+# define __NR_kexec_file_load 382
+# endif
+# ifndef __NR_statx
+# define __NR_statx 383
+# endif
+# ifndef __NR_pkey_alloc
+# define __NR_pkey_alloc 384
+# endif
+# ifndef __NR_pkey_free
+# define __NR_pkey_free 385
+# endif
+# ifndef __NR_pkey_mprotect
+# define __NR_pkey_mprotect 386
+# endif
+# ifndef __NR_rseq
+# define __NR_rseq 387
+# endif
+# ifndef __NR_io_pgetevents
+# define __NR_io_pgetevents 388
+# endif
+# ifndef __NR_semtimedop
+# define __NR_semtimedop 392
+# endif
+# ifndef __NR_semget
+# define __NR_semget 393
+# endif
+# ifndef __NR_semctl
+# define __NR_semctl 394
+# endif
+# ifndef __NR_shmget
+# define __NR_shmget 395
+# endif
+# ifndef __NR_shmctl
+# define __NR_shmctl 396
+# endif
+# ifndef __NR_shmat
+# define __NR_shmat 397
+# endif
+# ifndef __NR_shmdt
+# define __NR_shmdt 398
+# endif
+# ifndef __NR_msgget
+# define __NR_msgget 399
+# endif
+# ifndef __NR_msgsnd
+# define __NR_msgsnd 400
+# endif
+# ifndef __NR_msgrcv
+# define __NR_msgrcv 401
+# endif
+# ifndef __NR_msgctl
+# define __NR_msgctl 402
+# endif
+# ifndef __NR_clock_gettime64
+# define __NR_clock_gettime64 403
+# endif
+# ifndef __NR_clock_settime64
+# define __NR_clock_settime64 404
+# endif
+# ifndef __NR_clock_adjtime64
+# define __NR_clock_adjtime64 405
+# endif
+# ifndef __NR_clock_getres_time64
+# define __NR_clock_getres_time64 406
+# endif
+# ifndef __NR_clock_nanosleep_time64
+# define __NR_clock_nanosleep_time64 407
+# endif
+# ifndef __NR_timer_gettime64
+# define __NR_timer_gettime64 408
+# endif
+# ifndef __NR_timer_settime64
+# define __NR_timer_settime64 409
+# endif
+# ifndef __NR_timerfd_gettime64
+# define __NR_timerfd_gettime64 410
+# endif
+# ifndef __NR_timerfd_settime64
+# define __NR_timerfd_settime64 411
+# endif
+# ifndef __NR_utimensat_time64
+# define __NR_utimensat_time64 412
+# endif
+# ifndef __NR_pselect6_time64
+# define __NR_pselect6_time64 413
+# endif
+# ifndef __NR_ppoll_time64
+# define __NR_ppoll_time64 414
+# endif
+# ifndef __NR_io_pgetevents_time64
+# define __NR_io_pgetevents_time64 416
+# endif
+# ifndef __NR_recvmmsg_time64
+# define __NR_recvmmsg_time64 417
+# endif
+# ifndef __NR_mq_timedsend_time64
+# define __NR_mq_timedsend_time64 418
+# endif
+# ifndef __NR_mq_timedreceive_time64
+# define __NR_mq_timedreceive_time64 419
+# endif
+# ifndef __NR_semtimedop_time64
+# define __NR_semtimedop_time64 420
+# endif
+# ifndef __NR_rt_sigtimedwait_time64
+# define __NR_rt_sigtimedwait_time64 421
+# endif
+# ifndef __NR_futex_time64
+# define __NR_futex_time64 422
+# endif
+# ifndef __NR_sched_rr_get_interval_time64
+# define __NR_sched_rr_get_interval_time64 423
+# endif
+# ifndef __NR_pidfd_send_signal
+# define __NR_pidfd_send_signal 424
+# endif
+# ifndef __NR_io_uring_setup
+# define __NR_io_uring_setup 425
+# endif
+# ifndef __NR_io_uring_enter
+# define __NR_io_uring_enter 426
+# endif
+# ifndef __NR_io_uring_register
+# define __NR_io_uring_register 427
+# endif
+# ifndef __NR_open_tree
+# define __NR_open_tree 428
+# endif
+# ifndef __NR_move_mount
+# define __NR_move_mount 429
+# endif
+# ifndef __NR_fsopen
+# define __NR_fsopen 430
+# endif
+# ifndef __NR_fsconfig
+# define __NR_fsconfig 431
+# endif
+# ifndef __NR_fsmount
+# define __NR_fsmount 432
+# endif
+# ifndef __NR_fspick
+# define __NR_fspick 433
+# endif
+# ifndef __NR_pidfd_open
+# define __NR_pidfd_open 434
+# endif
+# ifndef __NR_clone3
+# define __NR_clone3 435
+# endif
+# ifndef __NR_openat2
+# define __NR_openat2 437
+# endif
+# ifndef __NR_pidfd_getfd
+# define __NR_pidfd_getfd 438
+# endif
+#endif
+
+
+#ifdef __powerpc__
+# ifndef __NR_restart_syscall
+# define __NR_restart_syscall 0
+# endif
+# ifndef __NR_exit
+# define __NR_exit 1
+# endif
+# ifndef __NR_fork
+# define __NR_fork 2
+# endif
+# ifndef __NR_read
+# define __NR_read 3
+# endif
+# ifndef __NR_write
+# define __NR_write 4
+# endif
+# ifndef __NR_open
+# define __NR_open 5
+# endif
+# ifndef __NR_close
+# define __NR_close 6
+# endif
+# ifndef __NR_waitpid
+# define __NR_waitpid 7
+# endif
+# ifndef __NR_creat
+# define __NR_creat 8
+# endif
+# ifndef __NR_link
+# define __NR_link 9
+# endif
+# ifndef __NR_unlink
+# define __NR_unlink 10
+# endif
+# ifndef __NR_execve
+# define __NR_execve 11
+# endif
+# ifndef __NR_chdir
+# define __NR_chdir 12
+# endif
+# ifndef __NR_time
+# define __NR_time 13
+# endif
+# ifndef __NR_mknod
+# define __NR_mknod 14
+# endif
+# ifndef __NR_chmod
+# define __NR_chmod 15
+# endif
+# ifndef __NR_lchown
+# define __NR_lchown 16
+# endif
+# ifndef __NR_break
+# define __NR_break 17
+# endif
+# ifndef __NR_oldstat
+# define __NR_oldstat 18
+# endif
+# ifndef __NR_lseek
+# define __NR_lseek 19
+# endif
+# ifndef __NR_getpid
+# define __NR_getpid 20
+# endif
+# ifndef __NR_mount
+# define __NR_mount 21
+# endif
+# ifndef __NR_umount
+# define __NR_umount 22
+# endif
+# ifndef __NR_setuid
+# define __NR_setuid 23
+# endif
+# ifndef __NR_getuid
+# define __NR_getuid 24
+# endif
+# ifndef __NR_stime
+# define __NR_stime 25
+# endif
+# ifndef __NR_ptrace
+# define __NR_ptrace 26
+# endif
+# ifndef __NR_alarm
+# define __NR_alarm 27
+# endif
+# ifndef __NR_oldfstat
+# define __NR_oldfstat 28
+# endif
+# ifndef __NR_pause
+# define __NR_pause 29
+# endif
+# ifndef __NR_utime
+# define __NR_utime 30
+# endif
+# ifndef __NR_stty
+# define __NR_stty 31
+# endif
+# ifndef __NR_gtty
+# define __NR_gtty 32
+# endif
+# ifndef __NR_access
+# define __NR_access 33
+# endif
+# ifndef __NR_nice
+# define __NR_nice 34
+# endif
+# ifndef __NR_ftime
+# define __NR_ftime 35
+# endif
+# ifndef __NR_sync
+# define __NR_sync 36
+# endif
+# ifndef __NR_kill
+# define __NR_kill 37
+# endif
+# ifndef __NR_rename
+# define __NR_rename 38
+# endif
+# ifndef __NR_mkdir
+# define __NR_mkdir 39
+# endif
+# ifndef __NR_rmdir
+# define __NR_rmdir 40
+# endif
+# ifndef __NR_dup
+# define __NR_dup 41
+# endif
+# ifndef __NR_pipe
+# define __NR_pipe 42
+# endif
+# ifndef __NR_times
+# define __NR_times 43
+# endif
+# ifndef __NR_prof
+# define __NR_prof 44
+# endif
+# ifndef __NR_brk
+# define __NR_brk 45
+# endif
+# ifndef __NR_setgid
+# define __NR_setgid 46
+# endif
+# ifndef __NR_getgid
+# define __NR_getgid 47
+# endif
+# ifndef __NR_signal
+# define __NR_signal 48
+# endif
+# ifndef __NR_geteuid
+# define __NR_geteuid 49
+# endif
+# ifndef __NR_getegid
+# define __NR_getegid 50
+# endif
+# ifndef __NR_acct
+# define __NR_acct 51
+# endif
+# ifndef __NR_umount2
+# define __NR_umount2 52
+# endif
+# ifndef __NR_lock
+# define __NR_lock 53
+# endif
+# ifndef __NR_ioctl
+# define __NR_ioctl 54
+# endif
+# ifndef __NR_fcntl
+# define __NR_fcntl 55
+# endif
+# ifndef __NR_mpx
+# define __NR_mpx 56
+# endif
+# ifndef __NR_setpgid
+# define __NR_setpgid 57
+# endif
+# ifndef __NR_ulimit
+# define __NR_ulimit 58
+# endif
+# ifndef __NR_oldolduname
+# define __NR_oldolduname 59
+# endif
+# ifndef __NR_umask
+# define __NR_umask 60
+# endif
+# ifndef __NR_chroot
+# define __NR_chroot 61
+# endif
+# ifndef __NR_ustat
+# define __NR_ustat 62
+# endif
+# ifndef __NR_dup2
+# define __NR_dup2 63
+# endif
+# ifndef __NR_getppid
+# define __NR_getppid 64
+# endif
+# ifndef __NR_getpgrp
+# define __NR_getpgrp 65
+# endif
+# ifndef __NR_setsid
+# define __NR_setsid 66
+# endif
+# ifndef __NR_sigaction
+# define __NR_sigaction 67
+# endif
+# ifndef __NR_sgetmask
+# define __NR_sgetmask 68
+# endif
+# ifndef __NR_ssetmask
+# define __NR_ssetmask 69
+# endif
+# ifndef __NR_setreuid
+# define __NR_setreuid 70
+# endif
+# ifndef __NR_setregid
+# define __NR_setregid 71
+# endif
+# ifndef __NR_sigsuspend
+# define __NR_sigsuspend 72
+# endif
+# ifndef __NR_sigpending
+# define __NR_sigpending 73
+# endif
+# ifndef __NR_sethostname
+# define __NR_sethostname 74
+# endif
+# ifndef __NR_setrlimit
+# define __NR_setrlimit 75
+# endif
+# ifndef __NR_getrlimit
+# define __NR_getrlimit 76
+# endif
+# ifndef __NR_getrusage
+# define __NR_getrusage 77
+# endif
+# ifndef __NR_gettimeofday
+# define __NR_gettimeofday 78
+# endif
+# ifndef __NR_settimeofday
+# define __NR_settimeofday 79
+# endif
+# ifndef __NR_getgroups
+# define __NR_getgroups 80
+# endif
+# ifndef __NR_setgroups
+# define __NR_setgroups 81
+# endif
+# ifndef __NR_select
+# define __NR_select 82
+# endif
+# ifndef __NR_symlink
+# define __NR_symlink 83
+# endif
+# ifndef __NR_oldlstat
+# define __NR_oldlstat 84
+# endif
+# ifndef __NR_readlink
+# define __NR_readlink 85
+# endif
+# ifndef __NR_uselib
+# define __NR_uselib 86
+# endif
+# ifndef __NR_swapon
+# define __NR_swapon 87
+# endif
+# ifndef __NR_reboot
+# define __NR_reboot 88
+# endif
+# ifndef __NR_readdir
+# define __NR_readdir 89
+# endif
+# ifndef __NR_mmap
+# define __NR_mmap 90
+# endif
+# ifndef __NR_munmap
+# define __NR_munmap 91
+# endif
+# ifndef __NR_truncate
+# define __NR_truncate 92
+# endif
+# ifndef __NR_ftruncate
+# define __NR_ftruncate 93
+# endif
+# ifndef __NR_fchmod
+# define __NR_fchmod 94
+# endif
+# ifndef __NR_fchown
+# define __NR_fchown 95
+# endif
+# ifndef __NR_getpriority
+# define __NR_getpriority 96
+# endif
+# ifndef __NR_setpriority
+# define __NR_setpriority 97
+# endif
+# ifndef __NR_profil
+# define __NR_profil 98
+# endif
+# ifndef __NR_statfs
+# define __NR_statfs 99
+# endif
+# ifndef __NR_fstatfs
+# define __NR_fstatfs 100
+# endif
+# ifndef __NR_ioperm
+# define __NR_ioperm 101
+# endif
+# ifndef __NR_socketcall
+# define __NR_socketcall 102
+# endif
+# ifndef __NR_syslog
+# define __NR_syslog 103
+# endif
+# ifndef __NR_setitimer
+# define __NR_setitimer 104
+# endif
+# ifndef __NR_getitimer
+# define __NR_getitimer 105
+# endif
+# ifndef __NR_stat
+# define __NR_stat 106
+# endif
+# ifndef __NR_lstat
+# define __NR_lstat 107
+# endif
+# ifndef __NR_fstat
+# define __NR_fstat 108
+# endif
+# ifndef __NR_olduname
+# define __NR_olduname 109
+# endif
+# ifndef __NR_iopl
+# define __NR_iopl 110
+# endif
+# ifndef __NR_vhangup
+# define __NR_vhangup 111
+# endif
+# ifndef __NR_idle
+# define __NR_idle 112
+# endif
+# ifndef __NR_vm86
+# define __NR_vm86 113
+# endif
+# ifndef __NR_wait4
+# define __NR_wait4 114
+# endif
+# ifndef __NR_swapoff
+# define __NR_swapoff 115
+# endif
+# ifndef __NR_sysinfo
+# define __NR_sysinfo 116
+# endif
+# ifndef __NR_ipc
+# define __NR_ipc 117
+# endif
+# ifndef __NR_fsync
+# define __NR_fsync 118
+# endif
+# ifndef __NR_sigreturn
+# define __NR_sigreturn 119
+# endif
+# ifndef __NR_clone
+# define __NR_clone 120
+# endif
+# ifndef __NR_setdomainname
+# define __NR_setdomainname 121
+# endif
+# ifndef __NR_uname
+# define __NR_uname 122
+# endif
+# ifndef __NR_modify_ldt
+# define __NR_modify_ldt 123
+# endif
+# ifndef __NR_adjtimex
+# define __NR_adjtimex 124
+# endif
+# ifndef __NR_mprotect
+# define __NR_mprotect 125
+# endif
+# ifndef __NR_sigprocmask
+# define __NR_sigprocmask 126
+# endif
+# ifndef __NR_create_module
+# define __NR_create_module 127
+# endif
+# ifndef __NR_init_module
+# define __NR_init_module 128
+# endif
+# ifndef __NR_delete_module
+# define __NR_delete_module 129
+# endif
+# ifndef __NR_get_kernel_syms
+# define __NR_get_kernel_syms 130
+# endif
+# ifndef __NR_quotactl
+# define __NR_quotactl 131
+# endif
+# ifndef __NR_getpgid
+# define __NR_getpgid 132
+# endif
+# ifndef __NR_fchdir
+# define __NR_fchdir 133
+# endif
+# ifndef __NR_bdflush
+# define __NR_bdflush 134
+# endif
+# ifndef __NR_sysfs
+# define __NR_sysfs 135
+# endif
+# ifndef __NR_personality
+# define __NR_personality 136
+# endif
+# ifndef __NR_afs_syscall
+# define __NR_afs_syscall 137
+# endif
+# ifndef __NR_setfsuid
+# define __NR_setfsuid 138
+# endif
+# ifndef __NR_setfsgid
+# define __NR_setfsgid 139
+# endif
+# ifndef __NR__llseek
+# define __NR__llseek 140
+# endif
+# ifndef __NR_getdents
+# define __NR_getdents 141
+# endif
+# ifndef __NR__newselect
+# define __NR__newselect 142
+# endif
+# ifndef __NR_flock
+# define __NR_flock 143
+# endif
+# ifndef __NR_msync
+# define __NR_msync 144
+# endif
+# ifndef __NR_readv
+# define __NR_readv 145
+# endif
+# ifndef __NR_writev
+# define __NR_writev 146
+# endif
+# ifndef __NR_getsid
+# define __NR_getsid 147
+# endif
+# ifndef __NR_fdatasync
+# define __NR_fdatasync 148
+# endif
+# ifndef __NR__sysctl
+# define __NR__sysctl 149
+# endif
+# ifndef __NR_mlock
+# define __NR_mlock 150
+# endif
+# ifndef __NR_munlock
+# define __NR_munlock 151
+# endif
+# ifndef __NR_mlockall
+# define __NR_mlockall 152
+# endif
+# ifndef __NR_munlockall
+# define __NR_munlockall 153
+# endif
+# ifndef __NR_sched_setparam
+# define __NR_sched_setparam 154
+# endif
+# ifndef __NR_sched_getparam
+# define __NR_sched_getparam 155
+# endif
+# ifndef __NR_sched_setscheduler
+# define __NR_sched_setscheduler 156
+# endif
+# ifndef __NR_sched_getscheduler
+# define __NR_sched_getscheduler 157
+# endif
+# ifndef __NR_sched_yield
+# define __NR_sched_yield 158
+# endif
+# ifndef __NR_sched_get_priority_max
+# define __NR_sched_get_priority_max 159
+# endif
+# ifndef __NR_sched_get_priority_min
+# define __NR_sched_get_priority_min 160
+# endif
+# ifndef __NR_sched_rr_get_interval
+# define __NR_sched_rr_get_interval 161
+# endif
+# ifndef __NR_nanosleep
+# define __NR_nanosleep 162
+# endif
+# ifndef __NR_mremap
+# define __NR_mremap 163
+# endif
+# ifndef __NR_setresuid
+# define __NR_setresuid 164
+# endif
+# ifndef __NR_getresuid
+# define __NR_getresuid 165
+# endif
+# ifndef __NR_query_module
+# define __NR_query_module 166
+# endif
+# ifndef __NR_poll
+# define __NR_poll 167
+# endif
+# ifndef __NR_nfsservctl
+# define __NR_nfsservctl 168
+# endif
+# ifndef __NR_setresgid
+# define __NR_setresgid 169
+# endif
+# ifndef __NR_getresgid
+# define __NR_getresgid 170
+# endif
+# ifndef __NR_prctl
+# define __NR_prctl 171
+# endif
+# ifndef __NR_rt_sigreturn
+# define __NR_rt_sigreturn 172
+# endif
+# ifndef __NR_rt_sigaction
+# define __NR_rt_sigaction 173
+# endif
+# ifndef __NR_rt_sigprocmask
+# define __NR_rt_sigprocmask 174
+# endif
+# ifndef __NR_rt_sigpending
+# define __NR_rt_sigpending 175
+# endif
+# ifndef __NR_rt_sigtimedwait
+# define __NR_rt_sigtimedwait 176
+# endif
+# ifndef __NR_rt_sigqueueinfo
+# define __NR_rt_sigqueueinfo 177
+# endif
+# ifndef __NR_rt_sigsuspend
+# define __NR_rt_sigsuspend 178
+# endif
+# ifndef __NR_pread64
+# define __NR_pread64 179
+# endif
+# ifndef __NR_pwrite64
+# define __NR_pwrite64 180
+# endif
+# ifndef __NR_chown
+# define __NR_chown 181
+# endif
+# ifndef __NR_getcwd
+# define __NR_getcwd 182
+# endif
+# ifndef __NR_capget
+# define __NR_capget 183
+# endif
+# ifndef __NR_capset
+# define __NR_capset 184
+# endif
+# ifndef __NR_sigaltstack
+# define __NR_sigaltstack 185
+# endif
+# ifndef __NR_sendfile
+# define __NR_sendfile 186
+# endif
+# ifndef __NR_getpmsg
+# define __NR_getpmsg 187
+# endif
+# ifndef __NR_putpmsg
+# define __NR_putpmsg 188
+# endif
+# ifndef __NR_vfork
+# define __NR_vfork 189
+# endif
+# ifndef __NR_ugetrlimit
+# define __NR_ugetrlimit 190
+# endif
+# ifndef __NR_readahead
+# define __NR_readahead 191
+# endif
+# ifndef __NR_mmap2
+# define __NR_mmap2 192
+# endif
+# ifndef __NR_truncate64
+# define __NR_truncate64 193
+# endif
+# ifndef __NR_ftruncate64
+# define __NR_ftruncate64 194
+# endif
+# ifndef __NR_stat64
+# define __NR_stat64 195
+# endif
+# ifndef __NR_lstat64
+# define __NR_lstat64 196
+# endif
+# ifndef __NR_fstat64
+# define __NR_fstat64 197
+# endif
+# ifndef __NR_pciconfig_read
+# define __NR_pciconfig_read 198
+# endif
+# ifndef __NR_pciconfig_write
+# define __NR_pciconfig_write 199
+# endif
+# ifndef __NR_pciconfig_iobase
+# define __NR_pciconfig_iobase 200
+# endif
+# ifndef __NR_multiplexer
+# define __NR_multiplexer 201
+# endif
+# ifndef __NR_getdents64
+# define __NR_getdents64 202
+# endif
+# ifndef __NR_pivot_root
+# define __NR_pivot_root 203
+# endif
+# ifndef __NR_fcntl64
+# define __NR_fcntl64 204
+# endif
+# ifndef __NR_madvise
+# define __NR_madvise 205
+# endif
+# ifndef __NR_mincore
+# define __NR_mincore 206
+# endif
+# ifndef __NR_gettid
+# define __NR_gettid 207
+# endif
+# ifndef __NR_tkill
+# define __NR_tkill 208
+# endif
+# ifndef __NR_setxattr
+# define __NR_setxattr 209
+# endif
+# ifndef __NR_lsetxattr
+# define __NR_lsetxattr 210
+# endif
+# ifndef __NR_fsetxattr
+# define __NR_fsetxattr 211
+# endif
+# ifndef __NR_getxattr
+# define __NR_getxattr 212
+# endif
+# ifndef __NR_lgetxattr
+# define __NR_lgetxattr 213
+# endif
+# ifndef __NR_fgetxattr
+# define __NR_fgetxattr 214
+# endif
+# ifndef __NR_listxattr
+# define __NR_listxattr 215
+# endif
+# ifndef __NR_llistxattr
+# define __NR_llistxattr 216
+# endif
+# ifndef __NR_flistxattr
+# define __NR_flistxattr 217
+# endif
+# ifndef __NR_removexattr
+# define __NR_removexattr 218
+# endif
+# ifndef __NR_lremovexattr
+# define __NR_lremovexattr 219
+# endif
+# ifndef __NR_fremovexattr
+# define __NR_fremovexattr 220
+# endif
+# ifndef __NR_futex
+# define __NR_futex 221
+# endif
+# ifndef __NR_sched_setaffinity
+# define __NR_sched_setaffinity 222
+# endif
+# ifndef __NR_sched_getaffinity
+# define __NR_sched_getaffinity 223
+# endif
+# ifndef __NR_tuxcall
+# define __NR_tuxcall 225
+# endif
+# ifndef __NR_sendfile64
+# define __NR_sendfile64 226
+# endif
+# ifndef __NR_io_setup
+# define __NR_io_setup 227
+# endif
+# ifndef __NR_io_destroy
+# define __NR_io_destroy 228
+# endif
+# ifndef __NR_io_getevents
+# define __NR_io_getevents 229
+# endif
+# ifndef __NR_io_submit
+# define __NR_io_submit 230
+# endif
+# ifndef __NR_io_cancel
+# define __NR_io_cancel 231
+# endif
+# ifndef __NR_set_tid_address
+# define __NR_set_tid_address 232
+# endif
+# ifndef __NR_fadvise64
+# define __NR_fadvise64 233
+# endif
+# ifndef __NR_exit_group
+# define __NR_exit_group 234
+# endif
+# ifndef __NR_lookup_dcookie
+# define __NR_lookup_dcookie 235
+# endif
+# ifndef __NR_epoll_create
+# define __NR_epoll_create 236
+# endif
+# ifndef __NR_epoll_ctl
+# define __NR_epoll_ctl 237
+# endif
+# ifndef __NR_epoll_wait
+# define __NR_epoll_wait 238
+# endif
+# ifndef __NR_remap_file_pages
+# define __NR_remap_file_pages 239
+# endif
+# ifndef __NR_timer_create
+# define __NR_timer_create 240
+# endif
+# ifndef __NR_timer_settime
+# define __NR_timer_settime 241
+# endif
+# ifndef __NR_timer_gettime
+# define __NR_timer_gettime 242
+# endif
+# ifndef __NR_timer_getoverrun
+# define __NR_timer_getoverrun 243
+# endif
+# ifndef __NR_timer_delete
+# define __NR_timer_delete 244
+# endif
+# ifndef __NR_clock_settime
+# define __NR_clock_settime 245
+# endif
+# ifndef __NR_clock_gettime
+# define __NR_clock_gettime 246
+# endif
+# ifndef __NR_clock_getres
+# define __NR_clock_getres 247
+# endif
+# ifndef __NR_clock_nanosleep
+# define __NR_clock_nanosleep 248
+# endif
+# ifndef __NR_swapcontext
+# define __NR_swapcontext 249
+# endif
+# ifndef __NR_tgkill
+# define __NR_tgkill 250
+# endif
+# ifndef __NR_utimes
+# define __NR_utimes 251
+# endif
+# ifndef __NR_statfs64
+# define __NR_statfs64 252
+# endif
+# ifndef __NR_fstatfs64
+# define __NR_fstatfs64 253
+# endif
+# ifndef __NR_fadvise64_64
+# define __NR_fadvise64_64 254
+# endif
+# ifndef __NR_rtas
+# define __NR_rtas 255
+# endif
+# ifndef __NR_sys_debug_setcontext
+# define __NR_sys_debug_setcontext 256
+# endif
+# ifndef __NR_migrate_pages
+# define __NR_migrate_pages 258
+# endif
+# ifndef __NR_mbind
+# define __NR_mbind 259
+# endif
+# ifndef __NR_get_mempolicy
+# define __NR_get_mempolicy 260
+# endif
+# ifndef __NR_set_mempolicy
+# define __NR_set_mempolicy 261
+# endif
+# ifndef __NR_mq_open
+# define __NR_mq_open 262
+# endif
+# ifndef __NR_mq_unlink
+# define __NR_mq_unlink 263
+# endif
+# ifndef __NR_mq_timedsend
+# define __NR_mq_timedsend 264
+# endif
+# ifndef __NR_mq_timedreceive
+# define __NR_mq_timedreceive 265
+# endif
+# ifndef __NR_mq_notify
+# define __NR_mq_notify 266
+# endif
+# ifndef __NR_mq_getsetattr
+# define __NR_mq_getsetattr 267
+# endif
+# ifndef __NR_kexec_load
+# define __NR_kexec_load 268
+# endif
+# ifndef __NR_add_key
+# define __NR_add_key 269
+# endif
+# ifndef __NR_request_key
+# define __NR_request_key 270
+# endif
+# ifndef __NR_keyctl
+# define __NR_keyctl 271
+# endif
+# ifndef __NR_waitid
+# define __NR_waitid 272
+# endif
+# ifndef __NR_ioprio_set
+# define __NR_ioprio_set 273
+# endif
+# ifndef __NR_ioprio_get
+# define __NR_ioprio_get 274
+# endif
+# ifndef __NR_inotify_init
+# define __NR_inotify_init 275
+# endif
+# ifndef __NR_inotify_add_watch
+# define __NR_inotify_add_watch 276
+# endif
+# ifndef __NR_inotify_rm_watch
+# define __NR_inotify_rm_watch 277
+# endif
+# ifndef __NR_spu_run
+# define __NR_spu_run 278
+# endif
+# ifndef __NR_spu_create
+# define __NR_spu_create 279
+# endif
+# ifndef __NR_pselect6
+# define __NR_pselect6 280
+# endif
+# ifndef __NR_ppoll
+# define __NR_ppoll 281
+# endif
+# ifndef __NR_unshare
+# define __NR_unshare 282
+# endif
+# ifndef __NR_splice
+# define __NR_splice 283
+# endif
+# ifndef __NR_tee
+# define __NR_tee 284
+# endif
+# ifndef __NR_vmsplice
+# define __NR_vmsplice 285
+# endif
+# ifndef __NR_openat
+# define __NR_openat 286
+# endif
+# ifndef __NR_mkdirat
+# define __NR_mkdirat 287
+# endif
+# ifndef __NR_mknodat
+# define __NR_mknodat 288
+# endif
+# ifndef __NR_fchownat
+# define __NR_fchownat 289
+# endif
+# ifndef __NR_futimesat
+# define __NR_futimesat 290
+# endif
+# ifndef __NR_newfstatat
+# define __NR_newfstatat 291
+# endif
+# ifndef __NR_fstatat64
+# define __NR_fstatat64 291
+# endif
+# ifndef __NR_unlinkat
+# define __NR_unlinkat 292
+# endif
+# ifndef __NR_renameat
+# define __NR_renameat 293
+# endif
+# ifndef __NR_linkat
+# define __NR_linkat 294
+# endif
+# ifndef __NR_symlinkat
+# define __NR_symlinkat 295
+# endif
+# ifndef __NR_readlinkat
+# define __NR_readlinkat 296
+# endif
+# ifndef __NR_fchmodat
+# define __NR_fchmodat 297
+# endif
+# ifndef __NR_faccessat
+# define __NR_faccessat 298
+# endif
+# ifndef __NR_get_robust_list
+# define __NR_get_robust_list 299
+# endif
+# ifndef __NR_set_robust_list
+# define __NR_set_robust_list 300
+# endif
+# ifndef __NR_move_pages
+# define __NR_move_pages 301
+# endif
+# ifndef __NR_getcpu
+# define __NR_getcpu 302
+# endif
+# ifndef __NR_epoll_pwait
+# define __NR_epoll_pwait 303
+# endif
+# ifndef __NR_utimensat
+# define __NR_utimensat 304
+# endif
+# ifndef __NR_signalfd
+# define __NR_signalfd 305
+# endif
+# ifndef __NR_timerfd_create
+# define __NR_timerfd_create 306
+# endif
+# ifndef __NR_eventfd
+# define __NR_eventfd 307
+# endif
+# ifndef __NR_sync_file_range2
+# define __NR_sync_file_range2 308
+# endif
+# ifndef __NR_fallocate
+# define __NR_fallocate 309
+# endif
+# ifndef __NR_subpage_prot
+# define __NR_subpage_prot 310
+# endif
+# ifndef __NR_timerfd_settime
+# define __NR_timerfd_settime 311
+# endif
+# ifndef __NR_timerfd_gettime
+# define __NR_timerfd_gettime 312
+# endif
+# ifndef __NR_signalfd4
+# define __NR_signalfd4 313
+# endif
+# ifndef __NR_eventfd2
+# define __NR_eventfd2 314
+# endif
+# ifndef __NR_epoll_create1
+# define __NR_epoll_create1 315
+# endif
+# ifndef __NR_dup3
+# define __NR_dup3 316
+# endif
+# ifndef __NR_pipe2
+# define __NR_pipe2 317
+# endif
+# ifndef __NR_inotify_init1
+# define __NR_inotify_init1 318
+# endif
+# ifndef __NR_perf_event_open
+# define __NR_perf_event_open 319
+# endif
+# ifndef __NR_preadv
+# define __NR_preadv 320
+# endif
+# ifndef __NR_pwritev
+# define __NR_pwritev 321
+# endif
+# ifndef __NR_rt_tgsigqueueinfo
+# define __NR_rt_tgsigqueueinfo 322
+# endif
+# ifndef __NR_fanotify_init
+# define __NR_fanotify_init 323
+# endif
+# ifndef __NR_fanotify_mark
+# define __NR_fanotify_mark 324
+# endif
+# ifndef __NR_prlimit64
+# define __NR_prlimit64 325
+# endif
+# ifndef __NR_socket
+# define __NR_socket 326
+# endif
+# ifndef __NR_bind
+# define __NR_bind 327
+# endif
+# ifndef __NR_connect
+# define __NR_connect 328
+# endif
+# ifndef __NR_listen
+# define __NR_listen 329
+# endif
+# ifndef __NR_accept
+# define __NR_accept 330
+# endif
+# ifndef __NR_getsockname
+# define __NR_getsockname 331
+# endif
+# ifndef __NR_getpeername
+# define __NR_getpeername 332
+# endif
+# ifndef __NR_socketpair
+# define __NR_socketpair 333
+# endif
+# ifndef __NR_send
+# define __NR_send 334
+# endif
+# ifndef __NR_sendto
+# define __NR_sendto 335
+# endif
+# ifndef __NR_recv
+# define __NR_recv 336
+# endif
+# ifndef __NR_recvfrom
+# define __NR_recvfrom 337
+# endif
+# ifndef __NR_shutdown
+# define __NR_shutdown 338
+# endif
+# ifndef __NR_setsockopt
+# define __NR_setsockopt 339
+# endif
+# ifndef __NR_getsockopt
+# define __NR_getsockopt 340
+# endif
+# ifndef __NR_sendmsg
+# define __NR_sendmsg 341
+# endif
+# ifndef __NR_recvmsg
+# define __NR_recvmsg 342
+# endif
+# ifndef __NR_recvmmsg
+# define __NR_recvmmsg 343
+# endif
+# ifndef __NR_accept4
+# define __NR_accept4 344
+# endif
+# ifndef __NR_name_to_handle_at
+# define __NR_name_to_handle_at 345
+# endif
+# ifndef __NR_open_by_handle_at
+# define __NR_open_by_handle_at 346
+# endif
+# ifndef __NR_clock_adjtime
+# define __NR_clock_adjtime 347
+# endif
+# ifndef __NR_syncfs
+# define __NR_syncfs 348
+# endif
+# ifndef __NR_sendmmsg
+# define __NR_sendmmsg 349
+# endif
+# ifndef __NR_setns
+# define __NR_setns 350
+# endif
+# ifndef __NR_process_vm_readv
+# define __NR_process_vm_readv 351
+# endif
+# ifndef __NR_process_vm_writev
+# define __NR_process_vm_writev 352
+# endif
+# ifndef __NR_finit_module
+# define __NR_finit_module 353
+# endif
+# ifndef __NR_kcmp
+# define __NR_kcmp 354
+# endif
+# ifndef __NR_sched_setattr
+# define __NR_sched_setattr 355
+# endif
+# ifndef __NR_sched_getattr
+# define __NR_sched_getattr 356
+# endif
+# ifndef __NR_renameat2
+# define __NR_renameat2 357
+# endif
+# ifndef __NR_seccomp
+# define __NR_seccomp 358
+# endif
+# ifndef __NR_getrandom
+# define __NR_getrandom 359
+# endif
+# ifndef __NR_memfd_create
+# define __NR_memfd_create 360
+# endif
+# ifndef __NR_bpf
+# define __NR_bpf 361
+# endif
+# ifndef __NR_execveat
+# define __NR_execveat 362
+# endif
+# ifndef __NR_switch_endian
+# define __NR_switch_endian 363
+# endif
+# ifndef __NR_userfaultfd
+# define __NR_userfaultfd 364
+# endif
+# ifndef __NR_membarrier
+# define __NR_membarrier 365
+# endif
+# ifndef __NR_mlock2
+# define __NR_mlock2 378
+# endif
+# ifndef __NR_copy_file_range
+# define __NR_copy_file_range 379
+# endif
+# ifndef __NR_preadv2
+# define __NR_preadv2 380
+# endif
+# ifndef __NR_pwritev2
+# define __NR_pwritev2 381
+# endif
+# ifndef __NR_kexec_file_load
+# define __NR_kexec_file_load 382
+# endif
+# ifndef __NR_statx
+# define __NR_statx 383
+# endif
+# ifndef __NR_pkey_alloc
+# define __NR_pkey_alloc 384
+# endif
+# ifndef __NR_pkey_free
+# define __NR_pkey_free 385
+# endif
+# ifndef __NR_pkey_mprotect
+# define __NR_pkey_mprotect 386
+# endif
+# ifndef __NR_rseq
+# define __NR_rseq 387
+# endif
+# ifndef __NR_io_pgetevents
+# define __NR_io_pgetevents 388
+# endif
+# ifndef __NR_semtimedop
+# define __NR_semtimedop 392
+# endif
+# ifndef __NR_semget
+# define __NR_semget 393
+# endif
+# ifndef __NR_semctl
+# define __NR_semctl 394
+# endif
+# ifndef __NR_shmget
+# define __NR_shmget 395
+# endif
+# ifndef __NR_shmctl
+# define __NR_shmctl 396
+# endif
+# ifndef __NR_shmat
+# define __NR_shmat 397
+# endif
+# ifndef __NR_shmdt
+# define __NR_shmdt 398
+# endif
+# ifndef __NR_msgget
+# define __NR_msgget 399
+# endif
+# ifndef __NR_msgsnd
+# define __NR_msgsnd 400
+# endif
+# ifndef __NR_msgrcv
+# define __NR_msgrcv 401
+# endif
+# ifndef __NR_msgctl
+# define __NR_msgctl 402
+# endif
+# ifndef __NR_clock_gettime64
+# define __NR_clock_gettime64 403
+# endif
+# ifndef __NR_clock_settime64
+# define __NR_clock_settime64 404
+# endif
+# ifndef __NR_clock_adjtime64
+# define __NR_clock_adjtime64 405
+# endif
+# ifndef __NR_clock_getres_time64
+# define __NR_clock_getres_time64 406
+# endif
+# ifndef __NR_clock_nanosleep_time64
+# define __NR_clock_nanosleep_time64 407
+# endif
+# ifndef __NR_timer_gettime64
+# define __NR_timer_gettime64 408
+# endif
+# ifndef __NR_timer_settime64
+# define __NR_timer_settime64 409
+# endif
+# ifndef __NR_timerfd_gettime64
+# define __NR_timerfd_gettime64 410
+# endif
+# ifndef __NR_timerfd_settime64
+# define __NR_timerfd_settime64 411
+# endif
+# ifndef __NR_utimensat_time64
+# define __NR_utimensat_time64 412
+# endif
+# ifndef __NR_pselect6_time64
+# define __NR_pselect6_time64 413
+# endif
+# ifndef __NR_ppoll_time64
+# define __NR_ppoll_time64 414
+# endif
+# ifndef __NR_io_pgetevents_time64
+# define __NR_io_pgetevents_time64 416
+# endif
+# ifndef __NR_recvmmsg_time64
+# define __NR_recvmmsg_time64 417
+# endif
+# ifndef __NR_mq_timedsend_time64
+# define __NR_mq_timedsend_time64 418
+# endif
+# ifndef __NR_mq_timedreceive_time64
+# define __NR_mq_timedreceive_time64 419
+# endif
+# ifndef __NR_semtimedop_time64
+# define __NR_semtimedop_time64 420
+# endif
+# ifndef __NR_rt_sigtimedwait_time64
+# define __NR_rt_sigtimedwait_time64 421
+# endif
+# ifndef __NR_futex_time64
+# define __NR_futex_time64 422
+# endif
+# ifndef __NR_sched_rr_get_interval_time64
+# define __NR_sched_rr_get_interval_time64 423
+# endif
+# ifndef __NR_pidfd_send_signal
+# define __NR_pidfd_send_signal 424
+# endif
+# ifndef __NR_io_uring_setup
+# define __NR_io_uring_setup 425
+# endif
+# ifndef __NR_io_uring_enter
+# define __NR_io_uring_enter 426
+# endif
+# ifndef __NR_io_uring_register
+# define __NR_io_uring_register 427
+# endif
+# ifndef __NR_open_tree
+# define __NR_open_tree 428
+# endif
+# ifndef __NR_move_mount
+# define __NR_move_mount 429
+# endif
+# ifndef __NR_fsopen
+# define __NR_fsopen 430
+# endif
+# ifndef __NR_fsconfig
+# define __NR_fsconfig 431
+# endif
+# ifndef __NR_fsmount
+# define __NR_fsmount 432
+# endif
+# ifndef __NR_fspick
+# define __NR_fspick 433
+# endif
+# ifndef __NR_pidfd_open
+# define __NR_pidfd_open 434
+# endif
+# ifndef __NR_clone3
+# define __NR_clone3 435
+# endif
+# ifndef __NR_openat2
+# define __NR_openat2 437
+# endif
+# ifndef __NR_pidfd_getfd
+# define __NR_pidfd_getfd 438
+# endif
+#endif
+
+
+#ifdef __s390x__
+# ifndef __NR_exit
+# define __NR_exit 1
+# endif
+# ifndef __NR_fork
+# define __NR_fork 2
+# endif
+# ifndef __NR_read
+# define __NR_read 3
+# endif
+# ifndef __NR_write
+# define __NR_write 4
+# endif
+# ifndef __NR_open
+# define __NR_open 5
+# endif
+# ifndef __NR_close
+# define __NR_close 6
+# endif
+# ifndef __NR_restart_syscall
+# define __NR_restart_syscall 7
+# endif
+# ifndef __NR_creat
+# define __NR_creat 8
+# endif
+# ifndef __NR_link
+# define __NR_link 9
+# endif
+# ifndef __NR_unlink
+# define __NR_unlink 10
+# endif
+# ifndef __NR_execve
+# define __NR_execve 11
+# endif
+# ifndef __NR_chdir
+# define __NR_chdir 12
+# endif
+# ifndef __NR_mknod
+# define __NR_mknod 14
+# endif
+# ifndef __NR_chmod
+# define __NR_chmod 15
+# endif
+# ifndef __NR_lseek
+# define __NR_lseek 19
+# endif
+# ifndef __NR_getpid
+# define __NR_getpid 20
+# endif
+# ifndef __NR_mount
+# define __NR_mount 21
+# endif
+# ifndef __NR_umount
+# define __NR_umount 22
+# endif
+# ifndef __NR_ptrace
+# define __NR_ptrace 26
+# endif
+# ifndef __NR_alarm
+# define __NR_alarm 27
+# endif
+# ifndef __NR_pause
+# define __NR_pause 29
+# endif
+# ifndef __NR_utime
+# define __NR_utime 30
+# endif
+# ifndef __NR_access
+# define __NR_access 33
+# endif
+# ifndef __NR_nice
+# define __NR_nice 34
+# endif
+# ifndef __NR_sync
+# define __NR_sync 36
+# endif
+# ifndef __NR_kill
+# define __NR_kill 37
+# endif
+# ifndef __NR_rename
+# define __NR_rename 38
+# endif
+# ifndef __NR_mkdir
+# define __NR_mkdir 39
+# endif
+# ifndef __NR_rmdir
+# define __NR_rmdir 40
+# endif
+# ifndef __NR_dup
+# define __NR_dup 41
+# endif
+# ifndef __NR_pipe
+# define __NR_pipe 42
+# endif
+# ifndef __NR_times
+# define __NR_times 43
+# endif
+# ifndef __NR_brk
+# define __NR_brk 45
+# endif
+# ifndef __NR_signal
+# define __NR_signal 48
+# endif
+# ifndef __NR_acct
+# define __NR_acct 51
+# endif
+# ifndef __NR_umount2
+# define __NR_umount2 52
+# endif
+# ifndef __NR_ioctl
+# define __NR_ioctl 54
+# endif
+# ifndef __NR_fcntl
+# define __NR_fcntl 55
+# endif
+# ifndef __NR_setpgid
+# define __NR_setpgid 57
+# endif
+# ifndef __NR_umask
+# define __NR_umask 60
+# endif
+# ifndef __NR_chroot
+# define __NR_chroot 61
+# endif
+# ifndef __NR_ustat
+# define __NR_ustat 62
+# endif
+# ifndef __NR_dup2
+# define __NR_dup2 63
+# endif
+# ifndef __NR_getppid
+# define __NR_getppid 64
+# endif
+# ifndef __NR_getpgrp
+# define __NR_getpgrp 65
+# endif
+# ifndef __NR_setsid
+# define __NR_setsid 66
+# endif
+# ifndef __NR_sigaction
+# define __NR_sigaction 67
+# endif
+# ifndef __NR_sigsuspend
+# define __NR_sigsuspend 72
+# endif
+# ifndef __NR_sigpending
+# define __NR_sigpending 73
+# endif
+# ifndef __NR_sethostname
+# define __NR_sethostname 74
+# endif
+# ifndef __NR_setrlimit
+# define __NR_setrlimit 75
+# endif
+# ifndef __NR_getrusage
+# define __NR_getrusage 77
+# endif
+# ifndef __NR_gettimeofday
+# define __NR_gettimeofday 78
+# endif
+# ifndef __NR_settimeofday
+# define __NR_settimeofday 79
+# endif
+# ifndef __NR_symlink
+# define __NR_symlink 83
+# endif
+# ifndef __NR_readlink
+# define __NR_readlink 85
+# endif
+# ifndef __NR_uselib
+# define __NR_uselib 86
+# endif
+# ifndef __NR_swapon
+# define __NR_swapon 87
+# endif
+# ifndef __NR_reboot
+# define __NR_reboot 88
+# endif
+# ifndef __NR_readdir
+# define __NR_readdir 89
+# endif
+# ifndef __NR_mmap
+# define __NR_mmap 90
+# endif
+# ifndef __NR_munmap
+# define __NR_munmap 91
+# endif
+# ifndef __NR_truncate
+# define __NR_truncate 92
+# endif
+# ifndef __NR_ftruncate
+# define __NR_ftruncate 93
+# endif
+# ifndef __NR_fchmod
+# define __NR_fchmod 94
+# endif
+# ifndef __NR_getpriority
+# define __NR_getpriority 96
+# endif
+# ifndef __NR_setpriority
+# define __NR_setpriority 97
+# endif
+# ifndef __NR_statfs
+# define __NR_statfs 99
+# endif
+# ifndef __NR_fstatfs
+# define __NR_fstatfs 100
+# endif
+# ifndef __NR_socketcall
+# define __NR_socketcall 102
+# endif
+# ifndef __NR_syslog
+# define __NR_syslog 103
+# endif
+# ifndef __NR_setitimer
+# define __NR_setitimer 104
+# endif
+# ifndef __NR_getitimer
+# define __NR_getitimer 105
+# endif
+# ifndef __NR_stat
+# define __NR_stat 106
+# endif
+# ifndef __NR_lstat
+# define __NR_lstat 107
+# endif
+# ifndef __NR_fstat
+# define __NR_fstat 108
+# endif
+# ifndef __NR_lookup_dcookie
+# define __NR_lookup_dcookie 110
+# endif
+# ifndef __NR_vhangup
+# define __NR_vhangup 111
+# endif
+# ifndef __NR_idle
+# define __NR_idle 112
+# endif
+# ifndef __NR_wait4
+# define __NR_wait4 114
+# endif
+# ifndef __NR_swapoff
+# define __NR_swapoff 115
+# endif
+# ifndef __NR_sysinfo
+# define __NR_sysinfo 116
+# endif
+# ifndef __NR_ipc
+# define __NR_ipc 117
+# endif
+# ifndef __NR_fsync
+# define __NR_fsync 118
+# endif
+# ifndef __NR_sigreturn
+# define __NR_sigreturn 119
+# endif
+# ifndef __NR_clone
+# define __NR_clone 120
+# endif
+# ifndef __NR_setdomainname
+# define __NR_setdomainname 121
+# endif
+# ifndef __NR_uname
+# define __NR_uname 122
+# endif
+# ifndef __NR_adjtimex
+# define __NR_adjtimex 124
+# endif
+# ifndef __NR_mprotect
+# define __NR_mprotect 125
+# endif
+# ifndef __NR_sigprocmask
+# define __NR_sigprocmask 126
+# endif
+# ifndef __NR_create_module
+# define __NR_create_module 127
+# endif
+# ifndef __NR_init_module
+# define __NR_init_module 128
+# endif
+# ifndef __NR_delete_module
+# define __NR_delete_module 129
+# endif
+# ifndef __NR_get_kernel_syms
+# define __NR_get_kernel_syms 130
+# endif
+# ifndef __NR_quotactl
+# define __NR_quotactl 131
+# endif
+# ifndef __NR_getpgid
+# define __NR_getpgid 132
+# endif
+# ifndef __NR_fchdir
+# define __NR_fchdir 133
+# endif
+# ifndef __NR_bdflush
+# define __NR_bdflush 134
+# endif
+# ifndef __NR_sysfs
+# define __NR_sysfs 135
+# endif
+# ifndef __NR_personality
+# define __NR_personality 136
+# endif
+# ifndef __NR_afs_syscall
+# define __NR_afs_syscall 137
+# endif
+# ifndef __NR_getdents
+# define __NR_getdents 141
+# endif
+# ifndef __NR_select
+# define __NR_select 142
+# endif
+# ifndef __NR_flock
+# define __NR_flock 143
+# endif
+# ifndef __NR_msync
+# define __NR_msync 144
+# endif
+# ifndef __NR_readv
+# define __NR_readv 145
+# endif
+# ifndef __NR_writev
+# define __NR_writev 146
+# endif
+# ifndef __NR_getsid
+# define __NR_getsid 147
+# endif
+# ifndef __NR_fdatasync
+# define __NR_fdatasync 148
+# endif
+# ifndef __NR__sysctl
+# define __NR__sysctl 149
+# endif
+# ifndef __NR_mlock
+# define __NR_mlock 150
+# endif
+# ifndef __NR_munlock
+# define __NR_munlock 151
+# endif
+# ifndef __NR_mlockall
+# define __NR_mlockall 152
+# endif
+# ifndef __NR_munlockall
+# define __NR_munlockall 153
+# endif
+# ifndef __NR_sched_setparam
+# define __NR_sched_setparam 154
+# endif
+# ifndef __NR_sched_getparam
+# define __NR_sched_getparam 155
+# endif
+# ifndef __NR_sched_setscheduler
+# define __NR_sched_setscheduler 156
+# endif
+# ifndef __NR_sched_getscheduler
+# define __NR_sched_getscheduler 157
+# endif
+# ifndef __NR_sched_yield
+# define __NR_sched_yield 158
+# endif
+# ifndef __NR_sched_get_priority_max
+# define __NR_sched_get_priority_max 159
+# endif
+# ifndef __NR_sched_get_priority_min
+# define __NR_sched_get_priority_min 160
+# endif
+# ifndef __NR_sched_rr_get_interval
+# define __NR_sched_rr_get_interval 161
+# endif
+# ifndef __NR_nanosleep
+# define __NR_nanosleep 162
+# endif
+# ifndef __NR_mremap
+# define __NR_mremap 163
+# endif
+# ifndef __NR_query_module
+# define __NR_query_module 167
+# endif
+# ifndef __NR_poll
+# define __NR_poll 168
+# endif
+# ifndef __NR_nfsservctl
+# define __NR_nfsservctl 169
+# endif
+# ifndef __NR_prctl
+# define __NR_prctl 172
+# endif
+# ifndef __NR_rt_sigreturn
+# define __NR_rt_sigreturn 173
+# endif
+# ifndef __NR_rt_sigaction
+# define __NR_rt_sigaction 174
+# endif
+# ifndef __NR_rt_sigprocmask
+# define __NR_rt_sigprocmask 175
+# endif
+# ifndef __NR_rt_sigpending
+# define __NR_rt_sigpending 176
+# endif
+# ifndef __NR_rt_sigtimedwait
+# define __NR_rt_sigtimedwait 177
+# endif
+# ifndef __NR_rt_sigqueueinfo
+# define __NR_rt_sigqueueinfo 178
+# endif
+# ifndef __NR_rt_sigsuspend
+# define __NR_rt_sigsuspend 179
+# endif
+# ifndef __NR_pread64
+# define __NR_pread64 180
+# endif
+# ifndef __NR_pwrite64
+# define __NR_pwrite64 181
+# endif
+# ifndef __NR_getcwd
+# define __NR_getcwd 183
+# endif
+# ifndef __NR_capget
+# define __NR_capget 184
+# endif
+# ifndef __NR_capset
+# define __NR_capset 185
+# endif
+# ifndef __NR_sigaltstack
+# define __NR_sigaltstack 186
+# endif
+# ifndef __NR_sendfile
+# define __NR_sendfile 187
+# endif
+# ifndef __NR_getpmsg
+# define __NR_getpmsg 188
+# endif
+# ifndef __NR_putpmsg
+# define __NR_putpmsg 189
+# endif
+# ifndef __NR_vfork
+# define __NR_vfork 190
+# endif
+# ifndef __NR_getrlimit
+# define __NR_getrlimit 191
+# endif
+# ifndef __NR_lchown
+# define __NR_lchown 198
+# endif
+# ifndef __NR_getuid
+# define __NR_getuid 199
+# endif
+# ifndef __NR_getgid
+# define __NR_getgid 200
+# endif
+# ifndef __NR_geteuid
+# define __NR_geteuid 201
+# endif
+# ifndef __NR_getegid
+# define __NR_getegid 202
+# endif
+# ifndef __NR_setreuid
+# define __NR_setreuid 203
+# endif
+# ifndef __NR_setregid
+# define __NR_setregid 204
+# endif
+# ifndef __NR_getgroups
+# define __NR_getgroups 205
+# endif
+# ifndef __NR_setgroups
+# define __NR_setgroups 206
+# endif
+# ifndef __NR_fchown
+# define __NR_fchown 207
+# endif
+# ifndef __NR_setresuid
+# define __NR_setresuid 208
+# endif
+# ifndef __NR_getresuid
+# define __NR_getresuid 209
+# endif
+# ifndef __NR_setresgid
+# define __NR_setresgid 210
+# endif
+# ifndef __NR_getresgid
+# define __NR_getresgid 211
+# endif
+# ifndef __NR_chown
+# define __NR_chown 212
+# endif
+# ifndef __NR_setuid
+# define __NR_setuid 213
+# endif
+# ifndef __NR_setgid
+# define __NR_setgid 214
+# endif
+# ifndef __NR_setfsuid
+# define __NR_setfsuid 215
+# endif
+# ifndef __NR_setfsgid
+# define __NR_setfsgid 216
+# endif
+# ifndef __NR_pivot_root
+# define __NR_pivot_root 217
+# endif
+# ifndef __NR_mincore
+# define __NR_mincore 218
+# endif
+# ifndef __NR_madvise
+# define __NR_madvise 219
+# endif
+# ifndef __NR_getdents64
+# define __NR_getdents64 220
+# endif
+# ifndef __NR_readahead
+# define __NR_readahead 222
+# endif
+# ifndef __NR_setxattr
+# define __NR_setxattr 224
+# endif
+# ifndef __NR_lsetxattr
+# define __NR_lsetxattr 225
+# endif
+# ifndef __NR_fsetxattr
+# define __NR_fsetxattr 226
+# endif
+# ifndef __NR_getxattr
+# define __NR_getxattr 227
+# endif
+# ifndef __NR_lgetxattr
+# define __NR_lgetxattr 228
+# endif
+# ifndef __NR_fgetxattr
+# define __NR_fgetxattr 229
+# endif
+# ifndef __NR_listxattr
+# define __NR_listxattr 230
+# endif
+# ifndef __NR_llistxattr
+# define __NR_llistxattr 231
+# endif
+# ifndef __NR_flistxattr
+# define __NR_flistxattr 232
+# endif
+# ifndef __NR_removexattr
+# define __NR_removexattr 233
+# endif
+# ifndef __NR_lremovexattr
+# define __NR_lremovexattr 234
+# endif
+# ifndef __NR_fremovexattr
+# define __NR_fremovexattr 235
+# endif
+# ifndef __NR_gettid
+# define __NR_gettid 236
+# endif
+# ifndef __NR_tkill
+# define __NR_tkill 237
+# endif
+# ifndef __NR_futex
+# define __NR_futex 238
+# endif
+# ifndef __NR_sched_setaffinity
+# define __NR_sched_setaffinity 239
+# endif
+# ifndef __NR_sched_getaffinity
+# define __NR_sched_getaffinity 240
+# endif
+# ifndef __NR_tgkill
+# define __NR_tgkill 241
+# endif
+# ifndef __NR_io_setup
+# define __NR_io_setup 243
+# endif
+# ifndef __NR_io_destroy
+# define __NR_io_destroy 244
+# endif
+# ifndef __NR_io_getevents
+# define __NR_io_getevents 245
+# endif
+# ifndef __NR_io_submit
+# define __NR_io_submit 246
+# endif
+# ifndef __NR_io_cancel
+# define __NR_io_cancel 247
+# endif
+# ifndef __NR_exit_group
+# define __NR_exit_group 248
+# endif
+# ifndef __NR_epoll_create
+# define __NR_epoll_create 249
+# endif
+# ifndef __NR_epoll_ctl
+# define __NR_epoll_ctl 250
+# endif
+# ifndef __NR_epoll_wait
+# define __NR_epoll_wait 251
+# endif
+# ifndef __NR_set_tid_address
+# define __NR_set_tid_address 252
+# endif
+# ifndef __NR_fadvise64
+# define __NR_fadvise64 253
+# endif
+# ifndef __NR_timer_create
+# define __NR_timer_create 254
+# endif
+# ifndef __NR_timer_settime
+# define __NR_timer_settime 255
+# endif
+# ifndef __NR_timer_gettime
+# define __NR_timer_gettime 256
+# endif
+# ifndef __NR_timer_getoverrun
+# define __NR_timer_getoverrun 257
+# endif
+# ifndef __NR_timer_delete
+# define __NR_timer_delete 258
+# endif
+# ifndef __NR_clock_settime
+# define __NR_clock_settime 259
+# endif
+# ifndef __NR_clock_gettime
+# define __NR_clock_gettime 260
+# endif
+# ifndef __NR_clock_getres
+# define __NR_clock_getres 261
+# endif
+# ifndef __NR_clock_nanosleep
+# define __NR_clock_nanosleep 262
+# endif
+# ifndef __NR_statfs64
+# define __NR_statfs64 265
+# endif
+# ifndef __NR_fstatfs64
+# define __NR_fstatfs64 266
+# endif
+# ifndef __NR_remap_file_pages
+# define __NR_remap_file_pages 267
+# endif
+# ifndef __NR_mbind
+# define __NR_mbind 268
+# endif
+# ifndef __NR_get_mempolicy
+# define __NR_get_mempolicy 269
+# endif
+# ifndef __NR_set_mempolicy
+# define __NR_set_mempolicy 270
+# endif
+# ifndef __NR_mq_open
+# define __NR_mq_open 271
+# endif
+# ifndef __NR_mq_unlink
+# define __NR_mq_unlink 272
+# endif
+# ifndef __NR_mq_timedsend
+# define __NR_mq_timedsend 273
+# endif
+# ifndef __NR_mq_timedreceive
+# define __NR_mq_timedreceive 274
+# endif
+# ifndef __NR_mq_notify
+# define __NR_mq_notify 275
+# endif
+# ifndef __NR_mq_getsetattr
+# define __NR_mq_getsetattr 276
+# endif
+# ifndef __NR_kexec_load
+# define __NR_kexec_load 277
+# endif
+# ifndef __NR_add_key
+# define __NR_add_key 278
+# endif
+# ifndef __NR_request_key
+# define __NR_request_key 279
+# endif
+# ifndef __NR_keyctl
+# define __NR_keyctl 280
+# endif
+# ifndef __NR_waitid
+# define __NR_waitid 281
+# endif
+# ifndef __NR_ioprio_set
+# define __NR_ioprio_set 282
+# endif
+# ifndef __NR_ioprio_get
+# define __NR_ioprio_get 283
+# endif
+# ifndef __NR_inotify_init
+# define __NR_inotify_init 284
+# endif
+# ifndef __NR_inotify_add_watch
+# define __NR_inotify_add_watch 285
+# endif
+# ifndef __NR_inotify_rm_watch
+# define __NR_inotify_rm_watch 286
+# endif
+# ifndef __NR_migrate_pages
+# define __NR_migrate_pages 287
+# endif
+# ifndef __NR_openat
+# define __NR_openat 288
+# endif
+# ifndef __NR_mkdirat
+# define __NR_mkdirat 289
+# endif
+# ifndef __NR_mknodat
+# define __NR_mknodat 290
+# endif
+# ifndef __NR_fchownat
+# define __NR_fchownat 291
+# endif
+# ifndef __NR_futimesat
+# define __NR_futimesat 292
+# endif
+# ifndef __NR_newfstatat
+# define __NR_newfstatat 293
+# endif
+# ifndef __NR_unlinkat
+# define __NR_unlinkat 294
+# endif
+# ifndef __NR_renameat
+# define __NR_renameat 295
+# endif
+# ifndef __NR_linkat
+# define __NR_linkat 296
+# endif
+# ifndef __NR_symlinkat
+# define __NR_symlinkat 297
+# endif
+# ifndef __NR_readlinkat
+# define __NR_readlinkat 298
+# endif
+# ifndef __NR_fchmodat
+# define __NR_fchmodat 299
+# endif
+# ifndef __NR_faccessat
+# define __NR_faccessat 300
+# endif
+# ifndef __NR_pselect6
+# define __NR_pselect6 301
+# endif
+# ifndef __NR_ppoll
+# define __NR_ppoll 302
+# endif
+# ifndef __NR_unshare
+# define __NR_unshare 303
+# endif
+# ifndef __NR_set_robust_list
+# define __NR_set_robust_list 304
+# endif
+# ifndef __NR_get_robust_list
+# define __NR_get_robust_list 305
+# endif
+# ifndef __NR_splice
+# define __NR_splice 306
+# endif
+# ifndef __NR_sync_file_range
+# define __NR_sync_file_range 307
+# endif
+# ifndef __NR_tee
+# define __NR_tee 308
+# endif
+# ifndef __NR_vmsplice
+# define __NR_vmsplice 309
+# endif
+# ifndef __NR_move_pages
+# define __NR_move_pages 310
+# endif
+# ifndef __NR_getcpu
+# define __NR_getcpu 311
+# endif
+# ifndef __NR_epoll_pwait
+# define __NR_epoll_pwait 312
+# endif
+# ifndef __NR_utimes
+# define __NR_utimes 313
+# endif
+# ifndef __NR_fallocate
+# define __NR_fallocate 314
+# endif
+# ifndef __NR_utimensat
+# define __NR_utimensat 315
+# endif
+# ifndef __NR_signalfd
+# define __NR_signalfd 316
+# endif
+# ifndef __NR_timerfd
+# define __NR_timerfd 317
+# endif
+# ifndef __NR_eventfd
+# define __NR_eventfd 318
+# endif
+# ifndef __NR_timerfd_create
+# define __NR_timerfd_create 319
+# endif
+# ifndef __NR_timerfd_settime
+# define __NR_timerfd_settime 320
+# endif
+# ifndef __NR_timerfd_gettime
+# define __NR_timerfd_gettime 321
+# endif
+# ifndef __NR_signalfd4
+# define __NR_signalfd4 322
+# endif
+# ifndef __NR_eventfd2
+# define __NR_eventfd2 323
+# endif
+# ifndef __NR_inotify_init1
+# define __NR_inotify_init1 324
+# endif
+# ifndef __NR_pipe2
+# define __NR_pipe2 325
+# endif
+# ifndef __NR_dup3
+# define __NR_dup3 326
+# endif
+# ifndef __NR_epoll_create1
+# define __NR_epoll_create1 327
+# endif
+# ifndef __NR_preadv
+# define __NR_preadv 328
+# endif
+# ifndef __NR_pwritev
+# define __NR_pwritev 329
+# endif
+# ifndef __NR_rt_tgsigqueueinfo
+# define __NR_rt_tgsigqueueinfo 330
+# endif
+# ifndef __NR_perf_event_open
+# define __NR_perf_event_open 331
+# endif
+# ifndef __NR_fanotify_init
+# define __NR_fanotify_init 332
+# endif
+# ifndef __NR_fanotify_mark
+# define __NR_fanotify_mark 333
+# endif
+# ifndef __NR_prlimit64
+# define __NR_prlimit64 334
+# endif
+# ifndef __NR_name_to_handle_at
+# define __NR_name_to_handle_at 335
+# endif
+# ifndef __NR_open_by_handle_at
+# define __NR_open_by_handle_at 336
+# endif
+# ifndef __NR_clock_adjtime
+# define __NR_clock_adjtime 337
+# endif
+# ifndef __NR_syncfs
+# define __NR_syncfs 338
+# endif
+# ifndef __NR_setns
+# define __NR_setns 339
+# endif
+# ifndef __NR_process_vm_readv
+# define __NR_process_vm_readv 340
+# endif
+# ifndef __NR_process_vm_writev
+# define __NR_process_vm_writev 341
+# endif
+# ifndef __NR_s390_runtime_instr
+# define __NR_s390_runtime_instr 342
+# endif
+# ifndef __NR_kcmp
+# define __NR_kcmp 343
+# endif
+# ifndef __NR_finit_module
+# define __NR_finit_module 344
+# endif
+# ifndef __NR_sched_setattr
+# define __NR_sched_setattr 345
+# endif
+# ifndef __NR_sched_getattr
+# define __NR_sched_getattr 346
+# endif
+# ifndef __NR_renameat2
+# define __NR_renameat2 347
+# endif
+# ifndef __NR_seccomp
+# define __NR_seccomp 348
+# endif
+# ifndef __NR_getrandom
+# define __NR_getrandom 349
+# endif
+# ifndef __NR_memfd_create
+# define __NR_memfd_create 350
+# endif
+# ifndef __NR_bpf
+# define __NR_bpf 351
+# endif
+# ifndef __NR_s390_pci_mmio_write
+# define __NR_s390_pci_mmio_write 352
+# endif
+# ifndef __NR_s390_pci_mmio_read
+# define __NR_s390_pci_mmio_read 353
+# endif
+# ifndef __NR_execveat
+# define __NR_execveat 354
+# endif
+# ifndef __NR_userfaultfd
+# define __NR_userfaultfd 355
+# endif
+# ifndef __NR_membarrier
+# define __NR_membarrier 356
+# endif
+# ifndef __NR_recvmmsg
+# define __NR_recvmmsg 357
+# endif
+# ifndef __NR_sendmmsg
+# define __NR_sendmmsg 358
+# endif
+# ifndef __NR_socket
+# define __NR_socket 359
+# endif
+# ifndef __NR_socketpair
+# define __NR_socketpair 360
+# endif
+# ifndef __NR_bind
+# define __NR_bind 361
+# endif
+# ifndef __NR_connect
+# define __NR_connect 362
+# endif
+# ifndef __NR_listen
+# define __NR_listen 363
+# endif
+# ifndef __NR_accept4
+# define __NR_accept4 364
+# endif
+# ifndef __NR_getsockopt
+# define __NR_getsockopt 365
+# endif
+# ifndef __NR_setsockopt
+# define __NR_setsockopt 366
+# endif
+# ifndef __NR_getsockname
+# define __NR_getsockname 367
+# endif
+# ifndef __NR_getpeername
+# define __NR_getpeername 368
+# endif
+# ifndef __NR_sendto
+# define __NR_sendto 369
+# endif
+# ifndef __NR_sendmsg
+# define __NR_sendmsg 370
+# endif
+# ifndef __NR_recvfrom
+# define __NR_recvfrom 371
+# endif
+# ifndef __NR_recvmsg
+# define __NR_recvmsg 372
+# endif
+# ifndef __NR_shutdown
+# define __NR_shutdown 373
+# endif
+# ifndef __NR_mlock2
+# define __NR_mlock2 374
+# endif
+# ifndef __NR_copy_file_range
+# define __NR_copy_file_range 375
+# endif
+# ifndef __NR_preadv2
+# define __NR_preadv2 376
+# endif
+# ifndef __NR_pwritev2
+# define __NR_pwritev2 377
+# endif
+# ifndef __NR_s390_guarded_storage
+# define __NR_s390_guarded_storage 378
+# endif
+# ifndef __NR_statx
+# define __NR_statx 379
+# endif
+# ifndef __NR_s390_sthyi
+# define __NR_s390_sthyi 380
+# endif
+# ifndef __NR_kexec_file_load
+# define __NR_kexec_file_load 381
+# endif
+# ifndef __NR_io_pgetevents
+# define __NR_io_pgetevents 382
+# endif
+# ifndef __NR_rseq
+# define __NR_rseq 383
+# endif
+# ifndef __NR_pkey_mprotect
+# define __NR_pkey_mprotect 384
+# endif
+# ifndef __NR_pkey_alloc
+# define __NR_pkey_alloc 385
+# endif
+# ifndef __NR_pkey_free
+# define __NR_pkey_free 386
+# endif
+# ifndef __NR_semtimedop
+# define __NR_semtimedop 392
+# endif
+# ifndef __NR_semget
+# define __NR_semget 393
+# endif
+# ifndef __NR_semctl
+# define __NR_semctl 394
+# endif
+# ifndef __NR_shmget
+# define __NR_shmget 395
+# endif
+# ifndef __NR_shmctl
+# define __NR_shmctl 396
+# endif
+# ifndef __NR_shmat
+# define __NR_shmat 397
+# endif
+# ifndef __NR_shmdt
+# define __NR_shmdt 398
+# endif
+# ifndef __NR_msgget
+# define __NR_msgget 399
+# endif
+# ifndef __NR_msgsnd
+# define __NR_msgsnd 400
+# endif
+# ifndef __NR_msgrcv
+# define __NR_msgrcv 401
+# endif
+# ifndef __NR_msgctl
+# define __NR_msgctl 402
+# endif
+# ifndef __NR_pidfd_send_signal
+# define __NR_pidfd_send_signal 424
+# endif
+# ifndef __NR_io_uring_setup
+# define __NR_io_uring_setup 425
+# endif
+# ifndef __NR_io_uring_enter
+# define __NR_io_uring_enter 426
+# endif
+# ifndef __NR_io_uring_register
+# define __NR_io_uring_register 427
+# endif
+# ifndef __NR_open_tree
+# define __NR_open_tree 428
+# endif
+# ifndef __NR_move_mount
+# define __NR_move_mount 429
+# endif
+# ifndef __NR_fsopen
+# define __NR_fsopen 430
+# endif
+# ifndef __NR_fsconfig
+# define __NR_fsconfig 431
+# endif
+# ifndef __NR_fsmount
+# define __NR_fsmount 432
+# endif
+# ifndef __NR_fspick
+# define __NR_fspick 433
+# endif
+# ifndef __NR_pidfd_open
+# define __NR_pidfd_open 434
+# endif
+# ifndef __NR_clone3
+# define __NR_clone3 435
+# endif
+# ifndef __NR_openat2
+# define __NR_openat2 437
+# endif
+# ifndef __NR_pidfd_getfd
+# define __NR_pidfd_getfd 438
+# endif
+#endif
+
+
+#if defined(__s390__) && !defined(__s390x__)
+# ifndef __NR_exit
+# define __NR_exit 1
+# endif
+# ifndef __NR_fork
+# define __NR_fork 2
+# endif
+# ifndef __NR_read
+# define __NR_read 3
+# endif
+# ifndef __NR_write
+# define __NR_write 4
+# endif
+# ifndef __NR_open
+# define __NR_open 5
+# endif
+# ifndef __NR_close
+# define __NR_close 6
+# endif
+# ifndef __NR_restart_syscall
+# define __NR_restart_syscall 7
+# endif
+# ifndef __NR_creat
+# define __NR_creat 8
+# endif
+# ifndef __NR_link
+# define __NR_link 9
+# endif
+# ifndef __NR_unlink
+# define __NR_unlink 10
+# endif
+# ifndef __NR_execve
+# define __NR_execve 11
+# endif
+# ifndef __NR_chdir
+# define __NR_chdir 12
+# endif
+# ifndef __NR_time
+# define __NR_time 13
+# endif
+# ifndef __NR_mknod
+# define __NR_mknod 14
+# endif
+# ifndef __NR_chmod
+# define __NR_chmod 15
+# endif
+# ifndef __NR_lchown
+# define __NR_lchown 16
+# endif
+# ifndef __NR_lseek
+# define __NR_lseek 19
+# endif
+# ifndef __NR_getpid
+# define __NR_getpid 20
+# endif
+# ifndef __NR_mount
+# define __NR_mount 21
+# endif
+# ifndef __NR_umount
+# define __NR_umount 22
+# endif
+# ifndef __NR_setuid
+# define __NR_setuid 23
+# endif
+# ifndef __NR_getuid
+# define __NR_getuid 24
+# endif
+# ifndef __NR_stime
+# define __NR_stime 25
+# endif
+# ifndef __NR_ptrace
+# define __NR_ptrace 26
+# endif
+# ifndef __NR_alarm
+# define __NR_alarm 27
+# endif
+# ifndef __NR_pause
+# define __NR_pause 29
+# endif
+# ifndef __NR_utime
+# define __NR_utime 30
+# endif
+# ifndef __NR_access
+# define __NR_access 33
+# endif
+# ifndef __NR_nice
+# define __NR_nice 34
+# endif
+# ifndef __NR_sync
+# define __NR_sync 36
+# endif
+# ifndef __NR_kill
+# define __NR_kill 37
+# endif
+# ifndef __NR_rename
+# define __NR_rename 38
+# endif
+# ifndef __NR_mkdir
+# define __NR_mkdir 39
+# endif
+# ifndef __NR_rmdir
+# define __NR_rmdir 40
+# endif
+# ifndef __NR_dup
+# define __NR_dup 41
+# endif
+# ifndef __NR_pipe
+# define __NR_pipe 42
+# endif
+# ifndef __NR_times
+# define __NR_times 43
+# endif
+# ifndef __NR_brk
+# define __NR_brk 45
+# endif
+# ifndef __NR_setgid
+# define __NR_setgid 46
+# endif
+# ifndef __NR_getgid
+# define __NR_getgid 47
+# endif
+# ifndef __NR_signal
+# define __NR_signal 48
+# endif
+# ifndef __NR_geteuid
+# define __NR_geteuid 49
+# endif
+# ifndef __NR_getegid
+# define __NR_getegid 50
+# endif
+# ifndef __NR_acct
+# define __NR_acct 51
+# endif
+# ifndef __NR_umount2
+# define __NR_umount2 52
+# endif
+# ifndef __NR_ioctl
+# define __NR_ioctl 54
+# endif
+# ifndef __NR_fcntl
+# define __NR_fcntl 55
+# endif
+# ifndef __NR_setpgid
+# define __NR_setpgid 57
+# endif
+# ifndef __NR_umask
+# define __NR_umask 60
+# endif
+# ifndef __NR_chroot
+# define __NR_chroot 61
+# endif
+# ifndef __NR_ustat
+# define __NR_ustat 62
+# endif
+# ifndef __NR_dup2
+# define __NR_dup2 63
+# endif
+# ifndef __NR_getppid
+# define __NR_getppid 64
+# endif
+# ifndef __NR_getpgrp
+# define __NR_getpgrp 65
+# endif
+# ifndef __NR_setsid
+# define __NR_setsid 66
+# endif
+# ifndef __NR_sigaction
+# define __NR_sigaction 67
+# endif
+# ifndef __NR_setreuid
+# define __NR_setreuid 70
+# endif
+# ifndef __NR_setregid
+# define __NR_setregid 71
+# endif
+# ifndef __NR_sigsuspend
+# define __NR_sigsuspend 72
+# endif
+# ifndef __NR_sigpending
+# define __NR_sigpending 73
+# endif
+# ifndef __NR_sethostname
+# define __NR_sethostname 74
+# endif
+# ifndef __NR_setrlimit
+# define __NR_setrlimit 75
+# endif
+# ifndef __NR_getrlimit
+# define __NR_getrlimit 76
+# endif
+# ifndef __NR_getrusage
+# define __NR_getrusage 77
+# endif
+# ifndef __NR_gettimeofday
+# define __NR_gettimeofday 78
+# endif
+# ifndef __NR_settimeofday
+# define __NR_settimeofday 79
+# endif
+# ifndef __NR_getgroups
+# define __NR_getgroups 80
+# endif
+# ifndef __NR_setgroups
+# define __NR_setgroups 81
+# endif
+# ifndef __NR_symlink
+# define __NR_symlink 83
+# endif
+# ifndef __NR_readlink
+# define __NR_readlink 85
+# endif
+# ifndef __NR_uselib
+# define __NR_uselib 86
+# endif
+# ifndef __NR_swapon
+# define __NR_swapon 87
+# endif
+# ifndef __NR_reboot
+# define __NR_reboot 88
+# endif
+# ifndef __NR_readdir
+# define __NR_readdir 89
+# endif
+# ifndef __NR_mmap
+# define __NR_mmap 90
+# endif
+# ifndef __NR_munmap
+# define __NR_munmap 91
+# endif
+# ifndef __NR_truncate
+# define __NR_truncate 92
+# endif
+# ifndef __NR_ftruncate
+# define __NR_ftruncate 93
+# endif
+# ifndef __NR_fchmod
+# define __NR_fchmod 94
+# endif
+# ifndef __NR_fchown
+# define __NR_fchown 95
+# endif
+# ifndef __NR_getpriority
+# define __NR_getpriority 96
+# endif
+# ifndef __NR_setpriority
+# define __NR_setpriority 97
+# endif
+# ifndef __NR_statfs
+# define __NR_statfs 99
+# endif
+# ifndef __NR_fstatfs
+# define __NR_fstatfs 100
+# endif
+# ifndef __NR_ioperm
+# define __NR_ioperm 101
+# endif
+# ifndef __NR_socketcall
+# define __NR_socketcall 102
+# endif
+# ifndef __NR_syslog
+# define __NR_syslog 103
+# endif
+# ifndef __NR_setitimer
+# define __NR_setitimer 104
+# endif
+# ifndef __NR_getitimer
+# define __NR_getitimer 105
+# endif
+# ifndef __NR_stat
+# define __NR_stat 106
+# endif
+# ifndef __NR_lstat
+# define __NR_lstat 107
+# endif
+# ifndef __NR_fstat
+# define __NR_fstat 108
+# endif
+# ifndef __NR_lookup_dcookie
+# define __NR_lookup_dcookie 110
+# endif
+# ifndef __NR_vhangup
+# define __NR_vhangup 111
+# endif
+# ifndef __NR_idle
+# define __NR_idle 112
+# endif
+# ifndef __NR_wait4
+# define __NR_wait4 114
+# endif
+# ifndef __NR_swapoff
+# define __NR_swapoff 115
+# endif
+# ifndef __NR_sysinfo
+# define __NR_sysinfo 116
+# endif
+# ifndef __NR_ipc
+# define __NR_ipc 117
+# endif
+# ifndef __NR_fsync
+# define __NR_fsync 118
+# endif
+# ifndef __NR_sigreturn
+# define __NR_sigreturn 119
+# endif
+# ifndef __NR_clone
+# define __NR_clone 120
+# endif
+# ifndef __NR_setdomainname
+# define __NR_setdomainname 121
+# endif
+# ifndef __NR_uname
+# define __NR_uname 122
+# endif
+# ifndef __NR_adjtimex
+# define __NR_adjtimex 124
+# endif
+# ifndef __NR_mprotect
+# define __NR_mprotect 125
+# endif
+# ifndef __NR_sigprocmask
+# define __NR_sigprocmask 126
+# endif
+# ifndef __NR_create_module
+# define __NR_create_module 127
+# endif
+# ifndef __NR_init_module
+# define __NR_init_module 128
+# endif
+# ifndef __NR_delete_module
+# define __NR_delete_module 129
+# endif
+# ifndef __NR_get_kernel_syms
+# define __NR_get_kernel_syms 130
+# endif
+# ifndef __NR_quotactl
+# define __NR_quotactl 131
+# endif
+# ifndef __NR_getpgid
+# define __NR_getpgid 132
+# endif
+# ifndef __NR_fchdir
+# define __NR_fchdir 133
+# endif
+# ifndef __NR_bdflush
+# define __NR_bdflush 134
+# endif
+# ifndef __NR_sysfs
+# define __NR_sysfs 135
+# endif
+# ifndef __NR_personality
+# define __NR_personality 136
+# endif
+# ifndef __NR_afs_syscall
+# define __NR_afs_syscall 137
+# endif
+# ifndef __NR_setfsuid
+# define __NR_setfsuid 138
+# endif
+# ifndef __NR_setfsgid
+# define __NR_setfsgid 139
+# endif
+# ifndef __NR__llseek
+# define __NR__llseek 140
+# endif
+# ifndef __NR_getdents
+# define __NR_getdents 141
+# endif
+# ifndef __NR__newselect
+# define __NR__newselect 142
+# endif
+# ifndef __NR_flock
+# define __NR_flock 143
+# endif
+# ifndef __NR_msync
+# define __NR_msync 144
+# endif
+# ifndef __NR_readv
+# define __NR_readv 145
+# endif
+# ifndef __NR_writev
+# define __NR_writev 146
+# endif
+# ifndef __NR_getsid
+# define __NR_getsid 147
+# endif
+# ifndef __NR_fdatasync
+# define __NR_fdatasync 148
+# endif
+# ifndef __NR__sysctl
+# define __NR__sysctl 149
+# endif
+# ifndef __NR_mlock
+# define __NR_mlock 150
+# endif
+# ifndef __NR_munlock
+# define __NR_munlock 151
+# endif
+# ifndef __NR_mlockall
+# define __NR_mlockall 152
+# endif
+# ifndef __NR_munlockall
+# define __NR_munlockall 153
+# endif
+# ifndef __NR_sched_setparam
+# define __NR_sched_setparam 154
+# endif
+# ifndef __NR_sched_getparam
+# define __NR_sched_getparam 155
+# endif
+# ifndef __NR_sched_setscheduler
+# define __NR_sched_setscheduler 156
+# endif
+# ifndef __NR_sched_getscheduler
+# define __NR_sched_getscheduler 157
+# endif
+# ifndef __NR_sched_yield
+# define __NR_sched_yield 158
+# endif
+# ifndef __NR_sched_get_priority_max
+# define __NR_sched_get_priority_max 159
+# endif
+# ifndef __NR_sched_get_priority_min
+# define __NR_sched_get_priority_min 160
+# endif
+# ifndef __NR_sched_rr_get_interval
+# define __NR_sched_rr_get_interval 161
+# endif
+# ifndef __NR_nanosleep
+# define __NR_nanosleep 162
+# endif
+# ifndef __NR_mremap
+# define __NR_mremap 163
+# endif
+# ifndef __NR_setresuid
+# define __NR_setresuid 164
+# endif
+# ifndef __NR_getresuid
+# define __NR_getresuid 165
+# endif
+# ifndef __NR_query_module
+# define __NR_query_module 167
+# endif
+# ifndef __NR_poll
+# define __NR_poll 168
+# endif
+# ifndef __NR_nfsservctl
+# define __NR_nfsservctl 169
+# endif
+# ifndef __NR_setresgid
+# define __NR_setresgid 170
+# endif
+# ifndef __NR_getresgid
+# define __NR_getresgid 171
+# endif
+# ifndef __NR_prctl
+# define __NR_prctl 172
+# endif
+# ifndef __NR_rt_sigreturn
+# define __NR_rt_sigreturn 173
+# endif
+# ifndef __NR_rt_sigaction
+# define __NR_rt_sigaction 174
+# endif
+# ifndef __NR_rt_sigprocmask
+# define __NR_rt_sigprocmask 175
+# endif
+# ifndef __NR_rt_sigpending
+# define __NR_rt_sigpending 176
+# endif
+# ifndef __NR_rt_sigtimedwait
+# define __NR_rt_sigtimedwait 177
+# endif
+# ifndef __NR_rt_sigqueueinfo
+# define __NR_rt_sigqueueinfo 178
+# endif
+# ifndef __NR_rt_sigsuspend
+# define __NR_rt_sigsuspend 179
+# endif
+# ifndef __NR_pread64
+# define __NR_pread64 180
+# endif
+# ifndef __NR_pwrite64
+# define __NR_pwrite64 181
+# endif
+# ifndef __NR_chown
+# define __NR_chown 182
+# endif
+# ifndef __NR_getcwd
+# define __NR_getcwd 183
+# endif
+# ifndef __NR_capget
+# define __NR_capget 184
+# endif
+# ifndef __NR_capset
+# define __NR_capset 185
+# endif
+# ifndef __NR_sigaltstack
+# define __NR_sigaltstack 186
+# endif
+# ifndef __NR_sendfile
+# define __NR_sendfile 187
+# endif
+# ifndef __NR_getpmsg
+# define __NR_getpmsg 188
+# endif
+# ifndef __NR_putpmsg
+# define __NR_putpmsg 189
+# endif
+# ifndef __NR_vfork
+# define __NR_vfork 190
+# endif
+# ifndef __NR_ugetrlimit
+# define __NR_ugetrlimit 191
+# endif
+# ifndef __NR_mmap2
+# define __NR_mmap2 192
+# endif
+# ifndef __NR_truncate64
+# define __NR_truncate64 193
+# endif
+# ifndef __NR_ftruncate64
+# define __NR_ftruncate64 194
+# endif
+# ifndef __NR_stat64
+# define __NR_stat64 195
+# endif
+# ifndef __NR_lstat64
+# define __NR_lstat64 196
+# endif
+# ifndef __NR_fstat64
+# define __NR_fstat64 197
+# endif
+# ifndef __NR_lchown32
+# define __NR_lchown32 198
+# endif
+# ifndef __NR_getuid32
+# define __NR_getuid32 199
+# endif
+# ifndef __NR_getgid32
+# define __NR_getgid32 200
+# endif
+# ifndef __NR_geteuid32
+# define __NR_geteuid32 201
+# endif
+# ifndef __NR_getegid32
+# define __NR_getegid32 202
+# endif
+# ifndef __NR_setreuid32
+# define __NR_setreuid32 203
+# endif
+# ifndef __NR_setregid32
+# define __NR_setregid32 204
+# endif
+# ifndef __NR_getgroups32
+# define __NR_getgroups32 205
+# endif
+# ifndef __NR_setgroups32
+# define __NR_setgroups32 206
+# endif
+# ifndef __NR_fchown32
+# define __NR_fchown32 207
+# endif
+# ifndef __NR_setresuid32
+# define __NR_setresuid32 208
+# endif
+# ifndef __NR_getresuid32
+# define __NR_getresuid32 209
+# endif
+# ifndef __NR_setresgid32
+# define __NR_setresgid32 210
+# endif
+# ifndef __NR_getresgid32
+# define __NR_getresgid32 211
+# endif
+# ifndef __NR_chown32
+# define __NR_chown32 212
+# endif
+# ifndef __NR_setuid32
+# define __NR_setuid32 213
+# endif
+# ifndef __NR_setgid32
+# define __NR_setgid32 214
+# endif
+# ifndef __NR_setfsuid32
+# define __NR_setfsuid32 215
+# endif
+# ifndef __NR_setfsgid32
+# define __NR_setfsgid32 216
+# endif
+# ifndef __NR_pivot_root
+# define __NR_pivot_root 217
+# endif
+# ifndef __NR_mincore
+# define __NR_mincore 218
+# endif
+# ifndef __NR_madvise
+# define __NR_madvise 219
+# endif
+# ifndef __NR_getdents64
+# define __NR_getdents64 220
+# endif
+# ifndef __NR_fcntl64
+# define __NR_fcntl64 221
+# endif
+# ifndef __NR_readahead
+# define __NR_readahead 222
+# endif
+# ifndef __NR_sendfile64
+# define __NR_sendfile64 223
+# endif
+# ifndef __NR_setxattr
+# define __NR_setxattr 224
+# endif
+# ifndef __NR_lsetxattr
+# define __NR_lsetxattr 225
+# endif
+# ifndef __NR_fsetxattr
+# define __NR_fsetxattr 226
+# endif
+# ifndef __NR_getxattr
+# define __NR_getxattr 227
+# endif
+# ifndef __NR_lgetxattr
+# define __NR_lgetxattr 228
+# endif
+# ifndef __NR_fgetxattr
+# define __NR_fgetxattr 229
+# endif
+# ifndef __NR_listxattr
+# define __NR_listxattr 230
+# endif
+# ifndef __NR_llistxattr
+# define __NR_llistxattr 231
+# endif
+# ifndef __NR_flistxattr
+# define __NR_flistxattr 232
+# endif
+# ifndef __NR_removexattr
+# define __NR_removexattr 233
+# endif
+# ifndef __NR_lremovexattr
+# define __NR_lremovexattr 234
+# endif
+# ifndef __NR_fremovexattr
+# define __NR_fremovexattr 235
+# endif
+# ifndef __NR_gettid
+# define __NR_gettid 236
+# endif
+# ifndef __NR_tkill
+# define __NR_tkill 237
+# endif
+# ifndef __NR_futex
+# define __NR_futex 238
+# endif
+# ifndef __NR_sched_setaffinity
+# define __NR_sched_setaffinity 239
+# endif
+# ifndef __NR_sched_getaffinity
+# define __NR_sched_getaffinity 240
+# endif
+# ifndef __NR_tgkill
+# define __NR_tgkill 241
+# endif
+# ifndef __NR_io_setup
+# define __NR_io_setup 243
+# endif
+# ifndef __NR_io_destroy
+# define __NR_io_destroy 244
+# endif
+# ifndef __NR_io_getevents
+# define __NR_io_getevents 245
+# endif
+# ifndef __NR_io_submit
+# define __NR_io_submit 246
+# endif
+# ifndef __NR_io_cancel
+# define __NR_io_cancel 247
+# endif
+# ifndef __NR_exit_group
+# define __NR_exit_group 248
+# endif
+# ifndef __NR_epoll_create
+# define __NR_epoll_create 249
+# endif
+# ifndef __NR_epoll_ctl
+# define __NR_epoll_ctl 250
+# endif
+# ifndef __NR_epoll_wait
+# define __NR_epoll_wait 251
+# endif
+# ifndef __NR_set_tid_address
+# define __NR_set_tid_address 252
+# endif
+# ifndef __NR_fadvise64
+# define __NR_fadvise64 253
+# endif
+# ifndef __NR_timer_create
+# define __NR_timer_create 254
+# endif
+# ifndef __NR_timer_settime
+# define __NR_timer_settime 255
+# endif
+# ifndef __NR_timer_gettime
+# define __NR_timer_gettime 256
+# endif
+# ifndef __NR_timer_getoverrun
+# define __NR_timer_getoverrun 257
+# endif
+# ifndef __NR_timer_delete
+# define __NR_timer_delete 258
+# endif
+# ifndef __NR_clock_settime
+# define __NR_clock_settime 259
+# endif
+# ifndef __NR_clock_gettime
+# define __NR_clock_gettime 260
+# endif
+# ifndef __NR_clock_getres
+# define __NR_clock_getres 261
+# endif
+# ifndef __NR_clock_nanosleep
+# define __NR_clock_nanosleep 262
+# endif
+# ifndef __NR_fadvise64_64
+# define __NR_fadvise64_64 264
+# endif
+# ifndef __NR_statfs64
+# define __NR_statfs64 265
+# endif
+# ifndef __NR_fstatfs64
+# define __NR_fstatfs64 266
+# endif
+# ifndef __NR_remap_file_pages
+# define __NR_remap_file_pages 267
+# endif
+# ifndef __NR_mbind
+# define __NR_mbind 268
+# endif
+# ifndef __NR_get_mempolicy
+# define __NR_get_mempolicy 269
+# endif
+# ifndef __NR_set_mempolicy
+# define __NR_set_mempolicy 270
+# endif
+# ifndef __NR_mq_open
+# define __NR_mq_open 271
+# endif
+# ifndef __NR_mq_unlink
+# define __NR_mq_unlink 272
+# endif
+# ifndef __NR_mq_timedsend
+# define __NR_mq_timedsend 273
+# endif
+# ifndef __NR_mq_timedreceive
+# define __NR_mq_timedreceive 274
+# endif
+# ifndef __NR_mq_notify
+# define __NR_mq_notify 275
+# endif
+# ifndef __NR_mq_getsetattr
+# define __NR_mq_getsetattr 276
+# endif
+# ifndef __NR_kexec_load
+# define __NR_kexec_load 277
+# endif
+# ifndef __NR_add_key
+# define __NR_add_key 278
+# endif
+# ifndef __NR_request_key
+# define __NR_request_key 279
+# endif
+# ifndef __NR_keyctl
+# define __NR_keyctl 280
+# endif
+# ifndef __NR_waitid
+# define __NR_waitid 281
+# endif
+# ifndef __NR_ioprio_set
+# define __NR_ioprio_set 282
+# endif
+# ifndef __NR_ioprio_get
+# define __NR_ioprio_get 283
+# endif
+# ifndef __NR_inotify_init
+# define __NR_inotify_init 284
+# endif
+# ifndef __NR_inotify_add_watch
+# define __NR_inotify_add_watch 285
+# endif
+# ifndef __NR_inotify_rm_watch
+# define __NR_inotify_rm_watch 286
+# endif
+# ifndef __NR_migrate_pages
+# define __NR_migrate_pages 287
+# endif
+# ifndef __NR_openat
+# define __NR_openat 288
+# endif
+# ifndef __NR_mkdirat
+# define __NR_mkdirat 289
+# endif
+# ifndef __NR_mknodat
+# define __NR_mknodat 290
+# endif
+# ifndef __NR_fchownat
+# define __NR_fchownat 291
+# endif
+# ifndef __NR_futimesat
+# define __NR_futimesat 292
+# endif
+# ifndef __NR_fstatat64
+# define __NR_fstatat64 293
+# endif
+# ifndef __NR_unlinkat
+# define __NR_unlinkat 294
+# endif
+# ifndef __NR_renameat
+# define __NR_renameat 295
+# endif
+# ifndef __NR_linkat
+# define __NR_linkat 296
+# endif
+# ifndef __NR_symlinkat
+# define __NR_symlinkat 297
+# endif
+# ifndef __NR_readlinkat
+# define __NR_readlinkat 298
+# endif
+# ifndef __NR_fchmodat
+# define __NR_fchmodat 299
+# endif
+# ifndef __NR_faccessat
+# define __NR_faccessat 300
+# endif
+# ifndef __NR_pselect6
+# define __NR_pselect6 301
+# endif
+# ifndef __NR_ppoll
+# define __NR_ppoll 302
+# endif
+# ifndef __NR_unshare
+# define __NR_unshare 303
+# endif
+# ifndef __NR_set_robust_list
+# define __NR_set_robust_list 304
+# endif
+# ifndef __NR_get_robust_list
+# define __NR_get_robust_list 305
+# endif
+# ifndef __NR_splice
+# define __NR_splice 306
+# endif
+# ifndef __NR_sync_file_range
+# define __NR_sync_file_range 307
+# endif
+# ifndef __NR_tee
+# define __NR_tee 308
+# endif
+# ifndef __NR_vmsplice
+# define __NR_vmsplice 309
+# endif
+# ifndef __NR_move_pages
+# define __NR_move_pages 310
+# endif
+# ifndef __NR_getcpu
+# define __NR_getcpu 311
+# endif
+# ifndef __NR_epoll_pwait
+# define __NR_epoll_pwait 312
+# endif
+# ifndef __NR_utimes
+# define __NR_utimes 313
+# endif
+# ifndef __NR_fallocate
+# define __NR_fallocate 314
+# endif
+# ifndef __NR_utimensat
+# define __NR_utimensat 315
+# endif
+# ifndef __NR_signalfd
+# define __NR_signalfd 316
+# endif
+# ifndef __NR_timerfd
+# define __NR_timerfd 317
+# endif
+# ifndef __NR_eventfd
+# define __NR_eventfd 318
+# endif
+# ifndef __NR_timerfd_create
+# define __NR_timerfd_create 319
+# endif
+# ifndef __NR_timerfd_settime
+# define __NR_timerfd_settime 320
+# endif
+# ifndef __NR_timerfd_gettime
+# define __NR_timerfd_gettime 321
+# endif
+# ifndef __NR_signalfd4
+# define __NR_signalfd4 322
+# endif
+# ifndef __NR_eventfd2
+# define __NR_eventfd2 323
+# endif
+# ifndef __NR_inotify_init1
+# define __NR_inotify_init1 324
+# endif
+# ifndef __NR_pipe2
+# define __NR_pipe2 325
+# endif
+# ifndef __NR_dup3
+# define __NR_dup3 326
+# endif
+# ifndef __NR_epoll_create1
+# define __NR_epoll_create1 327
+# endif
+# ifndef __NR_preadv
+# define __NR_preadv 328
+# endif
+# ifndef __NR_pwritev
+# define __NR_pwritev 329
+# endif
+# ifndef __NR_rt_tgsigqueueinfo
+# define __NR_rt_tgsigqueueinfo 330
+# endif
+# ifndef __NR_perf_event_open
+# define __NR_perf_event_open 331
+# endif
+# ifndef __NR_fanotify_init
+# define __NR_fanotify_init 332
+# endif
+# ifndef __NR_fanotify_mark
+# define __NR_fanotify_mark 333
+# endif
+# ifndef __NR_prlimit64
+# define __NR_prlimit64 334
+# endif
+# ifndef __NR_name_to_handle_at
+# define __NR_name_to_handle_at 335
+# endif
+# ifndef __NR_open_by_handle_at
+# define __NR_open_by_handle_at 336
+# endif
+# ifndef __NR_clock_adjtime
+# define __NR_clock_adjtime 337
+# endif
+# ifndef __NR_syncfs
+# define __NR_syncfs 338
+# endif
+# ifndef __NR_setns
+# define __NR_setns 339
+# endif
+# ifndef __NR_process_vm_readv
+# define __NR_process_vm_readv 340
+# endif
+# ifndef __NR_process_vm_writev
+# define __NR_process_vm_writev 341
+# endif
+# ifndef __NR_s390_runtime_instr
+# define __NR_s390_runtime_instr 342
+# endif
+# ifndef __NR_kcmp
+# define __NR_kcmp 343
+# endif
+# ifndef __NR_finit_module
+# define __NR_finit_module 344
+# endif
+# ifndef __NR_sched_setattr
+# define __NR_sched_setattr 345
+# endif
+# ifndef __NR_sched_getattr
+# define __NR_sched_getattr 346
+# endif
+# ifndef __NR_renameat2
+# define __NR_renameat2 347
+# endif
+# ifndef __NR_seccomp
+# define __NR_seccomp 348
+# endif
+# ifndef __NR_getrandom
+# define __NR_getrandom 349
+# endif
+# ifndef __NR_memfd_create
+# define __NR_memfd_create 350
+# endif
+# ifndef __NR_bpf
+# define __NR_bpf 351
+# endif
+# ifndef __NR_s390_pci_mmio_write
+# define __NR_s390_pci_mmio_write 352
+# endif
+# ifndef __NR_s390_pci_mmio_read
+# define __NR_s390_pci_mmio_read 353
+# endif
+# ifndef __NR_execveat
+# define __NR_execveat 354
+# endif
+# ifndef __NR_userfaultfd
+# define __NR_userfaultfd 355
+# endif
+# ifndef __NR_membarrier
+# define __NR_membarrier 356
+# endif
+# ifndef __NR_recvmmsg
+# define __NR_recvmmsg 357
+# endif
+# ifndef __NR_sendmmsg
+# define __NR_sendmmsg 358
+# endif
+# ifndef __NR_socket
+# define __NR_socket 359
+# endif
+# ifndef __NR_socketpair
+# define __NR_socketpair 360
+# endif
+# ifndef __NR_bind
+# define __NR_bind 361
+# endif
+# ifndef __NR_connect
+# define __NR_connect 362
+# endif
+# ifndef __NR_listen
+# define __NR_listen 363
+# endif
+# ifndef __NR_accept4
+# define __NR_accept4 364
+# endif
+# ifndef __NR_getsockopt
+# define __NR_getsockopt 365
+# endif
+# ifndef __NR_setsockopt
+# define __NR_setsockopt 366
+# endif
+# ifndef __NR_getsockname
+# define __NR_getsockname 367
+# endif
+# ifndef __NR_getpeername
+# define __NR_getpeername 368
+# endif
+# ifndef __NR_sendto
+# define __NR_sendto 369
+# endif
+# ifndef __NR_sendmsg
+# define __NR_sendmsg 370
+# endif
+# ifndef __NR_recvfrom
+# define __NR_recvfrom 371
+# endif
+# ifndef __NR_recvmsg
+# define __NR_recvmsg 372
+# endif
+# ifndef __NR_shutdown
+# define __NR_shutdown 373
+# endif
+# ifndef __NR_mlock2
+# define __NR_mlock2 374
+# endif
+# ifndef __NR_copy_file_range
+# define __NR_copy_file_range 375
+# endif
+# ifndef __NR_preadv2
+# define __NR_preadv2 376
+# endif
+# ifndef __NR_pwritev2
+# define __NR_pwritev2 377
+# endif
+# ifndef __NR_s390_guarded_storage
+# define __NR_s390_guarded_storage 378
+# endif
+# ifndef __NR_statx
+# define __NR_statx 379
+# endif
+# ifndef __NR_s390_sthyi
+# define __NR_s390_sthyi 380
+# endif
+# ifndef __NR_kexec_file_load
+# define __NR_kexec_file_load 381
+# endif
+# ifndef __NR_io_pgetevents
+# define __NR_io_pgetevents 382
+# endif
+# ifndef __NR_rseq
+# define __NR_rseq 383
+# endif
+# ifndef __NR_pkey_mprotect
+# define __NR_pkey_mprotect 384
+# endif
+# ifndef __NR_pkey_alloc
+# define __NR_pkey_alloc 385
+# endif
+# ifndef __NR_pkey_free
+# define __NR_pkey_free 386
+# endif
+# ifndef __NR_semget
+# define __NR_semget 393
+# endif
+# ifndef __NR_semctl
+# define __NR_semctl 394
+# endif
+# ifndef __NR_shmget
+# define __NR_shmget 395
+# endif
+# ifndef __NR_shmctl
+# define __NR_shmctl 396
+# endif
+# ifndef __NR_shmat
+# define __NR_shmat 397
+# endif
+# ifndef __NR_shmdt
+# define __NR_shmdt 398
+# endif
+# ifndef __NR_msgget
+# define __NR_msgget 399
+# endif
+# ifndef __NR_msgsnd
+# define __NR_msgsnd 400
+# endif
+# ifndef __NR_msgrcv
+# define __NR_msgrcv 401
+# endif
+# ifndef __NR_msgctl
+# define __NR_msgctl 402
+# endif
+# ifndef __NR_clock_gettime64
+# define __NR_clock_gettime64 403
+# endif
+# ifndef __NR_clock_settime64
+# define __NR_clock_settime64 404
+# endif
+# ifndef __NR_clock_adjtime64
+# define __NR_clock_adjtime64 405
+# endif
+# ifndef __NR_clock_getres_time64
+# define __NR_clock_getres_time64 406
+# endif
+# ifndef __NR_clock_nanosleep_time64
+# define __NR_clock_nanosleep_time64 407
+# endif
+# ifndef __NR_timer_gettime64
+# define __NR_timer_gettime64 408
+# endif
+# ifndef __NR_timer_settime64
+# define __NR_timer_settime64 409
+# endif
+# ifndef __NR_timerfd_gettime64
+# define __NR_timerfd_gettime64 410
+# endif
+# ifndef __NR_timerfd_settime64
+# define __NR_timerfd_settime64 411
+# endif
+# ifndef __NR_utimensat_time64
+# define __NR_utimensat_time64 412
+# endif
+# ifndef __NR_pselect6_time64
+# define __NR_pselect6_time64 413
+# endif
+# ifndef __NR_ppoll_time64
+# define __NR_ppoll_time64 414
+# endif
+# ifndef __NR_io_pgetevents_time64
+# define __NR_io_pgetevents_time64 416
+# endif
+# ifndef __NR_recvmmsg_time64
+# define __NR_recvmmsg_time64 417
+# endif
+# ifndef __NR_mq_timedsend_time64
+# define __NR_mq_timedsend_time64 418
+# endif
+# ifndef __NR_mq_timedreceive_time64
+# define __NR_mq_timedreceive_time64 419
+# endif
+# ifndef __NR_semtimedop_time64
+# define __NR_semtimedop_time64 420
+# endif
+# ifndef __NR_rt_sigtimedwait_time64
+# define __NR_rt_sigtimedwait_time64 421
+# endif
+# ifndef __NR_futex_time64
+# define __NR_futex_time64 422
+# endif
+# ifndef __NR_sched_rr_get_interval_time64
+# define __NR_sched_rr_get_interval_time64 423
+# endif
+# ifndef __NR_pidfd_send_signal
+# define __NR_pidfd_send_signal 424
+# endif
+# ifndef __NR_io_uring_setup
+# define __NR_io_uring_setup 425
+# endif
+# ifndef __NR_io_uring_enter
+# define __NR_io_uring_enter 426
+# endif
+# ifndef __NR_io_uring_register
+# define __NR_io_uring_register 427
+# endif
+# ifndef __NR_open_tree
+# define __NR_open_tree 428
+# endif
+# ifndef __NR_move_mount
+# define __NR_move_mount 429
+# endif
+# ifndef __NR_fsopen
+# define __NR_fsopen 430
+# endif
+# ifndef __NR_fsconfig
+# define __NR_fsconfig 431
+# endif
+# ifndef __NR_fsmount
+# define __NR_fsmount 432
+# endif
+# ifndef __NR_fspick
+# define __NR_fspick 433
+# endif
+# ifndef __NR_pidfd_open
+# define __NR_pidfd_open 434
+# endif
+# ifndef __NR_clone3
+# define __NR_clone3 435
+# endif
+# ifndef __NR_openat2
+# define __NR_openat2 437
+# endif
+# ifndef __NR_pidfd_getfd
+# define __NR_pidfd_getfd 438
+# endif
+#endif
+
+
+#ifdef __sh__
+# ifndef __NR_restart_syscall
+# define __NR_restart_syscall 0
+# endif
+# ifndef __NR_exit
+# define __NR_exit 1
+# endif
+# ifndef __NR_fork
+# define __NR_fork 2
+# endif
+# ifndef __NR_read
+# define __NR_read 3
+# endif
+# ifndef __NR_write
+# define __NR_write 4
+# endif
+# ifndef __NR_open
+# define __NR_open 5
+# endif
+# ifndef __NR_close
+# define __NR_close 6
+# endif
+# ifndef __NR_waitpid
+# define __NR_waitpid 7
+# endif
+# ifndef __NR_creat
+# define __NR_creat 8
+# endif
+# ifndef __NR_link
+# define __NR_link 9
+# endif
+# ifndef __NR_unlink
+# define __NR_unlink 10
+# endif
+# ifndef __NR_execve
+# define __NR_execve 11
+# endif
+# ifndef __NR_chdir
+# define __NR_chdir 12
+# endif
+# ifndef __NR_time
+# define __NR_time 13
+# endif
+# ifndef __NR_mknod
+# define __NR_mknod 14
+# endif
+# ifndef __NR_chmod
+# define __NR_chmod 15
+# endif
+# ifndef __NR_lchown
+# define __NR_lchown 16
+# endif
+# ifndef __NR_oldstat
+# define __NR_oldstat 18
+# endif
+# ifndef __NR_lseek
+# define __NR_lseek 19
+# endif
+# ifndef __NR_getpid
+# define __NR_getpid 20
+# endif
+# ifndef __NR_mount
+# define __NR_mount 21
+# endif
+# ifndef __NR_umount
+# define __NR_umount 22
+# endif
+# ifndef __NR_setuid
+# define __NR_setuid 23
+# endif
+# ifndef __NR_getuid
+# define __NR_getuid 24
+# endif
+# ifndef __NR_stime
+# define __NR_stime 25
+# endif
+# ifndef __NR_ptrace
+# define __NR_ptrace 26
+# endif
+# ifndef __NR_alarm
+# define __NR_alarm 27
+# endif
+# ifndef __NR_oldfstat
+# define __NR_oldfstat 28
+# endif
+# ifndef __NR_pause
+# define __NR_pause 29
+# endif
+# ifndef __NR_utime
+# define __NR_utime 30
+# endif
+# ifndef __NR_access
+# define __NR_access 33
+# endif
+# ifndef __NR_nice
+# define __NR_nice 34
+# endif
+# ifndef __NR_sync
+# define __NR_sync 36
+# endif
+# ifndef __NR_kill
+# define __NR_kill 37
+# endif
+# ifndef __NR_rename
+# define __NR_rename 38
+# endif
+# ifndef __NR_mkdir
+# define __NR_mkdir 39
+# endif
+# ifndef __NR_rmdir
+# define __NR_rmdir 40
+# endif
+# ifndef __NR_dup
+# define __NR_dup 41
+# endif
+# ifndef __NR_pipe
+# define __NR_pipe 42
+# endif
+# ifndef __NR_times
+# define __NR_times 43
+# endif
+# ifndef __NR_brk
+# define __NR_brk 45
+# endif
+# ifndef __NR_setgid
+# define __NR_setgid 46
+# endif
+# ifndef __NR_getgid
+# define __NR_getgid 47
+# endif
+# ifndef __NR_signal
+# define __NR_signal 48
+# endif
+# ifndef __NR_geteuid
+# define __NR_geteuid 49
+# endif
+# ifndef __NR_getegid
+# define __NR_getegid 50
+# endif
+# ifndef __NR_acct
+# define __NR_acct 51
+# endif
+# ifndef __NR_umount2
+# define __NR_umount2 52
+# endif
+# ifndef __NR_ioctl
+# define __NR_ioctl 54
+# endif
+# ifndef __NR_fcntl
+# define __NR_fcntl 55
+# endif
+# ifndef __NR_setpgid
+# define __NR_setpgid 57
+# endif
+# ifndef __NR_umask
+# define __NR_umask 60
+# endif
+# ifndef __NR_chroot
+# define __NR_chroot 61
+# endif
+# ifndef __NR_ustat
+# define __NR_ustat 62
+# endif
+# ifndef __NR_dup2
+# define __NR_dup2 63
+# endif
+# ifndef __NR_getppid
+# define __NR_getppid 64
+# endif
+# ifndef __NR_getpgrp
+# define __NR_getpgrp 65
+# endif
+# ifndef __NR_setsid
+# define __NR_setsid 66
+# endif
+# ifndef __NR_sigaction
+# define __NR_sigaction 67
+# endif
+# ifndef __NR_sgetmask
+# define __NR_sgetmask 68
+# endif
+# ifndef __NR_ssetmask
+# define __NR_ssetmask 69
+# endif
+# ifndef __NR_setreuid
+# define __NR_setreuid 70
+# endif
+# ifndef __NR_setregid
+# define __NR_setregid 71
+# endif
+# ifndef __NR_sigsuspend
+# define __NR_sigsuspend 72
+# endif
+# ifndef __NR_sigpending
+# define __NR_sigpending 73
+# endif
+# ifndef __NR_sethostname
+# define __NR_sethostname 74
+# endif
+# ifndef __NR_setrlimit
+# define __NR_setrlimit 75
+# endif
+# ifndef __NR_getrlimit
+# define __NR_getrlimit 76
+# endif
+# ifndef __NR_getrusage
+# define __NR_getrusage 77
+# endif
+# ifndef __NR_gettimeofday
+# define __NR_gettimeofday 78
+# endif
+# ifndef __NR_settimeofday
+# define __NR_settimeofday 79
+# endif
+# ifndef __NR_getgroups
+# define __NR_getgroups 80
+# endif
+# ifndef __NR_setgroups
+# define __NR_setgroups 81
+# endif
+# ifndef __NR_symlink
+# define __NR_symlink 83
+# endif
+# ifndef __NR_oldlstat
+# define __NR_oldlstat 84
+# endif
+# ifndef __NR_readlink
+# define __NR_readlink 85
+# endif
+# ifndef __NR_uselib
+# define __NR_uselib 86
+# endif
+# ifndef __NR_swapon
+# define __NR_swapon 87
+# endif
+# ifndef __NR_reboot
+# define __NR_reboot 88
+# endif
+# ifndef __NR_readdir
+# define __NR_readdir 89
+# endif
+# ifndef __NR_mmap
+# define __NR_mmap 90
+# endif
+# ifndef __NR_munmap
+# define __NR_munmap 91
+# endif
+# ifndef __NR_truncate
+# define __NR_truncate 92
+# endif
+# ifndef __NR_ftruncate
+# define __NR_ftruncate 93
+# endif
+# ifndef __NR_fchmod
+# define __NR_fchmod 94
+# endif
+# ifndef __NR_fchown
+# define __NR_fchown 95
+# endif
+# ifndef __NR_getpriority
+# define __NR_getpriority 96
+# endif
+# ifndef __NR_setpriority
+# define __NR_setpriority 97
+# endif
+# ifndef __NR_statfs
+# define __NR_statfs 99
+# endif
+# ifndef __NR_fstatfs
+# define __NR_fstatfs 100
+# endif
+# ifndef __NR_socketcall
+# define __NR_socketcall 102
+# endif
+# ifndef __NR_syslog
+# define __NR_syslog 103
+# endif
+# ifndef __NR_setitimer
+# define __NR_setitimer 104
+# endif
+# ifndef __NR_getitimer
+# define __NR_getitimer 105
+# endif
+# ifndef __NR_stat
+# define __NR_stat 106
+# endif
+# ifndef __NR_lstat
+# define __NR_lstat 107
+# endif
+# ifndef __NR_fstat
+# define __NR_fstat 108
+# endif
+# ifndef __NR_olduname
+# define __NR_olduname 109
+# endif
+# ifndef __NR_vhangup
+# define __NR_vhangup 111
+# endif
+# ifndef __NR_wait4
+# define __NR_wait4 114
+# endif
+# ifndef __NR_swapoff
+# define __NR_swapoff 115
+# endif
+# ifndef __NR_sysinfo
+# define __NR_sysinfo 116
+# endif
+# ifndef __NR_ipc
+# define __NR_ipc 117
+# endif
+# ifndef __NR_fsync
+# define __NR_fsync 118
+# endif
+# ifndef __NR_sigreturn
+# define __NR_sigreturn 119
+# endif
+# ifndef __NR_clone
+# define __NR_clone 120
+# endif
+# ifndef __NR_setdomainname
+# define __NR_setdomainname 121
+# endif
+# ifndef __NR_uname
+# define __NR_uname 122
+# endif
+# ifndef __NR_cacheflush
+# define __NR_cacheflush 123
+# endif
+# ifndef __NR_adjtimex
+# define __NR_adjtimex 124
+# endif
+# ifndef __NR_mprotect
+# define __NR_mprotect 125
+# endif
+# ifndef __NR_sigprocmask
+# define __NR_sigprocmask 126
+# endif
+# ifndef __NR_init_module
+# define __NR_init_module 128
+# endif
+# ifndef __NR_delete_module
+# define __NR_delete_module 129
+# endif
+# ifndef __NR_quotactl
+# define __NR_quotactl 131
+# endif
+# ifndef __NR_getpgid
+# define __NR_getpgid 132
+# endif
+# ifndef __NR_fchdir
+# define __NR_fchdir 133
+# endif
+# ifndef __NR_bdflush
+# define __NR_bdflush 134
+# endif
+# ifndef __NR_sysfs
+# define __NR_sysfs 135
+# endif
+# ifndef __NR_personality
+# define __NR_personality 136
+# endif
+# ifndef __NR_setfsuid
+# define __NR_setfsuid 138
+# endif
+# ifndef __NR_setfsgid
+# define __NR_setfsgid 139
+# endif
+# ifndef __NR__llseek
+# define __NR__llseek 140
+# endif
+# ifndef __NR_getdents
+# define __NR_getdents 141
+# endif
+# ifndef __NR__newselect
+# define __NR__newselect 142
+# endif
+# ifndef __NR_flock
+# define __NR_flock 143
+# endif
+# ifndef __NR_msync
+# define __NR_msync 144
+# endif
+# ifndef __NR_readv
+# define __NR_readv 145
+# endif
+# ifndef __NR_writev
+# define __NR_writev 146
+# endif
+# ifndef __NR_getsid
+# define __NR_getsid 147
+# endif
+# ifndef __NR_fdatasync
+# define __NR_fdatasync 148
+# endif
+# ifndef __NR__sysctl
+# define __NR__sysctl 149
+# endif
+# ifndef __NR_mlock
+# define __NR_mlock 150
+# endif
+# ifndef __NR_munlock
+# define __NR_munlock 151
+# endif
+# ifndef __NR_mlockall
+# define __NR_mlockall 152
+# endif
+# ifndef __NR_munlockall
+# define __NR_munlockall 153
+# endif
+# ifndef __NR_sched_setparam
+# define __NR_sched_setparam 154
+# endif
+# ifndef __NR_sched_getparam
+# define __NR_sched_getparam 155
+# endif
+# ifndef __NR_sched_setscheduler
+# define __NR_sched_setscheduler 156
+# endif
+# ifndef __NR_sched_getscheduler
+# define __NR_sched_getscheduler 157
+# endif
+# ifndef __NR_sched_yield
+# define __NR_sched_yield 158
+# endif
+# ifndef __NR_sched_get_priority_max
+# define __NR_sched_get_priority_max 159
+# endif
+# ifndef __NR_sched_get_priority_min
+# define __NR_sched_get_priority_min 160
+# endif
+# ifndef __NR_sched_rr_get_interval
+# define __NR_sched_rr_get_interval 161
+# endif
+# ifndef __NR_nanosleep
+# define __NR_nanosleep 162
+# endif
+# ifndef __NR_mremap
+# define __NR_mremap 163
+# endif
+# ifndef __NR_setresuid
+# define __NR_setresuid 164
+# endif
+# ifndef __NR_getresuid
+# define __NR_getresuid 165
+# endif
+# ifndef __NR_poll
+# define __NR_poll 168
+# endif
+# ifndef __NR_nfsservctl
+# define __NR_nfsservctl 169
+# endif
+# ifndef __NR_setresgid
+# define __NR_setresgid 170
+# endif
+# ifndef __NR_getresgid
+# define __NR_getresgid 171
+# endif
+# ifndef __NR_prctl
+# define __NR_prctl 172
+# endif
+# ifndef __NR_rt_sigreturn
+# define __NR_rt_sigreturn 173
+# endif
+# ifndef __NR_rt_sigaction
+# define __NR_rt_sigaction 174
+# endif
+# ifndef __NR_rt_sigprocmask
+# define __NR_rt_sigprocmask 175
+# endif
+# ifndef __NR_rt_sigpending
+# define __NR_rt_sigpending 176
+# endif
+# ifndef __NR_rt_sigtimedwait
+# define __NR_rt_sigtimedwait 177
+# endif
+# ifndef __NR_rt_sigqueueinfo
+# define __NR_rt_sigqueueinfo 178
+# endif
+# ifndef __NR_rt_sigsuspend
+# define __NR_rt_sigsuspend 179
+# endif
+# ifndef __NR_pread64
+# define __NR_pread64 180
+# endif
+# ifndef __NR_pwrite64
+# define __NR_pwrite64 181
+# endif
+# ifndef __NR_chown
+# define __NR_chown 182
+# endif
+# ifndef __NR_getcwd
+# define __NR_getcwd 183
+# endif
+# ifndef __NR_capget
+# define __NR_capget 184
+# endif
+# ifndef __NR_capset
+# define __NR_capset 185
+# endif
+# ifndef __NR_sigaltstack
+# define __NR_sigaltstack 186
+# endif
+# ifndef __NR_sendfile
+# define __NR_sendfile 187
+# endif
+# ifndef __NR_vfork
+# define __NR_vfork 190
+# endif
+# ifndef __NR_ugetrlimit
+# define __NR_ugetrlimit 191
+# endif
+# ifndef __NR_mmap2
+# define __NR_mmap2 192
+# endif
+# ifndef __NR_truncate64
+# define __NR_truncate64 193
+# endif
+# ifndef __NR_ftruncate64
+# define __NR_ftruncate64 194
+# endif
+# ifndef __NR_stat64
+# define __NR_stat64 195
+# endif
+# ifndef __NR_lstat64
+# define __NR_lstat64 196
+# endif
+# ifndef __NR_fstat64
+# define __NR_fstat64 197
+# endif
+# ifndef __NR_lchown32
+# define __NR_lchown32 198
+# endif
+# ifndef __NR_getuid32
+# define __NR_getuid32 199
+# endif
+# ifndef __NR_getgid32
+# define __NR_getgid32 200
+# endif
+# ifndef __NR_geteuid32
+# define __NR_geteuid32 201
+# endif
+# ifndef __NR_getegid32
+# define __NR_getegid32 202
+# endif
+# ifndef __NR_setreuid32
+# define __NR_setreuid32 203
+# endif
+# ifndef __NR_setregid32
+# define __NR_setregid32 204
+# endif
+# ifndef __NR_getgroups32
+# define __NR_getgroups32 205
+# endif
+# ifndef __NR_setgroups32
+# define __NR_setgroups32 206
+# endif
+# ifndef __NR_fchown32
+# define __NR_fchown32 207
+# endif
+# ifndef __NR_setresuid32
+# define __NR_setresuid32 208
+# endif
+# ifndef __NR_getresuid32
+# define __NR_getresuid32 209
+# endif
+# ifndef __NR_setresgid32
+# define __NR_setresgid32 210
+# endif
+# ifndef __NR_getresgid32
+# define __NR_getresgid32 211
+# endif
+# ifndef __NR_chown32
+# define __NR_chown32 212
+# endif
+# ifndef __NR_setuid32
+# define __NR_setuid32 213
+# endif
+# ifndef __NR_setgid32
+# define __NR_setgid32 214
+# endif
+# ifndef __NR_setfsuid32
+# define __NR_setfsuid32 215
+# endif
+# ifndef __NR_setfsgid32
+# define __NR_setfsgid32 216
+# endif
+# ifndef __NR_pivot_root
+# define __NR_pivot_root 217
+# endif
+# ifndef __NR_mincore
+# define __NR_mincore 218
+# endif
+# ifndef __NR_madvise
+# define __NR_madvise 219
+# endif
+# ifndef __NR_getdents64
+# define __NR_getdents64 220
+# endif
+# ifndef __NR_fcntl64
+# define __NR_fcntl64 221
+# endif
+# ifndef __NR_gettid
+# define __NR_gettid 224
+# endif
+# ifndef __NR_readahead
+# define __NR_readahead 225
+# endif
+# ifndef __NR_setxattr
+# define __NR_setxattr 226
+# endif
+# ifndef __NR_lsetxattr
+# define __NR_lsetxattr 227
+# endif
+# ifndef __NR_fsetxattr
+# define __NR_fsetxattr 228
+# endif
+# ifndef __NR_getxattr
+# define __NR_getxattr 229
+# endif
+# ifndef __NR_lgetxattr
+# define __NR_lgetxattr 230
+# endif
+# ifndef __NR_fgetxattr
+# define __NR_fgetxattr 231
+# endif
+# ifndef __NR_listxattr
+# define __NR_listxattr 232
+# endif
+# ifndef __NR_llistxattr
+# define __NR_llistxattr 233
+# endif
+# ifndef __NR_flistxattr
+# define __NR_flistxattr 234
+# endif
+# ifndef __NR_removexattr
+# define __NR_removexattr 235
+# endif
+# ifndef __NR_lremovexattr
+# define __NR_lremovexattr 236
+# endif
+# ifndef __NR_fremovexattr
+# define __NR_fremovexattr 237
+# endif
+# ifndef __NR_tkill
+# define __NR_tkill 238
+# endif
+# ifndef __NR_sendfile64
+# define __NR_sendfile64 239
+# endif
+# ifndef __NR_futex
+# define __NR_futex 240
+# endif
+# ifndef __NR_sched_setaffinity
+# define __NR_sched_setaffinity 241
+# endif
+# ifndef __NR_sched_getaffinity
+# define __NR_sched_getaffinity 242
+# endif
+# ifndef __NR_io_setup
+# define __NR_io_setup 245
+# endif
+# ifndef __NR_io_destroy
+# define __NR_io_destroy 246
+# endif
+# ifndef __NR_io_getevents
+# define __NR_io_getevents 247
+# endif
+# ifndef __NR_io_submit
+# define __NR_io_submit 248
+# endif
+# ifndef __NR_io_cancel
+# define __NR_io_cancel 249
+# endif
+# ifndef __NR_fadvise64
+# define __NR_fadvise64 250
+# endif
+# ifndef __NR_exit_group
+# define __NR_exit_group 252
+# endif
+# ifndef __NR_lookup_dcookie
+# define __NR_lookup_dcookie 253
+# endif
+# ifndef __NR_epoll_create
+# define __NR_epoll_create 254
+# endif
+# ifndef __NR_epoll_ctl
+# define __NR_epoll_ctl 255
+# endif
+# ifndef __NR_epoll_wait
+# define __NR_epoll_wait 256
+# endif
+# ifndef __NR_remap_file_pages
+# define __NR_remap_file_pages 257
+# endif
+# ifndef __NR_set_tid_address
+# define __NR_set_tid_address 258
+# endif
+# ifndef __NR_timer_create
+# define __NR_timer_create 259
+# endif
+# ifndef __NR_timer_settime
+# define __NR_timer_settime 260
+# endif
+# ifndef __NR_timer_gettime
+# define __NR_timer_gettime 261
+# endif
+# ifndef __NR_timer_getoverrun
+# define __NR_timer_getoverrun 262
+# endif
+# ifndef __NR_timer_delete
+# define __NR_timer_delete 263
+# endif
+# ifndef __NR_clock_settime
+# define __NR_clock_settime 264
+# endif
+# ifndef __NR_clock_gettime
+# define __NR_clock_gettime 265
+# endif
+# ifndef __NR_clock_getres
+# define __NR_clock_getres 266
+# endif
+# ifndef __NR_clock_nanosleep
+# define __NR_clock_nanosleep 267
+# endif
+# ifndef __NR_statfs64
+# define __NR_statfs64 268
+# endif
+# ifndef __NR_fstatfs64
+# define __NR_fstatfs64 269
+# endif
+# ifndef __NR_tgkill
+# define __NR_tgkill 270
+# endif
+# ifndef __NR_utimes
+# define __NR_utimes 271
+# endif
+# ifndef __NR_fadvise64_64
+# define __NR_fadvise64_64 272
+# endif
+# ifndef __NR_mbind
+# define __NR_mbind 274
+# endif
+# ifndef __NR_get_mempolicy
+# define __NR_get_mempolicy 275
+# endif
+# ifndef __NR_set_mempolicy
+# define __NR_set_mempolicy 276
+# endif
+# ifndef __NR_mq_open
+# define __NR_mq_open 277
+# endif
+# ifndef __NR_mq_unlink
+# define __NR_mq_unlink 278
+# endif
+# ifndef __NR_mq_timedsend
+# define __NR_mq_timedsend 279
+# endif
+# ifndef __NR_mq_timedreceive
+# define __NR_mq_timedreceive 280
+# endif
+# ifndef __NR_mq_notify
+# define __NR_mq_notify 281
+# endif
+# ifndef __NR_mq_getsetattr
+# define __NR_mq_getsetattr 282
+# endif
+# ifndef __NR_kexec_load
+# define __NR_kexec_load 283
+# endif
+# ifndef __NR_waitid
+# define __NR_waitid 284
+# endif
+# ifndef __NR_add_key
+# define __NR_add_key 285
+# endif
+# ifndef __NR_request_key
+# define __NR_request_key 286
+# endif
+# ifndef __NR_keyctl
+# define __NR_keyctl 287
+# endif
+# ifndef __NR_ioprio_set
+# define __NR_ioprio_set 288
+# endif
+# ifndef __NR_ioprio_get
+# define __NR_ioprio_get 289
+# endif
+# ifndef __NR_inotify_init
+# define __NR_inotify_init 290
+# endif
+# ifndef __NR_inotify_add_watch
+# define __NR_inotify_add_watch 291
+# endif
+# ifndef __NR_inotify_rm_watch
+# define __NR_inotify_rm_watch 292
+# endif
+# ifndef __NR_migrate_pages
+# define __NR_migrate_pages 294
+# endif
+# ifndef __NR_openat
+# define __NR_openat 295
+# endif
+# ifndef __NR_mkdirat
+# define __NR_mkdirat 296
+# endif
+# ifndef __NR_mknodat
+# define __NR_mknodat 297
+# endif
+# ifndef __NR_fchownat
+# define __NR_fchownat 298
+# endif
+# ifndef __NR_futimesat
+# define __NR_futimesat 299
+# endif
+# ifndef __NR_fstatat64
+# define __NR_fstatat64 300
+# endif
+# ifndef __NR_unlinkat
+# define __NR_unlinkat 301
+# endif
+# ifndef __NR_renameat
+# define __NR_renameat 302
+# endif
+# ifndef __NR_linkat
+# define __NR_linkat 303
+# endif
+# ifndef __NR_symlinkat
+# define __NR_symlinkat 304
+# endif
+# ifndef __NR_readlinkat
+# define __NR_readlinkat 305
+# endif
+# ifndef __NR_fchmodat
+# define __NR_fchmodat 306
+# endif
+# ifndef __NR_faccessat
+# define __NR_faccessat 307
+# endif
+# ifndef __NR_pselect6
+# define __NR_pselect6 308
+# endif
+# ifndef __NR_ppoll
+# define __NR_ppoll 309
+# endif
+# ifndef __NR_unshare
+# define __NR_unshare 310
+# endif
+# ifndef __NR_set_robust_list
+# define __NR_set_robust_list 311
+# endif
+# ifndef __NR_get_robust_list
+# define __NR_get_robust_list 312
+# endif
+# ifndef __NR_splice
+# define __NR_splice 313
+# endif
+# ifndef __NR_sync_file_range
+# define __NR_sync_file_range 314
+# endif
+# ifndef __NR_tee
+# define __NR_tee 315
+# endif
+# ifndef __NR_vmsplice
+# define __NR_vmsplice 316
+# endif
+# ifndef __NR_move_pages
+# define __NR_move_pages 317
+# endif
+# ifndef __NR_getcpu
+# define __NR_getcpu 318
+# endif
+# ifndef __NR_epoll_pwait
+# define __NR_epoll_pwait 319
+# endif
+# ifndef __NR_utimensat
+# define __NR_utimensat 320
+# endif
+# ifndef __NR_signalfd
+# define __NR_signalfd 321
+# endif
+# ifndef __NR_timerfd_create
+# define __NR_timerfd_create 322
+# endif
+# ifndef __NR_eventfd
+# define __NR_eventfd 323
+# endif
+# ifndef __NR_fallocate
+# define __NR_fallocate 324
+# endif
+# ifndef __NR_timerfd_settime
+# define __NR_timerfd_settime 325
+# endif
+# ifndef __NR_timerfd_gettime
+# define __NR_timerfd_gettime 326
+# endif
+# ifndef __NR_signalfd4
+# define __NR_signalfd4 327
+# endif
+# ifndef __NR_eventfd2
+# define __NR_eventfd2 328
+# endif
+# ifndef __NR_epoll_create1
+# define __NR_epoll_create1 329
+# endif
+# ifndef __NR_dup3
+# define __NR_dup3 330
+# endif
+# ifndef __NR_pipe2
+# define __NR_pipe2 331
+# endif
+# ifndef __NR_inotify_init1
+# define __NR_inotify_init1 332
+# endif
+# ifndef __NR_preadv
+# define __NR_preadv 333
+# endif
+# ifndef __NR_pwritev
+# define __NR_pwritev 334
+# endif
+# ifndef __NR_rt_tgsigqueueinfo
+# define __NR_rt_tgsigqueueinfo 335
+# endif
+# ifndef __NR_perf_event_open
+# define __NR_perf_event_open 336
+# endif
+# ifndef __NR_fanotify_init
+# define __NR_fanotify_init 337
+# endif
+# ifndef __NR_fanotify_mark
+# define __NR_fanotify_mark 338
+# endif
+# ifndef __NR_prlimit64
+# define __NR_prlimit64 339
+# endif
+# ifndef __NR_socket
+# define __NR_socket 340
+# endif
+# ifndef __NR_bind
+# define __NR_bind 341
+# endif
+# ifndef __NR_connect
+# define __NR_connect 342
+# endif
+# ifndef __NR_listen
+# define __NR_listen 343
+# endif
+# ifndef __NR_accept
+# define __NR_accept 344
+# endif
+# ifndef __NR_getsockname
+# define __NR_getsockname 345
+# endif
+# ifndef __NR_getpeername
+# define __NR_getpeername 346
+# endif
+# ifndef __NR_socketpair
+# define __NR_socketpair 347
+# endif
+# ifndef __NR_send
+# define __NR_send 348
+# endif
+# ifndef __NR_sendto
+# define __NR_sendto 349
+# endif
+# ifndef __NR_recv
+# define __NR_recv 350
+# endif
+# ifndef __NR_recvfrom
+# define __NR_recvfrom 351
+# endif
+# ifndef __NR_shutdown
+# define __NR_shutdown 352
+# endif
+# ifndef __NR_setsockopt
+# define __NR_setsockopt 353
+# endif
+# ifndef __NR_getsockopt
+# define __NR_getsockopt 354
+# endif
+# ifndef __NR_sendmsg
+# define __NR_sendmsg 355
+# endif
+# ifndef __NR_recvmsg
+# define __NR_recvmsg 356
+# endif
+# ifndef __NR_recvmmsg
+# define __NR_recvmmsg 357
+# endif
+# ifndef __NR_accept4
+# define __NR_accept4 358
+# endif
+# ifndef __NR_name_to_handle_at
+# define __NR_name_to_handle_at 359
+# endif
+# ifndef __NR_open_by_handle_at
+# define __NR_open_by_handle_at 360
+# endif
+# ifndef __NR_clock_adjtime
+# define __NR_clock_adjtime 361
+# endif
+# ifndef __NR_syncfs
+# define __NR_syncfs 362
+# endif
+# ifndef __NR_sendmmsg
+# define __NR_sendmmsg 363
+# endif
+# ifndef __NR_setns
+# define __NR_setns 364
+# endif
+# ifndef __NR_process_vm_readv
+# define __NR_process_vm_readv 365
+# endif
+# ifndef __NR_process_vm_writev
+# define __NR_process_vm_writev 366
+# endif
+# ifndef __NR_kcmp
+# define __NR_kcmp 367
+# endif
+# ifndef __NR_finit_module
+# define __NR_finit_module 368
+# endif
+# ifndef __NR_sched_getattr
+# define __NR_sched_getattr 369
+# endif
+# ifndef __NR_sched_setattr
+# define __NR_sched_setattr 370
+# endif
+# ifndef __NR_renameat2
+# define __NR_renameat2 371
+# endif
+# ifndef __NR_seccomp
+# define __NR_seccomp 372
+# endif
+# ifndef __NR_getrandom
+# define __NR_getrandom 373
+# endif
+# ifndef __NR_memfd_create
+# define __NR_memfd_create 374
+# endif
+# ifndef __NR_bpf
+# define __NR_bpf 375
+# endif
+# ifndef __NR_execveat
+# define __NR_execveat 376
+# endif
+# ifndef __NR_userfaultfd
+# define __NR_userfaultfd 377
+# endif
+# ifndef __NR_membarrier
+# define __NR_membarrier 378
+# endif
+# ifndef __NR_mlock2
+# define __NR_mlock2 379
+# endif
+# ifndef __NR_copy_file_range
+# define __NR_copy_file_range 380
+# endif
+# ifndef __NR_preadv2
+# define __NR_preadv2 381
+# endif
+# ifndef __NR_pwritev2
+# define __NR_pwritev2 382
+# endif
+# ifndef __NR_statx
+# define __NR_statx 383
+# endif
+# ifndef __NR_pkey_mprotect
+# define __NR_pkey_mprotect 384
+# endif
+# ifndef __NR_pkey_alloc
+# define __NR_pkey_alloc 385
+# endif
+# ifndef __NR_pkey_free
+# define __NR_pkey_free 386
+# endif
+# ifndef __NR_rseq
+# define __NR_rseq 387
+# endif
+# ifndef __NR_semget
+# define __NR_semget 393
+# endif
+# ifndef __NR_semctl
+# define __NR_semctl 394
+# endif
+# ifndef __NR_shmget
+# define __NR_shmget 395
+# endif
+# ifndef __NR_shmctl
+# define __NR_shmctl 396
+# endif
+# ifndef __NR_shmat
+# define __NR_shmat 397
+# endif
+# ifndef __NR_shmdt
+# define __NR_shmdt 398
+# endif
+# ifndef __NR_msgget
+# define __NR_msgget 399
+# endif
+# ifndef __NR_msgsnd
+# define __NR_msgsnd 400
+# endif
+# ifndef __NR_msgrcv
+# define __NR_msgrcv 401
+# endif
+# ifndef __NR_msgctl
+# define __NR_msgctl 402
+# endif
+# ifndef __NR_clock_gettime64
+# define __NR_clock_gettime64 403
+# endif
+# ifndef __NR_clock_settime64
+# define __NR_clock_settime64 404
+# endif
+# ifndef __NR_clock_adjtime64
+# define __NR_clock_adjtime64 405
+# endif
+# ifndef __NR_clock_getres_time64
+# define __NR_clock_getres_time64 406
+# endif
+# ifndef __NR_clock_nanosleep_time64
+# define __NR_clock_nanosleep_time64 407
+# endif
+# ifndef __NR_timer_gettime64
+# define __NR_timer_gettime64 408
+# endif
+# ifndef __NR_timer_settime64
+# define __NR_timer_settime64 409
+# endif
+# ifndef __NR_timerfd_gettime64
+# define __NR_timerfd_gettime64 410
+# endif
+# ifndef __NR_timerfd_settime64
+# define __NR_timerfd_settime64 411
+# endif
+# ifndef __NR_utimensat_time64
+# define __NR_utimensat_time64 412
+# endif
+# ifndef __NR_pselect6_time64
+# define __NR_pselect6_time64 413
+# endif
+# ifndef __NR_ppoll_time64
+# define __NR_ppoll_time64 414
+# endif
+# ifndef __NR_io_pgetevents_time64
+# define __NR_io_pgetevents_time64 416
+# endif
+# ifndef __NR_recvmmsg_time64
+# define __NR_recvmmsg_time64 417
+# endif
+# ifndef __NR_mq_timedsend_time64
+# define __NR_mq_timedsend_time64 418
+# endif
+# ifndef __NR_mq_timedreceive_time64
+# define __NR_mq_timedreceive_time64 419
+# endif
+# ifndef __NR_semtimedop_time64
+# define __NR_semtimedop_time64 420
+# endif
+# ifndef __NR_rt_sigtimedwait_time64
+# define __NR_rt_sigtimedwait_time64 421
+# endif
+# ifndef __NR_futex_time64
+# define __NR_futex_time64 422
+# endif
+# ifndef __NR_sched_rr_get_interval_time64
+# define __NR_sched_rr_get_interval_time64 423
+# endif
+# ifndef __NR_pidfd_send_signal
+# define __NR_pidfd_send_signal 424
+# endif
+# ifndef __NR_io_uring_setup
+# define __NR_io_uring_setup 425
+# endif
+# ifndef __NR_io_uring_enter
+# define __NR_io_uring_enter 426
+# endif
+# ifndef __NR_io_uring_register
+# define __NR_io_uring_register 427
+# endif
+# ifndef __NR_open_tree
+# define __NR_open_tree 428
+# endif
+# ifndef __NR_move_mount
+# define __NR_move_mount 429
+# endif
+# ifndef __NR_fsopen
+# define __NR_fsopen 430
+# endif
+# ifndef __NR_fsconfig
+# define __NR_fsconfig 431
+# endif
+# ifndef __NR_fsmount
+# define __NR_fsmount 432
+# endif
+# ifndef __NR_fspick
+# define __NR_fspick 433
+# endif
+# ifndef __NR_pidfd_open
+# define __NR_pidfd_open 434
+# endif
+# ifndef __NR_openat2
+# define __NR_openat2 437
+# endif
+# ifndef __NR_pidfd_getfd
+# define __NR_pidfd_getfd 438
+# endif
+#endif
+
+
+#if defined(__sparc__) && defined(__arch64__)
+# ifndef __NR_restart_syscall
+# define __NR_restart_syscall 0
+# endif
+# ifndef __NR_exit
+# define __NR_exit 1
+# endif
+# ifndef __NR_fork
+# define __NR_fork 2
+# endif
+# ifndef __NR_read
+# define __NR_read 3
+# endif
+# ifndef __NR_write
+# define __NR_write 4
+# endif
+# ifndef __NR_open
+# define __NR_open 5
+# endif
+# ifndef __NR_close
+# define __NR_close 6
+# endif
+# ifndef __NR_wait4
+# define __NR_wait4 7
+# endif
+# ifndef __NR_creat
+# define __NR_creat 8
+# endif
+# ifndef __NR_link
+# define __NR_link 9
+# endif
+# ifndef __NR_unlink
+# define __NR_unlink 10
+# endif
+# ifndef __NR_execv
+# define __NR_execv 11
+# endif
+# ifndef __NR_chdir
+# define __NR_chdir 12
+# endif
+# ifndef __NR_chown
+# define __NR_chown 13
+# endif
+# ifndef __NR_mknod
+# define __NR_mknod 14
+# endif
+# ifndef __NR_chmod
+# define __NR_chmod 15
+# endif
+# ifndef __NR_lchown
+# define __NR_lchown 16
+# endif
+# ifndef __NR_brk
+# define __NR_brk 17
+# endif
+# ifndef __NR_perfctr
+# define __NR_perfctr 18
+# endif
+# ifndef __NR_lseek
+# define __NR_lseek 19
+# endif
+# ifndef __NR_getpid
+# define __NR_getpid 20
+# endif
+# ifndef __NR_capget
+# define __NR_capget 21
+# endif
+# ifndef __NR_capset
+# define __NR_capset 22
+# endif
+# ifndef __NR_setuid
+# define __NR_setuid 23
+# endif
+# ifndef __NR_getuid
+# define __NR_getuid 24
+# endif
+# ifndef __NR_vmsplice
+# define __NR_vmsplice 25
+# endif
+# ifndef __NR_ptrace
+# define __NR_ptrace 26
+# endif
+# ifndef __NR_alarm
+# define __NR_alarm 27
+# endif
+# ifndef __NR_sigaltstack
+# define __NR_sigaltstack 28
+# endif
+# ifndef __NR_pause
+# define __NR_pause 29
+# endif
+# ifndef __NR_utime
+# define __NR_utime 30
+# endif
+# ifndef __NR_lchown32
+# define __NR_lchown32 31
+# endif
+# ifndef __NR_fchown32
+# define __NR_fchown32 32
+# endif
+# ifndef __NR_access
+# define __NR_access 33
+# endif
+# ifndef __NR_nice
+# define __NR_nice 34
+# endif
+# ifndef __NR_sync
+# define __NR_sync 36
+# endif
+# ifndef __NR_kill
+# define __NR_kill 37
+# endif
+# ifndef __NR_stat
+# define __NR_stat 38
+# endif
+# ifndef __NR_sendfile
+# define __NR_sendfile 39
+# endif
+# ifndef __NR_lstat
+# define __NR_lstat 40
+# endif
+# ifndef __NR_dup
+# define __NR_dup 41
+# endif
+# ifndef __NR_pipe
+# define __NR_pipe 42
+# endif
+# ifndef __NR_times
+# define __NR_times 43
+# endif
+# ifndef __NR_umount2
+# define __NR_umount2 45
+# endif
+# ifndef __NR_setgid
+# define __NR_setgid 46
+# endif
+# ifndef __NR_getgid
+# define __NR_getgid 47
+# endif
+# ifndef __NR_signal
+# define __NR_signal 48
+# endif
+# ifndef __NR_geteuid
+# define __NR_geteuid 49
+# endif
+# ifndef __NR_getegid
+# define __NR_getegid 50
+# endif
+# ifndef __NR_acct
+# define __NR_acct 51
+# endif
+# ifndef __NR_memory_ordering
+# define __NR_memory_ordering 52
+# endif
+# ifndef __NR_ioctl
+# define __NR_ioctl 54
+# endif
+# ifndef __NR_reboot
+# define __NR_reboot 55
+# endif
+# ifndef __NR_symlink
+# define __NR_symlink 57
+# endif
+# ifndef __NR_readlink
+# define __NR_readlink 58
+# endif
+# ifndef __NR_execve
+# define __NR_execve 59
+# endif
+# ifndef __NR_umask
+# define __NR_umask 60
+# endif
+# ifndef __NR_chroot
+# define __NR_chroot 61
+# endif
+# ifndef __NR_fstat
+# define __NR_fstat 62
+# endif
+# ifndef __NR_fstat64
+# define __NR_fstat64 63
+# endif
+# ifndef __NR_getpagesize
+# define __NR_getpagesize 64
+# endif
+# ifndef __NR_msync
+# define __NR_msync 65
+# endif
+# ifndef __NR_vfork
+# define __NR_vfork 66
+# endif
+# ifndef __NR_pread64
+# define __NR_pread64 67
+# endif
+# ifndef __NR_pwrite64
+# define __NR_pwrite64 68
+# endif
+# ifndef __NR_mmap
+# define __NR_mmap 71
+# endif
+# ifndef __NR_munmap
+# define __NR_munmap 73
+# endif
+# ifndef __NR_mprotect
+# define __NR_mprotect 74
+# endif
+# ifndef __NR_madvise
+# define __NR_madvise 75
+# endif
+# ifndef __NR_vhangup
+# define __NR_vhangup 76
+# endif
+# ifndef __NR_mincore
+# define __NR_mincore 78
+# endif
+# ifndef __NR_getgroups
+# define __NR_getgroups 79
+# endif
+# ifndef __NR_setgroups
+# define __NR_setgroups 80
+# endif
+# ifndef __NR_getpgrp
+# define __NR_getpgrp 81
+# endif
+# ifndef __NR_setitimer
+# define __NR_setitimer 83
+# endif
+# ifndef __NR_swapon
+# define __NR_swapon 85
+# endif
+# ifndef __NR_getitimer
+# define __NR_getitimer 86
+# endif
+# ifndef __NR_sethostname
+# define __NR_sethostname 88
+# endif
+# ifndef __NR_dup2
+# define __NR_dup2 90
+# endif
+# ifndef __NR_fcntl
+# define __NR_fcntl 92
+# endif
+# ifndef __NR_select
+# define __NR_select 93
+# endif
+# ifndef __NR_fsync
+# define __NR_fsync 95
+# endif
+# ifndef __NR_setpriority
+# define __NR_setpriority 96
+# endif
+# ifndef __NR_socket
+# define __NR_socket 97
+# endif
+# ifndef __NR_connect
+# define __NR_connect 98
+# endif
+# ifndef __NR_accept
+# define __NR_accept 99
+# endif
+# ifndef __NR_getpriority
+# define __NR_getpriority 100
+# endif
+# ifndef __NR_rt_sigreturn
+# define __NR_rt_sigreturn 101
+# endif
+# ifndef __NR_rt_sigaction
+# define __NR_rt_sigaction 102
+# endif
+# ifndef __NR_rt_sigprocmask
+# define __NR_rt_sigprocmask 103
+# endif
+# ifndef __NR_rt_sigpending
+# define __NR_rt_sigpending 104
+# endif
+# ifndef __NR_rt_sigtimedwait
+# define __NR_rt_sigtimedwait 105
+# endif
+# ifndef __NR_rt_sigqueueinfo
+# define __NR_rt_sigqueueinfo 106
+# endif
+# ifndef __NR_rt_sigsuspend
+# define __NR_rt_sigsuspend 107
+# endif
+# ifndef __NR_setresuid
+# define __NR_setresuid 108
+# endif
+# ifndef __NR_getresuid
+# define __NR_getresuid 109
+# endif
+# ifndef __NR_setresgid
+# define __NR_setresgid 110
+# endif
+# ifndef __NR_getresgid
+# define __NR_getresgid 111
+# endif
+# ifndef __NR_recvmsg
+# define __NR_recvmsg 113
+# endif
+# ifndef __NR_sendmsg
+# define __NR_sendmsg 114
+# endif
+# ifndef __NR_gettimeofday
+# define __NR_gettimeofday 116
+# endif
+# ifndef __NR_getrusage
+# define __NR_getrusage 117
+# endif
+# ifndef __NR_getsockopt
+# define __NR_getsockopt 118
+# endif
+# ifndef __NR_getcwd
+# define __NR_getcwd 119
+# endif
+# ifndef __NR_readv
+# define __NR_readv 120
+# endif
+# ifndef __NR_writev
+# define __NR_writev 121
+# endif
+# ifndef __NR_settimeofday
+# define __NR_settimeofday 122
+# endif
+# ifndef __NR_fchown
+# define __NR_fchown 123
+# endif
+# ifndef __NR_fchmod
+# define __NR_fchmod 124
+# endif
+# ifndef __NR_recvfrom
+# define __NR_recvfrom 125
+# endif
+# ifndef __NR_setreuid
+# define __NR_setreuid 126
+# endif
+# ifndef __NR_setregid
+# define __NR_setregid 127
+# endif
+# ifndef __NR_rename
+# define __NR_rename 128
+# endif
+# ifndef __NR_truncate
+# define __NR_truncate 129
+# endif
+# ifndef __NR_ftruncate
+# define __NR_ftruncate 130
+# endif
+# ifndef __NR_flock
+# define __NR_flock 131
+# endif
+# ifndef __NR_lstat64
+# define __NR_lstat64 132
+# endif
+# ifndef __NR_sendto
+# define __NR_sendto 133
+# endif
+# ifndef __NR_shutdown
+# define __NR_shutdown 134
+# endif
+# ifndef __NR_socketpair
+# define __NR_socketpair 135
+# endif
+# ifndef __NR_mkdir
+# define __NR_mkdir 136
+# endif
+# ifndef __NR_rmdir
+# define __NR_rmdir 137
+# endif
+# ifndef __NR_utimes
+# define __NR_utimes 138
+# endif
+# ifndef __NR_stat64
+# define __NR_stat64 139
+# endif
+# ifndef __NR_sendfile64
+# define __NR_sendfile64 140
+# endif
+# ifndef __NR_getpeername
+# define __NR_getpeername 141
+# endif
+# ifndef __NR_futex
+# define __NR_futex 142
+# endif
+# ifndef __NR_gettid
+# define __NR_gettid 143
+# endif
+# ifndef __NR_getrlimit
+# define __NR_getrlimit 144
+# endif
+# ifndef __NR_setrlimit
+# define __NR_setrlimit 145
+# endif
+# ifndef __NR_pivot_root
+# define __NR_pivot_root 146
+# endif
+# ifndef __NR_prctl
+# define __NR_prctl 147
+# endif
+# ifndef __NR_pciconfig_read
+# define __NR_pciconfig_read 148
+# endif
+# ifndef __NR_pciconfig_write
+# define __NR_pciconfig_write 149
+# endif
+# ifndef __NR_getsockname
+# define __NR_getsockname 150
+# endif
+# ifndef __NR_inotify_init
+# define __NR_inotify_init 151
+# endif
+# ifndef __NR_inotify_add_watch
+# define __NR_inotify_add_watch 152
+# endif
+# ifndef __NR_poll
+# define __NR_poll 153
+# endif
+# ifndef __NR_getdents64
+# define __NR_getdents64 154
+# endif
+# ifndef __NR_inotify_rm_watch
+# define __NR_inotify_rm_watch 156
+# endif
+# ifndef __NR_statfs
+# define __NR_statfs 157
+# endif
+# ifndef __NR_fstatfs
+# define __NR_fstatfs 158
+# endif
+# ifndef __NR_umount
+# define __NR_umount 159
+# endif
+# ifndef __NR_sched_set_affinity
+# define __NR_sched_set_affinity 160
+# endif
+# ifndef __NR_sched_get_affinity
+# define __NR_sched_get_affinity 161
+# endif
+# ifndef __NR_getdomainname
+# define __NR_getdomainname 162
+# endif
+# ifndef __NR_setdomainname
+# define __NR_setdomainname 163
+# endif
+# ifndef __NR_utrap_install
+# define __NR_utrap_install 164
+# endif
+# ifndef __NR_quotactl
+# define __NR_quotactl 165
+# endif
+# ifndef __NR_set_tid_address
+# define __NR_set_tid_address 166
+# endif
+# ifndef __NR_mount
+# define __NR_mount 167
+# endif
+# ifndef __NR_ustat
+# define __NR_ustat 168
+# endif
+# ifndef __NR_setxattr
+# define __NR_setxattr 169
+# endif
+# ifndef __NR_lsetxattr
+# define __NR_lsetxattr 170
+# endif
+# ifndef __NR_fsetxattr
+# define __NR_fsetxattr 171
+# endif
+# ifndef __NR_getxattr
+# define __NR_getxattr 172
+# endif
+# ifndef __NR_lgetxattr
+# define __NR_lgetxattr 173
+# endif
+# ifndef __NR_getdents
+# define __NR_getdents 174
+# endif
+# ifndef __NR_setsid
+# define __NR_setsid 175
+# endif
+# ifndef __NR_fchdir
+# define __NR_fchdir 176
+# endif
+# ifndef __NR_fgetxattr
+# define __NR_fgetxattr 177
+# endif
+# ifndef __NR_listxattr
+# define __NR_listxattr 178
+# endif
+# ifndef __NR_llistxattr
+# define __NR_llistxattr 179
+# endif
+# ifndef __NR_flistxattr
+# define __NR_flistxattr 180
+# endif
+# ifndef __NR_removexattr
+# define __NR_removexattr 181
+# endif
+# ifndef __NR_lremovexattr
+# define __NR_lremovexattr 182
+# endif
+# ifndef __NR_sigpending
+# define __NR_sigpending 183
+# endif
+# ifndef __NR_query_module
+# define __NR_query_module 184
+# endif
+# ifndef __NR_setpgid
+# define __NR_setpgid 185
+# endif
+# ifndef __NR_fremovexattr
+# define __NR_fremovexattr 186
+# endif
+# ifndef __NR_tkill
+# define __NR_tkill 187
+# endif
+# ifndef __NR_exit_group
+# define __NR_exit_group 188
+# endif
+# ifndef __NR_uname
+# define __NR_uname 189
+# endif
+# ifndef __NR_init_module
+# define __NR_init_module 190
+# endif
+# ifndef __NR_personality
+# define __NR_personality 191
+# endif
+# ifndef __NR_remap_file_pages
+# define __NR_remap_file_pages 192
+# endif
+# ifndef __NR_epoll_create
+# define __NR_epoll_create 193
+# endif
+# ifndef __NR_epoll_ctl
+# define __NR_epoll_ctl 194
+# endif
+# ifndef __NR_epoll_wait
+# define __NR_epoll_wait 195
+# endif
+# ifndef __NR_ioprio_set
+# define __NR_ioprio_set 196
+# endif
+# ifndef __NR_getppid
+# define __NR_getppid 197
+# endif
+# ifndef __NR_sigaction
+# define __NR_sigaction 198
+# endif
+# ifndef __NR_sgetmask
+# define __NR_sgetmask 199
+# endif
+# ifndef __NR_ssetmask
+# define __NR_ssetmask 200
+# endif
+# ifndef __NR_sigsuspend
+# define __NR_sigsuspend 201
+# endif
+# ifndef __NR_oldlstat
+# define __NR_oldlstat 202
+# endif
+# ifndef __NR_uselib
+# define __NR_uselib 203
+# endif
+# ifndef __NR_readdir
+# define __NR_readdir 204
+# endif
+# ifndef __NR_readahead
+# define __NR_readahead 205
+# endif
+# ifndef __NR_socketcall
+# define __NR_socketcall 206
+# endif
+# ifndef __NR_syslog
+# define __NR_syslog 207
+# endif
+# ifndef __NR_lookup_dcookie
+# define __NR_lookup_dcookie 208
+# endif
+# ifndef __NR_fadvise64
+# define __NR_fadvise64 209
+# endif
+# ifndef __NR_fadvise64_64
+# define __NR_fadvise64_64 210
+# endif
+# ifndef __NR_tgkill
+# define __NR_tgkill 211
+# endif
+# ifndef __NR_waitpid
+# define __NR_waitpid 212
+# endif
+# ifndef __NR_swapoff
+# define __NR_swapoff 213
+# endif
+# ifndef __NR_sysinfo
+# define __NR_sysinfo 214
+# endif
+# ifndef __NR_ipc
+# define __NR_ipc 215
+# endif
+# ifndef __NR_sigreturn
+# define __NR_sigreturn 216
+# endif
+# ifndef __NR_clone
+# define __NR_clone 217
+# endif
+# ifndef __NR_ioprio_get
+# define __NR_ioprio_get 218
+# endif
+# ifndef __NR_adjtimex
+# define __NR_adjtimex 219
+# endif
+# ifndef __NR_sigprocmask
+# define __NR_sigprocmask 220
+# endif
+# ifndef __NR_create_module
+# define __NR_create_module 221
+# endif
+# ifndef __NR_delete_module
+# define __NR_delete_module 222
+# endif
+# ifndef __NR_get_kernel_syms
+# define __NR_get_kernel_syms 223
+# endif
+# ifndef __NR_getpgid
+# define __NR_getpgid 224
+# endif
+# ifndef __NR_bdflush
+# define __NR_bdflush 225
+# endif
+# ifndef __NR_sysfs
+# define __NR_sysfs 226
+# endif
+# ifndef __NR_afs_syscall
+# define __NR_afs_syscall 227
+# endif
+# ifndef __NR_setfsuid
+# define __NR_setfsuid 228
+# endif
+# ifndef __NR_setfsgid
+# define __NR_setfsgid 229
+# endif
+# ifndef __NR__newselect
+# define __NR__newselect 230
+# endif
+# ifndef __NR_splice
+# define __NR_splice 232
+# endif
+# ifndef __NR_stime
+# define __NR_stime 233
+# endif
+# ifndef __NR_statfs64
+# define __NR_statfs64 234
+# endif
+# ifndef __NR_fstatfs64
+# define __NR_fstatfs64 235
+# endif
+# ifndef __NR__llseek
+# define __NR__llseek 236
+# endif
+# ifndef __NR_mlock
+# define __NR_mlock 237
+# endif
+# ifndef __NR_munlock
+# define __NR_munlock 238
+# endif
+# ifndef __NR_mlockall
+# define __NR_mlockall 239
+# endif
+# ifndef __NR_munlockall
+# define __NR_munlockall 240
+# endif
+# ifndef __NR_sched_setparam
+# define __NR_sched_setparam 241
+# endif
+# ifndef __NR_sched_getparam
+# define __NR_sched_getparam 242
+# endif
+# ifndef __NR_sched_setscheduler
+# define __NR_sched_setscheduler 243
+# endif
+# ifndef __NR_sched_getscheduler
+# define __NR_sched_getscheduler 244
+# endif
+# ifndef __NR_sched_yield
+# define __NR_sched_yield 245
+# endif
+# ifndef __NR_sched_get_priority_max
+# define __NR_sched_get_priority_max 246
+# endif
+# ifndef __NR_sched_get_priority_min
+# define __NR_sched_get_priority_min 247
+# endif
+# ifndef __NR_sched_rr_get_interval
+# define __NR_sched_rr_get_interval 248
+# endif
+# ifndef __NR_nanosleep
+# define __NR_nanosleep 249
+# endif
+# ifndef __NR_mremap
+# define __NR_mremap 250
+# endif
+# ifndef __NR__sysctl
+# define __NR__sysctl 251
+# endif
+# ifndef __NR_getsid
+# define __NR_getsid 252
+# endif
+# ifndef __NR_fdatasync
+# define __NR_fdatasync 253
+# endif
+# ifndef __NR_nfsservctl
+# define __NR_nfsservctl 254
+# endif
+# ifndef __NR_sync_file_range
+# define __NR_sync_file_range 255
+# endif
+# ifndef __NR_clock_settime
+# define __NR_clock_settime 256
+# endif
+# ifndef __NR_clock_gettime
+# define __NR_clock_gettime 257
+# endif
+# ifndef __NR_clock_getres
+# define __NR_clock_getres 258
+# endif
+# ifndef __NR_clock_nanosleep
+# define __NR_clock_nanosleep 259
+# endif
+# ifndef __NR_sched_getaffinity
+# define __NR_sched_getaffinity 260
+# endif
+# ifndef __NR_sched_setaffinity
+# define __NR_sched_setaffinity 261
+# endif
+# ifndef __NR_timer_settime
+# define __NR_timer_settime 262
+# endif
+# ifndef __NR_timer_gettime
+# define __NR_timer_gettime 263
+# endif
+# ifndef __NR_timer_getoverrun
+# define __NR_timer_getoverrun 264
+# endif
+# ifndef __NR_timer_delete
+# define __NR_timer_delete 265
+# endif
+# ifndef __NR_timer_create
+# define __NR_timer_create 266
+# endif
+# ifndef __NR_vserver
+# define __NR_vserver 267
+# endif
+# ifndef __NR_io_setup
+# define __NR_io_setup 268
+# endif
+# ifndef __NR_io_destroy
+# define __NR_io_destroy 269
+# endif
+# ifndef __NR_io_submit
+# define __NR_io_submit 270
+# endif
+# ifndef __NR_io_cancel
+# define __NR_io_cancel 271
+# endif
+# ifndef __NR_io_getevents
+# define __NR_io_getevents 272
+# endif
+# ifndef __NR_mq_open
+# define __NR_mq_open 273
+# endif
+# ifndef __NR_mq_unlink
+# define __NR_mq_unlink 274
+# endif
+# ifndef __NR_mq_timedsend
+# define __NR_mq_timedsend 275
+# endif
+# ifndef __NR_mq_timedreceive
+# define __NR_mq_timedreceive 276
+# endif
+# ifndef __NR_mq_notify
+# define __NR_mq_notify 277
+# endif
+# ifndef __NR_mq_getsetattr
+# define __NR_mq_getsetattr 278
+# endif
+# ifndef __NR_waitid
+# define __NR_waitid 279
+# endif
+# ifndef __NR_tee
+# define __NR_tee 280
+# endif
+# ifndef __NR_add_key
+# define __NR_add_key 281
+# endif
+# ifndef __NR_request_key
+# define __NR_request_key 282
+# endif
+# ifndef __NR_keyctl
+# define __NR_keyctl 283
+# endif
+# ifndef __NR_openat
+# define __NR_openat 284
+# endif
+# ifndef __NR_mkdirat
+# define __NR_mkdirat 285
+# endif
+# ifndef __NR_mknodat
+# define __NR_mknodat 286
+# endif
+# ifndef __NR_fchownat
+# define __NR_fchownat 287
+# endif
+# ifndef __NR_futimesat
+# define __NR_futimesat 288
+# endif
+# ifndef __NR_fstatat64
+# define __NR_fstatat64 289
+# endif
+# ifndef __NR_unlinkat
+# define __NR_unlinkat 290
+# endif
+# ifndef __NR_renameat
+# define __NR_renameat 291
+# endif
+# ifndef __NR_linkat
+# define __NR_linkat 292
+# endif
+# ifndef __NR_symlinkat
+# define __NR_symlinkat 293
+# endif
+# ifndef __NR_readlinkat
+# define __NR_readlinkat 294
+# endif
+# ifndef __NR_fchmodat
+# define __NR_fchmodat 295
+# endif
+# ifndef __NR_faccessat
+# define __NR_faccessat 296
+# endif
+# ifndef __NR_pselect6
+# define __NR_pselect6 297
+# endif
+# ifndef __NR_ppoll
+# define __NR_ppoll 298
+# endif
+# ifndef __NR_unshare
+# define __NR_unshare 299
+# endif
+# ifndef __NR_set_robust_list
+# define __NR_set_robust_list 300
+# endif
+# ifndef __NR_get_robust_list
+# define __NR_get_robust_list 301
+# endif
+# ifndef __NR_migrate_pages
+# define __NR_migrate_pages 302
+# endif
+# ifndef __NR_mbind
+# define __NR_mbind 303
+# endif
+# ifndef __NR_get_mempolicy
+# define __NR_get_mempolicy 304
+# endif
+# ifndef __NR_set_mempolicy
+# define __NR_set_mempolicy 305
+# endif
+# ifndef __NR_kexec_load
+# define __NR_kexec_load 306
+# endif
+# ifndef __NR_move_pages
+# define __NR_move_pages 307
+# endif
+# ifndef __NR_getcpu
+# define __NR_getcpu 308
+# endif
+# ifndef __NR_epoll_pwait
+# define __NR_epoll_pwait 309
+# endif
+# ifndef __NR_utimensat
+# define __NR_utimensat 310
+# endif
+# ifndef __NR_signalfd
+# define __NR_signalfd 311
+# endif
+# ifndef __NR_timerfd_create
+# define __NR_timerfd_create 312
+# endif
+# ifndef __NR_eventfd
+# define __NR_eventfd 313
+# endif
+# ifndef __NR_fallocate
+# define __NR_fallocate 314
+# endif
+# ifndef __NR_timerfd_settime
+# define __NR_timerfd_settime 315
+# endif
+# ifndef __NR_timerfd_gettime
+# define __NR_timerfd_gettime 316
+# endif
+# ifndef __NR_signalfd4
+# define __NR_signalfd4 317
+# endif
+# ifndef __NR_eventfd2
+# define __NR_eventfd2 318
+# endif
+# ifndef __NR_epoll_create1
+# define __NR_epoll_create1 319
+# endif
+# ifndef __NR_dup3
+# define __NR_dup3 320
+# endif
+# ifndef __NR_pipe2
+# define __NR_pipe2 321
+# endif
+# ifndef __NR_inotify_init1
+# define __NR_inotify_init1 322
+# endif
+# ifndef __NR_accept4
+# define __NR_accept4 323
+# endif
+# ifndef __NR_preadv
+# define __NR_preadv 324
+# endif
+# ifndef __NR_pwritev
+# define __NR_pwritev 325
+# endif
+# ifndef __NR_rt_tgsigqueueinfo
+# define __NR_rt_tgsigqueueinfo 326
+# endif
+# ifndef __NR_perf_event_open
+# define __NR_perf_event_open 327
+# endif
+# ifndef __NR_recvmmsg
+# define __NR_recvmmsg 328
+# endif
+# ifndef __NR_fanotify_init
+# define __NR_fanotify_init 329
+# endif
+# ifndef __NR_fanotify_mark
+# define __NR_fanotify_mark 330
+# endif
+# ifndef __NR_prlimit64
+# define __NR_prlimit64 331
+# endif
+# ifndef __NR_name_to_handle_at
+# define __NR_name_to_handle_at 332
+# endif
+# ifndef __NR_open_by_handle_at
+# define __NR_open_by_handle_at 333
+# endif
+# ifndef __NR_clock_adjtime
+# define __NR_clock_adjtime 334
+# endif
+# ifndef __NR_syncfs
+# define __NR_syncfs 335
+# endif
+# ifndef __NR_sendmmsg
+# define __NR_sendmmsg 336
+# endif
+# ifndef __NR_setns
+# define __NR_setns 337
+# endif
+# ifndef __NR_process_vm_readv
+# define __NR_process_vm_readv 338
+# endif
+# ifndef __NR_process_vm_writev
+# define __NR_process_vm_writev 339
+# endif
+# ifndef __NR_kern_features
+# define __NR_kern_features 340
+# endif
+# ifndef __NR_kcmp
+# define __NR_kcmp 341
+# endif
+# ifndef __NR_finit_module
+# define __NR_finit_module 342
+# endif
+# ifndef __NR_sched_setattr
+# define __NR_sched_setattr 343
+# endif
+# ifndef __NR_sched_getattr
+# define __NR_sched_getattr 344
+# endif
+# ifndef __NR_renameat2
+# define __NR_renameat2 345
+# endif
+# ifndef __NR_seccomp
+# define __NR_seccomp 346
+# endif
+# ifndef __NR_getrandom
+# define __NR_getrandom 347
+# endif
+# ifndef __NR_memfd_create
+# define __NR_memfd_create 348
+# endif
+# ifndef __NR_bpf
+# define __NR_bpf 349
+# endif
+# ifndef __NR_execveat
+# define __NR_execveat 350
+# endif
+# ifndef __NR_membarrier
+# define __NR_membarrier 351
+# endif
+# ifndef __NR_userfaultfd
+# define __NR_userfaultfd 352
+# endif
+# ifndef __NR_bind
+# define __NR_bind 353
+# endif
+# ifndef __NR_listen
+# define __NR_listen 354
+# endif
+# ifndef __NR_setsockopt
+# define __NR_setsockopt 355
+# endif
+# ifndef __NR_mlock2
+# define __NR_mlock2 356
+# endif
+# ifndef __NR_copy_file_range
+# define __NR_copy_file_range 357
+# endif
+# ifndef __NR_preadv2
+# define __NR_preadv2 358
+# endif
+# ifndef __NR_pwritev2
+# define __NR_pwritev2 359
+# endif
+# ifndef __NR_statx
+# define __NR_statx 360
+# endif
+# ifndef __NR_io_pgetevents
+# define __NR_io_pgetevents 361
+# endif
+# ifndef __NR_pkey_mprotect
+# define __NR_pkey_mprotect 362
+# endif
+# ifndef __NR_pkey_alloc
+# define __NR_pkey_alloc 363
+# endif
+# ifndef __NR_pkey_free
+# define __NR_pkey_free 364
+# endif
+# ifndef __NR_rseq
+# define __NR_rseq 365
+# endif
+# ifndef __NR_semtimedop
+# define __NR_semtimedop 392
+# endif
+# ifndef __NR_semget
+# define __NR_semget 393
+# endif
+# ifndef __NR_semctl
+# define __NR_semctl 394
+# endif
+# ifndef __NR_shmget
+# define __NR_shmget 395
+# endif
+# ifndef __NR_shmctl
+# define __NR_shmctl 396
+# endif
+# ifndef __NR_shmat
+# define __NR_shmat 397
+# endif
+# ifndef __NR_shmdt
+# define __NR_shmdt 398
+# endif
+# ifndef __NR_msgget
+# define __NR_msgget 399
+# endif
+# ifndef __NR_msgsnd
+# define __NR_msgsnd 400
+# endif
+# ifndef __NR_msgrcv
+# define __NR_msgrcv 401
+# endif
+# ifndef __NR_msgctl
+# define __NR_msgctl 402
+# endif
+# ifndef __NR_pidfd_send_signal
+# define __NR_pidfd_send_signal 424
+# endif
+# ifndef __NR_io_uring_setup
+# define __NR_io_uring_setup 425
+# endif
+# ifndef __NR_io_uring_enter
+# define __NR_io_uring_enter 426
+# endif
+# ifndef __NR_io_uring_register
+# define __NR_io_uring_register 427
+# endif
+# ifndef __NR_open_tree
+# define __NR_open_tree 428
+# endif
+# ifndef __NR_move_mount
+# define __NR_move_mount 429
+# endif
+# ifndef __NR_fsopen
+# define __NR_fsopen 430
+# endif
+# ifndef __NR_fsconfig
+# define __NR_fsconfig 431
+# endif
+# ifndef __NR_fsmount
+# define __NR_fsmount 432
+# endif
+# ifndef __NR_fspick
+# define __NR_fspick 433
+# endif
+# ifndef __NR_pidfd_open
+# define __NR_pidfd_open 434
+# endif
+# ifndef __NR_openat2
+# define __NR_openat2 437
+# endif
+# ifndef __NR_pidfd_getfd
+# define __NR_pidfd_getfd 438
+# endif
+#endif
+
+
+#if defined(__sparc__) && !defined(__arch64__)
+# ifndef __NR_restart_syscall
+# define __NR_restart_syscall 0
+# endif
+# ifndef __NR_exit
+# define __NR_exit 1
+# endif
+# ifndef __NR_fork
+# define __NR_fork 2
+# endif
+# ifndef __NR_read
+# define __NR_read 3
+# endif
+# ifndef __NR_write
+# define __NR_write 4
+# endif
+# ifndef __NR_open
+# define __NR_open 5
+# endif
+# ifndef __NR_close
+# define __NR_close 6
+# endif
+# ifndef __NR_wait4
+# define __NR_wait4 7
+# endif
+# ifndef __NR_creat
+# define __NR_creat 8
+# endif
+# ifndef __NR_link
+# define __NR_link 9
+# endif
+# ifndef __NR_unlink
+# define __NR_unlink 10
+# endif
+# ifndef __NR_execv
+# define __NR_execv 11
+# endif
+# ifndef __NR_chdir
+# define __NR_chdir 12
+# endif
+# ifndef __NR_chown
+# define __NR_chown 13
+# endif
+# ifndef __NR_mknod
+# define __NR_mknod 14
+# endif
+# ifndef __NR_chmod
+# define __NR_chmod 15
+# endif
+# ifndef __NR_lchown
+# define __NR_lchown 16
+# endif
+# ifndef __NR_brk
+# define __NR_brk 17
+# endif
+# ifndef __NR_perfctr
+# define __NR_perfctr 18
+# endif
+# ifndef __NR_lseek
+# define __NR_lseek 19
+# endif
+# ifndef __NR_getpid
+# define __NR_getpid 20
+# endif
+# ifndef __NR_capget
+# define __NR_capget 21
+# endif
+# ifndef __NR_capset
+# define __NR_capset 22
+# endif
+# ifndef __NR_setuid
+# define __NR_setuid 23
+# endif
+# ifndef __NR_getuid
+# define __NR_getuid 24
+# endif
+# ifndef __NR_vmsplice
+# define __NR_vmsplice 25
+# endif
+# ifndef __NR_ptrace
+# define __NR_ptrace 26
+# endif
+# ifndef __NR_alarm
+# define __NR_alarm 27
+# endif
+# ifndef __NR_sigaltstack
+# define __NR_sigaltstack 28
+# endif
+# ifndef __NR_pause
+# define __NR_pause 29
+# endif
+# ifndef __NR_utime
+# define __NR_utime 30
+# endif
+# ifndef __NR_lchown32
+# define __NR_lchown32 31
+# endif
+# ifndef __NR_fchown32
+# define __NR_fchown32 32
+# endif
+# ifndef __NR_access
+# define __NR_access 33
+# endif
+# ifndef __NR_nice
+# define __NR_nice 34
+# endif
+# ifndef __NR_chown32
+# define __NR_chown32 35
+# endif
+# ifndef __NR_sync
+# define __NR_sync 36
+# endif
+# ifndef __NR_kill
+# define __NR_kill 37
+# endif
+# ifndef __NR_stat
+# define __NR_stat 38
+# endif
+# ifndef __NR_sendfile
+# define __NR_sendfile 39
+# endif
+# ifndef __NR_lstat
+# define __NR_lstat 40
+# endif
+# ifndef __NR_dup
+# define __NR_dup 41
+# endif
+# ifndef __NR_pipe
+# define __NR_pipe 42
+# endif
+# ifndef __NR_times
+# define __NR_times 43
+# endif
+# ifndef __NR_getuid32
+# define __NR_getuid32 44
+# endif
+# ifndef __NR_umount2
+# define __NR_umount2 45
+# endif
+# ifndef __NR_setgid
+# define __NR_setgid 46
+# endif
+# ifndef __NR_getgid
+# define __NR_getgid 47
+# endif
+# ifndef __NR_signal
+# define __NR_signal 48
+# endif
+# ifndef __NR_geteuid
+# define __NR_geteuid 49
+# endif
+# ifndef __NR_getegid
+# define __NR_getegid 50
+# endif
+# ifndef __NR_acct
+# define __NR_acct 51
+# endif
+# ifndef __NR_getgid32
+# define __NR_getgid32 53
+# endif
+# ifndef __NR_ioctl
+# define __NR_ioctl 54
+# endif
+# ifndef __NR_reboot
+# define __NR_reboot 55
+# endif
+# ifndef __NR_mmap2
+# define __NR_mmap2 56
+# endif
+# ifndef __NR_symlink
+# define __NR_symlink 57
+# endif
+# ifndef __NR_readlink
+# define __NR_readlink 58
+# endif
+# ifndef __NR_execve
+# define __NR_execve 59
+# endif
+# ifndef __NR_umask
+# define __NR_umask 60
+# endif
+# ifndef __NR_chroot
+# define __NR_chroot 61
+# endif
+# ifndef __NR_fstat
+# define __NR_fstat 62
+# endif
+# ifndef __NR_fstat64
+# define __NR_fstat64 63
+# endif
+# ifndef __NR_getpagesize
+# define __NR_getpagesize 64
+# endif
+# ifndef __NR_msync
+# define __NR_msync 65
+# endif
+# ifndef __NR_vfork
+# define __NR_vfork 66
+# endif
+# ifndef __NR_pread64
+# define __NR_pread64 67
+# endif
+# ifndef __NR_pwrite64
+# define __NR_pwrite64 68
+# endif
+# ifndef __NR_geteuid32
+# define __NR_geteuid32 69
+# endif
+# ifndef __NR_getegid32
+# define __NR_getegid32 70
+# endif
+# ifndef __NR_mmap
+# define __NR_mmap 71
+# endif
+# ifndef __NR_setreuid32
+# define __NR_setreuid32 72
+# endif
+# ifndef __NR_munmap
+# define __NR_munmap 73
+# endif
+# ifndef __NR_mprotect
+# define __NR_mprotect 74
+# endif
+# ifndef __NR_madvise
+# define __NR_madvise 75
+# endif
+# ifndef __NR_vhangup
+# define __NR_vhangup 76
+# endif
+# ifndef __NR_truncate64
+# define __NR_truncate64 77
+# endif
+# ifndef __NR_mincore
+# define __NR_mincore 78
+# endif
+# ifndef __NR_getgroups
+# define __NR_getgroups 79
+# endif
+# ifndef __NR_setgroups
+# define __NR_setgroups 80
+# endif
+# ifndef __NR_getpgrp
+# define __NR_getpgrp 81
+# endif
+# ifndef __NR_setgroups32
+# define __NR_setgroups32 82
+# endif
+# ifndef __NR_setitimer
+# define __NR_setitimer 83
+# endif
+# ifndef __NR_ftruncate64
+# define __NR_ftruncate64 84
+# endif
+# ifndef __NR_swapon
+# define __NR_swapon 85
+# endif
+# ifndef __NR_getitimer
+# define __NR_getitimer 86
+# endif
+# ifndef __NR_setuid32
+# define __NR_setuid32 87
+# endif
+# ifndef __NR_sethostname
+# define __NR_sethostname 88
+# endif
+# ifndef __NR_setgid32
+# define __NR_setgid32 89
+# endif
+# ifndef __NR_dup2
+# define __NR_dup2 90
+# endif
+# ifndef __NR_setfsuid32
+# define __NR_setfsuid32 91
+# endif
+# ifndef __NR_fcntl
+# define __NR_fcntl 92
+# endif
+# ifndef __NR_select
+# define __NR_select 93
+# endif
+# ifndef __NR_setfsgid32
+# define __NR_setfsgid32 94
+# endif
+# ifndef __NR_fsync
+# define __NR_fsync 95
+# endif
+# ifndef __NR_setpriority
+# define __NR_setpriority 96
+# endif
+# ifndef __NR_socket
+# define __NR_socket 97
+# endif
+# ifndef __NR_connect
+# define __NR_connect 98
+# endif
+# ifndef __NR_accept
+# define __NR_accept 99
+# endif
+# ifndef __NR_getpriority
+# define __NR_getpriority 100
+# endif
+# ifndef __NR_rt_sigreturn
+# define __NR_rt_sigreturn 101
+# endif
+# ifndef __NR_rt_sigaction
+# define __NR_rt_sigaction 102
+# endif
+# ifndef __NR_rt_sigprocmask
+# define __NR_rt_sigprocmask 103
+# endif
+# ifndef __NR_rt_sigpending
+# define __NR_rt_sigpending 104
+# endif
+# ifndef __NR_rt_sigtimedwait
+# define __NR_rt_sigtimedwait 105
+# endif
+# ifndef __NR_rt_sigqueueinfo
+# define __NR_rt_sigqueueinfo 106
+# endif
+# ifndef __NR_rt_sigsuspend
+# define __NR_rt_sigsuspend 107
+# endif
+# ifndef __NR_setresuid32
+# define __NR_setresuid32 108
+# endif
+# ifndef __NR_getresuid32
+# define __NR_getresuid32 109
+# endif
+# ifndef __NR_setresgid32
+# define __NR_setresgid32 110
+# endif
+# ifndef __NR_getresgid32
+# define __NR_getresgid32 111
+# endif
+# ifndef __NR_setregid32
+# define __NR_setregid32 112
+# endif
+# ifndef __NR_recvmsg
+# define __NR_recvmsg 113
+# endif
+# ifndef __NR_sendmsg
+# define __NR_sendmsg 114
+# endif
+# ifndef __NR_getgroups32
+# define __NR_getgroups32 115
+# endif
+# ifndef __NR_gettimeofday
+# define __NR_gettimeofday 116
+# endif
+# ifndef __NR_getrusage
+# define __NR_getrusage 117
+# endif
+# ifndef __NR_getsockopt
+# define __NR_getsockopt 118
+# endif
+# ifndef __NR_getcwd
+# define __NR_getcwd 119
+# endif
+# ifndef __NR_readv
+# define __NR_readv 120
+# endif
+# ifndef __NR_writev
+# define __NR_writev 121
+# endif
+# ifndef __NR_settimeofday
+# define __NR_settimeofday 122
+# endif
+# ifndef __NR_fchown
+# define __NR_fchown 123
+# endif
+# ifndef __NR_fchmod
+# define __NR_fchmod 124
+# endif
+# ifndef __NR_recvfrom
+# define __NR_recvfrom 125
+# endif
+# ifndef __NR_setreuid
+# define __NR_setreuid 126
+# endif
+# ifndef __NR_setregid
+# define __NR_setregid 127
+# endif
+# ifndef __NR_rename
+# define __NR_rename 128
+# endif
+# ifndef __NR_truncate
+# define __NR_truncate 129
+# endif
+# ifndef __NR_ftruncate
+# define __NR_ftruncate 130
+# endif
+# ifndef __NR_flock
+# define __NR_flock 131
+# endif
+# ifndef __NR_lstat64
+# define __NR_lstat64 132
+# endif
+# ifndef __NR_sendto
+# define __NR_sendto 133
+# endif
+# ifndef __NR_shutdown
+# define __NR_shutdown 134
+# endif
+# ifndef __NR_socketpair
+# define __NR_socketpair 135
+# endif
+# ifndef __NR_mkdir
+# define __NR_mkdir 136
+# endif
+# ifndef __NR_rmdir
+# define __NR_rmdir 137
+# endif
+# ifndef __NR_utimes
+# define __NR_utimes 138
+# endif
+# ifndef __NR_stat64
+# define __NR_stat64 139
+# endif
+# ifndef __NR_sendfile64
+# define __NR_sendfile64 140
+# endif
+# ifndef __NR_getpeername
+# define __NR_getpeername 141
+# endif
+# ifndef __NR_futex
+# define __NR_futex 142
+# endif
+# ifndef __NR_gettid
+# define __NR_gettid 143
+# endif
+# ifndef __NR_getrlimit
+# define __NR_getrlimit 144
+# endif
+# ifndef __NR_setrlimit
+# define __NR_setrlimit 145
+# endif
+# ifndef __NR_pivot_root
+# define __NR_pivot_root 146
+# endif
+# ifndef __NR_prctl
+# define __NR_prctl 147
+# endif
+# ifndef __NR_pciconfig_read
+# define __NR_pciconfig_read 148
+# endif
+# ifndef __NR_pciconfig_write
+# define __NR_pciconfig_write 149
+# endif
+# ifndef __NR_getsockname
+# define __NR_getsockname 150
+# endif
+# ifndef __NR_inotify_init
+# define __NR_inotify_init 151
+# endif
+# ifndef __NR_inotify_add_watch
+# define __NR_inotify_add_watch 152
+# endif
+# ifndef __NR_poll
+# define __NR_poll 153
+# endif
+# ifndef __NR_getdents64
+# define __NR_getdents64 154
+# endif
+# ifndef __NR_fcntl64
+# define __NR_fcntl64 155
+# endif
+# ifndef __NR_inotify_rm_watch
+# define __NR_inotify_rm_watch 156
+# endif
+# ifndef __NR_statfs
+# define __NR_statfs 157
+# endif
+# ifndef __NR_fstatfs
+# define __NR_fstatfs 158
+# endif
+# ifndef __NR_umount
+# define __NR_umount 159
+# endif
+# ifndef __NR_sched_set_affinity
+# define __NR_sched_set_affinity 160
+# endif
+# ifndef __NR_sched_get_affinity
+# define __NR_sched_get_affinity 161
+# endif
+# ifndef __NR_getdomainname
+# define __NR_getdomainname 162
+# endif
+# ifndef __NR_setdomainname
+# define __NR_setdomainname 163
+# endif
+# ifndef __NR_quotactl
+# define __NR_quotactl 165
+# endif
+# ifndef __NR_set_tid_address
+# define __NR_set_tid_address 166
+# endif
+# ifndef __NR_mount
+# define __NR_mount 167
+# endif
+# ifndef __NR_ustat
+# define __NR_ustat 168
+# endif
+# ifndef __NR_setxattr
+# define __NR_setxattr 169
+# endif
+# ifndef __NR_lsetxattr
+# define __NR_lsetxattr 170
+# endif
+# ifndef __NR_fsetxattr
+# define __NR_fsetxattr 171
+# endif
+# ifndef __NR_getxattr
+# define __NR_getxattr 172
+# endif
+# ifndef __NR_lgetxattr
+# define __NR_lgetxattr 173
+# endif
+# ifndef __NR_getdents
+# define __NR_getdents 174
+# endif
+# ifndef __NR_setsid
+# define __NR_setsid 175
+# endif
+# ifndef __NR_fchdir
+# define __NR_fchdir 176
+# endif
+# ifndef __NR_fgetxattr
+# define __NR_fgetxattr 177
+# endif
+# ifndef __NR_listxattr
+# define __NR_listxattr 178
+# endif
+# ifndef __NR_llistxattr
+# define __NR_llistxattr 179
+# endif
+# ifndef __NR_flistxattr
+# define __NR_flistxattr 180
+# endif
+# ifndef __NR_removexattr
+# define __NR_removexattr 181
+# endif
+# ifndef __NR_lremovexattr
+# define __NR_lremovexattr 182
+# endif
+# ifndef __NR_sigpending
+# define __NR_sigpending 183
+# endif
+# ifndef __NR_query_module
+# define __NR_query_module 184
+# endif
+# ifndef __NR_setpgid
+# define __NR_setpgid 185
+# endif
+# ifndef __NR_fremovexattr
+# define __NR_fremovexattr 186
+# endif
+# ifndef __NR_tkill
+# define __NR_tkill 187
+# endif
+# ifndef __NR_exit_group
+# define __NR_exit_group 188
+# endif
+# ifndef __NR_uname
+# define __NR_uname 189
+# endif
+# ifndef __NR_init_module
+# define __NR_init_module 190
+# endif
+# ifndef __NR_personality
+# define __NR_personality 191
+# endif
+# ifndef __NR_remap_file_pages
+# define __NR_remap_file_pages 192
+# endif
+# ifndef __NR_epoll_create
+# define __NR_epoll_create 193
+# endif
+# ifndef __NR_epoll_ctl
+# define __NR_epoll_ctl 194
+# endif
+# ifndef __NR_epoll_wait
+# define __NR_epoll_wait 195
+# endif
+# ifndef __NR_ioprio_set
+# define __NR_ioprio_set 196
+# endif
+# ifndef __NR_getppid
+# define __NR_getppid 197
+# endif
+# ifndef __NR_sigaction
+# define __NR_sigaction 198
+# endif
+# ifndef __NR_sgetmask
+# define __NR_sgetmask 199
+# endif
+# ifndef __NR_ssetmask
+# define __NR_ssetmask 200
+# endif
+# ifndef __NR_sigsuspend
+# define __NR_sigsuspend 201
+# endif
+# ifndef __NR_oldlstat
+# define __NR_oldlstat 202
+# endif
+# ifndef __NR_uselib
+# define __NR_uselib 203
+# endif
+# ifndef __NR_readdir
+# define __NR_readdir 204
+# endif
+# ifndef __NR_readahead
+# define __NR_readahead 205
+# endif
+# ifndef __NR_socketcall
+# define __NR_socketcall 206
+# endif
+# ifndef __NR_syslog
+# define __NR_syslog 207
+# endif
+# ifndef __NR_lookup_dcookie
+# define __NR_lookup_dcookie 208
+# endif
+# ifndef __NR_fadvise64
+# define __NR_fadvise64 209
+# endif
+# ifndef __NR_fadvise64_64
+# define __NR_fadvise64_64 210
+# endif
+# ifndef __NR_tgkill
+# define __NR_tgkill 211
+# endif
+# ifndef __NR_waitpid
+# define __NR_waitpid 212
+# endif
+# ifndef __NR_swapoff
+# define __NR_swapoff 213
+# endif
+# ifndef __NR_sysinfo
+# define __NR_sysinfo 214
+# endif
+# ifndef __NR_ipc
+# define __NR_ipc 215
+# endif
+# ifndef __NR_sigreturn
+# define __NR_sigreturn 216
+# endif
+# ifndef __NR_clone
+# define __NR_clone 217
+# endif
+# ifndef __NR_ioprio_get
+# define __NR_ioprio_get 218
+# endif
+# ifndef __NR_adjtimex
+# define __NR_adjtimex 219
+# endif
+# ifndef __NR_sigprocmask
+# define __NR_sigprocmask 220
+# endif
+# ifndef __NR_create_module
+# define __NR_create_module 221
+# endif
+# ifndef __NR_delete_module
+# define __NR_delete_module 222
+# endif
+# ifndef __NR_get_kernel_syms
+# define __NR_get_kernel_syms 223
+# endif
+# ifndef __NR_getpgid
+# define __NR_getpgid 224
+# endif
+# ifndef __NR_bdflush
+# define __NR_bdflush 225
+# endif
+# ifndef __NR_sysfs
+# define __NR_sysfs 226
+# endif
+# ifndef __NR_afs_syscall
+# define __NR_afs_syscall 227
+# endif
+# ifndef __NR_setfsuid
+# define __NR_setfsuid 228
+# endif
+# ifndef __NR_setfsgid
+# define __NR_setfsgid 229
+# endif
+# ifndef __NR__newselect
+# define __NR__newselect 230
+# endif
+# ifndef __NR_time
+# define __NR_time 231
+# endif
+# ifndef __NR_splice
+# define __NR_splice 232
+# endif
+# ifndef __NR_stime
+# define __NR_stime 233
+# endif
+# ifndef __NR_statfs64
+# define __NR_statfs64 234
+# endif
+# ifndef __NR_fstatfs64
+# define __NR_fstatfs64 235
+# endif
+# ifndef __NR__llseek
+# define __NR__llseek 236
+# endif
+# ifndef __NR_mlock
+# define __NR_mlock 237
+# endif
+# ifndef __NR_munlock
+# define __NR_munlock 238
+# endif
+# ifndef __NR_mlockall
+# define __NR_mlockall 239
+# endif
+# ifndef __NR_munlockall
+# define __NR_munlockall 240
+# endif
+# ifndef __NR_sched_setparam
+# define __NR_sched_setparam 241
+# endif
+# ifndef __NR_sched_getparam
+# define __NR_sched_getparam 242
+# endif
+# ifndef __NR_sched_setscheduler
+# define __NR_sched_setscheduler 243
+# endif
+# ifndef __NR_sched_getscheduler
+# define __NR_sched_getscheduler 244
+# endif
+# ifndef __NR_sched_yield
+# define __NR_sched_yield 245
+# endif
+# ifndef __NR_sched_get_priority_max
+# define __NR_sched_get_priority_max 246
+# endif
+# ifndef __NR_sched_get_priority_min
+# define __NR_sched_get_priority_min 247
+# endif
+# ifndef __NR_sched_rr_get_interval
+# define __NR_sched_rr_get_interval 248
+# endif
+# ifndef __NR_nanosleep
+# define __NR_nanosleep 249
+# endif
+# ifndef __NR_mremap
+# define __NR_mremap 250
+# endif
+# ifndef __NR__sysctl
+# define __NR__sysctl 251
+# endif
+# ifndef __NR_getsid
+# define __NR_getsid 252
+# endif
+# ifndef __NR_fdatasync
+# define __NR_fdatasync 253
+# endif
+# ifndef __NR_nfsservctl
+# define __NR_nfsservctl 254
+# endif
+# ifndef __NR_sync_file_range
+# define __NR_sync_file_range 255
+# endif
+# ifndef __NR_clock_settime
+# define __NR_clock_settime 256
+# endif
+# ifndef __NR_clock_gettime
+# define __NR_clock_gettime 257
+# endif
+# ifndef __NR_clock_getres
+# define __NR_clock_getres 258
+# endif
+# ifndef __NR_clock_nanosleep
+# define __NR_clock_nanosleep 259
+# endif
+# ifndef __NR_sched_getaffinity
+# define __NR_sched_getaffinity 260
+# endif
+# ifndef __NR_sched_setaffinity
+# define __NR_sched_setaffinity 261
+# endif
+# ifndef __NR_timer_settime
+# define __NR_timer_settime 262
+# endif
+# ifndef __NR_timer_gettime
+# define __NR_timer_gettime 263
+# endif
+# ifndef __NR_timer_getoverrun
+# define __NR_timer_getoverrun 264
+# endif
+# ifndef __NR_timer_delete
+# define __NR_timer_delete 265
+# endif
+# ifndef __NR_timer_create
+# define __NR_timer_create 266
+# endif
+# ifndef __NR_vserver
+# define __NR_vserver 267
+# endif
+# ifndef __NR_io_setup
+# define __NR_io_setup 268
+# endif
+# ifndef __NR_io_destroy
+# define __NR_io_destroy 269
+# endif
+# ifndef __NR_io_submit
+# define __NR_io_submit 270
+# endif
+# ifndef __NR_io_cancel
+# define __NR_io_cancel 271
+# endif
+# ifndef __NR_io_getevents
+# define __NR_io_getevents 272
+# endif
+# ifndef __NR_mq_open
+# define __NR_mq_open 273
+# endif
+# ifndef __NR_mq_unlink
+# define __NR_mq_unlink 274
+# endif
+# ifndef __NR_mq_timedsend
+# define __NR_mq_timedsend 275
+# endif
+# ifndef __NR_mq_timedreceive
+# define __NR_mq_timedreceive 276
+# endif
+# ifndef __NR_mq_notify
+# define __NR_mq_notify 277
+# endif
+# ifndef __NR_mq_getsetattr
+# define __NR_mq_getsetattr 278
+# endif
+# ifndef __NR_waitid
+# define __NR_waitid 279
+# endif
+# ifndef __NR_tee
+# define __NR_tee 280
+# endif
+# ifndef __NR_add_key
+# define __NR_add_key 281
+# endif
+# ifndef __NR_request_key
+# define __NR_request_key 282
+# endif
+# ifndef __NR_keyctl
+# define __NR_keyctl 283
+# endif
+# ifndef __NR_openat
+# define __NR_openat 284
+# endif
+# ifndef __NR_mkdirat
+# define __NR_mkdirat 285
+# endif
+# ifndef __NR_mknodat
+# define __NR_mknodat 286
+# endif
+# ifndef __NR_fchownat
+# define __NR_fchownat 287
+# endif
+# ifndef __NR_futimesat
+# define __NR_futimesat 288
+# endif
+# ifndef __NR_fstatat64
+# define __NR_fstatat64 289
+# endif
+# ifndef __NR_unlinkat
+# define __NR_unlinkat 290
+# endif
+# ifndef __NR_renameat
+# define __NR_renameat 291
+# endif
+# ifndef __NR_linkat
+# define __NR_linkat 292
+# endif
+# ifndef __NR_symlinkat
+# define __NR_symlinkat 293
+# endif
+# ifndef __NR_readlinkat
+# define __NR_readlinkat 294
+# endif
+# ifndef __NR_fchmodat
+# define __NR_fchmodat 295
+# endif
+# ifndef __NR_faccessat
+# define __NR_faccessat 296
+# endif
+# ifndef __NR_pselect6
+# define __NR_pselect6 297
+# endif
+# ifndef __NR_ppoll
+# define __NR_ppoll 298
+# endif
+# ifndef __NR_unshare
+# define __NR_unshare 299
+# endif
+# ifndef __NR_set_robust_list
+# define __NR_set_robust_list 300
+# endif
+# ifndef __NR_get_robust_list
+# define __NR_get_robust_list 301
+# endif
+# ifndef __NR_migrate_pages
+# define __NR_migrate_pages 302
+# endif
+# ifndef __NR_mbind
+# define __NR_mbind 303
+# endif
+# ifndef __NR_get_mempolicy
+# define __NR_get_mempolicy 304
+# endif
+# ifndef __NR_set_mempolicy
+# define __NR_set_mempolicy 305
+# endif
+# ifndef __NR_kexec_load
+# define __NR_kexec_load 306
+# endif
+# ifndef __NR_move_pages
+# define __NR_move_pages 307
+# endif
+# ifndef __NR_getcpu
+# define __NR_getcpu 308
+# endif
+# ifndef __NR_epoll_pwait
+# define __NR_epoll_pwait 309
+# endif
+# ifndef __NR_utimensat
+# define __NR_utimensat 310
+# endif
+# ifndef __NR_signalfd
+# define __NR_signalfd 311
+# endif
+# ifndef __NR_timerfd_create
+# define __NR_timerfd_create 312
+# endif
+# ifndef __NR_eventfd
+# define __NR_eventfd 313
+# endif
+# ifndef __NR_fallocate
+# define __NR_fallocate 314
+# endif
+# ifndef __NR_timerfd_settime
+# define __NR_timerfd_settime 315
+# endif
+# ifndef __NR_timerfd_gettime
+# define __NR_timerfd_gettime 316
+# endif
+# ifndef __NR_signalfd4
+# define __NR_signalfd4 317
+# endif
+# ifndef __NR_eventfd2
+# define __NR_eventfd2 318
+# endif
+# ifndef __NR_epoll_create1
+# define __NR_epoll_create1 319
+# endif
+# ifndef __NR_dup3
+# define __NR_dup3 320
+# endif
+# ifndef __NR_pipe2
+# define __NR_pipe2 321
+# endif
+# ifndef __NR_inotify_init1
+# define __NR_inotify_init1 322
+# endif
+# ifndef __NR_accept4
+# define __NR_accept4 323
+# endif
+# ifndef __NR_preadv
+# define __NR_preadv 324
+# endif
+# ifndef __NR_pwritev
+# define __NR_pwritev 325
+# endif
+# ifndef __NR_rt_tgsigqueueinfo
+# define __NR_rt_tgsigqueueinfo 326
+# endif
+# ifndef __NR_perf_event_open
+# define __NR_perf_event_open 327
+# endif
+# ifndef __NR_recvmmsg
+# define __NR_recvmmsg 328
+# endif
+# ifndef __NR_fanotify_init
+# define __NR_fanotify_init 329
+# endif
+# ifndef __NR_fanotify_mark
+# define __NR_fanotify_mark 330
+# endif
+# ifndef __NR_prlimit64
+# define __NR_prlimit64 331
+# endif
+# ifndef __NR_name_to_handle_at
+# define __NR_name_to_handle_at 332
+# endif
+# ifndef __NR_open_by_handle_at
+# define __NR_open_by_handle_at 333
+# endif
+# ifndef __NR_clock_adjtime
+# define __NR_clock_adjtime 334
+# endif
+# ifndef __NR_syncfs
+# define __NR_syncfs 335
+# endif
+# ifndef __NR_sendmmsg
+# define __NR_sendmmsg 336
+# endif
+# ifndef __NR_setns
+# define __NR_setns 337
+# endif
+# ifndef __NR_process_vm_readv
+# define __NR_process_vm_readv 338
+# endif
+# ifndef __NR_process_vm_writev
+# define __NR_process_vm_writev 339
+# endif
+# ifndef __NR_kern_features
+# define __NR_kern_features 340
+# endif
+# ifndef __NR_kcmp
+# define __NR_kcmp 341
+# endif
+# ifndef __NR_finit_module
+# define __NR_finit_module 342
+# endif
+# ifndef __NR_sched_setattr
+# define __NR_sched_setattr 343
+# endif
+# ifndef __NR_sched_getattr
+# define __NR_sched_getattr 344
+# endif
+# ifndef __NR_renameat2
+# define __NR_renameat2 345
+# endif
+# ifndef __NR_seccomp
+# define __NR_seccomp 346
+# endif
+# ifndef __NR_getrandom
+# define __NR_getrandom 347
+# endif
+# ifndef __NR_memfd_create
+# define __NR_memfd_create 348
+# endif
+# ifndef __NR_bpf
+# define __NR_bpf 349
+# endif
+# ifndef __NR_execveat
+# define __NR_execveat 350
+# endif
+# ifndef __NR_membarrier
+# define __NR_membarrier 351
+# endif
+# ifndef __NR_userfaultfd
+# define __NR_userfaultfd 352
+# endif
+# ifndef __NR_bind
+# define __NR_bind 353
+# endif
+# ifndef __NR_listen
+# define __NR_listen 354
+# endif
+# ifndef __NR_setsockopt
+# define __NR_setsockopt 355
+# endif
+# ifndef __NR_mlock2
+# define __NR_mlock2 356
+# endif
+# ifndef __NR_copy_file_range
+# define __NR_copy_file_range 357
+# endif
+# ifndef __NR_preadv2
+# define __NR_preadv2 358
+# endif
+# ifndef __NR_pwritev2
+# define __NR_pwritev2 359
+# endif
+# ifndef __NR_statx
+# define __NR_statx 360
+# endif
+# ifndef __NR_io_pgetevents
+# define __NR_io_pgetevents 361
+# endif
+# ifndef __NR_pkey_mprotect
+# define __NR_pkey_mprotect 362
+# endif
+# ifndef __NR_pkey_alloc
+# define __NR_pkey_alloc 363
+# endif
+# ifndef __NR_pkey_free
+# define __NR_pkey_free 364
+# endif
+# ifndef __NR_rseq
+# define __NR_rseq 365
+# endif
+# ifndef __NR_semget
+# define __NR_semget 393
+# endif
+# ifndef __NR_semctl
+# define __NR_semctl 394
+# endif
+# ifndef __NR_shmget
+# define __NR_shmget 395
+# endif
+# ifndef __NR_shmctl
+# define __NR_shmctl 396
+# endif
+# ifndef __NR_shmat
+# define __NR_shmat 397
+# endif
+# ifndef __NR_shmdt
+# define __NR_shmdt 398
+# endif
+# ifndef __NR_msgget
+# define __NR_msgget 399
+# endif
+# ifndef __NR_msgsnd
+# define __NR_msgsnd 400
+# endif
+# ifndef __NR_msgrcv
+# define __NR_msgrcv 401
+# endif
+# ifndef __NR_msgctl
+# define __NR_msgctl 402
+# endif
+# ifndef __NR_clock_gettime64
+# define __NR_clock_gettime64 403
+# endif
+# ifndef __NR_clock_settime64
+# define __NR_clock_settime64 404
+# endif
+# ifndef __NR_clock_adjtime64
+# define __NR_clock_adjtime64 405
+# endif
+# ifndef __NR_clock_getres_time64
+# define __NR_clock_getres_time64 406
+# endif
+# ifndef __NR_clock_nanosleep_time64
+# define __NR_clock_nanosleep_time64 407
+# endif
+# ifndef __NR_timer_gettime64
+# define __NR_timer_gettime64 408
+# endif
+# ifndef __NR_timer_settime64
+# define __NR_timer_settime64 409
+# endif
+# ifndef __NR_timerfd_gettime64
+# define __NR_timerfd_gettime64 410
+# endif
+# ifndef __NR_timerfd_settime64
+# define __NR_timerfd_settime64 411
+# endif
+# ifndef __NR_utimensat_time64
+# define __NR_utimensat_time64 412
+# endif
+# ifndef __NR_pselect6_time64
+# define __NR_pselect6_time64 413
+# endif
+# ifndef __NR_ppoll_time64
+# define __NR_ppoll_time64 414
+# endif
+# ifndef __NR_io_pgetevents_time64
+# define __NR_io_pgetevents_time64 416
+# endif
+# ifndef __NR_recvmmsg_time64
+# define __NR_recvmmsg_time64 417
+# endif
+# ifndef __NR_mq_timedsend_time64
+# define __NR_mq_timedsend_time64 418
+# endif
+# ifndef __NR_mq_timedreceive_time64
+# define __NR_mq_timedreceive_time64 419
+# endif
+# ifndef __NR_semtimedop_time64
+# define __NR_semtimedop_time64 420
+# endif
+# ifndef __NR_rt_sigtimedwait_time64
+# define __NR_rt_sigtimedwait_time64 421
+# endif
+# ifndef __NR_futex_time64
+# define __NR_futex_time64 422
+# endif
+# ifndef __NR_sched_rr_get_interval_time64
+# define __NR_sched_rr_get_interval_time64 423
+# endif
+# ifndef __NR_pidfd_send_signal
+# define __NR_pidfd_send_signal 424
+# endif
+# ifndef __NR_io_uring_setup
+# define __NR_io_uring_setup 425
+# endif
+# ifndef __NR_io_uring_enter
+# define __NR_io_uring_enter 426
+# endif
+# ifndef __NR_io_uring_register
+# define __NR_io_uring_register 427
+# endif
+# ifndef __NR_open_tree
+# define __NR_open_tree 428
+# endif
+# ifndef __NR_move_mount
+# define __NR_move_mount 429
+# endif
+# ifndef __NR_fsopen
+# define __NR_fsopen 430
+# endif
+# ifndef __NR_fsconfig
+# define __NR_fsconfig 431
+# endif
+# ifndef __NR_fsmount
+# define __NR_fsmount 432
+# endif
+# ifndef __NR_fspick
+# define __NR_fspick 433
+# endif
+# ifndef __NR_pidfd_open
+# define __NR_pidfd_open 434
+# endif
+# ifndef __NR_openat2
+# define __NR_openat2 437
+# endif
+# ifndef __NR_pidfd_getfd
+# define __NR_pidfd_getfd 438
+# endif
+#endif
+
+
+#ifdef __x86_64__
+# ifndef __NR_read
+# define __NR_read 0
+# endif
+# ifndef __NR_write
+# define __NR_write 1
+# endif
+# ifndef __NR_open
+# define __NR_open 2
+# endif
+# ifndef __NR_close
+# define __NR_close 3
+# endif
+# ifndef __NR_stat
+# define __NR_stat 4
+# endif
+# ifndef __NR_fstat
+# define __NR_fstat 5
+# endif
+# ifndef __NR_lstat
+# define __NR_lstat 6
+# endif
+# ifndef __NR_poll
+# define __NR_poll 7
+# endif
+# ifndef __NR_lseek
+# define __NR_lseek 8
+# endif
+# ifndef __NR_mmap
+# define __NR_mmap 9
+# endif
+# ifndef __NR_mprotect
+# define __NR_mprotect 10
+# endif
+# ifndef __NR_munmap
+# define __NR_munmap 11
+# endif
+# ifndef __NR_brk
+# define __NR_brk 12
+# endif
+# ifndef __NR_rt_sigaction
+# define __NR_rt_sigaction 13
+# endif
+# ifndef __NR_rt_sigprocmask
+# define __NR_rt_sigprocmask 14
+# endif
+# ifndef __NR_rt_sigreturn
+# define __NR_rt_sigreturn 15
+# endif
+# ifndef __NR_ioctl
+# define __NR_ioctl 16
+# endif
+# ifndef __NR_pread64
+# define __NR_pread64 17
+# endif
+# ifndef __NR_pwrite64
+# define __NR_pwrite64 18
+# endif
+# ifndef __NR_readv
+# define __NR_readv 19
+# endif
+# ifndef __NR_writev
+# define __NR_writev 20
+# endif
+# ifndef __NR_access
+# define __NR_access 21
+# endif
+# ifndef __NR_pipe
+# define __NR_pipe 22
+# endif
+# ifndef __NR_select
+# define __NR_select 23
+# endif
+# ifndef __NR_sched_yield
+# define __NR_sched_yield 24
+# endif
+# ifndef __NR_mremap
+# define __NR_mremap 25
+# endif
+# ifndef __NR_msync
+# define __NR_msync 26
+# endif
+# ifndef __NR_mincore
+# define __NR_mincore 27
+# endif
+# ifndef __NR_madvise
+# define __NR_madvise 28
+# endif
+# ifndef __NR_shmget
+# define __NR_shmget 29
+# endif
+# ifndef __NR_shmat
+# define __NR_shmat 30
+# endif
+# ifndef __NR_shmctl
+# define __NR_shmctl 31
+# endif
+# ifndef __NR_dup
+# define __NR_dup 32
+# endif
+# ifndef __NR_dup2
+# define __NR_dup2 33
+# endif
+# ifndef __NR_pause
+# define __NR_pause 34
+# endif
+# ifndef __NR_nanosleep
+# define __NR_nanosleep 35
+# endif
+# ifndef __NR_getitimer
+# define __NR_getitimer 36
+# endif
+# ifndef __NR_alarm
+# define __NR_alarm 37
+# endif
+# ifndef __NR_setitimer
+# define __NR_setitimer 38
+# endif
+# ifndef __NR_getpid
+# define __NR_getpid 39
+# endif
+# ifndef __NR_sendfile
+# define __NR_sendfile 40
+# endif
+# ifndef __NR_socket
+# define __NR_socket 41
+# endif
+# ifndef __NR_connect
+# define __NR_connect 42
+# endif
+# ifndef __NR_accept
+# define __NR_accept 43
+# endif
+# ifndef __NR_sendto
+# define __NR_sendto 44
+# endif
+# ifndef __NR_recvfrom
+# define __NR_recvfrom 45
+# endif
+# ifndef __NR_sendmsg
+# define __NR_sendmsg 46
+# endif
+# ifndef __NR_recvmsg
+# define __NR_recvmsg 47
+# endif
+# ifndef __NR_shutdown
+# define __NR_shutdown 48
+# endif
+# ifndef __NR_bind
+# define __NR_bind 49
+# endif
+# ifndef __NR_listen
+# define __NR_listen 50
+# endif
+# ifndef __NR_getsockname
+# define __NR_getsockname 51
+# endif
+# ifndef __NR_getpeername
+# define __NR_getpeername 52
+# endif
+# ifndef __NR_socketpair
+# define __NR_socketpair 53
+# endif
+# ifndef __NR_setsockopt
+# define __NR_setsockopt 54
+# endif
+# ifndef __NR_getsockopt
+# define __NR_getsockopt 55
+# endif
+# ifndef __NR_clone
+# define __NR_clone 56
+# endif
+# ifndef __NR_fork
+# define __NR_fork 57
+# endif
+# ifndef __NR_vfork
+# define __NR_vfork 58
+# endif
+# ifndef __NR_execve
+# define __NR_execve 59
+# endif
+# ifndef __NR_exit
+# define __NR_exit 60
+# endif
+# ifndef __NR_wait4
+# define __NR_wait4 61
+# endif
+# ifndef __NR_kill
+# define __NR_kill 62
+# endif
+# ifndef __NR_uname
+# define __NR_uname 63
+# endif
+# ifndef __NR_semget
+# define __NR_semget 64
+# endif
+# ifndef __NR_semop
+# define __NR_semop 65
+# endif
+# ifndef __NR_semctl
+# define __NR_semctl 66
+# endif
+# ifndef __NR_shmdt
+# define __NR_shmdt 67
+# endif
+# ifndef __NR_msgget
+# define __NR_msgget 68
+# endif
+# ifndef __NR_msgsnd
+# define __NR_msgsnd 69
+# endif
+# ifndef __NR_msgrcv
+# define __NR_msgrcv 70
+# endif
+# ifndef __NR_msgctl
+# define __NR_msgctl 71
+# endif
+# ifndef __NR_fcntl
+# define __NR_fcntl 72
+# endif
+# ifndef __NR_flock
+# define __NR_flock 73
+# endif
+# ifndef __NR_fsync
+# define __NR_fsync 74
+# endif
+# ifndef __NR_fdatasync
+# define __NR_fdatasync 75
+# endif
+# ifndef __NR_truncate
+# define __NR_truncate 76
+# endif
+# ifndef __NR_ftruncate
+# define __NR_ftruncate 77
+# endif
+# ifndef __NR_getdents
+# define __NR_getdents 78
+# endif
+# ifndef __NR_getcwd
+# define __NR_getcwd 79
+# endif
+# ifndef __NR_chdir
+# define __NR_chdir 80
+# endif
+# ifndef __NR_fchdir
+# define __NR_fchdir 81
+# endif
+# ifndef __NR_rename
+# define __NR_rename 82
+# endif
+# ifndef __NR_mkdir
+# define __NR_mkdir 83
+# endif
+# ifndef __NR_rmdir
+# define __NR_rmdir 84
+# endif
+# ifndef __NR_creat
+# define __NR_creat 85
+# endif
+# ifndef __NR_link
+# define __NR_link 86
+# endif
+# ifndef __NR_unlink
+# define __NR_unlink 87
+# endif
+# ifndef __NR_symlink
+# define __NR_symlink 88
+# endif
+# ifndef __NR_readlink
+# define __NR_readlink 89
+# endif
+# ifndef __NR_chmod
+# define __NR_chmod 90
+# endif
+# ifndef __NR_fchmod
+# define __NR_fchmod 91
+# endif
+# ifndef __NR_chown
+# define __NR_chown 92
+# endif
+# ifndef __NR_fchown
+# define __NR_fchown 93
+# endif
+# ifndef __NR_lchown
+# define __NR_lchown 94
+# endif
+# ifndef __NR_umask
+# define __NR_umask 95
+# endif
+# ifndef __NR_gettimeofday
+# define __NR_gettimeofday 96
+# endif
+# ifndef __NR_getrlimit
+# define __NR_getrlimit 97
+# endif
+# ifndef __NR_getrusage
+# define __NR_getrusage 98
+# endif
+# ifndef __NR_sysinfo
+# define __NR_sysinfo 99
+# endif
+# ifndef __NR_times
+# define __NR_times 100
+# endif
+# ifndef __NR_ptrace
+# define __NR_ptrace 101
+# endif
+# ifndef __NR_getuid
+# define __NR_getuid 102
+# endif
+# ifndef __NR_syslog
+# define __NR_syslog 103
+# endif
+# ifndef __NR_getgid
+# define __NR_getgid 104
+# endif
+# ifndef __NR_setuid
+# define __NR_setuid 105
+# endif
+# ifndef __NR_setgid
+# define __NR_setgid 106
+# endif
+# ifndef __NR_geteuid
+# define __NR_geteuid 107
+# endif
+# ifndef __NR_getegid
+# define __NR_getegid 108
+# endif
+# ifndef __NR_setpgid
+# define __NR_setpgid 109
+# endif
+# ifndef __NR_getppid
+# define __NR_getppid 110
+# endif
+# ifndef __NR_getpgrp
+# define __NR_getpgrp 111
+# endif
+# ifndef __NR_setsid
+# define __NR_setsid 112
+# endif
+# ifndef __NR_setreuid
+# define __NR_setreuid 113
+# endif
+# ifndef __NR_setregid
+# define __NR_setregid 114
+# endif
+# ifndef __NR_getgroups
+# define __NR_getgroups 115
+# endif
+# ifndef __NR_setgroups
+# define __NR_setgroups 116
+# endif
+# ifndef __NR_setresuid
+# define __NR_setresuid 117
+# endif
+# ifndef __NR_getresuid
+# define __NR_getresuid 118
+# endif
+# ifndef __NR_setresgid
+# define __NR_setresgid 119
+# endif
+# ifndef __NR_getresgid
+# define __NR_getresgid 120
+# endif
+# ifndef __NR_getpgid
+# define __NR_getpgid 121
+# endif
+# ifndef __NR_setfsuid
+# define __NR_setfsuid 122
+# endif
+# ifndef __NR_setfsgid
+# define __NR_setfsgid 123
+# endif
+# ifndef __NR_getsid
+# define __NR_getsid 124
+# endif
+# ifndef __NR_capget
+# define __NR_capget 125
+# endif
+# ifndef __NR_capset
+# define __NR_capset 126
+# endif
+# ifndef __NR_rt_sigpending
+# define __NR_rt_sigpending 127
+# endif
+# ifndef __NR_rt_sigtimedwait
+# define __NR_rt_sigtimedwait 128
+# endif
+# ifndef __NR_rt_sigqueueinfo
+# define __NR_rt_sigqueueinfo 129
+# endif
+# ifndef __NR_rt_sigsuspend
+# define __NR_rt_sigsuspend 130
+# endif
+# ifndef __NR_sigaltstack
+# define __NR_sigaltstack 131
+# endif
+# ifndef __NR_utime
+# define __NR_utime 132
+# endif
+# ifndef __NR_mknod
+# define __NR_mknod 133
+# endif
+# ifndef __NR_uselib
+# define __NR_uselib 134
+# endif
+# ifndef __NR_personality
+# define __NR_personality 135
+# endif
+# ifndef __NR_ustat
+# define __NR_ustat 136
+# endif
+# ifndef __NR_statfs
+# define __NR_statfs 137
+# endif
+# ifndef __NR_fstatfs
+# define __NR_fstatfs 138
+# endif
+# ifndef __NR_sysfs
+# define __NR_sysfs 139
+# endif
+# ifndef __NR_getpriority
+# define __NR_getpriority 140
+# endif
+# ifndef __NR_setpriority
+# define __NR_setpriority 141
+# endif
+# ifndef __NR_sched_setparam
+# define __NR_sched_setparam 142
+# endif
+# ifndef __NR_sched_getparam
+# define __NR_sched_getparam 143
+# endif
+# ifndef __NR_sched_setscheduler
+# define __NR_sched_setscheduler 144
+# endif
+# ifndef __NR_sched_getscheduler
+# define __NR_sched_getscheduler 145
+# endif
+# ifndef __NR_sched_get_priority_max
+# define __NR_sched_get_priority_max 146
+# endif
+# ifndef __NR_sched_get_priority_min
+# define __NR_sched_get_priority_min 147
+# endif
+# ifndef __NR_sched_rr_get_interval
+# define __NR_sched_rr_get_interval 148
+# endif
+# ifndef __NR_mlock
+# define __NR_mlock 149
+# endif
+# ifndef __NR_munlock
+# define __NR_munlock 150
+# endif
+# ifndef __NR_mlockall
+# define __NR_mlockall 151
+# endif
+# ifndef __NR_munlockall
+# define __NR_munlockall 152
+# endif
+# ifndef __NR_vhangup
+# define __NR_vhangup 153
+# endif
+# ifndef __NR_modify_ldt
+# define __NR_modify_ldt 154
+# endif
+# ifndef __NR_pivot_root
+# define __NR_pivot_root 155
+# endif
+# ifndef __NR__sysctl
+# define __NR__sysctl 156
+# endif
+# ifndef __NR_prctl
+# define __NR_prctl 157
+# endif
+# ifndef __NR_arch_prctl
+# define __NR_arch_prctl 158
+# endif
+# ifndef __NR_adjtimex
+# define __NR_adjtimex 159
+# endif
+# ifndef __NR_setrlimit
+# define __NR_setrlimit 160
+# endif
+# ifndef __NR_chroot
+# define __NR_chroot 161
+# endif
+# ifndef __NR_sync
+# define __NR_sync 162
+# endif
+# ifndef __NR_acct
+# define __NR_acct 163
+# endif
+# ifndef __NR_settimeofday
+# define __NR_settimeofday 164
+# endif
+# ifndef __NR_mount
+# define __NR_mount 165
+# endif
+# ifndef __NR_umount2
+# define __NR_umount2 166
+# endif
+# ifndef __NR_swapon
+# define __NR_swapon 167
+# endif
+# ifndef __NR_swapoff
+# define __NR_swapoff 168
+# endif
+# ifndef __NR_reboot
+# define __NR_reboot 169
+# endif
+# ifndef __NR_sethostname
+# define __NR_sethostname 170
+# endif
+# ifndef __NR_setdomainname
+# define __NR_setdomainname 171
+# endif
+# ifndef __NR_iopl
+# define __NR_iopl 172
+# endif
+# ifndef __NR_ioperm
+# define __NR_ioperm 173
+# endif
+# ifndef __NR_create_module
+# define __NR_create_module 174
+# endif
+# ifndef __NR_init_module
+# define __NR_init_module 175
+# endif
+# ifndef __NR_delete_module
+# define __NR_delete_module 176
+# endif
+# ifndef __NR_get_kernel_syms
+# define __NR_get_kernel_syms 177
+# endif
+# ifndef __NR_query_module
+# define __NR_query_module 178
+# endif
+# ifndef __NR_quotactl
+# define __NR_quotactl 179
+# endif
+# ifndef __NR_nfsservctl
+# define __NR_nfsservctl 180
+# endif
+# ifndef __NR_getpmsg
+# define __NR_getpmsg 181
+# endif
+# ifndef __NR_putpmsg
+# define __NR_putpmsg 182
+# endif
+# ifndef __NR_afs_syscall
+# define __NR_afs_syscall 183
+# endif
+# ifndef __NR_tuxcall
+# define __NR_tuxcall 184
+# endif
+# ifndef __NR_security
+# define __NR_security 185
+# endif
+# ifndef __NR_gettid
+# define __NR_gettid 186
+# endif
+# ifndef __NR_readahead
+# define __NR_readahead 187
+# endif
+# ifndef __NR_setxattr
+# define __NR_setxattr 188
+# endif
+# ifndef __NR_lsetxattr
+# define __NR_lsetxattr 189
+# endif
+# ifndef __NR_fsetxattr
+# define __NR_fsetxattr 190
+# endif
+# ifndef __NR_getxattr
+# define __NR_getxattr 191
+# endif
+# ifndef __NR_lgetxattr
+# define __NR_lgetxattr 192
+# endif
+# ifndef __NR_fgetxattr
+# define __NR_fgetxattr 193
+# endif
+# ifndef __NR_listxattr
+# define __NR_listxattr 194
+# endif
+# ifndef __NR_llistxattr
+# define __NR_llistxattr 195
+# endif
+# ifndef __NR_flistxattr
+# define __NR_flistxattr 196
+# endif
+# ifndef __NR_removexattr
+# define __NR_removexattr 197
+# endif
+# ifndef __NR_lremovexattr
+# define __NR_lremovexattr 198
+# endif
+# ifndef __NR_fremovexattr
+# define __NR_fremovexattr 199
+# endif
+# ifndef __NR_tkill
+# define __NR_tkill 200
+# endif
+# ifndef __NR_time
+# define __NR_time 201
+# endif
+# ifndef __NR_futex
+# define __NR_futex 202
+# endif
+# ifndef __NR_sched_setaffinity
+# define __NR_sched_setaffinity 203
+# endif
+# ifndef __NR_sched_getaffinity
+# define __NR_sched_getaffinity 204
+# endif
+# ifndef __NR_set_thread_area
+# define __NR_set_thread_area 205
+# endif
+# ifndef __NR_io_setup
+# define __NR_io_setup 206
+# endif
+# ifndef __NR_io_destroy
+# define __NR_io_destroy 207
+# endif
+# ifndef __NR_io_getevents
+# define __NR_io_getevents 208
+# endif
+# ifndef __NR_io_submit
+# define __NR_io_submit 209
+# endif
+# ifndef __NR_io_cancel
+# define __NR_io_cancel 210
+# endif
+# ifndef __NR_get_thread_area
+# define __NR_get_thread_area 211
+# endif
+# ifndef __NR_lookup_dcookie
+# define __NR_lookup_dcookie 212
+# endif
+# ifndef __NR_epoll_create
+# define __NR_epoll_create 213
+# endif
+# ifndef __NR_epoll_ctl_old
+# define __NR_epoll_ctl_old 214
+# endif
+# ifndef __NR_epoll_wait_old
+# define __NR_epoll_wait_old 215
+# endif
+# ifndef __NR_remap_file_pages
+# define __NR_remap_file_pages 216
+# endif
+# ifndef __NR_getdents64
+# define __NR_getdents64 217
+# endif
+# ifndef __NR_set_tid_address
+# define __NR_set_tid_address 218
+# endif
+# ifndef __NR_restart_syscall
+# define __NR_restart_syscall 219
+# endif
+# ifndef __NR_semtimedop
+# define __NR_semtimedop 220
+# endif
+# ifndef __NR_fadvise64
+# define __NR_fadvise64 221
+# endif
+# ifndef __NR_timer_create
+# define __NR_timer_create 222
+# endif
+# ifndef __NR_timer_settime
+# define __NR_timer_settime 223
+# endif
+# ifndef __NR_timer_gettime
+# define __NR_timer_gettime 224
+# endif
+# ifndef __NR_timer_getoverrun
+# define __NR_timer_getoverrun 225
+# endif
+# ifndef __NR_timer_delete
+# define __NR_timer_delete 226
+# endif
+# ifndef __NR_clock_settime
+# define __NR_clock_settime 227
+# endif
+# ifndef __NR_clock_gettime
+# define __NR_clock_gettime 228
+# endif
+# ifndef __NR_clock_getres
+# define __NR_clock_getres 229
+# endif
+# ifndef __NR_clock_nanosleep
+# define __NR_clock_nanosleep 230
+# endif
+# ifndef __NR_exit_group
+# define __NR_exit_group 231
+# endif
+# ifndef __NR_epoll_wait
+# define __NR_epoll_wait 232
+# endif
+# ifndef __NR_epoll_ctl
+# define __NR_epoll_ctl 233
+# endif
+# ifndef __NR_tgkill
+# define __NR_tgkill 234
+# endif
+# ifndef __NR_utimes
+# define __NR_utimes 235
+# endif
+# ifndef __NR_vserver
+# define __NR_vserver 236
+# endif
+# ifndef __NR_mbind
+# define __NR_mbind 237
+# endif
+# ifndef __NR_set_mempolicy
+# define __NR_set_mempolicy 238
+# endif
+# ifndef __NR_get_mempolicy
+# define __NR_get_mempolicy 239
+# endif
+# ifndef __NR_mq_open
+# define __NR_mq_open 240
+# endif
+# ifndef __NR_mq_unlink
+# define __NR_mq_unlink 241
+# endif
+# ifndef __NR_mq_timedsend
+# define __NR_mq_timedsend 242
+# endif
+# ifndef __NR_mq_timedreceive
+# define __NR_mq_timedreceive 243
+# endif
+# ifndef __NR_mq_notify
+# define __NR_mq_notify 244
+# endif
+# ifndef __NR_mq_getsetattr
+# define __NR_mq_getsetattr 245
+# endif
+# ifndef __NR_kexec_load
+# define __NR_kexec_load 246
+# endif
+# ifndef __NR_waitid
+# define __NR_waitid 247
+# endif
+# ifndef __NR_add_key
+# define __NR_add_key 248
+# endif
+# ifndef __NR_request_key
+# define __NR_request_key 249
+# endif
+# ifndef __NR_keyctl
+# define __NR_keyctl 250
+# endif
+# ifndef __NR_ioprio_set
+# define __NR_ioprio_set 251
+# endif
+# ifndef __NR_ioprio_get
+# define __NR_ioprio_get 252
+# endif
+# ifndef __NR_inotify_init
+# define __NR_inotify_init 253
+# endif
+# ifndef __NR_inotify_add_watch
+# define __NR_inotify_add_watch 254
+# endif
+# ifndef __NR_inotify_rm_watch
+# define __NR_inotify_rm_watch 255
+# endif
+# ifndef __NR_migrate_pages
+# define __NR_migrate_pages 256
+# endif
+# ifndef __NR_openat
+# define __NR_openat 257
+# endif
+# ifndef __NR_mkdirat
+# define __NR_mkdirat 258
+# endif
+# ifndef __NR_mknodat
+# define __NR_mknodat 259
+# endif
+# ifndef __NR_fchownat
+# define __NR_fchownat 260
+# endif
+# ifndef __NR_futimesat
+# define __NR_futimesat 261
+# endif
+# ifndef __NR_newfstatat
+# define __NR_newfstatat 262
+# endif
+# ifndef __NR_unlinkat
+# define __NR_unlinkat 263
+# endif
+# ifndef __NR_renameat
+# define __NR_renameat 264
+# endif
+# ifndef __NR_linkat
+# define __NR_linkat 265
+# endif
+# ifndef __NR_symlinkat
+# define __NR_symlinkat 266
+# endif
+# ifndef __NR_readlinkat
+# define __NR_readlinkat 267
+# endif
+# ifndef __NR_fchmodat
+# define __NR_fchmodat 268
+# endif
+# ifndef __NR_faccessat
+# define __NR_faccessat 269
+# endif
+# ifndef __NR_pselect6
+# define __NR_pselect6 270
+# endif
+# ifndef __NR_ppoll
+# define __NR_ppoll 271
+# endif
+# ifndef __NR_unshare
+# define __NR_unshare 272
+# endif
+# ifndef __NR_set_robust_list
+# define __NR_set_robust_list 273
+# endif
+# ifndef __NR_get_robust_list
+# define __NR_get_robust_list 274
+# endif
+# ifndef __NR_splice
+# define __NR_splice 275
+# endif
+# ifndef __NR_tee
+# define __NR_tee 276
+# endif
+# ifndef __NR_sync_file_range
+# define __NR_sync_file_range 277
+# endif
+# ifndef __NR_vmsplice
+# define __NR_vmsplice 278
+# endif
+# ifndef __NR_move_pages
+# define __NR_move_pages 279
+# endif
+# ifndef __NR_utimensat
+# define __NR_utimensat 280
+# endif
+# ifndef __NR_epoll_pwait
+# define __NR_epoll_pwait 281
+# endif
+# ifndef __NR_signalfd
+# define __NR_signalfd 282
+# endif
+# ifndef __NR_timerfd_create
+# define __NR_timerfd_create 283
+# endif
+# ifndef __NR_eventfd
+# define __NR_eventfd 284
+# endif
+# ifndef __NR_fallocate
+# define __NR_fallocate 285
+# endif
+# ifndef __NR_timerfd_settime
+# define __NR_timerfd_settime 286
+# endif
+# ifndef __NR_timerfd_gettime
+# define __NR_timerfd_gettime 287
+# endif
+# ifndef __NR_accept4
+# define __NR_accept4 288
+# endif
+# ifndef __NR_signalfd4
+# define __NR_signalfd4 289
+# endif
+# ifndef __NR_eventfd2
+# define __NR_eventfd2 290
+# endif
+# ifndef __NR_epoll_create1
+# define __NR_epoll_create1 291
+# endif
+# ifndef __NR_dup3
+# define __NR_dup3 292
+# endif
+# ifndef __NR_pipe2
+# define __NR_pipe2 293
+# endif
+# ifndef __NR_inotify_init1
+# define __NR_inotify_init1 294
+# endif
+# ifndef __NR_preadv
+# define __NR_preadv 295
+# endif
+# ifndef __NR_pwritev
+# define __NR_pwritev 296
+# endif
+# ifndef __NR_rt_tgsigqueueinfo
+# define __NR_rt_tgsigqueueinfo 297
+# endif
+# ifndef __NR_perf_event_open
+# define __NR_perf_event_open 298
+# endif
+# ifndef __NR_recvmmsg
+# define __NR_recvmmsg 299
+# endif
+# ifndef __NR_fanotify_init
+# define __NR_fanotify_init 300
+# endif
+# ifndef __NR_fanotify_mark
+# define __NR_fanotify_mark 301
+# endif
+# ifndef __NR_prlimit64
+# define __NR_prlimit64 302
+# endif
+# ifndef __NR_name_to_handle_at
+# define __NR_name_to_handle_at 303
+# endif
+# ifndef __NR_open_by_handle_at
+# define __NR_open_by_handle_at 304
+# endif
+# ifndef __NR_clock_adjtime
+# define __NR_clock_adjtime 305
+# endif
+# ifndef __NR_syncfs
+# define __NR_syncfs 306
+# endif
+# ifndef __NR_sendmmsg
+# define __NR_sendmmsg 307
+# endif
+# ifndef __NR_setns
+# define __NR_setns 308
+# endif
+# ifndef __NR_getcpu
+# define __NR_getcpu 309
+# endif
+# ifndef __NR_process_vm_readv
+# define __NR_process_vm_readv 310
+# endif
+# ifndef __NR_process_vm_writev
+# define __NR_process_vm_writev 311
+# endif
+# ifndef __NR_kcmp
+# define __NR_kcmp 312
+# endif
+# ifndef __NR_finit_module
+# define __NR_finit_module 313
+# endif
+# ifndef __NR_sched_setattr
+# define __NR_sched_setattr 314
+# endif
+# ifndef __NR_sched_getattr
+# define __NR_sched_getattr 315
+# endif
+# ifndef __NR_renameat2
+# define __NR_renameat2 316
+# endif
+# ifndef __NR_seccomp
+# define __NR_seccomp 317
+# endif
+# ifndef __NR_getrandom
+# define __NR_getrandom 318
+# endif
+# ifndef __NR_memfd_create
+# define __NR_memfd_create 319
+# endif
+# ifndef __NR_kexec_file_load
+# define __NR_kexec_file_load 320
+# endif
+# ifndef __NR_bpf
+# define __NR_bpf 321
+# endif
+# ifndef __NR_execveat
+# define __NR_execveat 322
+# endif
+# ifndef __NR_userfaultfd
+# define __NR_userfaultfd 323
+# endif
+# ifndef __NR_membarrier
+# define __NR_membarrier 324
+# endif
+# ifndef __NR_mlock2
+# define __NR_mlock2 325
+# endif
+# ifndef __NR_copy_file_range
+# define __NR_copy_file_range 326
+# endif
+# ifndef __NR_preadv2
+# define __NR_preadv2 327
+# endif
+# ifndef __NR_pwritev2
+# define __NR_pwritev2 328
+# endif
+# ifndef __NR_pkey_mprotect
+# define __NR_pkey_mprotect 329
+# endif
+# ifndef __NR_pkey_alloc
+# define __NR_pkey_alloc 330
+# endif
+# ifndef __NR_pkey_free
+# define __NR_pkey_free 331
+# endif
+# ifndef __NR_statx
+# define __NR_statx 332
+# endif
+# ifndef __NR_io_pgetevents
+# define __NR_io_pgetevents 333
+# endif
+# ifndef __NR_rseq
+# define __NR_rseq 334
+# endif
+# ifndef __NR_pidfd_send_signal
+# define __NR_pidfd_send_signal 424
+# endif
+# ifndef __NR_io_uring_setup
+# define __NR_io_uring_setup 425
+# endif
+# ifndef __NR_io_uring_enter
+# define __NR_io_uring_enter 426
+# endif
+# ifndef __NR_io_uring_register
+# define __NR_io_uring_register 427
+# endif
+# ifndef __NR_open_tree
+# define __NR_open_tree 428
+# endif
+# ifndef __NR_move_mount
+# define __NR_move_mount 429
+# endif
+# ifndef __NR_fsopen
+# define __NR_fsopen 430
+# endif
+# ifndef __NR_fsconfig
+# define __NR_fsconfig 431
+# endif
+# ifndef __NR_fsmount
+# define __NR_fsmount 432
+# endif
+# ifndef __NR_fspick
+# define __NR_fspick 433
+# endif
+# ifndef __NR_pidfd_open
+# define __NR_pidfd_open 434
+# endif
+# ifndef __NR_clone3
+# define __NR_clone3 435
+# endif
+# ifndef __NR_openat2
+# define __NR_openat2 437
+# endif
+# ifndef __NR_pidfd_getfd
+# define __NR_pidfd_getfd 438
+# endif
+# ifndef __NR_rt_sigaction
+# define __NR_rt_sigaction 512
+# endif
+# ifndef __NR_rt_sigreturn
+# define __NR_rt_sigreturn 513
+# endif
+# ifndef __NR_ioctl
+# define __NR_ioctl 514
+# endif
+# ifndef __NR_readv
+# define __NR_readv 515
+# endif
+# ifndef __NR_writev
+# define __NR_writev 516
+# endif
+# ifndef __NR_recvfrom
+# define __NR_recvfrom 517
+# endif
+# ifndef __NR_sendmsg
+# define __NR_sendmsg 518
+# endif
+# ifndef __NR_recvmsg
+# define __NR_recvmsg 519
+# endif
+# ifndef __NR_execve
+# define __NR_execve 520
+# endif
+# ifndef __NR_ptrace
+# define __NR_ptrace 521
+# endif
+# ifndef __NR_rt_sigpending
+# define __NR_rt_sigpending 522
+# endif
+# ifndef __NR_rt_sigtimedwait
+# define __NR_rt_sigtimedwait 523
+# endif
+# ifndef __NR_rt_sigqueueinfo
+# define __NR_rt_sigqueueinfo 524
+# endif
+# ifndef __NR_sigaltstack
+# define __NR_sigaltstack 525
+# endif
+# ifndef __NR_timer_create
+# define __NR_timer_create 526
+# endif
+# ifndef __NR_mq_notify
+# define __NR_mq_notify 527
+# endif
+# ifndef __NR_kexec_load
+# define __NR_kexec_load 528
+# endif
+# ifndef __NR_waitid
+# define __NR_waitid 529
+# endif
+# ifndef __NR_set_robust_list
+# define __NR_set_robust_list 530
+# endif
+# ifndef __NR_get_robust_list
+# define __NR_get_robust_list 531
+# endif
+# ifndef __NR_vmsplice
+# define __NR_vmsplice 532
+# endif
+# ifndef __NR_move_pages
+# define __NR_move_pages 533
+# endif
+# ifndef __NR_preadv
+# define __NR_preadv 534
+# endif
+# ifndef __NR_pwritev
+# define __NR_pwritev 535
+# endif
+# ifndef __NR_rt_tgsigqueueinfo
+# define __NR_rt_tgsigqueueinfo 536
+# endif
+# ifndef __NR_recvmmsg
+# define __NR_recvmmsg 537
+# endif
+# ifndef __NR_sendmmsg
+# define __NR_sendmmsg 538
+# endif
+# ifndef __NR_process_vm_readv
+# define __NR_process_vm_readv 539
+# endif
+# ifndef __NR_process_vm_writev
+# define __NR_process_vm_writev 540
+# endif
+# ifndef __NR_setsockopt
+# define __NR_setsockopt 541
+# endif
+# ifndef __NR_getsockopt
+# define __NR_getsockopt 542
+# endif
+# ifndef __NR_io_setup
+# define __NR_io_setup 543
+# endif
+# ifndef __NR_io_submit
+# define __NR_io_submit 544
+# endif
+# ifndef __NR_execveat
+# define __NR_execveat 545
+# endif
+# ifndef __NR_preadv2
+# define __NR_preadv2 546
+# endif
+# ifndef __NR_pwritev2
+# define __NR_pwritev2 547
+# endif
+#endif
+
+
+/* Common stubs */
+# ifndef __NR__llseek
+# define __NR__llseek __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR__newselect
+# define __NR__newselect __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR__sysctl
+# define __NR__sysctl __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_accept
+# define __NR_accept __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_accept4
+# define __NR_accept4 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_access
+# define __NR_access __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_acct
+# define __NR_acct __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_add_key
+# define __NR_add_key __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_adjtimex
+# define __NR_adjtimex __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_afs_syscall
+# define __NR_afs_syscall __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_alarm
+# define __NR_alarm __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_arc_gettls
+# define __NR_arc_gettls __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_arc_settls
+# define __NR_arc_settls __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_arc_usr_cmpxchg
+# define __NR_arc_usr_cmpxchg __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_arch_prctl
+# define __NR_arch_prctl __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_arm_fadvise64_64
+# define __NR_arm_fadvise64_64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_arm_sync_file_range
+# define __NR_arm_sync_file_range __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_bdflush
+# define __NR_bdflush __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_bind
+# define __NR_bind __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_bpf
+# define __NR_bpf __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_break
+# define __NR_break __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_brk
+# define __NR_brk __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_cachectl
+# define __NR_cachectl __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_cacheflush
+# define __NR_cacheflush __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_capget
+# define __NR_capget __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_capset
+# define __NR_capset __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_chdir
+# define __NR_chdir __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_chmod
+# define __NR_chmod __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_chown
+# define __NR_chown __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_chown32
+# define __NR_chown32 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_chroot
+# define __NR_chroot __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_clock_adjtime
+# define __NR_clock_adjtime __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_clock_adjtime64
+# define __NR_clock_adjtime64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_clock_getres
+# define __NR_clock_getres __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_clock_getres_time64
+# define __NR_clock_getres_time64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_clock_gettime
+# define __NR_clock_gettime __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_clock_gettime64
+# define __NR_clock_gettime64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_clock_nanosleep
+# define __NR_clock_nanosleep __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_clock_nanosleep_time64
+# define __NR_clock_nanosleep_time64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_clock_settime
+# define __NR_clock_settime __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_clock_settime64
+# define __NR_clock_settime64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_clone
+# define __NR_clone __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_clone2
+# define __NR_clone2 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_clone3
+# define __NR_clone3 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_close
+# define __NR_close __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_connect
+# define __NR_connect __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_copy_file_range
+# define __NR_copy_file_range __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_creat
+# define __NR_creat __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_create_module
+# define __NR_create_module __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_delete_module
+# define __NR_delete_module __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_dup
+# define __NR_dup __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_dup2
+# define __NR_dup2 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_dup3
+# define __NR_dup3 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_epoll_create
+# define __NR_epoll_create __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_epoll_create1
+# define __NR_epoll_create1 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_epoll_ctl
+# define __NR_epoll_ctl __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_epoll_ctl_old
+# define __NR_epoll_ctl_old __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_epoll_pwait
+# define __NR_epoll_pwait __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_epoll_wait
+# define __NR_epoll_wait __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_epoll_wait_old
+# define __NR_epoll_wait_old __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_eventfd
+# define __NR_eventfd __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_eventfd2
+# define __NR_eventfd2 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_execv
+# define __NR_execv __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_execve
+# define __NR_execve __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_execveat
+# define __NR_execveat __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_exit
+# define __NR_exit __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_exit_group
+# define __NR_exit_group __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_faccessat
+# define __NR_faccessat __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_fadvise64
+# define __NR_fadvise64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_fadvise64_64
+# define __NR_fadvise64_64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_fallocate
+# define __NR_fallocate __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_fanotify_init
+# define __NR_fanotify_init __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_fanotify_mark
+# define __NR_fanotify_mark __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_fchdir
+# define __NR_fchdir __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_fchmod
+# define __NR_fchmod __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_fchmodat
+# define __NR_fchmodat __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_fchown
+# define __NR_fchown __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_fchown32
+# define __NR_fchown32 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_fchownat
+# define __NR_fchownat __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_fcntl
+# define __NR_fcntl __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_fcntl64
+# define __NR_fcntl64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_fdatasync
+# define __NR_fdatasync __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_fgetxattr
+# define __NR_fgetxattr __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_finit_module
+# define __NR_finit_module __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_flistxattr
+# define __NR_flistxattr __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_flock
+# define __NR_flock __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_fork
+# define __NR_fork __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_fremovexattr
+# define __NR_fremovexattr __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_fsconfig
+# define __NR_fsconfig __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_fsetxattr
+# define __NR_fsetxattr __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_fsmount
+# define __NR_fsmount __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_fsopen
+# define __NR_fsopen __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_fspick
+# define __NR_fspick __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_fstat
+# define __NR_fstat __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_fstat64
+# define __NR_fstat64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_fstatat
+# define __NR_fstatat __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_fstatat64
+# define __NR_fstatat64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_fstatfs
+# define __NR_fstatfs __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_fstatfs64
+# define __NR_fstatfs64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_fsync
+# define __NR_fsync __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_ftime
+# define __NR_ftime __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_ftruncate
+# define __NR_ftruncate __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_ftruncate64
+# define __NR_ftruncate64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_futex
+# define __NR_futex __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_futex_time64
+# define __NR_futex_time64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_futimesat
+# define __NR_futimesat __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_get_kernel_syms
+# define __NR_get_kernel_syms __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_get_mempolicy
+# define __NR_get_mempolicy __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_get_robust_list
+# define __NR_get_robust_list __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_get_thread_area
+# define __NR_get_thread_area __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_getcpu
+# define __NR_getcpu __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_getcwd
+# define __NR_getcwd __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_getdents
+# define __NR_getdents __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_getdents64
+# define __NR_getdents64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_getdomainname
+# define __NR_getdomainname __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_getegid
+# define __NR_getegid __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_getegid32
+# define __NR_getegid32 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_geteuid
+# define __NR_geteuid __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_geteuid32
+# define __NR_geteuid32 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_getgid
+# define __NR_getgid __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_getgid32
+# define __NR_getgid32 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_getgroups
+# define __NR_getgroups __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_getgroups32
+# define __NR_getgroups32 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_getitimer
+# define __NR_getitimer __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_getpagesize
+# define __NR_getpagesize __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_getpeername
+# define __NR_getpeername __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_getpgid
+# define __NR_getpgid __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_getpgrp
+# define __NR_getpgrp __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_getpid
+# define __NR_getpid __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_getpmsg
+# define __NR_getpmsg __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_getppid
+# define __NR_getppid __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_getpriority
+# define __NR_getpriority __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_getrandom
+# define __NR_getrandom __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_getresgid
+# define __NR_getresgid __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_getresgid32
+# define __NR_getresgid32 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_getresuid
+# define __NR_getresuid __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_getresuid32
+# define __NR_getresuid32 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_getrlimit
+# define __NR_getrlimit __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_getrusage
+# define __NR_getrusage __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_getsid
+# define __NR_getsid __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_getsockname
+# define __NR_getsockname __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_getsockopt
+# define __NR_getsockopt __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_gettid
+# define __NR_gettid __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_gettimeofday
+# define __NR_gettimeofday __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_getuid
+# define __NR_getuid __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_getuid32
+# define __NR_getuid32 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_getunwind
+# define __NR_getunwind __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_getxattr
+# define __NR_getxattr __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_gtty
+# define __NR_gtty __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_idle
+# define __NR_idle __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_init_module
+# define __NR_init_module __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_inotify_add_watch
+# define __NR_inotify_add_watch __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_inotify_init
+# define __NR_inotify_init __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_inotify_init1
+# define __NR_inotify_init1 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_inotify_rm_watch
+# define __NR_inotify_rm_watch __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_io_cancel
+# define __NR_io_cancel __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_io_destroy
+# define __NR_io_destroy __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_io_getevents
+# define __NR_io_getevents __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_io_pgetevents
+# define __NR_io_pgetevents __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_io_pgetevents_time64
+# define __NR_io_pgetevents_time64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_io_setup
+# define __NR_io_setup __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_io_submit
+# define __NR_io_submit __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_io_uring_enter
+# define __NR_io_uring_enter __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_io_uring_register
+# define __NR_io_uring_register __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_io_uring_setup
+# define __NR_io_uring_setup __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_ioctl
+# define __NR_ioctl __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_ioperm
+# define __NR_ioperm __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_iopl
+# define __NR_iopl __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_ioprio_get
+# define __NR_ioprio_get __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_ioprio_set
+# define __NR_ioprio_set __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_ipc
+# define __NR_ipc __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_kcmp
+# define __NR_kcmp __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_kern_features
+# define __NR_kern_features __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_kexec_file_load
+# define __NR_kexec_file_load __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_kexec_load
+# define __NR_kexec_load __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_keyctl
+# define __NR_keyctl __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_kill
+# define __NR_kill __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_lchown
+# define __NR_lchown __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_lchown32
+# define __NR_lchown32 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_lgetxattr
+# define __NR_lgetxattr __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_link
+# define __NR_link __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_linkat
+# define __NR_linkat __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_listen
+# define __NR_listen __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_listxattr
+# define __NR_listxattr __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_llistxattr
+# define __NR_llistxattr __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_lock
+# define __NR_lock __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_lookup_dcookie
+# define __NR_lookup_dcookie __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_lremovexattr
+# define __NR_lremovexattr __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_lseek
+# define __NR_lseek __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_lsetxattr
+# define __NR_lsetxattr __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_lstat
+# define __NR_lstat __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_lstat64
+# define __NR_lstat64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_madvise
+# define __NR_madvise __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_madvise1
+# define __NR_madvise1 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_mbind
+# define __NR_mbind __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_membarrier
+# define __NR_membarrier __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_memfd_create
+# define __NR_memfd_create __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_memory_ordering
+# define __NR_memory_ordering __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_migrate_pages
+# define __NR_migrate_pages __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_mincore
+# define __NR_mincore __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_mkdir
+# define __NR_mkdir __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_mkdirat
+# define __NR_mkdirat __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_mknod
+# define __NR_mknod __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_mknodat
+# define __NR_mknodat __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_mlock
+# define __NR_mlock __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_mlock2
+# define __NR_mlock2 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_mlockall
+# define __NR_mlockall __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_mmap
+# define __NR_mmap __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_mmap2
+# define __NR_mmap2 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_modify_ldt
+# define __NR_modify_ldt __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_mount
+# define __NR_mount __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_move_mount
+# define __NR_move_mount __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_move_pages
+# define __NR_move_pages __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_mprotect
+# define __NR_mprotect __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_mpx
+# define __NR_mpx __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_mq_getsetattr
+# define __NR_mq_getsetattr __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_mq_notify
+# define __NR_mq_notify __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_mq_open
+# define __NR_mq_open __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_mq_timedreceive
+# define __NR_mq_timedreceive __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_mq_timedreceive_time64
+# define __NR_mq_timedreceive_time64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_mq_timedsend
+# define __NR_mq_timedsend __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_mq_timedsend_time64
+# define __NR_mq_timedsend_time64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_mq_unlink
+# define __NR_mq_unlink __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_mremap
+# define __NR_mremap __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_msgctl
+# define __NR_msgctl __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_msgget
+# define __NR_msgget __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_msgrcv
+# define __NR_msgrcv __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_msgsnd
+# define __NR_msgsnd __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_msync
+# define __NR_msync __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_multiplexer
+# define __NR_multiplexer __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_munlock
+# define __NR_munlock __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_munlockall
+# define __NR_munlockall __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_munmap
+# define __NR_munmap __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_name_to_handle_at
+# define __NR_name_to_handle_at __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_nanosleep
+# define __NR_nanosleep __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_newfstatat
+# define __NR_newfstatat __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_nfsservctl
+# define __NR_nfsservctl __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_ni_syscall
+# define __NR_ni_syscall __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_nice
+# define __NR_nice __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_old_getpagesize
+# define __NR_old_getpagesize __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_oldfstat
+# define __NR_oldfstat __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_oldlstat
+# define __NR_oldlstat __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_oldolduname
+# define __NR_oldolduname __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_oldstat
+# define __NR_oldstat __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_olduname
+# define __NR_olduname __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_open
+# define __NR_open __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_open_by_handle_at
+# define __NR_open_by_handle_at __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_open_tree
+# define __NR_open_tree __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_openat
+# define __NR_openat __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_openat2
+# define __NR_openat2 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_pause
+# define __NR_pause __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_pciconfig_iobase
+# define __NR_pciconfig_iobase __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_pciconfig_read
+# define __NR_pciconfig_read __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_pciconfig_write
+# define __NR_pciconfig_write __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_perf_event_open
+# define __NR_perf_event_open __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_perfctr
+# define __NR_perfctr __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_perfmonctl
+# define __NR_perfmonctl __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_personality
+# define __NR_personality __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_pidfd_getfd
+# define __NR_pidfd_getfd __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_pidfd_open
+# define __NR_pidfd_open __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_pidfd_send_signal
+# define __NR_pidfd_send_signal __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_pipe
+# define __NR_pipe __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_pipe2
+# define __NR_pipe2 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_pivot_root
+# define __NR_pivot_root __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_pkey_alloc
+# define __NR_pkey_alloc __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_pkey_free
+# define __NR_pkey_free __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_pkey_mprotect
+# define __NR_pkey_mprotect __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_poll
+# define __NR_poll __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_ppoll
+# define __NR_ppoll __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_ppoll_time64
+# define __NR_ppoll_time64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_prctl
+# define __NR_prctl __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_pread64
+# define __NR_pread64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_preadv
+# define __NR_preadv __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_preadv2
+# define __NR_preadv2 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_prlimit64
+# define __NR_prlimit64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_process_vm_readv
+# define __NR_process_vm_readv __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_process_vm_writev
+# define __NR_process_vm_writev __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_prof
+# define __NR_prof __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_profil
+# define __NR_profil __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_pselect6
+# define __NR_pselect6 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_pselect6_time64
+# define __NR_pselect6_time64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_ptrace
+# define __NR_ptrace __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_putpmsg
+# define __NR_putpmsg __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_pwrite64
+# define __NR_pwrite64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_pwritev
+# define __NR_pwritev __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_pwritev2
+# define __NR_pwritev2 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_query_module
+# define __NR_query_module __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_quotactl
+# define __NR_quotactl __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_read
+# define __NR_read __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_readahead
+# define __NR_readahead __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_readdir
+# define __NR_readdir __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_readlink
+# define __NR_readlink __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_readlinkat
+# define __NR_readlinkat __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_readv
+# define __NR_readv __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_reboot
+# define __NR_reboot __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_recv
+# define __NR_recv __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_recvfrom
+# define __NR_recvfrom __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_recvmmsg
+# define __NR_recvmmsg __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_recvmmsg_time64
+# define __NR_recvmmsg_time64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_recvmsg
+# define __NR_recvmsg __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_remap_file_pages
+# define __NR_remap_file_pages __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_removexattr
+# define __NR_removexattr __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_rename
+# define __NR_rename __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_renameat
+# define __NR_renameat __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_renameat2
+# define __NR_renameat2 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_request_key
+# define __NR_request_key __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_reserved177
+# define __NR_reserved177 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_reserved193
+# define __NR_reserved193 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_reserved221
+# define __NR_reserved221 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_reserved82
+# define __NR_reserved82 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_restart_syscall
+# define __NR_restart_syscall __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_rmdir
+# define __NR_rmdir __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_rseq
+# define __NR_rseq __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_rt_sigaction
+# define __NR_rt_sigaction __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_rt_sigpending
+# define __NR_rt_sigpending __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_rt_sigprocmask
+# define __NR_rt_sigprocmask __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_rt_sigqueueinfo
+# define __NR_rt_sigqueueinfo __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_rt_sigreturn
+# define __NR_rt_sigreturn __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_rt_sigsuspend
+# define __NR_rt_sigsuspend __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_rt_sigtimedwait
+# define __NR_rt_sigtimedwait __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_rt_sigtimedwait_time64
+# define __NR_rt_sigtimedwait_time64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_rt_tgsigqueueinfo
+# define __NR_rt_tgsigqueueinfo __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_rtas
+# define __NR_rtas __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_s390_guarded_storage
+# define __NR_s390_guarded_storage __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_s390_pci_mmio_read
+# define __NR_s390_pci_mmio_read __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_s390_pci_mmio_write
+# define __NR_s390_pci_mmio_write __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_s390_runtime_instr
+# define __NR_s390_runtime_instr __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_s390_sthyi
+# define __NR_s390_sthyi __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sched_get_affinity
+# define __NR_sched_get_affinity __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sched_get_priority_max
+# define __NR_sched_get_priority_max __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sched_get_priority_min
+# define __NR_sched_get_priority_min __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sched_getaffinity
+# define __NR_sched_getaffinity __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sched_getattr
+# define __NR_sched_getattr __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sched_getparam
+# define __NR_sched_getparam __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sched_getscheduler
+# define __NR_sched_getscheduler __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sched_rr_get_interval
+# define __NR_sched_rr_get_interval __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sched_rr_get_interval_time64
+# define __NR_sched_rr_get_interval_time64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sched_set_affinity
+# define __NR_sched_set_affinity __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sched_setaffinity
+# define __NR_sched_setaffinity __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sched_setattr
+# define __NR_sched_setattr __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sched_setparam
+# define __NR_sched_setparam __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sched_setscheduler
+# define __NR_sched_setscheduler __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sched_yield
+# define __NR_sched_yield __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_seccomp
+# define __NR_seccomp __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_security
+# define __NR_security __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_select
+# define __NR_select __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_semctl
+# define __NR_semctl __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_semget
+# define __NR_semget __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_semop
+# define __NR_semop __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_semtimedop
+# define __NR_semtimedop __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_semtimedop_time64
+# define __NR_semtimedop_time64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_send
+# define __NR_send __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sendfile
+# define __NR_sendfile __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sendfile64
+# define __NR_sendfile64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sendmmsg
+# define __NR_sendmmsg __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sendmsg
+# define __NR_sendmsg __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sendto
+# define __NR_sendto __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_set_mempolicy
+# define __NR_set_mempolicy __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_set_robust_list
+# define __NR_set_robust_list __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_set_thread_area
+# define __NR_set_thread_area __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_set_tid_address
+# define __NR_set_tid_address __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_setdomainname
+# define __NR_setdomainname __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_setfsgid
+# define __NR_setfsgid __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_setfsgid32
+# define __NR_setfsgid32 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_setfsuid
+# define __NR_setfsuid __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_setfsuid32
+# define __NR_setfsuid32 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_setgid
+# define __NR_setgid __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_setgid32
+# define __NR_setgid32 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_setgroups
+# define __NR_setgroups __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_setgroups32
+# define __NR_setgroups32 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sethostname
+# define __NR_sethostname __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_setitimer
+# define __NR_setitimer __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_setns
+# define __NR_setns __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_setpgid
+# define __NR_setpgid __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_setpriority
+# define __NR_setpriority __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_setregid
+# define __NR_setregid __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_setregid32
+# define __NR_setregid32 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_setresgid
+# define __NR_setresgid __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_setresgid32
+# define __NR_setresgid32 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_setresuid
+# define __NR_setresuid __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_setresuid32
+# define __NR_setresuid32 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_setreuid
+# define __NR_setreuid __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_setreuid32
+# define __NR_setreuid32 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_setrlimit
+# define __NR_setrlimit __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_setsid
+# define __NR_setsid __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_setsockopt
+# define __NR_setsockopt __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_settimeofday
+# define __NR_settimeofday __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_setuid
+# define __NR_setuid __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_setuid32
+# define __NR_setuid32 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_setxattr
+# define __NR_setxattr __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sgetmask
+# define __NR_sgetmask __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_shmat
+# define __NR_shmat __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_shmctl
+# define __NR_shmctl __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_shmdt
+# define __NR_shmdt __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_shmget
+# define __NR_shmget __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_shutdown
+# define __NR_shutdown __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sigaction
+# define __NR_sigaction __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sigaltstack
+# define __NR_sigaltstack __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_signal
+# define __NR_signal __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_signalfd
+# define __NR_signalfd __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_signalfd4
+# define __NR_signalfd4 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sigpending
+# define __NR_sigpending __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sigprocmask
+# define __NR_sigprocmask __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sigreturn
+# define __NR_sigreturn __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sigsuspend
+# define __NR_sigsuspend __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_socket
+# define __NR_socket __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_socketcall
+# define __NR_socketcall __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_socketpair
+# define __NR_socketpair __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_splice
+# define __NR_splice __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_spu_create
+# define __NR_spu_create __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_spu_run
+# define __NR_spu_run __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_ssetmask
+# define __NR_ssetmask __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_stat
+# define __NR_stat __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_stat64
+# define __NR_stat64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_statfs
+# define __NR_statfs __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_statfs64
+# define __NR_statfs64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_statx
+# define __NR_statx __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_stime
+# define __NR_stime __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_stty
+# define __NR_stty __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_subpage_prot
+# define __NR_subpage_prot __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_swapcontext
+# define __NR_swapcontext __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_swapoff
+# define __NR_swapoff __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_swapon
+# define __NR_swapon __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_switch_endian
+# define __NR_switch_endian __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_symlink
+# define __NR_symlink __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_symlinkat
+# define __NR_symlinkat __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sync
+# define __NR_sync __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sync_file_range
+# define __NR_sync_file_range __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sync_file_range2
+# define __NR_sync_file_range2 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_syncfs
+# define __NR_syncfs __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sys_debug_setcontext
+# define __NR_sys_debug_setcontext __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_syscall
+# define __NR_syscall __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sysfs
+# define __NR_sysfs __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sysinfo
+# define __NR_sysinfo __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_syslog
+# define __NR_syslog __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_sysmips
+# define __NR_sysmips __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_tee
+# define __NR_tee __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_tgkill
+# define __NR_tgkill __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_time
+# define __NR_time __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_timer_create
+# define __NR_timer_create __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_timer_delete
+# define __NR_timer_delete __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_timer_getoverrun
+# define __NR_timer_getoverrun __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_timer_gettime
+# define __NR_timer_gettime __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_timer_gettime64
+# define __NR_timer_gettime64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_timer_settime
+# define __NR_timer_settime __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_timer_settime64
+# define __NR_timer_settime64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_timerfd
+# define __NR_timerfd __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_timerfd_create
+# define __NR_timerfd_create __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_timerfd_gettime
+# define __NR_timerfd_gettime __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_timerfd_gettime64
+# define __NR_timerfd_gettime64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_timerfd_settime
+# define __NR_timerfd_settime __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_timerfd_settime64
+# define __NR_timerfd_settime64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_times
+# define __NR_times __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_tkill
+# define __NR_tkill __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_truncate
+# define __NR_truncate __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_truncate64
+# define __NR_truncate64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_tuxcall
+# define __NR_tuxcall __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_ugetrlimit
+# define __NR_ugetrlimit __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_ulimit
+# define __NR_ulimit __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_umask
+# define __NR_umask __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_umount
+# define __NR_umount __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_umount2
+# define __NR_umount2 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_uname
+# define __NR_uname __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_unlink
+# define __NR_unlink __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_unlinkat
+# define __NR_unlinkat __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_unshare
+# define __NR_unshare __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_unused109
+# define __NR_unused109 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_unused150
+# define __NR_unused150 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_unused18
+# define __NR_unused18 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_unused28
+# define __NR_unused28 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_unused59
+# define __NR_unused59 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_unused84
+# define __NR_unused84 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_uselib
+# define __NR_uselib __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_userfaultfd
+# define __NR_userfaultfd __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_ustat
+# define __NR_ustat __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_utime
+# define __NR_utime __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_utimensat
+# define __NR_utimensat __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_utimensat_time64
+# define __NR_utimensat_time64 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_utimes
+# define __NR_utimes __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_utrap_install
+# define __NR_utrap_install __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_vfork
+# define __NR_vfork __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_vhangup
+# define __NR_vhangup __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_vm86
+# define __NR_vm86 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_vm86old
+# define __NR_vm86old __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_vmsplice
+# define __NR_vmsplice __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_vserver
+# define __NR_vserver __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_wait4
+# define __NR_wait4 __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_waitid
+# define __NR_waitid __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_waitpid
+# define __NR_waitpid __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_write
+# define __NR_write __LTP__NR_INVALID_SYSCALL
+# endif
+# ifndef __NR_writev
+# define __NR_writev __LTP__NR_INVALID_SYSCALL
+# endif
+#endif
diff --git a/kernel/tests/include/lapi/tcp.h b/kernel/tests/include/lapi/tcp.h
new file mode 100644
index 0000000..bb98f28
--- /dev/null
+++ b/kernel/tests/include/lapi/tcp.h
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
+ */
+
+#ifndef LAPI_TCP_H__
+#define LAPI_TCP_H__
+
+#include <netinet/tcp.h>
+
+#ifndef TCP_FASTOPEN
+# define TCP_FASTOPEN 23
+#endif
+
+#ifndef TCP_FASTOPEN_CONNECT
+# define TCP_FASTOPEN_CONNECT 30 /* Attempt FastOpen with connect */
+#endif
+
+#endif /* LAPI_TCP_H__ */
diff --git a/kernel/tests/include/lapi/tee.h b/kernel/tests/include/lapi/tee.h
new file mode 100644
index 0000000..422e811
--- /dev/null
+++ b/kernel/tests/include/lapi/tee.h
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) International Business Machines Corp., 2007
+ * Copyright (c) 2014 Fujitsu Ltd.
+ */
+
+#ifndef TEE_H
+#define TEE_H
+
+#include "config.h"
+#include "lapi/syscalls.h"
+
+#if !defined(HAVE_TEE)
+ssize_t tee(int fd_in, int fd_out, size_t len, unsigned int flags)
+{
+ return tst_syscall(__NR_tee, fd_in, fd_out, len, flags);
+}
+#endif
+
+#endif /* TEE_H */
diff --git a/kernel/tests/include/lapi/termbits.h b/kernel/tests/include/lapi/termbits.h
new file mode 100644
index 0000000..d79da08
--- /dev/null
+++ b/kernel/tests/include/lapi/termbits.h
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2018 Linux Test Project
+ */
+
+#ifndef LAPI_TERMBITS_H__
+#define LAPI_TERMBITS_H__
+
+#ifndef EXTPROC
+# define EXTPROC 0200000
+#endif
+
+#endif
diff --git a/kernel/tests/include/lapi/timerfd.h b/kernel/tests/include/lapi/timerfd.h
new file mode 100644
index 0000000..50e0972
--- /dev/null
+++ b/kernel/tests/include/lapi/timerfd.h
@@ -0,0 +1,41 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) International Business Machines Corp., 2007
+ * Copyright (c) 2014 Fujitsu Ltd.
+ */
+
+#ifndef TIMERFD_H
+#define TIMERFD_H
+
+#include <time.h>
+#include "config.h"
+#include "lapi/syscalls.h"
+
+#ifdef HAVE_SYS_TIMERFD_H
+#include <sys/timerfd.h>
+#endif
+
+#if !defined(HAVE_TIMERFD_CREATE)
+int timerfd_create(int clockid, int flags)
+{
+ return ltp_syscall(__NR_timerfd_create, clockid, flags);
+}
+#endif
+
+#if !defined(HAVE_TIMERFD_GETTIME)
+int timerfd_settime(int fd, int flags, const struct itimerspec *new_value,
+ struct itimerspec *old_value)
+{
+ return ltp_syscall(__NR_timerfd_settime, fd, flags, new_value,
+ old_value);
+}
+#endif
+
+#if !defined(HAVE_TIMERFD_SETTIME)
+int timerfd_gettime(int fd, struct itimerspec *curr_value)
+{
+ return ltp_syscall(__NR_timerfd_gettime, fd, curr_value);
+}
+#endif
+
+#endif /* TIMERFD_H */
diff --git a/kernel/tests/include/lapi/timex.h b/kernel/tests/include/lapi/timex.h
new file mode 100644
index 0000000..c2c9e4d
--- /dev/null
+++ b/kernel/tests/include/lapi/timex.h
@@ -0,0 +1,30 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
+ */
+
+#ifndef LAPI_TIMEX_H__
+# define LAPI_TIMEX_H__
+
+#define ADJ_ALL (ADJ_OFFSET | ADJ_FREQUENCY | ADJ_MAXERROR | \
+ ADJ_ESTERROR | ADJ_STATUS | ADJ_TIMECONST | \
+ ADJ_TICK)
+
+#ifndef ADJ_OFFSET_SS_READ
+# define ADJ_OFFSET_SS_READ 0xa001
+#endif
+
+#ifndef ADJ_NANO
+# define ADJ_NANO 0x2000
+#endif
+
+#ifndef STA_NANO
+# define STA_NANO 0x2000
+#endif
+
+#ifndef ADJ_MICRO
+# define ADJ_MICRO 0x1000
+#endif
+
+#endif/* LAPI_TIMEX_H__ */
diff --git a/kernel/tests/include/lapi/tty.h b/kernel/tests/include/lapi/tty.h
new file mode 100644
index 0000000..6122145
--- /dev/null
+++ b/kernel/tests/include/lapi/tty.h
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Petr Vorel <pvorel@suse.cz>
+ */
+
+#ifndef LAPI_TTY_H
+#define LAPI_TTY_H
+
+#ifdef HAVE_LINUX_TTY_H
+# include <linux/tty.h>
+#endif
+
+#ifndef N_HDLC
+# define N_HDLC 13
+#endif
+
+#ifndef N_SLCAN
+# define N_SLCAN 17 /* Serial / USB serial CAN Adaptors */
+#endif
+
+#endif /* LAPI_TTY_H */
diff --git a/kernel/tests/include/lapi/udp.h b/kernel/tests/include/lapi/udp.h
new file mode 100644
index 0000000..5c73dd3
--- /dev/null
+++ b/kernel/tests/include/lapi/udp.h
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2018 Oracle and/or its affiliates.
+ */
+
+#ifndef LAPI_UDP_H__
+#define LAPI_UDP_H__
+
+#include <netinet/udp.h>
+
+#ifndef UDPLITE_SEND_CSCOV
+# define UDPLITE_SEND_CSCOV 10 /* sender partial coverage (as sent) */
+#endif
+#ifndef UDPLITE_RECV_CSCOV
+# define UDPLITE_RECV_CSCOV 11 /* receiver partial coverage (threshold ) */
+#endif
+
+#endif /* LAPI_UDP_H__ */
diff --git a/kernel/tests/include/lapi/ustat.h b/kernel/tests/include/lapi/ustat.h
new file mode 100644
index 0000000..98633e7
--- /dev/null
+++ b/kernel/tests/include/lapi/ustat.h
@@ -0,0 +1,22 @@
+//SPDX-License-Identifier: GPL-2.0-or-later
+
+#ifndef LAPI_USTAT_H
+#define LAPI_USTAT_H
+
+#include "config.h"
+
+#include <sys/types.h>
+
+#ifdef HAVE_SYS_USTAT_H
+# include <sys/ustat.h>
+#elif HAVE_LINUX_TYPES_H
+# include <linux/types.h>
+struct ustat {
+ __kernel_daddr_t f_tfree;
+ ino_t f_tinode;
+ char f_fname[6];
+ char f_fpack[6];
+};
+#endif
+
+#endif /* LAPI_USTAT_H */
diff --git a/kernel/tests/include/lapi/utime.h b/kernel/tests/include/lapi/utime.h
new file mode 100644
index 0000000..dbfaa55
--- /dev/null
+++ b/kernel/tests/include/lapi/utime.h
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
+ */
+
+#ifndef __UTIME_H__
+
+#ifndef UTIME_NOW
+# define UTIME_NOW ((1l << 30) - 1l)
+#endif
+
+#ifndef UTIME_OMIT
+# define UTIME_OMIT ((1l << 30) - 2l)
+#endif
+
+#endif /* __UTIME_H__ */
diff --git a/kernel/tests/include/lapi/utsname.h b/kernel/tests/include/lapi/utsname.h
new file mode 100644
index 0000000..6209eac
--- /dev/null
+++ b/kernel/tests/include/lapi/utsname.h
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Petr Vorel <petr.vorel@gmail.com>
+ */
+
+#ifdef HAVE_SYS_UTSNAME_H
+# include <sys/utsname.h>
+#endif
+
+#ifndef _UTSNAME_LENGTH
+# define _UTSNAME_LENGTH 65
+#endif
+
+#ifndef _UTSNAME_DOMAIN_LENGTH
+# define _UTSNAME_DOMAIN_LENGTH _UTSNAME_LENGTH
+#endif
diff --git a/kernel/tests/include/lapi/vmsplice.h b/kernel/tests/include/lapi/vmsplice.h
new file mode 100644
index 0000000..ba0fcca
--- /dev/null
+++ b/kernel/tests/include/lapi/vmsplice.h
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) International Business Machines Corp., 2007
+ * Copyright (c) 2014 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#ifndef VMSPLICE_H
+#define VMSPLICE_H
+
+#include "config.h"
+#include "lapi/syscalls.h"
+
+#include "lapi/iovec.h"
+
+#if !defined(HAVE_VMSPLICE)
+ssize_t vmsplice(int fd, const struct iovec *iov,
+ unsigned long nr_segs, unsigned int flags)
+{
+ return tst_syscall(__NR_vmsplice, fd, iov, nr_segs, flags);
+}
+#endif
+
+#endif /* VMSPLICE_H */
diff --git a/kernel/tests/include/lapi/xfrm.h b/kernel/tests/include/lapi/xfrm.h
new file mode 100644
index 0000000..d905120
--- /dev/null
+++ b/kernel/tests/include/lapi/xfrm.h
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2018 Linux Test Project
+ */
+
+#ifndef LAPI_XFRM_H__
+#define LAPI_XFRM_H__
+
+#ifndef XFRMNLGRP_NONE
+# define XFRMNLGRP_NONE 0
+#endif
+
+#ifndef XFRM_MSG_GETPOLICY
+# define XFRM_MSG_GETPOLICY 21
+#endif
+
+#endif
diff --git a/kernel/tests/include/libmsgctl.h b/kernel/tests/include/libmsgctl.h
new file mode 100644
index 0000000..e1afeab
--- /dev/null
+++ b/kernel/tests/include/libmsgctl.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) International Business Machines Corp., 2002
+ * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __LIBMSGCTL_H__
+#define __LIBMSGCTL_H__
+
+#define FAIL 1
+#define PASS 0
+
+struct mbuffer {
+ long type;
+ struct {
+ char len;
+ char pbytes[99];
+ } data;
+};
+
+int doreader(long key, int tid, long type, int child, int nreps);
+int dowriter(long key, int tid, long type, int child, int nreps);
+int fill_buffer(char *buf, char val, int size);
+int verify(char *buf, char val, int size, int child);
+
+#endif /*__LIBMSGCTL_H__ */
diff --git a/kernel/tests/include/libnewipc.h b/kernel/tests/include/libnewipc.h
new file mode 100644
index 0000000..30288cd
--- /dev/null
+++ b/kernel/tests/include/libnewipc.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2016 Xiao Yang <yangx.jy@cn.fujitsu.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.
+ */
+
+/*
+ * common definitions for the IPC system calls.
+ */
+
+#ifndef __LIBNEWIPC_H
+#define __LIBNEWIPC_H 1
+
+#include <sys/types.h>
+
+#define MSG_RD 0400
+#define MSG_WR 0200
+#define MSG_RW (MSG_RD | MSG_WR)
+#define MSGSIZE 1024
+#define MSGTYPE 1
+#define NR_MSGQUEUES 16
+#define min(a, b) (((a) < (b)) ? (a) : (b))
+
+#define SEM_RD 0400
+#define SEM_ALT 0200
+#define SEM_RA (SEM_RD | SEM_ALT)
+#define PSEMS 10
+
+#define SHM_RD 0400
+#define SHM_WR 0200
+#define SHM_RW (SHM_RD | SHM_WR)
+#define SHM_SIZE 2048
+#define INT_SIZE 4
+#define MODE_MASK 0x01FF
+
+key_t getipckey(const char *file, const int lineno);
+#define GETIPCKEY() \
+ getipckey(__FILE__, __LINE__)
+
+int get_used_queues(const char *file, const int lineno);
+#define GET_USED_QUEUES() \
+ get_used_queues(__FILE__, __LINE__)
+
+void *probe_free_addr(const char *file, const int lineno);
+#define PROBE_FREE_ADDR() \
+ probe_free_addr(__FILE__, __LINE__)
+
+#endif /* newlibipc.h */
diff --git a/kernel/tests/include/libsigwait.h b/kernel/tests/include/libsigwait.h
new file mode 100644
index 0000000..2fca578
--- /dev/null
+++ b/kernel/tests/include/libsigwait.h
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Linaro Limited. All rights reserved.
+ * Author: Viresh Kumar <viresh.kumar@linaro.org>
+ */
+
+#ifndef SIGWAIT_H__
+#define SIGWAIT_H__
+
+#include "tst_test.h"
+#include "tst_timer.h"
+#include <signal.h>
+
+/* swi: sigwaitinfo() */
+typedef int (*swi_func) (const sigset_t * set, siginfo_t * info,
+ void * timeout);
+typedef void (*test_func) (swi_func, int, enum tst_ts_type type);
+
+struct sigwait_test_desc {
+ test_func tf;
+ int signo;
+};
+
+void test_empty_set(swi_func sigwaitinfo, int signo,
+ enum tst_ts_type type LTP_ATTRIBUTE_UNUSED);
+void test_timeout(swi_func sigwaitinfo, int signo, enum tst_ts_type type);
+void test_unmasked_matching(swi_func sigwaitinfo, int signo,
+ enum tst_ts_type type LTP_ATTRIBUTE_UNUSED);
+void test_unmasked_matching_noinfo(swi_func sigwaitinfo, int signo,
+ enum tst_ts_type type LTP_ATTRIBUTE_UNUSED);
+void test_masked_matching(swi_func sigwaitinfo, int signo,
+ enum tst_ts_type type LTP_ATTRIBUTE_UNUSED);
+void test_masked_matching_rt(swi_func sigwaitinfo, int signo,
+ enum tst_ts_type type LTP_ATTRIBUTE_UNUSED);
+void test_masked_matching_noinfo(swi_func sigwaitinfo, int signo,
+ enum tst_ts_type type LTP_ATTRIBUTE_UNUSED);
+void test_bad_address(swi_func sigwaitinfo, int signo,
+ enum tst_ts_type type LTP_ATTRIBUTE_UNUSED);
+void test_bad_address2(swi_func sigwaitinfo, int signo LTP_ATTRIBUTE_UNUSED,
+ enum tst_ts_type type LTP_ATTRIBUTE_UNUSED);
+void test_bad_address3(swi_func sigwaitinfo, int signo LTP_ATTRIBUTE_UNUSED,
+ enum tst_ts_type type LTP_ATTRIBUTE_UNUSED);
+void sigwait_setup(void);
+#endif /* SIGWAIT_H__ */
diff --git a/kernel/tests/include/old/cleanup.c b/kernel/tests/include/old/cleanup.c
new file mode 100644
index 0000000..040dff8
--- /dev/null
+++ b/kernel/tests/include/old/cleanup.c
@@ -0,0 +1,47 @@
+/*
+ * Default cleanup logic because linux_syscall_numbers.h's need for cleanup
+ * and binutils bugs suck.
+ *
+ * Copyright (c) 2009 Cisco Systems, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it is
+ * free of the rightful claim of any third person regarding infringement
+ * or the like. Any license provided herein, whether implied or
+ * otherwise, applies only to this software file. Patent licenses, if
+ * any, provided herein do not apply to combinations of this program with
+ * other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#ifndef __CLEANUP_C__
+#define __CLEANUP_C__
+
+/* Did the user define a cleanup function? */
+#ifndef CLEANUP
+#define USING_DUMMY_CLEANUP 1
+#define CLEANUP dummy_cleanup
+#endif
+
+/* A freebie for defining the function prototype. */
+static void CLEANUP(void) __attribute__ ((unused));
+
+#ifdef USING_DUMMY_CLEANUP
+/* The stub function. Wewt.. */
+static void dummy_cleanup(void)
+{
+}
+#endif
+
+#endif
diff --git a/kernel/tests/include/old/ltp_cpuid.h b/kernel/tests/include/old/ltp_cpuid.h
new file mode 100644
index 0000000..6bd5537
--- /dev/null
+++ b/kernel/tests/include/old/ltp_cpuid.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2012-2013 The Chromium OS Authors. All rights reserved.
+ *
+ * Licensed under the BSD 3-clause.
+ */
+
+#ifndef __LTP_CPUID_H__
+#define __LTP_CPUID_H__
+
+static inline void cpuid(unsigned int info, unsigned int *eax, unsigned int *ebx,
+ unsigned int *ecx, unsigned int *edx)
+{
+#if defined(__i386__) || defined(__x86_64__)
+ unsigned int _eax = info, _ebx, _ecx, _edx;
+ asm volatile(
+# ifdef __i386__
+ "xchg %%ebx, %%esi;" /* save ebx (for PIC) */
+ "cpuid;"
+ "xchg %%esi, %%ebx;" /* restore ebx & pass to caller */
+ : "=S" (_ebx),
+# else
+ "cpuid;"
+ : "=b" (_ebx),
+# endif
+ "+a" (_eax), "=c" (_ecx), "=d" (_edx)
+ : /* inputs: eax is handled above */
+ );
+ if (eax) *eax = _eax;
+ if (ebx) *ebx = _ebx;
+ if (ecx) *ecx = _ecx;
+ if (edx) *edx = _edx;
+#endif
+}
+
+#endif
diff --git a/kernel/tests/include/old/ltp_priv.h b/kernel/tests/include/old/ltp_priv.h
new file mode 100644
index 0000000..0552457
--- /dev/null
+++ b/kernel/tests/include/old/ltp_priv.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2013 Cyril Hrubis chrubis@suse.cz
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __LTP_PRIV_H__
+#define __LTP_PRIV_H__
+
+#include <stdarg.h>
+
+/*
+ * This is the default temporary directory used by tst_tmpdir().
+ *
+ * This is used when TMPDIR env variable is not set.
+ */
+#define TEMPDIR "/tmp"
+
+/*
+ * Default filesystem to be used for tests.
+ */
+#define DEFAULT_FS_TYPE "ext2"
+
+/* environment variables for controlling tst_res verbosity */
+#define TOUT_VERBOSE_S "VERBOSE" /* All test cases reported */
+#define TOUT_NOPASS_S "NOPASS" /* No pass test cases are reported */
+#define TOUT_DISCARD_S "DISCARD" /* No output is reported */
+
+#define USC_ITERATION_ENV "USC_ITERATIONS"
+#define USC_LOOP_WALLTIME "USC_LOOP_WALLTIME"
+#define USC_NO_FUNC_CHECK "USC_NO_FUNC_CHECK"
+#define USC_LOOP_DELAY "USC_LOOP_DELAY"
+
+const char *parse_opts(int ac, char **av, const option_t *user_optarr, void
+ (*uhf)(void));
+
+/* Interface for rerouting to new lib calls from tst_res.c */
+extern void *tst_test;
+
+void tst_vbrk_(const char *file, const int lineno, int ttype,
+ const char *fmt, va_list va) __attribute__((noreturn));
+
+void tst_brk_(const char *file, const int lineno, int ttype,
+ const char *msg, ...);
+
+void tst_vres_(const char *file, const int lineno, int ttype,
+ const char *fmt, va_list va);
+
+void tst_res_(const char *file, const int lineno, int ttype,
+ const char *msg, ...);
+
+
+#define NO_NEWLIB_ASSERT(file, lineno) \
+ if (tst_test) { \
+ tst_brk_(file, lineno, TBROK, \
+ "%s() executed from newlib!", __FUNCTION__); \
+ }
+
+#endif /* __LTP_PRIV_H__ */
diff --git a/kernel/tests/include/old/ltp_signal.h b/kernel/tests/include/old/ltp_signal.h
new file mode 100644
index 0000000..02ee834
--- /dev/null
+++ b/kernel/tests/include/old/ltp_signal.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2009 Cisco Systems, Inc. All Rights Reserved.
+ * Copyright (c) 2009 FUJITSU LIMITED. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it is
+ * free of the rightful claim of any third person regarding infringement
+ * or the like. Any license provided herein, whether implied or
+ * otherwise, applies only to this software file. Patent licenses, if
+ * any, provided herein do not apply to combinations of this program with
+ * other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Author: Liu Bo <liubo2009@cn.fujitsu.com>
+ * Author: Ngie Cooper <yaneurabeya@gmail.com>
+ *
+ */
+
+#ifndef __LTP_SIGNAL_H
+#define __LTP_SIGNAL_H
+
+#include <errno.h>
+#include <signal.h>
+#include <stdio.h>
+#include "config.h"
+
+/*
+ * For all but __mips__:
+ *
+ * _COMPAT_NSIG / _COMPAT_NSIG_BPW == 2.
+ *
+ * For __mips__:
+ *
+ * _COMPAT_NSIG / _COMPAT_NSIG_BPW == 4.
+ *
+ * See asm/compat.h under the kernel source for more details.
+ *
+ * Multiply that by a fudge factor of 4 and you have your SIGSETSIZE.
+ */
+#if defined __mips__
+#define SIGSETSIZE 16
+#else
+#define SIGSETSIZE (_NSIG / 8)
+#endif
+
+#endif
diff --git a/kernel/tests/include/old/old_checkpoint.h b/kernel/tests/include/old/old_checkpoint.h
new file mode 100644
index 0000000..c8ffc92
--- /dev/null
+++ b/kernel/tests/include/old/old_checkpoint.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2015-2016 Cyril Hrubis <chrubis@suse.cz>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+ /*
+
+ Checkpoint - easy to use parent-child synchronization.
+
+ Checkpoint is based on futexes (man futex). The library allocates a page of
+ shared memory for futexes and the id is an offset to it which gives the user
+ up to page_size/sizeof(uint32_t) checkpoint pairs. Up to INT_MAX processes
+ can sleep on single id and can be woken up by single wake.
+
+ */
+
+#ifndef OLD_CHECKPOINT__
+#define OLD_CHECKPOINT__
+
+#include "test.h"
+#include "tst_checkpoint_fn.h"
+
+/*
+ * Checkpoint initializaton, must be done first.
+ *
+ * NOTE: tst_tmpdir() must be called beforehand.
+ */
+#define TST_CHECKPOINT_INIT(cleanup_fn) \
+ tst_checkpoint_init(__FILE__, __LINE__, cleanup_fn)
+
+#define TST_SAFE_CHECKPOINT_WAIT(cleanup_fn, id) \
+ tst_safe_checkpoint_wait(__FILE__, __LINE__, cleanup_fn, id, 0);
+
+#define TST_SAFE_CHECKPOINT_WAIT2(cleanup_fn, id, msec_timeout) \
+ tst_safe_checkpoint_wait(__FILE__, __LINE__, cleanup_fn, id, msec_timeout);
+
+#define TST_SAFE_CHECKPOINT_WAKE(cleanup_fn, id) \
+ tst_safe_checkpoint_wake(__FILE__, __LINE__, cleanup_fn, id, 1);
+
+#define TST_SAFE_CHECKPOINT_WAKE2(cleanup_fn, id, nr_wake) \
+ tst_safe_checkpoint_wake(__FILE__, __LINE__, cleanup_fn, id, nr_wake);
+
+#define TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(cleanup_fn, id) \
+ tst_safe_checkpoint_wake(__FILE__, __LINE__, cleanup_fn, id, 1); \
+ tst_safe_checkpoint_wait(__FILE__, __LINE__, cleanup_fn, id, 0);
+
+#endif /* OLD_CHECKPOINT__ */
diff --git a/kernel/tests/include/old/old_device.h b/kernel/tests/include/old/old_device.h
new file mode 100644
index 0000000..a6e9fea
--- /dev/null
+++ b/kernel/tests/include/old/old_device.h
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2014-2016 Cyril Hrubis <chrubis@suse.cz>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef OLD_DEVICE_H__
+#define OLD_DEVICE_H__
+
+/*
+ * Returns filesystem type to be used for the testing. Unless your test is
+ * designed for specific filesystem you should use this function to the tested
+ * filesystem.
+ *
+ * If TST_DEV_FS_TYPE is set the function returns it's content,
+ * otherwise default fs type hardcoded in the library is returned.
+ */
+const char *tst_dev_fs_type(void);
+
+/*
+ * Acquires test device.
+ *
+ * Can be used only once, i.e. you cannot get two different devices.
+ *
+ * Looks for LTP_DEV env variable first (which may be passed by the test
+ * driver or by a user) and returns just it's value if found.
+ *
+ * Otherwise creates a temp file and loop device.
+ *
+ * Note that you have to call tst_tmpdir() beforehand.
+ *
+ * Returns path to the device or NULL if it cannot be created.
+ * Call tst_release_device() when you're done.
+ */
+const char *tst_acquire_device_(void (cleanup_fn)(void), unsigned int size);
+
+const char *tst_acquire_device__(unsigned int size);
+
+static inline const char *tst_acquire_device(void (cleanup_fn)(void))
+{
+ return tst_acquire_device_(cleanup_fn, 0);
+}
+
+/*
+ * Acquire a loop device with specified temp filename. This function allows
+ * you to acquire multiple devices at the same time. LTP_DEV is ignored.
+ * If you call this function directly, use tst_detach_device() to release
+ * the devices. tst_release_device() will not work correctly.
+ *
+ * The return value points to a static buffer and additional calls of
+ * tst_acquire_loop_device() or tst_acquire_device() will overwrite it.
+ */
+const char *tst_acquire_loop_device(unsigned int size, const char *filename);
+
+/*
+ * @dev: device path returned by the tst_acquire_device()
+ */
+int tst_release_device(const char *dev);
+
+/*
+ * Cleanup function for tst_acquire_loop_device(). If you have acquired
+ * a device using tst_acquire_device(), use tst_release_device() instead.
+ * @dev: device path returned by the tst_acquire_loop_device()
+ */
+int tst_detach_device(const char *dev);
+
+/*
+ * Just like umount() but retries several times on failure.
+ * @path: Path to umount
+ */
+int tst_umount(const char *path);
+
+#endif /* OLD_DEVICE_H__ */
diff --git a/kernel/tests/include/old/old_module.h b/kernel/tests/include/old/old_module.h
new file mode 100644
index 0000000..c50efec
--- /dev/null
+++ b/kernel/tests/include/old/old_module.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author:
+ * Alexey Kodanev <alexey.kodanev@oracle.com>
+ *
+ * These functions help to load and unload kernel modules in the tests.
+ *
+ * tst_module_load function already includes tst_module_exists function,
+ * which is checking the following possible module's locations:
+ *
+ * 1. Current working directory
+ *
+ * 2. LTP installation path (using env LTPROOT, which is usually /opt/ltp)
+ *
+ * 3. If tmp directory created, it'll look at the test start working directory
+ *
+ */
+
+#ifndef TST_MODULE
+#define TST_MODULE
+
+/*
+ * Check module existence.
+ *
+ * @mod_name: module's file name.
+ * @mod_path: if it is not NULL, then tst_module_exists places the found
+ * module's path into the location pointed to by *mod_path. It must be freed
+ * with free() when it is no longer needed.
+ *
+ * In case of failure, test'll call cleanup_fn and exit with TCONF return value.
+ */
+void tst_module_exist(void (cleanup_fn)(void), const char *mod_name,
+ char **mod_path);
+
+/*
+ * Load a module using insmod program.
+ *
+ * @mod_name: module's file name.
+ * @argv: an array of pointers to null-terminated strings that represent the
+ * additional parameters to the module. The array of pointers must be
+ * terminated by a NULL pointer. If argv points to NULL, it will be ignored.
+ *
+ * In case of insmod failure, test will call cleanup_fn and exit with TBROK
+ * return value.
+ */
+void tst_module_load(void (cleanup_fn)(void),
+ const char *mod_name, char *const argv[]);
+
+/*
+ * Unload a module using rmmod program. In case of failure, test will call
+ * cleanup_fn and exit with TBROK return value.
+ *
+ * @mod_name: can be module name or module's file name.
+ */
+void tst_module_unload(void (cleanup_fn)(void), const char *mod_name);
+
+#endif /* TST_MODULE */
diff --git a/kernel/tests/include/old/old_resource.h b/kernel/tests/include/old/old_resource.h
new file mode 100644
index 0000000..46767f3
--- /dev/null
+++ b/kernel/tests/include/old/old_resource.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2012 Cyril Hrubis chrubis@suse.cz
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it is
+ * free of the rightful claim of any third person regarding infringement
+ * or the like. Any license provided herein, whether implied or
+ * otherwise, applies only to this software file. Patent licenses, if
+ * any, provided herein do not apply to combinations of this program with
+ * other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+ /*
+
+ Small helper for preparing files the test needs to copy before the testing.
+
+ We need to support two scenarios.
+
+ 1. Test is executed in local directory and this is also the place
+ we should look for files
+
+
+ 2. Test is executed after LTP has been installed, in this case we
+ look for env LTPROOT (usually /opt/ltp/)
+
+ */
+
+#ifndef TST_RESOURCE
+#define TST_RESOURCE
+
+const char *tst_dataroot(void);
+
+/*
+ * Copy a file to the CWD. The destination is apended to CWD.
+ */
+#define TST_RESOURCE_COPY(cleanup_fn, filename, dest) \
+ tst_resource_copy(__FILE__, __LINE__, (cleanup_fn), \
+ (filename), (dest))
+
+void tst_resource_copy(const char *file, const int lineno,
+ void (*cleanup_fn)(void),
+ const char *filename, const char *dest);
+
+#endif /* TST_RESOURCE */
diff --git a/kernel/tests/include/old/old_safe_file_ops.h b/kernel/tests/include/old/old_safe_file_ops.h
new file mode 100644
index 0000000..d6e2d29
--- /dev/null
+++ b/kernel/tests/include/old/old_safe_file_ops.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2012-2016 Cyril Hrubis <chrubis@suse.cz>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+ /*
+
+ This code helps with file reading/writing files providing scanf/printf like
+ interface that opens and closes the file automatically.
+
+ This kind of interface is especially useful for reading/writing values
+ from/to pseudo filesystems like procfs or sysfs.
+
+ */
+
+#ifndef SAFE_FILE_OPS
+#define SAFE_FILE_OPS
+
+#include "safe_file_ops_fn.h"
+
+#define FILE_SCANF(path, fmt, ...) \
+ file_scanf(__FILE__, __LINE__, \
+ (path), (fmt), ## __VA_ARGS__)
+
+#define SAFE_FILE_SCANF(cleanup_fn, path, fmt, ...) \
+ safe_file_scanf(__FILE__, __LINE__, (cleanup_fn), \
+ (path), (fmt), ## __VA_ARGS__)
+
+#define FILE_LINES_SCANF(cleanup_fn, path, fmt, ...) \
+ file_lines_scanf(__FILE__, __LINE__, (cleanup_fn), 0, \
+ (path), (fmt), ## __VA_ARGS__)
+
+#define SAFE_FILE_LINES_SCANF(cleanup_fn, path, fmt, ...) \
+ file_lines_scanf(__FILE__, __LINE__, (cleanup_fn), 1, \
+ (path), (fmt), ## __VA_ARGS__)
+
+#define FILE_PRINTF(path, fmt, ...) \
+ file_printf(__FILE__, __LINE__, \
+ (path), (fmt), ## __VA_ARGS__)
+
+#define SAFE_FILE_PRINTF(cleanup_fn, path, fmt, ...) \
+ safe_file_printf(__FILE__, __LINE__, (cleanup_fn), \
+ (path), (fmt), ## __VA_ARGS__)
+
+#define SAFE_CP(cleanup_fn, src, dst) \
+ safe_cp(__FILE__, __LINE__, (cleanup_fn), (src), (dst))
+
+#define SAFE_TOUCH(cleanup_fn, pathname, mode, times) \
+ safe_touch(__FILE__, __LINE__, (cleanup_fn), \
+ (pathname), (mode), (times))
+
+#endif /* SAFE_FILE_OPS */
diff --git a/kernel/tests/include/old/old_safe_net.h b/kernel/tests/include/old/old_safe_net.h
new file mode 100644
index 0000000..639094a
--- /dev/null
+++ b/kernel/tests/include/old/old_safe_net.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2015 Fujitsu Ltd.
+ * Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef OLD_SAFE_NET_H__
+#define OLD_SAFE_NET_H__
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <sys/un.h>
+
+#include "safe_net_fn.h"
+
+#define SAFE_SOCKET(cleanup_fn, domain, type, protocol) \
+ safe_socket(__FILE__, __LINE__, (cleanup_fn), domain, type, protocol)
+
+#define SAFE_BIND(cleanup_fn, socket, address, address_len) \
+ safe_bind(__FILE__, __LINE__, (cleanup_fn), socket, address, \
+ address_len)
+
+#define SAFE_LISTEN(cleanup_fn, socket, backlog) \
+ safe_listen(__FILE__, __LINE__, (cleanup_fn), socket, backlog)
+
+#define SAFE_CONNECT(cleanup_fn, sockfd, addr, addrlen) \
+ safe_connect(__FILE__, __LINE__, (cleanup_fn), sockfd, addr, addrlen)
+
+#define SAFE_GETSOCKNAME(cleanup_fn, sockfd, addr, addrlen) \
+ safe_getsockname(__FILE__, __LINE__, (cleanup_fn), sockfd, addr, \
+ addrlen)
+
+#define TST_GET_UNUSED_PORT(cleanup_fn, family, type) \
+ tst_get_unused_port(__FILE__, __LINE__, (cleanup_fn), family, type)
+
+#endif /* OLD_SAFE_NET_H__ */
diff --git a/kernel/tests/include/old/old_safe_stdio.h b/kernel/tests/include/old/old_safe_stdio.h
new file mode 100644
index 0000000..3508b24
--- /dev/null
+++ b/kernel/tests/include/old/old_safe_stdio.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2013-2016 Cyril Hrubis <chrubis@suse.cz>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef OLD_SAFE_STDIO_H__
+#define OLD_SAFE_STDIO_H__
+
+#include <stdio.h>
+
+#include "safe_stdio_fn.h"
+
+#define SAFE_FOPEN(cleanup_fn, path, mode) \
+ safe_fopen(__FILE__, __LINE__, cleanup_fn, path, mode)
+
+#define SAFE_FCLOSE(cleanup_fn, f) \
+ safe_fclose(__FILE__, __LINE__, cleanup_fn, f)
+
+#define SAFE_ASPRINTF(cleanup_fn, strp, fmt, ...) \
+ safe_asprintf(__FILE__, __LINE__, cleanup_fn, strp, fmt, __VA_ARGS__)
+
+#define SAFE_POPEN(cleanup_fn, command, type) \
+ safe_popen(__FILE__, __LINE__, cleanup_fn, command, type)
+
+#endif /* OLD_SAFE_STDIO_H__ */
diff --git a/kernel/tests/include/old/old_tmpdir.h b/kernel/tests/include/old/old_tmpdir.h
new file mode 100644
index 0000000..9c61172
--- /dev/null
+++ b/kernel/tests/include/old/old_tmpdir.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef OLD_TMPDIR_H__
+#define OLD_TMPDIR_H__
+
+/*
+ * Create a unique temporary directory and chdir() to it. It expects the caller
+ * to have defined/initialized the TCID/TST_TOTAL global variables.
+ * The TESTDIR global variable will be set to the directory that gets used
+ * as the testing directory.
+ *
+ * NOTE: This function must be called BEFORE any activity that would require
+ * CLEANUP. If tst_tmpdir() fails, it cleans up afer itself and calls
+ * tst_exit() (i.e. does not return).
+ */
+void tst_tmpdir(void);
+
+/*
+ * Recursively remove the temporary directory created by tst_tmpdir().
+ * This function is intended ONLY as a companion to tst_tmpdir().
+ */
+void tst_rmdir(void);
+
+/* tst_get_tmpdir()
+ *
+ * Return a copy of the test temp directory as seen by LTP. This is for
+ * path-oriented tests like chroot, etc, that may munge the path a bit.
+ *
+ * FREE VARIABLE AFTER USE IF IT IS REUSED!
+ */
+char *tst_get_tmpdir(void);
+
+/*
+ * Returns 1 if temp directory was created.
+ */
+int tst_tmpdir_created(void);
+
+/* declared in tst_tmpdir.c */
+const char *tst_get_startwd(void);
+
+#endif /* OLD_TMPDIR_H__ */
diff --git a/kernel/tests/include/old/random_range.h b/kernel/tests/include/old/random_range.h
new file mode 100644
index 0000000..22b3f93
--- /dev/null
+++ b/kernel/tests/include/old/random_range.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it is
+ * free of the rightful claim of any third person regarding infringement
+ * or the like. Any license provided herein, whether implied or
+ * otherwise, applies only to this software file. Patent licenses, if
+ * any, provided herein do not apply to combinations of this program with
+ * other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
+ * Mountain View, CA 94043, or:
+ *
+ * http://www.sgi.com
+ *
+ * For further information regarding this notice, see:
+ *
+ * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
+ */
+#ifndef _RANDOM_RANGE_H_
+#define _RANDOM_RANGE_H_
+
+int parse_ranges ( char *, int, int, int, int (*)(), char **, char ** );
+int range_min ( char *, int );
+int range_max ( char *, int );
+int range_mult ( char *, int );
+long random_range ( int, int, int, char ** );
+long random_rangel ( long, long, long, char ** );
+long long random_rangell ( long long, long long, long long, char ** );
+void random_range_seed( long );
+long random_bit ( long );
+
+#endif
diff --git a/kernel/tests/include/old/safe_macros.h b/kernel/tests/include/old/safe_macros.h
new file mode 100644
index 0000000..e778d30
--- /dev/null
+++ b/kernel/tests/include/old/safe_macros.h
@@ -0,0 +1,340 @@
+/*
+ * Safe macros for commonly used syscalls to reduce code duplication in LTP
+ * testcases, and to ensure all errors are caught in said testcases as
+ * gracefully as possible.
+ *
+ * Also satiates some versions of gcc/glibc when the warn_unused_result
+ * attribute is applied to the function call.
+ *
+ * Licensed under the GPLv2.
+ */
+
+#ifndef __TEST_H__
+#error "you must include test.h before this file"
+#else
+
+#ifndef __SAFE_MACROS_H__
+#define __SAFE_MACROS_H__
+
+#include "safe_macros_fn.h"
+#include "old_safe_stdio.h"
+#include "old_safe_net.h"
+
+#define SAFE_BASENAME(cleanup_fn, path) \
+ safe_basename(__FILE__, __LINE__, (cleanup_fn), (path))
+
+#define SAFE_CHDIR(cleanup_fn, path) \
+ safe_chdir(__FILE__, __LINE__, (cleanup_fn), (path))
+
+#define SAFE_CLOSE(cleanup_fn, fd) ({ \
+ int ret = safe_close(__FILE__, __LINE__, (cleanup_fn), (fd)); \
+ fd = -1; \
+ ret; \
+ })
+
+#define SAFE_CREAT(cleanup_fn, pathname, mode) \
+ safe_creat(__FILE__, __LINE__, cleanup_fn, (pathname), (mode))
+
+#define SAFE_DIRNAME(cleanup_fn, path) \
+ safe_dirname(__FILE__, __LINE__, (cleanup_fn), (path))
+
+#define SAFE_GETCWD(cleanup_fn, buf, size) \
+ safe_getcwd(__FILE__, __LINE__, (cleanup_fn), (buf), (size))
+
+#define SAFE_GETPWNAM(cleanup_fn, name) \
+ safe_getpwnam(__FILE__, __LINE__, cleanup_fn, (name))
+
+#define SAFE_GETRUSAGE(cleanup_fn, who, usage) \
+ safe_getrusage(__FILE__, __LINE__, (cleanup_fn), (who), (usage))
+
+#define SAFE_MALLOC(cleanup_fn, size) \
+ safe_malloc(__FILE__, __LINE__, (cleanup_fn), (size))
+
+#define SAFE_MKDIR(cleanup_fn, pathname, mode) \
+ safe_mkdir(__FILE__, __LINE__, (cleanup_fn), (pathname), (mode))
+
+#define SAFE_RMDIR(cleanup_fn, pathname) \
+ safe_rmdir(__FILE__, __LINE__, (cleanup_fn), (pathname))
+
+#define SAFE_MUNMAP(cleanup_fn, addr, length) \
+ safe_munmap(__FILE__, __LINE__, (cleanup_fn), (addr), (length))
+
+#define SAFE_OPEN(cleanup_fn, pathname, oflags, ...) \
+ safe_open(__FILE__, __LINE__, (cleanup_fn), (pathname), (oflags), \
+ ##__VA_ARGS__)
+
+#define SAFE_PIPE(cleanup_fn, fildes) \
+ safe_pipe(__FILE__, __LINE__, cleanup_fn, (fildes))
+
+#define SAFE_READ(cleanup_fn, len_strict, fildes, buf, nbyte) \
+ safe_read(__FILE__, __LINE__, cleanup_fn, (len_strict), (fildes), \
+ (buf), (nbyte))
+
+#define SAFE_SETEGID(cleanup_fn, egid) \
+ safe_setegid(__FILE__, __LINE__, cleanup_fn, (egid))
+
+#define SAFE_SETEUID(cleanup_fn, euid) \
+ safe_seteuid(__FILE__, __LINE__, cleanup_fn, (euid))
+
+#define SAFE_SETGID(cleanup_fn, gid) \
+ safe_setgid(__FILE__, __LINE__, cleanup_fn, (gid))
+
+#define SAFE_SETUID(cleanup_fn, uid) \
+ safe_setuid(__FILE__, __LINE__, cleanup_fn, (uid))
+
+#define SAFE_GETRESUID(cleanup_fn, ruid, euid, suid) \
+ safe_getresuid(__FILE__, __LINE__, cleanup_fn, (ruid), (euid), (suid))
+
+#define SAFE_GETRESGID(cleanup_fn, rgid, egid, sgid) \
+ safe_getresgid(__FILE__, __LINE__, cleanup_fn, (rgid), (egid), (sgid))
+
+#define SAFE_UNLINK(cleanup_fn, pathname) \
+ safe_unlink(__FILE__, __LINE__, cleanup_fn, (pathname))
+
+#define SAFE_LINK(cleanup_fn, oldpath, newpath) \
+ safe_link(__FILE__, __LINE__, cleanup_fn, (oldpath), (newpath))
+
+#define SAFE_LINKAT(cleanup_fn, olddirfd, oldpath, newdirfd, newpath, flags) \
+ safe_linkat(__FILE__, __LINE__, cleanup_fn, (olddirfd), (oldpath), \
+ (newdirfd), (newpath), (flags))
+
+#define SAFE_READLINK(cleanup_fn, path, buf, bufsize) \
+ safe_readlink(__FILE__, __LINE__, cleanup_fn, (path), (buf), (bufsize))
+
+#define SAFE_SYMLINK(cleanup_fn, oldpath, newpath) \
+ safe_symlink(__FILE__, __LINE__, cleanup_fn, (oldpath), (newpath))
+
+#define SAFE_WRITE(cleanup_fn, len_strict, fildes, buf, nbyte) \
+ safe_write(__FILE__, __LINE__, cleanup_fn, (len_strict), (fildes), \
+ (buf), (nbyte))
+
+#define SAFE_STRTOL(cleanup_fn, str, min, max) \
+ safe_strtol(__FILE__, __LINE__, cleanup_fn, (str), (min), (max))
+
+#define SAFE_STRTOUL(cleanup_fn, str, min, max) \
+ safe_strtoul(__FILE__, __LINE__, cleanup_fn, (str), (min), (max))
+
+#define SAFE_SYSCONF(cleanup_fn, name) \
+ safe_sysconf(__FILE__, __LINE__, cleanup_fn, name)
+
+#define SAFE_CHMOD(cleanup_fn, path, mode) \
+ safe_chmod(__FILE__, __LINE__, (cleanup_fn), (path), (mode))
+
+#define SAFE_FCHMOD(cleanup_fn, fd, mode) \
+ safe_fchmod(__FILE__, __LINE__, (cleanup_fn), (fd), (mode))
+
+#define SAFE_CHOWN(cleanup_fn, path, owner, group) \
+ safe_chown(__FILE__, __LINE__, (cleanup_fn), (path), (owner), (group))
+
+#define SAFE_FCHOWN(cleanup_fn, fd, owner, group) \
+ safe_fchown(__FILE__, __LINE__, (cleanup_fn), (fd), (owner), (group))
+
+#define SAFE_WAIT(cleanup_fn, status) \
+ safe_wait(__FILE__, __LINE__, (cleanup_fn), (status))
+
+#define SAFE_WAITPID(cleanup_fn, pid, status, opts) \
+ safe_waitpid(__FILE__, __LINE__, (cleanup_fn), (pid), (status), (opts))
+
+#define SAFE_KILL(cleanup_fn, pid, sig) \
+ safe_kill(__FILE__, __LINE__, (cleanup_fn), (pid), (sig))
+
+#define SAFE_MEMALIGN(cleanup_fn, alignment, size) \
+ safe_memalign(__FILE__, __LINE__, (cleanup_fn), (alignment), (size))
+
+#define SAFE_MKFIFO(cleanup_fn, pathname, mode) \
+ safe_mkfifo(__FILE__, __LINE__, (cleanup_fn), (pathname), (mode))
+
+#define SAFE_RENAME(cleanup_fn, oldpath, newpath) \
+ safe_rename(__FILE__, __LINE__, (cleanup_fn), (oldpath), (newpath))
+
+#define SAFE_MOUNT(cleanup_fn, source, target, filesystemtype, \
+ mountflags, data) \
+ safe_mount(__FILE__, __LINE__, (cleanup_fn), (source), (target), \
+ (filesystemtype), (mountflags), (data))
+
+#define SAFE_UMOUNT(cleanup_fn, target) \
+ safe_umount(__FILE__, __LINE__, (cleanup_fn), (target))
+
+/*
+ * following functions are inline because the behaviour may depend on
+ * -D_FILE_OFFSET_BITS=64 -DOFF_T=__off64_t compile flags
+ */
+
+static inline void *safe_mmap(const char *file, const int lineno,
+ void (*cleanup_fn)(void), void *addr, size_t length,
+ int prot, int flags, int fd, off_t offset)
+{
+ void *rval;
+
+ rval = mmap(addr, length, prot, flags, fd, offset);
+ if (rval == MAP_FAILED) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: mmap(%p,%zu,%d,%d,%d,%ld) failed",
+ file, lineno, addr, length, prot, flags, fd,
+ (long) offset);
+ }
+
+ return rval;
+}
+#define SAFE_MMAP(cleanup_fn, addr, length, prot, flags, fd, offset) \
+ safe_mmap(__FILE__, __LINE__, (cleanup_fn), (addr), (length), (prot), \
+ (flags), (fd), (offset))
+
+static inline int safe_ftruncate(const char *file, const int lineno,
+ void (cleanup_fn) (void), int fd, off_t length)
+{
+ int rval;
+
+ rval = ftruncate(fd, length);
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: ftruncate(%d,%ld) failed",
+ file, lineno, fd, (long)length);
+ }
+
+ return rval;
+}
+#define SAFE_FTRUNCATE(cleanup_fn, fd, length) \
+ safe_ftruncate(__FILE__, __LINE__, cleanup_fn, (fd), (length))
+
+static inline int safe_truncate(const char *file, const int lineno,
+ void (cleanup_fn) (void), const char *path, off_t length)
+{
+ int rval;
+
+ rval = truncate(path, length);
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: truncate(%s,%ld) failed",
+ file, lineno, path, (long)length);
+ }
+
+ return rval;
+}
+#define SAFE_TRUNCATE(cleanup_fn, path, length) \
+ safe_truncate(__FILE__, __LINE__, cleanup_fn, (path), (length))
+
+static inline int safe_stat(const char *file, const int lineno,
+ void (cleanup_fn)(void), const char *path, struct stat *buf)
+{
+ int rval;
+
+ rval = stat(path, buf);
+
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: stat(%s,%p) failed", file, lineno, path, buf);
+ }
+
+ return rval;
+}
+#define SAFE_STAT(cleanup_fn, path, buf) \
+ safe_stat(__FILE__, __LINE__, (cleanup_fn), (path), (buf))
+
+static inline int safe_fstat(const char *file, const int lineno,
+ void (cleanup_fn)(void), int fd, struct stat *buf)
+{
+ int rval;
+
+ rval = fstat(fd, buf);
+
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: fstat(%d,%p) failed", file, lineno, fd, buf);
+ }
+
+ return rval;
+}
+#define SAFE_FSTAT(cleanup_fn, fd, buf) \
+ safe_fstat(__FILE__, __LINE__, (cleanup_fn), (fd), (buf))
+
+static inline int safe_lstat(const char *file, const int lineno,
+ void (cleanup_fn)(void), const char *path, struct stat *buf)
+{
+ int rval;
+
+ rval = lstat(path, buf);
+
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: lstat(%s,%p) failed", file, lineno, path, buf);
+ }
+
+ return rval;
+}
+#define SAFE_LSTAT(cleanup_fn, path, buf) \
+ safe_lstat(__FILE__, __LINE__, (cleanup_fn), (path), (buf))
+
+static inline off_t safe_lseek(const char *file, const int lineno,
+ void (cleanup_fn)(void), int fd, off_t offset, int whence)
+{
+ off_t rval;
+
+ rval = lseek(fd, offset, whence);
+
+ if (rval == (off_t) -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: lseek(%d,%ld,%d) failed",
+ file, lineno, fd, (long)offset, whence);
+ }
+
+ return rval;
+}
+#define SAFE_LSEEK(cleanup_fn, fd, offset, whence) \
+ safe_lseek(__FILE__, __LINE__, cleanup_fn, (fd), (offset), (whence))
+
+static inline int safe_getrlimit(const char *file, const int lineno,
+ void (cleanup_fn)(void), int resource, struct rlimit *rlim)
+{
+ int rval;
+
+ rval = getrlimit(resource, rlim);
+
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: getrlimit(%d,%p) failed",
+ file, lineno, resource, rlim);
+ }
+
+ return rval;
+}
+#define SAFE_GETRLIMIT(cleanup_fn, resource, rlim) \
+ safe_getrlimit(__FILE__, __LINE__, (cleanup_fn), (resource), (rlim))
+
+static inline int safe_setrlimit(const char *file, const int lineno,
+ void (cleanup_fn)(void), int resource, const struct rlimit *rlim)
+{
+ int rval;
+
+ rval = setrlimit(resource, rlim);
+
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: setrlimit(%d,%p) failed",
+ file, lineno, resource, rlim);
+ }
+
+ return rval;
+}
+#define SAFE_SETRLIMIT(cleanup_fn, resource, rlim) \
+ safe_setrlimit(__FILE__, __LINE__, (cleanup_fn), (resource), (rlim))
+
+#define SAFE_OPENDIR(cleanup_fn, name) \
+ safe_opendir(__FILE__, __LINE__, (cleanup_fn), (name))
+
+#define SAFE_CLOSEDIR(cleanup_fn, dirp) \
+ safe_closedir(__FILE__, __LINE__, (cleanup_fn), (dirp))
+
+#define SAFE_READDIR(cleanup_fn, dirp) \
+ safe_readdir(__FILE__, __LINE__, (cleanup_fn), (dirp))
+
+
+#define SAFE_IOCTL(cleanup_fn, fd, request, ...) \
+ ({int ret = ioctl(fd, request, __VA_ARGS__); \
+ if (ret < 0) \
+ tst_brkm(TBROK | TERRNO, cleanup_fn, \
+ "ioctl(%i,%s,...) failed", fd, #request); \
+ ret;})
+
+#endif /* __SAFE_MACROS_H__ */
+#endif /* __TEST_H__ */
diff --git a/kernel/tests/include/old/test.h b/kernel/tests/include/old/test.h
new file mode 100644
index 0000000..604254e
--- /dev/null
+++ b/kernel/tests/include/old/test.h
@@ -0,0 +1,214 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
+ * Copyright (c) 2009-2013 Cyril Hrubis chrubis@suse.cz
+ */
+
+#ifndef __TEST_H__
+#define __TEST_H__
+
+#ifdef TST_TEST_H__
+# error Newlib tst_test.h already included
+#endif /* TST_TEST_H__ */
+
+#include <stdio.h>
+#include <signal.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+#include "usctest.h"
+
+#include "tst_common.h"
+#include "old_safe_file_ops.h"
+#include "old_checkpoint.h"
+#include "tst_process_state.h"
+#include "old_resource.h"
+#include "tst_res_flags.h"
+#include "tst_kvercmp.h"
+#include "tst_fs.h"
+#include "tst_pid.h"
+#include "tst_cmd.h"
+#include "tst_cpu.h"
+#include "tst_clone.h"
+#include "old_device.h"
+#include "old_tmpdir.h"
+#include "tst_minmax.h"
+#include "tst_get_bad_addr.h"
+#include "tst_path_has_mnt_flags.h"
+
+/*
+ * Ensure that NUMSIGS is defined.
+ * It should be defined in signal.h or sys/signal.h on
+ * UNICOS/mk and IRIX systems. On UNICOS systems,
+ * it is not defined, thus it is being set to UNICOS's NSIG.
+ * Note: IRIX's NSIG (signals are 1-(NSIG-1))
+ * is not same meaning as UNICOS/UMK's NSIG (signals 1-NSIG)
+ */
+#ifndef NUMSIGS
+#define NUMSIGS NSIG
+#endif
+
+
+/* defines for unexpected signal setup routine (set_usig.c) */
+#define FORK 1 /* SIGCHLD is to be ignored */
+#define NOFORK 0 /* SIGCHLD is to be caught */
+#define DEF_HANDLER SIG_ERR /* tells set_usig() to use default signal handler */
+
+/*
+ * The following defines are used to control tst_res and t_result reporting.
+ */
+
+#define TOUTPUT "TOUTPUT" /* The name of the environment variable */
+ /* that can be set to one of the following */
+ /* strings to control tst_res output */
+ /* If not set, TOUT_VERBOSE_S is assumed */
+
+/*
+ * fork() can't be used on uClinux systems, so use FORK_OR_VFORK instead,
+ * which will run vfork() on uClinux.
+ * mmap() doesn't support MAP_PRIVATE on uClinux systems, so use
+ * MAP_PRIVATE_EXCEPT_UCLINUX instead, which will skip the option on uClinux.
+ * If MAP_PRIVATE really is required, the test can not be run on uClinux.
+ */
+#ifdef UCLINUX
+# define FORK_OR_VFORK tst_vfork
+# define MAP_PRIVATE_EXCEPT_UCLINUX 0
+/* tst_old_flush() + vfork() */
+pid_t tst_vfork(void);
+#else
+# define FORK_OR_VFORK tst_fork
+# define MAP_PRIVATE_EXCEPT_UCLINUX MAP_PRIVATE
+#endif
+
+/*
+ * Macro to use for making functions called only once in
+ * multi-threaded tests such as init or cleanup function.
+ * The first call to @name_fn function by any thread shall
+ * call the @exec_fn. Subsequent calls shall not call @exec_fn.
+ * *_fn functions must not take any arguments.
+ */
+#define TST_DECLARE_ONCE_FN(name_fn, exec_fn) \
+ void name_fn(void) \
+ { \
+ static pthread_once_t ltp_once = PTHREAD_ONCE_INIT; \
+ pthread_once(&ltp_once, exec_fn); \
+ }
+
+/*
+ * lib/forker.c
+ */
+extern int Forker_pids[];
+extern int Forker_npids;
+
+typedef struct {
+ char *option; /* Valid option string (one option only) like "a:" */
+ int *flag; /* Pointer to location to set true if option given */
+ char **arg; /* Pointer to location to place argument, if needed */
+} option_t;
+
+/* lib/tst_parse_opts.c */
+void tst_parse_opts(int argc, char *argv[], const option_t *user_optarg,
+ void (*user_help)(void));
+
+/* lib/tst_res.c */
+const char *strttype(int ttype);
+
+void tst_resm_(const char *file, const int lineno, int ttype,
+ const char *arg_fmt, ...)
+ __attribute__ ((format (printf, 4, 5)));
+#define tst_resm(ttype, arg_fmt, ...) \
+ tst_resm_(__FILE__, __LINE__, (ttype), \
+ (arg_fmt), ##__VA_ARGS__)
+
+void tst_resm_hexd_(const char *file, const int lineno, int ttype,
+ const void *buf, size_t size, const char *arg_fmt, ...)
+ __attribute__ ((format (printf, 6, 7)));
+#define tst_resm_hexd(ttype, buf, size, arg_fmt, ...) \
+ tst_resm_hexd_(__FILE__, __LINE__, (ttype), (buf), (size), \
+ (arg_fmt), ##__VA_ARGS__)
+
+void tst_brkm_(const char *file, const int lineno, int ttype,
+ void (*func)(void), const char *arg_fmt, ...)
+ __attribute__ ((format (printf, 5, 6))) LTP_ATTRIBUTE_NORETURN;
+
+#ifdef LTPLIB
+# include "ltp_priv.h"
+# define tst_brkm(flags, cleanup, fmt, ...) do { \
+ if (tst_test) \
+ tst_brk_(__FILE__, __LINE__, flags, fmt, ##__VA_ARGS__); \
+ else \
+ tst_brkm_(__FILE__, __LINE__, flags, cleanup, fmt, ##__VA_ARGS__); \
+ } while (0)
+#else
+# define tst_brkm(flags, cleanup, fmt, ...) do { \
+ tst_brkm_(__FILE__, __LINE__, flags, cleanup, fmt, ##__VA_ARGS__); \
+ } while (0)
+#endif
+
+void tst_require_root(void);
+void tst_exit(void) LTP_ATTRIBUTE_NORETURN;
+void tst_old_flush(void);
+
+/*
+ * tst_old_flush() + fork
+ * NOTE: tst_fork() will reset T_exitval to 0 for child process.
+ */
+pid_t tst_fork(void);
+
+/* lib/tst_res.c */
+/*
+ * In case we need do real test work in child process parent process can use
+ * tst_record_childstatus() to make child process's test results propagated to
+ * parent process correctly.
+ *
+ * The child can use tst_resm(), tst_brkm() followed by the tst_exit() or
+ * plain old exit() (with TPASS, TFAIL and TBROK).
+ *
+ * WARNING: Be wary that the child cleanup function passed to tst_brkm()
+ * must clean only resources the child has allocated. E.g. the
+ * child cleanup is different function from the parent cleanup.
+ */
+void tst_record_childstatus(void (*cleanup)(void), pid_t child);
+
+extern int tst_count;
+
+/* lib/tst_sig.c */
+void tst_sig(int fork_flag, void (*handler)(), void (*cleanup)());
+
+/* lib/self_exec.c */
+void maybe_run_child(void (*child)(), const char *fmt, ...);
+int self_exec(const char *argv0, const char *fmt, ...);
+
+/* lib/tst_mkfs.c
+ *
+ * @dev: path to a device
+ * @fs_type: filesystem type
+ * @fs_opts: NULL or NULL terminated array of mkfs options
+ * @extra_opt: extra mkfs option which is passed after the device name
+ */
+#define tst_mkfs(cleanup, dev, fs_type, fs_opts, extra_opts) \
+ tst_mkfs_(__FILE__, __LINE__, cleanup, dev, fs_type, \
+ fs_opts, extra_opts)
+void tst_mkfs_(const char *file, const int lineno, void (cleanup_fn)(void),
+ const char *dev, const char *fs_type,
+ const char *const fs_opts[], const char *const extra_opts[]);
+
+/* lib/tst_res.c
+ * tst_strsig converts signal's value to corresponding string.
+ * tst_strerrno converts errno to corresponding string.
+ */
+const char *tst_strsig(int sig);
+const char *tst_strerrno(int err);
+
+#ifdef TST_USE_COMPAT16_SYSCALL
+#define TCID_BIT_SUFFIX "_16"
+#elif TST_USE_NEWER64_SYSCALL
+#define TCID_BIT_SUFFIX "_64"
+#else
+#define TCID_BIT_SUFFIX ""
+#endif
+#define TCID_DEFINE(ID) char *TCID = (#ID TCID_BIT_SUFFIX)
+
+#endif /* __TEST_H__ */
diff --git a/kernel/tests/include/old/tlibio.h b/kernel/tests/include/old/tlibio.h
new file mode 100644
index 0000000..0fe9ce9
--- /dev/null
+++ b/kernel/tests/include/old/tlibio.h
@@ -0,0 +1,161 @@
+/*
+ * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it is
+ * free of the rightful claim of any third person regarding infringement
+ * or the like. Any license provided herein, whether implied or
+ * otherwise, applies only to this software file. Patent licenses, if
+ * any, provided herein do not apply to combinations of this program with
+ * other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
+ * Mountain View, CA 94043, or:
+ *
+ * http://www.sgi.com
+ *
+ * For further information regarding this notice, see:
+ *
+ * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
+ */
+
+#define LIO_IO_SYNC 00001 /* read/write */
+#define LIO_IO_ASYNC 00002 /* reada/writea/aio_write/aio_read */
+#define LIO_IO_SLISTIO 00004 /* single stride sync listio */
+#define LIO_IO_ALISTIO 00010 /* single stride async listio */
+#define LIO_IO_SYNCV 00020 /* single-buffer readv/writev */
+#define LIO_IO_SYNCP 00040 /* pread/pwrite */
+
+#ifdef sgi
+#define LIO_IO_ATYPES 00077 /* all io types */
+#define LIO_IO_TYPES 00061 /* all io types, non-async */
+#endif /* sgi */
+#if defined(__linux__) && !defined(__UCLIBC__)
+#define LIO_IO_TYPES 00061 /* all io types */
+#define LIO_IO_ATYPES 00077 /* all io types */
+#endif
+#if defined(__sun) || defined(__hpux) || defined(_AIX) || defined(__UCLIBC__)
+#define LIO_IO_TYPES 00021 /* all io types except pread/pwrite */
+#endif /* linux */
+#ifdef CRAY
+#define LIO_IO_TYPES 00017 /* all io types */
+#endif /* CRAY */
+
+#ifndef LIO_IO_ATYPES
+#define LIO_IO_ATYPES LIO_IO_TYPES
+#endif
+
+#define LIO_WAIT_NONE 00010000 /* return asap -- use with care */
+#define LIO_WAIT_ACTIVE 00020000 /* spin looking at iosw fields, or EINPROGRESS */
+#define LIO_WAIT_RECALL 00040000 /* call recall(2)/aio_suspend(3) */
+#define LIO_WAIT_SIGPAUSE 00100000 /* call pause */
+#define LIO_WAIT_SIGACTIVE 00200000 /* spin waiting for signal */
+#if defined(sgi) || defined(__linux__)
+#define LIO_WAIT_CBSUSPEND 00400000 /* aio_suspend waiting for callback */
+#define LIO_WAIT_SIGSUSPEND 01000000 /* aio_suspend waiting for signal */
+#define LIO_WAIT_ATYPES 01760000 /* all async wait types, except nowait */
+#define LIO_WAIT_TYPES 00020000 /* all sync wait types (sorta) */
+#endif /* sgi */
+#if defined(__sun) || defined(__hpux) || defined(_AIX)
+#define LIO_WAIT_TYPES 00300000 /* all wait types, except nowait */
+#endif /* linux */
+#ifdef CRAY
+#define LIO_WAIT_TYPES 00360000 /* all wait types, except nowait */
+#endif /* CRAY */
+
+/* meta wait io */
+/* 00 000 0000 */
+
+#if defined(sgi) || defined(__linux__)
+/* all callback wait types */
+#define LIO_WAIT_CBTYPES (LIO_WAIT_CBSUSPEND)
+/* all signal wait types */
+#define LIO_WAIT_SIGTYPES (LIO_WAIT_SIGPAUSE|LIO_WAIT_SIGACTIVE|LIO_WAIT_SIGSUSPEND)
+/* all aio_{read,write} or lio_listio */
+#define LIO_IO_ASYNC_TYPES (LIO_IO_ASYNC|LIO_IO_SLISTIO|LIO_IO_ALISTIO)
+#endif /* sgi */
+#if defined(__sun) || defined(__hpux) || defined(_AIX)
+/* all signal wait types */
+#define LIO_WAIT_SIGTYPES (LIO_WAIT_SIGPAUSE)
+#endif /* linux */
+#ifdef CRAY
+/* all signal wait types */
+#define LIO_WAIT_SIGTYPES (LIO_WAIT_SIGPAUSE|LIO_WAIT_SIGACTIVE)
+#endif /* CRAY */
+
+/*
+ * This bit provides a way to randomly pick an io type and wait method.
+ * lio_read_buffer() and lio_write_buffer() functions will call
+ * lio_random_methods() with the given method.
+ */
+#define LIO_RANDOM 010000000
+
+/*
+ * This bit provides a way for the programmer to use async i/o with
+ * signals and to use their own signal handler. By default,
+ * the signal will only be given to the system call if the wait
+ * method is LIO_WAIT_SIGPAUSE or LIO_WAIT_SIGACTIVE.
+ * Whenever these wait methods are used, libio signal handler
+ * will be used.
+ */
+#define LIO_USE_SIGNAL 020000000
+
+/*
+ * prototypes/structures for functions in the libio.c module. See comments
+ * in that module, or man page entries for information on the individual
+ * functions.
+ */
+
+int stride_bounds(int offset, int stride, int nstrides,
+ int bytes_per_stride, int *min_byte, int *max_byte);
+
+int lio_set_debug(int level);
+int lio_parse_io_arg1(char *string);
+void lio_help1(char *prefex);
+int lio_parse_io_arg2(char *string, char **badtoken);
+void lio_help2(char *prefex);
+int lio_write_buffer(int fd, int method, char *buffer, int size,
+ int sig, char **errmsg, long wrd);
+
+int lio_read_buffer(int fd, int method, char *buffer, int size,
+ int sig, char **errmsg, long wrd);
+int lio_random_methods(long mask);
+
+#if CRAY
+#include <sys/iosw.h>
+int lio_wait4asyncio(int method, int fd, struct iosw **statptr);
+int lio_check_asyncio(char *io_type, int size, struct iosw *status);
+#endif /* CRAY */
+#if defined (sgi)
+#include <aio.h>
+int lio_wait4asyncio(int method, int fd, aiocb_t *aiocbp);
+int lio_check_asyncio(char *io_type, int size, aiocb_t *aiocbp, int method);
+#endif /* sgi */
+#if defined(__linux__) && !defined(__UCLIBC__)
+#include <aio.h>
+int lio_wait4asyncio(int method, int fd, struct aiocb *aiocbp);
+int lio_check_asyncio(char *io_type, int size, struct aiocb *aiocbp, int method);
+#endif
+
+/*
+ * Define the structure that contains the infomation that is used
+ * by the parsing and help functions.
+ */
+struct lio_info_type {
+ char *token;
+ int bits;
+ char *desc;
+};
+
+
diff --git a/kernel/tests/include/old/usctest.h b/kernel/tests/include/old/usctest.h
new file mode 100644
index 0000000..9b9446d
--- /dev/null
+++ b/kernel/tests/include/old/usctest.h
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
+ * Author: William Roske
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it is
+ * free of the rightful claim of any third person regarding infringement
+ * or the like. Any license provided herein, whether implied or
+ * otherwise, applies only to this software file. Patent licenses, if
+ * any, provided herein do not apply to combinations of this program with
+ * other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
+ * Mountain View, CA 94043, or:
+ *
+ * http://www.sgi.com
+ *
+ * For further information regarding this notice, see:
+ *
+ * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
+ */
+
+#ifndef __USCTEST_H__
+#define __USCTEST_H__
+
+/*
+ * Ensure that PATH_MAX is defined
+ */
+#ifndef PATH_MAX
+#ifdef MAXPATHLEN
+#define PATH_MAX MAXPATHLEN
+#else
+#define PATH_MAX 1024
+#endif
+#endif
+
+/***********************************************************************
+ * The following globals are defined in parse_opts.c but must be
+ * externed here because they are used in the macros defined below.
+ ***********************************************************************/
+extern int STD_LOOP_COUNT; /* changed by -in to set loop count to n */
+
+extern long TEST_RETURN;
+extern int TEST_ERRNO;
+
+/***********************************************************************
+ * TEST: calls a system call
+ *
+ * parameters:
+ * SCALL = system call and parameters to execute
+ *
+ ***********************************************************************/
+#define TEST(SCALL) \
+ do { \
+ errno = 0; \
+ TEST_RETURN = SCALL; \
+ TEST_ERRNO = errno; \
+ } while (0)
+
+/***********************************************************************
+ * TEST_VOID: calls a system call
+ *
+ * parameters:
+ * SCALL = system call and parameters to execute
+ *
+ * Note: This is IDENTICAL to the TEST() macro except that it is intended
+ * for use with syscalls returning no values (void syscall()). The
+ * Typecasting nothing (void) into an unsigned integer causes compilation
+ * errors.
+ *
+ ***********************************************************************/
+#define TEST_VOID(SCALL) do { errno = 0; SCALL; TEST_ERRNO = errno; } while (0)
+
+/***********************************************************************
+ * TEST_PAUSE: Pause for SIGUSR1 if the pause flag is set.
+ * Just continue when signal comes in.
+ *
+ * parameters:
+ * none
+ *
+ ***********************************************************************/
+#define TEST_PAUSE usc_global_setup_hook();
+int usc_global_setup_hook();
+
+/***********************************************************************
+ * TEST_LOOPING now call the usc_test_looping function.
+ * The function will return 1 if the test should continue
+ * iterating.
+ *
+ ***********************************************************************/
+#define TEST_LOOPING usc_test_looping
+int usc_test_looping(int counter);
+
+#endif /* __USCTEST_H__ */
diff --git a/kernel/tests/include/parse_vdso.h b/kernel/tests/include/parse_vdso.h
new file mode 100644
index 0000000..5212fc6
--- /dev/null
+++ b/kernel/tests/include/parse_vdso.h
@@ -0,0 +1,41 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Linaro Limited. All rights reserved.
+ * Author: Viresh Kumar <viresh.kumar@linaro.org>
+ */
+
+#ifndef PARSE_VDSO_H__
+#define PARSE_VDSO_H__
+
+#include <stdint.h>
+
+/*
+ * To use this vDSO parser, first call one of the vdso_init_* functions.
+ * If you've already parsed auxv, then pass the value of AT_SYSINFO_EHDR
+ * to vdso_init_from_sysinfo_ehdr. Otherwise pass auxv to vdso_init_from_auxv.
+ * Then call vdso_sym for each symbol you want. For example, to look up
+ * gettimeofday on x86_64, use:
+ *
+ * <some pointer> = vdso_sym("LINUX_2.6", "gettimeofday");
+ * or
+ * <some pointer> = vdso_sym("LINUX_2.6", "__vdso_gettimeofday");
+ *
+ * vdso_sym will return 0 if the symbol doesn't exist or if the init function
+ * failed or was not called. vdso_sym is a little slow, so its return value
+ * should be cached.
+ *
+ * vdso_sym is threadsafe; the init functions are not.
+ *
+ * These are the prototypes:
+ */
+
+#include <time.h>
+
+extern void vdso_init_from_auxv(void *auxv);
+extern void vdso_init_from_sysinfo_ehdr(uintptr_t base);
+extern void *vdso_sym(const char *version, const char *name);
+
+typedef int (*gettime_t)(clockid_t clk_id, void *ts);
+void find_clock_gettime_vdso(gettime_t *ptr_vdso_gettime,
+ gettime_t *ptr_vdso_gettime64);
+#endif /* PARSE_VDSO_H__ */
diff --git a/kernel/tests/include/safe_file_ops_fn.h b/kernel/tests/include/safe_file_ops_fn.h
new file mode 100644
index 0000000..052fb1b
--- /dev/null
+++ b/kernel/tests/include/safe_file_ops_fn.h
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2012-2016 Cyril Hrubis <chrubis@suse.cz>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef SAFE_FILE_OPS_FN
+#define SAFE_FILE_OPS_FN
+
+#include <sys/stat.h>
+#include <time.h>
+
+#include "lapi/utime.h"
+
+/*
+ * All-in-one function to scanf value(s) from a file.
+ */
+int file_scanf(const char *file, const int lineno,
+ const char *path, const char *fmt, ...)
+ __attribute__ ((format (scanf, 4, 5)));
+
+void safe_file_scanf(const char *file, const int lineno,
+ void (*cleanup_fn)(void),
+ const char *path, const char *fmt, ...)
+ __attribute__ ((format (scanf, 5, 6)));
+
+int file_lines_scanf(const char *file, const int lineno,
+ void (*cleanup_fn)(void), int strict,
+ const char *path, const char *fmt, ...)
+ __attribute__ ((format (scanf, 6, 7)));
+
+/*
+ * All-in-one function that lets you printf directly into a file.
+ */
+int file_printf(const char *file, const int lineno,
+ const char *path, const char *fmt, ...)
+ __attribute__ ((format (printf, 4, 5)));
+
+void safe_file_printf(const char *file, const int lineno,
+ void (*cleanup_fn)(void),
+ const char *path, const char *fmt, ...)
+ __attribute__ ((format (printf, 5, 6)));
+
+/*
+ * Safe function to copy files, no more system("cp ...") please.
+ */
+void safe_cp(const char *file, const int lineno,
+ void (*cleanup_fn)(void),
+ const char *src, const char *dst);
+
+/*
+ * Safe function to touch a file.
+ *
+ * If the file (pathname) does not exist It will be created with
+ * the specified permission (mode) and the access/modification times (times).
+ *
+ * If mode is 0 then the file is created with (0666 & ~umask)
+ * permission or (if the file exists) the permission is not changed.
+ *
+ * times is a timespec[2] (as for utimensat(2)). If times is NULL then
+ * the access/modification times of the file is set to the current time.
+ */
+void safe_touch(const char *file, const int lineno,
+ void (*cleanup_fn)(void),
+ const char *pathname,
+ mode_t mode, const struct timespec times[2]);
+
+/* helper functions to setup overlayfs mountpoint */
+void create_overlay_dirs(void);
+int mount_overlay(const char *file, const int lineno, int skip);
+
+#endif /* SAFE_FILE_OPS_FN */
diff --git a/kernel/tests/include/safe_macros_fn.h b/kernel/tests/include/safe_macros_fn.h
new file mode 100644
index 0000000..3df9528
--- /dev/null
+++ b/kernel/tests/include/safe_macros_fn.h
@@ -0,0 +1,187 @@
+/*
+ * Safe macros for commonly used syscalls to reduce code duplication in LTP
+ * testcases, and to ensure all errors are caught in said testcases as
+ * gracefully as possible.
+ *
+ * Also satiates some versions of gcc/glibc when the warn_unused_result
+ * attribute is applied to the function call.
+ *
+ * Licensed under the GPLv2.
+ */
+
+#ifndef SAFE_MACROS_FN_H__
+#define SAFE_MACROS_FN_H__
+
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <libgen.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <dirent.h>
+
+char* safe_basename(const char *file, const int lineno,
+ void (*cleanup_fn)(void), char *path);
+
+int safe_chdir(const char *file, const int lineno,
+ void (*cleanup_fn)(void), const char *path);
+
+int safe_close(const char *file, const int lineno,
+ void (*cleanup_fn)(void), int fildes);
+
+int safe_creat(const char *file, const int lineno,
+ void (*cleanup_fn)(void), const char *pathname, mode_t mode);
+
+char* safe_dirname(const char *file, const int lineno,
+ void (*cleanup_fn)(void), char *path);
+
+char* safe_getcwd(const char *file, const int lineno,
+ void (*cleanup_fn)(void), char *buf, size_t size);
+
+struct passwd* safe_getpwnam(const char *file, const int lineno,
+ void (*cleanup_fn)(void), const char *name);
+
+int safe_getrusage(const char *file, const int lineno,
+ void (*cleanup_fn)(void), int who, struct rusage *usage);
+
+void* safe_malloc(const char *file, const int lineno,
+ void (*cleanup_fn)(void), size_t size);
+
+int safe_mkdir(const char *file, const int lineno,
+ void (*cleanup_fn)(void), const char *pathname, mode_t mode);
+
+int safe_rmdir(const char *file, const int lineno,
+ void (*cleanup_fn)(void), const char *pathname);
+
+
+int safe_munmap(const char *file, const int lineno,
+ void (*cleanup_fn)(void), void *addr, size_t length);
+
+int safe_open(const char *file, const int lineno,
+ void (*cleanup_fn)(void), const char *pathname, int oflags, ...);
+
+int safe_pipe(const char *file, const int lineno,
+ void (*cleanup_fn)(void), int fildes[2]);
+
+ssize_t safe_read(const char *file, const int lineno,
+ void (*cleanup_fn)(void), char len_strict, int fildes,
+ void *buf, size_t nbyte);
+
+int safe_setegid(const char *file, const int lineno,
+ void (*cleanup_fn)(void), gid_t egid);
+
+int safe_seteuid(const char *file, const int lineno,
+ void (*cleanup_fn)(void), uid_t euid);
+
+int safe_setgid(const char *file, const int lineno,
+ void (*cleanup_fn)(void), gid_t gid);
+
+int safe_setuid(const char *file, const int lineno,
+ void (*cleanup_fn)(void), uid_t uid);
+
+int safe_getresuid(const char *file, const int lineno,
+ void (*cleanup_fn)(void),
+ uid_t *ruid, uid_t *euid, uid_t *suid);
+
+int safe_getresgid(const char *file, const int lineno,
+ void (*cleanup_fn)(void),
+ gid_t *rgid, gid_t *egid, gid_t *sgid);
+
+int safe_unlink(const char *file, const int lineno,
+ void (*cleanup_fn)(void), const char *pathname);
+
+int safe_link(const char *file, const int lineno,
+ void (cleanup_fn)(void), const char *oldpath,
+ const char *newpath);
+
+int safe_linkat(const char *file, const int lineno,
+ void (cleanup_fn)(void), int olddirfd, const char *oldpath,
+ int newdirfd, const char *newpath, int flags);
+
+ssize_t safe_readlink(const char *file, const int lineno,
+ void (cleanup_fn)(void), const char *path,
+ char *buf, size_t bufsize);
+
+int safe_symlink(const char *file, const int lineno,
+ void (cleanup_fn)(void), const char *oldpath,
+ const char *newpath);
+
+ssize_t safe_write(const char *file, const int lineno,
+ void (cleanup_fn)(void), char len_strict, int fildes,
+ const void *buf, size_t nbyte);
+
+long safe_strtol(const char *file, const int lineno,
+ void (cleanup_fn)(void), char *str, long min, long max);
+
+unsigned long safe_strtoul(const char *file, const int lineno,
+ void (cleanup_fn)(void),
+ char *str, unsigned long min, unsigned long max);
+
+long safe_sysconf(const char *file, const int lineno,
+ void (cleanup_fn)(void), int name);
+
+int safe_chmod(const char *file, const int lineno, void (cleanup_fn)(void),
+ const char *path, mode_t mode);
+
+int safe_fchmod(const char *file, const int lineno, void (cleanup_fn)(void),
+ int fd, mode_t mode);
+
+int safe_chown(const char *file, const int lineno, void (cleanup_fn)(void),
+ const char *path, uid_t owner, gid_t group);
+
+int safe_fchown(const char *file, const int lineno, void (cleanup_fn)(void),
+ int fd, uid_t owner, gid_t group);
+
+pid_t safe_wait(const char *file, const int lineno, void (cleanup_fn)(void),
+ int *status);
+
+pid_t safe_waitpid(const char *file, const int lineno, void (cleanup_fn)(void),
+ pid_t pid, int *status, int opts);
+
+int safe_kill(const char *file, const int lineno, void (cleanup_fn)(void),
+ pid_t pid, int sig);
+
+void *safe_memalign(const char *file, const int lineno,
+ void (*cleanup_fn)(void), size_t alignment, size_t size);
+
+int safe_mkfifo(const char *file, const int lineno,
+ void (*cleanup_fn)(void), const char *pathname, mode_t mode);
+
+int safe_rename(const char *file, const int lineno, void (*cleanup_fn)(void),
+ const char *oldpath, const char *newpath);
+
+int safe_mount(const char *file, const int lineno, void (*cleanup_fn)(void),
+ const char *source, const char *target,
+ const char *filesystemtype, unsigned long mountflags,
+ const void *data);
+
+int safe_umount(const char *file, const int lineno, void (*cleanup_fn)(void),
+ const char *target);
+
+DIR* safe_opendir(const char *file, const int lineno, void (cleanup_fn)(void),
+ const char *name);
+
+int safe_closedir(const char *file, const int lineno, void (cleanup_fn)(void),
+ DIR *dirp);
+
+struct dirent *safe_readdir(const char *file, const int lineno,
+ void (cleanup_fn)(void),
+ DIR *dirp);
+
+DIR* safe_opendir(const char *file, const int lineno,
+ void (cleanup_fn)(void),
+ const char *name);
+
+struct dirent *safe_readdir(const char *file, const int lineno,
+ void (cleanup_fn)(void),
+ DIR *dirp);
+
+int safe_closedir(const char *file, const int lineno,
+ void (cleanup_fn)(void),
+ DIR *dirp);
+
+#endif /* SAFE_MACROS_FN_H__ */
diff --git a/kernel/tests/include/safe_net_fn.h b/kernel/tests/include/safe_net_fn.h
new file mode 100644
index 0000000..2fda11f
--- /dev/null
+++ b/kernel/tests/include/safe_net_fn.h
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
+ * Copyright (c) 2015 Fujitsu Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef SAFE_NET_FN_H__
+#define SAFE_NET_FN_H__
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <sys/un.h>
+
+int safe_socket(const char *file, const int lineno, void (cleanup_fn)(void),
+ int domain, int type, int protocol);
+
+int safe_socketpair(const char *file, const int lineno, int domain, int type,
+ int protocol, int sv[]);
+
+int safe_getsockopt(const char *file, const int lineno, int sockfd, int level,
+ int optname, void *optval, socklen_t *optlen);
+
+int safe_setsockopt(const char *file, const int lineno, int sockfd, int level,
+ int optname, const void *optval, socklen_t optlen);
+
+ssize_t safe_send(const char *file, const int lineno, char len_strict,
+ int sockfd, const void *buf, size_t len, int flags);
+
+ssize_t safe_sendto(const char *file, const int lineno, char len_strict,
+ int sockfd, const void *buf, size_t len, int flags,
+ const struct sockaddr *dest_addr, socklen_t addrlen);
+
+ssize_t safe_sendmsg(const char *file, const int lineno, size_t msg_len,
+ int sockfd, const struct msghdr *msg, int flags);
+
+ssize_t safe_recvmsg(const char *file, const int lineno, size_t msg_len,
+ int sockfd, struct msghdr *msg, int flags);
+
+int safe_bind(const char *file, const int lineno, void (cleanup_fn)(void),
+ int socket, const struct sockaddr *address,
+ socklen_t address_len);
+
+int safe_listen(const char *file, const int lineno, void (cleanup_fn)(void),
+ int socket, int backlog);
+
+int safe_accept(const char *file, const int lineno, void (cleanup_fn)(void),
+ int sockfd, struct sockaddr *addr, socklen_t *addrlen);
+
+int safe_connect(const char *file, const int lineno, void (cleanup_fn)(void),
+ int sockfd, const struct sockaddr *addr, socklen_t addrlen);
+
+int safe_getsockname(const char *file, const int lineno,
+ void (cleanup_fn)(void), int sockfd, struct sockaddr *addr,
+ socklen_t *addrlen);
+
+int safe_gethostname(const char *file, const int lineno,
+ char *name, size_t size);
+
+int tst_getsockport(const char *file, const int lineno, int sockfd);
+
+unsigned short tst_get_unused_port(const char *file, const int lineno,
+ void (cleanup_fn)(void), unsigned short family, int type);
+
+char *tst_sock_addr(const struct sockaddr *sa, socklen_t salen, char *res,
+ size_t len);
+
+#endif /* SAFE_NET_FN_H__ */
diff --git a/kernel/tests/include/safe_stdio_fn.h b/kernel/tests/include/safe_stdio_fn.h
new file mode 100644
index 0000000..3818a86
--- /dev/null
+++ b/kernel/tests/include/safe_stdio_fn.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2013-2016 Cyril Hrubis <chrubis@suse.cz>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef SAFE_STDIO_FN_H__
+#define SAFE_STDIO_FN_H__
+
+#include <stdio.h>
+
+FILE *safe_fopen(const char *file, const int lineno, void (cleanup_fn)(void),
+ const char *path, const char *mode);
+
+int safe_fclose(const char *file, const int lineno, void (cleanup_fn)(void),
+ FILE *f);
+
+int safe_asprintf(const char *file, const int lineno, void (cleanup_fn)(void),
+ char **strp, const char *fmt, ...);
+
+FILE *safe_popen(const char *file, const int lineno, void (cleanup_fn)(void),
+ const char *command, const char *type);
+
+#endif /* SAFE_STDIO_FN_H__ */
diff --git a/kernel/tests/include/tst_af_alg.h b/kernel/tests/include/tst_af_alg.h
new file mode 100644
index 0000000..fd2ff06
--- /dev/null
+++ b/kernel/tests/include/tst_af_alg.h
@@ -0,0 +1,168 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright 2019 Google LLC
+ */
+/**
+ * @file tst_af_alg.h
+ *
+ * Library for accessing kernel crypto algorithms via AF_ALG.
+ *
+ * See https://www.kernel.org/doc/html/latest/crypto/userspace-if.html
+ * for more information about AF_ALG.
+ */
+
+#ifndef TST_AF_ALG_H
+#define TST_AF_ALG_H
+
+#include "lapi/if_alg.h"
+#include <stdbool.h>
+
+/**
+ * Create an AF_ALG algorithm socket.
+ *
+ * This creates an AF_ALG algorithm socket that is initially not bound to any
+ * particular algorithm. On failure, tst_brk() is called with TCONF if the
+ * kernel doesn't support AF_ALG, otherwise TBROK.
+ *
+ * @return a new AF_ALG algorithm socket
+ */
+int tst_alg_create(void);
+
+/**
+ * Bind an AF_ALG algorithm socket to an algorithm.
+ *
+ * @param algfd An AF_ALG algorithm socket
+ * @param addr A structure which specifies the algorithm to use
+ *
+ * On failure, tst_brk() is called with TCONF if the kernel doesn't support the
+ * specified algorithm, otherwise TBROK.
+ */
+void tst_alg_bind_addr(int algfd, const struct sockaddr_alg *addr);
+
+/**
+ * Bind an AF_ALG algorithm socket to an algorithm.
+ *
+ * @param algfd An AF_ALG algorithm socket
+ * @param algtype The type of algorithm, such as "hash" or "skcipher"
+ * @param algname The name of the algorithm, such as "sha256" or "xts(aes)"
+ *
+ * Like tst_alg_bind_addr(), except this just takes in the algorithm type and
+ * name. The 'feat' and 'mask' fields are left 0.
+ *
+ * On failure, tst_brk() is called with TCONF if the kernel doesn't support the
+ * specified algorithm, otherwise TBROK.
+ */
+void tst_alg_bind(int algfd, const char *algtype, const char *algname);
+
+/**
+ * Check for the availability of an algorithm.
+ *
+ * @param algtype The type of algorithm, such as "hash" or "skcipher"
+ * @param algname The name of the algorithm, such as "sha256" or "xts(aes)"
+ *
+ * Return true if the algorithm is available, or false if unavailable.
+ * If another error occurs, tst_brk() is called with TBROK.
+ */
+bool tst_have_alg(const char *algtype, const char *algname);
+
+/**
+ * Require the availability of an algorithm.
+ *
+ * @param algtype The type of algorithm, such as "hash" or "skcipher"
+ * @param algname The name of the algorithm, such as "sha256" or "xts(aes)"
+ *
+ * If the algorithm is unavailable, tst_brk() is called with TCONF.
+ * If another error occurs, tst_brk() is called with TBROK.
+ */
+void tst_require_alg(const char *algtype, const char *algname);
+
+/**
+ * Assign a cryptographic key to an AF_ALG algorithm socket.
+ *
+ * @param algfd An AF_ALG algorithm socket
+ * @param key Pointer to the key. If NULL, a random key is generated.
+ * @param keylen Length of the key in bytes
+ *
+ * On failure, tst_brk() is called with TBROK.
+ */
+void tst_alg_setkey(int algfd, const uint8_t *key, unsigned int keylen);
+
+/**
+ * Create an AF_ALG request socket for the given algorithm socket.
+ *
+ * @param algfd An AF_ALG algorithm socket
+ *
+ * This creates a request socket for the given algorithm socket, which must be
+ * bound to an algorithm. The same algorithm socket can have many request
+ * sockets used concurrently to perform independent cryptographic operations,
+ * e.g. hashing or encryption/decryption. But the key, if any, that has been
+ * assigned to the algorithm is shared by all request sockets.
+ *
+ * On failure, tst_brk() is called with TBROK.
+ *
+ * @return a new AF_ALG request socket
+ */
+int tst_alg_accept(int algfd);
+
+/**
+ * Set up an AF_ALG algorithm socket for the given algorithm w/ given key.
+ *
+ * @param algtype The type of algorithm, such as "hash" or "skcipher"
+ * @param algname The name of the algorithm, such as "sha256" or "xts(aes)"
+ * @param key The key to use (optional)
+ * @param keylen The length of the key in bytes (optional)
+ *
+ * This is a helper function which creates an AF_ALG algorithm socket, binds it
+ * to the specified algorithm, and optionally sets a key. If keylen is 0 then
+ * no key is set; otherwise if key is NULL a key of the given length is randomly
+ * generated and set; otherwise the given key is set.
+ *
+ * @return the AF_ALG algorithm socket that was set up
+ */
+int tst_alg_setup(const char *algtype, const char *algname,
+ const uint8_t *key, unsigned int keylen);
+
+/**
+ * Set up an AF_ALG request socket for the given algorithm w/ given key.
+ *
+ * This is like tst_alg_setup(), except this returns a request fd instead of the
+ * alg fd. The alg fd is closed, so it doesn't need to be kept track of.
+ *
+ * @return the AF_ALG request socket that was set up
+ */
+int tst_alg_setup_reqfd(const char *algtype, const char *algname,
+ const uint8_t *key, unsigned int keylen);
+
+/** Specification of control data to send to an AF_ALG request socket */
+struct tst_alg_sendmsg_params {
+
+ /** If true, send ALG_SET_OP with ALG_OP_ENCRYPT */
+ bool encrypt;
+
+ /** If true, send ALG_SET_OP with ALG_OP_DECRYPT */
+ bool decrypt;
+
+ /** If ivlen != 0, send ALG_SET_IV */
+ const uint8_t *iv;
+ unsigned int ivlen;
+
+ /** If assoclen != 0, send ALG_SET_AEAD_ASSOCLEN */
+ unsigned int assoclen;
+
+ /* Value to use as msghdr::msg_flags */
+ uint32_t msg_flags;
+};
+
+/**
+ * Send some data to an AF_ALG request socket, including control data.
+ * @param reqfd An AF_ALG request socket
+ * @param data The data to send
+ * @param datalen The length of data in bytes
+ * @param params Specification of the control data to send
+ *
+ * On failure, tst_brk() is called with TBROK.
+ */
+void tst_alg_sendmsg(int reqfd, const void *data, size_t datalen,
+ const struct tst_alg_sendmsg_params *params);
+
+#endif /* TST_AF_ALG_H */
diff --git a/kernel/tests/include/tst_ansi_color.h b/kernel/tests/include/tst_ansi_color.h
new file mode 100644
index 0000000..770bf46
--- /dev/null
+++ b/kernel/tests/include/tst_ansi_color.h
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
+ */
+
+#ifndef TST_ANSI_COLOR_H__
+#define TST_ANSI_COLOR_H__
+/*
+ * NOTE: these colors should match colors defined in tst_flag2color() in
+ * testcases/lib/tst_ansi_color.sh
+ */
+#define ANSI_COLOR_BLUE "\033[1;34m"
+#define ANSI_COLOR_GREEN "\033[1;32m"
+#define ANSI_COLOR_MAGENTA "\033[1;35m"
+#define ANSI_COLOR_RED "\033[1;31m"
+#define ANSI_COLOR_YELLOW "\033[1;33m"
+
+#define ANSI_COLOR_RESET "\033[0m"
+
+char* tst_ttype2color(int ttype);
+int tst_color_enabled(int fd);
+
+#endif /* TST_ANSI_COLOR_H__ */
diff --git a/kernel/tests/include/tst_assert.h b/kernel/tests/include/tst_assert.h
new file mode 100644
index 0000000..dcb62df
--- /dev/null
+++ b/kernel/tests/include/tst_assert.h
@@ -0,0 +1,65 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
+ * Copyright (c) 2020 Cyril Hrubis <chrubis@suse.cz>
+ */
+#ifndef TST_ASSERT_H__
+#define TST_ASSERT_H__
+
+#define TST_ASSERT_INT(path, val) \
+ tst_assert_int(__FILE__, __LINE__, path, val)
+
+/*
+ * Asserts that integer value stored in file pointed by path equals to the
+ * value passed to this function. This is mostly useful for asserting correct
+ * values in sysfs, procfs, etc.
+ */
+void tst_assert_int(const char *file, const int lineno,
+ const char *path, int val);
+
+#define TST_ASSERT_FILE_INT(path, prefix, val) \
+ tst_assert_file_int(__FILE__, __LINE__, path, prefix, val)
+
+/*
+ * Same as tst_assert_int() but for unsigned long.
+ */
+void tst_assert_ulong(const char *file, const int lineno,
+ const char *path, unsigned long val);
+
+#define TST_ASSERT_ULONG(path, val) \
+ tst_assert_ulong(__FILE__, __LINE__, path, val)
+
+/*
+ * Asserts that integer value stored in the prefix field of file pointed by path
+ * equals to the value passed to this function. This is mostly useful for
+ * asserting correct field values in sysfs, procfs, etc.
+ */
+
+void tst_assert_file_int(const char *file, const int lineno,
+ const char *path, const char *prefix, int val);
+
+
+#define TST_ASSERT_STR(path, val) \
+ tst_assert_str(__FILE__, __LINE__, path, val)
+
+/*
+ * Asserts that a string value stored in file pointed by path equals to the
+ * value passed to this function. This is mostly useful for asserting correct
+ * values in sysfs, procfs, etc.
+ */
+void tst_assert_str(const char *file, const int lineno,
+ const char *path, const char *val);
+
+#define TST_ASSERT_FILE_STR(path, prefix, val) \
+ tst_assert_file_str(__FILE__, __LINE__, path, prefix, val)
+
+/*
+ * Asserts that a string value stored in the prefix field of file pointed by path
+ * equals to the value passed to this function. This is mostly useful for
+ * asserting correct field values in sysfs, procfs, etc.
+ */
+void tst_assert_file_str(const char *file, const int lineno,
+ const char *path, const char *prefix, const char *val);
+
+#endif /* TST_ASSERT_H__ */
diff --git a/kernel/tests/include/tst_atomic.h b/kernel/tests/include/tst_atomic.h
new file mode 100644
index 0000000..061cd3d
--- /dev/null
+++ b/kernel/tests/include/tst_atomic.h
@@ -0,0 +1,334 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+/* The LTP library has some of its own atomic synchronisation primitives
+ * contained in this file. Generally speaking these should not be used
+ * directly in tests for synchronisation, instead use tst_checkpoint.h,
+ * tst_fuzzy_sync.h or the POSIX library.
+ *
+ * Notes on compile and runtime memory barriers and atomics.
+ *
+ * Within the LTP library we have three concerns when accessing variables
+ * shared by multiple threads or processes:
+ *
+ * (1) Removal or reordering of accesses by the compiler.
+ * (2) Atomicity of addition.
+ * (3) LOAD-STORE ordering between threads.
+ *
+ * The first (1) is the most likely to cause an error if not properly
+ * handled. We avoid it by using volatile variables and statements which will
+ * not be removed or reordered by the compiler during optimisation. This includes
+ * the __atomic and __sync intrinsics and volatile asm statements marked with
+ * "memory" as well as variables marked with volatile.
+ *
+ * On any platform Linux is likely to run on, a LOAD (fetch) or STORE of a
+ * 32-bit integer will be atomic. However fetching and adding to a variable is
+ * quite likely not; so for (2) we need to ensure we use atomic addition.
+ *
+ * Finally, for tst_fuzzy_sync at least, we need to ensure that LOADs and
+ * STOREs of any shared variables (including non-atomics) that are made
+ * between calls to tst_fzsync_wait are completed (globally visible) before
+ * tst_fzsync_wait completes. For this, runtime memory and instruction
+ * barriers are required in addition to compile time.
+ *
+ * We use full sequential ordering (__ATOMIC_SEQ_CST) for the sake of
+ * simplicity. LTP tests tend to be syscall heavy so any performance gain from
+ * using a weaker memory model is unlikely to result in a relatively large
+ * performance improvement while at the same time being a potent source of
+ * confusion.
+ *
+ * Likewise, for the fallback ASM, the simplest "definitely will work, always"
+ * approach is preferred over anything more performant.
+ *
+ * Also see Documentation/memory-barriers.txt in the kernel tree and
+ * https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html
+ * terminology may vary between sources.
+ */
+
+#ifndef TST_ATOMIC_H__
+#define TST_ATOMIC_H__
+
+#include "config.h"
+
+#if HAVE_ATOMIC_MEMORY_MODEL == 1
+static inline int tst_atomic_add_return(int i, int *v)
+{
+ return __atomic_add_fetch(v, i, __ATOMIC_SEQ_CST);
+}
+
+static inline int tst_atomic_load(int *v)
+{
+ return __atomic_load_n(v, __ATOMIC_SEQ_CST);
+}
+
+static inline void tst_atomic_store(int i, int *v)
+{
+ __atomic_store_n(v, i, __ATOMIC_SEQ_CST);
+}
+
+#elif HAVE_SYNC_ADD_AND_FETCH == 1
+static inline int tst_atomic_add_return(int i, int *v)
+{
+ return __sync_add_and_fetch(v, i);
+}
+
+static inline int tst_atomic_load(int *v)
+{
+ int ret;
+
+ __sync_synchronize();
+ ret = *v;
+ __sync_synchronize();
+ return ret;
+}
+
+static inline void tst_atomic_store(int i, int *v)
+{
+ __sync_synchronize();
+ *v = i;
+ __sync_synchronize();
+}
+
+#elif defined(__i386__) || defined(__x86_64__)
+# define LTP_USE_GENERIC_LOAD_STORE_ASM 1
+
+static inline int tst_atomic_add_return(int i, int *v)
+{
+ int __ret = i;
+
+ /*
+ * taken from arch/x86/include/asm/cmpxchg.h
+ */
+ asm volatile ("lock; xaddl %0, %1\n"
+ : "+r" (__ret), "+m" (*v) : : "memory", "cc");
+
+ return i + __ret;
+}
+
+#elif defined(__powerpc__) || defined(__powerpc64__)
+static inline int tst_atomic_add_return(int i, int *v)
+{
+ int t;
+
+ /* taken from arch/powerpc/include/asm/atomic.h */
+ asm volatile(
+ " sync\n"
+ "1: lwarx %0,0,%2 # atomic_add_return\n"
+ " add %0,%1,%0\n"
+ " stwcx. %0,0,%2 \n"
+ " bne- 1b\n"
+ " sync\n"
+ : "=&r" (t)
+ : "r" (i), "r" (v)
+ : "cc", "memory");
+
+ return t;
+}
+
+static inline int tst_atomic_load(int *v)
+{
+ int ret;
+
+ asm volatile("sync\n" : : : "memory");
+ ret = *v;
+ asm volatile("sync\n" : : : "memory");
+
+ return ret;
+}
+
+static inline void tst_atomic_store(int i, int *v)
+{
+ asm volatile("sync\n" : : : "memory");
+ *v = i;
+ asm volatile("sync\n" : : : "memory");
+}
+
+#elif defined(__s390__) || defined(__s390x__)
+# define LTP_USE_GENERIC_LOAD_STORE_ASM 1
+
+static inline int tst_atomic_add_return(int i, int *v)
+{
+ int old_val, new_val;
+
+ /* taken from arch/s390/include/asm/atomic.h */
+ asm volatile(
+ " l %0,%2\n"
+ "0: lr %1,%0\n"
+ " ar %1,%3\n"
+ " cs %0,%1,%2\n"
+ " jl 0b"
+ : "=&d" (old_val), "=&d" (new_val), "+Q" (*v)
+ : "d" (i)
+ : "cc", "memory");
+
+ return old_val + i;
+}
+
+#elif defined(__arc__)
+
+/*ARCv2 defines the smp barriers */
+#ifdef __ARC700__
+#define smp_mb() asm volatile("" : : : "memory")
+#else
+#define smp_mb() asm volatile("dmb 3\n" : : : "memory")
+#endif
+
+static inline int tst_atomic_add_return(int i, int *v)
+{
+ unsigned int val;
+
+ smp_mb();
+
+ asm volatile(
+ "1: llock %[val], [%[ctr]] \n"
+ " add %[val], %[val], %[i] \n"
+ " scond %[val], [%[ctr]] \n"
+ " bnz 1b \n"
+ : [val] "=&r" (val)
+ : [ctr] "r" (v),
+ [i] "ir" (i)
+ : "cc", "memory");
+
+ smp_mb();
+
+ return val;
+}
+
+static inline int tst_atomic_load(int *v)
+{
+ int ret;
+
+ smp_mb();
+ ret = *v;
+ smp_mb();
+
+ return ret;
+}
+
+static inline void tst_atomic_store(int i, int *v)
+{
+ smp_mb();
+ *v = i;
+ smp_mb();
+}
+
+#elif defined (__aarch64__)
+static inline int tst_atomic_add_return(int i, int *v)
+{
+ unsigned long tmp;
+ int result;
+
+ __asm__ __volatile__(
+" prfm pstl1strm, %2 \n"
+"1: ldaxr %w0, %2 \n"
+" add %w0, %w0, %w3 \n"
+" stlxr %w1, %w0, %2 \n"
+" cbnz %w1, 1b \n"
+" dmb ish \n"
+ : "=&r" (result), "=&r" (tmp), "+Q" (*v)
+ : "Ir" (i)
+ : "memory");
+
+ return result;
+}
+
+/* We are using load and store exclusive (ldaxr & stlxr) instructions to try
+ * and help prevent the tst_atomic_load and, more likely, tst_atomic_store
+ * functions from interfering with tst_atomic_add_return which takes advantage
+ * of exclusivity. It is not clear if this is a good idea or not, but does
+ * mean that all three functions are very similar.
+ */
+static inline int tst_atomic_load(int *v)
+{
+ int ret;
+ unsigned long tmp;
+
+ asm volatile("//atomic_load \n"
+ " prfm pstl1strm, %[v] \n"
+ "1: ldaxr %w[ret], %[v] \n"
+ " stlxr %w[tmp], %w[ret], %[v] \n"
+ " cbnz %w[tmp], 1b \n"
+ " dmb ish \n"
+ : [tmp] "=&r" (tmp), [ret] "=&r" (ret), [v] "+Q" (*v)
+ : : "memory");
+
+ return ret;
+}
+
+static inline void tst_atomic_store(int i, int *v)
+{
+ unsigned long tmp;
+
+ asm volatile("//atomic_store \n"
+ " prfm pstl1strm, %[v] \n"
+ "1: ldaxr %w[tmp], %[v] \n"
+ " stlxr %w[tmp], %w[i], %[v] \n"
+ " cbnz %w[tmp], 1b \n"
+ " dmb ish \n"
+ : [tmp] "=&r" (tmp), [v] "+Q" (*v)
+ : [i] "r" (i)
+ : "memory");
+}
+
+#elif defined(__sparc__) && defined(__arch64__)
+# define LTP_USE_GENERIC_LOAD_STORE_ASM 1
+static inline int tst_atomic_add_return(int i, int *v)
+{
+ int ret, tmp;
+
+ /* Based on arch/sparc/lib/atomic_64.S with the exponential backoff
+ * function removed because we are unlikely to have a large (>= 16?)
+ * number of cores continuously trying to update one variable.
+ */
+ asm volatile("/*atomic_add_return*/ \n"
+ "1: ldsw [%[v]], %[ret]; \n"
+ " add %[ret], %[i], %[tmp]; \n"
+ " cas [%[v]], %[ret], %[tmp]; \n"
+ " cmp %[ret], %[tmp]; \n"
+ " bne,pn %%icc, 1b; \n"
+ " nop; \n"
+ " add %[ret], %[i], %[ret]; \n"
+ : [ret] "=r&" (ret), [tmp] "=r&" (tmp)
+ : [i] "r" (i), [v] "r" (v)
+ : "memory", "cc");
+
+ return ret;
+}
+
+#else /* HAVE_SYNC_ADD_AND_FETCH == 1 */
+# error Your compiler does not provide __atomic_add_fetch, __sync_add_and_fetch \
+ and an LTP implementation is missing for your architecture.
+#endif
+
+#ifdef LTP_USE_GENERIC_LOAD_STORE_ASM
+static inline int tst_atomic_load(int *v)
+{
+ int ret;
+
+ asm volatile("" : : : "memory");
+ ret = *v;
+ asm volatile("" : : : "memory");
+
+ return ret;
+}
+
+static inline void tst_atomic_store(int i, int *v)
+{
+ asm volatile("" : : : "memory");
+ *v = i;
+ asm volatile("" : : : "memory");
+}
+#endif
+
+static inline int tst_atomic_inc(int *v)
+{
+ return tst_atomic_add_return(1, v);
+}
+
+static inline int tst_atomic_dec(int *v)
+{
+ return tst_atomic_add_return(-1, v);
+}
+
+#endif /* TST_ATOMIC_H__ */
diff --git a/kernel/tests/include/tst_buffers.h b/kernel/tests/include/tst_buffers.h
new file mode 100644
index 0000000..d19ac8c
--- /dev/null
+++ b/kernel/tests/include/tst_buffers.h
@@ -0,0 +1,63 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#ifndef TST_BUFFERS_H__
+#define TST_BUFFERS_H__
+
+/*
+ * Buffer description consist of a pointer to a pointer and buffer type/size
+ * encoded as a different structure members.
+ *
+ * Only one of the size and iov_sizes can be set at a time.
+ */
+struct tst_buffers {
+ /*
+ * This pointer points to a buffer pointer.
+ */
+ void *ptr;
+ /*
+ * Buffer size.
+ */
+ size_t size;
+ /*
+ * Array of iov buffer sizes terminated by -1.
+ */
+ int *iov_sizes;
+};
+
+/*
+ * Allocates buffers based on the tst_buffers structure.
+ *
+ * @bufs NULL terminated array of test buffer descriptions.
+ *
+ * This is called from the test library if the tst_test->bufs pointer is set.
+ */
+void tst_buffers_alloc(struct tst_buffers bufs[]);
+
+/*
+ * strdup() that callls tst_alloc().
+ */
+char *tst_strdup(const char *str);
+
+/*
+ * Allocates size bytes, returns pointer to the allocated buffer.
+ */
+void *tst_alloc(size_t size);
+
+/*
+ * Allocates iovec structure including the buffers.
+ *
+ * @sizes -1 terminated array of buffer sizes.
+ */
+struct iovec *tst_iovec_alloc(int sizes[]);
+
+/*
+ * Frees all allocated buffers.
+ *
+ * This is called at the end of the test automatically.
+ */
+void tst_free_all(void);
+
+#endif /* TST_BUFFERS_H__ */
diff --git a/kernel/tests/include/tst_capability.h b/kernel/tests/include/tst_capability.h
new file mode 100644
index 0000000..6067804
--- /dev/null
+++ b/kernel/tests/include/tst_capability.h
@@ -0,0 +1,83 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (c) 2019 Richard Palethorpe <rpalethorpe@suse.com>
+ */
+/**
+ * @file tst_capability.h
+ *
+ * Limited capability operations without libcap.
+ */
+
+#ifndef TST_CAPABILITY_H
+#define TST_CAPABILITY_H
+
+#include <stdint.h>
+
+#include "lapi/capability.h"
+
+#define TST_CAP_DROP 1
+#define TST_CAP_REQ (1 << 1)
+
+#define TST_CAP(action, capability) {action, capability, #capability}
+
+struct tst_cap_user_header {
+ uint32_t version;
+ int pid;
+};
+
+struct tst_cap_user_data {
+ uint32_t effective;
+ uint32_t permitted;
+ uint32_t inheritable;
+};
+
+struct tst_cap {
+ uint32_t action;
+ uint32_t id;
+ char *name;
+};
+
+/**
+ * Get the capabilities as decided by hdr.
+ *
+ * Note that the memory pointed to by data should be large enough to store two
+ * structs.
+ */
+int tst_capget(struct tst_cap_user_header *hdr,
+ struct tst_cap_user_data *data);
+
+/**
+ * Set the capabilities as decided by hdr and data
+ *
+ * Note that the memory pointed to by data should be large enough to store two
+ * structs.
+ */
+int tst_capset(struct tst_cap_user_header *hdr,
+ const struct tst_cap_user_data *data);
+
+/**
+ * Add, check or remove a capability
+ *
+ * It will attempt to drop or add capability to the effective set. It will
+ * try to detect if this is needed and whether it can or can't be done. If it
+ * clearly can not add a privilege to the effective set then it will return
+ * TCONF. However it may fail for some other reason and return TBROK.
+ *
+ * This only tries to change the effective set. Some tests may need to change
+ * the inheritable and ambient sets, so that child processes retain some
+ * capability.
+ */
+void tst_cap_action(struct tst_cap *cap);
+
+
+/**
+ * Add, check or remove a capabilities
+ *
+ * Takes a NULL terminated array of structs which describe whether some
+ * capabilities are needed or not and mask that determines subset of the
+ * actions to be performed. Loops over the array and if mask matches the
+ * element action it's passed to tst_cap_action().
+ */
+void tst_cap_setup(struct tst_cap *cap, unsigned int action_mask);
+
+#endif /* TST_CAPABILITY_H */
diff --git a/kernel/tests/include/tst_cgroup.h b/kernel/tests/include/tst_cgroup.h
new file mode 100644
index 0000000..77780e0
--- /dev/null
+++ b/kernel/tests/include/tst_cgroup.h
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Red Hat, Inc.
+ * Copyright (c) 2020 Li Wang <liwang@redhat.com>
+ */
+
+#ifndef TST_CGROUP_H
+#define TST_CGROUP_H
+
+#define PATH_TMP_CG_MEM "/tmp/cgroup_mem"
+#define PATH_TMP_CG_CST "/tmp/cgroup_cst"
+
+enum tst_cgroup_ver {
+ TST_CGROUP_V1 = 1,
+ TST_CGROUP_V2 = 2,
+};
+
+enum tst_cgroup_ctrl {
+ TST_CGROUP_MEMCG = 1,
+ TST_CGROUP_CPUSET = 2,
+ /* add cgroup controller */
+};
+
+enum tst_cgroup_ver tst_cgroup_version(void);
+
+/* To mount/umount specified cgroup controller on 'cgroup_dir' path */
+void tst_cgroup_mount(enum tst_cgroup_ctrl ctrl, const char *cgroup_dir);
+void tst_cgroup_umount(const char *cgroup_dir);
+
+/* To move current process PID to the mounted cgroup tasks */
+void tst_cgroup_move_current(const char *cgroup_dir);
+
+/* To set cgroup controller knob with new value */
+void tst_cgroup_set_knob(const char *cgroup_dir, const char *knob, long value);
+
+/* Set of functions to set knobs under the memory controller */
+void tst_cgroup_mem_set_maxbytes(const char *cgroup_dir, long memsz);
+int tst_cgroup_mem_swapacct_enabled(const char *cgroup_dir);
+void tst_cgroup_mem_set_maxswap(const char *cgroup_dir, long memsz);
+
+/* Set of functions to read/write cpuset controller files content */
+void tst_cgroup_cpuset_read_files(const char *cgroup_dir, const char *filename, char *retbuf);
+void tst_cgroup_cpuset_write_files(const char *cgroup_dir, const char *filename, const char *buf);
+
+#endif /* TST_CGROUP_H */
diff --git a/kernel/tests/include/tst_checkpoint.h b/kernel/tests/include/tst_checkpoint.h
new file mode 100644
index 0000000..5c8067d
--- /dev/null
+++ b/kernel/tests/include/tst_checkpoint.h
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#ifndef TST_CHECKPOINT__
+#define TST_CHECKPOINT__
+
+#include "tst_checkpoint_fn.h"
+
+#define TST_CHECKPOINT_WAIT(id) \
+ tst_safe_checkpoint_wait(__FILE__, __LINE__, NULL, id, 0);
+
+#define TST_CHECKPOINT_WAIT2(id, msec_timeout) \
+ tst_safe_checkpoint_wait(__FILE__, __LINE__, NULL, id, msec_timeout);
+
+#define TST_CHECKPOINT_WAKE(id) \
+ tst_safe_checkpoint_wake(__FILE__, __LINE__, NULL, id, 1);
+
+#define TST_CHECKPOINT_WAKE2(id, nr_wake) \
+ tst_safe_checkpoint_wake(__FILE__, __LINE__, NULL, id, nr_wake);
+
+#define TST_CHECKPOINT_WAKE_AND_WAIT(id) \
+ tst_safe_checkpoint_wake(__FILE__, __LINE__, NULL, id, 1); \
+ tst_safe_checkpoint_wait(__FILE__, __LINE__, NULL, id, 0);
+
+extern const char *tst_ipc_path;
+
+#endif /* TST_CHECKPOINT__ */
diff --git a/kernel/tests/include/tst_checkpoint_fn.h b/kernel/tests/include/tst_checkpoint_fn.h
new file mode 100644
index 0000000..57db905
--- /dev/null
+++ b/kernel/tests/include/tst_checkpoint_fn.h
@@ -0,0 +1,42 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2015-2016 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#ifndef TST_CHECKPOINT_FN__
+#define TST_CHECKPOINT_FN__
+
+/*
+ * Checkpoint initializaton, must be done first.
+ *
+ * NOTE: tst_tmpdir() must be called beforehand.
+ */
+void tst_checkpoint_init(const char *file, const int lineno,
+ void (*cleanup_fn)(void));
+
+/*
+ * Waits for wakeup.
+ *
+ * @id: Checkpoint id, possitive number
+ * @msec_timeout: Timeout in milliseconds, 0 == no timeout
+ */
+int tst_checkpoint_wait(unsigned int id, unsigned int msec_timeout);
+
+/*
+ * Wakes up sleeping process(es)/thread(s).
+ *
+ * @id: Checkpoint id, possitive number
+ * @nr_wake: Number of processes/threads to wake up
+ * @msec_timeout: Timeout in milliseconds, 0 == no timeout
+ */
+int tst_checkpoint_wake(unsigned int id, unsigned int nr_wake,
+ unsigned int msec_timeout);
+
+void tst_safe_checkpoint_wait(const char *file, const int lineno,
+ void (*cleanup_fn)(void), unsigned int id,
+ unsigned int msec_timeout);
+
+void tst_safe_checkpoint_wake(const char *file, const int lineno,
+ void (*cleanup_fn)(void), unsigned int id,
+ unsigned int nr_wake);
+
+#endif /* TST_CHECKPOINT_FN__ */
diff --git a/kernel/tests/include/tst_checksum.h b/kernel/tests/include/tst_checksum.h
new file mode 100644
index 0000000..f062869
--- /dev/null
+++ b/kernel/tests/include/tst_checksum.h
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2018 Oracle and/or its affiliates. All Rights Reserved.
+ */
+
+#ifndef TST_CHECKSUM_H__
+#define TST_CHECKSUM_H__
+
+#include <stdint.h>
+#include <stddef.h>
+
+/*
+ * Generates CRC32c checksum.
+ */
+uint32_t tst_crc32c(uint8_t *buf, size_t buf_len);
+
+#endif
diff --git a/kernel/tests/include/tst_clocks.h b/kernel/tests/include/tst_clocks.h
new file mode 100644
index 0000000..80030c6
--- /dev/null
+++ b/kernel/tests/include/tst_clocks.h
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+/*
+ * clock_gettime() and clock_getres() functions
+ */
+
+#ifndef TST_CLOCKS__
+#define TST_CLOCKS__
+
+int tst_clock_getres(clockid_t clk_id, struct timespec *res);
+
+int tst_clock_gettime(clockid_t clk_id, struct timespec *ts);
+
+int tst_clock_settime(clockid_t clk_id, struct timespec *ts);
+
+/*
+ * Converts clock id to a readable name.
+ */
+const char *tst_clock_name(clockid_t clk_id);
+
+#endif /* TST_CLOCKS__ */
diff --git a/kernel/tests/include/tst_clone.h b/kernel/tests/include/tst_clone.h
new file mode 100644
index 0000000..8818852
--- /dev/null
+++ b/kernel/tests/include/tst_clone.h
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2016 Xiao Yang <yangx.jy@cn.fujitsu.com>
+ */
+
+#ifndef TST_CLONE_H__
+#define TST_CLONE_H__
+
+/* Functions from lib/cloner.c */
+int ltp_clone(unsigned long flags, int (*fn)(void *arg), void *arg,
+ size_t stack_size, void *stack);
+int ltp_clone7(unsigned long flags, int (*fn)(void *arg), void *arg,
+ size_t stack_size, void *stack, ...);
+int ltp_clone_alloc(unsigned long clone_flags, int (*fn)(void *arg),
+ void *arg, size_t stacksize);
+int ltp_clone_quick(unsigned long clone_flags, int (*fn)(void *arg),
+ void *arg);
+void *ltp_alloc_stack(size_t size);
+
+#define clone(...) (use_the_ltp_clone_functions__do_not_use_clone)
+
+#endif /* TST_CLONE_H__ */
diff --git a/kernel/tests/include/tst_cmd.h b/kernel/tests/include/tst_cmd.h
new file mode 100644
index 0000000..1f39f69
--- /dev/null
+++ b/kernel/tests/include/tst_cmd.h
@@ -0,0 +1,94 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2015-2016 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#ifndef TST_CMD_H__
+#define TST_CMD_H__
+
+enum tst_cmd_flags {
+ /*
+ * return the program exit code, otherwise it will call cleanup_fn() if the
+ * program exit code is not zero.
+ */
+ TST_CMD_PASS_RETVAL = 1,
+
+ /* exit with TCONF if program is not in path */
+ TST_CMD_TCONF_ON_MISSING = 2,
+};
+
+/*
+ * vfork() + execvp() specified program.
+ * @argv: a list of two (at least program name + NULL) or more pointers that
+ * represent the argument list to the new program. The array of pointers
+ * must be terminated by a NULL pointer.
+ * @stdout_fd: file descriptor where to redirect stdout. Set -1 if
+ * redirection is not needed.
+ * @stderr_fd: file descriptor where to redirect stderr. Set -1 if
+ * redirection is not needed.
+ * @flags: enum tst_cmd_flags
+ */
+int tst_cmd_fds_(void (cleanup_fn)(void),
+ const char *const argv[],
+ int stdout_fd,
+ int stderr_fd,
+ enum tst_cmd_flags flags);
+
+/* Executes tst_cmd_fds() and redirects its output to a file
+ * @stdout_path: path where to redirect stdout. Set NULL if redirection is
+ * not needed.
+ * @stderr_path: path where to redirect stderr. Set NULL if redirection is
+ * not needed.
+ * @flags: enum tst_cmd_flags
+ */
+int tst_cmd_(void (cleanup_fn)(void),
+ const char *const argv[],
+ const char *stdout_path,
+ const char *stderr_path,
+ enum tst_cmd_flags flags);
+
+#ifdef TST_TEST_H__
+static inline int tst_cmd_fds(const char *const argv[],
+ int stdout_fd,
+ int stderr_fd,
+ enum tst_cmd_flags flags)
+{
+ return tst_cmd_fds_(NULL, argv,
+ stdout_fd, stderr_fd, flags);
+}
+
+static inline int tst_cmd(const char *const argv[],
+ const char *stdout_path,
+ const char *stderr_path,
+ enum tst_cmd_flags flags)
+{
+ return tst_cmd_(NULL, argv,
+ stdout_path, stderr_path, flags);
+}
+#else
+static inline int tst_cmd_fds(void (cleanup_fn)(void),
+ const char *const argv[],
+ int stdout_fd,
+ int stderr_fd,
+ enum tst_cmd_flags flags)
+{
+ return tst_cmd_fds_(cleanup_fn, argv,
+ stdout_fd, stderr_fd, flags);
+}
+
+static inline int tst_cmd(void (cleanup_fn)(void),
+ const char *const argv[],
+ const char *stdout_path,
+ const char *stderr_path,
+ enum tst_cmd_flags flags)
+{
+ return tst_cmd_(cleanup_fn, argv,
+ stdout_path, stderr_path, flags);
+}
+#endif
+
+/* Wrapper function for system(3), ignorcing SIGCHLD signal.
+ * @command: the command to be run.
+ */
+int tst_system(const char *command);
+
+#endif /* TST_CMD_H__ */
diff --git a/kernel/tests/include/tst_common.h b/kernel/tests/include/tst_common.h
new file mode 100644
index 0000000..fd7a900
--- /dev/null
+++ b/kernel/tests/include/tst_common.h
@@ -0,0 +1,86 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
+ * Copyright (c) 2013 Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
+ * Copyright (c) 2010 Ngie Cooper <yaneurabeya@gmail.com>
+ * Copyright (c) 2008 Mike Frysinger <vapier@gmail.com>
+ */
+
+#ifndef TST_COMMON_H__
+#define TST_COMMON_H__
+
+#define LTP_ATTRIBUTE_NORETURN __attribute__((noreturn))
+#define LTP_ATTRIBUTE_UNUSED __attribute__((unused))
+#define LTP_ATTRIBUTE_UNUSED_RESULT __attribute__((warn_unused_result))
+
+#ifndef ARRAY_SIZE
+# define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+#endif
+
+/* Round x to the next multiple of a.
+ * a should be a power of 2.
+ */
+#define LTP_ALIGN(x, a) __LTP_ALIGN_MASK(x, (typeof(x))(a) - 1)
+#define __LTP_ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask))
+
+/**
+ * TST_RETRY_FUNC() - Repeatedly retry a function with an increasing delay.
+ * @FUNC - The function which will be retried
+ * @ECHCK - Function/macro for validating @FUNC return value
+ *
+ * This macro will call @FUNC in a loop with a delay between retries.
+ * If ECHCK(ret) evaluates to non-zero, the loop ends. The delay between
+ * retries starts at one microsecond and is then doubled each iteration until
+ * it exceeds one second (the total time sleeping will be approximately one
+ * second as well). When the delay exceeds one second, the loop will end.
+ * The TST_RETRY_FUNC() macro returns the last value returned by @FUNC.
+ */
+#define TST_RETRY_FUNC(FUNC, ECHCK) \
+ TST_RETRY_FN_EXP_BACKOFF(FUNC, ECHCK, 1)
+
+#define TST_RETRY_FN_EXP_BACKOFF(FUNC, ECHCK, MAX_DELAY) \
+({ unsigned int tst_delay_, tst_max_delay_; \
+ typeof(FUNC) tst_ret_; \
+ tst_delay_ = 1; \
+ tst_max_delay_ = tst_multiply_timeout(MAX_DELAY * 1000000); \
+ for (;;) { \
+ errno = 0; \
+ tst_ret_ = FUNC; \
+ if (ECHCK(tst_ret_)) \
+ break; \
+ if (tst_delay_ < tst_max_delay_) { \
+ usleep(tst_delay_); \
+ tst_delay_ *= 2; \
+ } else { \
+ break; \
+ } \
+ } \
+ tst_ret_; \
+})
+
+/*
+ * Return value validation macros for TST_RETRY_FUNC():
+ * TST_RETVAL_EQ0() - Check that value is equal to zero
+ */
+#define TST_RETVAL_EQ0(x) (!(x))
+
+/*
+ * TST_RETVAL_NOTNULL() - Check that value is not equal to zero/NULL
+ */
+#define TST_RETVAL_NOTNULL(x) (!!(x))
+
+/*
+ * TST_RETVAL_GE0() - Check that value is greater than or equal to zero
+ */
+#define TST_RETVAL_GE0(x) ((x) >= 0)
+
+#define TST_BUILD_BUG_ON(condition) \
+ do { ((void)sizeof(char[1 - 2 * !!(condition)])); } while (0)
+
+#define TST_BRK_SUPPORTS_ONLY_TCONF_TBROK(condition) \
+ TST_BUILD_BUG_ON(condition)
+
+#define TST_RES_SUPPORTS_TCONF_TFAIL_TINFO_TPASS_TWARN(condition) \
+ TST_BUILD_BUG_ON(condition)
+
+#endif /* TST_COMMON_H__ */
diff --git a/kernel/tests/include/tst_coredump.h b/kernel/tests/include/tst_coredump.h
new file mode 100644
index 0000000..e1f8925
--- /dev/null
+++ b/kernel/tests/include/tst_coredump.h
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Red Hat, Inc.
+ */
+
+#ifndef TST_COREDUMP__
+#define TST_COREDUMP__
+
+/*
+ * If crash is expected, avoid dumping corefile.
+ * 1 is a special value, that disables core-to-pipe.
+ * At the same time it is small enough value for
+ * core-to-file, so it skips creating cores as well.
+ */
+void tst_no_corefile(int verbose);
+
+#endif /* TST_COREDUMP_H */
+
diff --git a/kernel/tests/include/tst_cpu.h b/kernel/tests/include/tst_cpu.h
new file mode 100644
index 0000000..c83a582
--- /dev/null
+++ b/kernel/tests/include/tst_cpu.h
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2015-2016 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#ifndef TST_CPU_H__
+#define TST_CPU_H__
+
+long tst_ncpus(void);
+long tst_ncpus_conf(void);
+long tst_ncpus_max(void);
+
+#define VIRT_ANY 0 /* catch-all argument for tst_is_virt() */
+#define VIRT_XEN 1 /* xen dom0/domU */
+#define VIRT_KVM 2 /* only default virtual CPU */
+#define VIRT_OTHER 0xffff /* unrecognized hypervisor */
+
+int tst_is_virt(int virt_type);
+
+#endif /* TST_CPU_H__ */
diff --git a/kernel/tests/include/tst_crypto.h b/kernel/tests/include/tst_crypto.h
new file mode 100644
index 0000000..ae406bd
--- /dev/null
+++ b/kernel/tests/include/tst_crypto.h
@@ -0,0 +1,112 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2018 Richard Palethorpe <rpalethorpe@suse.com>
+ */
+
+/**
+ * @file tst_crypto.h
+ *
+ * Library for interacting with kernel's crypto layer using the netlink
+ * interface.
+ */
+
+#ifndef TST_CRYPTO_H
+#define TST_CRYPTO_H
+
+#include "lapi/cryptouser.h"
+
+/**
+ * A reference to a crypto session and associated state.
+ *
+ * Holds state relevant to a netlink crypto connection. The seq_num is used
+ * to tag each message sent to the netlink layer and is automatically
+ * incremented by the tst_crypto_ functions. When the netlink layer sends a
+ * response (ack) it will use the sequences number from the request.
+ *
+ * Some functions, such as delete ALG, may return EBUSY in which case it is
+ * safe to retry them. The retries field allows you to set the number of
+ * times this should be done. If set to zero the operation will only be tried
+ * once. For operations which do not return EBUSY, the field is ignored.
+ *
+ * Use TST_CRYPTO_SESSION_INIT to statically initialize this struct with sane
+ * defaults.
+ */
+struct tst_crypto_session {
+ /** File descriptor for the netlink socket */
+ int fd;
+ /** A sequence number used to identify responses from the kernel. */
+ uint32_t seq_num;
+ /** Number of times some operations will be retried. */
+ uint32_t retries;
+};
+
+/**
+ * Default static definition of tst_crypto_session.
+ *
+ * @relates tst_crypto_session
+ */
+#define TST_CRYPTO_SESSION_INIT {\
+ .fd = 0, \
+ .seq_num = 0, \
+ .retries = 1000 \
+}
+
+/**
+ * Creates a crypto session.
+ *
+ * @relates tst_crypto_session
+ * @param ses Session structure to use, it can be uninitialized.
+ *
+ * If some necessary feature is missing then it will call tst_brk() with
+ * TCONF, for any other error it will use TBROK.
+ */
+void tst_crypto_open(struct tst_crypto_session *ses);
+
+/**
+ * Close a crypto session.
+ *
+ * @relates tst_crypto_session
+ * @param ses The session to close.
+ */
+void tst_crypto_close(struct tst_crypto_session *ses);
+
+/**
+ * Add a crypto algorithm to a session.
+ *
+ * @relates tst_crypto_session
+ * @param ses An open session.
+ * @param alg The crypto algorithm or module to add.
+ *
+ * This requests a new crypto algorithm/engine/module to be initialized by the
+ * kernel. It sends the request contained in alg and then waits for a
+ * response. If sending the message or receiving the ack fails at the netlink
+ * level then tst_brk() with TBROK will be called.
+ *
+ * @return On success it will return 0 otherwise it will return an inverted
+ * error code from the crypto layer.
+ */
+int tst_crypto_add_alg(struct tst_crypto_session *ses,
+ const struct crypto_user_alg *alg);
+
+/**
+ * Delete a crypto algorithm from a session.
+ *
+ * @relates tst_crypto_session
+ * @param ses An open session.
+ * @param alg The crypto algorithm to delete.
+ *
+ * Request that the kernel remove an existing crypto algorithm. This behaves
+ * in a similar way to tst_crypto_add_alg() except that it is the inverse
+ * operation and that it is not unusual for the crypto layer to return
+ * EBUSY. If EBUSY is returned then the function will internally retry the
+ * operation tst_crypto_session::retries times before giving up and returning
+ * EBUSY.
+ *
+ * Return: Either 0 or an inverted error code from the crypto layer. If called
+ * during cleanup it may return a positive ENODATA value from the LTP
+ * library, you don't need to log this error as it will already have
+ * been printed by tst_brk().
+ */
+int tst_crypto_del_alg(struct tst_crypto_session *ses,
+ const struct crypto_user_alg *alg);
+
+#endif /* TST_CRYPTO_H */
diff --git a/kernel/tests/include/tst_device.h b/kernel/tests/include/tst_device.h
new file mode 100644
index 0000000..1d1246e
--- /dev/null
+++ b/kernel/tests/include/tst_device.h
@@ -0,0 +1,108 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2016-2019 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#ifndef TST_DEVICE_H__
+#define TST_DEVICE_H__
+
+#include <unistd.h>
+
+struct tst_device {
+ const char *dev;
+ const char *fs_type;
+};
+
+/*
+ * Automatically initialized if test.needs_device is set.
+ */
+extern struct tst_device *tst_device;
+
+/*
+ * Just like umount() but retries several times on failure.
+ * @path: Path to umount
+ */
+int tst_umount(const char *path);
+
+/*
+ * Verifies if an earlier mount is successful or not.
+ * @path: Mount path to verify
+ */
+int tst_is_mounted(const char *path);
+int tst_is_mounted_at_tmpdir(const char *path);
+
+/*
+ * Clears a first few blocks of the device. This is needed when device has
+ * already been formatted with a filesystems, subset of mkfs.foo utils aborts
+ * the operation if it finds a filesystem signature there.
+ *
+ * Note that this is called from tst_mkfs() automatically, so you probably will
+ * not need to use this from the test yourself.
+ */
+int tst_clear_device(const char *dev);
+
+/*
+ * Finds a free loop device for use and returns the free loopdev minor(-1 for no
+ * free loopdev). If path is non-NULL, it will be filled with free loopdev path.
+ *
+ */
+int tst_find_free_loopdev(const char *path, size_t path_len);
+
+/*
+ * Attaches a file to a loop device.
+ *
+ * @dev_path Path to the loop device e.g. /dev/loop0
+ * @file_path Path to a file e.g. disk.img
+ * @return Zero on success, non-zero otherwise.
+ */
+int tst_attach_device(const char *dev_path, const char *file_path);
+
+/*
+ * Detaches a file from a loop device fd.
+ *
+ * @dev_path Path to the loop device e.g. /dev/loop0
+ * @dev_fd a open fd for the loop device
+ * @return Zero on succes, non-zero otherwise.
+ */
+int tst_detach_device_by_fd(const char *dev_path, int dev_fd);
+
+/*
+ * Detaches a file from a loop device.
+ *
+ * @dev_path Path to the loop device e.g. /dev/loop0
+ * @return Zero on succes, non-zero otherwise.
+ *
+ * Internally this function opens the device and calls
+ * tst_detach_device_by_fd(). If you keep device file descriptor open you
+ * have to call the by_fd() variant since having the device open twice will
+ * prevent it from being detached.
+ */
+int tst_detach_device(const char *dev_path);
+
+/*
+ * To avoid FS deferred IO metadata/cache interference, so we do syncfs
+ * simply before the tst_dev_bytes_written invocation. For easy to use,
+ * we create this inline function tst_dev_sync.
+ */
+int tst_dev_sync(int fd);
+
+/*
+ * Reads test block device stat file and returns the bytes written since the
+ * last call of this function.
+ * @dev: test block device
+ */
+unsigned long tst_dev_bytes_written(const char *dev);
+
+/*
+ * Wipe the contents of given directory but keep the directory itself
+ */
+void tst_purge_dir(const char *path);
+
+/*
+ * Find the file or path belongs to which block dev
+ * @path Path to find the backing dev
+ * @dev The block dev
+ */
+void tst_find_backing_dev(const char *path, char *dev);
+
+#endif /* TST_DEVICE_H__ */
diff --git a/kernel/tests/include/tst_fs.h b/kernel/tests/include/tst_fs.h
new file mode 100644
index 0000000..fc03905
--- /dev/null
+++ b/kernel/tests/include/tst_fs.h
@@ -0,0 +1,246 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2015-2016 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#ifndef TST_FS_H__
+#define TST_FS_H__
+
+/* man 2 statfs or kernel-source/include/linux/magic.h */
+#define TST_BTRFS_MAGIC 0x9123683E
+#define TST_NFS_MAGIC 0x6969
+#define TST_RAMFS_MAGIC 0x858458f6
+#define TST_TMPFS_MAGIC 0x01021994
+#define TST_V9FS_MAGIC 0x01021997
+#define TST_XFS_MAGIC 0x58465342
+#define TST_EXT2_OLD_MAGIC 0xEF51
+/* ext2, ext3, ext4 have the same magic number */
+#define TST_EXT234_MAGIC 0xEF53
+#define TST_MINIX_MAGIC 0x137F
+#define TST_MINIX_MAGIC2 0x138F
+#define TST_MINIX2_MAGIC 0x2468
+#define TST_MINIX2_MAGIC2 0x2478
+#define TST_MINIX3_MAGIC 0x4D5A
+#define TST_UDF_MAGIC 0x15013346
+#define TST_SYSV2_MAGIC 0x012FF7B6
+#define TST_SYSV4_MAGIC 0x012FF7B5
+#define TST_UFS_MAGIC 0x00011954
+#define TST_UFS2_MAGIC 0x19540119
+#define TST_F2FS_MAGIC 0xF2F52010
+#define TST_NILFS_MAGIC 0x3434
+#define TST_EXOFS_MAGIC 0x5DF5
+#define TST_OVERLAYFS_MAGIC 0x794c7630
+
+enum {
+ TST_BYTES = 1,
+ TST_KB = 1024,
+ TST_MB = 1048576,
+ TST_GB = 1073741824,
+};
+
+#define OVL_BASE_MNTPOINT "mntpoint"
+#define OVL_LOWER OVL_BASE_MNTPOINT"/lower"
+#define OVL_UPPER OVL_BASE_MNTPOINT"/upper"
+#define OVL_WORK OVL_BASE_MNTPOINT"/work"
+#define OVL_MNT OVL_BASE_MNTPOINT"/ovl"
+
+/*
+ * @path: path is the pathname of any file within the mounted file system
+ * @mult: mult should be TST_KB, TST_MB or TST_GB
+ * the required free space is calculated by @size * @mult
+ */
+int tst_fs_has_free_(void (*cleanup)(void), const char *path,
+ unsigned int size, unsigned int mult);
+
+/*
+ * Returns filesystem magick for a given path.
+ *
+ * The expected usage is:
+ *
+ * if (tst_fs_type(cleanup, ".") == TST_NFS_MAGIC) {
+ * tst_brkm(TCONF, cleanup,
+ * "Test not supported on NFS filesystem");
+ * }
+ *
+ * Or:
+ *
+ * long type;
+ *
+ * swtich ((type = tst_fs_type(cleanup, "."))) {
+ * case TST_NFS_MAGIC:
+ * case TST_TMPFS_MAGIC:
+ * case TST_RAMFS_MAGIC:
+ * tst_brkm(TCONF, cleanup, "Test not supported on %s filesystem",
+ * tst_fs_type_name(type));
+ * break;
+ * }
+ */
+long tst_fs_type_(void (*cleanup)(void), const char *path);
+
+/*
+ * Returns filesystem name given magic.
+ */
+const char *tst_fs_type_name(long f_type);
+
+/*
+ * Try to get maximum number of hard links to a regular file inside the @dir.
+ *
+ * Note: This number depends on the filesystem @dir is on.
+ *
+ * The code uses link(2) to create hard links to a single file until it gets
+ * EMLINK or creates 65535 links.
+ *
+ * If limit is hit maximal number of hardlinks is returned and the the @dir is
+ * filled with hardlinks in format "testfile%i" where i belongs to [0, limit)
+ * interval.
+ *
+ * If no limit is hit (succed to create 65535 without error) or if link()
+ * failed with ENOSPC or EDQUOT zero is returned previously created files are
+ * removed.
+ */
+int tst_fs_fill_hardlinks_(void (*cleanup) (void), const char *dir);
+
+/*
+ * Try to get maximum number of subdirectories in directory.
+ *
+ * Note: This number depends on the filesystem @dir is on.
+ *
+ * The code uses mkdir(2) to create directories in @dir until it gets EMLINK
+ * or creates 65535 directories.
+ *
+ * If limit is hit the maximal number of subdirectories is returned and the
+ * @dir is filled with subdirectories in format "testdir%i" where i belongs to
+ * [0, limit - 2) interval (because each newly created dir has two links
+ * already the '.' and link from parent dir).
+ *
+ * If no limit is hit or mkdir() failed with ENOSPC or EDQUOT zero is returned
+ * previously created directories are removed.
+ *
+ */
+int tst_fs_fill_subdirs_(void (*cleanup) (void), const char *dir);
+
+/*
+ * Checks if a given directory contains any entities,
+ * returns 1 if directory is empty, 0 otherwise
+ */
+int tst_dir_is_empty_(void (*cleanup)(void), const char *name, int verbose);
+
+/*
+ * Search $PATH for prog_name and fills buf with absolute path if found.
+ *
+ * Returns -1 on failure, either command was not found or buffer was too small.
+ */
+int tst_get_path(const char *prog_name, char *buf, size_t buf_len);
+
+/*
+ * Fill a file with specified pattern
+ * @fd: file descriptor
+ * @pattern: pattern
+ * @bs: block size
+ * @bcount: blocks count
+ */
+int tst_fill_fd(int fd, char pattern, size_t bs, size_t bcount);
+
+/*
+ * Preallocate space in open file. If fallocate() fails, falls back to
+ * using tst_fill_fd().
+ * @fd: file descriptor
+ * @bs: block size
+ * @bcount: blocks count
+ */
+int tst_prealloc_size_fd(int fd, size_t bs, size_t bcount);
+
+/*
+ * Creates/ovewrites a file with specified pattern
+ * @path: path to file
+ * @pattern: pattern
+ * @bs: block size
+ * @bcount: blocks amount
+ */
+int tst_fill_file(const char *path, char pattern, size_t bs, size_t bcount);
+
+/*
+ * Creates file of specified size. Space will be only preallocated if possible.
+ * @path: path to file
+ * @bs: block size
+ * @bcount: blocks amount
+ */
+int tst_prealloc_file(const char *path, size_t bs, size_t bcount);
+
+#define TST_FS_SKIP_FUSE 0x01
+
+/*
+ * Return 1 if a specified fiilsystem is supported
+ * Return 0 if a specified fiilsystem isn't supported
+ */
+int tst_fs_is_supported(const char *fs_type, int flags);
+
+/*
+ * Returns NULL-terminated array of kernel-supported filesystems.
+ */
+const char **tst_get_supported_fs_types(int flags);
+
+/*
+ * Creates and writes to files on given path until write fails with ENOSPC
+ */
+void tst_fill_fs(const char *path, int verbose);
+
+/*
+ * test if FIBMAP ioctl is supported
+ */
+int tst_fibmap(const char *filename);
+
+#ifdef TST_TEST_H__
+static inline long tst_fs_type(const char *path)
+{
+ return tst_fs_type_(NULL, path);
+}
+
+static inline int tst_fs_has_free(const char *path, unsigned int size,
+ unsigned int mult)
+{
+ return tst_fs_has_free_(NULL, path, size, mult);
+}
+
+static inline int tst_fs_fill_hardlinks(const char *dir)
+{
+ return tst_fs_fill_hardlinks_(NULL, dir);
+}
+
+static inline int tst_fs_fill_subdirs(const char *dir)
+{
+ return tst_fs_fill_subdirs_(NULL, dir);
+}
+
+static inline int tst_dir_is_empty(const char *name, int verbose)
+{
+ return tst_dir_is_empty_(NULL, name, verbose);
+}
+#else
+static inline long tst_fs_type(void (*cleanup)(void), const char *path)
+{
+ return tst_fs_type_(cleanup, path);
+}
+
+static inline int tst_fs_has_free(void (*cleanup)(void), const char *path,
+ unsigned int size, unsigned int mult)
+{
+ return tst_fs_has_free_(cleanup, path, size, mult);
+}
+
+static inline int tst_fs_fill_hardlinks(void (*cleanup)(void), const char *dir)
+{
+ return tst_fs_fill_hardlinks_(cleanup, dir);
+}
+
+static inline int tst_fs_fill_subdirs(void (*cleanup)(void), const char *dir)
+{
+ return tst_fs_fill_subdirs_(cleanup, dir);
+}
+
+static inline int tst_dir_is_empty(void (*cleanup)(void), const char *name, int verbose)
+{
+ return tst_dir_is_empty_(cleanup, name, verbose);
+}
+#endif
+
+#endif /* TST_FS_H__ */
diff --git a/kernel/tests/include/tst_fuzzy_sync.h b/kernel/tests/include/tst_fuzzy_sync.h
new file mode 100644
index 0000000..4141f5c
--- /dev/null
+++ b/kernel/tests/include/tst_fuzzy_sync.h
@@ -0,0 +1,776 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (c) 2017-2018 Richard Palethorpe <rpalethorpe@suse.com>
+ */
+/**
+ * @file tst_fuzzy_sync.h
+ * Fuzzy Synchronisation - abbreviated to fzsync
+ *
+ * This library is intended to help reproduce race conditions by synchronising
+ * two threads at a given place by marking the range a race may occur
+ * in. Because the exact place where any race occurs is within the kernel,
+ * and therefore impossible to mark accurately, the library may add randomised
+ * delays to either thread in order to help find the exact race timing.
+ *
+ * Currently only two way races are explicitly supported, that is races
+ * involving two threads or processes. We refer to the main test thread as
+ * thread A and the child thread as thread B.
+ *
+ * In each thread you need a simple while- or for-loop which the tst_fzsync_*
+ * functions are called in. In the simplest case thread A will look something
+ * like:
+ *
+ * tst_fzsync_pair_reset(&pair, run_thread_b);
+ * while (tst_fzsync_run_a(&pair)) {
+ * // Perform some setup which must happen before the race
+ * tst_fzsync_start_race_a(&pair);
+ * // Do some dodgy syscall
+ * tst_fzsync_end_race_a(&pair);
+ * }
+ *
+ * Then in thread B (run_thread_b):
+ *
+ * while (tst_fzsync_run_b(&pair)) {
+ * tst_fzsync_start_race_b(&pair);
+ * // Do something which can race with the dodgy syscall in A
+ * tst_fzsync_end_race_b(&pair)
+ * }
+ *
+ * The calls to tst_fzsync_start/end_race and tst_fzsync_run_a/b block (at
+ * least) until both threads have enter them. These functions can only be
+ * called once for each iteration, but further synchronisation points can be
+ * added by calling tst_fzsync_wait_a() and tst_fzsync_wait_b() in each
+ * thread.
+ *
+ * The execution of the loops in threads A and B are bounded by both iteration
+ * count and time. A slow machine is likely to be limited by time and a fast
+ * one by iteration count. The user can use the -i parameter to run the test
+ * multiple times or LTP_TIMEOUT_MUL to give the test more time.
+ *
+ * It is possible to use the library just for tst_fzsync_pair_wait() to get a
+ * basic spin wait. However if you are actually testing a race condition then
+ * it is recommended to use tst_fzsync_start_race_a/b even if the
+ * randomisation is not needed. It provides some semantic information which
+ * may be useful in the future.
+ *
+ * For a usage example see testcases/cve/cve-2016-7117.c or just run
+ * 'git grep tst_fuzzy_sync.h'
+ *
+ * @sa tst_fzsync_pair
+ */
+
+#include <sys/time.h>
+#include <time.h>
+#include <math.h>
+#include <stdlib.h>
+#include <pthread.h>
+#include "tst_atomic.h"
+#include "tst_timer.h"
+#include "tst_safe_pthread.h"
+
+#ifndef TST_FUZZY_SYNC_H__
+#define TST_FUZZY_SYNC_H__
+
+/* how much of exec time is sampling allowed to take */
+#define SAMPLING_SLICE 0.5f
+
+/** Some statistics for a variable */
+struct tst_fzsync_stat {
+ float avg;
+ float avg_dev;
+ float dev_ratio;
+};
+
+/**
+ * The state of a two way synchronisation or race.
+ *
+ * This contains all the necessary state for approximately synchronising two
+ * sections of code in different threads.
+ *
+ * Some of the fields can be configured before calling
+ * tst_fzsync_pair_reset(), however this is mainly for debugging purposes. If
+ * a test requires one of the parameters to be modified, we should consider
+ * finding a way of automatically selecting an appropriate value at runtime.
+ *
+ * Internal fields should only be accessed by library functions.
+ */
+struct tst_fzsync_pair {
+ /**
+ * The rate at which old diff samples are forgotten
+ *
+ * Defaults to 0.25.
+ */
+ float avg_alpha;
+ /** Internal; Thread A start time */
+ struct timespec a_start;
+ /** Internal; Thread B start time */
+ struct timespec b_start;
+ /** Internal; Thread A end time */
+ struct timespec a_end;
+ /** Internal; Thread B end time */
+ struct timespec b_end;
+ /** Internal; Avg. difference between a_start and b_start */
+ struct tst_fzsync_stat diff_ss;
+ /** Internal; Avg. difference between a_start and a_end */
+ struct tst_fzsync_stat diff_sa;
+ /** Internal; Avg. difference between b_start and b_end */
+ struct tst_fzsync_stat diff_sb;
+ /** Internal; Avg. difference between a_end and b_end */
+ struct tst_fzsync_stat diff_ab;
+ /** Internal; Number of spins while waiting for the slower thread */
+ int spins;
+ struct tst_fzsync_stat spins_avg;
+ /**
+ * Internal; Number of spins to use in the delay.
+ *
+ * A negative value delays thread A and a positive delays thread B.
+ */
+ int delay;
+ int delay_bias;
+ /**
+ * Internal; The number of samples left or the sampling state.
+ *
+ * A positive value is the number of remaining mandatory
+ * samples. Zero or a negative indicate some other state.
+ */
+ int sampling;
+ /**
+ * The Minimum number of statistical samples which must be collected.
+ *
+ * The minimum number of iterations which must be performed before a
+ * random delay can be calculated. Defaults to 1024.
+ */
+ int min_samples;
+ /**
+ * The maximum allowed proportional average deviation.
+ *
+ * A value in the range (0, 1) which gives the maximum average
+ * deviation which must be attained before random delays can be
+ * calculated.
+ *
+ * It is a ratio of (average_deviation / total_time). The default is
+ * 0.1, so this allows an average deviation of at most 10%.
+ */
+ float max_dev_ratio;
+
+ /** Internal; Atomic counter used by fzsync_pair_wait() */
+ int a_cntr;
+ /** Internal; Atomic counter used by fzsync_pair_wait() */
+ int b_cntr;
+ /** Internal; Used by tst_fzsync_pair_exit() and fzsync_pair_wait() */
+ int exit;
+ /**
+ * The maximum desired execution time as a proportion of the timeout
+ *
+ * A value x so that 0 < x < 1 which decides how long the test should
+ * be run for (assuming the loop limit is not exceeded first).
+ *
+ * Defaults to 0.5 (~150 seconds with default timeout).
+ */
+ float exec_time_p;
+ /** Internal; The test time remaining on tst_fzsync_pair_reset() */
+ float exec_time_start;
+ /**
+ * The maximum number of iterations to execute during the test
+ *
+ * Defaults to a large number, but not too large.
+ */
+ int exec_loops;
+ /** Internal; The current loop index */
+ int exec_loop;
+ /** Internal; The second thread or 0 */
+ pthread_t thread_b;
+};
+
+#define CHK(param, low, hi, def) do { \
+ pair->param = (pair->param ? pair->param : def); \
+ if (pair->param < low) \
+ tst_brk(TBROK, #param " is less than the lower bound " #low); \
+ if (pair->param > hi) \
+ tst_brk(TBROK, #param " is more than the upper bound " #hi); \
+ } while (0)
+/**
+ * Ensures that any Fuzzy Sync parameters are properly set
+ *
+ * @relates tst_fzsync_pair
+ *
+ * Usually called from the setup function, it sets default parameter values or
+ * validates any existing non-defaults.
+ *
+ * @sa tst_fzsync_pair_reset()
+ */
+static void tst_fzsync_pair_init(struct tst_fzsync_pair *pair)
+{
+ CHK(avg_alpha, 0, 1, 0.25);
+ CHK(min_samples, 20, INT_MAX, 1024);
+ CHK(max_dev_ratio, 0, 1, 0.1);
+ CHK(exec_time_p, 0, 1, 0.5);
+ CHK(exec_loops, 20, INT_MAX, 3000000);
+}
+#undef CHK
+
+/**
+ * Exit and join thread B if necessary.
+ *
+ * @relates tst_fzsync_pair
+ *
+ * Call this from your cleanup function.
+ */
+static void tst_fzsync_pair_cleanup(struct tst_fzsync_pair *pair)
+{
+ if (pair->thread_b) {
+ /* Revoke thread B if parent hits accidental break */
+ if (!pair->exit) {
+ tst_atomic_store(1, &pair->exit);
+ usleep(100000);
+ pthread_cancel(pair->thread_b);
+ }
+ SAFE_PTHREAD_JOIN(pair->thread_b, NULL);
+ pair->thread_b = 0;
+ }
+}
+
+/** To store the run_b pointer and pass to tst_fzsync_thread_wrapper */
+struct tst_fzsync_run_thread {
+ void *(*func)(void *);
+ void *arg;
+};
+
+/**
+ * Wrap run_b for tst_fzsync_pair_reset to enable pthread cancel
+ * at the start of the thread B.
+ */
+static void *tst_fzsync_thread_wrapper(void *run_thread)
+{
+ struct tst_fzsync_run_thread t = *(struct tst_fzsync_run_thread *)run_thread;
+
+ pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
+ pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
+ return t.func(t.arg);
+}
+
+/**
+ * Zero some stat fields
+ *
+ * @relates tst_fzsync_stat
+ */
+static void tst_init_stat(struct tst_fzsync_stat *s)
+{
+ s->avg = 0;
+ s->avg_dev = 0;
+}
+
+/**
+ * Reset or initialise fzsync.
+ *
+ * @relates tst_fzsync_pair
+ * @param pair The state structure initialised with TST_FZSYNC_PAIR_INIT.
+ * @param run_b The function defining thread B or NULL.
+ *
+ * Call this from your main test function (thread A), just before entering the
+ * main loop. It will (re)set any variables needed by fzsync and (re)start
+ * thread B using the function provided.
+ *
+ * If you need to use fork or clone to start the second thread/process then
+ * you can pass NULL to run_b and handle starting and stopping thread B
+ * yourself. You may need to place tst_fzsync_pair in some shared memory as
+ * well.
+ *
+ * @sa tst_fzsync_pair_init()
+ */
+static void tst_fzsync_pair_reset(struct tst_fzsync_pair *pair,
+ void *(*run_b)(void *))
+{
+ tst_fzsync_pair_cleanup(pair);
+
+ tst_init_stat(&pair->diff_ss);
+ tst_init_stat(&pair->diff_sa);
+ tst_init_stat(&pair->diff_sb);
+ tst_init_stat(&pair->diff_ab);
+ tst_init_stat(&pair->spins_avg);
+ pair->delay = 0;
+ pair->sampling = pair->min_samples;
+
+ pair->exec_loop = 0;
+
+ pair->a_cntr = 0;
+ pair->b_cntr = 0;
+ pair->exit = 0;
+ if (run_b) {
+ static struct tst_fzsync_run_thread wrap_run_b;
+
+ wrap_run_b.func = run_b;
+ wrap_run_b.arg = NULL;
+ SAFE_PTHREAD_CREATE(&pair->thread_b, 0, tst_fzsync_thread_wrapper, &wrap_run_b);
+ }
+
+ pair->exec_time_start = (float)tst_timeout_remaining();
+}
+
+/**
+ * Print stat
+ *
+ * @relates tst_fzsync_stat
+ */
+static inline void tst_fzsync_stat_info(struct tst_fzsync_stat stat,
+ char *unit, char *name)
+{
+ tst_res(TINFO,
+ "%1$-17s: { avg = %3$5.0f%2$s, avg_dev = %4$5.0f%2$s, dev_ratio = %5$.2f }",
+ name, unit, stat.avg, stat.avg_dev, stat.dev_ratio);
+}
+
+/**
+ * Print some synchronisation statistics
+ *
+ * @relates tst_fzsync_pair
+ */
+static void tst_fzsync_pair_info(struct tst_fzsync_pair *pair)
+{
+ tst_res(TINFO, "loop = %d, delay_bias = %d",
+ pair->exec_loop, pair->delay_bias);
+ tst_fzsync_stat_info(pair->diff_ss, "ns", "start_a - start_b");
+ tst_fzsync_stat_info(pair->diff_sa, "ns", "end_a - start_a");
+ tst_fzsync_stat_info(pair->diff_sb, "ns", "end_b - start_b");
+ tst_fzsync_stat_info(pair->diff_ab, "ns", "end_a - end_b");
+ tst_fzsync_stat_info(pair->spins_avg, " ", "spins");
+}
+
+/** Wraps clock_gettime */
+static inline void tst_fzsync_time(struct timespec *t)
+{
+#ifdef CLOCK_MONOTONIC_RAW
+ clock_gettime(CLOCK_MONOTONIC_RAW, t);
+#else
+ clock_gettime(CLOCK_MONOTONIC, t);
+#endif
+}
+
+/**
+ * Exponential moving average
+ *
+ * @param alpha The preference for recent samples over old ones.
+ * @param sample The current sample
+ * @param prev_avg The average of the all the previous samples
+ *
+ * @return The average including the current sample.
+ */
+static inline float tst_exp_moving_avg(float alpha,
+ float sample,
+ float prev_avg)
+{
+ return alpha * sample + (1.0 - alpha) * prev_avg;
+}
+
+/**
+ * Update a stat with a new sample
+ *
+ * @relates tst_fzsync_stat
+ */
+static inline void tst_upd_stat(struct tst_fzsync_stat *s,
+ float alpha,
+ float sample)
+{
+ s->avg = tst_exp_moving_avg(alpha, sample, s->avg);
+ s->avg_dev = tst_exp_moving_avg(alpha,
+ fabs(s->avg - sample), s->avg_dev);
+ s->dev_ratio = fabs(s->avg ? s->avg_dev / s->avg : 0);
+}
+
+/**
+ * Update a stat with a new diff sample
+ *
+ * @relates tst_fzsync_stat
+ */
+static inline void tst_upd_diff_stat(struct tst_fzsync_stat *s,
+ float alpha,
+ struct timespec t1,
+ struct timespec t2)
+{
+ tst_upd_stat(s, alpha, tst_timespec_diff_ns(t1, t2));
+}
+
+/**
+ * Calculate various statistics and the delay
+ *
+ * This function helps create the fuzz in fuzzy sync. Imagine we have the
+ * following timelines in threads A and B:
+ *
+ * start_race_a
+ * ^ end_race_a (a)
+ * | ^
+ * | |
+ * - --+------------------------+-- - -
+ * | Syscall A | Thread A
+ * - --+------------------------+-- - -
+ * - --+----------------+-------+-- - -
+ * | Syscall B | spin | Thread B
+ * - --+----------------+-------+-- - -
+ * | |
+ * ^ ^
+ * start_race_b end_race_b
+ *
+ * Here we have synchronised the calls to syscall A and B with start_race_{a,
+ * b} so that they happen at approximately the same time in threads A and
+ * B. If the race condition occurs during the entry code for these two
+ * functions then we will quickly hit it. If it occurs during the exit code of
+ * B and mid way through A, then we will quickly hit it.
+ *
+ * However if the exit paths of A and B need to be aligned and (end_race_a -
+ * end_race_b) is large relative to the variation in call times, the
+ * probability of hitting the race condition is close to zero. To solve this
+ * scenario (and others) a randomised delay is introduced before the syscalls
+ * in A and B. Given enough time the following should happen where the exit
+ * paths are now synchronised:
+ *
+ * start_race_a
+ * ^ end_race_a (a)
+ * | ^
+ * | |
+ * - --+------------------------+-- - -
+ * | Syscall A | Thread A
+ * - --+------------------------+-- - -
+ * - --+-------+----------------+-- - -
+ * | delay | Syscall B | Thread B
+ * - --+-------+----------------+-- - -
+ * | |
+ * ^ ^
+ * start_race_b end_race_b
+ *
+ * The delay is not introduced immediately and the delay range is only
+ * calculated once the average relative deviation has dropped below some
+ * percentage of the total time.
+ *
+ * The delay range is chosen so that any point in Syscall A could be
+ * synchronised with any point in Syscall B using a value from the
+ * range. Because the delay range may be too large for a linear search, we use
+ * an evenly distributed random function to pick a value from it.
+ *
+ * The delay range goes from positive to negative. A negative delay will delay
+ * thread A and a positive one will delay thread B. The range is bounded by
+ * the point where the entry code to Syscall A is synchronised with the exit
+ * to Syscall B and the entry code to Syscall B is synchronised with the exit
+ * of A.
+ *
+ * In order to calculate the lower bound (the max delay of A) we can simply
+ * negate the execution time of Syscall B and convert it to a spin count. For
+ * the upper bound (the max delay of B), we just take the execution time of A
+ * and convert it to a spin count.
+ *
+ * In order to calculate spin count we need to know approximately how long a
+ * spin takes and divide the delay time with it. We find this by first
+ * counting how many spins one thread spends waiting for the other during
+ * end_race[1]. We also know when each syscall exits so we can take the
+ * difference between the exit times and divide it with the number of spins
+ * spent waiting.
+ *
+ * All the times and counts we use in the calculation are averaged over a
+ * variable number of iterations. There is an initial sampling period where we
+ * simply collect time and count samples then calculate their averages. When a
+ * minimum number of samples have been collected, and if the average deviation
+ * is below some proportion of the average sample magnitude, then the sampling
+ * period is ended. On all further iterations a random delay is calculated and
+ * applied, but the averages are not updated.
+ *
+ * [1] This assumes there is always a significant difference. The algorithm
+ * may fail to introduce a delay (when one is needed) in situations where
+ * Syscall A and B finish at approximately the same time.
+ *
+ * @relates tst_fzsync_pair
+ */
+static void tst_fzsync_pair_update(struct tst_fzsync_pair *pair)
+{
+ float alpha = pair->avg_alpha;
+ float per_spin_time, time_delay;
+ float max_dev = pair->max_dev_ratio;
+ int over_max_dev;
+
+ pair->delay = pair->delay_bias;
+
+ over_max_dev = pair->diff_ss.dev_ratio > max_dev
+ || pair->diff_sa.dev_ratio > max_dev
+ || pair->diff_sb.dev_ratio > max_dev
+ || pair->diff_ab.dev_ratio > max_dev
+ || pair->spins_avg.dev_ratio > max_dev;
+
+ if (pair->sampling > 0 || over_max_dev) {
+ tst_upd_diff_stat(&pair->diff_ss, alpha,
+ pair->a_start, pair->b_start);
+ tst_upd_diff_stat(&pair->diff_sa, alpha,
+ pair->a_end, pair->a_start);
+ tst_upd_diff_stat(&pair->diff_sb, alpha,
+ pair->b_end, pair->b_start);
+ tst_upd_diff_stat(&pair->diff_ab, alpha,
+ pair->a_end, pair->b_end);
+ tst_upd_stat(&pair->spins_avg, alpha, pair->spins);
+ if (pair->sampling > 0 && --pair->sampling == 0) {
+ tst_res(TINFO, "Minimum sampling period ended");
+ tst_fzsync_pair_info(pair);
+ }
+ } else if (fabsf(pair->diff_ab.avg) >= 1) {
+ per_spin_time = fabsf(pair->diff_ab.avg) / MAX(pair->spins_avg.avg, 1.0f);
+ time_delay = drand48() * (pair->diff_sa.avg + pair->diff_sb.avg)
+ - pair->diff_sb.avg;
+ pair->delay += (int)(1.1 * time_delay / per_spin_time);
+
+ if (!pair->sampling) {
+ tst_res(TINFO,
+ "Reached deviation ratios < %.2f, introducing randomness",
+ pair->max_dev_ratio);
+ tst_res(TINFO, "Delay range is [-%d, %d]",
+ (int)(pair->diff_sb.avg / per_spin_time) + pair->delay_bias,
+ (int)(pair->diff_sa.avg / per_spin_time) - pair->delay_bias);
+ tst_fzsync_pair_info(pair);
+ pair->sampling = -1;
+ }
+ } else if (!pair->sampling) {
+ tst_res(TWARN, "Can't calculate random delay");
+ tst_fzsync_pair_info(pair);
+ pair->sampling = -1;
+ }
+
+ pair->spins = 0;
+}
+
+/**
+ * Wait for the other thread
+ *
+ * @relates tst_fzsync_pair
+ * @param our_cntr The counter for the thread we are on
+ * @param other_cntr The counter for the thread we are synchronising with
+ * @param spins A pointer to the spin counter or NULL
+ *
+ * Used by tst_fzsync_pair_wait_a(), tst_fzsync_pair_wait_b(),
+ * tst_fzsync_start_race_a(), etc. If the calling thread is ahead of the other
+ * thread, then it will spin wait. Unlike pthread_barrier_wait it will never
+ * use futex and can count the number of spins spent waiting.
+ *
+ * @return A non-zero value if the thread should continue otherwise the
+ * calling thread should exit.
+ */
+static inline void tst_fzsync_pair_wait(int *our_cntr,
+ int *other_cntr,
+ int *spins)
+{
+ if (tst_atomic_inc(other_cntr) == INT_MAX) {
+ /*
+ * We are about to break the invariant that the thread with
+ * the lowest count is in front of the other. So we must wait
+ * here to ensure the other thread has at least reached the
+ * line above before doing that. If we are in rear position
+ * then our counter may already have been set to zero.
+ */
+ while (tst_atomic_load(our_cntr) > 0
+ && tst_atomic_load(our_cntr) < INT_MAX) {
+ if (spins)
+ (*spins)++;
+ }
+
+ tst_atomic_store(0, other_cntr);
+ /*
+ * Once both counters have been set to zero the invariant
+ * is restored and we can continue.
+ */
+ while (tst_atomic_load(our_cntr) > 1)
+ ;
+ } else {
+ /*
+ * If our counter is less than the other thread's we are ahead
+ * of it and need to wait.
+ */
+ while (tst_atomic_load(our_cntr) < tst_atomic_load(other_cntr)) {
+ if (spins)
+ (*spins)++;
+ }
+ }
+}
+
+/**
+ * Wait in thread A
+ *
+ * @relates tst_fzsync_pair
+ * @sa tst_fzsync_pair_wait
+ */
+static inline void tst_fzsync_wait_a(struct tst_fzsync_pair *pair)
+{
+ tst_fzsync_pair_wait(&pair->a_cntr, &pair->b_cntr, NULL);
+}
+
+/**
+ * Wait in thread B
+ *
+ * @relates tst_fzsync_pair
+ * @sa tst_fzsync_pair_wait
+ */
+static inline void tst_fzsync_wait_b(struct tst_fzsync_pair *pair)
+{
+ tst_fzsync_pair_wait(&pair->b_cntr, &pair->a_cntr, NULL);
+}
+
+/**
+ * Decide whether to continue running thread A
+ *
+ * @relates tst_fzsync_pair
+ *
+ * Checks some values and decides whether it is time to break the loop of
+ * thread A.
+ *
+ * @return True to continue and false to break.
+ * @sa tst_fzsync_run_a
+ */
+static inline int tst_fzsync_run_a(struct tst_fzsync_pair *pair)
+{
+ int exit = 0;
+ float rem_p = 1 - tst_timeout_remaining() / pair->exec_time_start;
+
+ if ((pair->exec_time_p * SAMPLING_SLICE < rem_p)
+ && (pair->sampling > 0)) {
+ tst_res(TINFO, "Stopped sampling at %d (out of %d) samples, "
+ "sampling time reached 50%% of the total time limit",
+ pair->exec_loop, pair->min_samples);
+ pair->sampling = 0;
+ tst_fzsync_pair_info(pair);
+ }
+
+ if (pair->exec_time_p < rem_p) {
+ tst_res(TINFO,
+ "Exceeded execution time, requesting exit");
+ exit = 1;
+ }
+
+ if (++pair->exec_loop > pair->exec_loops) {
+ tst_res(TINFO,
+ "Exceeded execution loops, requesting exit");
+ exit = 1;
+ }
+
+ tst_atomic_store(exit, &pair->exit);
+ tst_fzsync_wait_a(pair);
+
+ if (exit) {
+ tst_fzsync_pair_cleanup(pair);
+ return 0;
+ }
+
+ return 1;
+}
+
+/**
+ * Decide whether to continue running thread B
+ *
+ * @relates tst_fzsync_pair
+ * @sa tst_fzsync_run_a
+ */
+static inline int tst_fzsync_run_b(struct tst_fzsync_pair *pair)
+{
+ tst_fzsync_wait_b(pair);
+ return !tst_atomic_load(&pair->exit);
+}
+
+/**
+ * Marks the start of a race region in thread A
+ *
+ * @relates tst_fzsync_pair
+ *
+ * This should be placed just before performing whatever action can cause a
+ * race condition. Usually it is placed just before a syscall and
+ * tst_fzsync_end_race_a() is placed just afterwards.
+ *
+ * A corresponding call to tst_fzsync_start_race_b() should be made in thread
+ * B.
+ *
+ * @return A non-zero value if the calling thread should continue to loop. If
+ * it returns zero then tst_fzsync_exit() has been called and you must exit
+ * the thread.
+ *
+ * @sa tst_fzsync_pair_update
+ */
+static inline void tst_fzsync_start_race_a(struct tst_fzsync_pair *pair)
+{
+ volatile int delay;
+
+ tst_fzsync_pair_update(pair);
+
+ tst_fzsync_wait_a(pair);
+
+ delay = pair->delay;
+ while (delay < 0)
+ delay++;
+
+ tst_fzsync_time(&pair->a_start);
+}
+
+/**
+ * Marks the end of a race region in thread A
+ *
+ * @relates tst_fzsync_pair
+ * @sa tst_fzsync_start_race_a
+ */
+static inline void tst_fzsync_end_race_a(struct tst_fzsync_pair *pair)
+{
+ tst_fzsync_time(&pair->a_end);
+ tst_fzsync_pair_wait(&pair->a_cntr, &pair->b_cntr, &pair->spins);
+}
+
+/**
+ * Marks the start of a race region in thread B
+ *
+ * @relates tst_fzsync_pair
+ * @sa tst_fzsync_start_race_a
+ */
+static inline void tst_fzsync_start_race_b(struct tst_fzsync_pair *pair)
+{
+ volatile int delay;
+
+ tst_fzsync_wait_b(pair);
+
+ delay = pair->delay;
+ while (delay > 0)
+ delay--;
+
+ tst_fzsync_time(&pair->b_start);
+}
+
+/**
+ * Marks the end of a race region in thread B
+ *
+ * @relates tst_fzsync_pair
+ * @sa tst_fzsync_start_race_a
+ */
+static inline void tst_fzsync_end_race_b(struct tst_fzsync_pair *pair)
+{
+ tst_fzsync_time(&pair->b_end);
+ tst_fzsync_pair_wait(&pair->b_cntr, &pair->a_cntr, &pair->spins);
+}
+
+/**
+ * Add some amount to the delay bias
+ *
+ * @relates tst_fzsync_pair
+ * @param change The amount to add, can be negative
+ *
+ * A positive change delays thread B and a negative one delays thread
+ * A.
+ *
+ * It is intended to be used in tests where the time taken by syscall A and/or
+ * B are significantly affected by their chronological order. To the extent
+ * that the delay range will not include the correct values if too many of the
+ * initial samples are taken when the syscalls (or operations within the
+ * syscalls) happen in the wrong order.
+ *
+ * An example of this is cve/cve-2016-7117.c where a call to close() is racing
+ * with a call to recvmmsg(). If close() happens before recvmmsg() has chance
+ * to check if the file descriptor is open then recvmmsg() completes very
+ * quickly. If the call to close() happens once recvmmsg() has already checked
+ * the descriptor it takes much longer. The sample where recvmmsg() completes
+ * quickly is essentially invalid for our purposes. The test uses the simple
+ * heuristic of whether recvmmsg() returns EBADF, to decide if it should call
+ * tst_fzsync_pair_add_bias() to further delay syscall B.
+ */
+static inline void tst_fzsync_pair_add_bias(struct tst_fzsync_pair *pair, int change)
+{
+ if (pair->sampling > 0)
+ pair->delay_bias += change;
+}
+
+#endif /* TST_FUZZY_SYNC_H__ */
diff --git a/kernel/tests/include/tst_get_bad_addr.h b/kernel/tests/include/tst_get_bad_addr.h
new file mode 100644
index 0000000..69d7402
--- /dev/null
+++ b/kernel/tests/include/tst_get_bad_addr.h
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
+ * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
+ */
+
+#ifndef TST_GET_BAD_ADDR_H__
+#define TST_GET_BAD_ADDR_H__
+
+/* Functions from lib/tst_get_bad_addr.c */
+void *tst_get_bad_addr(void (*cleanup_fn) (void));
+
+#endif /* TST_GET_BAD_ADDR_H__ */
diff --git a/kernel/tests/include/tst_hugepage.h b/kernel/tests/include/tst_hugepage.h
new file mode 100644
index 0000000..e08a2da
--- /dev/null
+++ b/kernel/tests/include/tst_hugepage.h
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Red Hat, Inc.
+ */
+
+#ifndef TST_HUGEPAGE__
+#define TST_HUGEPAGE__
+
+#define PATH_HUGEPAGES "/sys/kernel/mm/hugepages/"
+#define PATH_NR_HPAGES "/proc/sys/vm/nr_hugepages"
+
+extern char *nr_opt; /* -s num Set the number of the been allocated hugepages */
+extern char *Hopt; /* -H /.. Location of hugetlbfs, i.e. -H /var/hugetlbfs */
+
+/*
+ * Get the default hugepage size. Returns 0 if hugepages are not supported.
+ */
+size_t tst_get_hugepage_size(void);
+
+/*
+ * Try the best to request a specified number of huge pages from system,
+ * it will store the reserved hpage number in tst_hugepages.
+ *
+ * Note: this depend on the status of system memory fragmentation.
+ */
+unsigned long tst_request_hugepages(unsigned long hpages);
+
+/*
+ * This variable is used for recording the number of hugepages which system can
+ * provides. It will be equal to 'hpages' if tst_request_hugepages on success,
+ * otherwise set it to a number of hugepages that we were able to reserve.
+ *
+ * If system does not support hugetlb, then it will be set to 0.
+ */
+extern unsigned long tst_hugepages;
+
+#endif /* TST_HUGEPAGE_H */
diff --git a/kernel/tests/include/tst_kconfig.h b/kernel/tests/include/tst_kconfig.h
new file mode 100644
index 0000000..2d2cfd7
--- /dev/null
+++ b/kernel/tests/include/tst_kconfig.h
@@ -0,0 +1,56 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2018 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#ifndef TST_KCONFIG_H__
+#define TST_KCONFIG_H__
+
+struct tst_kconfig_res {
+ char match;
+ char *value;
+};
+
+/**
+ * Reads a kernel config and parses it for values defined in kconfigs array.
+ *
+ * The path to the kernel config should be autodetected in most of the cases as
+ * the code looks for know locations. It can be explicitely set/overrided with
+ * the KCONFIG_PATH environment variable as well.
+ *
+ * The kcofings array is expected to contain strings in a format "CONFIG_FOO"
+ * or "CONFIG_FOO=bar". The result array has to be suitably sized to fit the
+ * results.
+ *
+ * @param kconfigs array of config strings to look for
+ * @param results array to store results to
+ * @param cnt size of the arrays
+ *
+ * The match in the tst_kconfig_res structure is set as follows:
+ *
+ * 'm' - config option set to m
+ * 'y' - config option set to y
+ * 'v' - config option set to other value
+ * 'n' - config option is not set
+ * 0 - config option not found
+ *
+ * In the case that match is set to 'v' the value points to a newly allocated
+ * string that holds the value.
+ */
+void tst_kconfig_read(const char *const kconfigs[],
+ struct tst_kconfig_res results[], size_t cnt);
+
+/**
+ * Checks if required kernel configuration options are set in the kernel
+ * config and exits the test with TCONF if at least one is missing.
+ *
+ * The config options can be passed in two different formats, either
+ * "CONFIG_FOO" in which case the option has to be set in order to continue the
+ * test or with an explicit value "CONFIG_FOO=bar" in which case the value has
+ * to match.
+ *
+ * @param kconfigs NULL-terminated array of config strings needed for the testrun.
+ */
+void tst_kconfig_check(const char *const kconfigs[]);
+
+#endif /* TST_KCONFIG_H__ */
diff --git a/kernel/tests/include/tst_kernel.h b/kernel/tests/include/tst_kernel.h
new file mode 100644
index 0000000..71ab946
--- /dev/null
+++ b/kernel/tests/include/tst_kernel.h
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#ifndef TST_KERNEL_H__
+#define TST_KERNEL_H__
+
+/*
+ * Returns 32 if we are running on 32bit kernel and 64 if on 64bit kernel.
+ */
+int tst_kernel_bits(void);
+
+/**
+ * Checks support for the kernel driver.
+ *
+ * @param name The name of the driver.
+ * @return Returns 0 if the kernel has the driver or modprobe is missing.
+ */
+int tst_check_driver(const char *name);
+
+#endif /* TST_KERNEL_H__ */
diff --git a/kernel/tests/include/tst_kvercmp.h b/kernel/tests/include/tst_kvercmp.h
new file mode 100644
index 0000000..495e8db
--- /dev/null
+++ b/kernel/tests/include/tst_kvercmp.h
@@ -0,0 +1,44 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
+ * Copyright (c) 2009-2016 Cyril Hrubis chrubis@suse.cz
+ */
+
+#ifndef TST_KVERCMP_H__
+#define TST_KVERCMP_H__
+
+/*
+ * The same as tst_kvercmp() but running kernel version is passed as parameter
+ * instead of utilizing uname().
+ */
+int tst_kvcmp(const char *cur_kver, int r1, int r2, int r3);
+
+/*
+ * Parsers string into three integer version.
+ */
+int tst_parse_kver(const char *str_kver, int *v1, int *v2, int *v3);
+
+/*
+ * Returns distribution name parsed from kernel version string or NULL.
+ */
+const char *tst_kvcmp_distname(const char *cur_kver);
+
+/*
+ * Compares versions up to five version numbers long.
+ */
+int tst_kvexcmp(const char *tst_exv, const char *cur_kver);
+
+/*
+ * Compare given kernel version with currently running kernel.
+ *
+ * Returns negative if older, 0 if the same and possitive if newer.
+ */
+int tst_kvercmp(int r1, int r2, int r3);
+
+struct tst_kern_exv {
+ char *dist_name;
+ char *extra_ver;
+};
+
+int tst_kvercmp2(int r1, int r2, int r3, struct tst_kern_exv *vers);
+
+#endif /* TST_KVERCMP_H__ */
diff --git a/kernel/tests/include/tst_lockdown.h b/kernel/tests/include/tst_lockdown.h
new file mode 100644
index 0000000..78eaecc
--- /dev/null
+++ b/kernel/tests/include/tst_lockdown.h
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#ifndef TST_LOCKDOWN_H
+#define TST_LOCKDOWN_H
+
+#define PATH_LOCKDOWN "/sys/kernel/security/lockdown"
+
+int tst_lockdown_enabled(void);
+
+#endif /* TST_LOCKDOWN_H */
diff --git a/kernel/tests/include/tst_memutils.h b/kernel/tests/include/tst_memutils.h
new file mode 100644
index 0000000..91dad07
--- /dev/null
+++ b/kernel/tests/include/tst_memutils.h
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (c) 2020 SUSE LLC <mdoucha@suse.cz>
+ */
+
+#ifndef TST_MEMUTILS_H__
+#define TST_MEMUTILS_H__
+
+/*
+ * Fill up to maxsize physical memory with fillchar, then free it for reuse.
+ * If maxsize is zero, fill as much memory as possible. This function is
+ * intended for data disclosure vulnerability tests to reduce the probability
+ * that a vulnerable kernel will leak a block of memory that was full of
+ * zeroes by chance.
+ *
+ * The function keeps a safety margin to avoid invoking OOM killer and
+ * respects the limitations of available address space. (Less than 3GB can be
+ * polluted on a 32bit system regardless of available physical RAM.)
+ */
+void tst_pollute_memory(size_t maxsize, int fillchar);
+
+#endif /* TST_MEMUTILS_H__ */
diff --git a/kernel/tests/include/tst_minmax.h b/kernel/tests/include/tst_minmax.h
new file mode 100644
index 0000000..6417dd7
--- /dev/null
+++ b/kernel/tests/include/tst_minmax.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#ifndef TST_MINMAX_H__
+#define TST_MINMAX_H__
+
+#ifndef MIN
+# define MIN(a, b) ({ \
+ typeof(a) _a = (a); \
+ typeof(b) _b = (b); \
+ _a < _b ? _a : _b; \
+})
+#endif /* MIN */
+
+#ifndef MAX
+# define MAX(a, b) ({ \
+ typeof(a) _a = (a); \
+ typeof(b) _b = (b); \
+ _a > _b ? _a : _b; \
+})
+#endif /* MAX */
+
+#endif /* TST_MINMAX_H__ */
diff --git a/kernel/tests/include/tst_mkfs.h b/kernel/tests/include/tst_mkfs.h
new file mode 100644
index 0000000..b89bf81
--- /dev/null
+++ b/kernel/tests/include/tst_mkfs.h
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#ifndef TST_MKFS_H__
+#define TST_MKFS_H__
+
+/*
+ * @dev: path to a device
+ * @fs_type: filesystem type
+ * @fs_opts: NULL or NULL terminated array of extra mkfs options
+ * @extra_opts: NULL or NULL terminated array of extra mkfs options
+ */
+void tst_mkfs_(const char *file, const int lineno, void (cleanup_fn)(void),
+ const char *dev, const char *fs_type,
+ const char *const fs_opts[], const char *const extra_opts[]);
+
+#define SAFE_MKFS(device, fs_type, fs_opts, extra_opts) \
+ tst_mkfs_(__FILE__, __LINE__, NULL, device, fs_type, \
+ fs_opts, extra_opts)
+
+#endif /* TST_MKFS_H__ */
diff --git a/kernel/tests/include/tst_net.h b/kernel/tests/include/tst_net.h
new file mode 100644
index 0000000..daefdd9
--- /dev/null
+++ b/kernel/tests/include/tst_net.h
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2017-2019 Petr Vorel <pvorel@suse.cz>
+ */
+
+#ifndef TST_NET_H_
+#define TST_NET_H_
+
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <netinet/ip.h>
+#include <sys/types.h>
+
+void tst_get_in_addr(const char *ip_str, struct in_addr *ip);
+void tst_get_in6_addr(const char *ip_str, struct in6_addr *ip6);
+
+/*
+ * Find valid connection address for a given bound socket
+ */
+socklen_t tst_get_connect_address(int sock, struct sockaddr_storage *addr);
+
+/*
+ * Initialize AF_INET/AF_INET6 socket address structure with address and port
+ */
+void tst_init_sockaddr_inet(struct sockaddr_in *sa, const char *ip_str, uint16_t port);
+void tst_init_sockaddr_inet_bin(struct sockaddr_in *sa, uint32_t ip_val, uint16_t port);
+void tst_init_sockaddr_inet6(struct sockaddr_in6 *sa, const char *ip_str, uint16_t port);
+void tst_init_sockaddr_inet6_bin(struct sockaddr_in6 *sa, const struct in6_addr *ip_val, uint16_t port);
+
+void safe_getaddrinfo(const char *file, const int lineno, const char *src_addr,
+ const char *port, const struct addrinfo *hints,
+ struct addrinfo **addr_info);
+
+#endif /* TST_NET_H_ */
diff --git a/kernel/tests/include/tst_netlink.h b/kernel/tests/include/tst_netlink.h
new file mode 100644
index 0000000..2030ac3
--- /dev/null
+++ b/kernel/tests/include/tst_netlink.h
@@ -0,0 +1,88 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2018 Richard Palethorpe <rpalethorpe@suse.com>
+ */
+
+/**
+ * @file tst_netlink.h
+ *
+ * Library for communicating with the kernel over the netlink interface.
+ */
+
+#ifndef TST_NETLINK_H
+#define TST_NETLINK_H
+
+#include <linux/netlink.h>
+
+#ifndef NETLINK_CRYPTO
+/**
+ * The netlink-crypto socket protocol.
+ */
+#define NETLINK_CRYPTO 21
+#endif
+
+/** @private */
+static inline ssize_t safe_netlink_send(const char *file, const int lineno,
+ int fd, const struct nlmsghdr *nh,
+ const void *payload)
+{
+ struct sockaddr_nl sa = { .nl_family = AF_NETLINK };
+ struct iovec iov[2] = {
+ {(struct nlmsghdr *)nh, sizeof(*nh)},
+ {(void *)payload, nh->nlmsg_len - sizeof(*nh)}
+ };
+ struct msghdr msg = {
+ .msg_name = &sa,
+ .msg_namelen = sizeof(sa),
+ .msg_iov = iov,
+ .msg_iovlen = 2
+ };
+
+ return safe_sendmsg(file, lineno, nh->nlmsg_len, fd, &msg, 0);
+}
+
+/**
+ * Sends a netlink message using safe_sendmsg().
+ *
+ * @param fd netlink socket file descriptor.
+ * @param nl_header netlink header structure describing the message.
+ * @param payload an opaque object containing the message data.
+ *
+ * You should set the message length, type and flags to appropriate values
+ * within the nl_header object. See lib/tst_crypto.c for an example.
+ *
+ * @return The number of bytes sent.
+ */
+#define SAFE_NETLINK_SEND(fd, nl_header, payload) \
+ safe_netlink_send(__FILE__, __LINE__, fd, nl_header, payload)
+
+/** @private */
+static inline ssize_t safe_netlink_recv(const char *file, const int lineno,
+ int fd, char *nl_headers_buf,
+ size_t buf_len)
+{
+ struct iovec iov = { nl_headers_buf, buf_len };
+ struct sockaddr_nl sa;
+ struct msghdr msg = {
+ .msg_name = &sa,
+ .msg_namelen = sizeof(sa),
+ .msg_iov = &iov,
+ .msg_iovlen = 1
+ };
+
+ return safe_recvmsg(file, lineno, 0, fd, &msg, 0);
+}
+
+/**
+ * Receives a netlink message using safe_recvmsg().
+ *
+ * @param fd netlink socket file descriptor.
+ * @param nl_header_buf buffer to contain the received netlink header structure.
+ * @param buf_len The length of the header buffer. Must be greater than the page
+ * size.
+ *
+ * @return The number of bytes received.
+ */
+#define SAFE_NETLINK_RECV(fd, nl_header_buf, buf_len) \
+ safe_netlink_recv(__FILE__, __LINE__, fd, nl_header_buf, buf_len)
+
+#endif /* TST_NETLINK_H */
diff --git a/kernel/tests/include/tst_numa.h b/kernel/tests/include/tst_numa.h
new file mode 100644
index 0000000..846e093
--- /dev/null
+++ b/kernel/tests/include/tst_numa.h
@@ -0,0 +1,112 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2018 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#ifndef TST_NUMA_H__
+#define TST_NUMA_H__
+
+#include <string.h>
+
+/**
+ * Numa nodemap.
+ */
+struct tst_nodemap {
+ /** Number of nodes in map */
+ unsigned int cnt;
+ /** Page allocation counters */
+ unsigned int *counters;
+ /** Array of numa ids */
+ unsigned int map[];
+};
+
+/**
+ * Clears numa counters. The counters are lazy-allocated on first call of this function.
+ *
+ * @nodes Numa nodemap.
+ */
+void tst_nodemap_reset_counters(struct tst_nodemap *nodes);
+
+/**
+ * Prints pages allocated per each node.
+ *
+ * @nodes Numa nodemap.
+ */
+void tst_nodemap_print_counters(struct tst_nodemap *nodes);
+
+/**
+ * Returns a name for a mempolicy/mbind mode.
+ *
+ * @mode Numa mempolicy mode.
+ */
+const char *tst_numa_mode_name(int mode);
+
+/**
+ * Maps pages into memory, if path is NULL the mapping is anonymous otherwise is backed by the file.
+ *
+ * @path Path to a file, if not NULL mapping is file based.
+ * @size Mapping size.
+ */
+void *tst_numa_map(const char *path, size_t size);
+
+/*
+ * Writes to memory in order to get the pages faulted.
+ *
+ * @ptr Start of the mapping.
+ * @size Size of the mapping.
+ */
+static inline void tst_numa_fault(void *ptr, size_t size)
+{
+ memset(ptr, 'a', size);
+}
+
+/*
+ * Frees the memory.
+ *
+ * @ptr Start of the mapping.
+ * @size Size of the mapping.
+ */
+static inline void tst_numa_unmap(void *ptr, size_t size)
+{
+ SAFE_MUNMAP(ptr, size);
+}
+
+/**
+ * Check on which numa node resides each page of the mapping starting at ptr
+ * and continuing pages long and increases nodemap counters accordingly.
+ *
+ * @nodes Nodemap with initialized counters.
+ * @ptr Pointer to start of a mapping.
+ * @size Size of the mapping.
+ */
+void tst_nodemap_count_pages(struct tst_nodemap *nodes, void *ptr, size_t size);
+
+/**
+ * Frees nodemap.
+ *
+ * @nodes Numa nodemap to be freed.
+ */
+void tst_nodemap_free(struct tst_nodemap *nodes);
+
+/**
+ * Bitflags for tst_get_nodemap() function.
+ */
+enum tst_numa_types {
+ TST_NUMA_ANY = 0x00,
+ TST_NUMA_MEM = 0x01,
+};
+
+/**
+ * Allocates and returns numa node map, which is an array of numa nodes which
+ * contain desired resources e.g. memory.
+ *
+ * @type Bitflags of enum tst_numa_types specifying desired resources.
+ * @min_mem_kb Minimal free RAM on memory nodes, if given node has less than
+ * requested amount of free+buffers memory it's not included in
+ * the resulting list of nodes.
+ *
+ * @return On success returns allocated and initialized struct tst_nodemap which contains
+ * array of numa node ids that contains desired resources.
+ */
+struct tst_nodemap *tst_get_nodemap(int type, size_t min_mem_kb);
+
+#endif /* TST_NUMA_H__ */
diff --git a/kernel/tests/include/tst_path_has_mnt_flags.h b/kernel/tests/include/tst_path_has_mnt_flags.h
new file mode 100644
index 0000000..a9e1f40
--- /dev/null
+++ b/kernel/tests/include/tst_path_has_mnt_flags.h
@@ -0,0 +1,29 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
+ * Copyright (c) 2018 Cyril Hrubis <chrubis@suse.cz>
+ * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
+ */
+
+#ifndef TST_PATH_HAS_MNT_FLAGS_H__
+#define TST_PATH_HAS_MNT_FLAGS_H__
+
+#ifdef TST_TEST_H__
+# define tst_path_has_mnt_flags(...) tst_path_has_mnt_flags_(NULL, __VA_ARGS__)
+#else
+# define tst_path_has_mnt_flags tst_path_has_mnt_flags_
+#endif
+
+/* lib/tst_path_has_mnt_flags.c
+ *
+ * Check whether a path is on a filesystem that is mounted with
+ * specified flags
+ * @path: path to file, if path is NULL tst_tmpdir is used.
+ * @flags: NULL or NULL terminated array of mount flags
+ *
+ * Return: 0..n - number of flags matched
+ */
+int tst_path_has_mnt_flags_(void (*cleanup_fn)(void),
+ const char *path, const char *flags[]);
+
+#endif /* TST_PATH_HAS_MNT_FLAGS_H__ */
diff --git a/kernel/tests/include/tst_pid.h b/kernel/tests/include/tst_pid.h
new file mode 100644
index 0000000..9ba1abb
--- /dev/null
+++ b/kernel/tests/include/tst_pid.h
@@ -0,0 +1,43 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2015-2016 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#ifndef TST_PID_H__
+#define TST_PID_H__
+
+#include <sys/types.h>
+
+/*
+ * Get a pid value not used by the OS
+ */
+pid_t tst_get_unused_pid_(void (*cleanup_fn)(void));
+
+/*
+ * Returns number of free pids by substarction of the number of pids
+ * currently used ('ps -eT') from max_pids
+ */
+int tst_get_free_pids_(void (*cleanup_fn)(void));
+
+#ifdef TST_TEST_H__
+static inline pid_t tst_get_unused_pid(void)
+{
+ return tst_get_unused_pid_(NULL);
+}
+
+static inline int tst_get_free_pids(void)
+{
+ return tst_get_free_pids_(NULL);
+}
+#else
+static inline pid_t tst_get_unused_pid(void (*cleanup_fn)(void))
+{
+ return tst_get_unused_pid_(cleanup_fn);
+}
+
+static inline int tst_get_free_pids(void (*cleanup_fn)(void))
+{
+ return tst_get_free_pids_(cleanup_fn);
+}
+#endif
+
+#endif /* TST_PID_H__ */
diff --git a/kernel/tests/include/tst_private.h b/kernel/tests/include/tst_private.h
new file mode 100644
index 0000000..e30d347
--- /dev/null
+++ b/kernel/tests/include/tst_private.h
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2017-2019 Petr Vorel <pvorel@suse.cz>
+ *
+ * Internal helper functions for the shell library. Do not use directly
+ * in test programs.
+ */
+
+#ifndef TST_PRIVATE_H_
+#define TST_PRIVATE_H_
+
+#include <stdio.h>
+#include <netdb.h>
+
+#define MAX_IPV4_PREFIX 32
+#define MAX_IPV6_PREFIX 128
+
+#define tst_res_comment(...) { \
+ fprintf(stderr, "# "); \
+ tst_res(__VA_ARGS__); } \
+
+
+#define tst_brk_comment(...) { \
+ fprintf(stderr, "# "); \
+ tst_brk(TCONF, __VA_ARGS__); } \
+
+void tst_print_svar(const char *name, const char *val);
+void tst_print_svar_change(const char *name, const char *val);
+
+int tst_get_prefix(const char *ip_str, int is_ipv6);
+
+#endif
diff --git a/kernel/tests/include/tst_process_state.h b/kernel/tests/include/tst_process_state.h
new file mode 100644
index 0000000..c32aa58
--- /dev/null
+++ b/kernel/tests/include/tst_process_state.h
@@ -0,0 +1,53 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (C) 2012-2014 Cyril Hrubis chrubis@suse.cz
+ */
+
+ /*
+
+ These functions helps you wait till a process with given pid changes state.
+ This is for example useful when you need to wait in parent until child
+ blocks.
+
+ */
+
+#ifndef TST_PROCESS_STATE__
+#define TST_PROCESS_STATE__
+
+#include <unistd.h>
+
+/*
+ * Waits for process state change.
+ *
+ * The state is one of the following:
+ *
+ * R - process is running
+ * S - process is sleeping
+ * D - process sleeping uninterruptibly
+ * Z - zombie process
+ * T - process is traced
+ */
+#ifdef TST_TEST_H__
+
+#define TST_PROCESS_STATE_WAIT(pid, state, msec_timeout) \
+ tst_process_state_wait(__FILE__, __LINE__, NULL, \
+ (pid), (state), (msec_timeout))
+#else
+/*
+ * The same as above but does not use tst_brkm() interface.
+ *
+ * This function is intended to be used from child processes.
+ *
+ * Returns zero on success, non-zero on failure.
+ */
+int tst_process_state_wait2(pid_t pid, const char state);
+
+# define TST_PROCESS_STATE_WAIT(cleanup_fn, pid, state) \
+ tst_process_state_wait(__FILE__, __LINE__, (cleanup_fn), \
+ (pid), (state), 0)
+#endif
+
+int tst_process_state_wait(const char *file, const int lineno,
+ void (*cleanup_fn)(void), pid_t pid,
+ const char state, unsigned int msec_timeout);
+
+#endif /* TST_PROCESS_STATE__ */
diff --git a/kernel/tests/include/tst_res_flags.h b/kernel/tests/include/tst_res_flags.h
new file mode 100644
index 0000000..8eda2f8
--- /dev/null
+++ b/kernel/tests/include/tst_res_flags.h
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) Linux Test Project, 2014
+ */
+
+#ifndef TST_RES_FLAGS_H
+#define TST_RES_FLAGS_H
+
+/* Use low 6 bits to encode test type */
+#define TTYPE_MASK 0x3f
+#define TPASS 0 /* Test passed flag */
+#define TFAIL 1 /* Test failed flag */
+#define TBROK 2 /* Test broken flag */
+#define TWARN 4 /* Test warning flag */
+#define TINFO 16 /* Test information flag */
+#define TCONF 32 /* Test not appropriate for configuration flag */
+#define TTYPE_RESULT(ttype) ((ttype) & TTYPE_MASK)
+
+#define TERRNO 0x100 /* Append errno information to output */
+#define TTERRNO 0x200 /* Append TEST_ERRNO information to output */
+#define TRERRNO 0x400 /* Capture errno information from TEST_RETURN to
+ output; useful for pthread-like APIs :). */
+
+#endif /* TST_RES_FLAGS_H */
diff --git a/kernel/tests/include/tst_safe_clocks.h b/kernel/tests/include/tst_safe_clocks.h
new file mode 100644
index 0000000..5909f40
--- /dev/null
+++ b/kernel/tests/include/tst_safe_clocks.h
@@ -0,0 +1,157 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019, Linux Test Project
+ * Copyright (c) Zilogic Systems Pvt. Ltd., 2018
+ * Email : code@zilogic.com
+ */
+
+#ifndef TST_SAFE_CLOCKS_H__
+#define TST_SAFE_CLOCKS_H__
+
+#include <time.h>
+#include <sys/timex.h>
+#include "tst_test.h"
+#include "tst_clocks.h"
+#include "lapi/syscalls.h"
+#include "lapi/posix_clocks.h"
+
+static inline void safe_clock_getres(const char *file, const int lineno,
+ clockid_t clk_id, struct timespec *res)
+{
+ int rval;
+
+ rval = clock_getres(clk_id, res);
+ if (rval != 0) {
+ tst_brk(TBROK | TERRNO,
+ "%s:%d clock_getres(%s) failed",
+ file, lineno, tst_clock_name(clk_id));
+ }
+}
+
+static inline void safe_clock_gettime(const char *file, const int lineno,
+ clockid_t clk_id, struct timespec *tp)
+{
+ int rval;
+
+ rval = clock_gettime(clk_id, tp);
+ if (rval != 0) {
+ tst_brk(TBROK | TERRNO,
+ "%s:%d clock_gettime(%s) failed",
+ file, lineno, tst_clock_name(clk_id));
+ }
+}
+
+
+static inline void safe_clock_settime(const char *file, const int lineno,
+ clockid_t clk_id, struct timespec *tp)
+{
+ int rval;
+
+ rval = clock_settime(clk_id, tp);
+ if (rval != 0) {
+ tst_brk(TBROK | TERRNO,
+ "%s:%d clock_gettime(%s) failed",
+ file, lineno, tst_clock_name(clk_id));
+ }
+}
+
+static inline int safe_timer_create(const char *file, const int lineno,
+ clockid_t clockid, struct sigevent *sevp, timer_t *timerid)
+{
+ int ret;
+
+ errno = 0;
+ ret = timer_create(clockid, sevp, timerid);
+
+ if (ret == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "timer_create(%s) failed", tst_clock_name(clockid));
+ } else if (ret) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "Invalid timer_create(%s) return value %d",
+ tst_clock_name(clockid), ret);
+ }
+
+ return ret;
+}
+
+static inline int safe_timer_settime(const char *file, const int lineno,
+ timer_t timerid, int flags, const struct itimerspec *new_value,
+ struct itimerspec *old_value)
+{
+ int ret;
+
+ errno = 0;
+ ret = timer_settime(timerid, flags, new_value, old_value);
+
+ if (ret == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "timer_settime() failed");
+ } else if (ret) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "Invalid timer_settime() return value %d", ret);
+ }
+
+ return ret;
+}
+
+static inline int safe_timer_gettime(const char *file, const int lineno,
+ timer_t timerid, struct itimerspec *curr_value)
+{
+ int ret;
+
+ errno = 0;
+ ret = timer_gettime(timerid, curr_value);
+
+ if (ret == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "timer_gettime() failed");
+ } else if (ret) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "Invalid timer_gettime() return value %d", ret);
+ }
+
+ return ret;
+}
+
+static inline int safe_timer_delete(const char *file, const int lineno,
+ timer_t timerid)
+{
+ int ret;
+
+ errno = 0;
+ ret = timer_delete(timerid);
+
+ if (ret == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO, "timer_delete() failed");
+ } else if (ret) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "Invalid timer_delete() return value %d", ret);
+ }
+
+ return ret;
+}
+
+#define SAFE_CLOCK_GETRES(clk_id, res)\
+ safe_clock_getres(__FILE__, __LINE__, (clk_id), (res))
+
+#define SAFE_CLOCK_GETTIME(clk_id, tp)\
+ safe_clock_gettime(__FILE__, __LINE__, (clk_id), (tp))
+
+#define SAFE_CLOCK_SETTIME(clk_id, tp)\
+ safe_clock_settime(__FILE__, __LINE__, (clk_id), (tp))
+
+#define SAFE_TIMER_CREATE(clockid, sevp, timerid)\
+ safe_timer_create(__FILE__, __LINE__, (clockid), (sevp), (timerid))
+
+#define SAFE_TIMER_SETTIME(timerid, flags, new_value, old_value)\
+ safe_timer_settime(__FILE__, __LINE__, (timerid), (flags),\
+ (new_value), (old_value))
+
+#define SAFE_TIMER_GETTIME(timerid, curr_value)\
+ safe_timer_gettime(__FILE__, __LINE__, (timerid), (curr_value))
+
+#define SAFE_TIMER_DELETE(timerid)\
+ safe_timer_delete(__FILE__, __LINE__, timerid)
+
+#endif /* SAFE_CLOCKS_H__ */
diff --git a/kernel/tests/include/tst_safe_file_ops.h b/kernel/tests/include/tst_safe_file_ops.h
new file mode 100644
index 0000000..894c161
--- /dev/null
+++ b/kernel/tests/include/tst_safe_file_ops.h
@@ -0,0 +1,49 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (C) 2012 Cyril Hrubis chrubis@suse.cz
+ */
+
+#ifndef TST_SAFE_FILE_OPS
+#define TST_SAFE_FILE_OPS
+
+#include "safe_file_ops_fn.h"
+
+#define SAFE_FILE_SCANF(path, fmt, ...) \
+ safe_file_scanf(__FILE__, __LINE__, NULL, \
+ (path), (fmt), ## __VA_ARGS__)
+
+#define FILE_LINES_SCANF(path, fmt, ...) \
+ file_lines_scanf(__FILE__, __LINE__, NULL, 0,\
+ (path), (fmt), ## __VA_ARGS__)
+
+#define SAFE_FILE_LINES_SCANF(path, fmt, ...) \
+ file_lines_scanf(__FILE__, __LINE__, NULL, 1,\
+ (path), (fmt), ## __VA_ARGS__)
+
+#define SAFE_READ_MEMINFO(item) \
+ ({long tst_rval; \
+ SAFE_FILE_LINES_SCANF("/proc/meminfo", item " %ld", \
+ &tst_rval); \
+ tst_rval;})
+
+#define FILE_PRINTF(path, fmt, ...) \
+ file_printf(__FILE__, __LINE__, \
+ (path), (fmt), ## __VA_ARGS__)
+
+#define SAFE_FILE_PRINTF(path, fmt, ...) \
+ safe_file_printf(__FILE__, __LINE__, NULL, \
+ (path), (fmt), ## __VA_ARGS__)
+
+#define SAFE_CP(src, dst) \
+ safe_cp(__FILE__, __LINE__, NULL, (src), (dst))
+
+#define SAFE_TOUCH(pathname, mode, times) \
+ safe_touch(__FILE__, __LINE__, NULL, \
+ (pathname), (mode), (times))
+
+#define SAFE_MOUNT_OVERLAY() \
+ ((void) mount_overlay(__FILE__, __LINE__, 1))
+
+#define TST_MOUNT_OVERLAY() \
+ (mount_overlay(__FILE__, __LINE__, 0) == 0)
+
+#endif /* TST_SAFE_FILE_OPS */
diff --git a/kernel/tests/include/tst_safe_macros.h b/kernel/tests/include/tst_safe_macros.h
new file mode 100644
index 0000000..053c3bc
--- /dev/null
+++ b/kernel/tests/include/tst_safe_macros.h
@@ -0,0 +1,606 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2010-2018 Linux Test Project
+ * Copyright (c) 2011-2015 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#ifndef TST_SAFE_MACROS_H__
+#define TST_SAFE_MACROS_H__
+
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <sys/stat.h>
+#include <sys/vfs.h>
+#include <sys/sysinfo.h>
+#include <fcntl.h>
+#include <libgen.h>
+#include <signal.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <grp.h>
+
+#include "safe_macros_fn.h"
+#include "tst_cmd.h"
+
+#define SAFE_BASENAME(path) \
+ safe_basename(__FILE__, __LINE__, NULL, (path))
+
+#define SAFE_CHDIR(path) \
+ safe_chdir(__FILE__, __LINE__, NULL, (path))
+
+#define SAFE_CLOSE(fd) do { \
+ safe_close(__FILE__, __LINE__, NULL, (fd)); \
+ fd = -1; \
+ } while (0)
+
+#define SAFE_CREAT(pathname, mode) \
+ safe_creat(__FILE__, __LINE__, NULL, (pathname), (mode))
+
+#define SAFE_CHROOT(path) \
+ safe_chroot(__FILE__, __LINE__, (path))
+int safe_chroot(const char *file, const int lineno, const char *path);
+
+#define SAFE_DIRNAME(path) \
+ safe_dirname(__FILE__, __LINE__, NULL, (path))
+
+static inline int safe_dup(const char *file, const int lineno,
+ int oldfd)
+{
+ int rval;
+
+ rval = dup(oldfd);
+ if (rval == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "dup(%i) failed", oldfd);
+ }
+
+ return rval;
+}
+#define SAFE_DUP(oldfd) \
+ safe_dup(__FILE__, __LINE__, (oldfd))
+
+#define SAFE_GETCWD(buf, size) \
+ safe_getcwd(__FILE__, __LINE__, NULL, (buf), (size))
+
+#define SAFE_GETPWNAM(name) \
+ safe_getpwnam(__FILE__, __LINE__, NULL, (name))
+
+#define SAFE_GETRUSAGE(who, usage) \
+ safe_getrusage(__FILE__, __LINE__, NULL, (who), (usage))
+
+#define SAFE_MALLOC(size) \
+ safe_malloc(__FILE__, __LINE__, NULL, (size))
+
+#define SAFE_MKDIR(pathname, mode) \
+ safe_mkdir(__FILE__, __LINE__, NULL, (pathname), (mode))
+
+#define SAFE_RMDIR(pathname) \
+ safe_rmdir(__FILE__, __LINE__, NULL, (pathname))
+
+#define SAFE_MUNMAP(addr, length) \
+ safe_munmap(__FILE__, __LINE__, NULL, (addr), (length))
+
+#define SAFE_OPEN(pathname, oflags, ...) \
+ safe_open(__FILE__, __LINE__, NULL, (pathname), (oflags), \
+ ##__VA_ARGS__)
+
+#define SAFE_PIPE(fildes) \
+ safe_pipe(__FILE__, __LINE__, NULL, (fildes))
+
+int safe_pipe2(const char *file, const int lineno, int fildes[2], int flags);
+
+#define SAFE_PIPE2(fildes, flags) \
+ safe_pipe2(__FILE__, __LINE__, (fildes), (flags))
+
+#define SAFE_READ(len_strict, fildes, buf, nbyte) \
+ safe_read(__FILE__, __LINE__, NULL, (len_strict), (fildes), (buf), (nbyte))
+
+#define SAFE_SETEGID(egid) \
+ safe_setegid(__FILE__, __LINE__, NULL, (egid))
+
+#define SAFE_SETEUID(euid) \
+ safe_seteuid(__FILE__, __LINE__, NULL, (euid))
+
+#define SAFE_SETGID(gid) \
+ safe_setgid(__FILE__, __LINE__, NULL, (gid))
+
+#define SAFE_SETUID(uid) \
+ safe_setuid(__FILE__, __LINE__, NULL, (uid))
+
+int safe_setregid(const char *file, const int lineno,
+ gid_t rgid, gid_t egid);
+
+#define SAFE_SETREGID(rgid, egid) \
+ safe_setregid(__FILE__, __LINE__, (rgid), (egid))
+
+int safe_setreuid(const char *file, const int lineno,
+ uid_t ruid, uid_t euid);
+
+#define SAFE_SETREUID(ruid, euid) \
+ safe_setreuid(__FILE__, __LINE__, (ruid), (euid))
+
+#define SAFE_GETRESUID(ruid, euid, suid) \
+ safe_getresuid(__FILE__, __LINE__, NULL, (ruid), (euid), (suid))
+
+#define SAFE_GETRESGID(rgid, egid, sgid) \
+ safe_getresgid(__FILE__, __LINE__, NULL, (rgid), (egid), (sgid))
+
+int safe_setpgid(const char *file, const int lineno, pid_t pid, pid_t pgid);
+
+#define SAFE_SETPGID(pid, pgid) \
+ safe_setpgid(__FILE__, __LINE__, (pid), (pgid));
+
+pid_t safe_getpgid(const char *file, const int lineno, pid_t pid);
+
+#define SAFE_GETPGID(pid) \
+ safe_getpgid(__FILE__, __LINE__, (pid))
+
+#define SAFE_UNLINK(pathname) \
+ safe_unlink(__FILE__, __LINE__, NULL, (pathname))
+
+#define SAFE_LINK(oldpath, newpath) \
+ safe_link(__FILE__, __LINE__, NULL, (oldpath), (newpath))
+
+#define SAFE_LINKAT(olddirfd, oldpath, newdirfd, newpath, flags) \
+ safe_linkat(__FILE__, __LINE__, NULL, (olddirfd), (oldpath), \
+ (newdirfd), (newpath), (flags))
+
+#define SAFE_READLINK(path, buf, bufsize) \
+ safe_readlink(__FILE__, __LINE__, NULL, (path), (buf), (bufsize))
+
+#define SAFE_SYMLINK(oldpath, newpath) \
+ safe_symlink(__FILE__, __LINE__, NULL, (oldpath), (newpath))
+
+#define SAFE_WRITE(len_strict, fildes, buf, nbyte) \
+ safe_write(__FILE__, __LINE__, NULL, (len_strict), (fildes), (buf), (nbyte))
+
+#define SAFE_STRTOL(str, min, max) \
+ safe_strtol(__FILE__, __LINE__, NULL, (str), (min), (max))
+
+#define SAFE_STRTOUL(str, min, max) \
+ safe_strtoul(__FILE__, __LINE__, NULL, (str), (min), (max))
+
+#define SAFE_SYSCONF(name) \
+ safe_sysconf(__FILE__, __LINE__, NULL, name)
+
+#define SAFE_CHMOD(path, mode) \
+ safe_chmod(__FILE__, __LINE__, NULL, (path), (mode))
+
+#define SAFE_FCHMOD(fd, mode) \
+ safe_fchmod(__FILE__, __LINE__, NULL, (fd), (mode))
+
+#define SAFE_CHOWN(path, owner, group) \
+ safe_chown(__FILE__, __LINE__, NULL, (path), (owner), (group))
+
+#define SAFE_FCHOWN(fd, owner, group) \
+ safe_fchown(__FILE__, __LINE__, NULL, (fd), (owner), (group))
+
+#define SAFE_WAIT(status) \
+ safe_wait(__FILE__, __LINE__, NULL, (status))
+
+#define SAFE_WAITPID(pid, status, opts) \
+ safe_waitpid(__FILE__, __LINE__, NULL, (pid), (status), (opts))
+
+#define SAFE_KILL(pid, sig) \
+ safe_kill(__FILE__, __LINE__, NULL, (pid), (sig))
+
+#define SAFE_MEMALIGN(alignment, size) \
+ safe_memalign(__FILE__, __LINE__, NULL, (alignment), (size))
+
+#define SAFE_MKFIFO(pathname, mode) \
+ safe_mkfifo(__FILE__, __LINE__, NULL, (pathname), (mode))
+
+#define SAFE_RENAME(oldpath, newpath) \
+ safe_rename(__FILE__, __LINE__, NULL, (oldpath), (newpath))
+
+#define SAFE_MOUNT(source, target, filesystemtype, \
+ mountflags, data) \
+ safe_mount(__FILE__, __LINE__, NULL, (source), (target), \
+ (filesystemtype), (mountflags), (data))
+
+#define SAFE_UMOUNT(target) \
+ safe_umount(__FILE__, __LINE__, NULL, (target))
+
+#define SAFE_OPENDIR(name) \
+ safe_opendir(__FILE__, __LINE__, NULL, (name))
+
+#define SAFE_CLOSEDIR(dirp) \
+ safe_closedir(__FILE__, __LINE__, NULL, (dirp))
+
+#define SAFE_READDIR(dirp) \
+ safe_readdir(__FILE__, __LINE__, NULL, (dirp))
+
+#define SAFE_IOCTL(fd, request, ...) \
+ ({int tst_ret_ = ioctl(fd, request, ##__VA_ARGS__); \
+ tst_ret_ < 0 ? \
+ tst_brk(TBROK | TERRNO, \
+ "ioctl(%i,%s,...) failed", fd, #request), 0 \
+ : tst_ret_;})
+
+#define SAFE_FCNTL(fd, cmd, ...) \
+ ({int tst_ret_ = fcntl(fd, cmd, ##__VA_ARGS__); \
+ tst_ret_ == -1 ? \
+ tst_brk(TBROK | TERRNO, \
+ "fcntl(%i,%s,...) failed", fd, #cmd), 0 \
+ : tst_ret_;})
+
+/*
+ * following functions are inline because the behaviour may depend on
+ * -D_FILE_OFFSET_BITS=64 -DOFF_T=off64_t compile flags
+ */
+
+static inline void *safe_mmap(const char *file, const int lineno,
+ void *addr, size_t length,
+ int prot, int flags, int fd, off_t offset)
+{
+ void *rval;
+
+ rval = mmap(addr, length, prot, flags, fd, offset);
+ if (rval == MAP_FAILED) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "mmap(%p,%zu,%d,%d,%d,%ld) failed",
+ addr, length, prot, flags, fd, (long) offset);
+ }
+
+ return rval;
+}
+#define SAFE_MMAP(addr, length, prot, flags, fd, offset) \
+ safe_mmap(__FILE__, __LINE__, (addr), (length), (prot), \
+ (flags), (fd), (offset))
+
+static inline int safe_ftruncate(const char *file, const int lineno,
+ int fd, off_t length)
+{
+ int rval;
+
+ rval = ftruncate(fd, length);
+ if (rval == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "ftruncate(%d,%ld) failed",
+ fd, (long)length);
+ }
+
+ return rval;
+}
+#define SAFE_FTRUNCATE(fd, length) \
+ safe_ftruncate(__FILE__, __LINE__, (fd), (length))
+
+static inline int safe_truncate(const char *file, const int lineno,
+ const char *path, off_t length)
+{
+ int rval;
+
+ rval = truncate(path, length);
+ if (rval == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "truncate(%s,%ld) failed",
+ path, (long)length);
+ }
+
+ return rval;
+}
+#define SAFE_TRUNCATE(path, length) \
+ safe_truncate(__FILE__, __LINE__, (path), (length))
+
+static inline int safe_stat(const char *file, const int lineno,
+ const char *path, struct stat *buf)
+{
+ int rval;
+
+ rval = stat(path, buf);
+
+ if (rval == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "stat(%s,%p) failed", path, buf);
+ }
+
+ return rval;
+}
+#define SAFE_STAT(path, buf) \
+ safe_stat(__FILE__, __LINE__, (path), (buf))
+
+static inline int safe_fstat(const char *file, const int lineno,
+ int fd, struct stat *buf)
+{
+ int rval;
+
+ rval = fstat(fd, buf);
+
+ if (rval == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "fstat(%d,%p) failed", fd, buf);
+ }
+
+ return rval;
+}
+#define SAFE_FSTAT(fd, buf) \
+ safe_fstat(__FILE__, __LINE__, (fd), (buf))
+
+static inline int safe_lstat(const char *file, const int lineno,
+ const char *path, struct stat *buf)
+{
+ int rval;
+
+ rval = lstat(path, buf);
+
+ if (rval == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "lstat(%s,%p) failed", path, buf);
+ }
+
+ return rval;
+}
+#define SAFE_LSTAT(path, buf) \
+ safe_lstat(__FILE__, __LINE__, (path), (buf))
+
+static inline int safe_statfs(const char *file, const int lineno,
+ const char *path, struct statfs *buf)
+{
+ int rval;
+
+ rval = statfs(path, buf);
+
+ if (rval == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "statfs(%s,%p) failed", path, buf);
+ }
+
+ return rval;
+}
+#define SAFE_STATFS(path, buf) \
+ safe_statfs(__FILE__, __LINE__, (path), (buf))
+
+static inline off_t safe_lseek(const char *file, const int lineno,
+ int fd, off_t offset, int whence)
+{
+ off_t rval;
+
+ rval = lseek(fd, offset, whence);
+
+ if (rval == (off_t) -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "lseek(%d,%ld,%d) failed",
+ fd, (long)offset, whence);
+ }
+
+ return rval;
+}
+#define SAFE_LSEEK(fd, offset, whence) \
+ safe_lseek(__FILE__, __LINE__, (fd), (offset), (whence))
+
+static inline int safe_getrlimit(const char *file, const int lineno,
+ int resource, struct rlimit *rlim)
+{
+ int rval;
+
+ rval = getrlimit(resource, rlim);
+
+ if (rval == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "getrlimit(%d,%p) failed",
+ resource, rlim);
+ }
+
+ return rval;
+}
+#define SAFE_GETRLIMIT(resource, rlim) \
+ safe_getrlimit(__FILE__, __LINE__, (resource), (rlim))
+
+static inline int safe_setrlimit(const char *file, const int lineno,
+ int resource, const struct rlimit *rlim)
+{
+ int rval;
+
+ rval = setrlimit(resource, rlim);
+
+ if (rval == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "setrlimit(%d,%p) failed",
+ resource, rlim);
+ }
+
+ return rval;
+}
+#define SAFE_SETRLIMIT(resource, rlim) \
+ safe_setrlimit(__FILE__, __LINE__, (resource), (rlim))
+
+typedef void (*sighandler_t)(int);
+static inline sighandler_t safe_signal(const char *file, const int lineno,
+ int signum, sighandler_t handler)
+{
+ sighandler_t rval;
+
+ rval = signal(signum, handler);
+
+ if (rval == SIG_ERR) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "signal(%d,%p) failed",
+ signum, handler);
+ }
+
+ return rval;
+}
+
+#define SAFE_SIGNAL(signum, handler) \
+ safe_signal(__FILE__, __LINE__, (signum), (handler))
+
+int safe_sigaction(const char *file, const int lineno,
+ int signum, const struct sigaction *act,
+ struct sigaction *oldact);
+#define SAFE_SIGACTION(signum, act, oldact) \
+ safe_sigaction(__FILE__, __LINE__, (signum), (act), (oldact))
+
+void safe_sigaddset(const char *file, const int lineno,
+ sigset_t *sigs, int signo);
+#define SAFE_SIGADDSET(sigs, signo) \
+ safe_sigaddset(__FILE__, __LINE__, (sigs), (signo))
+
+void safe_sigdelset(const char *file, const int lineno,
+ sigset_t *sigs, int signo);
+#define SAFE_SIGDELSET(sigs, signo) \
+ safe_sigdelset(__FILE__, __LINE__, (sigs), (signo))
+
+void safe_sigemptyset(const char *file, const int lineno,
+ sigset_t *sigs);
+#define SAFE_SIGEMPTYSET(sigs) \
+ safe_sigemptyset(__FILE__, __LINE__, (sigs))
+
+void safe_sigfillset(const char *file, const int lineno,
+ sigset_t *sigs);
+#define SAFE_SIGFILLSET(sigs) \
+ safe_sigfillset(__FILE__, __LINE__, (sigs))
+
+void safe_sigprocmask(const char *file, const int lineno,
+ int how, sigset_t *set, sigset_t *oldset);
+#define SAFE_SIGPROCMASK(how, set, oldset) \
+ safe_sigprocmask(__FILE__, __LINE__, (how), (set), (oldset))
+
+void safe_sigwait(const char *file, const int lineno,
+ sigset_t *set, int *sig);
+#define SAFE_SIGWAIT(set, sig) \
+ safe_sigwait(__FILE__, __LINE__, (set), (sig))
+
+#define SAFE_EXECLP(file, arg, ...) do { \
+ execlp((file), (arg), ##__VA_ARGS__); \
+ tst_brk_(__FILE__, __LINE__, TBROK | TERRNO, \
+ "execlp(%s, %s, ...) failed", file, arg); \
+ } while (0)
+
+#define SAFE_EXECL(file, arg, ...) do { \
+ execl((file), (arg), ##__VA_ARGS__); \
+ tst_brk_(__FILE__, __LINE__, TBROK | TERRNO, \
+ "execl(%s, %s, ...) failed", file, arg); \
+ } while (0)
+
+int safe_getpriority(const char *file, const int lineno, int which, id_t who);
+#define SAFE_GETPRIORITY(which, who) \
+ safe_getpriority(__FILE__, __LINE__, (which), (who))
+
+struct group *safe_getgrnam(const char *file, const int lineno,
+ const char *name);
+#define SAFE_GETGRNAM(name) \
+ safe_getgrnam(__FILE__, __LINE__, (name))
+
+struct group *safe_getgrnam_fallback(const char *file, const int lineno,
+ const char *name, const char *fallback);
+#define SAFE_GETGRNAM_FALLBACK(name, fallback) \
+ safe_getgrnam_fallback(__FILE__, __LINE__, (name), (fallback))
+
+struct group *safe_getgrgid(const char *file, const int lineno, gid_t gid);
+#define SAFE_GETGRGID(gid) \
+ safe_getgrgid(__FILE__, __LINE__, (gid))
+
+ssize_t safe_getxattr(const char *file, const int lineno, const char *path,
+ const char *name, void *value, size_t size);
+#define SAFE_GETXATTR(path, name, value, size) \
+ safe_getxattr(__FILE__, __LINE__, (path), (name), (value), (size))
+
+int safe_setxattr(const char *file, const int lineno, const char *path,
+ const char *name, const void *value, size_t size, int flags);
+#define SAFE_SETXATTR(path, name, value, size, flags) \
+ safe_setxattr(__FILE__, __LINE__, (path), (name), (value), (size), (flags))
+
+int safe_lsetxattr(const char *file, const int lineno, const char *path,
+ const char *name, const void *value, size_t size, int flags);
+#define SAFE_LSETXATTR(path, name, value, size, flags) \
+ safe_lsetxattr(__FILE__, __LINE__, (path), (name), (value), (size), (flags))
+
+int safe_fsetxattr(const char *file, const int lineno, int fd, const char *name,
+ const void *value, size_t size, int flags);
+#define SAFE_FSETXATTR(fd, name, value, size, flags) \
+ safe_fsetxattr(__FILE__, __LINE__, (fd), (name), (value), (size), (flags))
+
+int safe_removexattr(const char *file, const int lineno, const char *path,
+ const char *name);
+#define SAFE_REMOVEXATTR(path, name) \
+ safe_removexattr(__FILE__, __LINE__, (path), (name))
+
+int safe_lremovexattr(const char *file, const int lineno, const char *path,
+ const char *name);
+#define SAFE_LREMOVEXATTR(path, name) \
+ safe_lremovexattr(__FILE__, __LINE__, (path), (name))
+
+int safe_fremovexattr(const char *file, const int lineno, int fd,
+ const char *name);
+#define SAFE_FREMOVEXATTR(fd, name) \
+ safe_fremovexattr(__FILE__, __LINE__, (fd), (name))
+
+int safe_fsync(const char *file, const int lineno, int fd);
+#define SAFE_FSYNC(fd) safe_fsync(__FILE__, __LINE__, (fd))
+
+int safe_setsid(const char *file, const int lineno);
+#define SAFE_SETSID() safe_setsid(__FILE__, __LINE__)
+
+int safe_mknod(const char *file, const int lineno, const char *pathname,
+ mode_t mode, dev_t dev);
+#define SAFE_MKNOD(pathname, mode, dev) \
+ safe_mknod(__FILE__, __LINE__, (pathname), (mode), (dev))
+
+int safe_mlock(const char *file, const int lineno, const char *addr,
+ size_t len);
+#define SAFE_MLOCK(addr, len) safe_mlock(__FILE__, __LINE__, (addr), (len))
+
+int safe_munlock(const char *file, const int lineno, const char *addr,
+ size_t len);
+#define SAFE_MUNLOCK(addr, len) safe_munlock(__FILE__, __LINE__, (addr), (len))
+
+int safe_mincore(const char *file, const int lineno, void *start,
+ size_t length, unsigned char *vec);
+#define SAFE_MINCORE(start, length, vec) \
+ safe_mincore(__FILE__, __LINE__, (start), (length), (vec))
+
+int safe_fanotify_init(const char *file, const int lineno,
+ unsigned int flags, unsigned int event_f_flags);
+#define SAFE_FANOTIFY_INIT(fan, mode) \
+ safe_fanotify_init(__FILE__, __LINE__, (fan), (mode))
+
+int safe_personality(const char *filename, unsigned int lineno,
+ unsigned long persona);
+#define SAFE_PERSONALITY(persona) safe_personality(__FILE__, __LINE__, persona)
+
+#define SAFE_SETENV(name, value, overwrite) do { \
+ if (setenv(name, value, overwrite)) { \
+ tst_brk_(__FILE__, __LINE__, TBROK | TERRNO, \
+ "setenv(%s, %s, %d) failed", \
+ name, value, overwrite); \
+ } \
+ } while (0)
+
+void safe_unshare(const char *file, const int lineno, int flags);
+#define SAFE_UNSHARE(flags) safe_unshare(__FILE__, __LINE__, (flags))
+
+void safe_setns(const char *file, const int lineno, int fd, int nstype);
+#define SAFE_SETNS(fd, nstype) safe_setns(__FILE__, __LINE__, (fd), (nstype));
+
+static inline void safe_cmd(const char *file, const int lineno, const char *const argv[],
+ const char *stdout_path, const char *stderr_path)
+{
+ int rval;
+
+ switch ((rval = tst_cmd(argv, stdout_path, stderr_path,
+ TST_CMD_PASS_RETVAL | TST_CMD_TCONF_ON_MISSING))) {
+ case 0:
+ break;
+ default:
+ tst_brk(TBROK, "%s:%d: %s failed (%d)", file, lineno, argv[0], rval);
+ }
+}
+#define SAFE_CMD(argv, stdout_path, stderr_path) \
+ safe_cmd(__FILE__, __LINE__, (argv), (stdout_path), (stderr_path))
+/*
+ * SAFE_PTRACE() treats any non-zero return value as error. Don't use it
+ * for requests like PTRACE_PEEK* or PTRACE_SECCOMP_GET_FILTER which use
+ * the return value to pass arbitrary data.
+ */
+long tst_safe_ptrace(const char *file, const int lineno, int req, pid_t pid,
+ void *addr, void *data);
+#define SAFE_PTRACE(req, pid, addr, data) \
+ tst_safe_ptrace(__FILE__, __LINE__, req, pid, addr, data)
+
+int safe_sysinfo(const char *file, const int lineno, struct sysinfo *info);
+#define SAFE_SYSINFO(info) \
+ safe_sysinfo(__FILE__, __LINE__, (info))
+
+#endif /* SAFE_MACROS_H__ */
diff --git a/kernel/tests/include/tst_safe_net.h b/kernel/tests/include/tst_safe_net.h
new file mode 100644
index 0000000..78a488a
--- /dev/null
+++ b/kernel/tests/include/tst_safe_net.h
@@ -0,0 +1,79 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#ifndef TST_SAFE_NET_H__
+#define TST_SAFE_NET_H__
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <sys/un.h>
+
+#include "safe_net_fn.h"
+#include "tst_net.h"
+
+#define SAFE_SOCKET(domain, type, protocol) \
+ safe_socket(__FILE__, __LINE__, NULL, domain, type, protocol)
+
+#define SAFE_SOCKETPAIR(domain, type, protocol, sv) \
+ safe_socketpair(__FILE__, __LINE__, domain, type, protocol, sv)
+
+#define SAFE_GETSOCKOPT(fd, level, optname, optval, optlen) \
+ safe_getsockopt(__FILE__, __LINE__, fd, level, optname, optval, optlen)
+
+#define SAFE_SETSOCKOPT(fd, level, optname, optval, optlen) \
+ safe_setsockopt(__FILE__, __LINE__, fd, level, optname, optval, optlen)
+
+#define SAFE_SETSOCKOPT_INT(fd, l, n, val) \
+ do { \
+ int v = val; \
+ safe_setsockopt(__FILE__, __LINE__, fd, l, n, &v, sizeof(v)); \
+ } while (0)
+
+#define SAFE_SEND(strict, sockfd, buf, len, flags) \
+ safe_send(__FILE__, __LINE__, strict, sockfd, buf, len, flags)
+
+#define SAFE_SENDTO(strict, fd, buf, len, flags, dest_addr, addrlen) \
+ safe_sendto(__FILE__, __LINE__, strict, fd, buf, len, flags, \
+ dest_addr, addrlen)
+
+#define SAFE_SENDMSG(msg_len, fd, msg, flags) \
+ safe_sendmsg(__FILE__, __LINE__, msg_len, fd, msg, flags)
+
+#define SAFE_RECVMSG(msg_len, fd, msg, flags) \
+ safe_recvmsg(__FILE__, __LINE__, msg_len, fd, msg, flags)
+
+#define SAFE_BIND(socket, address, address_len) \
+ safe_bind(__FILE__, __LINE__, NULL, socket, address, \
+ address_len)
+
+#define SAFE_LISTEN(socket, backlog) \
+ safe_listen(__FILE__, __LINE__, NULL, socket, backlog)
+
+#define SAFE_ACCEPT(sockfd, addr, addrlen) \
+ safe_accept(__FILE__, __LINE__, NULL, sockfd, addr, addrlen)
+
+#define SAFE_CONNECT(sockfd, addr, addrlen) \
+ safe_connect(__FILE__, __LINE__, NULL, sockfd, addr, addrlen)
+
+#define SAFE_GETSOCKNAME(sockfd, addr, addrlen) \
+ safe_getsockname(__FILE__, __LINE__, NULL, sockfd, addr, \
+ addrlen)
+
+#define SAFE_GETHOSTNAME(name, size) \
+ safe_gethostname(__FILE__, __LINE__, name, size)
+
+#define TST_GETSOCKPORT(sockfd) \
+ tst_getsockport(__FILE__, __LINE__, sockfd)
+
+#define TST_GET_UNUSED_PORT(family, type) \
+ tst_get_unused_port(__FILE__, __LINE__, NULL, family, type)
+
+/* new API only */
+
+#define SAFE_GETADDRINFO(src_addr, port, hints, addr_info) \
+ safe_getaddrinfo(__FILE__, __LINE__, src_addr, port, hints, addr_info)
+
+#endif /* TST_SAFE_NET_H__ */
diff --git a/kernel/tests/include/tst_safe_posix_ipc.h b/kernel/tests/include/tst_safe_posix_ipc.h
new file mode 100644
index 0000000..d74ef4e
--- /dev/null
+++ b/kernel/tests/include/tst_safe_posix_ipc.h
@@ -0,0 +1,47 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2017-2019 Petr Vorel pvorel@suse.cz
+ */
+
+#ifndef TST_SAFE_POSIX_IPC_H__
+#define TST_SAFE_POSIX_IPC_H__
+
+#include <mqueue.h>
+#include <stdarg.h>
+
+#define SAFE_MQ_OPEN(pathname, oflags, ...) \
+ safe_mq_open(__FILE__, __LINE__, (pathname), (oflags), ##__VA_ARGS__)
+
+static inline int safe_mq_open(const char *file, const int lineno,
+ const char *pathname, int oflags, ...)
+{
+ va_list ap;
+ int rval;
+ mode_t mode;
+ struct mq_attr *attr;
+
+ va_start(ap, oflags);
+
+ /* Android's NDK's mode_t is smaller than an int, which results in
+ * SIGILL here when passing the mode_t type.
+ */
+#ifndef __ANDROID__
+ mode = va_arg(ap, mode_t);
+#else
+ mode = va_arg(ap, int);
+#endif
+
+ attr = va_arg(ap, struct mq_attr *);
+
+ va_end(ap);
+
+ rval = mq_open(pathname, oflags, mode, attr);
+ if (rval == -1) {
+ tst_brk(TBROK | TERRNO, "%s:%d: mq_open(%s,%d,0%o,%p) failed",
+ file, lineno, pathname, oflags, mode, attr);
+ }
+
+ return rval;
+}
+
+#endif /* TST_SAFE_POSIX_IPC_H__ */
diff --git a/kernel/tests/include/tst_safe_prw.h b/kernel/tests/include/tst_safe_prw.h
new file mode 100644
index 0000000..01a684d
--- /dev/null
+++ b/kernel/tests/include/tst_safe_prw.h
@@ -0,0 +1,47 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2010-2017 Linux Test Project
+ */
+
+#ifndef TST_SAFE_PRW_H__
+#define TST_SAFE_PRW_H__
+
+static inline ssize_t safe_pread(const char *file, const int lineno,
+ char len_strict, int fildes, void *buf, size_t nbyte,
+ off_t offset)
+{
+ ssize_t rval;
+
+ rval = pread(fildes, buf, nbyte, offset);
+
+ if (rval == -1 || (len_strict && (size_t)rval != nbyte)) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "pread(%d,%p,%zu,%lld) failed",
+ fildes, buf, nbyte, (long long)offset);
+ }
+
+ return rval;
+}
+#define SAFE_PREAD(len_strict, fildes, buf, nbyte, offset) \
+ safe_pread(__FILE__, __LINE__, (len_strict), (fildes), \
+ (buf), (nbyte), (offset))
+
+static inline ssize_t safe_pwrite(const char *file, const int lineno,
+ char len_strict, int fildes, const void *buf, size_t nbyte,
+ off_t offset)
+{
+ ssize_t rval;
+
+ rval = pwrite(fildes, buf, nbyte, offset);
+ if (rval == -1 || (len_strict && (size_t)rval != nbyte)) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "pwrite(%d,%p,%zu,%lld) failed",
+ fildes, buf, nbyte, (long long)offset);
+ }
+
+ return rval;
+}
+#define SAFE_PWRITE(len_strict, fildes, buf, nbyte, offset) \
+ safe_pwrite(__FILE__, __LINE__, (len_strict), (fildes), \
+ (buf), (nbyte), (offset))
+
+#endif /* SAFE_PRW_H__ */
diff --git a/kernel/tests/include/tst_safe_pthread.h b/kernel/tests/include/tst_safe_pthread.h
new file mode 100644
index 0000000..0c6d4d2
--- /dev/null
+++ b/kernel/tests/include/tst_safe_pthread.h
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2016 Oracle and/or its affiliates. All Rights Reserved.
+ */
+
+#ifndef TST_SAFE_PTHREAD_H__
+#define TST_SAFE_PTHREAD_H__
+
+/*
+ * Macro to use for making functions called only once in
+ * multi-threaded tests such as init or cleanup function.
+ * The first call to @name_fn function by any thread shall
+ * call the @exec_fn. Subsequent calls shall not call @exec_fn.
+ * *_fn functions must not take any arguments.
+ */
+#define TST_DECLARE_ONCE_FN(name_fn, exec_fn) \
+ void name_fn(void) \
+ { \
+ static pthread_once_t ltp_once = PTHREAD_ONCE_INIT; \
+ pthread_once(&ltp_once, exec_fn); \
+ }
+
+int safe_pthread_create(const char *file, const int lineno,
+ pthread_t *thread_id, const pthread_attr_t *attr,
+ void *(*thread_fn)(void *), void *arg);
+#define SAFE_PTHREAD_CREATE(thread_id, attr, thread_fn, arg) \
+ safe_pthread_create(__FILE__, __LINE__, thread_id, attr, thread_fn, arg)
+
+int safe_pthread_join(const char *file, const int lineno,
+ pthread_t thread_id, void **retval);
+#define SAFE_PTHREAD_JOIN(thread_id, retval) \
+ safe_pthread_join(__FILE__, __LINE__, thread_id, retval)
+
+#endif /* TST_SAFE_PTHREAD_H__ */
diff --git a/kernel/tests/include/tst_safe_stdio.h b/kernel/tests/include/tst_safe_stdio.h
new file mode 100644
index 0000000..e4bff34
--- /dev/null
+++ b/kernel/tests/include/tst_safe_stdio.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2013-2016 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#ifndef TST_SAFE_STDIO_H__
+#define TST_SAFE_STDIO_H__
+
+#include <stdio.h>
+
+#include "safe_stdio_fn.h"
+
+#define SAFE_FOPEN(path, mode) \
+ safe_fopen(__FILE__, __LINE__, NULL, path, mode)
+
+#define SAFE_FCLOSE(f) \
+ safe_fclose(__FILE__, __LINE__, NULL, f)
+
+#define SAFE_ASPRINTF(strp, fmt, ...) \
+ safe_asprintf(__FILE__, __LINE__, NULL, strp, fmt, __VA_ARGS__)
+
+#define SAFE_POPEN(command, type) \
+ safe_popen(__FILE__, __LINE__, NULL, command, type)
+
+#endif /* TST_SAFE_STDIO_H__ */
diff --git a/kernel/tests/include/tst_safe_sysv_ipc.h b/kernel/tests/include/tst_safe_sysv_ipc.h
new file mode 100644
index 0000000..3e0e50e
--- /dev/null
+++ b/kernel/tests/include/tst_safe_sysv_ipc.h
@@ -0,0 +1,54 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2017 Xiao yang <yangx.jy@cn.fujitsu.com>
+ */
+
+#ifndef TST_SAFE_SYSV_IPC_H__
+#define TST_SAFE_SYSV_IPC_H__
+
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <sys/shm.h>
+
+int safe_msgget(const char *file, const int lineno, key_t key, int msgflg);
+#define SAFE_MSGGET(key, msgflg) \
+ safe_msgget(__FILE__, __LINE__, (key), (msgflg))
+
+int safe_msgsnd(const char *file, const int lineno, int msqid, const void *msgp,
+ size_t msgsz, int msgflg);
+#define SAFE_MSGSND(msqid, msgp, msgsz, msgflg) \
+ safe_msgsnd(__FILE__, __LINE__, (msqid), (msgp), (msgsz), (msgflg))
+
+ssize_t safe_msgrcv(const char *file, const int lineno, int msqid, void *msgp,
+ size_t msgsz, long msgtyp, int msgflg);
+#define SAFE_MSGRCV(msqid, msgp, msgsz, msgtyp, msgflg) \
+ safe_msgrcv(__FILE__, __LINE__, (msqid), (msgp), (msgsz), (msgtyp), (msgflg))
+
+int safe_msgctl(const char *file, const int lineno, int msqid, int cmd,
+ struct msqid_ds *buf);
+#define SAFE_MSGCTL(msqid, cmd, buf) ({ \
+ int tst_ret_ = safe_msgctl(__FILE__, __LINE__, (msqid), (cmd), (buf)); \
+ (msqid) = ((cmd) == IPC_RMID ? -1 : (msqid)); \
+ tst_ret_;})
+
+int safe_shmget(const char *file, const int lineno, key_t key, size_t size,
+ int shmflg);
+#define SAFE_SHMGET(key, size, shmflg) \
+ safe_shmget(__FILE__, __LINE__, (key), (size), (shmflg))
+
+void *safe_shmat(const char *file, const int lineno, int shmid,
+ const void *shmaddr, int shmflg);
+#define SAFE_SHMAT(shmid, shmaddr, shmflg) \
+ safe_shmat(__FILE__, __LINE__, (shmid), (shmaddr), (shmflg))
+
+int safe_shmdt(const char *file, const int lineno, const void *shmaddr);
+#define SAFE_SHMDT(shmaddr) safe_shmdt(__FILE__, __LINE__, (shmaddr))
+
+int safe_shmctl(const char *file, const int lineno, int shmid, int cmd,
+ struct shmid_ds *buf);
+#define SAFE_SHMCTL(shmid, cmd, buf) ({ \
+ int tst_ret_ = safe_shmctl(__FILE__, __LINE__, (shmid), (cmd), (buf)); \
+ (shmid) = ((cmd) == IPC_RMID ? -1 : (shmid)); \
+ tst_ret_;})
+
+#endif /* TST_SAFE_SYSV_IPC_H__ */
diff --git a/kernel/tests/include/tst_safe_timerfd.h b/kernel/tests/include/tst_safe_timerfd.h
new file mode 100644
index 0000000..526f128
--- /dev/null
+++ b/kernel/tests/include/tst_safe_timerfd.h
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Petr Vorel <pvorel@suse.cz>
+ */
+
+#ifndef TST_SAFE_TIMERFD_H__
+#define TST_SAFE_TIMERFD_H__
+
+#include "lapi/timerfd.h"
+
+int safe_timerfd_create(const char *file, const int lineno,
+ int clockid, int flags);
+
+#define SAFE_TIMERFD_CREATE(clockid, flags)\
+ safe_timerfd_create(__FILE__, __LINE__, (clockid), (flags))
+
+int safe_timerfd_gettime(const char *file, const int lineno,
+ int fd, struct itimerspec *curr_value);
+
+#define SAFE_TIMERFD_GETTIME(fd, curr_value)\
+ safe_timerfd_gettime(__FILE__, __LINE__, (fd), (curr_value))
+
+int safe_timerfd_settime(const char *file, const int lineno,
+ int fd, int flags,
+ const struct itimerspec *new_value,
+ struct itimerspec *old_value);
+
+#define SAFE_TIMERFD_SETTIME(fd, flags, new_value, old_value)\
+ safe_timerfd_settime(__FILE__, __LINE__, (fd), (flags), (new_value), \
+ (old_value))
+
+#endif /* SAFE_TIMERFD_H__ */
diff --git a/kernel/tests/include/tst_sig_proc.h b/kernel/tests/include/tst_sig_proc.h
new file mode 100644
index 0000000..b85981e
--- /dev/null
+++ b/kernel/tests/include/tst_sig_proc.h
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2016 Linux Test Project
+ */
+
+#ifndef TST_SIG_PROC_H__
+#define TST_SIG_PROC_H__
+
+#include <sys/types.h>
+
+pid_t create_sig_proc(int sig, int count, unsigned int usec);
+
+#endif /* TST_SIG_PROC_H__ */
diff --git a/kernel/tests/include/tst_sys_conf.h b/kernel/tests/include/tst_sys_conf.h
new file mode 100644
index 0000000..323e29a
--- /dev/null
+++ b/kernel/tests/include/tst_sys_conf.h
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2018 Jan Stancek <jstancek@redhat.com>
+ */
+
+#ifndef TST_SYS_CONF_H__
+#define TST_SYS_CONF_H__
+
+struct tst_sys_conf {
+ char path[PATH_MAX];
+ char value[PATH_MAX];
+ struct tst_sys_conf *next;
+};
+
+int tst_sys_conf_save_str(const char *path, const char *value);
+int tst_sys_conf_save(const char *path);
+void tst_sys_conf_restore(int verbose);
+void tst_sys_conf_dump(void);
+
+#endif
diff --git a/kernel/tests/include/tst_taint.h b/kernel/tests/include/tst_taint.h
new file mode 100644
index 0000000..bd8076c
--- /dev/null
+++ b/kernel/tests/include/tst_taint.h
@@ -0,0 +1,98 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2018 Michael Moese <mmoese@suse.de>
+ */
+
+/* Usage example
+ *
+ * ...
+ * #include "tst_test.h"
+ * ..
+ * static struct tst_test test = {
+ * ...
+ * .taint_check = TST_TAINT_W | TST_TAINT_D,
+ * ...
+ * };
+ *
+ * void run(void)
+ * {
+ * ...
+ * . test code here
+ * ...
+ * if (tst_taint_check() != 0)
+ * tst_res(TFAIL, "kernel has issues");
+ * else
+ * tst_res(TPASS, "kernel seems to be fine");
+ * }
+ *
+ *
+ *
+ * The above code checks whether the kernel issued a warning (TST_TAINT_W)
+ * or even died (TST_TAINT_D) during test execution.
+ * If these are set after running a test case, we most likely
+ * triggered a kernel bug.
+ *
+ * You do not need to use tst_taint_check() explicitly because it'll be called
+ * automatically at the end of testing by the LTP library if
+ * tst_test.taint_check in non-zero.
+ */
+
+#ifndef TST_TAINTED_H__
+#define TST_TAINTED_H__
+
+/*
+ * This are all 17 flags that are present in kernel 4.15
+ * see kernel/panic.c in kernel sources
+ *
+ * Not all of them are valid in all kernel versions.
+ */
+#define TST_TAINT_G (1 << 0) /* a module with non-GPL license loaded */
+#define TST_TAINT_F (1 << 1) /* a module was force-loaded */
+#define TST_TAINT_S (1 << 2) /* SMP with Non-SMP kernel */
+#define TST_TAINT_R (1 << 3) /* module force unloaded */
+#define TST_TAINT_M (1 << 4) /* machine check error occurred */
+#define TST_TAINT_B (1 << 5) /* page-release function found bad page */
+#define TST_TAINT_U (1 << 6) /* user requested taint flag */
+#define TST_TAINT_D (1 << 7) /* kernel died recently - OOPS or BUG */
+#define TST_TAINT_A (1 << 8) /* ACPI table has been overwritten */
+#define TST_TAINT_W (1 << 9) /* a warning has been issued by kernel */
+#define TST_TAINT_C (1 << 10) /* driver from drivers/staging was loaded */
+#define TST_TAINT_I (1 << 11) /* working around BIOS/Firmware bug */
+#define TST_TAINT_O (1 << 12) /* out of tree module loaded */
+#define TST_TAINT_E (1 << 13) /* unsigned module was loaded */
+#define TST_TAINT_L (1 << 14) /* A soft lock-up has previously occurred */
+#define TST_TAINT_K (1 << 15) /* kernel has been live-patched */
+#define TST_TAINT_X (1 << 16) /* auxiliary taint, for distro's use */
+#define TST_TAINT_T (1 << 17) /* kernel was built with the struct randomization plugin */
+
+/*
+ * Initialize and prepare support for checking tainted kernel. Called
+ * automatically by LTP library during test setup if tst_test.taint_check
+ * is non-zero. The value of tst_test.taint_check will be passed as the mask
+ * argument.
+ *
+ * supply the mask of TAINT-flags you want to check, for example
+ * (TST_TAINT_W | TST_TAINT_D) when you want to check if the kernel issued
+ * a warning or even reported it died.
+ *
+ * This function tests if the requested flags are supported on the
+ * locally running kernel. In case the tainted-flags are already set by
+ * the kernel, there is no reason to continue and TBROK is generated.
+ *
+ * The mask must not be zero.
+ */
+void tst_taint_init(unsigned int mask);
+
+
+/*
+ * check if the tainted flags handed to tst_taint_init() are still not set
+ * during or after running the test.
+ * Calling this function is only allowed after tst_taint_init() was called,
+ * otherwise TBROK will be generated.
+ *
+ * returns 0 or a bitmask of the flags that currently tainted the kernel.
+ */
+unsigned int tst_taint_check(void);
+
+
+#endif /* TST_TAINTED_H__ */
diff --git a/kernel/tests/include/tst_test.h b/kernel/tests/include/tst_test.h
new file mode 100644
index 0000000..c91d3f1
--- /dev/null
+++ b/kernel/tests/include/tst_test.h
@@ -0,0 +1,335 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2015-2016 Cyril Hrubis <chrubis@suse.cz>
+ * Copyright (c) Linux Test Project, 2016-2019
+ */
+
+#ifndef TST_TEST_H__
+#define TST_TEST_H__
+
+#ifdef __TEST_H__
+# error Oldlib test.h already included
+#endif /* __TEST_H__ */
+
+#include <unistd.h>
+#include <limits.h>
+#include <string.h>
+#include <errno.h>
+
+#include "tst_common.h"
+#include "tst_res_flags.h"
+#include "tst_checkpoint.h"
+#include "tst_device.h"
+#include "tst_mkfs.h"
+#include "tst_fs.h"
+#include "tst_pid.h"
+#include "tst_cmd.h"
+#include "tst_cpu.h"
+#include "tst_process_state.h"
+#include "tst_atomic.h"
+#include "tst_kvercmp.h"
+#include "tst_clone.h"
+#include "tst_kernel.h"
+#include "tst_minmax.h"
+#include "tst_get_bad_addr.h"
+#include "tst_path_has_mnt_flags.h"
+#include "tst_sys_conf.h"
+#include "tst_coredump.h"
+#include "tst_buffers.h"
+#include "tst_capability.h"
+#include "tst_hugepage.h"
+#include "tst_assert.h"
+#include "tst_cgroup.h"
+#include "tst_lockdown.h"
+#include "tst_taint.h"
+
+/*
+ * Reports testcase result.
+ */
+void tst_res_(const char *file, const int lineno, int ttype,
+ const char *fmt, ...)
+ __attribute__ ((format (printf, 4, 5)));
+
+#define tst_res(ttype, arg_fmt, ...) \
+ ({ \
+ TST_RES_SUPPORTS_TCONF_TFAIL_TINFO_TPASS_TWARN(!((TTYPE_RESULT(ttype) ?: TCONF) & \
+ (TCONF | TFAIL | TINFO | TPASS | TWARN))); \
+ tst_res_(__FILE__, __LINE__, (ttype), (arg_fmt), ##__VA_ARGS__);\
+ })
+
+void tst_resm_hexd_(const char *file, const int lineno, int ttype,
+ const void *buf, size_t size, const char *arg_fmt, ...)
+ __attribute__ ((format (printf, 6, 7)));
+
+#define tst_res_hexd(ttype, buf, size, arg_fmt, ...) \
+ tst_resm_hexd_(__FILE__, __LINE__, (ttype), (buf), (size), \
+ (arg_fmt), ##__VA_ARGS__)
+
+/*
+ * Reports result and exits a test.
+ */
+void tst_brk_(const char *file, const int lineno, int ttype,
+ const char *fmt, ...)
+ __attribute__ ((format (printf, 4, 5)));
+
+#define tst_brk(ttype, arg_fmt, ...) \
+ ({ \
+ TST_BRK_SUPPORTS_ONLY_TCONF_TBROK(!((ttype) & \
+ (TBROK | TCONF | TFAIL))); \
+ tst_brk_(__FILE__, __LINE__, (ttype), (arg_fmt), ##__VA_ARGS__);\
+ })
+
+/* flush stderr and stdout */
+void tst_flush(void);
+
+pid_t safe_fork(const char *filename, unsigned int lineno);
+#define SAFE_FORK() \
+ safe_fork(__FILE__, __LINE__)
+
+#define TST_TRACE(expr) \
+ ({int ret = expr; \
+ ret != 0 ? tst_res(TINFO, #expr " failed"), ret : ret; }) \
+
+#include "tst_safe_macros.h"
+#include "tst_safe_file_ops.h"
+#include "tst_safe_net.h"
+
+/*
+ * Wait for all children and exit with TBROK if
+ * any of them returned a non-zero exit status.
+ */
+void tst_reap_children(void);
+
+struct tst_option {
+ char *optstr;
+ char **arg;
+ char *help;
+};
+
+/*
+ * Options parsing helpers.
+ *
+ * If str is NULL these are No-op.
+ *
+ * On failure non-zero (errno) is returned.
+ */
+int tst_parse_int(const char *str, int *val, int min, int max);
+int tst_parse_long(const char *str, long *val, long min, long max);
+int tst_parse_float(const char *str, float *val, float min, float max);
+
+struct tst_tag {
+ const char *name;
+ const char *value;
+};
+
+extern unsigned int tst_variant;
+
+struct tst_test {
+ /* number of tests available in test() function */
+ unsigned int tcnt;
+
+ struct tst_option *options;
+
+ const char *min_kver;
+
+ /* If set the test is compiled out */
+ const char *tconf_msg;
+
+ int needs_tmpdir:1;
+ int needs_root:1;
+ int forks_child:1;
+ int needs_device:1;
+ int needs_checkpoints:1;
+ int needs_overlay:1;
+ int format_device:1;
+ int mount_device:1;
+ int needs_rofs:1;
+ int child_needs_reinit:1;
+ int needs_devfs:1;
+ int restore_wallclock:1;
+ /*
+ * If set the test function will be executed for all available
+ * filesystems and the current filesytem type would be set in the
+ * tst_device->fs_type.
+ *
+ * The test setup and cleanup are executed before/after __EACH__ call
+ * to the test function.
+ */
+ int all_filesystems:1;
+
+ /*
+ * If set non-zero number of request_hugepages, test will try to reserve the
+ * expected number of hugepage for testing in setup phase. If system does not
+ * have enough hpage for using, it will try the best to reserve 80% available
+ * number of hpages. With success test stores the reserved hugepage number in
+ * 'tst_hugepages. For the system without hugetlb supporting, variable
+ * 'tst_hugepages' will be set to 0.
+ *
+ * Also, we do cleanup and restore work for the hpages resetting automatically.
+ */
+ unsigned long request_hugepages;
+
+ /*
+ * If set to non-zero, call tst_taint_init(taint_check) during setup
+ * and check kernel taint at the end of the test. If all_filesystems
+ * is non-zero, taint check will be performed after each FS test and
+ * testing will be terminated by TBROK if taint is detected.
+ */
+ unsigned int taint_check;
+
+ /*
+ * If set non-zero denotes number of test variant, the test is executed
+ * variants times each time with tst_variant set to different number.
+ *
+ * This allows us to run the same test for different settings. The
+ * intended use is to test different syscall wrappers/variants but the
+ * API is generic and does not limit the usage in any way.
+ */
+ unsigned int test_variants;
+
+ /* Minimal device size in megabytes */
+ unsigned int dev_min_size;
+
+ /* Device filesystem type override NULL == default */
+ const char *dev_fs_type;
+ /* Flags to be passed to tst_get_supported_fs_types() */
+ int dev_fs_flags;
+
+ /* Options passed to SAFE_MKFS() when format_device is set */
+ const char *const *dev_fs_opts;
+ const char *const *dev_extra_opts;
+
+ /* Device mount options, used if mount_device is set */
+ const char *mntpoint;
+ unsigned int mnt_flags;
+ void *mnt_data;
+
+ /* override default timeout per test run, disabled == -1 */
+ int timeout;
+
+ void (*setup)(void);
+ void (*cleanup)(void);
+
+ void (*test)(unsigned int test_nr);
+ void (*test_all)(void);
+
+ /* Syscall name used by the timer measurement library */
+ const char *scall;
+
+ /* Sampling function for timer measurement testcases */
+ int (*sample)(int clk_id, long long usec);
+
+ /* NULL terminated array of resource file names */
+ const char *const *resource_files;
+
+ /* NULL terminated array of needed kernel drivers */
+ const char * const *needs_drivers;
+
+ /*
+ * NULL terminated array of (/proc, /sys) files to save
+ * before setup and restore after cleanup
+ */
+ const char * const *save_restore;
+
+ /*
+ * NULL terminated array of kernel config options required for the
+ * test.
+ */
+ const char *const *needs_kconfigs;
+
+ /*
+ * NULL-terminated array to be allocated buffers.
+ */
+ struct tst_buffers *bufs;
+
+ /*
+ * NULL-terminated array of capability settings
+ */
+ struct tst_cap *caps;
+
+ /*
+ * {NULL, NULL} terminated array of tags.
+ */
+ const struct tst_tag *tags;
+
+ /* NULL terminated array of required commands */
+ const char *const *needs_cmds;
+};
+
+/*
+ * Runs tests.
+ */
+void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
+ __attribute__ ((noreturn));
+
+/*
+ * Does library initialization for child processes started by exec()
+ *
+ * The LTP_IPC_PATH variable must be passed to the program environment.
+ */
+void tst_reinit(void);
+
+//TODO Clean?
+#define TEST(SCALL) \
+ do { \
+ errno = 0; \
+ TST_RET = SCALL; \
+ TST_ERR = errno; \
+ } while (0)
+
+#define TEST_VOID(SCALL) \
+ do { \
+ errno = 0; \
+ SCALL; \
+ TST_ERR = errno; \
+ } while (0)
+
+extern long TST_RET;
+extern int TST_ERR;
+
+extern void *TST_RET_PTR;
+
+#define TESTPTR(SCALL) \
+ do { \
+ errno = 0; \
+ TST_RET_PTR = (void*)SCALL; \
+ TST_ERR = errno; \
+ } while (0)
+
+/*
+ * Functions to convert ERRNO to its name and SIGNAL to its name.
+ */
+const char *tst_strerrno(int err);
+const char *tst_strsig(int sig);
+/*
+ * Returns string describing status as returned by wait().
+ *
+ * BEWARE: Not thread safe.
+ */
+const char *tst_strstatus(int status);
+
+unsigned int tst_timeout_remaining(void);
+unsigned int tst_multiply_timeout(unsigned int timeout);
+void tst_set_timeout(int timeout);
+
+
+/*
+ * Returns path to the test temporary directory in a newly allocated buffer.
+ */
+char *tst_get_tmpdir(void);
+
+#ifndef TST_NO_DEFAULT_MAIN
+
+static struct tst_test test;
+
+int main(int argc, char *argv[])
+{
+ tst_run_tcases(argc, argv, &test);
+}
+
+#endif /* TST_NO_DEFAULT_MAIN */
+
+#define TST_TEST_TCONF(message) \
+ static struct tst_test test = { .tconf_msg = message } \
+
+#endif /* TST_TEST_H__ */
diff --git a/kernel/tests/include/tst_timer.h b/kernel/tests/include/tst_timer.h
new file mode 100644
index 0000000..d2c3f3c
--- /dev/null
+++ b/kernel/tests/include/tst_timer.h
@@ -0,0 +1,1055 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (C) 2015-2020 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+ /*
+
+ Timer - struct timespec conversion runtimes and easy to use functions to
+ measure elapsed time.
+
+ */
+
+#ifndef TST_TIMER
+#define TST_TIMER
+
+#include <sched.h>
+#include <sys/time.h>
+#include <mqueue.h>
+#include <time.h>
+#include "tst_test.h"
+#include "lapi/common_timers.h"
+#include "lapi/posix_types.h"
+#include "lapi/syscalls.h"
+
+/*
+ * Converts timeval to microseconds.
+ */
+static inline long long tst_timeval_to_us(struct timeval t)
+{
+ return t.tv_sec * 1000000 + t.tv_usec;
+}
+
+/*
+ * Converts timeval to milliseconds.
+ */
+static inline long long tst_timeval_to_ms(struct timeval t)
+{
+ return t.tv_sec * 1000 + (t.tv_usec + 500) / 1000;
+}
+
+/*
+ * Converts milliseconds to struct timeval
+ */
+static inline struct timeval tst_ms_to_timeval(long long ms)
+{
+ struct timeval ret;
+
+ ret.tv_sec = ms / 1000;
+ ret.tv_usec = (ms % 1000) * 1000;
+
+ return ret;
+}
+
+/*
+ * Converts microseconds to struct timeval
+ */
+static inline struct timeval tst_us_to_timeval(long long us)
+{
+ struct timeval ret;
+
+ ret.tv_sec = us / 1000000;
+ ret.tv_usec = us % 1000000;
+
+ return ret;
+}
+
+/*
+ * Returns difference between two timeval structures.
+ */
+static inline struct timeval tst_timeval_diff(struct timeval t1,
+ struct timeval t2)
+{
+ struct timeval res;
+
+ res.tv_sec = t1.tv_sec - t2.tv_sec;
+
+ if (t1.tv_usec < t2.tv_usec) {
+ res.tv_sec--;
+ res.tv_usec = 1000000 - (t2.tv_usec - t1.tv_usec);
+ } else {
+ res.tv_usec = t1.tv_usec - t2.tv_usec;
+ }
+
+ return res;
+}
+
+static inline long long tst_timeval_diff_us(struct timeval t1,
+ struct timeval t2)
+{
+ return tst_timeval_to_us(tst_timeval_diff(t1, t2));
+}
+
+static inline long long tst_timeval_diff_ms(struct timeval t1,
+ struct timeval t2)
+{
+ return tst_timeval_to_ms(tst_timeval_diff(t1, t2));
+}
+
+#ifndef __kernel_timespec
+
+typedef __kernel_long_t __kernel_old_time_t;
+
+struct __kernel_old_timeval {
+ __kernel_old_time_t tv_sec; /* seconds */
+ __kernel_suseconds_t tv_usec; /* microseconds */
+};
+
+struct __kernel_old_timespec {
+ __kernel_old_time_t tv_sec; /* seconds */
+ __kernel_old_time_t tv_nsec; /* nanoseconds */
+};
+
+typedef long long __kernel_time64_t;
+
+struct __kernel_timespec {
+ __kernel_time64_t tv_sec; /* seconds */
+ long long tv_nsec; /* nanoseconds */
+};
+
+struct __kernel_old_itimerspec {
+ struct __kernel_old_timespec it_interval; /* timer period */
+ struct __kernel_old_timespec it_value; /* timer expiration */
+};
+
+struct __kernel_itimerspec {
+ struct __kernel_timespec it_interval; /* timer period */
+ struct __kernel_timespec it_value; /* timer expiration */
+};
+#endif
+
+enum tst_ts_type {
+ TST_LIBC_TIMESPEC,
+ TST_KERN_OLD_TIMESPEC,
+ TST_KERN_TIMESPEC
+};
+
+struct tst_ts {
+ enum tst_ts_type type;
+ union ts {
+ struct timespec libc_ts;
+ struct __kernel_old_timespec kern_old_ts;
+ struct __kernel_timespec kern_ts;
+ } ts;
+};
+
+struct tst_its {
+ enum tst_ts_type type;
+ union {
+ struct __kernel_old_itimerspec kern_old_its;
+ struct __kernel_itimerspec kern_its;
+ } ts;
+};
+
+static inline void *tst_ts_get(struct tst_ts *t)
+{
+ if (!t)
+ return NULL;
+
+ switch (t->type) {
+ case TST_LIBC_TIMESPEC:
+ return &t->ts.libc_ts;
+ case TST_KERN_OLD_TIMESPEC:
+ return &t->ts.kern_old_ts;
+ case TST_KERN_TIMESPEC:
+ return &t->ts.kern_ts;
+ default:
+ tst_brk(TBROK, "Invalid type: %d", t->type);
+ return NULL;
+ }
+}
+
+static inline void *tst_its_get(struct tst_its *t)
+{
+ if (!t)
+ return NULL;
+
+ switch (t->type) {
+ case TST_KERN_OLD_TIMESPEC:
+ return &t->ts.kern_old_its;
+ case TST_KERN_TIMESPEC:
+ return &t->ts.kern_its;
+ default:
+ tst_brk(TBROK, "Invalid type: %d", t->type);
+ return NULL;
+ }
+}
+
+static inline int libc_clock_getres(clockid_t clk_id, void *ts)
+{
+ return clock_getres(clk_id, ts);
+}
+
+static inline int sys_clock_getres(clockid_t clk_id, void *ts)
+{
+ return tst_syscall(__NR_clock_getres, clk_id, ts);
+}
+
+static inline int sys_clock_getres64(clockid_t clk_id, void *ts)
+{
+ return tst_syscall(__NR_clock_getres_time64, clk_id, ts);
+}
+
+static inline int libc_clock_gettime(clockid_t clk_id, void *ts)
+{
+ return clock_gettime(clk_id, ts);
+}
+
+static inline int sys_clock_gettime(clockid_t clk_id, void *ts)
+{
+ return tst_syscall(__NR_clock_gettime, clk_id, ts);
+}
+
+static inline int sys_clock_gettime64(clockid_t clk_id, void *ts)
+{
+ return tst_syscall(__NR_clock_gettime64, clk_id, ts);
+}
+
+static inline int libc_clock_settime(clockid_t clk_id, void *ts)
+{
+ return clock_settime(clk_id, ts);
+}
+
+static inline int sys_clock_settime(clockid_t clk_id, void *ts)
+{
+ return tst_syscall(__NR_clock_settime, clk_id, ts);
+}
+
+static inline int sys_clock_settime64(clockid_t clk_id, void *ts)
+{
+ return tst_syscall(__NR_clock_settime64, clk_id, ts);
+}
+
+static inline int libc_clock_nanosleep(clockid_t clk_id, int flags,
+ void *request, void *remain)
+{
+ return clock_nanosleep(clk_id, flags, request, remain);
+}
+
+static inline int sys_clock_nanosleep(clockid_t clk_id, int flags,
+ void *request, void *remain)
+{
+ return tst_syscall(__NR_clock_nanosleep, clk_id, flags,
+ request, remain);
+}
+
+static inline int sys_clock_nanosleep64(clockid_t clk_id, int flags,
+ void *request, void *remain)
+{
+ return tst_syscall(__NR_clock_nanosleep_time64, clk_id, flags,
+ request, remain);
+}
+
+static inline int sys_futex(int *uaddr, int futex_op, int val, void *to,
+ int *uaddr2, int val3)
+{
+ return tst_syscall(__NR_futex, uaddr, futex_op, val, to, uaddr2, val3);
+}
+
+static inline int sys_futex_time64(int *uaddr, int futex_op, int val, void *to,
+ int *uaddr2, int val3)
+{
+ return tst_syscall(__NR_futex_time64, uaddr, futex_op, val, to, uaddr2, val3);
+}
+
+static inline int libc_mq_timedsend(mqd_t mqdes, const char *msg_ptr,
+ size_t msg_len, unsigned int msg_prio, void *abs_timeout)
+{
+ return mq_timedsend(mqdes, msg_ptr, msg_len, msg_prio, abs_timeout);
+}
+
+static inline int sys_mq_timedsend(mqd_t mqdes, const char *msg_ptr,
+ size_t msg_len, unsigned int msg_prio, void *abs_timeout)
+{
+ return tst_syscall(__NR_mq_timedsend, mqdes, msg_ptr, msg_len, msg_prio,
+ abs_timeout);
+}
+
+static inline int sys_mq_timedsend64(mqd_t mqdes, const char *msg_ptr,
+ size_t msg_len, unsigned int msg_prio, void *abs_timeout)
+{
+ return tst_syscall(__NR_mq_timedsend_time64, mqdes, msg_ptr, msg_len,
+ msg_prio, abs_timeout);
+}
+
+static inline ssize_t libc_mq_timedreceive(mqd_t mqdes, char *msg_ptr,
+ size_t msg_len, unsigned int *msg_prio, void *abs_timeout)
+{
+ return mq_timedreceive(mqdes, msg_ptr, msg_len, msg_prio, abs_timeout);
+}
+
+static inline ssize_t sys_mq_timedreceive(mqd_t mqdes, char *msg_ptr,
+ size_t msg_len, unsigned int *msg_prio, void *abs_timeout)
+{
+ return tst_syscall(__NR_mq_timedreceive, mqdes, msg_ptr, msg_len,
+ msg_prio, abs_timeout);
+}
+
+static inline ssize_t sys_mq_timedreceive64(mqd_t mqdes, char *msg_ptr,
+ size_t msg_len, unsigned int *msg_prio, void *abs_timeout)
+{
+ return tst_syscall(__NR_mq_timedreceive_time64, mqdes, msg_ptr, msg_len,
+ msg_prio, abs_timeout);
+}
+
+static inline int libc_sched_rr_get_interval(pid_t pid, void *ts)
+{
+ return sched_rr_get_interval(pid, ts);
+}
+
+static inline int sys_sched_rr_get_interval(pid_t pid, void *ts)
+{
+ return tst_syscall(__NR_sched_rr_get_interval, pid, ts);
+}
+
+static inline int sys_sched_rr_get_interval64(pid_t pid, void *ts)
+{
+ return tst_syscall(__NR_sched_rr_get_interval_time64, pid, ts);
+}
+
+static inline int sys_timer_gettime(kernel_timer_t timerid, void *its)
+{
+ return tst_syscall(__NR_timer_gettime, timerid, its);
+}
+
+static inline int sys_timer_gettime64(kernel_timer_t timerid, void *its)
+{
+ return tst_syscall(__NR_timer_gettime64, timerid, its);
+}
+
+static inline int sys_timer_settime(kernel_timer_t timerid, int flags, void *its,
+ void *old_its)
+{
+ return tst_syscall(__NR_timer_settime, timerid, flags, its, old_its);
+}
+
+static inline int sys_timer_settime64(kernel_timer_t timerid, int flags, void *its,
+ void *old_its)
+{
+ return tst_syscall(__NR_timer_settime64, timerid, flags, its, old_its);
+}
+
+static inline int sys_timerfd_gettime(int fd, void *its)
+{
+ return tst_syscall(__NR_timerfd_gettime, fd, its);
+}
+
+static inline int sys_timerfd_gettime64(int fd, void *its)
+{
+ return tst_syscall(__NR_timerfd_gettime64, fd, its);
+}
+
+static inline int sys_timerfd_settime(int fd, int flags, void *its,
+ void *old_its)
+{
+ return tst_syscall(__NR_timerfd_settime, fd, flags, its, old_its);
+}
+
+static inline int sys_timerfd_settime64(int fd, int flags, void *its,
+ void *old_its)
+{
+ return tst_syscall(__NR_timerfd_settime64, fd, flags, its, old_its);
+}
+
+/*
+ * Returns tst_ts seconds.
+ */
+static inline long long tst_ts_get_sec(struct tst_ts ts)
+{
+ switch (ts.type) {
+ case TST_LIBC_TIMESPEC:
+ return ts.ts.libc_ts.tv_sec;
+ case TST_KERN_OLD_TIMESPEC:
+ return ts.ts.kern_old_ts.tv_sec;
+ case TST_KERN_TIMESPEC:
+ return ts.ts.kern_ts.tv_sec;
+ default:
+ tst_brk(TBROK, "Invalid type: %d", ts.type);
+ return -1;
+ }
+}
+
+/*
+ * Returns tst_ts nanoseconds.
+ */
+static inline long long tst_ts_get_nsec(struct tst_ts ts)
+{
+ switch (ts.type) {
+ case TST_LIBC_TIMESPEC:
+ return ts.ts.libc_ts.tv_nsec;
+ case TST_KERN_OLD_TIMESPEC:
+ return ts.ts.kern_old_ts.tv_nsec;
+ case TST_KERN_TIMESPEC:
+ return ts.ts.kern_ts.tv_nsec;
+ default:
+ tst_brk(TBROK, "Invalid type: %d", ts.type);
+ return -1;
+ }
+}
+
+/*
+ * Sets tst_ts seconds.
+ */
+static inline void tst_ts_set_sec(struct tst_ts *ts, long long sec)
+{
+ switch (ts->type) {
+ case TST_LIBC_TIMESPEC:
+ ts->ts.libc_ts.tv_sec = sec;
+ break;
+ case TST_KERN_OLD_TIMESPEC:
+ ts->ts.kern_old_ts.tv_sec = sec;
+ break;
+ case TST_KERN_TIMESPEC:
+ ts->ts.kern_ts.tv_sec = sec;
+ break;
+ default:
+ tst_brk(TBROK, "Invalid type: %d", ts->type);
+ }
+}
+
+/*
+ * Sets tst_ts nanoseconds.
+ */
+static inline void tst_ts_set_nsec(struct tst_ts *ts, long long nsec)
+{
+ switch (ts->type) {
+ case TST_LIBC_TIMESPEC:
+ ts->ts.libc_ts.tv_nsec = nsec;
+ break;
+ case TST_KERN_OLD_TIMESPEC:
+ ts->ts.kern_old_ts.tv_nsec = nsec;
+ break;
+ case TST_KERN_TIMESPEC:
+ ts->ts.kern_ts.tv_nsec = nsec;
+ break;
+ default:
+ tst_brk(TBROK, "Invalid type: %d", ts->type);
+ }
+}
+
+/*
+ * Returns tst_its it_interval seconds.
+ */
+static inline long long tst_its_get_interval_sec(struct tst_its its)
+{
+ switch (its.type) {
+ case TST_KERN_OLD_TIMESPEC:
+ return its.ts.kern_old_its.it_interval.tv_sec;
+ case TST_KERN_TIMESPEC:
+ return its.ts.kern_its.it_interval.tv_sec;
+ default:
+ tst_brk(TBROK, "Invalid type: %d", its.type);
+ return -1;
+ }
+}
+
+/*
+ * Returns tst_its it_interval nanoseconds.
+ */
+static inline long long tst_its_get_interval_nsec(struct tst_its its)
+{
+ switch (its.type) {
+ case TST_KERN_OLD_TIMESPEC:
+ return its.ts.kern_old_its.it_interval.tv_nsec;
+ case TST_KERN_TIMESPEC:
+ return its.ts.kern_its.it_interval.tv_nsec;
+ default:
+ tst_brk(TBROK, "Invalid type: %d", its.type);
+ return -1;
+ }
+}
+
+/*
+ * Sets tst_its it_interval seconds.
+ */
+static inline void tst_its_set_interval_sec(struct tst_its *its, long long sec)
+{
+ switch (its->type) {
+ break;
+ case TST_KERN_OLD_TIMESPEC:
+ its->ts.kern_old_its.it_interval.tv_sec = sec;
+ break;
+ case TST_KERN_TIMESPEC:
+ its->ts.kern_its.it_interval.tv_sec = sec;
+ break;
+ default:
+ tst_brk(TBROK, "Invalid type: %d", its->type);
+ }
+}
+
+/*
+ * Sets tst_its it_interval nanoseconds.
+ */
+static inline void tst_its_set_interval_nsec(struct tst_its *its, long long nsec)
+{
+ switch (its->type) {
+ break;
+ case TST_KERN_OLD_TIMESPEC:
+ its->ts.kern_old_its.it_interval.tv_nsec = nsec;
+ break;
+ case TST_KERN_TIMESPEC:
+ its->ts.kern_its.it_interval.tv_nsec = nsec;
+ break;
+ default:
+ tst_brk(TBROK, "Invalid type: %d", its->type);
+ }
+}
+
+/*
+ * Returns tst_its it_value seconds.
+ */
+static inline long long tst_its_get_value_sec(struct tst_its its)
+{
+ switch (its.type) {
+ case TST_KERN_OLD_TIMESPEC:
+ return its.ts.kern_old_its.it_value.tv_sec;
+ case TST_KERN_TIMESPEC:
+ return its.ts.kern_its.it_value.tv_sec;
+ default:
+ tst_brk(TBROK, "Invalid type: %d", its.type);
+ return -1;
+ }
+}
+
+/*
+ * Returns tst_its it_value nanoseconds.
+ */
+static inline long long tst_its_get_value_nsec(struct tst_its its)
+{
+ switch (its.type) {
+ case TST_KERN_OLD_TIMESPEC:
+ return its.ts.kern_old_its.it_value.tv_nsec;
+ case TST_KERN_TIMESPEC:
+ return its.ts.kern_its.it_value.tv_nsec;
+ default:
+ tst_brk(TBROK, "Invalid type: %d", its.type);
+ return -1;
+ }
+}
+
+/*
+ * Sets tst_its it_value seconds.
+ */
+static inline void tst_its_set_value_sec(struct tst_its *its, long long sec)
+{
+ switch (its->type) {
+ break;
+ case TST_KERN_OLD_TIMESPEC:
+ its->ts.kern_old_its.it_value.tv_sec = sec;
+ break;
+ case TST_KERN_TIMESPEC:
+ its->ts.kern_its.it_value.tv_sec = sec;
+ break;
+ default:
+ tst_brk(TBROK, "Invalid type: %d", its->type);
+ }
+}
+
+/*
+ * Sets tst_its it_value nanoseconds.
+ */
+static inline void tst_its_set_value_nsec(struct tst_its *its, long long nsec)
+{
+ switch (its->type) {
+ break;
+ case TST_KERN_OLD_TIMESPEC:
+ its->ts.kern_old_its.it_value.tv_nsec = nsec;
+ break;
+ case TST_KERN_TIMESPEC:
+ its->ts.kern_its.it_value.tv_nsec = nsec;
+ break;
+ default:
+ tst_brk(TBROK, "Invalid type: %d", its->type);
+ }
+}
+
+/*
+ * Checks that timespec is valid, i.e. that the timestamp is not zero and that
+ * the nanoseconds are normalized i.e. in <0, 1s) interval.
+ *
+ * 0: On success, i.e. timespec updated correctly.
+ * -1: Error, timespec not updated.
+ * -2: Error, tv_nsec is corrupted.
+ */
+static inline int tst_ts_valid(struct tst_ts *t)
+{
+ long long nsec = tst_ts_get_nsec(*t);
+
+ if (nsec < 0 || nsec >= 1000000000)
+ return -2;
+
+ if (tst_ts_get_sec(*t) == 0 && tst_ts_get_nsec(*t) == 0)
+ return -1;
+
+ return 0;
+}
+
+/*
+ * Converts timespec to tst_ts.
+ */
+static inline struct tst_ts tst_ts_from_timespec(struct timespec ts)
+{
+ struct tst_ts t = {
+ .type = TST_LIBC_TIMESPEC,
+ .ts.libc_ts.tv_sec = ts.tv_sec,
+ .ts.libc_ts.tv_nsec = ts.tv_nsec,
+ };
+
+ return t;
+}
+
+/*
+ * Converst tst_ts into timespec.
+ */
+static inline struct timespec tst_ts_to_timespec(struct tst_ts t)
+{
+ return t.ts.libc_ts;
+}
+
+/*
+ * Converts tst_ts to nanoseconds.
+ */
+static inline long long tst_ts_to_ns(struct tst_ts t)
+{
+ return tst_ts_get_sec(t) * 1000000000 + tst_ts_get_nsec(t);
+}
+
+/*
+ * Converts tst_ts to microseconds and rounds the value.
+ */
+static inline long long tst_ts_to_us(struct tst_ts t)
+{
+ return tst_ts_get_sec(t) * 1000000 +
+ (tst_ts_get_nsec(t) + 500) / 1000;
+}
+
+/*
+ * Converts timespec to microseconds and rounds the value.
+ */
+static inline long long tst_timespec_to_us(struct timespec ts)
+{
+ return tst_ts_to_us(tst_ts_from_timespec(ts));
+}
+
+/*
+ * Converts tst_ts to milliseconds and rounds the value.
+ */
+static inline long long tst_ts_to_ms(struct tst_ts t)
+{
+ return tst_ts_get_sec(t) * 1000 +
+ (tst_ts_get_nsec(t) + 500000) / 1000000;
+}
+
+/*
+ * Converts timespec to milliseconds and rounds the value.
+ */
+static inline long long tst_timespec_to_ms(struct timespec ts)
+{
+ return tst_ts_to_ms(tst_ts_from_timespec(ts));
+}
+
+/*
+ * Converts nanoseconds to tst_ts
+ */
+static inline struct tst_ts
+tst_ts_from_ns(enum tst_ts_type type, long long ns)
+{
+ struct tst_ts ret = {.type = type};
+
+ tst_ts_set_sec(&ret, ns / 1000000000);
+ tst_ts_set_nsec(&ret, ns % 1000000000);
+
+ return ret;
+}
+
+/*
+ * Converts microseconds to tst_ts
+ */
+static inline struct tst_ts
+tst_ts_from_us(enum tst_ts_type type, long long us)
+{
+ struct tst_ts ret = {.type = type};
+
+ tst_ts_set_sec(&ret, us / 1000000);
+ tst_ts_set_nsec(&ret, (us % 1000000) * 1000);
+
+ return ret;
+}
+
+/*
+ * Converts microseconds to timespec
+ */
+static inline struct timespec
+tst_timespec_from_us(long long us)
+{
+ return tst_ts_to_timespec(tst_ts_from_us(TST_LIBC_TIMESPEC, us));
+}
+
+/*
+ * Converts miliseconds to tst_ts
+ */
+static inline struct tst_ts
+tst_ts_from_ms(enum tst_ts_type type, long long ms)
+{
+ struct tst_ts ret = {.type = type};
+
+ tst_ts_set_sec(&ret, ms / 1000);
+ tst_ts_set_nsec(&ret, (ms % 1000) * 1000000);
+
+ return ret;
+}
+
+/*
+ * Converts miliseconds to timespec
+ */
+static inline struct timespec
+tst_timespec_from_ms(long long ms)
+{
+ return tst_ts_to_timespec(tst_ts_from_ms(TST_LIBC_TIMESPEC, ms));
+}
+
+/*
+ * Sets tst_its it_value from microseconds.
+ */
+static inline void tst_its_set_interval_from_us(struct tst_its *its, long long usec)
+{
+ struct timespec tp = tst_timespec_from_us(usec);
+
+ tst_its_set_interval_sec(its, tp.tv_sec);
+ tst_its_set_interval_nsec(its, tp.tv_nsec);
+}
+
+/*
+ * Sets tst_its it_value from microseconds.
+ */
+static inline void tst_its_set_value_from_us(struct tst_its *its, long long usec)
+{
+ struct timespec tp = tst_timespec_from_us(usec);
+
+ tst_its_set_value_sec(its, tp.tv_sec);
+ tst_its_set_value_nsec(its, tp.tv_nsec);
+}
+
+/*
+ * Sets tst_its it_interval from tst_ts.
+ */
+static inline void tst_its_set_interval_from_ts(struct tst_its *its, struct tst_ts ts)
+{
+ tst_its_set_interval_sec(its, tst_ts_get_sec(ts));
+ tst_its_set_interval_nsec(its, tst_ts_get_nsec(ts));
+}
+
+/*
+ * Sets tst_its it_value from tst_ts.
+ */
+static inline void tst_its_set_value_from_ts(struct tst_its *its, struct tst_ts ts)
+{
+ tst_its_set_value_sec(its, tst_ts_get_sec(ts));
+ tst_its_set_value_nsec(its, tst_ts_get_nsec(ts));
+}
+
+/*
+ * Returns if t1 less than t2. Both t1 and t2 must be normalized.
+ */
+static inline int tst_ts_lt(struct tst_ts t1, struct tst_ts t2)
+{
+ if (tst_ts_get_sec(t1) == tst_ts_get_sec(t2))
+ return tst_ts_get_nsec(t1) < tst_ts_get_nsec(t2);
+
+ return tst_ts_get_sec(t1) < tst_ts_get_sec(t2);
+}
+
+/*
+ * Returns if ts1 less than ts2. Both ts1 and ts2 must be normalized.
+ */
+static inline int tst_timespec_lt(struct timespec ts1, struct timespec ts2)
+{
+ return tst_ts_lt(tst_ts_from_timespec(ts1), tst_ts_from_timespec(ts2));
+}
+
+/*
+ * Returns normalized tst_ts, i.e. 0 <= nsec < 1000000000.
+ */
+static inline struct tst_ts tst_ts_normalize(struct tst_ts t)
+{
+ long long sec = tst_ts_get_sec(t);
+ long long nsec = tst_ts_get_nsec(t);
+
+ if (nsec >= 1000000000) {
+ tst_ts_set_sec(&t, sec + 1);
+ tst_ts_set_nsec(&t, nsec - 1000000000);
+ }
+
+ if (nsec < 0) {
+ tst_ts_set_sec(&t, sec - 1);
+ tst_ts_set_nsec(&t, nsec + 1000000000);
+ }
+
+ return t;
+}
+
+/*
+ * Adds us microseconds to tst_ts.
+ */
+static inline struct tst_ts
+tst_ts_add_us(struct tst_ts t, long long us)
+{
+ struct tst_ts res = {.type = t.type};
+
+ tst_ts_set_sec(&res, tst_ts_get_sec(t) + us / 1000000);
+ tst_ts_set_nsec(&res, tst_ts_get_nsec(t) + (us % 1000000) * 1000);
+
+ return tst_ts_normalize(res);
+}
+
+/*
+ * Adds us microseconds to struct timespec.
+ */
+static inline struct timespec
+tst_timespec_add_us(struct timespec ts, long long us)
+{
+ struct tst_ts res;
+
+ res = tst_ts_add_us(tst_ts_from_timespec(ts), us);
+
+ return tst_ts_to_timespec(res);
+}
+
+/*
+ * Substracts us microseconds from tst_ts.
+ */
+static inline struct tst_ts
+tst_ts_sub_us(struct tst_ts t, long long us)
+{
+ struct tst_ts res = {.type = t.type};
+
+ tst_ts_set_sec(&res, tst_ts_get_sec(t) - us / 1000000);
+ tst_ts_set_nsec(&res, tst_ts_get_nsec(t) - (us % 1000000) * 1000);
+
+ return tst_ts_normalize(res);
+}
+
+/*
+ * Substracts us microseconds from timespec.
+ */
+static inline struct timespec
+tst_timespec_sub_us(struct timespec ts, long long us)
+{
+ struct tst_ts res;
+
+ res = tst_ts_sub_us(tst_ts_from_timespec(ts), us);
+
+ return tst_ts_to_timespec(res);
+}
+
+/*
+ * Adds two tst_ts structures.
+ */
+static inline struct tst_ts
+tst_ts_add(struct tst_ts t1, struct tst_ts t2)
+{
+ struct tst_ts res = {.type = t1.type};
+
+ tst_ts_set_sec(&res, tst_ts_get_sec(t1) + tst_ts_get_sec(t2));
+ tst_ts_set_nsec(&res, tst_ts_get_nsec(t1) + tst_ts_get_nsec(t2));
+
+ return tst_ts_normalize(res);
+}
+
+/*
+ * Adds two timespec structures.
+ */
+static inline struct timespec
+tst_timespec_add(struct timespec ts1, struct timespec ts2)
+{
+ struct tst_ts res;
+
+ res = tst_ts_add(tst_ts_from_timespec(ts1), tst_ts_from_timespec(ts2));
+
+ return tst_ts_to_timespec(res);
+}
+
+/*
+ * Substract two tst_ts structures.
+ */
+static inline struct tst_ts
+tst_ts_diff(struct tst_ts t1, struct tst_ts t2)
+{
+ struct tst_ts res = {.type = t1.type};
+
+ tst_ts_set_sec(&res, tst_ts_get_sec(t1) - tst_ts_get_sec(t2));
+ tst_ts_set_nsec(&res, tst_ts_get_nsec(t1) - tst_ts_get_nsec(t2));
+
+ return tst_ts_normalize(res);
+}
+
+/*
+ * Substract two timespec structures.
+ */
+static inline struct timespec
+tst_timespec_diff(struct timespec ts1, struct timespec ts2)
+{
+ struct tst_ts res;
+
+ res = tst_ts_diff(tst_ts_from_timespec(ts1), tst_ts_from_timespec(ts2));
+
+ return tst_ts_to_timespec(res);
+}
+
+/*
+ * Substract two tst_ts structures returns number of nanoseconds.
+ */
+static inline long long
+tst_ts_diff_ns(struct tst_ts t1, struct tst_ts t2)
+{
+ return tst_ts_to_ns(tst_ts_diff(t1, t2));
+}
+
+/*
+ * Substract two timespec structures returns number of nanoseconds.
+ */
+static inline long long
+tst_timespec_diff_ns(struct timespec ts1, struct timespec ts2)
+{
+ return tst_ts_diff_ns(tst_ts_from_timespec(ts1), tst_ts_from_timespec(ts2));
+}
+
+/*
+ * Substract two tst_ts structures returns number of microseconds.
+ */
+static inline long long
+tst_ts_diff_us(struct tst_ts t1, struct tst_ts t2)
+{
+ return tst_ts_to_us(tst_ts_diff(t1, t2));
+}
+
+/*
+ * Substract two timespec structures returns number of microseconds.
+ */
+static inline long long
+tst_timespec_diff_us(struct timespec ts1, struct timespec ts2)
+{
+ return tst_ts_diff_us(tst_ts_from_timespec(ts1), tst_ts_from_timespec(ts2));
+}
+
+/*
+ * Substract two tst_ts structures returns number of milliseconds.
+ */
+static inline long long
+tst_ts_diff_ms(struct tst_ts t1, struct tst_ts t2)
+{
+ return tst_ts_to_ms(tst_ts_diff(t1, t2));
+}
+
+/*
+ * Substract two timespec structures returns number of milliseconds.
+ */
+static inline long long
+tst_timespec_diff_ms(struct timespec ts1, struct timespec ts2)
+{
+ return tst_ts_diff_ms(tst_ts_from_timespec(ts1), tst_ts_from_timespec(ts2));
+}
+
+/*
+ * Returns absolute value of difference between two timespec structures.
+ */
+static inline struct tst_ts
+tst_ts_abs_diff(struct tst_ts t1, struct tst_ts t2)
+{
+ if (tst_ts_lt(t1, t2))
+ return tst_ts_diff(t2, t1);
+ else
+ return tst_ts_diff(t1, t2);
+}
+
+/*
+ * Returns absolute value of difference between two tst_ts structures in
+ * microseconds.
+ */
+static inline long long
+tst_ts_abs_diff_us(struct tst_ts t1, struct tst_ts t2)
+{
+ return tst_ts_to_us(tst_ts_abs_diff(t1, t2));
+}
+
+/*
+ * Returns absolute value of difference between two timespec structures in
+ * microseconds.
+ */
+static inline long long
+tst_timespec_abs_diff_us(struct timespec ts1, struct timespec ts2)
+{
+ return tst_ts_abs_diff_us(tst_ts_from_timespec(ts1), tst_ts_from_timespec(ts2));
+}
+
+/*
+ * Returns absolute value of difference between two timespec structures in
+ * milliseconds.
+ */
+static inline long long
+tst_ts_abs_diff_ms(struct tst_ts t1, struct tst_ts t2)
+{
+ return tst_ts_to_ms(tst_ts_abs_diff(t1, t2));
+}
+
+/*
+ * Exits the test with TCONF if particular timer is not supported. This is
+ * intended to be used in test setup. There is no cleanup callback parameter as
+ * you are expected to call it before initializing any resources that has to be
+ * cleaned up later.
+ *
+ * @clk_id: Posix clock to use.
+ */
+void tst_timer_check(clockid_t clk_id);
+
+/*
+ * Marks a start time for given clock type.
+ *
+ * @clk_id: Posix clock to use.
+ */
+void tst_timer_start(clockid_t clk_id);
+
+/*
+ * Returns true if timer started by tst_timer_start() has been running for
+ * longer than ms seconds.
+ *
+ * @ms: Time interval in milliseconds.
+ */
+int tst_timer_expired_ms(long long ms);
+
+/*
+ * Marks timer end time.
+ */
+void tst_timer_stop(void);
+
+/*
+ * Retuns elapsed time in struct timespec.
+ */
+struct timespec tst_timer_elapsed(void);
+
+/*
+ * Returns elapsed time in milliseconds.
+ */
+static inline long long tst_timer_elapsed_ms(void)
+{
+ return tst_timespec_to_ms(tst_timer_elapsed());
+}
+
+/*
+ * Returns elapsed time in microseconds.
+ */
+static inline long long tst_timer_elapsed_us(void)
+{
+ return tst_timespec_to_us(tst_timer_elapsed());
+}
+
+#endif /* TST_TIMER */
diff --git a/kernel/tests/include/tst_timer_test.h b/kernel/tests/include/tst_timer_test.h
new file mode 100644
index 0000000..b825a4d
--- /dev/null
+++ b/kernel/tests/include/tst_timer_test.h
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+ /*
+
+ Timer measuring library.
+
+ The test is supposed to define sampling function and set it in the tst_test
+ structure the rest of the work is then done by the library.
+
+ int sample(int clk_id, long long usec)
+ {
+ // Any setup done here
+
+ tst_timer_start(clk_id);
+ // Call that is being measured sleeps for usec
+ tst_timer_stop();
+ tst_timer_sample();
+
+ // Any cleanup done here
+
+ // Non-zero return exits the test
+ }
+
+ struct tst_test test = {
+ .scall = "syscall_name()",
+ .sample = sample,
+ };
+
+ */
+
+#ifndef TST_TIMER_TEST__
+#define TST_TIMER_TEST__
+
+#include "tst_test.h"
+#include "tst_timer.h"
+
+void tst_timer_sample(void);
+
+# ifdef TST_NO_DEFAULT_MAIN
+struct tst_test *tst_timer_test_setup(struct tst_test *test);
+# endif /* TST_NO_DEFAULT_MAIN */
+#endif /* TST_TIMER_TEST__ */
diff --git a/kernel/tests/include/tst_uinput.h b/kernel/tests/include/tst_uinput.h
new file mode 100644
index 0000000..cf351cd
--- /dev/null
+++ b/kernel/tests/include/tst_uinput.h
@@ -0,0 +1,47 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#ifndef TST_UINPUT_H__
+#define TST_UINPUT_H__
+
+/**
+ * Tries to open the uinput device.
+ *
+ * Returns file descriptor on success, -1 on failure.
+ */
+int open_uinput(void);
+
+/**
+ * Creates virtual input device.
+ *
+ * @fd File descriptor returned by open_uinput().
+ */
+void create_input_device(int fd);
+
+/**
+ * Parses /proc/bus/input/devices and returns the strings for our virtual device.
+ * If passing 'H' to it, it returns HANDLERS string. If passing 'S' to it, it
+ * returns SYSFS string.
+ *
+ * Returns newly allocated string, or NULL in a case of failure.
+ */
+char *get_input_field_value(char field);
+
+/**
+ * Sets up the virtual device to appear as a mouse, this must be called before
+ * the call to create_input_device().
+ *
+ * @fd File descriptor as returned by open_uinput().
+ */
+void setup_mouse_events(int fd);
+
+/**
+ * Destroys virtual input device.
+ *
+ * @fd File descriptor returned by open_uinput().
+ */
+void destroy_input_device(int fd);
+
+#endif /* TST_UINPUT_H__ */
diff --git a/kernel/tests/include/tst_wallclock.h b/kernel/tests/include/tst_wallclock.h
new file mode 100644
index 0000000..7d6723a
--- /dev/null
+++ b/kernel/tests/include/tst_wallclock.h
@@ -0,0 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Linaro Limited. All rights reserved.
+ * Author: Rafael David Tinoco <rafael.tinoco@linaro.org>
+ */
+
+
+#ifndef TST_WALLCLK_H__
+#define TST_WALLCLK_H__
+
+void tst_wallclock_save(void);
+
+void tst_wallclock_restore(void);
+
+#endif /* TST_WALLCLK_H__ */
diff --git a/kernel/tests/lib/CMakeLists.txt b/kernel/tests/lib/CMakeLists.txt
new file mode 100644
index 0000000..9cea565
--- /dev/null
+++ b/kernel/tests/lib/CMakeLists.txt
@@ -0,0 +1,69 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(xloop-kernel-test-lib)
+
+add_library(libltp STATIC ${CMAKE_CURRENT_SOURCE_DIR}/cloner.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/get_path.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/parse_opts.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/random_range.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/safe_file_ops.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/safe_macros.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/safe_net.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/safe_pthread.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/safe_stdio.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/self_exec.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tlibio.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_af_alg.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_ansi_color.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_assert.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_buffers.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_capability.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_cgroup.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_checkpoint.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_checksum.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_clocks.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_cmd.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_coredump.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_cpu.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_crypto.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_device.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_dir_is_empty.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_fill_file.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_fill_fs.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_fs_has_free.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_fs_link_count.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_fs_setup.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_fs_type.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_get_bad_addr.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_hugepage.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_ioctl.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_kconfig.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_kernel.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_kvercmp.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_lockdown.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_memutils.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_mkfs.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_module.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_net.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_parse_opts.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_path_has_mnt_flags.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_pid.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_process_state.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_res.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_resource.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_safe_macros.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_safe_sysv_ipc.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_safe_timerfd.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_sig.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_sig_proc.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_status.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_supported_fs_types.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_sys_conf.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_taint.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_test.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_timer.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_timer_test.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_tmpdir.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_virt.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_wallclock.c)
+target_include_directories(libltp PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
diff --git a/kernel/tests/lib/cloner.c b/kernel/tests/lib/cloner.c
new file mode 100644
index 0000000..11401f2
--- /dev/null
+++ b/kernel/tests/lib/cloner.c
@@ -0,0 +1,175 @@
+/*
+ * Copyright (c) International Business Machines Corp., 2009
+ * Some wrappers for clone functionality. Thrown together by Serge Hallyn
+ * <serue@us.ibm.com> based on existing clone usage in ltp.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ * the GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE
+#endif
+
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sched.h>
+#include <stdarg.h>
+#include "config.h"
+#include "tst_clone.h"
+
+#undef clone /* we want to use clone() */
+
+/*
+ * The ia64 port has never included a prototype for __clone2(). It was updated
+ * to take eight parameters in glibc commit:
+ *
+ * commit 625f22fc7f8e0d61e3e6cff2c65468b91dbad426
+ * Author: Ulrich Drepper <drepper@redhat.com>
+ * Date: Mon Mar 3 19:53:27 2003 +0000
+ *
+ * The first release that contained this commit was glibc-2.3.3 which is old
+ * enough to assume that __clone2() takes eight parameters.
+ */
+#if defined(__ia64__)
+extern int __clone2(int (*fn) (void *arg), void *child_stack_base,
+ size_t child_stack_size, int flags, void *arg,
+ pid_t *parent_tid, void *tls, pid_t *child_tid);
+#endif
+
+#ifndef CLONE_SUPPORTS_7_ARGS
+# define clone(fn, stack, flags, arg, ptid, tls, ctid) \
+ clone(fn, stack, flags, arg)
+#endif
+
+/*
+ * ltp_clone: wrapper for clone to hide the architecture dependencies.
+ * 1. hppa takes bottom of stack and no stacksize (stack grows up)
+ * 2. __ia64__ takes bottom of stack and uses clone2
+ * 3. all others take top of stack (stack grows down)
+ */
+static int
+ltp_clone_(unsigned long flags, int (*fn)(void *arg), void *arg,
+ size_t stack_size, void *stack, pid_t *ptid, void *tls, pid_t *ctid)
+{
+ int ret;
+
+#if defined(__ia64__)
+ ret = __clone2(fn, stack, stack_size, flags, arg, ptid, tls, ctid);
+#else
+# if defined(__hppa__) || defined(__metag__)
+ /*
+ * These arches grow their stack up, so don't need to adjust the base.
+ * XXX: This should be made into a runtime test.
+ */
+# else
+ /*
+ * For archs where stack grows downwards, stack points to the topmost
+ * address of the memory space set up for the child stack.
+ */
+ if (stack)
+ stack += stack_size;
+# endif
+
+ ret = clone(fn, stack, flags, arg, ptid, tls, ctid);
+#endif
+
+ return ret;
+}
+
+int ltp_clone(unsigned long flags, int (*fn)(void *arg), void *arg,
+ size_t stack_size, void *stack)
+{
+ return ltp_clone_(flags, fn, arg, stack_size, stack, NULL, NULL, NULL);
+}
+
+int ltp_clone7(unsigned long flags, int (*fn)(void *arg), void *arg,
+ size_t stack_size, void *stack, ...)
+{
+ pid_t *ptid, *ctid;
+ void *tls;
+ va_list arg_clone;
+
+ va_start(arg_clone, stack);
+ ptid = va_arg(arg_clone, pid_t *);
+ tls = va_arg(arg_clone, void *);
+ ctid = va_arg(arg_clone, pid_t *);
+ va_end(arg_clone);
+
+#ifdef CLONE_SUPPORTS_7_ARGS
+ return ltp_clone_(flags, fn, arg, stack_size, stack, ptid, tls, ctid);
+#else
+ errno = ENOSYS;
+ return -1;
+#endif
+}
+
+/*
+ * ltp_alloc_stack: allocate stack of size 'size', that is sufficiently
+ * aligned for all arches. User is responsible for freeing allocated
+ * memory.
+ * Returns pointer to new stack. On error, returns NULL with errno set.
+ */
+void *ltp_alloc_stack(size_t size)
+{
+ void *ret = NULL;
+ int err;
+
+ err = posix_memalign(&ret, 64, size);
+ if (err)
+ errno = err;
+
+ return ret;
+}
+
+/*
+ * ltp_clone_alloc: also does the memory allocation for clone with a
+ * caller-specified size.
+ */
+int
+ltp_clone_alloc(unsigned long clone_flags, int (*fn) (void *arg), void *arg,
+ size_t stack_size)
+{
+ void *stack;
+ int ret;
+ int saved_errno;
+
+ stack = ltp_alloc_stack(stack_size);
+ if (stack == NULL)
+ return -1;
+
+ ret = ltp_clone(clone_flags, fn, arg, stack_size, stack);
+
+ if (ret == -1) {
+ saved_errno = errno;
+ free(stack);
+ errno = saved_errno;
+ }
+
+ return ret;
+}
+
+/*
+ * ltp_clone_quick: calls ltp_clone_alloc with predetermined stack size.
+ * Experience thus far suggests that one page is often insufficient,
+ * while 6*getpagesize() seems adequate.
+ */
+int ltp_clone_quick(unsigned long clone_flags, int (*fn) (void *arg), void *arg)
+{
+ size_t stack_size = getpagesize() * 6;
+
+ return ltp_clone_alloc(clone_flags, fn, arg, stack_size);
+}
diff --git a/kernel/tests/lib/errnos.h b/kernel/tests/lib/errnos.h
new file mode 100644
index 0000000..df8fea8
--- /dev/null
+++ b/kernel/tests/lib/errnos.h
@@ -0,0 +1,186 @@
+/*
+ * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
+ * Copyright (c) 2009-2013 Cyril Hrubis <chrubis@suse.cz>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it is
+ * free of the rightful claim of any third person regarding infringement
+ * or the like. Any license provided herein, whether implied or
+ * otherwise, applies only to this software file. Patent licenses, if
+ * any, provided herein do not apply to combinations of this program with
+ * other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
+ * Mountain View, CA 94043, or:
+ */
+
+const char *tst_strerrno(int err)
+{
+ static const struct pair errno_pairs[] = {
+ STRPAIR(0, "SUCCESS")
+ /* asm-generic/errno-base.h */
+ PAIR(EPERM)
+ PAIR(ENOENT)
+ PAIR(ESRCH)
+ PAIR(EINTR)
+ PAIR(EIO)
+ PAIR(ENXIO)
+ PAIR(E2BIG)
+ PAIR(ENOEXEC)
+ PAIR(EBADF)
+ PAIR(ECHILD)
+ STRPAIR(EAGAIN, "EAGAIN/EWOULDBLOCK")
+ PAIR(ENOMEM)
+ PAIR(EACCES)
+ PAIR(EFAULT)
+ PAIR(ENOTBLK)
+ PAIR(EBUSY)
+ PAIR(EEXIST)
+ PAIR(EXDEV)
+ PAIR(ENODEV)
+ PAIR(ENOTDIR)
+ PAIR(EISDIR)
+ PAIR(EINVAL)
+ PAIR(ENFILE)
+ PAIR(EMFILE)
+ PAIR(ENOTTY)
+ PAIR(ETXTBSY)
+ PAIR(EFBIG)
+ PAIR(ENOSPC)
+ PAIR(ESPIPE)
+ PAIR(EROFS)
+ PAIR(EMLINK)
+ PAIR(EPIPE)
+ PAIR(EDOM)
+ PAIR(ERANGE)
+ /* asm-generic/errno.h */
+ PAIR(EDEADLK)
+ PAIR(ENAMETOOLONG)
+ PAIR(ENOLCK)
+ PAIR(ENOSYS)
+ PAIR(ENOTEMPTY)
+ PAIR(ELOOP)
+ /* EWOULDBLOCK == EAGAIN skipped */
+ PAIR(ENOMSG)
+ PAIR(EIDRM)
+ PAIR(ECHRNG)
+ PAIR(EL2NSYNC)
+ PAIR(EL3HLT)
+ PAIR(EL3RST)
+ PAIR(ELNRNG)
+ PAIR(EUNATCH)
+ PAIR(ENOCSI)
+ PAIR(EL2HLT)
+ PAIR(EBADE)
+ PAIR(EBADR)
+ PAIR(EXFULL)
+ PAIR(ENOANO)
+ PAIR(EBADRQC)
+ PAIR(EBADSLT)
+ /* EDEADLOCK == EDEADLK skipped */
+ PAIR(EBFONT)
+ PAIR(ENOSTR)
+ PAIR(ENODATA)
+ PAIR(ETIME)
+ PAIR(ENOSR)
+ PAIR(ENONET)
+ PAIR(ENOPKG)
+ PAIR(EREMOTE)
+ PAIR(ENOLINK)
+ PAIR(EADV)
+ PAIR(ESRMNT)
+ PAIR(ECOMM)
+ PAIR(EPROTO)
+ PAIR(EMULTIHOP)
+ PAIR(EDOTDOT)
+ PAIR(EBADMSG)
+ PAIR(EOVERFLOW)
+ PAIR(ENOTUNIQ)
+ PAIR(EBADFD)
+ PAIR(EREMCHG)
+ PAIR(ELIBACC)
+ PAIR(ELIBBAD)
+ PAIR(ELIBSCN)
+ PAIR(ELIBMAX)
+ PAIR(ELIBEXEC)
+ PAIR(EILSEQ)
+ PAIR(ERESTART)
+ PAIR(ESTRPIPE)
+ PAIR(EUSERS)
+ PAIR(ENOTSOCK)
+ PAIR(EDESTADDRREQ)
+ PAIR(EMSGSIZE)
+ PAIR(EPROTOTYPE)
+ PAIR(ENOPROTOOPT)
+ PAIR(EPROTONOSUPPORT)
+ PAIR(ESOCKTNOSUPPORT)
+ PAIR(EOPNOTSUPP)
+ PAIR(EPFNOSUPPORT)
+ PAIR(EAFNOSUPPORT)
+ PAIR(EADDRINUSE)
+ PAIR(EADDRNOTAVAIL)
+ PAIR(ENETDOWN)
+ PAIR(ENETUNREACH)
+ PAIR(ENETRESET)
+ PAIR(ECONNABORTED)
+ PAIR(ECONNRESET)
+ PAIR(ENOBUFS)
+ PAIR(EISCONN)
+ PAIR(ENOTCONN)
+ PAIR(ESHUTDOWN)
+ PAIR(ETOOMANYREFS)
+ PAIR(ETIMEDOUT)
+ PAIR(ECONNREFUSED)
+ PAIR(EHOSTDOWN)
+ PAIR(EHOSTUNREACH)
+ PAIR(EALREADY)
+ PAIR(EINPROGRESS)
+ PAIR(ESTALE)
+ PAIR(EUCLEAN)
+ PAIR(ENOTNAM)
+ PAIR(ENAVAIL)
+ PAIR(EISNAM)
+ PAIR(EREMOTEIO)
+ PAIR(EDQUOT)
+ PAIR(ENOMEDIUM)
+ PAIR(EMEDIUMTYPE)
+ PAIR(ECANCELED)
+#ifdef ENOKEY
+ PAIR(ENOKEY)
+#endif
+#ifdef EKEYEXPIRED
+ PAIR(EKEYEXPIRED)
+#endif
+#ifdef EKEYREVOKED
+ PAIR(EKEYREVOKED)
+#endif
+#ifdef EKEYREJECTED
+ PAIR(EKEYREJECTED)
+#endif
+#ifdef EOWNERDEAD
+ PAIR(EOWNERDEAD)
+#endif
+#ifdef ENOTRECOVERABLE
+ PAIR(ENOTRECOVERABLE)
+#endif
+#ifdef ERFKILL
+ PAIR(ERFKILL)
+#endif
+#ifdef EHWPOISON
+ PAIR(EHWPOISON)
+#endif
+ };
+
+ PAIR_LOOKUP(errno_pairs, err);
+}
diff --git a/kernel/tests/lib/get_path.c b/kernel/tests/lib/get_path.c
new file mode 100644
index 0000000..aafbc2c
--- /dev/null
+++ b/kernel/tests/lib/get_path.c
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2010 Cyril Hrubis chrubis@suse.cz
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it is
+ * free of the rightful claim of any third person regarding infringement
+ * or the like. Any license provided herein, whether implied or
+ * otherwise, applies only to this software file. Patent licenses, if
+ * any, provided herein do not apply to combinations of this program with
+ * other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+ /*
+ * Looks for binary prog_name in $PATH.
+ *
+ * If such file exists and if you are able at least to read it, zero is
+ * returned and absolute path to the file is filled into buf. In case buf is
+ * too short to hold the absolute path + prog_name for the file we are looking
+ * for -1 is returned as well as when there is no such file in all paths in
+ * $PATH.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "test.h"
+
+static int file_exist(const char *path)
+{
+ struct stat st;
+
+ if (!access(path, R_OK) && !stat(path, &st) && S_ISREG(st.st_mode))
+ return 1;
+
+ return 0;
+}
+
+int tst_get_path(const char *prog_name, char *buf, size_t buf_len)
+{
+ const char *path = (const char *)getenv("PATH");
+ const char *start = path;
+ const char *end;
+ size_t size, ret;
+
+ if (path == NULL)
+ return -1;
+
+ do {
+ end = strchr(start, ':');
+
+ if (end != NULL)
+ snprintf(buf, MIN(buf_len, (size_t) (end - start + 1)),
+ "%s", start);
+ else
+ snprintf(buf, buf_len, "%s", start);
+
+ size = strlen(buf);
+
+ /*
+ * "::" inside $PATH, $PATH ending with ':' or $PATH starting
+ * with ':' should be expanded into current working directory.
+ */
+ if (size == 0) {
+ snprintf(buf, buf_len, ".");
+ size = strlen(buf);
+ }
+
+ /*
+ * If there is no '/' ad the end of path from $PATH add it.
+ */
+ if (buf[size - 1] != '/')
+ ret =
+ snprintf(buf + size, buf_len - size, "/%s",
+ prog_name);
+ else
+ ret =
+ snprintf(buf + size, buf_len - size, "%s",
+ prog_name);
+
+ if (buf_len - size > ret && file_exist(buf))
+ return 0;
+
+ start = end + 1;
+
+ } while (end != NULL);
+
+ return -1;
+}
diff --git a/kernel/tests/lib/parse_opts.c b/kernel/tests/lib/parse_opts.c
new file mode 100644
index 0000000..a9d5058
--- /dev/null
+++ b/kernel/tests/lib/parse_opts.c
@@ -0,0 +1,621 @@
+/*
+ * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
+ * AUTHOR : William Roske/Richard Logan
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it is
+ * free of the rightful claim of any third person regarding infringement
+ * or the like. Any license provided herein, whether implied or
+ * otherwise, applies only to this software file. Patent licenses, if
+ * any, provided herein do not apply to combinations of this program with
+ * other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
+ * Mountain View, CA 94043, or:
+ *
+ * http://www.sgi.com
+ *
+ * For further information regarding this notice, see:
+ *
+ * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
+ */
+
+#include "config.h"
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/param.h>
+#include <sys/signal.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <time.h>
+#include <stdint.h>
+
+#include "test.h"
+#include "ltp_priv.h"
+#include "usctest.h"
+#include "tst_clocks.h"
+
+#ifndef UNIT_TEST
+#define UNIT_TEST 0
+#endif
+
+/* Define flags and args for standard options */
+static int STD_INFINITE = 0; /* flag indciating to loop forever */
+int STD_LOOP_COUNT = 1; /* number of iterations */
+
+static float STD_LOOP_DURATION = 0.0; /* duration value in fractional seconds */
+
+static char **STD_opt_arr = NULL; /* array of option strings */
+static int STD_argind = 1; /* argv index to next argv element */
+ /* (first argument) */
+ /* To getopt users, it is like optind */
+
+/*
+ * The following variables are to support system testing additions.
+ */
+static int STD_TP_barrier = 0; /* flag to do barrier in TEST_PAUSE */
+ /* 2 - wait_barrier(), 3 - set_barrier(), * - barrier() */
+static int STD_LP_barrier = 0; /* flag to do barrier in TEST_LOOPING */
+ /* 2 - wait_barrier(), 3 - set_barrier(), * - barrier() */
+static int STD_TP_shmem_sz = 0; /* shmalloc this many words per pe in TEST_PAUSE */
+static int STD_LD_shmem = 0; /* flag to do shmem_puts and shmem_gets during delay */
+static int STD_LP_shmem = 0; /* flag to do shmem_puts and gets during TEST_LOOPING */
+static int STD_LD_recfun = 0; /* do recressive function calls in loop delay */
+static int STD_LP_recfun = 0; /* do recressive function calls in TEST_LOOPING */
+static int STD_TP_sbrk = 0; /* do sbrk in TEST_PAUSE */
+static int STD_LP_sbrk = 0; /* do sbrk in TEST_LOOPING */
+static char *STD_start_break = 0; /* original sbrk size */
+static int Debug = 0;
+
+static struct std_option_t {
+ char *optstr;
+ char *help;
+ char *flag;
+ char **arg;
+} std_options[] = {
+ {"h", " -h Show this help screen\n", NULL, NULL},
+ {"i:", " -i n Execute test n times\n", NULL, NULL},
+ {"I:", " -I x Execute test for x seconds\n", NULL, NULL},
+#ifdef UCLINUX
+ {"C:",
+ " -C ARG Run the child process with arguments ARG (for internal use)\n",
+ NULL, NULL},
+#endif
+ {NULL, NULL, NULL, NULL}
+};
+
+/*
+ * Structure for usc_recressive_func argument
+ */
+struct usc_bigstack_t {
+ char space[4096];
+};
+
+static struct usc_bigstack_t *STD_bigstack = NULL;
+
+/* define the string length for Mesg and Mesg2 strings */
+#define STRLEN 2048
+
+static char Mesg2[STRLEN]; /* holds possible return string */
+static void usc_recressive_func();
+
+/*
+ * Define bits for options that might have env variable default
+ */
+#define OPT_iteration 01
+#define OPT_duration 04
+#define OPT_delay 010
+
+#ifdef UCLINUX
+/* Allocated and used in self_exec.c: */
+extern char *child_args; /* Arguments to child when -C is used */
+#endif
+
+static void print_help(void (*user_help)(void))
+{
+ int i;
+
+ for (i = 0; std_options[i].optstr; ++i) {
+ if (std_options[i].help)
+ printf("%s", std_options[i].help);
+ }
+
+ if (user_help)
+ user_help();
+}
+
+/**********************************************************************
+ * parse_opts:
+ **********************************************************************/
+const char *parse_opts(int ac, char **av, const option_t * user_optarr,
+ void (*uhf)(void))
+{
+ int found; /* flag to indicate that an option specified was */
+ /* found in the user's list */
+ int k; /* scratch integer for returns and short time usage */
+ float ftmp; /* tmp float for parsing env variables */
+ char *ptr; /* used in getting env variables */
+ int options = 0; /* no options specified */
+ int optstrlen, i;
+ char *optionstr;
+ int opt;
+
+ /*
+ * If not the first time this function is called, release the old STD_opt_arr
+ * vector.
+ */
+ if (STD_opt_arr != NULL) {
+ free(STD_opt_arr);
+ STD_opt_arr = NULL;
+ }
+ /* Calculate how much space we need for the option string */
+ optstrlen = 0;
+ for (i = 0; std_options[i].optstr; ++i)
+ optstrlen += strlen(std_options[i].optstr);
+ if (user_optarr)
+ for (i = 0; user_optarr[i].option; ++i) {
+ if (strlen(user_optarr[i].option) > 2)
+ return
+ "parse_opts: ERROR - Only short options are allowed";
+ optstrlen += strlen(user_optarr[i].option);
+ }
+ optstrlen += 1;
+
+ /* Create the option string for getopt */
+ optionstr = malloc(optstrlen);
+ if (!optionstr)
+ return
+ "parse_opts: ERROR - Could not allocate memory for optionstr";
+
+ optionstr[0] = '\0';
+
+ for (i = 0; std_options[i].optstr; ++i)
+ strcat(optionstr, std_options[i].optstr);
+ if (user_optarr)
+ for (i = 0; user_optarr[i].option; ++i)
+ /* only add the option if it wasn't there already */
+ if (strchr(optionstr, user_optarr[i].option[0]) == NULL)
+ strcat(optionstr, user_optarr[i].option);
+
+ /*
+ * Loop through av parsing options.
+ */
+ while ((opt = getopt(ac, av, optionstr)) > 0) {
+
+ STD_argind = optind;
+
+ switch (opt) {
+ case '?': /* Unknown option */
+ return "Unknown option";
+ break;
+ case ':': /* Missing Arg */
+ return "Missing argument";
+ break;
+ case 'i': /* Iterations */
+ options |= OPT_iteration;
+ STD_LOOP_COUNT = atoi(optarg);
+ if (STD_LOOP_COUNT == 0)
+ STD_INFINITE = 1;
+ break;
+ case 'I': /* Time duration */
+ options |= OPT_duration;
+ STD_LOOP_DURATION = atof(optarg);
+ if (STD_LOOP_DURATION == 0.0)
+ STD_INFINITE = 1;
+ break;
+ case 'h': /* Help */
+ print_help(uhf);
+ exit(0);
+ break;
+#ifdef UCLINUX
+ case 'C': /* Run child */
+ child_args = optarg;
+ break;
+#endif
+ default:
+
+ /* Check all the user specified options */
+ found = 0;
+ for (i = 0; user_optarr[i].option; ++i) {
+
+ if (opt == user_optarr[i].option[0]) {
+ /* Yup, This is a user option, set the flag and look for argument */
+ if (user_optarr[i].flag) {
+ *user_optarr[i].flag = 1;
+ }
+ found++;
+
+ /* save the argument at the user's location */
+ if (user_optarr[i].
+ option[strlen(user_optarr[i].option)
+ - 1] == ':') {
+ *user_optarr[i].arg = optarg;
+ }
+ break; /* option found - break out of the for loop */
+ }
+ }
+ /* This condition "should never happen". SO CHECK FOR IT!!!! */
+ if (!found) {
+ sprintf(Mesg2,
+ "parse_opts: ERROR - option:\"%c\" NOT FOUND... INTERNAL "
+ "ERROR", opt);
+ return (Mesg2);
+ }
+ }
+
+ }
+ free(optionstr);
+
+ STD_argind = optind;
+
+ /*
+ * Turn on debug
+ */
+ if (getenv("USC_DEBUG") != NULL) {
+ Debug = 1;
+ printf("env USC_DEBUG is defined, turning on debug\n");
+ }
+ if (getenv("USC_VERBOSE") != NULL) {
+ Debug = 1;
+ printf("env USC_VERBOSE is defined, turning on debug\n");
+ }
+
+ /*
+ * If the USC_ITERATION_ENV environmental variable is set to
+ * a number, use that number as iteration count (same as -c option).
+ * The -c option with arg will be used even if this env var is set.
+ */
+ if (!(options & OPT_iteration)
+ && (ptr = getenv(USC_ITERATION_ENV)) != NULL) {
+ if (sscanf(ptr, "%i", &k) == 1) {
+ if (k == 0) { /* if arg is 0, set infinite loop flag */
+ STD_INFINITE = 1;
+ if (Debug)
+ printf
+ ("Using env %s, set STD_INFINITE to 1\n",
+ USC_ITERATION_ENV);
+ } else { /* else, set the loop count to the arguement */
+ STD_LOOP_COUNT = k;
+ if (Debug)
+ printf
+ ("Using env %s, set STD_LOOP_COUNT to %d\n",
+ USC_ITERATION_ENV, k);
+ }
+ }
+ }
+
+ /*
+ * If the USC_LOOP_WALLTIME environmental variable is set,
+ * use that number as duration (same as -I option).
+ * The -I option with arg will be used even if this env var is set.
+ */
+
+ if (!(options & OPT_duration) &&
+ (ptr = getenv(USC_LOOP_WALLTIME)) != NULL) {
+ if (sscanf(ptr, "%f", &ftmp) == 1 && ftmp >= 0.0) {
+ STD_LOOP_DURATION = ftmp;
+ if (Debug)
+ printf
+ ("Using env %s, set STD_LOOP_DURATION to %f\n",
+ USC_LOOP_WALLTIME, ftmp);
+ if (STD_LOOP_DURATION == 0.0) { /* if arg is 0, set infinite loop flag */
+ STD_INFINITE = 1;
+ if (Debug)
+ printf
+ ("Using env %s, set STD_INFINITE to 1\n",
+ USC_LOOP_WALLTIME);
+ }
+ }
+ }
+ if (!(options & OPT_duration) && (ptr = getenv("USC_DURATION")) != NULL) {
+ if (sscanf(ptr, "%f", &ftmp) == 1 && ftmp >= 0.0) {
+ STD_LOOP_DURATION = ftmp;
+ if (Debug)
+ printf
+ ("Using env USC_DURATION, set STD_LOOP_DURATION to %f\n",
+ ftmp);
+ if (STD_LOOP_DURATION == 0.0) { /* if arg is 0, set infinite loop flag */
+ STD_INFINITE = 1;
+ if (Debug)
+ printf
+ ("Using env USC_DURATION, set STD_INFINITE to 1\n");
+ }
+ }
+ }
+
+ /*
+ * The following are special system testing envs to turn on special
+ * hooks in the code.
+ */
+ if ((ptr = getenv("USC_TP_BARRIER")) != NULL) {
+ if (sscanf(ptr, "%i", &k) == 1 && k >= 0)
+ STD_TP_barrier = k;
+ else
+ STD_TP_barrier = 1;
+ if (Debug)
+ printf
+ ("using env USC_TP_BARRIER, Set STD_TP_barrier to %d\n",
+ STD_TP_barrier);
+ }
+
+ if ((ptr = getenv("USC_LP_BARRIER")) != NULL) {
+ if (sscanf(ptr, "%i", &k) == 1 && k >= 0)
+ STD_LP_barrier = k;
+ else
+ STD_LP_barrier = 1;
+ if (Debug)
+ printf
+ ("using env USC_LP_BARRIER, Set STD_LP_barrier to %d\n",
+ STD_LP_barrier);
+ }
+
+ if ((ptr = getenv("USC_TP_SHMEM")) != NULL) {
+ if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
+ STD_TP_shmem_sz = k;
+ if (Debug)
+ printf
+ ("Using env USC_TP_SHMEM, Set STD_TP_shmem_sz to %d\n",
+ STD_TP_shmem_sz);
+ }
+ }
+
+ if ((ptr = getenv("USC_LP_SHMEM")) != NULL) {
+ if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
+ STD_LP_shmem = k;
+ if (Debug)
+ printf
+ ("Using env USC_LP_SHMEM, Set STD_LP_shmem to %d\n",
+ STD_LP_shmem);
+ }
+ }
+
+ if ((ptr = getenv("USC_LD_SHMEM")) != NULL) {
+ if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
+ STD_LD_shmem = k;
+ if (Debug)
+ printf
+ ("Using env USC_LD_SHMEM, Set STD_LD_shmem to %d\n",
+ STD_LD_shmem);
+ }
+ }
+
+ if ((ptr = getenv("USC_TP_SBRK")) != NULL) {
+ if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
+ STD_TP_sbrk = k;
+ if (Debug)
+ printf
+ ("Using env USC_TP_SBRK, Set STD_TP_sbrk to %d\n",
+ STD_TP_sbrk);
+ }
+ }
+#if !defined(UCLINUX)
+ if ((ptr = getenv("USC_LP_SBRK")) != NULL) {
+ if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
+ STD_LP_sbrk = k;
+ if (Debug)
+ printf
+ ("Using env USC_LP_SBRK, Set STD_LP_sbrk to %d\n",
+ STD_LP_sbrk);
+ }
+ }
+#endif /* if !defined(UCLINUX) */
+
+ if ((ptr = getenv("USC_LP_RECFUN")) != NULL) {
+ if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
+ STD_LP_recfun = k;
+ if (STD_bigstack != NULL)
+ STD_bigstack =
+ malloc(sizeof(struct usc_bigstack_t));
+ if (Debug)
+ printf
+ ("Using env USC_LP_RECFUN, Set STD_LP_recfun to %d\n",
+ STD_LP_recfun);
+ }
+ }
+
+ if ((ptr = getenv("USC_LD_RECFUN")) != NULL) {
+ if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
+ STD_LD_recfun = k;
+ if (STD_bigstack != NULL)
+ STD_bigstack =
+ malloc(sizeof(struct usc_bigstack_t));
+ if (Debug)
+ printf
+ ("Using env USC_LD_RECFUN, Set STD_LD_recfun to %d\n",
+ STD_LD_recfun);
+ }
+ }
+#if UNIT_TEST
+ printf("The following variables after option and env parsing:\n");
+ printf("STD_LOOP_DURATION = %f\n", STD_LOOP_DURATION);
+ printf("STD_LOOP_COUNT = %d\n", STD_LOOP_COUNT);
+ printf("STD_INFINITE = %d\n", STD_INFINITE);
+#endif
+
+ return NULL;
+}
+
+/***********************************************************************
+ * This function will do desired end of global setup test
+ * hooks.
+ ***********************************************************************/
+int usc_global_setup_hook(void)
+{
+#ifndef UCLINUX
+ if (STD_TP_sbrk || STD_LP_sbrk)
+ STD_start_break = sbrk(0); /* get original sbreak size */
+
+ if (STD_TP_sbrk) {
+ sbrk(STD_TP_sbrk);
+ if (Debug)
+ printf("after sbrk(%d)\n", STD_TP_sbrk);
+ }
+#endif
+ return 0;
+}
+
+#define USECS_PER_SEC 1000000 /* microseconds per second */
+
+static uint64_t get_current_time(void)
+{
+ struct timespec ts;
+
+ tst_clock_gettime(CLOCK_MONOTONIC, &ts);
+
+ return (((uint64_t) ts.tv_sec) * USECS_PER_SEC) + ts.tv_nsec / 1000;
+}
+
+/***********************************************************************
+ *
+ * This function will determine if test should continue iterating
+ * If the STD_INFINITE flag is set, return 1.
+ * If the STD_LOOP_COUNT variable is set, compare it against
+ * the counter.
+ * If the STD_LOOP_DURATION variable is set, compare current time against
+ * calculated stop_time.
+ * This function will return 1 until all desired looping methods
+ * have been met.
+ *
+ * counter integer is supplied by the user program.
+ ***********************************************************************/
+int usc_test_looping(int counter)
+{
+ static int first_time = 1;
+ static uint64_t stop_time = 0;
+ int keepgoing = 0;
+
+ /*
+ * If this is the first iteration and we are looping for
+ * duration of STD_LOOP_DURATION seconds (fractional) or
+ * doing loop delays, get the clocks per second.
+ */
+ if (first_time) {
+ first_time = 0;
+
+ /*
+ * If looping for duration, calculate stop time in
+ * clocks.
+ */
+ if (STD_LOOP_DURATION) {
+ stop_time =
+ (uint64_t) (USECS_PER_SEC * STD_LOOP_DURATION)
+ + get_current_time();
+ }
+ }
+
+ if (STD_INFINITE)
+ keepgoing++;
+
+ if (STD_LOOP_COUNT && counter < STD_LOOP_COUNT)
+ keepgoing++;
+
+ if (STD_LOOP_DURATION != 0.0 && get_current_time() < stop_time)
+ keepgoing++;
+
+ if (keepgoing == 0)
+ return 0;
+
+ /*
+ * The following code allows special system testing hooks.
+ */
+
+ if (STD_LP_recfun) {
+ if (Debug)
+ printf
+ ("calling usc_recressive_func(0, %d, *STD_bigstack)\n",
+ STD_LP_recfun);
+ usc_recressive_func(0, STD_LP_recfun, *STD_bigstack);
+ }
+#if !defined(UCLINUX)
+ if (STD_LP_sbrk) {
+ if (Debug)
+ printf("about to do sbrk(%d)\n", STD_LP_sbrk);
+ sbrk(STD_LP_sbrk);
+ }
+#endif
+
+ if (keepgoing)
+ return 1;
+ else
+ return 0;
+}
+
+/*
+ * This function recressively calls itself max times.
+ */
+static void usc_recressive_func(int cnt, int max, struct usc_bigstack_t bstack)
+{
+ if (cnt < max)
+ usc_recressive_func(cnt + 1, max, bstack);
+
+}
+
+#if UNIT_TEST
+
+/******************************************************************************
+ * UNIT TEST CODE
+ * UNIT TEST CODE
+ *
+ * this following code is provide so that unit testing can
+ * be done fairly easily.
+ ******************************************************************************/
+
+int Help = 0;
+int Help2 = 0;
+char *ptr;
+
+long TEST_RETURN;
+int TEST_ERRNO;
+
+/* for test specific parse_opts options */
+option_t Options[] = {
+ {"help", &Help2, NULL}, /* -help option */
+ {"h", &Help, NULL}, /* -h option */
+
+#if INVALID_TEST_CASES
+ {"missingflag", NULL, &ptr}, /* error */
+ {"missingarg:", &Help, NULL}, /* error */
+#endif /* INVALID_TEST_CASES */
+
+ {NULL, NULL, NULL}
+};
+
+int main(int argc, char **argv)
+{
+ int lc;
+ char *msg;
+ struct timeval t;
+ int cnt;
+
+ if ((msg = parse_opts(argc, argv, Options, NULL)) != NULL) {
+ printf("ERROR: %s\n", msg);
+ exit(1);
+ }
+
+ TEST_PAUSE;
+
+ for (lc = 0; TEST_LOOPING(lc); lc++) {
+
+ TEST(gettimeofday(&t, NULL));
+ printf("iter=%d: sec:%d, usec:%6.6d %s", lc + 1, t.tv_sec,
+ t.tv_usec, ctime(&t.tv_sec));
+ }
+
+ TEST_CLEANUP;
+
+ exit(0);
+}
+
+#endif /* UNIT_TEST */
diff --git a/kernel/tests/lib/random_range.c b/kernel/tests/lib/random_range.c
new file mode 100644
index 0000000..510a4a1
--- /dev/null
+++ b/kernel/tests/lib/random_range.c
@@ -0,0 +1,892 @@
+/*
+ * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it is
+ * free of the rightful claim of any third person regarding infringement
+ * or the like. Any license provided herein, whether implied or
+ * otherwise, applies only to this software file. Patent licenses, if
+ * any, provided herein do not apply to combinations of this program with
+ * other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
+ * Mountain View, CA 94043, or:
+ *
+ * http://www.sgi.com
+ *
+ * For further information regarding this notice, see:
+ *
+ * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <malloc.h>
+#include "random_range.h"
+
+/*
+ * Internal format of the range array set up by parse_range()
+ */
+
+struct range {
+ int min;
+ int max;
+ int mult;
+};
+
+/*
+ * parse_ranges() is a function to parse a comma-separated list of range
+ * tokens each having the following form:
+ *
+ * num
+ * or
+ * min:max[:mult]
+ *
+ * any of the values may be blank (ie. min::mult, :max, etc.) and default
+ * values for missing arguments may be supplied by the caller.
+ *
+ * The special first form is short hand for 'num:num'.
+ *
+ * After parsing the string, the ranges are put into an array of integers,
+ * which is malloc'd by the routine. The min, max, and mult entries of each
+ * range can be extracted from the array using the range_min(), range_max(),
+ * and range_mult() functions.
+ *
+ * It is the responsibility of the caller to free the space allocated by
+ * parse_ranges() - a single call to free() will free the space.
+ *
+ * str The string to parse - assumed to be a comma-separated
+ * list of tokens having the above format.
+ * defmin default value to plug in for min, if it is missing
+ * defmax default value to plug in for max, if it is missing
+ * defmult default value to plug in for mult, if missing
+ * parse_func A user-supplied function pointer, which parse_ranges()
+ * can call to parse the min, max, and mult strings. This
+ * allows for customized number formats. The function
+ * MUST have the following prototype:
+ * parse_func(char *str, int *val)
+ * The function should return -1 if str cannot be parsed
+ * into an integer, or >= 0 if it was successfully
+ * parsed. The resulting integer will be stored in
+ * *val. If parse_func is NULL, parse_ranges will parse
+ * the tokens in a manner consistent with the the sscanf
+ * %i format.
+ * range_ptr A user-supplied char **, which will be set to point
+ * at malloc'd space which holds the parsed range
+ * values. If range_ptr is NULL, parse_ranges() just
+ * parses the string. The data returned in range_ptr
+ * should not be processed directly - use the functions
+ * range_min(), range_max(), and range_mult() to access
+ * data for a given range.
+ * errptr user-supplied char ** which can be set to point to a
+ * static error string. If errptr is NULL, it is ignored.
+ *
+ * parse_range() returns -1 on error, or the number of ranges parsed.
+ */
+
+static int str_to_int();
+static long long divider(long long, long long, long long, long long);
+
+int parse_ranges(char *str, int defmin, int defmax, int defmult,
+ int (*parse_func)(), char **rangeptr, char **errptr)
+{
+ int ncommas;
+ char *tmpstr, *cp, *tok, *n1str, *n2str, *multstr;
+ struct range *rp, *ranges;
+ static char errmsg[256];
+
+ if (errptr != NULL) {
+ *errptr = errmsg;
+ }
+
+ for (ncommas = 0, cp = str; *cp != '\0'; cp++) {
+ if (*cp == ',') {
+ ncommas++;
+ }
+ }
+
+ if (parse_func == NULL) {
+ parse_func = str_to_int;
+ }
+
+ tmpstr = strdup(str);
+ ranges = malloc((ncommas + 1) * sizeof(struct range));
+ rp = ranges;
+
+ tok = strtok(tmpstr, ",");
+ while (tok != NULL) {
+ n1str = tok;
+ n2str = NULL;
+ multstr = NULL;
+
+ rp->min = defmin;
+ rp->max = defmax;
+ rp->mult = defmult;
+
+ if ((cp = strchr(n1str, ':')) != NULL) {
+ *cp = '\0';
+ n2str = cp + 1;
+
+ if ((cp = strchr(n2str, ':')) != NULL) {
+ *cp = '\0';
+ multstr = cp + 1;
+ }
+ }
+
+ /*
+ * Parse the 'min' field - if it is zero length (:n2[:mult]
+ * format), retain the default value, otherwise, pass the
+ * string to the parse function.
+ */
+
+ if ((int)strlen(n1str) > 0) {
+ if ((*parse_func) (n1str, &rp->min) < 0) {
+ sprintf(errmsg,
+ "error parsing string %s into an integer",
+ n1str);
+ free(tmpstr);
+ free(ranges);
+ return -1;
+ }
+ }
+
+ /*
+ * Process the 'max' field - if one was not present (n1 format)
+ * set max equal to min. If the field was present, but
+ * zero length (n1: format), retain the default. Otherwise
+ * pass the string to the parse function.
+ */
+
+ if (n2str == NULL) {
+ rp->max = rp->min;
+ } else if ((int)strlen(n2str) > 0) {
+ if ((*parse_func) (n2str, &rp->max) < 0) {
+ sprintf(errmsg,
+ "error parsing string %s into an integer",
+ n2str);
+ free(tmpstr);
+ free(ranges);
+ return -1;
+ }
+ }
+
+ /*
+ * Process the 'mult' field - if one was not present
+ * (n1:n2 format), or the field was zero length (n1:n2: format)
+ * then set the mult field to defmult - otherwise pass then
+ * mult field to the parse function.
+ */
+
+ if (multstr != NULL && (int)strlen(multstr) > 0) {
+ if ((*parse_func) (multstr, &rp->mult) < 0) {
+ sprintf(errmsg,
+ "error parsing string %s into an integer",
+ multstr);
+ free(tmpstr);
+ free(ranges);
+ return -1;
+ }
+ }
+
+ rp++;
+ tok = strtok(NULL, ",");
+ }
+
+ free(tmpstr);
+
+ if (rangeptr != NULL) {
+ *rangeptr = (char *)ranges;
+ } else {
+ free(ranges); /* just running in parse mode */
+ }
+
+ return (rp - ranges);
+}
+
+/*
+ * The default integer-parsing function
+ */
+
+static int str_to_int(char *str, int *ip)
+{
+ char c;
+
+ if (sscanf(str, "%i%c", ip, &c) != 1) {
+ return -1;
+ } else {
+ return 0;
+ }
+}
+
+/*
+ * Three simple functions to return the min, max, and mult values for a given
+ * range. It is assumed that rbuf is a range buffer set up by parse_ranges(),
+ * and that r is a valid range within that buffer.
+ */
+
+int range_min(char *rbuf, int r)
+{
+ return ((struct range *)rbuf)[r].min;
+}
+
+int range_max(char *rbuf, int r)
+{
+ return ((struct range *)rbuf)[r].max;
+}
+
+int range_mult(char *rbuf, int r)
+{
+ return ((struct range *)rbuf)[r].mult;
+}
+
+/*****************************************************************************
+ * random_range(int start, int end, int mult, char **errp)
+ *
+ * Returns a psuedo-random number which is >= 'start', <= 'end', and a multiple
+ * of 'mult'. Start and end may be any valid integer, but mult must be an
+ * integer > 0. errp is a char ** which will be set to point to a static
+ * error message buffer if it is not NULL, and an error occurs.
+ *
+ * The errp is the only way to check if the routine fails - currently the only
+ * failure conditions are:
+ *
+ * mult < 1
+ * no numbers in the start-end range that are a multiple of 'mult'
+ *
+ * If random_range_fails, and errp is a valid pointer, it will point to an
+ * internal error buffer. If errp is a vaild pointer, and random_range
+ * is successful, errp will be set to NULL.
+ *
+ * Note - if mult is 1 (the most common case), there are error conditions
+ * possible, and errp need not be used.
+ *
+ * Note: Uses lrand48(), assuming that set_random_seed() uses srand48() when
+ * setting the seed.
+ *****************************************************************************/
+
+long random_range(int min, int max, int mult, char **errp)
+{
+ int r, nmults, orig_min, orig_max, orig_mult, tmp;
+ extern long lrand48();
+ static char errbuf[128];
+
+ /*
+ * Sanity check
+ */
+
+ if (mult < 1) {
+ if (errp != NULL) {
+ sprintf(errbuf, "mult arg must be greater than 0");
+ *errp = errbuf;
+ }
+ return -1;
+ }
+
+ /*
+ * Save original parameter values for use in error message
+ */
+
+ orig_min = min;
+ orig_max = max;
+ orig_mult = mult;
+
+ /*
+ * switch min/max if max < min
+ */
+
+ if (max < min) {
+ tmp = max;
+ max = min;
+ min = tmp;
+ }
+
+ /*
+ * select the random number
+ */
+
+ if ((r = min % mult)) /* bump to the next higher 'mult' multiple */
+ min += mult - r;
+
+ if ((r = max % mult)) /* reduce to the next lower 'mult' multiple */
+ max -= r;
+
+ if (min > max) { /* no 'mult' multiples between min & max */
+ if (errp != NULL) {
+ sprintf(errbuf,
+ "no numbers in the range %d:%d that are a multiple of %d",
+ orig_min, orig_max, orig_mult);
+ *errp = errbuf;
+ }
+ return -1;
+ }
+
+ if (errp != NULL) {
+ *errp = NULL;
+ }
+
+ nmults = ((max - min) / mult) + 1;
+#if CRAY
+ /*
+ * If max is less than 2gb, then the value can fit in 32 bits
+ * and the standard lrand48() routine can be used.
+ */
+ if (max <= (long)2147483647) {
+ return (long)(min + (((long)lrand48() % nmults) * mult));
+ } else {
+ /*
+ * max is greater than 2gb - meeds more than 32 bits.
+ * Since lrand48 only will get a number up to 32bits.
+ */
+ long randnum;
+ randnum = divider(min, max, 0, -1);
+ return (long)(min + ((randnum % nmults) * mult));
+ }
+
+#else
+ return (min + ((lrand48() % nmults) * mult));
+#endif
+
+}
+
+/*
+ * Just like random_range, but all values are longs.
+ */
+long random_rangel(long min, long max, long mult, char **errp)
+{
+ long r, nmults, orig_min, orig_max, orig_mult, tmp;
+ extern long lrand48();
+ static char errbuf[128];
+
+ /*
+ * Sanity check
+ */
+
+ if (mult < 1) {
+ if (errp != NULL) {
+ sprintf(errbuf, "mult arg must be greater than 0");
+ *errp = errbuf;
+ }
+ return -1;
+ }
+
+ /*
+ * Save original parameter values for use in error message
+ */
+
+ orig_min = min;
+ orig_max = max;
+ orig_mult = mult;
+
+ /*
+ * switch min/max if max < min
+ */
+
+ if (max < min) {
+ tmp = max;
+ max = min;
+ min = tmp;
+ }
+
+ /*
+ * select the random number
+ */
+
+ if ((r = min % mult)) /* bump to the next higher 'mult' multiple */
+ min += mult - r;
+
+ if ((r = max % mult)) /* reduce to the next lower 'mult' multiple */
+ max -= r;
+
+ if (min > max) { /* no 'mult' multiples between min & max */
+ if (errp != NULL) {
+ sprintf(errbuf,
+ "no numbers in the range %ld:%ld that are a multiple of %ld",
+ orig_min, orig_max, orig_mult);
+ *errp = errbuf;
+ }
+ return -1;
+ }
+
+ if (errp != NULL) {
+ *errp = NULL;
+ }
+
+ nmults = ((max - min) / mult) + 1;
+#if CRAY || (_MIPS_SZLONG == 64)
+ /*
+ * If max is less than 2gb, then the value can fit in 32 bits
+ * and the standard lrand48() routine can be used.
+ */
+ if (max <= (long)2147483647) {
+ return (long)(min + (((long)lrand48() % nmults) * mult));
+ } else {
+ /*
+ * max is greater than 2gb - meeds more than 32 bits.
+ * Since lrand48 only will get a number up to 32bits.
+ */
+ long randnum;
+ randnum = divider(min, max, 0, -1);
+ return (long)(min + ((randnum % nmults) * mult));
+ }
+
+#else
+ return (min + ((lrand48() % nmults) * mult));
+#endif
+}
+
+/*
+ * Attempts to be just like random_range, but everything is long long (64 bit)
+ */
+long long random_rangell(long long min, long long max,
+ long long mult, char **errp)
+{
+ long long r, nmults, orig_min, orig_max, orig_mult, tmp;
+ long long randnum;
+ extern long lrand48();
+ static char errbuf[128];
+
+ /*
+ * Sanity check
+ */
+
+ if (mult < 1) {
+ if (errp != NULL) {
+ sprintf(errbuf, "mult arg must be greater than 0");
+ *errp = errbuf;
+ }
+ return -1;
+ }
+
+ /*
+ * Save original parameter values for use in error message
+ */
+
+ orig_min = min;
+ orig_max = max;
+ orig_mult = mult;
+
+ /*
+ * switch min/max if max < min
+ */
+
+ if (max < min) {
+ tmp = max;
+ max = min;
+ min = tmp;
+ }
+
+ /*
+ * select the random number
+ */
+
+ if ((r = min % mult)) /* bump to the next higher 'mult' multiple */
+ min += mult - r;
+
+ if ((r = max % mult)) /* reduce to the next lower 'mult' multiple */
+ max -= r;
+
+ if (min > max) { /* no 'mult' multiples between min & max */
+ if (errp != NULL) {
+ sprintf(errbuf,
+ "no numbers in the range %lld:%lld that are a multiple of %lld",
+ orig_min, orig_max, orig_mult);
+ *errp = errbuf;
+ }
+ return -1;
+ }
+
+ if (errp != NULL) {
+ *errp = NULL;
+ }
+
+ nmults = ((max - min) / mult) + 1;
+ /*
+ * If max is less than 2gb, then the value can fit in 32 bits
+ * and the standard lrand48() routine can be used.
+ */
+ if (max <= (long)2147483647) {
+ return (long long)(min +
+ (((long long)lrand48() % nmults) * mult));
+ } else {
+ /*
+ * max is greater than 2gb - meeds more than 32 bits.
+ * Since lrand48 only will get a number up to 32bits.
+ */
+ randnum = divider(min, max, 0, -1);
+ return (long long)(min + ((randnum % nmults) * mult));
+ }
+
+}
+
+/*
+ * This functional will recusively call itself to return a random
+ * number min and max. It was designed to work the 64bit numbers
+ * even when compiled as 32 bit process.
+ * algorithm: to use the official lrand48() routine - limited to 32 bits.
+ * find the difference between min and max (max-min).
+ * if the difference is 2g or less, use the random number gotton from lrand48().
+ * Determine the midway point between min and max.
+ * if the midway point is less than 2g from min or max,
+ * randomly add the random number gotton from lrand48() to
+ * either min or the midpoint.
+ * Otherwise, call outself with min and max being min and midway value or
+ * midway value and max. This will reduce the range in half.
+ */
+static long long
+divider(long long min, long long max, long long cnt, long long rand)
+{
+ long long med, half, diff;
+
+ /*
+ * prevent run away code. We are dividing by two each count.
+ * if we get to a count of more than 32, we should have gotten
+ * to 2gb.
+ */
+ if (cnt > 32)
+ return -1;
+
+ /*
+ * Only get a random number the first time.
+ */
+ if (cnt == 0 || rand < -1) {
+ rand = (long long)lrand48(); /* 32 bit random number */
+ }
+
+ diff = max - min;
+
+ if (diff <= 2147483647)
+ return min + rand;
+
+ half = diff / (long long)2; /* half the distance between min and max */
+ med = min + half; /* med way point between min and max */
+
+#if DEBUG
+ printf("divider: min=%lld, max=%lld, cnt=%lld, rand=%lld\n", min, max,
+ cnt, rand);
+ printf(" diff = %lld, half = %lld, med = %lld\n", diff, half, med);
+#endif
+
+ if (half <= 2147483647) {
+ /*
+ * If half is smaller than 2gb, we can use the random number
+ * to pick the number within the min to med or med to max
+ * if the cnt bit of rand is zero or one, respectively.
+ */
+ if (rand & (1 << cnt))
+ return med + rand;
+ else
+ return min + rand;
+ } else {
+ /*
+ * recursively call ourself to reduce the value to the bottom half
+ * or top half (bit cnt is set).
+ */
+ if (rand & (1 << cnt)) {
+ return divider(med, max, cnt + 1, rand);
+ } else {
+ return divider(min, med, cnt + 1, rand);
+ }
+
+ }
+
+}
+
+/*****************************************************************************
+ * random_range_seed(s)
+ *
+ * Sets the random seed to s. Uses srand48(), assuming that lrand48() will
+ * be used in random_range().
+ *****************************************************************************/
+
+void random_range_seed(long s)
+{
+ extern void srand48();
+
+ srand48(s);
+}
+
+/****************************************************************************
+ * random_bit(mask)
+ *
+ * This function randomly returns a single bit from the bits
+ * set in mask. If mask is zero, zero is returned.
+ *
+ ****************************************************************************/
+long random_bit(long mask)
+{
+ int nbits = 0; /* number of set bits in mask */
+ long bit; /* used to count bits and num of set bits choosen */
+ int nshift; /* used to count bit shifts */
+
+ if (mask == 0)
+ return 0;
+
+ /*
+ * get the number of bits set in mask
+ */
+#ifndef CRAY
+
+ bit = 1L;
+ for (nshift = 0; (unsigned int)nshift < sizeof(long) * 8; nshift++) {
+ if (mask & bit)
+ nbits++;
+ bit = bit << 1;
+ }
+
+#else
+ nbits = _popcnt(mask);
+#endif /* if CRAY */
+
+ /*
+ * randomly choose a bit.
+ */
+ bit = random_range(1, nbits, 1, NULL);
+
+ /*
+ * shift bits until you determine which bit was randomly choosen.
+ * nshift will hold the number of shifts to make.
+ */
+
+ nshift = 0;
+ while (bit) {
+ /* check if the current one's bit is set */
+ if (mask & 1L) {
+ bit--;
+ }
+ mask = mask >> 1;
+ nshift++;
+ }
+
+ return 01L << (nshift - 1);
+
+}
+
+#if RANDOM_BIT_UNITTEST
+/*
+ * The following is a unit test main function for random_bit().
+ */
+main(argc, argv)
+int argc;
+char **argv;
+{
+ int ind;
+ int cnt, iter;
+ long mask, ret;
+
+ printf("test for first and last bit set\n");
+ mask = 1L;
+ ret = random_bit(mask);
+ printf("random_bit(%#o) returned %#o\n", mask, ret);
+
+ mask = 1L << (sizeof(long) * 8 - 1);
+ ret = random_bit(mask);
+ printf("random_bit(%#o) returned %#o\n", mask, ret);
+
+ if (argc >= 3) {
+ iter = atoi(argv[1]);
+ for (ind = 2; ind < argc; ind++) {
+ printf("Calling random_bit %d times for mask %#o\n",
+ iter, mask);
+ sscanf(argv[ind], "%i", &mask);
+ for (cnt = 0; cnt < iter; cnt++) {
+ ret = random_bit(mask);
+ printf("random_bit(%#o) returned %#o\n", mask,
+ ret);
+ }
+ }
+ }
+ exit(0);
+}
+
+#endif /* end if RANDOM_BIT_UNITTEST */
+
+#if UNIT_TEST
+/*
+ * The following is a unit test main function for random_range*().
+ */
+
+#define PARTNUM 10 /* used to determine even distribution of random numbers */
+#define MEG 1024*1024*1024
+#define GIG 1073741824
+int main(argc, argv)
+int argc;
+char **argv;
+{
+ int ind;
+ int cnt, iter = 10;
+ int imin = 0, imult = 1, itmin, itmax = 0;
+#if CRAY
+ int imax = 6 * GIG; /* higher than 32 bits */
+#else
+ int imax = 1048576;
+#endif
+
+ long lret, lmin = 0, lmult = 1, ltmin, ltmax = 0;
+#if CRAY || (_MIPS_SZLONG == 64)
+ long lmax = 6 * (long)GIG; /* higher than 32 bits */
+#else
+ long lmax = 1048576;
+#endif
+ long long llret, llmin = 0, llmult = 1, lltmin, lltmax = 0;
+ long long llmax = (long long)80 * (long long)GIG;
+
+ long part;
+ long long lpart;
+ long cntarr[PARTNUM];
+ long valbound[PARTNUM];
+ long long lvalbound[PARTNUM];
+
+ for (ind = 0; ind < PARTNUM; ind++)
+ cntarr[ind] = 0;
+
+ if (argc < 2) {
+ printf("Usage: %s func [iterations] \n", argv[0]);
+ printf
+ ("func can be random_range, random_rangel, random_rangell\n");
+ exit(1);
+ }
+
+ if (argc >= 3) {
+ if (sscanf(argv[2], "%i", &iter) != 1) {
+ printf("Usage: %s [func iterations] \n", argv[0]);
+ printf("argv[2] is not a number\n");
+ exit(1);
+ }
+ }
+
+ /*
+ * random_rangel ()
+ */
+ if (strcmp(argv[1], "random_rangel") == 0) {
+ ltmin = lmax;
+ part = lmax / PARTNUM;
+ for (ind = 0; ind < PARTNUM; ind++) {
+ valbound[ind] = part * ind;
+ }
+
+ for (cnt = 0; cnt < iter; cnt++) {
+ lret = random_rangel(lmin, lmax, lmult, NULL);
+ if (iter < 100)
+ printf("%ld\n", lret);
+ if (lret < ltmin)
+ ltmin = lret;
+ if (lret > ltmax)
+ ltmax = lret;
+ for (ind = 0; ind < PARTNUM - 1; ind++) {
+ if (valbound[ind] < lret
+ && lret <= valbound[ind + 1]) {
+ cntarr[ind]++;
+ break;
+ }
+ }
+ if (lret > valbound[PARTNUM - 1]) {
+ cntarr[PARTNUM - 1]++;
+ }
+ }
+ for (ind = 0; ind < PARTNUM - 1; ind++) {
+ printf("%2d %-13ld to %-13ld %5ld %4.4f\n", ind + 1,
+ valbound[ind], valbound[ind + 1], cntarr[ind],
+ (float)(cntarr[ind] / (float)iter));
+ }
+ printf("%2d %-13ld to %-13ld %5ld %4.4f\n", PARTNUM,
+ valbound[PARTNUM - 1], lmax, cntarr[PARTNUM - 1],
+ (float)(cntarr[PARTNUM - 1] / (float)iter));
+ printf(" min=%ld, max=%ld\n", ltmin, ltmax);
+
+ } else if (strcmp(argv[1], "random_rangell") == 0) {
+ /*
+ * random_rangell() unit test
+ */
+ lltmin = llmax;
+ lpart = llmax / PARTNUM;
+ for (ind = 0; ind < PARTNUM; ind++) {
+ lvalbound[ind] = (long long)(lpart * ind);
+ }
+
+ for (cnt = 0; cnt < iter; cnt++) {
+ llret = random_rangell(llmin, llmax, llmult, NULL);
+ if (iter < 100)
+ printf("random_rangell returned %lld\n", llret);
+ if (llret < lltmin)
+ lltmin = llret;
+ if (llret > lltmax)
+ lltmax = llret;
+
+ for (ind = 0; ind < PARTNUM - 1; ind++) {
+ if (lvalbound[ind] < llret
+ && llret <= lvalbound[ind + 1]) {
+ cntarr[ind]++;
+ break;
+ }
+ }
+ if (llret > lvalbound[PARTNUM - 1]) {
+ cntarr[PARTNUM - 1]++;
+ }
+ }
+ for (ind = 0; ind < PARTNUM - 1; ind++) {
+ printf("%2d %-13lld to %-13lld %5ld %4.4f\n",
+ ind + 1, lvalbound[ind], lvalbound[ind + 1],
+ cntarr[ind], (float)(cntarr[ind] / (float)iter));
+ }
+ printf("%2d %-13lld to %-13lld %5ld %4.4f\n", PARTNUM,
+ lvalbound[PARTNUM - 1], llmax, cntarr[PARTNUM - 1],
+ (float)(cntarr[PARTNUM - 1] / (float)iter));
+ printf(" min=%lld, max=%lld\n", lltmin, lltmax);
+
+ } else {
+ /*
+ * random_range() unit test
+ */
+ itmin = imax;
+ part = imax / PARTNUM;
+ for (ind = 0; ind < PARTNUM; ind++) {
+ valbound[ind] = part * ind;
+ }
+
+ for (cnt = 0; cnt < iter; cnt++) {
+ lret = random_range(imin, imax, imult, NULL);
+ if (iter < 100)
+ printf("%ld\n", lret);
+ if (lret < itmin)
+ itmin = lret;
+ if (lret > itmax)
+ itmax = lret;
+
+ for (ind = 0; ind < PARTNUM - 1; ind++) {
+ if (valbound[ind] < lret
+ && lret <= valbound[ind + 1]) {
+ cntarr[ind]++;
+ break;
+ }
+ }
+ if (lret > valbound[PARTNUM - 1]) {
+ cntarr[PARTNUM - 1]++;
+ }
+ }
+ for (ind = 0; ind < PARTNUM - 1; ind++) {
+ printf("%2d %-13ld to %-13ld %5ld %4.4f\n", ind + 1,
+ valbound[ind], valbound[ind + 1], cntarr[ind],
+ (float)(cntarr[ind] / (float)iter));
+ }
+ printf("%2d %-13ld to %-13ld %5ld %4.4f\n", PARTNUM,
+ valbound[PARTNUM - 1], (long)imax, cntarr[PARTNUM - 1],
+ (float)(cntarr[PARTNUM - 1] / (float)iter));
+ printf(" min=%d, max=%d\n", itmin, itmax);
+
+ }
+
+ exit(0);
+}
+
+#endif
diff --git a/kernel/tests/lib/safe_file_ops.c b/kernel/tests/lib/safe_file_ops.c
new file mode 100644
index 0000000..e06d399
--- /dev/null
+++ b/kernel/tests/lib/safe_file_ops.c
@@ -0,0 +1,422 @@
+/*
+ * Copyright (C) 2012 Cyril Hrubis chrubis@suse.cz
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it is
+ * free of the rightful claim of any third person regarding infringement
+ * or the like. Any license provided herein, whether implied or
+ * otherwise, applies only to this software file. Patent licenses, if
+ * any, provided herein do not apply to combinations of this program with
+ * other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+#include <stdarg.h>
+#include <stdio.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <utime.h>
+
+#include "test.h"
+#include "safe_file_ops_fn.h"
+
+/*
+ * Count number of expected assigned conversions. Any conversion starts with '%'.
+ * The '%%' matches % and no assignment is done. The %*x matches as x would do but
+ * the assignment is suppressed.
+ *
+ * NOTE: This is not 100% correct for complex scanf strings, but will do for
+ * all of our intended usage.
+ */
+static int count_scanf_conversions(const char *fmt)
+{
+ unsigned int cnt = 0;
+ int flag = 0;
+
+ while (*fmt) {
+ switch (*fmt) {
+ case '%':
+ if (flag) {
+ cnt--;
+ flag = 0;
+ } else {
+ flag = 1;
+ cnt++;
+ }
+ break;
+ case '*':
+ if (flag) {
+ cnt--;
+ flag = 0;
+ }
+ break;
+ default:
+ flag = 0;
+ }
+
+ fmt++;
+ }
+
+ return cnt;
+}
+
+int file_scanf(const char *file, const int lineno,
+ const char *path, const char *fmt, ...)
+{
+ va_list va;
+ FILE *f;
+ int exp_convs, ret;
+
+ f = fopen(path, "r");
+
+ if (f == NULL) {
+ tst_resm(TWARN,
+ "Failed to open FILE '%s' at %s:%d",
+ path, file, lineno);
+ return 1;
+ }
+
+ exp_convs = count_scanf_conversions(fmt);
+
+ va_start(va, fmt);
+ ret = vfscanf(f, fmt, va);
+ va_end(va);
+
+ if (ret == EOF) {
+ tst_resm(TWARN,
+ "The FILE '%s' ended prematurely at %s:%d",
+ path, file, lineno);
+ goto err;
+ }
+
+ if (ret != exp_convs) {
+ tst_resm(TWARN,
+ "Expected %i conversions got %i FILE '%s' at %s:%d",
+ exp_convs, ret, path, file, lineno);
+ goto err;
+ }
+
+ if (fclose(f)) {
+ tst_resm(TWARN,
+ "Failed to close FILE '%s' at %s:%d",
+ path, file, lineno);
+ return 1;
+ }
+
+ return 0;
+
+err:
+ if (fclose(f)) {
+ tst_resm(TWARN,
+ "Failed to close FILE '%s' at %s:%d",
+ path, file, lineno);
+ }
+ return 1;
+}
+
+void safe_file_scanf(const char *file, const int lineno,
+ void (*cleanup_fn) (void),
+ const char *path, const char *fmt, ...)
+{
+ va_list va;
+ FILE *f;
+ int exp_convs, ret;
+
+ f = fopen(path, "r");
+
+ if (f == NULL) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "Failed to open FILE '%s' for reading at %s:%d",
+ path, file, lineno);
+ return;
+ }
+
+ exp_convs = count_scanf_conversions(fmt);
+
+ va_start(va, fmt);
+ ret = vfscanf(f, fmt, va);
+ va_end(va);
+
+ if (ret == EOF) {
+ tst_brkm(TBROK, cleanup_fn,
+ "The FILE '%s' ended prematurely at %s:%d",
+ path, file, lineno);
+ return;
+ }
+
+ if (ret != exp_convs) {
+ tst_brkm(TBROK, cleanup_fn,
+ "Expected %i conversions got %i FILE '%s' at %s:%d",
+ exp_convs, ret, path, file, lineno);
+ return;
+ }
+
+ if (fclose(f)) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "Failed to close FILE '%s' at %s:%d",
+ path, file, lineno);
+ return;
+ }
+}
+
+
+/*
+ * Try to parse each line from file specified by 'path' according
+ * to scanf format 'fmt'. If all fields could be parsed, stop and
+ * return 0, otherwise continue or return 1 if EOF is reached.
+ */
+int file_lines_scanf(const char *file, const int lineno,
+ void (*cleanup_fn)(void), int strict,
+ const char *path, const char *fmt, ...)
+{
+ FILE *fp;
+ int ret = 0;
+ int arg_count = 0;
+ char line[BUFSIZ];
+ va_list ap;
+
+ if (!fmt) {
+ tst_brkm(TBROK, cleanup_fn, "pattern is NULL, %s:%d",
+ file, lineno);
+ return 1;
+ }
+
+ fp = fopen(path, "r");
+ if (fp == NULL) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "Failed to open FILE '%s' for reading at %s:%d",
+ path, file, lineno);
+ return 1;
+ }
+
+ arg_count = count_scanf_conversions(fmt);
+
+ while (fgets(line, BUFSIZ, fp) != NULL) {
+ va_start(ap, fmt);
+ ret = vsscanf(line, fmt, ap);
+ va_end(ap);
+
+ if (ret == arg_count)
+ break;
+ }
+ fclose(fp);
+
+ if (strict && ret != arg_count) {
+ tst_brkm(TBROK, cleanup_fn, "Expected %i conversions got %i"
+ " FILE '%s' at %s:%d", arg_count, ret, path, file, lineno);
+ return 1;
+ }
+
+ return !(ret == arg_count);
+}
+
+int file_printf(const char *file, const int lineno,
+ const char *path, const char *fmt, ...)
+{
+ va_list va;
+ FILE *f;
+
+ f = fopen(path, "w");
+
+ if (f == NULL) {
+ tst_resm(TWARN,
+ "Failed to open FILE '%s' at %s:%d",
+ path, file, lineno);
+ return 1;
+ }
+
+ va_start(va, fmt);
+
+ if (vfprintf(f, fmt, va) < 0) {
+ tst_resm(TWARN,
+ "Failed to print to FILE '%s' at %s:%d",
+ path, file, lineno);
+ goto err;
+ }
+
+ va_end(va);
+
+ if (fclose(f)) {
+ tst_resm(TWARN,
+ "Failed to close FILE '%s' at %s:%d",
+ path, file, lineno);
+ return 1;
+ }
+
+ return 0;
+
+err:
+ if (fclose(f)) {
+ tst_resm(TWARN,
+ "Failed to close FILE '%s' at %s:%d",
+ path, file, lineno);
+ }
+ return 1;
+}
+
+void safe_file_printf(const char *file, const int lineno,
+ void (*cleanup_fn) (void),
+ const char *path, const char *fmt, ...)
+{
+ va_list va;
+ FILE *f;
+
+ f = fopen(path, "w");
+
+ if (f == NULL) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "Failed to open FILE '%s' for writing at %s:%d",
+ path, file, lineno);
+ return;
+ }
+
+ va_start(va, fmt);
+
+ if (vfprintf(f, fmt, va) < 0) {
+ tst_brkm(TBROK, cleanup_fn,
+ "Failed to print to FILE '%s' at %s:%d",
+ path, file, lineno);
+ return;
+ }
+
+ va_end(va);
+
+ if (fclose(f)) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "Failed to close FILE '%s' at %s:%d",
+ path, file, lineno);
+ return;
+ }
+}
+
+//TODO: C implementation? better error condition reporting?
+void safe_cp(const char *file, const int lineno,
+ void (*cleanup_fn) (void), const char *src, const char *dst)
+{
+ size_t len = strlen(src) + strlen(dst) + 16;
+ char buf[len];
+ int ret;
+
+ snprintf(buf, sizeof(buf), "cp \"%s\" \"%s\"", src, dst);
+
+ ret = system(buf);
+
+ if (ret) {
+ tst_brkm(TBROK, cleanup_fn,
+ "Failed to copy '%s' to '%s' at %s:%d",
+ src, dst, file, lineno);
+ }
+}
+
+#ifndef HAVE_UTIMENSAT
+
+static void set_time(struct timeval *res, const struct timespec *src,
+ long cur_tv_sec, long cur_tv_usec)
+{
+ switch (src->tv_nsec) {
+ case UTIME_NOW:
+ break;
+ case UTIME_OMIT:
+ res->tv_sec = cur_tv_sec;
+ res->tv_usec = cur_tv_usec;
+ break;
+ default:
+ res->tv_sec = src->tv_sec;
+ res->tv_usec = src->tv_nsec / 1000;
+ }
+}
+
+#endif
+
+void safe_touch(const char *file, const int lineno,
+ void (*cleanup_fn)(void),
+ const char *pathname,
+ mode_t mode, const struct timespec times[2])
+{
+ int ret;
+ mode_t defmode;
+
+ defmode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
+
+ ret = open(pathname, O_CREAT | O_WRONLY, defmode);
+ if (ret == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "Failed to open file '%s' at %s:%d",
+ pathname, file, lineno);
+ return;
+ }
+
+ ret = close(ret);
+ if (ret == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "Failed to close file '%s' at %s:%d",
+ pathname, file, lineno);
+ return;
+ }
+
+ if (mode != 0) {
+ ret = chmod(pathname, mode);
+ if (ret == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "Failed to chmod file '%s' at %s:%d",
+ pathname, file, lineno);
+ return;
+ }
+ }
+
+
+#ifdef HAVE_UTIMENSAT
+ ret = utimensat(AT_FDCWD, pathname, times, 0);
+#else
+ if (times == NULL) {
+ ret = utimes(pathname, NULL);
+ } else {
+ struct stat sb;
+ struct timeval cotimes[2];
+
+ ret = stat(pathname, &sb);
+ if (ret == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "Failed to stat file '%s' at %s:%d",
+ pathname, file, lineno);
+ return;
+ }
+
+ ret = gettimeofday(cotimes, NULL);
+ if (ret == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "Failed to gettimeofday() at %s:%d",
+ file, lineno);
+ return;
+ }
+
+ cotimes[1] = cotimes[0];
+
+ set_time(cotimes, times,
+ sb.st_atime, sb.st_atim.tv_nsec / 1000);
+ set_time(cotimes + 1, times + 1,
+ sb.st_mtime, sb.st_mtim.tv_nsec / 1000);
+
+ ret = utimes(pathname, cotimes);
+ }
+#endif
+ if (ret == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "Failed to update the access/modification time on file"
+ " '%s' at %s:%d", pathname, file, lineno);
+ }
+}
diff --git a/kernel/tests/lib/safe_macros.c b/kernel/tests/lib/safe_macros.c
new file mode 100644
index 0000000..4f48d75
--- /dev/null
+++ b/kernel/tests/lib/safe_macros.c
@@ -0,0 +1,1109 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Linux Test Project, 2010-2020
+ */
+
+#define _GNU_SOURCE
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/resource.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <sys/mount.h>
+#include <sys/xattr.h>
+#include <sys/sysinfo.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <libgen.h>
+#include <limits.h>
+#include <pwd.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <malloc.h>
+#include "test.h"
+#include "safe_macros.h"
+
+char *safe_basename(const char *file, const int lineno,
+ void (*cleanup_fn) (void), char *path)
+{
+ char *rval;
+
+ rval = basename(path);
+ if (rval == NULL) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: basename(%s) failed",
+ file, lineno, path);
+ }
+
+ return rval;
+}
+
+int
+safe_chdir(const char *file, const int lineno, void (*cleanup_fn) (void),
+ const char *path)
+{
+ int rval;
+
+ rval = chdir(path);
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: chdir(%s) failed",
+ file, lineno, path);
+ }
+
+ return rval;
+}
+
+int
+safe_close(const char *file, const int lineno, void (*cleanup_fn) (void),
+ int fildes)
+{
+ int rval;
+
+ rval = close(fildes);
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: close(%d) failed",
+ file, lineno, fildes);
+ }
+
+ return rval;
+}
+
+int
+safe_creat(const char *file, const int lineno, void (*cleanup_fn) (void),
+ const char *pathname, mode_t mode)
+{
+ int rval;
+
+ rval = creat(pathname, mode);
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: creat(%s,0%o) failed",
+ file, lineno, pathname, mode);
+ }
+
+ return rval;
+}
+
+char *safe_dirname(const char *file, const int lineno,
+ void (*cleanup_fn) (void), char *path)
+{
+ char *rval;
+
+ rval = dirname(path);
+ if (rval == NULL) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: dirname(%s) failed",
+ file, lineno, path);
+ }
+
+ return rval;
+}
+
+char *safe_getcwd(const char *file, const int lineno, void (*cleanup_fn) (void),
+ char *buf, size_t size)
+{
+ char *rval;
+
+ rval = getcwd(buf, size);
+ if (rval == NULL) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: getcwd(%p,%zu) failed",
+ file, lineno, buf, size);
+ }
+
+ return rval;
+}
+
+struct passwd *safe_getpwnam(const char *file, const int lineno,
+ void (*cleanup_fn) (void), const char *name)
+{
+ struct passwd *rval;
+
+ rval = getpwnam(name);
+ if (rval == NULL) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: getpwnam(%s) failed",
+ file, lineno, name);
+ }
+
+ return rval;
+}
+
+int
+safe_getrusage(const char *file, const int lineno, void (*cleanup_fn) (void),
+ int who, struct rusage *usage)
+{
+ int rval;
+
+ rval = getrusage(who, usage);
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: getrusage(%d,%p) failed",
+ file, lineno, who, usage);
+ }
+
+ return rval;
+}
+
+void *safe_malloc(const char *file, const int lineno, void (*cleanup_fn) (void),
+ size_t size)
+{
+ void *rval;
+
+ rval = malloc(size);
+ if (rval == NULL) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: malloc(%zu) failed",
+ file, lineno, size);
+ }
+
+ return rval;
+}
+
+int safe_mkdir(const char *file, const int lineno, void (*cleanup_fn) (void),
+ const char *pathname, mode_t mode)
+{
+ int rval;
+
+ rval = mkdir(pathname, mode);
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: mkdir(%s,0%o) failed",
+ file, lineno, pathname, mode);
+ }
+
+ return (rval);
+}
+
+int safe_rmdir(const char *file, const int lineno, void (*cleanup_fn) (void),
+ const char *pathname)
+{
+ int rval;
+
+ rval = rmdir(pathname);
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: rmdir(%s) failed",
+ file, lineno, pathname);
+ }
+
+ return (rval);
+}
+
+int safe_munmap(const char *file, const int lineno, void (*cleanup_fn) (void),
+ void *addr, size_t length)
+{
+ int rval;
+
+ rval = munmap(addr, length);
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: munmap(%p,%zu) failed",
+ file, lineno, addr, length);
+ }
+
+ return rval;
+}
+
+int safe_open(const char *file, const int lineno, void (*cleanup_fn) (void),
+ const char *pathname, int oflags, ...)
+{
+ va_list ap;
+ int rval;
+ mode_t mode;
+
+ va_start(ap, oflags);
+
+ /* Android's NDK's mode_t is smaller than an int, which results in
+ * SIGILL here when passing the mode_t type.
+ */
+ mode = va_arg(ap, int);
+
+ va_end(ap);
+
+ rval = open(pathname, oflags, mode);
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: open(%s,%d,0%o) failed",
+ file, lineno, pathname, oflags, mode);
+ }
+
+ return rval;
+}
+
+int safe_pipe(const char *file, const int lineno, void (*cleanup_fn) (void),
+ int fildes[2])
+{
+ int rval;
+
+ rval = pipe(fildes);
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: pipe({%d,%d}) failed",
+ file, lineno, fildes[0], fildes[1]);
+ }
+
+ return rval;
+}
+
+ssize_t safe_read(const char *file, const int lineno, void (*cleanup_fn) (void),
+ char len_strict, int fildes, void *buf, size_t nbyte)
+{
+ ssize_t rval;
+
+ rval = read(fildes, buf, nbyte);
+ if (rval == -1 || (len_strict && (size_t)rval != nbyte)) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: read(%d,%p,%zu) failed, returned %zd",
+ file, lineno, fildes, buf, nbyte, rval);
+ }
+
+ return rval;
+}
+
+int safe_setegid(const char *file, const int lineno, void (*cleanup_fn) (void),
+ gid_t egid)
+{
+ int rval;
+
+ rval = setegid(egid);
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: setegid(%u) failed",
+ file, lineno, (unsigned) egid);
+ }
+
+ return rval;
+}
+
+int safe_seteuid(const char *file, const int lineno, void (*cleanup_fn) (void),
+ uid_t euid)
+{
+ int rval;
+
+ rval = seteuid(euid);
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: seteuid(%u) failed",
+ file, lineno, (unsigned) euid);
+ }
+
+ return rval;
+}
+
+int safe_setgid(const char *file, const int lineno, void (*cleanup_fn) (void),
+ gid_t gid)
+{
+ int rval;
+
+ rval = setgid(gid);
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: setgid(%u) failed",
+ file, lineno, (unsigned) gid);
+ }
+
+ return rval;
+}
+
+int safe_setuid(const char *file, const int lineno, void (*cleanup_fn) (void),
+ uid_t uid)
+{
+ int rval;
+
+ rval = setuid(uid);
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: setuid(%u) failed",
+ file, lineno, (unsigned) uid);
+ }
+
+ return rval;
+}
+
+int safe_getresuid(const char *file, const int lineno, void (*cleanup_fn)(void),
+ uid_t *ruid, uid_t *euid, uid_t *suid)
+{
+ int rval;
+
+ rval = getresuid(ruid, euid, suid);
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: getresuid(%p, %p, %p) failed",
+ file, lineno, ruid, euid, suid);
+ }
+
+ return rval;
+}
+
+int safe_getresgid(const char *file, const int lineno, void (*cleanup_fn)(void),
+ gid_t *rgid, gid_t *egid, gid_t *sgid)
+{
+ int rval;
+
+ rval = getresgid(rgid, egid, sgid);
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: getresgid(%p, %p, %p) failed",
+ file, lineno, rgid, egid, sgid);
+ }
+
+ return rval;
+}
+
+int safe_unlink(const char *file, const int lineno, void (*cleanup_fn) (void),
+ const char *pathname)
+{
+ int rval;
+
+ rval = unlink(pathname);
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: unlink(%s) failed",
+ file, lineno, pathname);
+ }
+
+ return rval;
+}
+
+
+int safe_link(const char *file, const int lineno,
+ void (cleanup_fn)(void), const char *oldpath,
+ const char *newpath)
+{
+ int rval;
+
+ rval = link(oldpath, newpath);
+
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: link(%s,%s) failed",
+ file, lineno, oldpath, newpath);
+ }
+
+ return rval;
+}
+
+int safe_linkat(const char *file, const int lineno,
+ void (cleanup_fn)(void), int olddirfd, const char *oldpath,
+ int newdirfd, const char *newpath, int flags)
+{
+ int rval;
+
+ rval = linkat(olddirfd, oldpath, newdirfd, newpath, flags);
+
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: linkat(%d,%s,%d,%s,%d) failed",
+ file, lineno, olddirfd, oldpath, newdirfd,
+ newpath, flags);
+ }
+
+ return rval;
+}
+
+ssize_t safe_readlink(const char *file, const int lineno,
+ void (cleanup_fn)(void), const char *path,
+ char *buf, size_t bufsize)
+{
+ ssize_t rval;
+
+ rval = readlink(path, buf, bufsize);
+
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: readlink(%s,%p,%zu) failed",
+ file, lineno, path, buf, bufsize);
+ } else {
+ /* readlink does not append a NUL byte to the buffer.
+ * Add it now. */
+ if ((size_t) rval < bufsize)
+ buf[rval] = '\0';
+ else
+ buf[bufsize-1] = '\0';
+ }
+
+ return rval;
+}
+
+int safe_symlink(const char *file, const int lineno,
+ void (cleanup_fn)(void), const char *oldpath,
+ const char *newpath)
+{
+ int rval;
+
+ rval = symlink(oldpath, newpath);
+
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: symlink(%s,%s) failed",
+ file, lineno, oldpath, newpath);
+ }
+
+ return rval;
+}
+
+ssize_t safe_write(const char *file, const int lineno, void (cleanup_fn) (void),
+ char len_strict, int fildes, const void *buf, size_t nbyte)
+{
+ ssize_t rval;
+
+ rval = write(fildes, buf, nbyte);
+ if (rval == -1 || (len_strict && (size_t)rval != nbyte)) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: write(%d,%p,%zu) failed",
+ file, lineno, fildes, buf, rval);
+ }
+
+ return rval;
+}
+
+long safe_strtol(const char *file, const int lineno,
+ void (cleanup_fn) (void), char *str, long min, long max)
+{
+ long rval;
+ char *endptr;
+
+ errno = 0;
+ rval = strtol(str, &endptr, 10);
+
+ if ((errno == ERANGE && (rval == LONG_MAX || rval == LONG_MIN))
+ || (errno != 0 && rval == 0)) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: strtol(%s) failed", file, lineno, str);
+ return rval;
+ }
+
+ if (endptr == str || (*endptr != '\0' && *endptr != '\n')) {
+ tst_brkm(TBROK, cleanup_fn,
+ "%s:%d: strtol(%s): Invalid value", file, lineno, str);
+ return 0;
+ }
+
+ if (rval > max || rval < min) {
+ tst_brkm(TBROK, cleanup_fn,
+ "%s:%d: strtol(%s): %ld is out of range %ld - %ld",
+ file, lineno, str, rval, min, max);
+ return 0;
+ }
+
+ return rval;
+}
+
+unsigned long safe_strtoul(const char *file, const int lineno,
+ void (cleanup_fn) (void), char *str,
+ unsigned long min, unsigned long max)
+{
+ unsigned long rval;
+ char *endptr;
+
+ errno = 0;
+ rval = strtoul(str, &endptr, 10);
+
+ if ((errno == ERANGE && rval == ULONG_MAX)
+ || (errno != 0 && rval == 0)) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: strtoul(%s) failed", file, lineno, str);
+ return rval;
+ }
+
+ if (rval > max || rval < min) {
+ tst_brkm(TBROK, cleanup_fn,
+ "%s:%d: strtoul(%s): %lu is out of range %lu - %lu",
+ file, lineno, str, rval, min, max);
+ return 0;
+ }
+
+ if (endptr == str || (*endptr != '\0' && *endptr != '\n')) {
+ tst_brkm(TBROK, cleanup_fn,
+ "Invalid value: '%s' at %s:%d", str, file, lineno);
+ return 0;
+ }
+
+ return rval;
+}
+
+long safe_sysconf(const char *file, const int lineno,
+ void (cleanup_fn) (void), int name)
+{
+ long rval;
+ errno = 0;
+
+ rval = sysconf(name);
+
+ if (rval == -1) {
+ if (errno) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: sysconf(%d) failed",
+ file, lineno, name);
+ } else {
+ tst_resm(TINFO, "%s:%d: sysconf(%d): "
+ "queried option is not available"
+ " or there is no definite limit",
+ file, lineno, name);
+ }
+ }
+
+ return rval;
+}
+
+int safe_chmod(const char *file, const int lineno,
+ void (cleanup_fn)(void), const char *path, mode_t mode)
+{
+ int rval;
+
+ rval = chmod(path, mode);
+
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: chmod(%s,0%o) failed",
+ file, lineno, path, mode);
+ }
+
+ return rval;
+}
+
+int safe_fchmod(const char *file, const int lineno,
+ void (cleanup_fn)(void), int fd, mode_t mode)
+{
+ int rval;
+
+ rval = fchmod(fd, mode);
+
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: fchmod(%d,0%o) failed",
+ file, lineno, fd, mode);
+ }
+
+ return rval;
+}
+
+int safe_chown(const char *file, const int lineno, void (cleanup_fn)(void),
+ const char *path, uid_t owner, gid_t group)
+{
+ int rval;
+
+ rval = chown(path, owner, group);
+
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: chown(%s,%d,%d) failed",
+ file, lineno, path, owner, group);
+ }
+
+ return rval;
+}
+
+int safe_fchown(const char *file, const int lineno, void (cleanup_fn)(void),
+ int fd, uid_t owner, gid_t group)
+{
+ int rval;
+
+ rval = fchown(fd, owner, group);
+
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: fchown(%d,%d,%d) failed",
+ file, lineno, fd, owner, group);
+ }
+
+ return rval;
+}
+
+pid_t safe_wait(const char *file, const int lineno, void (cleanup_fn)(void),
+ int *status)
+{
+ pid_t rval;
+
+ rval = wait(status);
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: wait(%p) failed",
+ file, lineno, status);
+ }
+
+ return rval;
+}
+
+pid_t safe_waitpid(const char *file, const int lineno, void (cleanup_fn)(void),
+ pid_t pid, int *status, int opts)
+{
+ pid_t rval;
+
+ rval = waitpid(pid, status, opts);
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: waitpid(%d,%p,%d) failed",
+ file, lineno, pid, status, opts);
+ }
+
+ return rval;
+}
+
+void *safe_memalign(const char *file, const int lineno,
+ void (*cleanup_fn) (void), size_t alignment, size_t size)
+{
+ void *rval;
+
+ rval = memalign(alignment, size);
+ if (rval == NULL)
+ tst_brkm(TBROK | TERRNO, cleanup_fn, "memalign failed at %s:%d",
+ file, lineno);
+
+ return rval;
+}
+
+int safe_kill(const char *file, const int lineno, void (cleanup_fn)(void),
+ pid_t pid, int sig)
+{
+ int rval;
+
+ rval = kill(pid, sig);
+
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: kill(%d,%s) failed",
+ file, lineno, pid, tst_strsig(sig));
+ }
+
+ return rval;
+}
+
+int safe_mkfifo(const char *file, const int lineno,
+ void (*cleanup_fn)(void), const char *pathname, mode_t mode)
+{
+ int rval;
+
+ rval = mkfifo(pathname, mode);
+
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: mkfifo(%s, 0%o) failed",
+ file, lineno, pathname, mode);
+ }
+
+ return rval;
+}
+
+int safe_rename(const char *file, const int lineno, void (*cleanup_fn)(void),
+ const char *oldpath, const char *newpath)
+{
+ int rval;
+
+ rval = rename(oldpath, newpath);
+
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: rename(%s, %s) failed",
+ file, lineno, oldpath, newpath);
+ }
+
+ return rval;
+}
+
+static const char *const fuse_fs_types[] = {
+ "exfat",
+ "ntfs",
+};
+
+static int possibly_fuse(const char *fs_type)
+{
+ unsigned int i;
+
+ if (!fs_type)
+ return 0;
+
+ for (i = 0; i < ARRAY_SIZE(fuse_fs_types); i++) {
+ if (!strcmp(fuse_fs_types[i], fs_type))
+ return 1;
+ }
+
+ return 0;
+}
+
+int safe_mount(const char *file, const int lineno, void (*cleanup_fn)(void),
+ const char *source, const char *target,
+ const char *filesystemtype, unsigned long mountflags,
+ const void *data)
+{
+ int rval;
+
+ /*
+ * Don't try using the kernel's NTFS driver when mounting NTFS, since
+ * the kernel's NTFS driver doesn't have proper write support.
+ */
+ if (!filesystemtype || strcmp(filesystemtype, "ntfs")) {
+ rval = mount(source, target, filesystemtype, mountflags, data);
+ if (!rval)
+ return 0;
+ }
+
+ /*
+ * The FUSE filesystem executes mount.fuse helper, which tries to
+ * execute corresponding binary name which is encoded at the start of
+ * the source string and separated by # from the device name.
+ *
+ * The mount helpers are called mount.$fs_type.
+ */
+ if (possibly_fuse(filesystemtype)) {
+ char buf[1024];
+
+ tst_resm(TINFO, "Trying FUSE...");
+ snprintf(buf, sizeof(buf), "mount.%s '%s' '%s'",
+ filesystemtype, source, target);
+
+ rval = tst_system(buf);
+ if (WIFEXITED(rval) && WEXITSTATUS(rval) == 0)
+ return 0;
+
+ tst_brkm(TBROK, cleanup_fn, "mount.%s failed with %i",
+ filesystemtype, rval);
+ return -1;
+ } else {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: mount(%s, %s, %s, %lu, %p) failed",
+ file, lineno, source, target, filesystemtype,
+ mountflags, data);
+ }
+
+ return -1;
+}
+
+int safe_umount(const char *file, const int lineno, void (*cleanup_fn)(void),
+ const char *target)
+{
+ int rval;
+
+ rval = tst_umount(target);
+
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: umount(%s) failed",
+ file, lineno, target);
+ }
+
+ return rval;
+}
+
+DIR* safe_opendir(const char *file, const int lineno, void (cleanup_fn)(void),
+ const char *name)
+{
+ DIR *rval;
+
+ rval = opendir(name);
+
+ if (!rval) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: opendir(%s) failed", file, lineno, name);
+ }
+
+ return rval;
+}
+
+int safe_closedir(const char *file, const int lineno, void (cleanup_fn)(void),
+ DIR *dirp)
+{
+ int rval;
+
+ rval = closedir(dirp);
+
+ if (rval) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: closedir(%p) failed", file, lineno, dirp);
+ }
+
+ return rval;
+}
+
+struct dirent *safe_readdir(const char *file, const int lineno, void (cleanup_fn)(void),
+ DIR *dirp)
+{
+ struct dirent *rval;
+ int err = errno;
+
+ errno = 0;
+ rval = readdir(dirp);
+
+ if (!rval && errno) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: readdir(%p) failed", file, lineno, dirp);
+ }
+
+ errno = err;
+ return rval;
+}
+
+int safe_getpriority(const char *file, const int lineno, int which, id_t who)
+{
+ int rval, err = errno;
+
+ errno = 0;
+ rval = getpriority(which, who);
+ if (errno) {
+ tst_brkm(TBROK | TERRNO, NULL,
+ "%s:%d getpriority(%i, %i) failed",
+ file, lineno, which, who);
+ }
+
+ errno = err;
+ return rval;
+}
+
+ssize_t safe_getxattr(const char *file, const int lineno, const char *path,
+ const char *name, void *value, size_t size)
+{
+ ssize_t rval;
+
+ rval = getxattr(path, name, value, size);
+
+ if (rval == -1) {
+ if (errno == ENOTSUP) {
+ tst_brkm(TCONF, NULL,
+ "%s:%d: no xattr support in fs or mounted "
+ "without user_xattr option", file, lineno);
+ }
+
+ tst_brkm(TBROK | TERRNO, NULL,
+ "%s:%d: getxattr(%s, %s, %p, %zu) failed",
+ file, lineno, path, name, value, size);
+ }
+
+ return rval;
+}
+
+int safe_setxattr(const char *file, const int lineno, const char *path,
+ const char *name, const void *value, size_t size, int flags)
+{
+ int rval;
+
+ rval = setxattr(path, name, value, size, flags);
+
+ if (rval) {
+ if (errno == ENOTSUP) {
+ tst_brkm(TCONF, NULL,
+ "%s:%d: no xattr support in fs or mounted "
+ "without user_xattr option", file, lineno);
+ }
+
+ tst_brkm(TBROK | TERRNO, NULL,
+ "%s:%d: setxattr(%s, %s, %p, %zu) failed",
+ file, lineno, path, name, value, size);
+ }
+
+ return rval;
+}
+
+int safe_lsetxattr(const char *file, const int lineno, const char *path,
+ const char *name, const void *value, size_t size, int flags)
+{
+ int rval;
+
+ rval = lsetxattr(path, name, value, size, flags);
+
+ if (rval) {
+ if (errno == ENOTSUP) {
+ tst_brkm(TCONF, NULL,
+ "%s:%d: no xattr support in fs or mounted "
+ "without user_xattr option", file, lineno);
+ }
+
+ tst_brkm(TBROK | TERRNO, NULL,
+ "%s:%d: lsetxattr(%s, %s, %p, %zu, %i) failed",
+ file, lineno, path, name, value, size, flags);
+ }
+
+ return rval;
+}
+
+int safe_fsetxattr(const char *file, const int lineno, int fd, const char *name,
+ const void *value, size_t size, int flags)
+{
+ int rval;
+
+ rval = fsetxattr(fd, name, value, size, flags);
+
+ if (rval) {
+ if (errno == ENOTSUP) {
+ tst_brkm(TCONF, NULL,
+ "%s:%d: no xattr support in fs or mounted "
+ "without user_xattr option", file, lineno);
+ }
+
+ tst_brkm(TBROK | TERRNO, NULL,
+ "%s:%d: fsetxattr(%i, %s, %p, %zu, %i) failed",
+ file, lineno, fd, name, value, size, flags);
+ }
+
+ return rval;
+}
+
+int safe_removexattr(const char *file, const int lineno, const char *path,
+ const char *name)
+{
+ int rval;
+
+ rval = removexattr(path, name);
+
+ if (rval) {
+ if (errno == ENOTSUP) {
+ tst_brkm(TCONF, NULL,
+ "%s:%d: no xattr support in fs or mounted "
+ "without user_xattr option", file, lineno);
+ }
+
+ tst_brkm(TBROK | TERRNO, NULL,
+ "%s:%d: removexattr(%s, %s) failed",
+ file, lineno, path, name);
+ }
+
+ return rval;
+}
+
+int safe_lremovexattr(const char *file, const int lineno, const char *path,
+ const char *name)
+{
+ int rval;
+
+ rval = lremovexattr(path, name);
+
+ if (rval) {
+ if (errno == ENOTSUP) {
+ tst_brkm(TCONF, NULL,
+ "%s:%d: no xattr support in fs or mounted "
+ "without user_xattr option", file, lineno);
+ }
+
+ tst_brkm(TBROK | TERRNO, NULL,
+ "%s:%d: lremovexattr(%s, %s) failed",
+ file, lineno, path, name);
+ }
+
+ return rval;
+}
+
+int safe_fremovexattr(const char *file, const int lineno, int fd,
+ const char *name)
+{
+ int rval;
+
+ rval = fremovexattr(fd, name);
+
+ if (rval) {
+ if (errno == ENOTSUP) {
+ tst_brkm(TCONF, NULL,
+ "%s:%d: no xattr support in fs or mounted "
+ "without user_xattr option", file, lineno);
+ }
+
+ tst_brkm(TBROK | TERRNO, NULL,
+ "%s:%d: fremovexattr(%i, %s) failed",
+ file, lineno, fd, name);
+ }
+
+ return rval;
+}
+
+int safe_fsync(const char *file, const int lineno, int fd)
+{
+ int rval;
+
+ rval = fsync(fd);
+
+ if (rval) {
+ tst_brkm(TBROK | TERRNO, NULL,
+ "%s:%d: fsync(%i) failed", file, lineno, fd);
+ }
+
+ return rval;
+}
+
+pid_t safe_setsid(const char *file, const int lineno)
+{
+ pid_t rval;
+
+ rval = setsid();
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, NULL,
+ "%s:%d: setsid() failed", file, lineno);
+ }
+
+ return rval;
+}
+
+int safe_mknod(const char *file, const int lineno, const char *pathname,
+ mode_t mode, dev_t dev)
+{
+ int rval;
+
+ rval = mknod(pathname, mode, dev);
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, NULL,
+ "%s:%d: mknod() failed", file, lineno);
+ }
+
+ return rval;
+}
+
+int safe_mlock(const char *file, const int lineno, const void *addr,
+ size_t len)
+{
+ int rval;
+
+ rval = mlock(addr, len);
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, NULL,
+ "%s:%d: mlock() failed", file, lineno);
+ }
+
+ return rval;
+}
+
+int safe_munlock(const char *file, const int lineno, const void *addr,
+ size_t len)
+{
+ int rval;
+
+ rval = munlock(addr, len);
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, NULL,
+ "%s:%d: munlock() failed", file, lineno);
+ }
+
+ return rval;
+}
+
+int safe_mincore(const char *file, const int lineno, void *start,
+ size_t length, unsigned char *vec)
+{
+ int rval;
+
+ rval = mincore(start, length, vec);
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, NULL,
+ "%s:%d: mincore() failed", file, lineno);
+ }
+
+ return rval;
+}
+
+int safe_sysinfo(const char *file, const int lineno, struct sysinfo *info)
+{
+ int ret;
+
+ errno = 0;
+ ret = sysinfo(info);
+
+ if (ret == -1) {
+ tst_brkm_(file, lineno, TBROK | TERRNO, NULL,
+ "sysinfo() failed");
+ } else if (ret) {
+ tst_brkm_(file, lineno, TBROK | TERRNO, NULL,
+ "Invalid sysinfo() return value %d", ret);
+ }
+
+ return ret;
+}
diff --git a/kernel/tests/lib/safe_net.c b/kernel/tests/lib/safe_net.c
new file mode 100644
index 0000000..4993680
--- /dev/null
+++ b/kernel/tests/lib/safe_net.c
@@ -0,0 +1,459 @@
+/*
+ * Copyright (c) 2015 Fujitsu Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <errno.h>
+#include "test.h"
+#include "safe_net_fn.h"
+
+char *tst_sock_addr(const struct sockaddr *sa, socklen_t salen, char *res,
+ size_t len)
+{
+ char portstr[8];
+
+ switch (sa->sa_family) {
+
+ case AF_INET: {
+ struct sockaddr_in *sin = (struct sockaddr_in *)sa;
+
+ if (!inet_ntop(AF_INET, &sin->sin_addr, res, len))
+ return NULL;
+
+ if (ntohs(sin->sin_port) != 0) {
+ snprintf(portstr, sizeof(portstr), ":%d",
+ ntohs(sin->sin_port));
+ strcat(res, portstr);
+ }
+
+ return res;
+ }
+
+ case AF_INET6: {
+ struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
+
+ res[0] = '[';
+ if (!inet_ntop(AF_INET6, &sin6->sin6_addr, res + 1, len - 1))
+ return NULL;
+
+ if (ntohs(sin6->sin6_port) != 0) {
+ snprintf(portstr, sizeof(portstr), "]:%d",
+ ntohs(sin6->sin6_port));
+ strcat(res, portstr);
+ return res;
+ }
+
+ return res + 1;
+ }
+
+ case AF_UNIX: {
+ struct sockaddr_un *unp = (struct sockaddr_un *)sa;
+
+ if (unp->sun_path[0] == '\0')
+ strcpy(res, "(no pathname bound)");
+ else
+ snprintf(res, len, "%s", unp->sun_path);
+
+ return res;
+ }
+
+ default: {
+ snprintf(res, len,
+ "sock_ntop: unknown AF_xxx: %d, len: %d",
+ sa->sa_family, salen);
+
+ return res;
+ }
+
+ }
+}
+
+int tst_getsockport(const char *file, const int lineno, int sockfd)
+{
+ struct sockaddr_storage ss;
+ socklen_t addrlen = sizeof(ss);
+ struct sockaddr *sa = (struct sockaddr *)&ss;
+
+ safe_getsockname(file, lineno, NULL, sockfd, sa, &addrlen);
+
+ switch (sa->sa_family) {
+ case AF_INET: {
+ struct sockaddr_in *sin = (struct sockaddr_in *)sa;
+
+ return ntohs(sin->sin_port);
+ }
+ case AF_INET6: {
+ struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
+
+ return ntohs(sin6->sin6_port);
+ } }
+
+ return -1;
+}
+
+int safe_socket(const char *file, const int lineno, void (cleanup_fn)(void),
+ int domain, int type, int protocol)
+{
+ int rval, ttype;
+
+ rval = socket(domain, type, protocol);
+
+ if (rval < 0) {
+ switch (errno) {
+ case EPROTONOSUPPORT:
+ case ESOCKTNOSUPPORT:
+ case EOPNOTSUPP:
+ case EPFNOSUPPORT:
+ case EAFNOSUPPORT:
+ ttype = TCONF;
+ break;
+ default:
+ ttype = TBROK;
+ }
+
+ tst_brkm(ttype | TERRNO, cleanup_fn,
+ "%s:%d: socket(%d, %d, %d) failed", file, lineno,
+ domain, type, protocol);
+ }
+
+ return rval;
+}
+
+int safe_socketpair(const char *file, const int lineno, int domain, int type,
+ int protocol, int sv[])
+{
+ int rval, ttype;
+
+ rval = socketpair(domain, type, protocol, sv);
+
+ if (rval < 0) {
+ switch (errno) {
+ case EPROTONOSUPPORT:
+ case EOPNOTSUPP:
+ case EAFNOSUPPORT:
+ ttype = TCONF;
+ break;
+ default:
+ ttype = TBROK;
+ }
+
+ tst_brkm(ttype | TERRNO, NULL,
+ "%s:%d: socketpair(%d, %d, %d, %p) failed",
+ file, lineno, domain, type, protocol, sv);
+ }
+
+ return rval;
+}
+
+int safe_getsockopt(const char *file, const int lineno, int sockfd, int level,
+ int optname, void *optval, socklen_t *optlen)
+{
+ int rval = getsockopt(sockfd, level, optname, optval, optlen);
+
+ if (!rval)
+ return 0;
+
+ tst_brkm(TBROK | TERRNO, NULL,
+ "%s:%d: getsockopt(%d, %d, %d, %p, %p) failed",
+ file, lineno, sockfd, level, optname, optval, optlen);
+
+ return rval;
+}
+
+int safe_setsockopt(const char *file, const int lineno, int sockfd, int level,
+ int optname, const void *optval, socklen_t optlen)
+{
+ int rval;
+
+ rval = setsockopt(sockfd, level, optname, optval, optlen);
+
+ if (rval) {
+ tst_brkm(TBROK | TERRNO, NULL,
+ "%s:%d: setsockopt(%d, %d, %d, %p, %d) failed",
+ file, lineno, sockfd, level, optname, optval, optlen);
+ }
+
+ return rval;
+}
+
+ssize_t safe_send(const char *file, const int lineno, char len_strict,
+ int sockfd, const void *buf, size_t len, int flags)
+{
+ ssize_t rval;
+
+ rval = send(sockfd, buf, len, flags);
+
+ if (rval == -1 || (len_strict && (size_t)rval != len)) {
+ tst_brkm(TBROK | TERRNO, NULL,
+ "%s:%d: send(%d, %p, %zu, %d) failed",
+ file, lineno, sockfd, buf, len, flags);
+ }
+
+ return rval;
+}
+
+ssize_t safe_sendto(const char *file, const int lineno, char len_strict,
+ int sockfd, const void *buf, size_t len, int flags,
+ const struct sockaddr *dest_addr, socklen_t addrlen)
+{
+ ssize_t rval;
+ char res[128];
+
+ rval = sendto(sockfd, buf, len, flags, dest_addr, addrlen);
+
+ if (rval == -1 || (len_strict && (size_t)rval != len)) {
+ tst_brkm(TBROK | TERRNO, NULL,
+ "%s:%d: sendto(%d, %p, %zu, %d, %s, %d) failed",
+ file, lineno, sockfd, buf, len, flags,
+ tst_sock_addr(dest_addr, addrlen, res, sizeof(res)),
+ addrlen);
+ }
+
+ return rval;
+}
+
+ssize_t safe_sendmsg(const char *file, const int lineno, size_t len,
+ int sockfd, const struct msghdr *msg, int flags)
+{
+ ssize_t rval;
+
+ rval = sendmsg(sockfd, msg, flags);
+
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, NULL,
+ "%s:%d: sendmsg(%d, %p, %d) failed",
+ file, lineno, sockfd, msg, flags);
+ }
+
+ if (len && (size_t)rval != len) {
+ tst_brkm(TBROK, NULL,
+ "%s:%d: sendmsg(%d, %p, %d) ret(%zd) != len(%zu)",
+ file, lineno, sockfd, msg, flags, rval, len);
+ }
+
+ return rval;
+}
+
+ssize_t safe_recvmsg(const char *file, const int lineno, size_t len,
+ int sockfd, struct msghdr *msg, int flags)
+{
+ ssize_t rval;
+
+ rval = recvmsg(sockfd, msg, flags);
+
+ if (rval == -1) {
+ tst_brkm(TBROK | TERRNO, NULL,
+ "%s:%d: recvmsg(%d, %p, %d) failed",
+ file, lineno, sockfd, msg, flags);
+ }
+
+ if (len && (size_t)rval != len) {
+ tst_brkm(TBROK, NULL,
+ "%s:%d: recvmsg(%d, %p, %d) ret(%zd) != len(%zu)",
+ file, lineno, sockfd, msg, flags, rval, len);
+ }
+
+ return rval;
+
+}
+
+int safe_bind(const char *file, const int lineno, void (cleanup_fn)(void),
+ int socket, const struct sockaddr *address,
+ socklen_t address_len)
+{
+ int i;
+ char buf[128];
+
+ for (i = 0; i < 120; i++) {
+ if (!bind(socket, address, address_len))
+ return 0;
+
+ if (errno != EADDRINUSE) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: bind(%d, %s, %d) failed", file, lineno,
+ socket, tst_sock_addr(address, address_len,
+ buf, sizeof(buf)),
+ address_len);
+ return -1;
+ }
+
+ if ((i + 1) % 10 == 0) {
+ tst_resm(TINFO, "address is in use, waited %3i sec",
+ i + 1);
+ }
+
+ sleep(1);
+ }
+
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: Failed to bind(%d, %s, %d) after 120 retries", file,
+ lineno, socket,
+ tst_sock_addr(address, address_len, buf, sizeof(buf)),
+ address_len);
+ return -1;
+}
+
+int safe_listen(const char *file, const int lineno, void (cleanup_fn)(void),
+ int socket, int backlog)
+{
+ int rval;
+
+ rval = listen(socket, backlog);
+
+ if (rval < 0) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: listen(%d, %d) failed", file, lineno, socket,
+ backlog);
+ }
+
+ return rval;
+}
+
+int safe_accept(const char *file, const int lineno, void (cleanup_fn)(void),
+ int sockfd, struct sockaddr *addr, socklen_t *addrlen)
+{
+ int rval;
+
+ rval = accept(sockfd, addr, addrlen);
+
+ if (rval < 0) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: accept(%d, %p, %d) failed", file, lineno,
+ sockfd, addr, *addrlen);
+ }
+
+ return rval;
+}
+
+int safe_connect(const char *file, const int lineno, void (cleanup_fn)(void),
+ int sockfd, const struct sockaddr *addr, socklen_t addrlen)
+{
+ int rval;
+ char buf[128];
+
+ rval = connect(sockfd, addr, addrlen);
+
+ if (rval < 0) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: connect(%d, %s, %d) failed", file, lineno,
+ sockfd, tst_sock_addr(addr, addrlen, buf,
+ sizeof(buf)), addrlen);
+ }
+
+ return rval;
+}
+
+int safe_getsockname(const char *file, const int lineno,
+ void (cleanup_fn)(void), int sockfd, struct sockaddr *addr,
+ socklen_t *addrlen)
+{
+ int rval;
+ char buf[128];
+
+ rval = getsockname(sockfd, addr, addrlen);
+
+ if (rval < 0) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: getsockname(%d, %s, %d) failed", file, lineno,
+ sockfd, tst_sock_addr(addr, *addrlen, buf,
+ sizeof(buf)), *addrlen);
+ }
+
+ return rval;
+}
+
+int safe_gethostname(const char *file, const int lineno,
+ char *name, size_t size)
+{
+ int rval = gethostname(name, size);
+
+ if (rval < 0) {
+ tst_brkm(TBROK | TERRNO, NULL,
+ "%s:%d: gethostname(%p, %zu) failed",
+ file, lineno, name, size);
+ }
+
+ return rval;
+}
+
+/*
+ * @return port in network byte order.
+ */
+unsigned short tst_get_unused_port(const char *file, const int lineno,
+ void (cleanup_fn)(void), unsigned short family, int type)
+{
+ int sock;
+ socklen_t slen;
+ struct sockaddr_storage _addr;
+ struct sockaddr *addr = (struct sockaddr *)&_addr;
+ struct sockaddr_in *addr4 = (struct sockaddr_in *)addr;
+ struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)addr;
+
+ switch (family) {
+ case AF_INET:
+ addr4->sin_family = AF_INET;
+ addr4->sin_port = 0;
+ addr4->sin_addr.s_addr = INADDR_ANY;
+ slen = sizeof(*addr4);
+ break;
+
+ case AF_INET6:
+ addr6->sin6_family = AF_INET6;
+ addr6->sin6_port = 0;
+ addr6->sin6_addr = in6addr_any;
+ slen = sizeof(*addr6);
+ break;
+
+ default:
+ tst_brkm(TBROK, cleanup_fn,
+ "%s:%d: unknown family", file, lineno);
+ return -1;
+ }
+
+ sock = socket(addr->sa_family, type, 0);
+ if (sock < 0) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: socket failed", file, lineno);
+ return -1;
+ }
+
+ if (bind(sock, addr, slen) < 0) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: bind failed", file, lineno);
+ return -1;
+ }
+
+ if (getsockname(sock, addr, &slen) == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: getsockname failed", file, lineno);
+ return -1;
+ }
+
+ if (close(sock) == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: close failed", file, lineno);
+ return -1;
+ }
+
+ switch (family) {
+ case AF_INET:
+ return addr4->sin_port;
+ case AF_INET6:
+ return addr6->sin6_port;
+ default:
+ return -1;
+ }
+}
diff --git a/kernel/tests/lib/safe_pthread.c b/kernel/tests/lib/safe_pthread.c
new file mode 100644
index 0000000..2866aa5
--- /dev/null
+++ b/kernel/tests/lib/safe_pthread.c
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2016 Oracle and/or its affiliates. All Rights Reserved.
+ */
+
+#include <pthread.h>
+#include <stdio.h>
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+
+int safe_pthread_create(const char *file, const int lineno,
+ pthread_t *thread_id, const pthread_attr_t *attr,
+ void *(*thread_fn)(void *), void *arg)
+{
+ int rval;
+
+ rval = pthread_create(thread_id, attr, thread_fn, arg);
+
+ if (rval) {
+ tst_brk_(file, lineno, TBROK,
+ "pthread_create(%p,%p,%p,%p) failed: %s", thread_id,
+ attr, thread_fn, arg, tst_strerrno(rval));
+ }
+
+ return rval;
+}
+
+int safe_pthread_join(const char *file, const int lineno,
+ pthread_t thread_id, void **retval)
+{
+ int rval;
+
+ rval = pthread_join(thread_id, retval);
+
+ if (rval) {
+ tst_brk_(file, lineno, TBROK,
+ "pthread_join(..., %p) failed: %s",
+ retval, tst_strerrno(rval));
+ }
+
+ return rval;
+}
diff --git a/kernel/tests/lib/safe_stdio.c b/kernel/tests/lib/safe_stdio.c
new file mode 100644
index 0000000..966a039
--- /dev/null
+++ b/kernel/tests/lib/safe_stdio.c
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2013 Cyril Hrubis <chrubis@suse.cz>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#define _GNU_SOURCE
+#include <stdarg.h>
+#include <stdio.h>
+#include <errno.h>
+#include "test.h"
+#include "safe_stdio_fn.h"
+
+FILE *safe_fopen(const char *file, const int lineno, void (cleanup_fn)(void),
+ const char *path, const char *mode)
+{
+ FILE *f = fopen(path, mode);
+
+ if (f == NULL) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: fopen(%s,%s) failed",
+ file, lineno, path, mode);
+ }
+
+ return f;
+}
+
+int safe_fclose(const char *file, const int lineno, void (cleanup_fn)(void),
+ FILE *f)
+{
+ int ret;
+
+ ret = fclose(f);
+
+ if (ret) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: fclose(%p) failed", file, lineno, f);
+ }
+
+ return ret;
+}
+
+int safe_asprintf(const char *file, const int lineno, void (cleanup_fn)(void),
+ char **strp, const char *fmt, ...)
+{
+ int ret;
+ va_list va;
+
+ va_start(va, fmt);
+ ret = vasprintf(strp, fmt, va);
+ va_end(va);
+
+ if (ret < 0) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: asprintf(%s,...) failed", file, lineno, fmt);
+ }
+
+ return ret;
+}
+
+FILE *safe_popen(const char *file, const int lineno, void (cleanup_fn)(void),
+ const char *command, const char *type)
+{
+ FILE *stream;
+ const int saved_errno = errno;
+
+ errno = 0;
+ stream = popen(command, type);
+
+ if (stream == NULL) {
+ if (errno != 0) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: popen(%s,%s) failed",
+ file, lineno, command, type);
+ } else {
+ tst_brkm(TBROK, cleanup_fn,
+ "%s:%d: popen(%s,%s) failed: Out of memory",
+ file, lineno, command, type);
+ }
+ }
+
+ errno = saved_errno;
+
+ return stream;
+}
diff --git a/kernel/tests/lib/self_exec.c b/kernel/tests/lib/self_exec.c
new file mode 100644
index 0000000..de7d095
--- /dev/null
+++ b/kernel/tests/lib/self_exec.c
@@ -0,0 +1,225 @@
+/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: t -*- */
+/*
+ * self_exec.c: self_exec magic required to run child functions on uClinux
+ *
+ * Copyright (C) 2005 Paul J.Y. Lahaie <pjlahaie-at-steamballoon.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * This software was produced by Steamballoon Incorporated
+ * 55 Byward Market Square, 2nd Floor North, Ottawa, ON K1N 9C3, Canada
+ */
+
+#define _GNU_SOURCE /* for asprintf */
+
+#include "config.h"
+
+#ifdef UCLINUX
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include "test.h"
+#include "safe_macros.h"
+
+/* Set from parse_opts.c: */
+char *child_args; /* Arguments to child when -C is used */
+
+static char *start_cwd; /* Stores the starting directory for self_exec */
+
+int asprintf(char **app, const char *fmt, ...)
+{
+ va_list ptr;
+ int rv;
+ char *p;
+
+ /*
+ * First iteration - find out size of buffer required and allocate it.
+ */
+ va_start(ptr, fmt);
+ rv = vsnprintf(NULL, 0, fmt, ptr);
+ va_end(ptr);
+
+ p = malloc(++rv); /* allocate the buffer */
+ *app = p;
+ if (!p) {
+ return -1;
+ }
+
+ /*
+ * Second iteration - actually produce output.
+ */
+ va_start(ptr, fmt);
+ rv = vsnprintf(p, rv, fmt, ptr);
+ va_end(ptr);
+
+ return rv;
+}
+
+void maybe_run_child(void (*child) (), const char *fmt, ...)
+{
+ va_list ap;
+ char *child_dir;
+ char *p, *tok;
+ int *iptr, i, j;
+ char *s;
+ char **sptr;
+ char *endptr;
+
+ /* Store the current directory for later use. */
+ start_cwd = getcwd(NULL, 0);
+
+ if (child_args) {
+ char *args = strdup(child_args);
+
+ child_dir = strtok(args, ",");
+ if (strlen(child_dir) == 0) {
+ tst_brkm(TBROK, NULL,
+ "Could not get directory from -C option");
+ return;
+ }
+
+ va_start(ap, fmt);
+
+ for (p = fmt; *p; p++) {
+ tok = strtok(NULL, ",");
+ if (!tok || strlen(tok) == 0) {
+ tst_brkm(TBROK, NULL,
+ "Invalid argument to -C option");
+ return;
+ }
+
+ switch (*p) {
+ case 'd':
+ iptr = va_arg(ap, int *);
+ i = strtol(tok, &endptr, 10);
+ if (*endptr != '\0') {
+ tst_brkm(TBROK, NULL,
+ "Invalid argument to -C option");
+ return;
+ }
+ *iptr = i;
+ break;
+ case 'n':
+ j = va_arg(ap, int);
+ i = strtol(tok, &endptr, 10);
+ if (*endptr != '\0') {
+ tst_brkm(TBROK, NULL,
+ "Invalid argument to -C option");
+ return;
+ }
+ if (j != i) {
+ va_end(ap);
+ free(args);
+ return;
+ }
+ break;
+ case 's':
+ s = va_arg(ap, char *);
+ if (!strncpy(s, tok, strlen(tok) + 1)) {
+ tst_brkm(TBROK, NULL,
+ "Could not strncpy for -C option");
+ return;
+ }
+ break;
+ case 'S':
+ sptr = va_arg(ap, char **);
+ *sptr = strdup(tok);
+ if (!*sptr) {
+ tst_brkm(TBROK, NULL,
+ "Could not strdup for -C option");
+ return;
+ }
+ break;
+ default:
+ tst_brkm(TBROK, NULL,
+ "Format string option %c not implemented",
+ *p);
+ return;
+ }
+ }
+
+ va_end(ap);
+ free(args);
+ SAFE_CHDIR(NULL, child_dir);
+
+ (*child) ();
+ tst_resm(TWARN, "Child function returned unexpectedly");
+ /* Exit here? or exit silently? */
+ }
+}
+
+int self_exec(const char *argv0, const char *fmt, ...)
+{
+ va_list ap;
+ char *p;
+ char *tmp_cwd;
+ char *arg;
+ int ival;
+ char *str;
+
+ if ((tmp_cwd = getcwd(NULL, 0)) == NULL) {
+ tst_resm(TBROK, "Could not getcwd()");
+ return -1;
+ }
+
+ arg = strdup(tmp_cwd);
+ if (arg == NULL) {
+ tst_resm(TBROK, "Could not produce self_exec string");
+ return -1;
+ }
+
+ va_start(ap, fmt);
+
+ for (p = fmt; *p; p++) {
+ switch (*p) {
+ case 'd':
+ case 'n':
+ ival = va_arg(ap, int);
+ if (asprintf(&arg, "%s,%d", arg, ival) < 0) {
+ tst_resm(TBROK,
+ "Could not produce self_exec string");
+ return -1;
+ }
+ break;
+ case 's':
+ case 'S':
+ str = va_arg(ap, char *);
+ if (asprintf(&arg, "%s,%s", arg, str) < 0) {
+ tst_resm(TBROK,
+ "Could not produce self_exec string");
+ return -1;
+ }
+ break;
+ default:
+ tst_resm(TBROK,
+ "Format string option %c not implemented", *p);
+ return -1;
+ break;
+ }
+ }
+
+ va_end(ap);
+
+ if (chdir(start_cwd) < 0) {
+ tst_resm(TBROK, "Could not change to %s for self_exec",
+ start_cwd);
+ return -1;
+ }
+
+ return execlp(argv0, argv0, "-C", arg, (char *)NULL);
+}
+
+#endif /* UCLINUX */
diff --git a/kernel/tests/lib/signame.h b/kernel/tests/lib/signame.h
new file mode 100644
index 0000000..d420458
--- /dev/null
+++ b/kernel/tests/lib/signame.h
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2014 Fujitsu Ltd.
+ * Author: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+const char *tst_strsig(int sig)
+{
+ static const struct pair signal_pairs[] = {
+ PAIR(SIGHUP)
+ PAIR(SIGINT)
+ PAIR(SIGQUIT)
+ PAIR(SIGILL)
+ #ifdef SIGTRAP
+ PAIR(SIGTRAP)
+ #endif
+
+ #ifdef SIGIOT
+ /* SIGIOT same as SIGABRT */
+ STRPAIR(SIGABRT, "SIGIOT/SIGABRT")
+ #else
+ PAIR(SIGABRT)
+ #endif
+
+ #ifdef SIGEMT
+ PAIR(SIGEMT)
+ #endif
+ #ifdef SIGBUS
+ PAIR(SIGBUS)
+ #endif
+ PAIR(SIGFPE)
+ PAIR(SIGKILL)
+ PAIR(SIGUSR1)
+ PAIR(SIGSEGV)
+ PAIR(SIGUSR2)
+ PAIR(SIGPIPE)
+ PAIR(SIGALRM)
+ PAIR(SIGTERM)
+ #ifdef SIGSTKFLT
+ PAIR(SIGSTKFLT)
+ #endif
+ PAIR(SIGCHLD)
+ PAIR(SIGCONT)
+ PAIR(SIGSTOP)
+ PAIR(SIGTSTP)
+ PAIR(SIGTTIN)
+ PAIR(SIGTTOU)
+ #ifdef SIGURG
+ PAIR(SIGURG)
+ #endif
+ #ifdef SIGXCPU
+ PAIR(SIGXCPU)
+ #endif
+ #ifdef SIGXFSZ
+ PAIR(SIGXFSZ)
+ #endif
+ #ifdef SIGVTALRM
+ PAIR(SIGVTALRM)
+ #endif
+ #ifdef SIGPROF
+ PAIR(SIGPROF)
+ #endif
+ #ifdef SIGWINCH
+ PAIR(SIGWINCH)
+ #endif
+
+ #if defined(SIGIO) && defined(SIGPOLL)
+ /* SIGPOLL same as SIGIO */
+ STRPAIR(SIGIO, "SIGIO/SIGPOLL")
+ #elif defined(SIGIO)
+ PAIR(SIGIO)
+ #elif defined(SIGPOLL)
+ PAIR(SIGPOLL)
+ #endif
+
+ #ifdef SIGINFO
+ PAIR(SIGINFO)
+ #endif
+ #ifdef SIGLOST
+ PAIR(SIGLOST)
+ #endif
+ #ifdef SIGPWR
+ PAIR(SIGPWR)
+ #endif
+ #if defined(SIGSYS)
+ /*
+ * According to signal(7)'s manpage, SIGUNUSED is synonymous
+ * with SIGSYS on most architectures.
+ */
+ STRPAIR(SIGSYS, "SIGSYS/SIGUNUSED")
+ #endif
+ };
+
+ PAIR_LOOKUP(signal_pairs, sig);
+};
diff --git a/kernel/tests/lib/tlibio.c b/kernel/tests/lib/tlibio.c
new file mode 100644
index 0000000..cc110d1
--- /dev/null
+++ b/kernel/tests/lib/tlibio.c
@@ -0,0 +1,2161 @@
+/*
+ * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it is
+ * free of the rightful claim of any third person regarding infringement
+ * or the like. Any license provided herein, whether implied or
+ * otherwise, applies only to this software file. Patent licenses, if
+ * any, provided herein do not apply to combinations of this program with
+ * other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
+ * Mountain View, CA 94043, or:
+ *
+ * http://www.sgi.com
+ *
+ * For further information regarding this notice, see:
+ *
+ * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
+ */
+/*
+ *
+ * Lib i/o
+ *
+ * This file contains several functions to doing reads and writes.
+ * It was written so that a single function could be called in a test
+ * program and only a io type field value would have to change to
+ * do different types of io. There is even a couple of functions that
+ * will allow you to parse a string to determine the iotype.
+ *
+ * This file contains functions for writing/reading to/from open files
+ * Prototypes:
+ *
+ * Functions declared in this module - see individual function code for
+ * usage comments:
+ *
+ * int stride_bounds(int offset, int stride, int nstrides,
+ * int bytes_per_stride, int *min, int *max);
+
+ * int lio_write_buffer(int fd, int method, char *buffer, int size,
+ * char **errmsg, long wrd);
+ * int lio_read_buffer(int fd, int method, char *buffer, int size,
+ * char **errmsg, long wrd);
+ *
+ * #ifdef CRAY
+ * int lio_wait4asyncio(int method, int fd, struct iosw **statptr)
+ * int lio_check_asyncio(char *io_type, int size, struct iosw *status)
+ * #endif
+ * #ifdef sgi
+ * int lio_wait4asyncio(int method, int fd, aiocb_t *aiocbp)
+ * int lio_check_asyncio(char *io_type, int size, aiocb_t *aiocbp, int method)
+ * #endif
+ *
+ * int lio_parse_io_arg1(char *string)
+ * void lio_help1(char *prefix);
+ *
+ * int lio_parse_io_arg2(char *string, char **badtoken)
+ * void lio_help2(char *prefix);
+ *
+ * int lio_set_debug(int level);
+ *
+ * char Lio_SysCall[];
+ * struct lio_info_type Lio_info1[];
+ * struct lio_info_type Lio_info2[];
+ *
+ * Author : Richard Logan
+ *
+ */
+
+#ifdef __linux__
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+#define _LARGEFILE64_SOURCE
+#endif
+#include "config.h"
+#include <stdio.h>
+#include <ctype.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/param.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/file.h>
+#include <signal.h>
+#include <stdint.h>
+#ifdef CRAY
+#include <sys/secparm.h>
+#include <sys/iosw.h>
+#include <sys/listio.h>
+#else
+/* for linux or sgi */
+#include <sys/uio.h> /* readv(2)/writev(2) */
+#include <string.h>
+#endif
+#if defined(__linux__) || defined(__sun) || defined(__hpux) || defined(_AIX)
+#if !defined(UCLINUX) && !defined(__UCLIBC__)
+#include <aio.h>
+#endif
+#endif
+#include <stdlib.h> /* atoi, abs */
+
+#include "tlibio.h" /* defines LIO* marcos */
+#include "random_range.h"
+
+#ifndef PATH_MAX
+#define PATH_MAX MAXPATHLEN
+#endif
+
+#if 0 /* disabled until it's needed -- roehrich 6/11/97 */
+#define BUG1_workaround 1 /* Work around a condition where aio_return gives
+ * a value of zero but there is no errno followup
+ * and the read/write operation actually did its
+ * job. spr/pv 705244
+ */
+#endif
+
+
+/*
+ * Define the structure as used in lio_parse_arg1 and lio_help1
+ */
+struct lio_info_type Lio_info1[] = {
+ {"s", LIO_IO_SYNC, "sync i/o"},
+ {"p", LIO_IO_ASYNC | LIO_WAIT_SIGACTIVE,
+ "async i/o using a loop to wait for a signal"},
+ {"b", LIO_IO_ASYNC | LIO_WAIT_SIGPAUSE, "async i/o using pause"},
+ {"a", LIO_IO_ASYNC | LIO_WAIT_RECALL,
+ "async i/o using recall/aio_suspend"},
+#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
+ {"r",
+ LIO_RANDOM | LIO_IO_TYPES | LIO_WAIT_TYPES,
+ "random sync i/o types and wait methods"},
+ {"R",
+ LIO_RANDOM | LIO_IO_ATYPES | LIO_WAIT_ATYPES,
+ "random i/o types and wait methods"},
+#else
+ {"r",
+ LIO_RANDOM | LIO_IO_TYPES | LIO_WAIT_TYPES,
+ "random i/o types and wait methods"},
+ {"R",
+ LIO_RANDOM | LIO_IO_TYPES | LIO_WAIT_TYPES,
+ "random i/o types and wait methods"},
+#endif
+ {"l", LIO_IO_SLISTIO | LIO_WAIT_RECALL, "single stride sync listio"},
+ {"L", LIO_IO_ALISTIO | LIO_WAIT_RECALL,
+ "single stride async listio using recall"},
+ {"X", LIO_IO_ALISTIO | LIO_WAIT_SIGPAUSE,
+ "single stride async listio using pause"},
+ {"v", LIO_IO_SYNCV, "single buffer sync readv/writev"},
+ {"P", LIO_IO_SYNCP, "sync pread/pwrite"},
+};
+
+/*
+ * Define the structure used by lio_parse_arg2 and lio_help2
+ */
+struct lio_info_type Lio_info2[] = {
+ {"sync", LIO_IO_SYNC, "sync i/o (read/write)"},
+ {"async", LIO_IO_ASYNC, "async i/o (reada/writea/aio_read/aio_write)"},
+ {"slistio", LIO_IO_SLISTIO, "single stride sync listio"},
+ {"alistio", LIO_IO_ALISTIO, "single stride async listio"},
+ {"syncv", LIO_IO_SYNCV, "single buffer sync readv/writev"},
+ {"syncp", LIO_IO_SYNCP, "pread/pwrite"},
+ {"active", LIO_WAIT_ACTIVE, "spin on status/control values"},
+ {"recall", LIO_WAIT_RECALL,
+ "use recall(2)/aio_suspend(3) to wait for i/o to complete"},
+ {"sigactive", LIO_WAIT_SIGACTIVE, "spin waiting for signal"},
+ {"sigpause", LIO_WAIT_SIGPAUSE, "call pause(2) to wait for signal"},
+/* nowait is a touchy thing, it's an accident that this implementation worked at all. 6/27/97 roehrich */
+/* { "nowait", LIO_WAIT_NONE, "do not wait for async io to complete" },*/
+ {"random", LIO_RANDOM, "set random bit"},
+ {"randomall",
+ LIO_RANDOM | LIO_IO_TYPES | LIO_WAIT_TYPES,
+ "all random i/o types and wait methods (except nowait)"},
+};
+
+char Lio_SysCall[PATH_MAX]; /* string containing last i/o system call */
+
+static volatile int Received_signal = 0; /* number of signals received */
+static volatile int Rec_signal;
+#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
+static volatile int Received_callback = 0; /* number of callbacks received */
+static volatile int Rec_callback;
+#endif
+static char Errormsg[500];
+static int Debug_level = 0;
+
+/***********************************************************************
+ * stride_bounds()
+ *
+ * Determine the bounds of a strided request, normalized to offset. Returns
+ * the number of bytes needed to satisfy the request, and optionally sets
+ * *min and *max to the mininum and maximum bytes referenced, normalized
+ * around offset.
+ *
+ * Returns -1 on error - the only possible error conditions are illegal values
+ * for nstrides and/or bytes_per_stride - both parameters must be >= 0.
+ *
+ * (maule, 11/16/95)
+ ***********************************************************************/
+
+int stride_bounds(int offset, int stride, int nstrides, int bytes_per_stride,
+ int *min, int *max)
+{
+ int nbytes, min_byte, max_byte;
+
+ /*
+ * sanity checks ...
+ */
+
+ if (nstrides < 0 || bytes_per_stride < 0) {
+ return -1;
+ }
+
+ if (stride == 0) {
+ stride = bytes_per_stride;
+ }
+
+ /*
+ * Determine the # of bytes needed to satisfy the request. This
+ * value, along with the offset argument, determines the min and max
+ * bytes referenced.
+ */
+
+ nbytes = abs(stride) * (nstrides - 1) + bytes_per_stride;
+
+ if (stride < 0) {
+ max_byte = offset + bytes_per_stride - 1;
+ min_byte = max_byte - nbytes + 1;
+ } else {
+ min_byte = offset;
+ max_byte = min_byte + nbytes - 1;
+ }
+
+ if (min != NULL) {
+ *min = min_byte;
+ }
+
+ if (max != NULL) {
+ *max = max_byte;
+ }
+
+ return nbytes;
+}
+
+/***********************************************************************
+ * This function will allow someone to set the debug level.
+ ***********************************************************************/
+int lio_set_debug(int level)
+{
+ int old;
+
+ old = Debug_level;
+ Debug_level = level;
+ return old;
+}
+
+/***********************************************************************
+ * This function will parse a string and return desired io-method.
+ * Only the first character of the string is used.
+ *
+ * This function does not provide for meaningful option arguments,
+ * but it supports current growfiles/btlk interface.
+ *
+ * (rrl 04/96)
+ ***********************************************************************/
+int lio_parse_io_arg1(char *string)
+{
+ unsigned int ind;
+ int found = 0;
+ int mask = 0;
+
+ /*
+ * Determine if token is a valid string.
+ */
+ for (ind = 0; ind < sizeof(Lio_info1) / sizeof(struct lio_info_type);
+ ind++) {
+ if (strcmp(string, Lio_info1[ind].token) == 0) {
+ mask |= Lio_info1[ind].bits;
+ found = 1;
+ break;
+ }
+ }
+
+ if (found == 0) {
+ return -1;
+ }
+
+ return mask;
+
+}
+
+/***********************************************************************
+ * This function will print a help message describing the characters
+ * that can be parsed by lio_parse_io_arg1().
+ * They will be printed one per line.
+ * (rrl 04/96)
+ ***********************************************************************/
+void lio_help1(char *prefix)
+{
+ unsigned int ind;
+
+ for (ind = 0; ind < sizeof(Lio_info1) / sizeof(struct lio_info_type);
+ ind++) {
+ printf("%s %s : %s\n", prefix, Lio_info1[ind].token,
+ Lio_info1[ind].desc);
+ }
+
+ return;
+}
+
+/***********************************************************************
+ * This function will parse a string and return the desired io-method.
+ * This function will take a comma separated list of io type and wait
+ * method tokens as defined in Lio_info2[]. If a token does not match
+ * any of the tokens in Lio_info2[], it will be coverted to a number.
+ * If it was a number, those bits are also set.
+ *
+ * (rrl 04/96)
+ ***********************************************************************/
+int lio_parse_io_arg2(char *string, char **badtoken)
+{
+ char *token = string;
+ char *cc = token;
+ char savecc;
+ int found;
+ int mask = 0;
+
+ int tmp;
+ unsigned int ind;
+ char chr;
+
+ if (token == NULL)
+ return -1;
+
+ for (;;) {
+ for (; ((*cc != ',') && (*cc != '\0')); cc++) ;
+ savecc = *cc;
+ *cc = '\0';
+
+ found = 0;
+
+ /*
+ * Determine if token is a valid string or number and if
+ * so, add the bits to the mask.
+ */
+ for (ind = 0;
+ ind < sizeof(Lio_info2) / sizeof(struct lio_info_type);
+ ind++) {
+ if (strcmp(token, Lio_info2[ind].token) == 0) {
+ mask |= Lio_info2[ind].bits;
+ found = 1;
+ break;
+ }
+ }
+
+ /*
+ * If token does not match one of the defined tokens, determine
+ * if it is a number, if so, add the bits.
+ */
+ if (!found) {
+ if (sscanf(token, "%i%c", &tmp, &chr) == 1) {
+ mask |= tmp;
+ found = 1;
+ }
+ }
+
+ *cc = savecc;
+
+ if (!found) { /* token is not valid */
+ if (badtoken != NULL)
+ *badtoken = token;
+ return (-1);
+ }
+
+ if (savecc == '\0')
+ break;
+
+ token = ++cc;
+ }
+
+ return mask;
+}
+
+/***********************************************************************
+ * This function will print a help message describing the tokens
+ * that can be parsed by lio_parse_io_arg2().
+ * It will print them one per line.
+ *
+ * (rrl 04/96)
+ ***********************************************************************/
+void lio_help2(char *prefix)
+{
+ unsigned int ind;
+
+ for (ind = 0; ind < sizeof(Lio_info2) / sizeof(struct lio_info_type);
+ ind++) {
+ printf("%s %s : %s\n", prefix, Lio_info2[ind].token,
+ Lio_info2[ind].desc);
+ }
+ return;
+}
+
+/***********************************************************************
+ * This is an internal signal handler.
+ * If the handler is called, it will increment the Received_signal
+ * global variable.
+ ***********************************************************************/
+static void lio_async_signal_handler(int sig)
+{
+ if (Debug_level)
+ printf
+ ("DEBUG %s/%d: received signal %d, a signal caught %d times\n",
+ __FILE__, __LINE__, sig, Received_signal + 1);
+
+ Received_signal++;
+
+ return;
+}
+
+#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
+/***********************************************************************
+ * This is an internal callback handler.
+ * If the handler is called, it will increment the Received_callback
+ * global variable.
+ ***********************************************************************/
+static void lio_async_callback_handler(union sigval sigval)
+{
+ if (Debug_level)
+ printf
+ ("DEBUG %s/%d: received callback, nbytes=%ld, a callback called %d times\n",
+ __FILE__, __LINE__, (long)sigval.sival_int,
+ Received_callback + 1);
+
+ Received_callback++;
+
+ return;
+}
+#endif /* sgi */
+
+/***********************************************************************
+ * lio_random_methods
+ * This function will randomly choose an io type and wait method
+ * from set of io types and wait methods. Since this information
+ * is stored in a bitmask, it randomly chooses an io type from
+ * the io type bits specified and does the same for wait methods.
+ *
+ * Return Value
+ * This function will return a value with all non choosen io type
+ * and wait method bits cleared. The LIO_RANDOM bit is also
+ * cleared. All other bits are left unchanged.
+ *
+ * (rrl 04/96)
+ ***********************************************************************/
+int lio_random_methods(long curr_mask)
+{
+ int mask = 0;
+
+ /* remove random select, io type, and wait method bits from curr_mask */
+ mask = curr_mask & (~(LIO_IO_TYPES | LIO_WAIT_TYPES | LIO_RANDOM));
+
+ /* randomly select io type from specified io types */
+ mask = mask | random_bit(curr_mask & LIO_IO_TYPES);
+
+ /* randomly select wait methods from specified wait methods */
+ mask = mask | random_bit(curr_mask & LIO_WAIT_TYPES);
+
+ return mask;
+}
+
+static void wait4sync_io(int fd, int read)
+{
+ fd_set s;
+ FD_ZERO(&s);
+ FD_SET(fd, &s);
+
+ select(fd + 1, read ? &s : NULL, read ? NULL : &s, NULL, NULL);
+}
+
+/***********************************************************************
+ * Generic write function
+ * This function can be used to do a write using write(2), writea(2),
+ * aio_write(3), writev(2), pwrite(2),
+ * or single stride listio(2)/lio_listio(3).
+ * By setting the desired bits in the method
+ * bitmask, the caller can control the type of write and the wait method
+ * that will be used. If no io type bits are set, write will be used.
+ *
+ * If async io was attempted and no wait method bits are set then the
+ * wait method is: recall(2) for writea(2) and listio(2); aio_suspend(3) for
+ * aio_write(3) and lio_listio(3).
+ *
+ * If multiple wait methods are specified,
+ * only one wait method will be used. The order is predetermined.
+ *
+ * If the call specifies a signal and one of the two signal wait methods,
+ * a signal handler for the signal is set. This will reset an already
+ * set handler for this signal.
+ *
+ * If the LIO_RANDOM method bit is set, this function will randomly
+ * choose a io type and wait method from bits in the method argument.
+ *
+ * If an error is encountered, an error message will be generated
+ * in a internal static buffer. If errmsg is not NULL, it will
+ * be updated to point to the static buffer, allowing the caller
+ * to print the error message.
+ *
+ * Return Value
+ * If a system call fails, -errno is returned.
+ * If LIO_WAIT_NONE bit is set, the return value is the return value
+ * of the system call.
+ * If the io did not fail, the amount of data written is returned.
+ * If the size the system call say was written is different
+ * then what was asked to be written, errmsg is updated for
+ * this error condition. The return value is still the amount
+ * the system call says was written.
+ *
+ * (rrl 04/96)
+ ***********************************************************************/
+int lio_write_buffer(int fd, /* open file descriptor */
+ int method, /* contains io type and wait method bitmask */
+ char *buffer, /* pointer to buffer */
+ int size, /* the size of the io */
+ int sig, /* signal to use if async io */
+ char **errmsg, /* char pointer that will be updated to point to err message */
+ long wrd) /* to allow future features, use zero for now */
+{
+ int ret = 0; /* syscall return or used to get random method */
+ char *io_type; /* Holds string of type of io */
+ int omethod = method;
+ int listio_cmd; /* Holds the listio/lio_listio cmd */
+#ifdef CRAY
+ struct listreq request; /* Used when a listio is wanted */
+ struct iosw status, *statptr[1];
+#else
+ /* for linux or sgi */
+ struct iovec iov; /* iovec for writev(2) */
+#endif
+#if defined (sgi)
+ aiocb_t aiocbp; /* POSIX aio control block */
+ aiocb_t *aiolist[1]; /* list of aio control blocks for lio_listio */
+ off64_t poffset; /* pwrite(2) offset */
+#endif
+#if defined(__linux__) && !defined(__UCLIBC__)
+ struct aiocb aiocbp; /* POSIX aio control block */
+ struct aiocb *aiolist[1]; /* list of aio control blocks for lio_listio */
+ off64_t poffset; /* pwrite(2) offset */
+#endif
+ /*
+ * If LIO_RANDOM bit specified, get new method randomly.
+ */
+ if (method & LIO_RANDOM) {
+ if (Debug_level > 3)
+ printf("DEBUG %s/%d: method mask to choose from: %#o\n",
+ __FILE__, __LINE__, method);
+ method = lio_random_methods(method);
+ if (Debug_level > 2)
+ printf("DEBUG %s/%d: random chosen method %#o\n",
+ __FILE__, __LINE__, method);
+ }
+
+ if (errmsg != NULL)
+ *errmsg = Errormsg;
+
+ Rec_signal = Received_signal; /* get the current number of signals received */
+#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
+ Rec_callback = Received_callback; /* get the current number of callbacks received */
+#endif
+
+#ifdef CRAY
+ memset(&status, 0x00, sizeof(struct iosw));
+ memset(&request, 0x00, sizeof(struct listreq));
+ statptr[0] = &status;
+#else
+ /* for linux or sgi */
+ memset(&iov, 0x00, sizeof(struct iovec));
+ iov.iov_base = buffer;
+ iov.iov_len = size;
+#endif
+#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
+#if defined(sgi)
+ memset(&aiocbp, 0x00, sizeof(aiocb_t));
+#else
+ memset(&aiocbp, 0x00, sizeof(struct aiocb));
+#endif
+ aiocbp.aio_fildes = fd;
+ aiocbp.aio_nbytes = size;
+ aiocbp.aio_buf = buffer;
+/* aiocbp.aio_offset = lseek( fd, 0, SEEK_CUR ); -- set below */
+ aiocbp.aio_sigevent.sigev_notify = SIGEV_NONE;
+ aiocbp.aio_sigevent.sigev_signo = 0;
+#ifdef sgi
+ aiocbp.aio_sigevent.sigev_func = NULL;
+ aiocbp.aio_sigevent.sigev_value.sival_int = 0;
+#elif defined(__linux__) && !defined(__UCLIBC__)
+ aiocbp.aio_sigevent.sigev_notify_function = NULL;
+ aiocbp.aio_sigevent.sigev_notify_attributes = 0;
+#endif
+ aiolist[0] = &aiocbp;
+
+ if ((ret = lseek(fd, 0, SEEK_CUR)) == -1) {
+ ret = 0;
+ /* If there is an error and it is not ESPIPE then kick out the error.
+ * If the fd is a fifo then we have to make sure that
+ * lio_random_methods() didn't select pwrite/pread; if it did then
+ * switch to write/read.
+ */
+ if (errno == ESPIPE) {
+ if (method & LIO_IO_SYNCP) {
+ if (omethod & LIO_RANDOM) {
+ method &= ~LIO_IO_SYNCP;
+ method |= LIO_IO_SYNC;
+ if (Debug_level > 2)
+ printf
+ ("DEBUG %s/%d: random chosen method switched to %#o for fifo\n",
+ __FILE__, __LINE__,
+ method);
+ } else if (Debug_level) {
+ printf
+ ("DEBUG %s/%d: pwrite will fail when it writes to a fifo\n",
+ __FILE__, __LINE__);
+ }
+ }
+ /* else: let it ride */
+ } else {
+ sprintf(Errormsg,
+ "%s/%d lseek(fd=%d,0,SEEK_CUR) failed, errno=%d %s",
+ __FILE__, __LINE__, fd, errno, strerror(errno));
+ return -errno;
+ }
+ }
+#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
+ poffset = (off64_t) ret;
+#endif
+ aiocbp.aio_offset = ret;
+
+#endif
+
+ /*
+ * If the LIO_USE_SIGNAL bit is not set, only use the signal
+ * if the LIO_WAIT_SIGPAUSE or the LIO_WAIT_SIGACTIVE bits are bit.
+ * Otherwise there is not necessary a signal handler to trap
+ * the signal.
+ */
+ if (sig && !(method & LIO_USE_SIGNAL) && !(method & LIO_WAIT_SIGTYPES)) {
+
+ sig = 0; /* ignore signal parameter */
+ }
+#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
+ if (sig && (method & LIO_WAIT_CBTYPES))
+ sig = 0; /* ignore signal parameter */
+#endif
+
+ /*
+ * only setup signal hander if sig was specified and
+ * a sig wait method was specified.
+ * Doing this will change the handler for this signal. The
+ * old signal handler will not be restored.
+ *** restoring the signal handler could be added ***
+ */
+
+ if (sig && (method & LIO_WAIT_SIGTYPES)) {
+#ifdef CRAY
+ sigctl(SCTL_REG, sig, lio_async_signal_handler);
+#endif
+#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
+ aiocbp.aio_sigevent.sigev_notify = SIGEV_SIGNAL;
+ aiocbp.aio_sigevent.sigev_signo = sig;
+ sigset(sig, lio_async_signal_handler);
+#endif /* sgi */
+ }
+#if defined(sgi)
+ else if (method & LIO_WAIT_CBTYPES) {
+ /* sival_int just has to be something that I can use
+ * to identify the callback, and "size" happens to be handy...
+ */
+ aiocbp.aio_sigevent.sigev_notify = SIGEV_CALLBACK;
+ aiocbp.aio_sigevent.sigev_func = lio_async_callback_handler;
+ aiocbp.aio_sigevent.sigev_value.sival_int = size;
+ }
+#endif
+#if defined(__linux__) && !defined(__UCLIBC__)
+ else if (method & LIO_WAIT_CBTYPES) {
+ /* sival_int just has to be something that I can use
+ * to identify the callback, and "size" happens to be handy...
+ */
+ aiocbp.aio_sigevent.sigev_notify = SIGEV_THREAD;
+ aiocbp.aio_sigevent.sigev_notify_function =
+ lio_async_callback_handler;
+ aiocbp.aio_sigevent.sigev_notify_attributes =
+ (void *)(uintptr_t) size;
+ }
+#endif
+ /*
+ * Determine the system call that will be called and produce
+ * the string of the system call and place it in Lio_SysCall.
+ * Also update the io_type char pointer to give brief description
+ * of system call. Execute the system call and check for
+ * system call failure. If sync i/o, return the number of
+ * bytes written/read.
+ */
+
+ if ((method & LIO_IO_SYNC)
+ || (method & (LIO_IO_TYPES | LIO_IO_ATYPES)) == 0) {
+ /*
+ * write(2) is used if LIO_IO_SYNC bit is set or not none
+ * of the LIO_IO_TYPES bits are set (default).
+ */
+
+ sprintf(Lio_SysCall, "write(%d, buf, %d)", fd, size);
+ io_type = "write";
+
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
+ while (1) {
+ if (((ret = write(fd, buffer, size)) == -1)
+ && errno != EAGAIN && errno != EINTR) {
+ sprintf(Errormsg,
+ "%s/%d write(%d, buf, %d) ret:-1, errno=%d %s",
+ __FILE__, __LINE__, fd, size, errno,
+ strerror(errno));
+ return -errno;
+ }
+
+ if (ret != -1) {
+ if (ret != size) {
+ sprintf(Errormsg,
+ "%s/%d write(%d, buf, %d) returned=%d",
+ __FILE__, __LINE__,
+ fd, size, ret);
+ size -= ret;
+ buffer += ret;
+ } else {
+ if (Debug_level > 1)
+ printf
+ ("DEBUG %s/%d: write completed without error (ret %d)\n",
+ __FILE__, __LINE__, ret);
+
+ return ret;
+ }
+ }
+ wait4sync_io(fd, 0);
+ }
+
+ }
+
+ else if (method & LIO_IO_ASYNC) {
+#ifdef CRAY
+ sprintf(Lio_SysCall,
+ "writea(%d, buf, %d, &status, %d)", fd, size, sig);
+ io_type = "writea";
+
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
+
+ sigoff();
+ if ((ret = writea(fd, buffer, size, &status, sig)) == -1) {
+ sprintf(Errormsg,
+ "%s/%d writea(%d, buf, %d, &stat, %d) ret:-1, errno=%d %s",
+ __FILE__, __LINE__,
+ fd, size, sig, errno, strerror(errno));
+ sigon();
+ return -errno;
+ }
+#endif
+#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
+ sprintf(Lio_SysCall,
+ "aio_write(fildes=%d, buf, nbytes=%d, signo=%d)", fd,
+ size, sig);
+ io_type = "aio_write";
+
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
+
+ if (sig)
+ sighold(sig);
+ if ((ret = aio_write(&aiocbp)) == -1) {
+ sprintf(Errormsg,
+ "%s/%d aio_write(fildes=%d, buf, nbytes=%d, signo=%d) ret:-1, errno=%d %s",
+ __FILE__, __LINE__,
+ fd, size, sig, errno, strerror(errno));
+ if (sig)
+ sigrelse(sig);
+ return -errno;
+ }
+#endif
+ }
+ /* LIO_IO_ASYNC */
+ else if (method & LIO_IO_SLISTIO) {
+#ifdef CRAY
+ request.li_opcode = LO_WRITE;
+ request.li_fildes = fd;
+ request.li_buf = buffer;
+ request.li_nbyte = size;
+ request.li_status = &status;
+ request.li_signo = sig;
+ request.li_nstride = 0;
+ request.li_filstride = 0;
+ request.li_memstride = 0;
+
+ listio_cmd = LC_WAIT;
+ io_type = "listio(2) sync write";
+
+ sprintf(Lio_SysCall,
+ "listio(LC_WAIT, &req, 1) LO_WRITE, fd:%d, nbyte:%d",
+ fd, size);
+
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
+
+ sigoff();
+ if (listio(listio_cmd, &request, 1) == -1) {
+ sprintf(Errormsg,
+ "%s/%d %s failed, fd:%d, nbyte:%d errno=%d %s",
+ __FILE__, __LINE__, Lio_SysCall, fd, size,
+ errno, strerror(errno));
+ sigon();
+ return -errno;
+ }
+
+ if (Debug_level > 1)
+ printf("DEBUG %s/%d: %s did not return -1\n",
+ __FILE__, __LINE__, Lio_SysCall);
+
+ ret = lio_check_asyncio(io_type, size, &status);
+ return ret;
+
+#endif
+#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
+
+ aiocbp.aio_lio_opcode = LIO_WRITE;
+ listio_cmd = LIO_WAIT;
+ io_type = "lio_listio(3) sync write";
+
+ sprintf(Lio_SysCall,
+ "lio_listio(LIO_WAIT, aiolist, 1, NULL) LIO_WRITE, fd:%d, nbyte:%d, sig:%d",
+ fd, size, sig);
+
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
+
+ if (sig)
+ sighold(sig);
+ if (lio_listio(listio_cmd, aiolist, 1, NULL) == -1) {
+ sprintf(Errormsg,
+ "%s/%d %s failed, fd:%d, nbyte:%d errno=%d %s",
+ __FILE__, __LINE__, Lio_SysCall, fd, size,
+ errno, strerror(errno));
+ if (sig)
+ sigrelse(sig);
+ return -errno;
+ }
+
+ if (Debug_level > 1)
+ printf("DEBUG %s/%d: %s did not return -1\n",
+ __FILE__, __LINE__, Lio_SysCall);
+
+ ret = lio_check_asyncio(io_type, size, &aiocbp, method);
+ return ret;
+#endif
+ }
+ /* LIO_IO_SLISTIO */
+ else if (method & LIO_IO_ALISTIO) {
+#ifdef CRAY
+ request.li_opcode = LO_WRITE;
+ request.li_fildes = fd;
+ request.li_buf = buffer;
+ request.li_nbyte = size;
+ request.li_status = &status;
+ request.li_signo = sig;
+ request.li_nstride = 0;
+ request.li_filstride = 0;
+ request.li_memstride = 0;
+
+ listio_cmd = LC_START;
+ io_type = "listio(2) async write";
+
+ sprintf(Lio_SysCall,
+ "listio(LC_START, &req, 1) LO_WRITE, fd:%d, nbyte:%d",
+ fd, size);
+
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
+
+ sigoff();
+ if (listio(listio_cmd, &request, 1) == -1) {
+ sprintf(Errormsg,
+ "%s/%d %s failed, fd:%d, nbyte:%d errno=%d %s",
+ __FILE__, __LINE__, Lio_SysCall, fd, size,
+ errno, strerror(errno));
+ sigon();
+ return -errno;
+ }
+#endif
+#if defined (sgi) || (defined(__linux__) && !defined(__UCLIBC__))
+ aiocbp.aio_lio_opcode = LIO_WRITE;
+ listio_cmd = LIO_NOWAIT;
+ io_type = "lio_listio(3) async write";
+
+ sprintf(Lio_SysCall,
+ "lio_listio(LIO_NOWAIT, aiolist, 1, NULL) LIO_WRITE, fd:%d, nbyte:%d",
+ fd, size);
+
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
+
+ if (sig)
+ sighold(sig);
+ if (lio_listio(listio_cmd, aiolist, 1, NULL) == -1) {
+ sprintf(Errormsg,
+ "%s/%d %s failed, fd:%d, nbyte:%d errno=%d %s",
+ __FILE__, __LINE__, Lio_SysCall, fd, size,
+ errno, strerror(errno));
+ if (sig)
+ sigrelse(sig);
+ return -errno;
+ }
+#endif
+ }
+ /* LIO_IO_ALISTIO */
+#ifndef CRAY
+ else if (method & LIO_IO_SYNCV) {
+ io_type = "writev(2)";
+
+ sprintf(Lio_SysCall, "writev(%d, &iov, 1) nbyte:%d", fd, size);
+
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
+ if ((ret = writev(fd, &iov, 1)) == -1) {
+ sprintf(Errormsg,
+ "%s/%d writev(%d, iov, 1) nbyte:%d ret:-1, errno=%d %s",
+ __FILE__, __LINE__, fd, size, errno,
+ strerror(errno));
+ return -errno;
+ }
+
+ if (ret != size) {
+ sprintf(Errormsg,
+ "%s/%d writev(%d, iov, 1) nbyte:%d returned=%d",
+ __FILE__, __LINE__, fd, size, ret);
+ } else if (Debug_level > 1)
+ printf
+ ("DEBUG %s/%d: writev completed without error (ret %d)\n",
+ __FILE__, __LINE__, ret);
+
+ return ret;
+ } /* LIO_IO_SYNCV */
+#endif
+
+#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
+ else if (method & LIO_IO_SYNCP) {
+ io_type = "pwrite(2)";
+
+ sprintf(Lio_SysCall,
+ "pwrite(%d, buf, %d, %lld)", fd, size,
+ (long long)poffset);
+
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
+ if ((ret = pwrite(fd, buffer, size, poffset)) == -1) {
+ sprintf(Errormsg,
+ "%s/%d pwrite(%d, buf, %d, %lld) ret:-1, errno=%d %s",
+ __FILE__, __LINE__, fd, size,
+ (long long)poffset, errno, strerror(errno));
+ return -errno;
+ }
+
+ if (ret != size) {
+ sprintf(Errormsg,
+ "%s/%d pwrite(%d, buf, %d, %lld) returned=%d",
+ __FILE__, __LINE__,
+ fd, size, (long long)poffset, ret);
+ } else if (Debug_level > 1)
+ printf
+ ("DEBUG %s/%d: pwrite completed without error (ret %d)\n",
+ __FILE__, __LINE__, ret);
+
+ return ret;
+ } /* LIO_IO_SYNCP */
+#endif
+
+ else {
+ printf("DEBUG %s/%d: No I/O method chosen\n", __FILE__,
+ __LINE__);
+ return -1;
+ }
+
+ /*
+ * wait for async io to complete.
+ */
+#ifdef CRAY
+ ret = lio_wait4asyncio(method, fd, statptr);
+#endif
+#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
+ ret = lio_wait4asyncio(method, fd, &aiocbp);
+#endif
+
+ /*
+ * If there was an error waiting for async i/o to complete,
+ * return the error value (errno) to the caller.
+ * Note: Errormsg should already have been updated.
+ */
+ if (ret < 0) {
+ return ret;
+ }
+
+ /*
+ * If i/o was not waited for (may not have been completed at this time),
+ * return the size that was requested.
+ */
+ if (ret == 1)
+ return size;
+
+ /*
+ * check that async io was successful.
+ * Note: if the there was an system call failure, -errno
+ * was returned and Errormsg should already have been updated.
+ * If amount i/o was different than size, Errormsg should already
+ * have been updated but the actual i/o size if returned.
+ */
+
+#ifdef CRAY
+ ret = lio_check_asyncio(io_type, size, &status);
+#endif
+#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
+ ret = lio_check_asyncio(io_type, size, &aiocbp, method);
+#endif
+
+ return ret;
+} /* end of lio_write_buffer */
+
+/***********************************************************************
+ * Generic read function
+ * This function can be used to do a read using read(2), reada(2),
+ * aio_read(3), readv(2), pread(2),
+ * or single stride listio(2)/lio_listio(3).
+ * By setting the desired bits in the method
+ * bitmask, the caller can control the type of read and the wait method
+ * that will be used. If no io type bits are set, read will be used.
+ *
+ * If async io was attempted and no wait method bits are set then the
+ * wait method is: recall(2) for reada(2) and listio(2); aio_suspend(3) for
+ * aio_read(3) and lio_listio(3).
+ *
+ * If multiple wait methods are specified,
+ * only one wait method will be used. The order is predetermined.
+ *
+ * If the call specifies a signal and one of the two signal wait methods,
+ * a signal handler for the signal is set. This will reset an already
+ * set handler for this signal.
+ *
+ * If the LIO_RANDOM method bit is set, this function will randomly
+ * choose a io type and wait method from bits in the method argument.
+ *
+ * If an error is encountered, an error message will be generated
+ * in a internal static buffer. If errmsg is not NULL, it will
+ * be updated to point to the static buffer, allowing the caller
+ * to print the error message.
+ *
+ * Return Value
+ * If a system call fails, -errno is returned.
+ * If LIO_WAIT_NONE bit is set, the return value is the return value
+ * of the system call.
+ * If the io did not fail, the amount of data written is returned.
+ * If the size the system call say was written is different
+ * then what was asked to be written, errmsg is updated for
+ * this error condition. The return value is still the amount
+ * the system call says was written.
+ *
+ * (rrl 04/96)
+ ***********************************************************************/
+int lio_read_buffer(int fd, /* open file descriptor */
+ int method, /* contains io type and wait method bitmask*/
+ char *buffer, /* pointer to buffer */
+ int size, /* the size of the io */
+ int sig, /* signal to use if async io */
+ char **errmsg, /* char pointer that will be updated to point to err message */
+ long wrd) /* to allow future features, use zero for now */
+{
+ int ret = 0; /* syscall return or used to get random method */
+ char *io_type; /* Holds string of type of io */
+ int listio_cmd; /* Holds the listio/lio_listio cmd */
+ int omethod = method;
+#ifdef CRAY
+ struct listreq request; /* Used when a listio is wanted */
+ struct iosw status, *statptr[1];
+#else
+ /* for linux or sgi */
+ struct iovec iov; /* iovec for readv(2) */
+#endif
+#ifdef sgi
+ aiocb_t aiocbp; /* POSIX aio control block */
+ aiocb_t *aiolist[1]; /* list of aio control blocks for lio_listio */
+ off64_t poffset; /* pread(2) offset */
+#endif
+#if defined (__linux__) && !defined(__UCLIBC__)
+ struct aiocb aiocbp; /* POSIX aio control block */
+ struct aiocb *aiolist[1]; /* list of aio control blocks for lio_listio */
+ off64_t poffset; /* pread(2) offset */
+#endif
+
+ /*
+ * If LIO_RANDOM bit specified, get new method randomly.
+ */
+ if (method & LIO_RANDOM) {
+ if (Debug_level > 3)
+ printf("DEBUG %s/%d: method mask to choose from: %#o\n",
+ __FILE__, __LINE__, method);
+ method = lio_random_methods(method);
+ if (Debug_level > 2)
+ printf("DEBUG %s/%d: random chosen method %#o\n",
+ __FILE__, __LINE__, method);
+ }
+
+ if (errmsg != NULL)
+ *errmsg = Errormsg;
+
+ Rec_signal = Received_signal; /* get the current number of signals received */
+#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
+ Rec_callback = Received_callback; /* get the current number of callbacks received */
+#endif
+
+#ifdef CRAY
+ memset(&status, 0x00, sizeof(struct iosw));
+ memset(&request, 0x00, sizeof(struct listreq));
+ statptr[0] = &status;
+#else
+ /* for linux or sgi */
+ memset(&iov, 0x00, sizeof(struct iovec));
+ iov.iov_base = buffer;
+ iov.iov_len = size;
+#endif
+#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
+#if defined(sgi)
+ memset(&aiocbp, 0x00, sizeof(aiocb_t));
+#else
+ memset(&aiocbp, 0x00, sizeof(struct aiocb));
+#endif
+ aiocbp.aio_fildes = fd;
+ aiocbp.aio_nbytes = size;
+ aiocbp.aio_buf = buffer;
+/* aiocbp.aio_offset = lseek( fd, 0, SEEK_CUR ); -- set below */
+ aiocbp.aio_sigevent.sigev_notify = SIGEV_NONE;
+ aiocbp.aio_sigevent.sigev_signo = 0;
+#ifdef sgi
+ aiocbp.aio_sigevent.sigev_func = NULL;
+ aiocbp.aio_sigevent.sigev_value.sival_int = 0;
+#elif defined(__linux__) && !defined(__UCLIBC__)
+ aiocbp.aio_sigevent.sigev_notify_function = NULL;
+ aiocbp.aio_sigevent.sigev_notify_attributes = 0;
+#endif
+ aiolist[0] = &aiocbp;
+
+ if ((ret = lseek(fd, 0, SEEK_CUR)) == -1) {
+ ret = 0;
+ /* If there is an error and it is not ESPIPE then kick out the error.
+ * If the fd is a fifo then we have to make sure that
+ * lio_random_methods() didn't select pwrite/pread; if it did then
+ * switch to write/read.
+ */
+ if (errno == ESPIPE) {
+ if (method & LIO_IO_SYNCP) {
+ if (omethod & LIO_RANDOM) {
+ method &= ~LIO_IO_SYNCP;
+ method |= LIO_IO_SYNC;
+ if (Debug_level > 2)
+ printf
+ ("DEBUG %s/%d: random chosen method switched to %#o for fifo\n",
+ __FILE__, __LINE__,
+ method);
+ } else if (Debug_level) {
+ printf
+ ("DEBUG %s/%d: pread will fail when it reads from a fifo\n",
+ __FILE__, __LINE__);
+ }
+ }
+ /* else: let it ride */
+ } else {
+ sprintf(Errormsg,
+ "%s/%d lseek(fd=%d,0,SEEK_CUR) failed, errno=%d %s",
+ __FILE__, __LINE__, fd, errno, strerror(errno));
+ return -errno;
+ }
+ }
+#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
+ poffset = (off64_t) ret;
+#endif
+ aiocbp.aio_offset = ret;
+
+#endif
+
+ /*
+ * If the LIO_USE_SIGNAL bit is not set, only use the signal
+ * if the LIO_WAIT_SIGPAUSE or the LIO_WAIT_SIGACTIVE bits are set.
+ * Otherwise there is not necessarily a signal handler to trap
+ * the signal.
+ */
+ if (sig && !(method & LIO_USE_SIGNAL) && !(method & LIO_WAIT_SIGTYPES)) {
+
+ sig = 0; /* ignore signal parameter */
+ }
+#if defined(sgi) || (defined(__linux__)&& !defined(__UCLIBC__))
+ if (sig && (method & LIO_WAIT_CBTYPES))
+ sig = 0; /* ignore signal parameter */
+#endif
+
+ /*
+ * only setup signal hander if sig was specified and
+ * a sig wait method was specified.
+ * Doing this will change the handler for this signal. The
+ * old signal handler will not be restored.
+ *** restoring the signal handler could be added ***
+ */
+
+ if (sig && (method & LIO_WAIT_SIGTYPES)) {
+#ifdef CRAY
+ sigctl(SCTL_REG, sig, lio_async_signal_handler);
+#endif
+#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
+ aiocbp.aio_sigevent.sigev_notify = SIGEV_SIGNAL;
+ aiocbp.aio_sigevent.sigev_signo = sig;
+ sigset(sig, lio_async_signal_handler);
+#endif /* CRAY */
+ }
+#if defined(sgi)
+ else if (method & LIO_WAIT_CBTYPES) {
+ aiocbp.aio_sigevent.sigev_notify = SIGEV_CALLBACK;
+ aiocbp.aio_sigevent.sigev_func = lio_async_callback_handler;
+ /* sival_int just has to be something that I can use
+ * to identify the callback, and "size" happens to be handy...
+ */
+ aiocbp.aio_sigevent.sigev_value.sival_int = size;
+ }
+#endif
+#if defined(__linux__) && !defined(__UCLIBC__)
+ else if (method & LIO_WAIT_CBTYPES) {
+ aiocbp.aio_sigevent.sigev_notify = SIGEV_THREAD;
+ aiocbp.aio_sigevent.sigev_notify_function =
+ lio_async_callback_handler;
+ /* sival_int just has to be something that I can use
+ * to identify the callback, and "size" happens to be handy...
+ */
+ aiocbp.aio_sigevent.sigev_notify_attributes =
+ (void *)(uintptr_t) size;
+ }
+#endif
+
+ /*
+ * Determine the system call that will be called and produce
+ * the string of the system call and place it in Lio_SysCall.
+ * Also update the io_type char pointer to give brief description
+ * of system call. Execute the system call and check for
+ * system call failure. If sync i/o, return the number of
+ * bytes written/read.
+ */
+
+ if ((method & LIO_IO_SYNC)
+ || (method & (LIO_IO_TYPES | LIO_IO_ATYPES)) == 0) {
+ /*
+ * read(2) is used if LIO_IO_SYNC bit is set or not none
+ * of the LIO_IO_TYPES bits are set (default).
+ */
+
+ sprintf(Lio_SysCall, "read(%d, buf, %d)", fd, size);
+ io_type = "read";
+
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
+
+ while (1) {
+ if (((ret = read(fd, buffer, size)) == -1)
+ && errno != EINTR && errno != EAGAIN) {
+ sprintf(Errormsg,
+ "%s/%d read(%d, buf, %d) ret:-1, errno=%d %s",
+ __FILE__, __LINE__, fd, size, errno,
+ strerror(errno));
+ return -errno;
+ }
+
+ if (ret == 0)
+ return 0;
+ if (ret != -1) {
+ if (ret != size) {
+ sprintf(Errormsg,
+ "%s/%d read(%d, buf, %d) returned=%d",
+ __FILE__, __LINE__,
+ fd, size, ret);
+ size -= ret;
+ buffer += ret;
+ } else {
+ if (Debug_level > 1)
+ printf
+ ("DEBUG %s/%d: read completed without error (ret %d)\n",
+ __FILE__, __LINE__, ret);
+
+ return ret;
+ }
+ }
+ wait4sync_io(fd, 1);
+ }
+
+ }
+
+ else if (method & LIO_IO_ASYNC) {
+#ifdef CRAY
+ sprintf(Lio_SysCall,
+ "reada(%d, buf, %d, &status, %d)", fd, size, sig);
+ io_type = "reada";
+
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
+
+ sigoff();
+ if ((ret = reada(fd, buffer, size, &status, sig)) == -1) {
+ sprintf(Errormsg,
+ "%s/%d reada(%d, buf, %d, &stat, %d) ret:-1, errno=%d %s",
+ __FILE__, __LINE__,
+ fd, size, sig, errno, strerror(errno));
+ sigon();
+ return -errno;
+ }
+#endif
+#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
+ sprintf(Lio_SysCall,
+ "aio_read(fildes=%d, buf, nbytes=%d, signo=%d)", fd,
+ size, sig);
+ io_type = "aio_read";
+
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
+
+ if (sig)
+ sighold(sig);
+ if ((ret = aio_read(&aiocbp)) == -1) {
+ sprintf(Errormsg,
+ "%s/%d aio_read(fildes=%d, buf, nbytes=%d, signo=%d) ret:-1, errno=%d %s",
+ __FILE__, __LINE__,
+ fd, size, sig, errno, strerror(errno));
+ if (sig)
+ sigrelse(sig);
+ return -errno;
+ }
+#endif
+ }
+ /* LIO_IO_ASYNC */
+ else if (method & LIO_IO_SLISTIO) {
+#ifdef CRAY
+ request.li_opcode = LO_READ;
+ request.li_fildes = fd;
+ request.li_buf = buffer;
+ request.li_nbyte = size;
+ request.li_status = &status;
+ request.li_signo = sig;
+ request.li_nstride = 0;
+ request.li_filstride = 0;
+ request.li_memstride = 0;
+
+ listio_cmd = LC_WAIT;
+ io_type = "listio(2) sync read";
+
+ sprintf(Lio_SysCall,
+ "listio(LC_WAIT, &req, 1) LO_READ, fd:%d, nbyte:%d",
+ fd, size);
+
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
+
+ sigoff();
+ if (listio(listio_cmd, &request, 1) == -1) {
+ sprintf(Errormsg,
+ "%s/%d %s failed, fd:%d, nbyte:%d errno=%d %s",
+ __FILE__, __LINE__, Lio_SysCall, fd, size,
+ errno, strerror(errno));
+ sigon();
+ return -errno;
+ }
+
+ if (Debug_level > 1)
+ printf("DEBUG %s/%d: %s did not return -1\n",
+ __FILE__, __LINE__, Lio_SysCall);
+
+ ret = lio_check_asyncio(io_type, size, &status);
+ return ret;
+#endif
+#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
+ aiocbp.aio_lio_opcode = LIO_READ;
+ listio_cmd = LIO_WAIT;
+ io_type = "lio_listio(3) sync read";
+
+ sprintf(Lio_SysCall,
+ "lio_listio(LIO_WAIT, aiolist, 1, NULL) LIO_READ, fd:%d, nbyte:%d",
+ fd, size);
+
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
+
+ if (sig)
+ sighold(sig);
+ if (lio_listio(listio_cmd, aiolist, 1, NULL) == -1) {
+ sprintf(Errormsg,
+ "%s/%d %s failed, fd:%d, nbyte:%d errno=%d %s",
+ __FILE__, __LINE__, Lio_SysCall, fd, size,
+ errno, strerror(errno));
+ if (sig)
+ sigrelse(sig);
+ return -errno;
+ }
+
+ if (Debug_level > 1)
+ printf("DEBUG %s/%d: %s did not return -1\n",
+ __FILE__, __LINE__, Lio_SysCall);
+
+ ret = lio_check_asyncio(io_type, size, &aiocbp, method);
+ return ret;
+#endif
+ }
+ /* LIO_IO_SLISTIO */
+ else if (method & LIO_IO_ALISTIO) {
+#ifdef CRAY
+ request.li_opcode = LO_READ;
+ request.li_fildes = fd;
+ request.li_buf = buffer;
+ request.li_nbyte = size;
+ request.li_status = &status;
+ request.li_signo = sig;
+ request.li_nstride = 0;
+ request.li_filstride = 0;
+ request.li_memstride = 0;
+
+ listio_cmd = LC_START;
+ io_type = "listio(2) async read";
+
+ sprintf(Lio_SysCall,
+ "listio(LC_START, &req, 1) LO_READ, fd:%d, nbyte:%d",
+ fd, size);
+
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
+
+ sigoff();
+ if (listio(listio_cmd, &request, 1) == -1) {
+ sprintf(Errormsg,
+ "%s/%d %s failed, fd:%d, nbyte:%d errno=%d %s",
+ __FILE__, __LINE__, Lio_SysCall, fd, size,
+ errno, strerror(errno));
+ sigon();
+ return -errno;
+ }
+#endif
+#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
+ aiocbp.aio_lio_opcode = LIO_READ;
+ listio_cmd = LIO_NOWAIT;
+ io_type = "lio_listio(3) async read";
+
+ sprintf(Lio_SysCall,
+ "lio_listio(LIO_NOWAIT, aiolist, 1, NULL) LIO_READ, fd:%d, nbyte:%d",
+ fd, size);
+
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
+
+ if (sig)
+ sighold(sig);
+ if (lio_listio(listio_cmd, aiolist, 1, NULL) == -1) {
+ sprintf(Errormsg,
+ "%s/%d %s failed, fd:%d, nbyte:%d errno=%d %s",
+ __FILE__, __LINE__, Lio_SysCall, fd, size,
+ errno, strerror(errno));
+ if (sig)
+ sigrelse(sig);
+ return -errno;
+ }
+#endif
+ }
+ /* LIO_IO_ALISTIO */
+#ifndef CRAY
+ else if (method & LIO_IO_SYNCV) {
+ io_type = "readv(2)";
+
+ sprintf(Lio_SysCall, "readv(%d, &iov, 1) nbyte:%d", fd, size);
+
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
+ if ((ret = readv(fd, &iov, 1)) == -1) {
+ sprintf(Errormsg,
+ "%s/%d readv(%d, iov, 1) nbyte:%d ret:-1, errno=%d %s",
+ __FILE__, __LINE__, fd, size, errno,
+ strerror(errno));
+ return -errno;
+ }
+
+ if (ret != size) {
+ sprintf(Errormsg,
+ "%s/%d readv(%d, iov, 1) nbyte:%d returned=%d",
+ __FILE__, __LINE__, fd, size, ret);
+ } else if (Debug_level > 1)
+ printf
+ ("DEBUG %s/%d: readv completed without error (ret %d)\n",
+ __FILE__, __LINE__, ret);
+
+ return ret;
+ } /* LIO_IO_SYNCV */
+#endif
+
+#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
+ else if (method & LIO_IO_SYNCP) {
+ io_type = "pread(2)";
+
+ sprintf(Lio_SysCall,
+ "pread(%d, buf, %d, %lld)", fd, size,
+ (long long)poffset);
+
+ if (Debug_level) {
+ printf("DEBUG %s/%d: %s\n", __FILE__, __LINE__,
+ Lio_SysCall);
+ }
+ if ((ret = pread(fd, buffer, size, poffset)) == -1) {
+ sprintf(Errormsg,
+ "%s/%d pread(%d, buf, %d, %lld) ret:-1, errno=%d %s",
+ __FILE__, __LINE__, fd, size,
+ (long long)poffset, errno, strerror(errno));
+ return -errno;
+ }
+
+ if (ret != size) {
+ sprintf(Errormsg,
+ "%s/%d pread(%d, buf, %d, %lld) returned=%d",
+ __FILE__, __LINE__,
+ fd, size, (long long)poffset, ret);
+ } else if (Debug_level > 1)
+ printf
+ ("DEBUG %s/%d: pread completed without error (ret %d)\n",
+ __FILE__, __LINE__, ret);
+
+ return ret;
+ } /* LIO_IO_SYNCP */
+#endif
+
+ else {
+ printf("DEBUG %s/%d: No I/O method chosen\n", __FILE__,
+ __LINE__);
+ return -1;
+ }
+
+ /*
+ * wait for async io to complete.
+ * Note: Sync io should have returned prior to getting here.
+ */
+#ifdef CRAY
+ ret = lio_wait4asyncio(method, fd, statptr);
+#endif
+#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
+ ret = lio_wait4asyncio(method, fd, &aiocbp);
+#endif
+
+ /*
+ * If there was an error waiting for async i/o to complete,
+ * return the error value (errno) to the caller.
+ * Note: Errormsg should already have been updated.
+ */
+ if (ret < 0) {
+ return ret;
+ }
+
+ /*
+ * If i/o was not waited for (may not have been completed at this time),
+ * return the size that was requested.
+ */
+ if (ret == 1)
+ return size;
+
+ /*
+ * check that async io was successful.
+ * Note: if the there was an system call failure, -errno
+ * was returned and Errormsg should already have been updated.
+ * If amount i/o was different than size, Errormsg should already
+ * have been updated but the actual i/o size if returned.
+ */
+
+#ifdef CRAY
+ ret = lio_check_asyncio(io_type, size, &status);
+#endif
+#if defined(sgi) || (defined(__linux__) && !defined(__UCLIBC__))
+ ret = lio_check_asyncio(io_type, size, &aiocbp, method);
+#endif
+
+ return ret;
+} /* end of lio_read_buffer */
+
+#if !defined(__sun) && !defined(__hpux) && !defined(_AIX)
+/***********************************************************************
+ * This function will check that async io was successful.
+ * It can also be used to check sync listio since it uses the
+ * same method.
+ *
+ * Return Values
+ * If status.sw_error is set, -status.sw_error is returned.
+ * Otherwise sw_count's field value is returned.
+ *
+ * (rrl 04/96)
+ ***********************************************************************/
+#ifdef CRAY
+int lio_check_asyncio(char *io_type, int size, struct iosw *status)
+#elif defined(sgi)
+int lio_check_asyncio(char *io_type, int size, aiocb_t * aiocbp, int method)
+#elif defined(__linux__) && !defined(__UCLIBC__)
+int lio_check_asyncio(char *io_type, int size, struct aiocb *aiocbp, int method)
+{
+ int ret;
+
+#ifdef CRAY
+ if (status->sw_error) {
+ sprintf(Errormsg,
+ "%s/%d %s, sw_error set = %d %s, sw_count = %d",
+ __FILE__, __LINE__, io_type,
+ status->sw_error, strerror(status->sw_error),
+ status->sw_count);
+ return -status->sw_error;
+ } else if (status->sw_count != size) {
+ sprintf(Errormsg,
+ "%s/%d %s, sw_count not as expected(%d), but actual:%d",
+ __FILE__, __LINE__, io_type, size, status->sw_count);
+ } else if (Debug_level > 1) {
+ printf
+ ("DEBUG %s/%d: %s completed without error (sw_error == 0, sw_count == %d)\n",
+ __FILE__, __LINE__, io_type, status->sw_count);
+ }
+
+ return status->sw_count;
+
+#else
+
+ int cnt = 1;
+
+ /* The I/O may have been synchronous with signal completion. It doesn't
+ * make sense, but the combination could be generated. Release the
+ * completion signal here otherwise it'll hang around and bite us
+ * later.
+ */
+ if (aiocbp->aio_sigevent.sigev_notify == SIGEV_SIGNAL)
+ sigrelse(aiocbp->aio_sigevent.sigev_signo);
+
+ ret = aio_error(aiocbp);
+
+ while (ret == EINPROGRESS) {
+ ret = aio_error(aiocbp);
+ ++cnt;
+ }
+ if (cnt > 1) {
+ sprintf(Errormsg,
+ "%s/%d %s, aio_error had to loop on EINPROGRESS, cnt=%d; random method %#o; sigev_notify=%s",
+ __FILE__, __LINE__, io_type, cnt, method,
+ (aiocbp->aio_sigevent.sigev_notify ==
+ SIGEV_SIGNAL ? "signal" : aiocbp->aio_sigevent.
+ sigev_notify == SIGEV_NONE ? "none" :
+#ifdef SIGEV_CALLBACK
+ aiocbp->aio_sigevent.sigev_notify ==
+ SIGEV_CALLBACK ? "callback" :
+#endif
+ aiocbp->aio_sigevent.sigev_notify ==
+ SIGEV_THREAD ? "thread" : "unknown"));
+ return -ret;
+ }
+
+ if (ret != 0) {
+ sprintf(Errormsg,
+ "%s/%d %s, aio_error = %d %s; random method %#o",
+ __FILE__, __LINE__, io_type,
+ ret, strerror(ret), method);
+ return -ret;
+ }
+ ret = aio_return(aiocbp);
+ if (ret != size) {
+ sprintf(Errormsg,
+ "%s/%d %s, aio_return not as expected(%d), but actual:%d",
+ __FILE__, __LINE__, io_type, size, ret);
+
+#ifdef BUG1_workaround
+ if (ret == 0) {
+ ret = size;
+ if (Debug_level > 1) {
+ printf
+ ("WARN %s/%d: %s completed with bug1_workaround (aio_error == 0, aio_return now == %d)\n",
+ __FILE__, __LINE__, io_type, ret);
+ }
+ }
+#endif /* BUG1_workaround */
+
+ } else if (Debug_level > 1) {
+ printf
+ ("DEBUG %s/%d: %s completed without error (aio_error == 0, aio_return == %d)\n",
+ __FILE__, __LINE__, io_type, ret);
+ }
+
+ return ret;
+
+#endif
+} /* end of lio_check_asyncio */
+#endif
+
+/***********************************************************************
+ *
+ * This function will wait for async io to complete.
+ * If multiple wait methods are specified, the order is predetermined
+ * to LIO_WAIT_RECALL,
+ * LIO_WAIT_ACTIVE, LIO_WAIT_SIGPAUSE, LIO_WAIT_SIGACTIVE,
+ * then LIO_WAIT_NONE.
+ *
+ * If no wait method was specified the default wait method is: recall(2)
+ * or aio_suspend(3), as appropriate.
+ *
+ * Return Values
+ * <0: errno of failed recall
+ * 0 : async io was completed
+ * 1 : async was not waited for, io may not have completed.
+ *
+ * (rrl 04/96)
+ ***********************************************************************/
+#ifdef CRAY
+int lio_wait4asyncio(int method, int fd, struct iosw **statptr)
+#elif defined(sgi)
+int lio_wait4asyncio(int method, int fd, aiocb_t * aiocbp)
+#elif defined(__linux__) && !defined(__UCLIBC__)
+int lio_wait4asyncio(int method, int fd, struct aiocb *aiocbp)
+{
+ int cnt;
+#ifdef sgi
+ int ret;
+ const aiocb_t *aioary[1];
+#endif
+#if defined(__linux__)&& !defined(__UCLIBC__)
+ int ret;
+ const struct aiocb *aioary[1];
+#endif
+
+ if ((method & LIO_WAIT_RECALL)
+#if defined(sgi) || (defined(__linux__)&& !defined(__UCLIBC__))
+ || (method & LIO_WAIT_CBSUSPEND)
+ || (method & LIO_WAIT_SIGSUSPEND)
+#endif
+ || ((method & LIO_WAIT_TYPES) == 0)) {
+ /*
+ * If method has LIO_WAIT_RECALL bit set or method does
+ * not have any wait method bits set (default), use recall/aio_suspend.
+ */
+#ifdef CRAY
+ if (Debug_level > 2)
+ printf("DEBUG %s/%d: wait method : recall\n", __FILE__,
+ __LINE__);
+ sigon();
+ if (recall(fd, 1, statptr)) {
+ sprintf(Errormsg,
+ "%s/%d recall(%d, 1, stat) failed, errno:%d %s",
+ __FILE__, __LINE__, fd, errno, strerror(errno));
+ return -errno;
+ }
+#else
+ if (Debug_level > 2)
+ printf
+ ("DEBUG %s/%d: wait method : aio_suspend, sigev_notify=%s\n",
+ __FILE__, __LINE__,
+ (aiocbp->aio_sigevent.sigev_notify ==
+ SIGEV_SIGNAL ? "signal" : aiocbp->aio_sigevent.
+ sigev_notify == SIGEV_NONE ? "none" :
+#ifdef SIGEV_CALLBACK
+ aiocbp->aio_sigevent.sigev_notify ==
+ SIGEV_CALLBACK ? "callback" :
+#endif
+ aiocbp->aio_sigevent.sigev_notify ==
+ SIGEV_THREAD ? "thread" : "unknown"));
+
+ aioary[0] = aiocbp;
+ ret = aio_suspend(aioary, 1, NULL);
+ if ((ret == -1) && (errno == EINTR)) {
+ if (aiocbp->aio_sigevent.sigev_notify == SIGEV_SIGNAL) {
+ if (Debug_level > 2) {
+ printf
+ ("DEBUG %s/%d: aio_suspend received EINTR, sigev_notify=SIGEV_SIGNAL -- ok\n",
+ __FILE__, __LINE__);
+ }
+ } else {
+ sprintf(Errormsg,
+ "%s/%d aio_suspend received EINTR, sigev_notify=%s, not ok\n",
+ __FILE__, __LINE__,
+ (aiocbp->aio_sigevent.sigev_notify ==
+ SIGEV_SIGNAL ? "signal" : aiocbp->
+ aio_sigevent.sigev_notify ==
+ SIGEV_NONE ? "none" :
+#ifdef SIGEV_CALLBACK
+ aiocbp->aio_sigevent.sigev_notify ==
+ SIGEV_CALLBACK ? "callback" :
+#endif
+ aiocbp->aio_sigevent.sigev_notify ==
+ SIGEV_THREAD ? "thread" : "unknown"));
+ return -errno;
+ }
+ } else if (ret) {
+ sprintf(Errormsg,
+ "%s/%d aio_suspend(fildes=%d, aioary, 1, NULL) failed, errno:%d %s",
+ __FILE__, __LINE__, fd, errno, strerror(errno));
+ return -errno;
+ }
+#endif
+
+ } else if (method & LIO_WAIT_ACTIVE) {
+ if (Debug_level > 2)
+ printf("DEBUG %s/%d: wait method : active\n", __FILE__,
+ __LINE__);
+#ifdef CRAY
+ sigon();
+ /*
+ * loop until sw_flag, sw_count or sw_error field elements
+ * change to non-zero.
+ */
+ cnt = 0;
+ while ((*statptr)->sw_flag == 0 &&
+ (*statptr)->sw_count == 0 && (*statptr)->sw_error == 0) {
+ cnt++;
+ }
+#else
+ /* loop while aio_error() returns EINPROGRESS */
+ cnt = 0;
+ while (1) {
+ ret = aio_error(aiocbp);
+ if (ret != EINPROGRESS) {
+ break;
+ }
+ ++cnt;
+ }
+
+#endif
+ if (Debug_level > 5 && cnt && (cnt % 50) == 0)
+ printf("DEBUG %s/%d: wait active cnt = %d\n",
+ __FILE__, __LINE__, cnt);
+
+ } else if (method & LIO_WAIT_SIGPAUSE) {
+ if (Debug_level > 2)
+ printf("DEBUG %s/%d: wait method : sigpause\n",
+ __FILE__, __LINE__);
+#ifdef sgi
+ /* note: don't do the sigon() for CRAY in this case. why? -- roehrich 6/11/97 */
+ if (aiocbp->aio_sigevent.sigev_notify == SIGEV_SIGNAL)
+ sigrelse(aiocbp->aio_sigevent.sigev_signo);
+ else {
+ printf("DEBUG %s/%d: sigev_notify != SIGEV_SIGNAL\n",
+ __FILE__, __LINE__);
+ return -1;
+ }
+#endif
+ pause();
+
+ } else if (method & LIO_WAIT_SIGACTIVE) {
+ if (Debug_level > 2)
+ printf("DEBUG %s/%d: wait method : sigactive\n",
+ __FILE__, __LINE__);
+#ifdef CRAY
+ sigon();
+#else
+ if (aiocbp->aio_sigevent.sigev_notify == SIGEV_SIGNAL)
+ sigrelse(aiocbp->aio_sigevent.sigev_signo);
+ else {
+ printf("DEBUG %s/%d: sigev_notify != SIGEV_SIGNAL\n",
+ __FILE__, __LINE__);
+ return -1;
+ }
+#endif
+ /* loop waiting for signal */
+ while (Received_signal == Rec_signal) {
+#ifdef CRAY
+ sigon();
+#else
+ sigrelse(aiocbp->aio_sigevent.sigev_signo);
+#endif
+ }
+
+ } else if (method & LIO_WAIT_NONE) {
+ if (Debug_level > 2)
+ printf("DEBUG %s/%d: wait method : none\n", __FILE__,
+ __LINE__);
+ /* It's broken because the aiocb/iosw is an automatic variable in
+ * lio_{read,write}_buffer, so when the function returns and the
+ * I/O completes there will be nowhere to write the I/O status.
+ * It doesn't cause a problem on unicos--probably because of some
+ * compiler quirk, or an accident. It causes POSIX async I/O
+ * to core dump some threads. spr/pv 705909. 6/27/97 roehrich
+ */
+ sprintf(Errormsg,
+ "%s/%d LIO_WAIT_NONE was selected (this is broken)\n",
+ __FILE__, __LINE__);
+#ifdef CRAY
+ sigon();
+#endif
+/* return 1;*/
+ return -1;
+ } else {
+ if (Debug_level > 2)
+ printf("DEBUG %s/%d: no wait method was chosen\n",
+ __FILE__, __LINE__);
+ return -1;
+ }
+
+ return 0;
+
+} /* end of lio_wait4asyncio */
+
+#endif /* ifndef linux */
+#endif
+
+#if UNIT_TEST
+/***********************************************************************
+ * The following code is provided as unit test.
+ * Just define add "-DUNIT_TEST=1" to the cc line.
+ *
+ * (rrl 04/96)
+ ***********************************************************************/
+struct unit_info_t {
+ int method;
+ int sig;
+ char *str;
+} Unit_info[] = {
+ {
+ LIO_IO_SYNC, 0, "sync io"}, {
+ LIO_IO_SYNCV, 0, "sync readv/writev"}, {
+ LIO_IO_SYNCP, 0, "sync pread/pwrite"}, {
+ LIO_IO_ASYNC, 0, "async io, def wait"}, {
+ LIO_IO_SLISTIO, 0, "sync listio"}, {
+ LIO_IO_ALISTIO, 0, "async listio, def wait"}, {
+ LIO_IO_ASYNC | LIO_WAIT_ACTIVE, 0, "async active"}, {
+ LIO_IO_ASYNC | LIO_WAIT_RECALL, 0, "async recall/suspend"}, {
+ LIO_IO_ASYNC | LIO_WAIT_SIGPAUSE, SIGUSR1, "async sigpause"}, {
+ LIO_IO_ASYNC | LIO_WAIT_SIGACTIVE, SIGUSR1, "async sigactive"}, {
+ LIO_IO_ALISTIO | LIO_WAIT_ACTIVE, 0, "async listio active"}, {
+ LIO_IO_ALISTIO | LIO_WAIT_RECALL, 0, "async listio recall"}, {
+ LIO_IO_ALISTIO | LIO_WAIT_SIGACTIVE, SIGUSR1, "async listio sigactive"},
+ {
+ LIO_IO_ALISTIO | LIO_WAIT_SIGPAUSE, SIGUSR1, "async listio sigpause"},
+ {
+ LIO_IO_ASYNC, SIGUSR2, "async io, def wait, sigusr2"}, {
+LIO_IO_ALISTIO, SIGUSR2, "async listio, def wait, sigusr2"},};
+
+int main(argc, argv)
+int argc;
+char **argv;
+{
+ extern char *optarg;
+ extern int optind;
+
+ int fd;
+ char *err;
+ char buffer[4096];
+ int size = 4096;
+ int ret;
+ int ind;
+ int iter = 3;
+ int method;
+ int exit_status = 0;
+ int c;
+ int i;
+ char *symbols = NULL;
+ int die_on_err = 0;
+
+ while ((c = getopt(argc, argv, "s:di:")) != -1) {
+ switch (c) {
+ case 's':
+ symbols = optarg;
+ break;
+ case 'd':
+ ++die_on_err;
+ break;
+ case 'i':
+ iter = atoi(optarg);
+ break;
+ }
+ }
+
+ if ((fd =
+ open("unit_test_file", O_CREAT | O_RDWR | O_TRUNC, 0777)) == -1) {
+ perror
+ ("open(unit_test_file, O_CREAT|O_RDWR|O_TRUNC, 0777) failed");
+ exit(1);
+ }
+
+ Debug_level = 9;
+
+ if (symbols != NULL) {
+ if ((method = lio_parse_io_arg2(symbols, &err)) == -1) {
+ printf
+ ("lio_parse_io_arg2(%s, &err) failed, bad token starting at %s\n",
+ symbols, err);
+ if (die_on_err)
+ exit(1);
+ } else
+ printf("lio_parse_io_arg2(%s, &err) returned %#o\n",
+ symbols, method);
+
+ exit_status = 0;
+ for (ind = 0; ind < iter; ind++) {
+ memset(buffer, 'A', 4096);
+ if (lseek(fd, 0, 0) == -1) {
+ printf("lseek(fd,0,0), %d, failed, errno %d\n",
+ __LINE__, errno);
+ ++exit_status;
+ }
+ if ((ret = lio_write_buffer(fd, method, buffer,
+ size, SIGUSR1, &err,
+ 0)) != size) {
+ printf
+ ("lio_write_buffer returned -1, err = %s\n",
+ err);
+ } else
+ printf("lio_write_buffer returned %d\n", ret);
+
+ memset(buffer, 'B', 4096);
+ if (lseek(fd, 0, 0) == -1) {
+ printf("lseek(fd,0,0), %d, failed, errno %d\n",
+ __LINE__, errno);
+ ++exit_status;
+ }
+ if ((ret = lio_read_buffer(fd, method, buffer,
+ size, SIGUSR2, &err,
+ 0)) != size) {
+ printf
+ ("lio_read_buffer returned -1, err = %s\n",
+ err);
+ } else
+ printf("lio_read_buffer returned %d\n", ret);
+
+ for (i = 0; i < 4096; ++i) {
+ if (buffer[i] != 'A') {
+ printf(" buffer[%d] = %d\n", i,
+ buffer[i]);
+ ++exit_status;
+ break;
+ }
+ }
+
+ if (exit_status)
+ exit(exit_status);
+
+ }
+
+ unlink("unit_test_file");
+ exit(0);
+ }
+
+ for (ind = 0; ind < sizeof(Unit_info) / sizeof(struct unit_info_t);
+ ind++) {
+
+ printf("\n********* write %s ***************\n",
+ Unit_info[ind].str);
+ if (lseek(fd, 0, 0) == -1) {
+ printf("lseek(fd,0,0), %d, failed, errno %d\n",
+ __LINE__, errno);
+ ++exit_status;
+ }
+
+ memset(buffer, 'A', 4096);
+ if ((ret = lio_write_buffer(fd, Unit_info[ind].method, buffer,
+ size, Unit_info[ind].sig, &err,
+ 0)) != size) {
+ printf
+ (">>>>> lio_write_buffer(fd,0%x,buffer,%d,%d,err,0) returned -1,\n err = %s\n",
+ Unit_info[ind].method, size, Unit_info[ind].sig,
+ err);
+ ++exit_status;
+ if (die_on_err)
+ exit(exit_status);
+ } else {
+ printf("lio_write_buffer returned %d\n", ret);
+ }
+
+ printf("\n********* read %s ***************\n",
+ Unit_info[ind].str);
+ if (lseek(fd, 0, 0) == -1) {
+ printf("lseek(fd,0,0), %d, failed, errno %d\n",
+ __LINE__, errno);
+ ++exit_status;
+ }
+ memset(buffer, 'B', 4096);
+ if ((ret = lio_read_buffer(fd, Unit_info[ind].method, buffer,
+ size, Unit_info[ind].sig, &err,
+ 0)) != size) {
+ printf
+ (">>>>> lio_read_buffer(fd,0%x,buffer,%d,%d,err,0) returned -1,\n err = %s\n",
+ Unit_info[ind].method, size, Unit_info[ind].sig,
+ err);
+ ++exit_status;
+ if (die_on_err)
+ exit(exit_status);
+ } else {
+ printf("lio_read_buffer returned %d\n", ret);
+ }
+
+ for (i = 0; i < 4096; ++i) {
+ if (buffer[i] != 'A') {
+ printf(" buffer[%d] = %d\n", i, buffer[i]);
+ ++exit_status;
+ if (die_on_err)
+ exit(exit_status);
+ break;
+ }
+ }
+
+ fflush(stdout);
+ fflush(stderr);
+ sleep(1);
+
+ }
+
+ unlink("unit_test_file");
+
+ exit(exit_status);
+}
+#endif
diff --git a/kernel/tests/lib/tst_af_alg.c b/kernel/tests/lib/tst_af_alg.c
new file mode 100644
index 0000000..d3895a8
--- /dev/null
+++ b/kernel/tests/lib/tst_af_alg.c
@@ -0,0 +1,212 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright 2019 Google LLC
+ */
+
+#include <errno.h>
+#include <stdlib.h>
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+#include "tst_af_alg.h"
+#include "lapi/socket.h"
+
+int tst_alg_create(void)
+{
+ TEST(socket(AF_ALG, SOCK_SEQPACKET, 0));
+ if (TST_RET >= 0)
+ return TST_RET;
+ if (TST_ERR == EAFNOSUPPORT)
+ tst_brk(TCONF, "kernel doesn't support AF_ALG");
+ tst_brk(TBROK | TTERRNO, "unexpected error creating AF_ALG socket");
+ return -1;
+}
+
+void tst_alg_bind_addr(int algfd, const struct sockaddr_alg *addr)
+{
+ TEST(bind(algfd, (const struct sockaddr *)addr, sizeof(*addr)));
+ if (TST_RET == 0)
+ return;
+ if (TST_ERR == ENOENT) {
+ tst_brk(TCONF, "kernel doesn't support %s algorithm '%s'",
+ addr->salg_type, addr->salg_name);
+ }
+ tst_brk(TBROK | TTERRNO,
+ "unexpected error binding AF_ALG socket to %s algorithm '%s'",
+ addr->salg_type, addr->salg_name);
+}
+
+static void init_sockaddr_alg(struct sockaddr_alg *addr,
+ const char *algtype, const char *algname)
+{
+ memset(addr, 0, sizeof(*addr));
+
+ addr->salg_family = AF_ALG;
+
+ strncpy((char *)addr->salg_type, algtype, sizeof(addr->salg_type));
+ if (addr->salg_type[sizeof(addr->salg_type) - 1] != '\0')
+ tst_brk(TBROK, "algorithm type too long: '%s'", algtype);
+
+ strncpy((char *)addr->salg_name, algname, sizeof(addr->salg_name));
+ if (addr->salg_name[sizeof(addr->salg_name) - 1] != '\0')
+ tst_brk(TBROK, "algorithm name too long: '%s'", algname);
+}
+
+void tst_alg_bind(int algfd, const char *algtype, const char *algname)
+{
+ struct sockaddr_alg addr;
+
+ init_sockaddr_alg(&addr, algtype, algname);
+
+ tst_alg_bind_addr(algfd, &addr);
+}
+
+bool tst_have_alg(const char *algtype, const char *algname)
+{
+ int algfd;
+ struct sockaddr_alg addr;
+ bool have_alg = true;
+
+ algfd = tst_alg_create();
+
+ init_sockaddr_alg(&addr, algtype, algname);
+
+ TEST(bind(algfd, (const struct sockaddr *)&addr, sizeof(addr)));
+ if (TST_RET != 0) {
+ if (TST_ERR != ENOENT) {
+ tst_brk(TBROK | TTERRNO,
+ "unexpected error binding AF_ALG socket to %s algorithm '%s'",
+ algtype, algname);
+ }
+ have_alg = false;
+ }
+
+ close(algfd);
+ return have_alg;
+}
+
+void tst_require_alg(const char *algtype, const char *algname)
+{
+ int algfd = tst_alg_create();
+
+ tst_alg_bind(algfd, algtype, algname);
+
+ close(algfd);
+}
+
+void tst_alg_setkey(int algfd, const uint8_t *key, unsigned int keylen)
+{
+ uint8_t *keybuf = NULL;
+ unsigned int i;
+
+ if (key == NULL) {
+ /* generate a random key */
+ keybuf = SAFE_MALLOC(keylen);
+ for (i = 0; i < keylen; i++)
+ keybuf[i] = rand();
+ key = keybuf;
+ }
+ TEST(setsockopt(algfd, SOL_ALG, ALG_SET_KEY, key, keylen));
+ if (TST_RET != 0) {
+ tst_brk(TBROK | TTERRNO,
+ "unexpected error setting key (len=%u)", keylen);
+ }
+ free(keybuf);
+}
+
+int tst_alg_accept(int algfd)
+{
+ TEST(accept(algfd, NULL, NULL));
+ if (TST_RET < 0) {
+ tst_brk(TBROK | TTERRNO,
+ "unexpected error accept()ing AF_ALG request socket");
+ }
+ return TST_RET;
+}
+
+int tst_alg_setup(const char *algtype, const char *algname,
+ const uint8_t *key, unsigned int keylen)
+{
+ int algfd = tst_alg_create();
+
+ tst_alg_bind(algfd, algtype, algname);
+
+ if (keylen != 0)
+ tst_alg_setkey(algfd, key, keylen);
+
+ return algfd;
+}
+
+int tst_alg_setup_reqfd(const char *algtype, const char *algname,
+ const uint8_t *key, unsigned int keylen)
+{
+ int algfd = tst_alg_setup(algtype, algname, key, keylen);
+ int reqfd = tst_alg_accept(algfd);
+
+ close(algfd);
+ return reqfd;
+}
+
+void tst_alg_sendmsg(int reqfd, const void *data, size_t datalen,
+ const struct tst_alg_sendmsg_params *params)
+{
+ struct iovec iov = {
+ .iov_base = (void *)data,
+ .iov_len = datalen,
+ };
+ struct msghdr msg = {
+ .msg_iov = &iov,
+ .msg_iovlen = 1,
+ .msg_flags = params->msg_flags,
+ };
+ size_t controllen;
+ uint8_t *control;
+ struct cmsghdr *cmsg;
+ struct af_alg_iv *alg_iv;
+
+ if (params->encrypt && params->decrypt)
+ tst_brk(TBROK, "Both encrypt and decrypt are specified");
+
+ controllen = 0;
+ if (params->encrypt || params->decrypt)
+ controllen += CMSG_SPACE(sizeof(uint32_t));
+ if (params->ivlen)
+ controllen += CMSG_SPACE(sizeof(struct af_alg_iv) +
+ params->ivlen);
+ if (params->assoclen)
+ controllen += CMSG_SPACE(sizeof(uint32_t));
+
+ control = SAFE_MALLOC(controllen);
+ memset(control, 0, controllen);
+ msg.msg_control = control;
+ msg.msg_controllen = controllen;
+ cmsg = CMSG_FIRSTHDR(&msg);
+
+ if (params->encrypt || params->decrypt) {
+ cmsg->cmsg_level = SOL_ALG;
+ cmsg->cmsg_type = ALG_SET_OP;
+ cmsg->cmsg_len = CMSG_LEN(sizeof(uint32_t));
+ *(uint32_t *)CMSG_DATA(cmsg) =
+ params->encrypt ? ALG_OP_ENCRYPT : ALG_OP_DECRYPT;
+ cmsg = CMSG_NXTHDR(&msg, cmsg);
+ }
+ if (params->ivlen) {
+ cmsg->cmsg_level = SOL_ALG;
+ cmsg->cmsg_type = ALG_SET_IV;
+ cmsg->cmsg_len = CMSG_LEN(sizeof(struct af_alg_iv) +
+ params->ivlen);
+ alg_iv = (struct af_alg_iv *)CMSG_DATA(cmsg);
+ alg_iv->ivlen = params->ivlen;
+ memcpy(alg_iv->iv, params->iv, params->ivlen);
+ cmsg = CMSG_NXTHDR(&msg, cmsg);
+ }
+ if (params->assoclen) {
+ cmsg->cmsg_level = SOL_ALG;
+ cmsg->cmsg_type = ALG_SET_AEAD_ASSOCLEN;
+ cmsg->cmsg_len = CMSG_LEN(sizeof(uint32_t));
+ *(uint32_t *)CMSG_DATA(cmsg) = params->assoclen;
+ cmsg = CMSG_NXTHDR(&msg, cmsg);
+ }
+
+ SAFE_SENDMSG(datalen, reqfd, &msg, 0);
+}
diff --git a/kernel/tests/lib/tst_ansi_color.c b/kernel/tests/lib/tst_ansi_color.c
new file mode 100644
index 0000000..1c29268
--- /dev/null
+++ b/kernel/tests/lib/tst_ansi_color.c
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "tst_res_flags.h"
+#include "tst_ansi_color.h"
+
+char* tst_ttype2color(int ttype)
+{
+ switch (TTYPE_RESULT(ttype)) {
+ case TPASS:
+ return ANSI_COLOR_GREEN;
+ break;
+ case TFAIL:
+ return ANSI_COLOR_RED;
+ break;
+ case TBROK:
+ return ANSI_COLOR_RED;
+ break;
+ case TCONF:
+ return ANSI_COLOR_YELLOW;
+ break;
+ case TWARN:
+ return ANSI_COLOR_MAGENTA;
+ break;
+ case TINFO:
+ return ANSI_COLOR_BLUE;
+ break;
+ default:
+ return "";
+ }
+}
+
+int tst_color_enabled(int fd)
+{
+ static int color;
+
+ if (color)
+ return color - 1;
+
+ char *env = getenv("LTP_COLORIZE_OUTPUT");
+
+ if (env) {
+ if (!strcmp(env, "n") || !strcmp(env, "0"))
+ color = 1;
+
+ if (!strcmp(env, "y") || !strcmp(env, "1"))
+ color = 2;
+
+ return color - 1;
+ }
+
+ if (isatty(fd) == 0)
+ color = 1;
+ else
+ color = 2;
+
+ return color - 1;
+}
diff --git a/kernel/tests/lib/tst_assert.c b/kernel/tests/lib/tst_assert.c
new file mode 100644
index 0000000..9b8ebc1
--- /dev/null
+++ b/kernel/tests/lib/tst_assert.c
@@ -0,0 +1,83 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
+ * Copyright (c) 2020 Cyril Hrubis <chrubis@suse.cz>
+ */
+#include <stdio.h>
+#define TST_NO_DEFAULT_MAIN
+#include "tst_assert.h"
+#include "tst_test.h"
+
+void tst_assert_int(const char *file, const int lineno, const char *path, int val)
+{
+ int sys_val;
+
+ safe_file_scanf(file, lineno, NULL, path, "%d", &sys_val);
+
+ if (val == sys_val) {
+ tst_res_(file, lineno, TPASS, "%s = %d", path, val);
+ return;
+ }
+
+ tst_res_(file, lineno, TFAIL, "%s != %d got %d", path, val, sys_val);
+}
+
+void tst_assert_ulong(const char *file, const int lineno, const char *path, unsigned long val)
+{
+ unsigned long sys_val;
+
+ safe_file_scanf(file, lineno, NULL, path, "%lu", &sys_val);
+
+ if (val == sys_val) {
+ tst_res_(file, lineno, TPASS, "%s = %lu", path, val);
+ return;
+ }
+
+ tst_res_(file, lineno, TFAIL, "%s != %lu got %lu", path, val, sys_val);
+}
+
+void tst_assert_file_int(const char *file, const int lineno, const char *path, const char *prefix, int val)
+{
+ int sys_val;
+ char fmt[1024];
+
+ snprintf(fmt, sizeof(fmt), "%s%%d", prefix);
+ file_lines_scanf(file, lineno, NULL, 1, path, fmt, &sys_val);
+
+ if (val == sys_val) {
+ tst_res_(file, lineno, TPASS, "%s %s = %d", path, prefix, sys_val);
+ return;
+ }
+
+ tst_res_(file, lineno, TFAIL, "%s %s != %d got %d", path, prefix, val, sys_val);
+}
+
+void tst_assert_str(const char *file, const int lineno, const char *path, const char *val)
+{
+ char sys_val[1024];
+
+ safe_file_scanf(file, lineno, NULL, path, "%1024s", sys_val);
+ if (!strcmp(val, sys_val)) {
+ tst_res_(file, lineno, TPASS, "%s = '%s'", path, val);
+ return;
+ }
+
+ tst_res_(file, lineno, TFAIL, "%s != '%s' got '%s'", path, val, sys_val);
+}
+
+void tst_assert_file_str(const char *file, const int lineno, const char *path, const char *prefix, const char *val)
+{
+ char sys_val[1024];
+ char fmt[2048];
+
+ snprintf(fmt, sizeof(fmt), "%s: %%1024s", prefix);
+ file_lines_scanf(file, lineno, NULL, 1, path, fmt, sys_val);
+
+ if (!strcmp(val, sys_val)) {
+ tst_res_(file, lineno, TPASS, "%s %s = '%s'", path, prefix, sys_val);
+ return;
+ }
+
+ tst_res_(file, lineno, TFAIL, "%s %s != '%s' got '%s'", path, prefix, val, sys_val);
+}
diff --git a/kernel/tests/lib/tst_buffers.c b/kernel/tests/lib/tst_buffers.c
new file mode 100644
index 0000000..b8b597a
--- /dev/null
+++ b/kernel/tests/lib/tst_buffers.c
@@ -0,0 +1,143 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#include <sys/mman.h>
+#include <stdlib.h>
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+
+struct map {
+ void *addr;
+ size_t size;
+ size_t buf_shift;
+ struct map *next;
+};
+
+static struct map *maps;
+
+static void setup_canary(struct map *map)
+{
+ size_t i;
+ char *buf = map->addr;
+
+ for (i = 0; i < map->buf_shift/2; i++) {
+ char c = random();
+ buf[map->buf_shift - i - 1] = c;
+ buf[i] = c;
+ }
+}
+
+static void check_canary(struct map *map)
+{
+ size_t i;
+ char *buf = map->addr;
+
+ for (i = 0; i < map->buf_shift/2; i++) {
+ if (buf[map->buf_shift - i - 1] != buf[i]) {
+ tst_res(TWARN,
+ "pid %i: buffer modified address %p[%zi]",
+ getpid(), (char*)map->addr + map->buf_shift, -i-1);
+ }
+ }
+}
+
+void *tst_alloc(size_t size)
+{
+ size_t page_size = getpagesize();
+ unsigned int pages = (size / page_size) + !!(size % page_size) + 1;
+ void *ret;
+ struct map *map = SAFE_MALLOC(sizeof(struct map));
+ static int print_msg = 1;
+
+ if (print_msg) {
+ tst_res(TINFO, "Test is using guarded buffers");
+ print_msg = 0;
+ }
+
+ ret = SAFE_MMAP(NULL, page_size * pages, PROT_READ | PROT_WRITE,
+ MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+
+ mprotect(ret + (pages-1) * page_size, page_size, PROT_NONE);
+
+ map->addr = ret;
+ map->size = pages * page_size;
+ map->next = maps;
+ maps = map;
+
+ if (size % page_size)
+ map->buf_shift = page_size - (size % page_size);
+ else
+ map->buf_shift = 0;
+
+ setup_canary(map);
+
+ return ret + map->buf_shift;
+}
+
+static int count_iovec(int *sizes)
+{
+ int ret = 0;
+
+ while (sizes[ret++] != -1);
+
+ return ret - 1;
+}
+
+struct iovec *tst_iovec_alloc(int sizes[])
+{
+ int i, cnt = count_iovec(sizes);
+ struct iovec *iovec;
+
+ if (cnt <= 0)
+ return NULL;
+
+ iovec = tst_alloc(sizeof(struct iovec) * cnt);
+
+ for (i = 0; i < cnt; i++) {
+ if (sizes[i]) {
+ iovec[i].iov_base = tst_alloc(sizes[i]);
+ iovec[i].iov_len = sizes[i];
+ } else {
+ iovec[i].iov_base = NULL;
+ iovec[i].iov_base = 0;
+ }
+ }
+
+ return iovec;
+}
+
+void tst_buffers_alloc(struct tst_buffers bufs[])
+{
+ unsigned int i;
+
+ for (i = 0; bufs[i].ptr; i++) {
+ if (bufs[i].size)
+ *((void**)bufs[i].ptr) = tst_alloc(bufs[i].size);
+ else
+ *((void**)bufs[i].ptr) = tst_iovec_alloc(bufs[i].iov_sizes);
+ }
+}
+
+char *tst_strdup(const char *str)
+{
+ size_t len = strlen(str);
+ char *ret = tst_alloc(len + 1);
+ return strcpy(ret, str);
+}
+
+void tst_free_all(void)
+{
+ struct map *i = maps;
+
+ while (i) {
+ struct map *j = i;
+ check_canary(i);
+ SAFE_MUNMAP(i->addr, i->size);
+ i = i->next;
+ free(j);
+ }
+
+ maps = NULL;
+}
diff --git a/kernel/tests/lib/tst_capability.c b/kernel/tests/lib/tst_capability.c
new file mode 100644
index 0000000..1fa0e49
--- /dev/null
+++ b/kernel/tests/lib/tst_capability.c
@@ -0,0 +1,90 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Richard Palethorpe <rpalethorpe@suse.com>
+ */
+
+#include <string.h>
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+#include "tst_capability.h"
+
+#include "lapi/syscalls.h"
+
+int tst_capget(struct tst_cap_user_header *hdr,
+ struct tst_cap_user_data *data)
+{
+ return tst_syscall(__NR_capget, hdr, data);
+}
+
+int tst_capset(struct tst_cap_user_header *hdr,
+ const struct tst_cap_user_data *data)
+{
+ return tst_syscall(__NR_capset, hdr, data);
+}
+
+static void do_cap_drop(uint32_t *set, uint32_t mask, const struct tst_cap *cap)
+{
+ if (*set & mask) {
+ tst_res(TINFO, "Dropping %s(%d)", cap->name, cap->id);
+ *set &= ~mask;
+ }
+}
+
+static void do_cap_req(uint32_t *permitted, uint32_t *effective, uint32_t mask,
+ const struct tst_cap *cap)
+{
+ if (!(*permitted & mask))
+ tst_brk(TCONF, "Need %s(%d)", cap->name, cap->id);
+
+ if (!(*effective & mask)) {
+ tst_res(TINFO, "Permitting %s(%d)", cap->name, cap->id);
+ *effective |= mask;
+ }
+}
+
+void tst_cap_action(struct tst_cap *cap)
+{
+ struct tst_cap_user_header hdr = {
+ .version = 0x20080522,
+ .pid = tst_syscall(__NR_gettid),
+ };
+ struct tst_cap_user_data cur[2] = { {0} };
+ struct tst_cap_user_data new[2] = { {0} };
+ uint32_t act = cap->action;
+ uint32_t *pE = &new[CAP_TO_INDEX(cap->id)].effective;
+ uint32_t *pP = &new[CAP_TO_INDEX(cap->id)].permitted;
+ uint32_t mask = CAP_TO_MASK(cap->id);
+
+ if (tst_capget(&hdr, cur))
+ tst_brk(TBROK | TTERRNO, "tst_capget()");
+
+ memcpy(new, cur, sizeof(new));
+
+ switch (act) {
+ case TST_CAP_DROP:
+ do_cap_drop(pE, mask, cap);
+ break;
+ case TST_CAP_REQ:
+ do_cap_req(pP, pE, mask, cap);
+ break;
+ default:
+ tst_brk(TBROK, "Unrecognised action %d", cap->action);
+ }
+
+ if (!memcmp(cur, new, sizeof(new)))
+ return;
+
+ if (tst_capset(&hdr, new))
+ tst_brk(TBROK | TERRNO, "tst_capset(%s)", cap->name);
+}
+
+void tst_cap_setup(struct tst_cap *caps, unsigned int action_mask)
+{
+ struct tst_cap *cap;
+
+ for (cap = caps; cap->action; cap++) {
+ if (cap->action & action_mask)
+ tst_cap_action(cap);
+ }
+}
diff --git a/kernel/tests/lib/tst_cgroup.c b/kernel/tests/lib/tst_cgroup.c
new file mode 100644
index 0000000..ba413d8
--- /dev/null
+++ b/kernel/tests/lib/tst_cgroup.c
@@ -0,0 +1,452 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Red Hat, Inc.
+ * Copyright (c) 2020 Li Wang <liwang@redhat.com>
+ */
+
+#define TST_NO_DEFAULT_MAIN
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/mount.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "tst_test.h"
+#include "tst_safe_macros.h"
+#include "tst_safe_stdio.h"
+#include "tst_cgroup.h"
+#include "tst_device.h"
+
+static enum tst_cgroup_ver tst_cg_ver;
+static int clone_children;
+
+static int tst_cgroup_check(const char *cgroup)
+{
+ char line[PATH_MAX];
+ FILE *file;
+ int cg_check = 0;
+
+ file = SAFE_FOPEN("/proc/filesystems", "r");
+ while (fgets(line, sizeof(line), file)) {
+ if (strstr(line, cgroup) != NULL) {
+ cg_check = 1;
+ break;
+ }
+ }
+ SAFE_FCLOSE(file);
+
+ return cg_check;
+}
+
+enum tst_cgroup_ver tst_cgroup_version(void)
+{
+ enum tst_cgroup_ver cg_ver;
+
+ if (tst_cgroup_check("cgroup2")) {
+ if (!tst_is_mounted("cgroup2") && tst_is_mounted("cgroup"))
+ cg_ver = TST_CGROUP_V1;
+ else
+ cg_ver = TST_CGROUP_V2;
+
+ goto out;
+ }
+
+ if (tst_cgroup_check("cgroup"))
+ cg_ver = TST_CGROUP_V1;
+
+ if (!cg_ver)
+ tst_brk(TCONF, "Cgroup is not configured");
+
+out:
+ return cg_ver;
+}
+
+static void tst_cgroup1_mount(const char *name, const char *option,
+ const char *mnt_path, const char *new_path)
+{
+ char knob_path[PATH_MAX];
+ if (tst_is_mounted(mnt_path))
+ goto out;
+
+ SAFE_MKDIR(mnt_path, 0777);
+ if (mount(name, mnt_path, "cgroup", 0, option) == -1) {
+ if (errno == ENODEV) {
+ if (rmdir(mnt_path) == -1)
+ tst_res(TWARN | TERRNO, "rmdir %s failed", mnt_path);
+ tst_brk(TCONF,
+ "Cgroup v1 is not configured in kernel");
+ }
+ tst_brk(TBROK | TERRNO, "mount %s", mnt_path);
+ }
+
+ /*
+ * We should assign one or more memory nodes to cpuset.mems and
+ * cpuset.cpus, otherwise, echo $$ > tasks gives “ENOSPC: no space
+ * left on device” when trying to use cpuset.
+ *
+ * Or, setting cgroup.clone_children to 1 can help in automatically
+ * inheriting memory and node setting from parent cgroup when a
+ * child cgroup is created.
+ */
+ if (strcmp(option, "cpuset") == 0) {
+ sprintf(knob_path, "%s/cgroup.clone_children", mnt_path);
+ SAFE_FILE_SCANF(knob_path, "%d", &clone_children);
+ SAFE_FILE_PRINTF(knob_path, "%d", 1);
+ }
+out:
+ SAFE_MKDIR(new_path, 0777);
+
+ tst_res(TINFO, "Cgroup(%s) v1 mount at %s success", option, mnt_path);
+}
+
+static void tst_cgroup2_mount(const char *mnt_path, const char *new_path)
+{
+ if (tst_is_mounted(mnt_path))
+ goto out;
+
+ SAFE_MKDIR(mnt_path, 0777);
+ if (mount("cgroup2", mnt_path, "cgroup2", 0, NULL) == -1) {
+ if (errno == ENODEV) {
+ if (rmdir(mnt_path) == -1)
+ tst_res(TWARN | TERRNO, "rmdir %s failed", mnt_path);
+ tst_brk(TCONF,
+ "Cgroup v2 is not configured in kernel");
+ }
+ tst_brk(TBROK | TERRNO, "mount %s", mnt_path);
+ }
+
+out:
+ SAFE_MKDIR(new_path, 0777);
+
+ tst_res(TINFO, "Cgroup v2 mount at %s success", mnt_path);
+}
+
+static void tst_cgroupN_umount(const char *mnt_path, const char *new_path)
+{
+ FILE *fp;
+ int fd;
+ char s_new[BUFSIZ], s[BUFSIZ], value[BUFSIZ];
+ char knob_path[PATH_MAX];
+
+ if (!tst_is_mounted(mnt_path))
+ return;
+
+ /* Move all processes in task(v2: cgroup.procs) to its parent node. */
+ if (tst_cg_ver & TST_CGROUP_V1)
+ sprintf(s, "%s/tasks", mnt_path);
+ if (tst_cg_ver & TST_CGROUP_V2)
+ sprintf(s, "%s/cgroup.procs", mnt_path);
+
+ fd = open(s, O_WRONLY);
+ if (fd == -1)
+ tst_res(TWARN | TERRNO, "open %s", s);
+
+ if (tst_cg_ver & TST_CGROUP_V1)
+ snprintf(s_new, BUFSIZ, "%s/tasks", new_path);
+ if (tst_cg_ver & TST_CGROUP_V2)
+ snprintf(s_new, BUFSIZ, "%s/cgroup.procs", new_path);
+
+ fp = fopen(s_new, "r");
+ if (fp == NULL)
+ tst_res(TWARN | TERRNO, "fopen %s", s_new);
+ if ((fd != -1) && (fp != NULL)) {
+ while (fgets(value, BUFSIZ, fp) != NULL)
+ if (write(fd, value, strlen(value) - 1)
+ != (ssize_t)strlen(value) - 1)
+ tst_res(TWARN | TERRNO, "write %s", s);
+ }
+ if (tst_cg_ver & TST_CGROUP_V1) {
+ sprintf(knob_path, "%s/cpuset.cpus", mnt_path);
+ if (!access(knob_path, F_OK)) {
+ sprintf(knob_path, "%s/cgroup.clone_children", mnt_path);
+ SAFE_FILE_PRINTF(knob_path, "%d", clone_children);
+ }
+ }
+ if (fd != -1)
+ close(fd);
+ if (fp != NULL)
+ fclose(fp);
+ if (rmdir(new_path) == -1)
+ tst_res(TWARN | TERRNO, "rmdir %s", new_path);
+ if (umount(mnt_path) == -1)
+ tst_res(TWARN | TERRNO, "umount %s", mnt_path);
+ if (rmdir(mnt_path) == -1)
+ tst_res(TWARN | TERRNO, "rmdir %s", mnt_path);
+
+ if (tst_cg_ver & TST_CGROUP_V1)
+ tst_res(TINFO, "Cgroup v1 unmount success");
+ if (tst_cg_ver & TST_CGROUP_V2)
+ tst_res(TINFO, "Cgroup v2 unmount success");
+}
+
+struct tst_cgroup_path {
+ char *mnt_path;
+ char *new_path;
+ struct tst_cgroup_path *next;
+};
+
+static struct tst_cgroup_path *tst_cgroup_paths;
+
+static void tst_cgroup_set_path(const char *cgroup_dir)
+{
+ char cgroup_new_dir[PATH_MAX];
+ struct tst_cgroup_path *tst_cgroup_path, *a;
+
+ if (!cgroup_dir)
+ tst_brk(TBROK, "Invalid cgroup dir, plese check cgroup_dir");
+
+ sprintf(cgroup_new_dir, "%s/ltp_%d", cgroup_dir, rand());
+
+ /* To store cgroup path in the 'path' list */
+ tst_cgroup_path = SAFE_MALLOC(sizeof(struct tst_cgroup_path));
+ tst_cgroup_path->mnt_path = SAFE_MALLOC(strlen(cgroup_dir) + 1);
+ tst_cgroup_path->new_path = SAFE_MALLOC(strlen(cgroup_new_dir) + 1);
+ tst_cgroup_path->next = NULL;
+
+ if (!tst_cgroup_paths) {
+ tst_cgroup_paths = tst_cgroup_path;
+ } else {
+ a = tst_cgroup_paths;
+ do {
+ if (!a->next) {
+ a->next = tst_cgroup_path;
+ break;
+ }
+ a = a->next;
+ } while (a);
+ }
+
+ sprintf(tst_cgroup_path->mnt_path, "%s", cgroup_dir);
+ sprintf(tst_cgroup_path->new_path, "%s", cgroup_new_dir);
+}
+
+static char *tst_cgroup_get_path(const char *cgroup_dir)
+{
+ struct tst_cgroup_path *a;
+
+ if (!tst_cgroup_paths)
+ return NULL;
+
+ a = tst_cgroup_paths;
+
+ while (strcmp(a->mnt_path, cgroup_dir) != 0){
+ if (!a->next) {
+ tst_res(TINFO, "%s is not found", cgroup_dir);
+ return NULL;
+ }
+ a = a->next;
+ };
+
+ return a->new_path;
+}
+
+static void tst_cgroup_del_path(const char *cgroup_dir)
+{
+ struct tst_cgroup_path *a, *b;
+
+ if (!tst_cgroup_paths)
+ return;
+
+ a = b = tst_cgroup_paths;
+
+ while (strcmp(b->mnt_path, cgroup_dir) != 0) {
+ if (!b->next) {
+ tst_res(TINFO, "%s is not found", cgroup_dir);
+ return;
+ }
+ a = b;
+ b = b->next;
+ };
+
+ if (b == tst_cgroup_paths)
+ tst_cgroup_paths = b->next;
+ else
+ a->next = b->next;
+
+ free(b->mnt_path);
+ free(b->new_path);
+ free(b);
+}
+
+void tst_cgroup_mount(enum tst_cgroup_ctrl ctrl, const char *cgroup_dir)
+{
+ char *cgroup_new_dir;
+ char knob_path[PATH_MAX];
+
+ tst_cg_ver = tst_cgroup_version();
+
+ tst_cgroup_set_path(cgroup_dir);
+ cgroup_new_dir = tst_cgroup_get_path(cgroup_dir);
+
+ if (tst_cg_ver & TST_CGROUP_V1) {
+ switch(ctrl) {
+ case TST_CGROUP_MEMCG:
+ tst_cgroup1_mount("memcg", "memory", cgroup_dir, cgroup_new_dir);
+ break;
+ case TST_CGROUP_CPUSET:
+ tst_cgroup1_mount("cpusetcg", "cpuset", cgroup_dir, cgroup_new_dir);
+ break;
+ default:
+ tst_brk(TBROK, "Invalid cgroup controller: %d", ctrl);
+ }
+ }
+
+ if (tst_cg_ver & TST_CGROUP_V2) {
+ tst_cgroup2_mount(cgroup_dir, cgroup_new_dir);
+
+ switch(ctrl) {
+ case TST_CGROUP_MEMCG:
+ sprintf(knob_path, "%s/cgroup.subtree_control", cgroup_dir);
+ SAFE_FILE_PRINTF(knob_path, "%s", "+memory");
+ break;
+ case TST_CGROUP_CPUSET:
+ tst_brk(TCONF, "Cgroup v2 hasn't achieve cpuset subsystem");
+ break;
+ default:
+ tst_brk(TBROK, "Invalid cgroup controller: %d", ctrl);
+ }
+ }
+}
+
+void tst_cgroup_umount(const char *cgroup_dir)
+{
+ char *cgroup_new_dir;
+
+ cgroup_new_dir = tst_cgroup_get_path(cgroup_dir);
+ tst_cgroupN_umount(cgroup_dir, cgroup_new_dir);
+ tst_cgroup_del_path(cgroup_dir);
+}
+
+void tst_cgroup_set_knob(const char *cgroup_dir, const char *knob, long value)
+{
+ char *cgroup_new_dir;
+ char knob_path[PATH_MAX];
+
+ cgroup_new_dir = tst_cgroup_get_path(cgroup_dir);
+ sprintf(knob_path, "%s/%s", cgroup_new_dir, knob);
+ SAFE_FILE_PRINTF(knob_path, "%ld", value);
+}
+
+void tst_cgroup_move_current(const char *cgroup_dir)
+{
+ if (tst_cg_ver & TST_CGROUP_V1)
+ tst_cgroup_set_knob(cgroup_dir, "tasks", getpid());
+
+ if (tst_cg_ver & TST_CGROUP_V2)
+ tst_cgroup_set_knob(cgroup_dir, "cgroup.procs", getpid());
+}
+
+void tst_cgroup_mem_set_maxbytes(const char *cgroup_dir, long memsz)
+{
+ if (tst_cg_ver & TST_CGROUP_V1)
+ tst_cgroup_set_knob(cgroup_dir, "memory.limit_in_bytes", memsz);
+
+ if (tst_cg_ver & TST_CGROUP_V2)
+ tst_cgroup_set_knob(cgroup_dir, "memory.max", memsz);
+}
+
+int tst_cgroup_mem_swapacct_enabled(const char *cgroup_dir)
+{
+ char *cgroup_new_dir;
+ char knob_path[PATH_MAX];
+
+ cgroup_new_dir = tst_cgroup_get_path(cgroup_dir);
+
+ if (tst_cg_ver & TST_CGROUP_V1) {
+ sprintf(knob_path, "%s/%s",
+ cgroup_new_dir, "/memory.memsw.limit_in_bytes");
+
+ if ((access(knob_path, F_OK) == -1)) {
+ if (errno == ENOENT)
+ tst_res(TCONF, "memcg swap accounting is disabled");
+ else
+ tst_brk(TBROK | TERRNO, "failed to access %s", knob_path);
+ } else {
+ return 1;
+ }
+ }
+
+ if (tst_cg_ver & TST_CGROUP_V2) {
+ sprintf(knob_path, "%s/%s",
+ cgroup_new_dir, "/memory.swap.max");
+
+ if ((access(knob_path, F_OK) == -1)) {
+ if (errno == ENOENT)
+ tst_res(TCONF, "memcg swap accounting is disabled");
+ else
+ tst_brk(TBROK | TERRNO, "failed to access %s", knob_path);
+ } else {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+void tst_cgroup_mem_set_maxswap(const char *cgroup_dir, long memsz)
+{
+ if (tst_cg_ver & TST_CGROUP_V1)
+ tst_cgroup_set_knob(cgroup_dir, "memory.memsw.limit_in_bytes", memsz);
+
+ if (tst_cg_ver & TST_CGROUP_V2)
+ tst_cgroup_set_knob(cgroup_dir, "memory.swap.max", memsz);
+}
+
+void tst_cgroup_cpuset_read_files(const char *cgroup_dir, const char *filename, char *retbuf)
+{
+ int fd;
+ char *cgroup_new_dir;
+ char knob_path[PATH_MAX];
+
+ cgroup_new_dir = tst_cgroup_get_path(cgroup_dir);
+
+ /*
+ * try either '/dev/cpuset/XXXX' or '/dev/cpuset/cpuset.XXXX'
+ * please see Documentation/cgroups/cpusets.txt from kernel src
+ * for details
+ */
+ sprintf(knob_path, "%s/%s", cgroup_new_dir, filename);
+ fd = open(knob_path, O_RDONLY);
+ if (fd == -1) {
+ if (errno == ENOENT) {
+ sprintf(knob_path, "%s/cpuset.%s",
+ cgroup_new_dir, filename);
+ fd = SAFE_OPEN(knob_path, O_RDONLY);
+ } else
+ tst_brk(TBROK | TERRNO, "open %s", knob_path);
+ }
+
+ if (read(fd, retbuf, sizeof(retbuf)) < 0)
+ tst_brk(TBROK | TERRNO, "read %s", knob_path);
+
+ close(fd);
+}
+
+void tst_cgroup_cpuset_write_files(const char *cgroup_dir, const char *filename, const char *buf)
+{
+ int fd;
+ char *cgroup_new_dir;
+ char knob_path[PATH_MAX];
+
+ cgroup_new_dir = tst_cgroup_get_path(cgroup_dir);
+
+ /*
+ * try either '/dev/cpuset/XXXX' or '/dev/cpuset/cpuset.XXXX'
+ * please see Documentation/cgroups/cpusets.txt from kernel src
+ * for details
+ */
+ sprintf(knob_path, "%s/%s", cgroup_new_dir, filename);
+ fd = open(knob_path, O_WRONLY);
+ if (fd == -1) {
+ if (errno == ENOENT) {
+ sprintf(knob_path, "%s/cpuset.%s", cgroup_new_dir, filename);
+ fd = SAFE_OPEN(knob_path, O_WRONLY);
+ } else
+ tst_brk(TBROK | TERRNO, "open %s", knob_path);
+ }
+
+ SAFE_WRITE(1, fd, buf, strlen(buf));
+
+ close(fd);
+}
diff --git a/kernel/tests/lib/tst_checkpoint.c b/kernel/tests/lib/tst_checkpoint.c
new file mode 100644
index 0000000..5e5b114
--- /dev/null
+++ b/kernel/tests/lib/tst_checkpoint.c
@@ -0,0 +1,164 @@
+/*
+ * Copyright (C) 2015 Cyril Hrubis <chrubis@suse.cz>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it is
+ * free of the rightful claim of any third person regarding infringement
+ * or the like. Any license provided herein, whether implied or
+ * otherwise, applies only to this software file. Patent licenses, if
+ * any, provided herein do not apply to combinations of this program with
+ * other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdint.h>
+#include <limits.h>
+#include <errno.h>
+#include <sys/syscall.h>
+#include <linux/futex.h>
+
+#include "test.h"
+#include "safe_macros.h"
+#include "lapi/futex.h"
+
+#define DEFAULT_MSEC_TIMEOUT 10000
+
+futex_t *tst_futexes;
+unsigned int tst_max_futexes;
+
+void tst_checkpoint_init(const char *file, const int lineno,
+ void (*cleanup_fn)(void))
+{
+ int fd;
+ unsigned int page_size;
+
+ if (tst_futexes) {
+ tst_brkm(TBROK, cleanup_fn,
+ "%s: %d checkpoints already initialized",
+ file, lineno);
+ return;
+ }
+
+ /*
+ * The parent test process is responsible for creating the temporary
+ * directory and therefore must pass non-zero cleanup (to remove the
+ * directory if something went wrong).
+ *
+ * We cannot do this check unconditionally because if we need to init
+ * the checkpoint from a binary that was started by exec() the
+ * tst_tmpdir_created() will return false because the tmpdir was
+ * created by parent. In this case we expect the subprogram can call
+ * the init as a first function with NULL as cleanup function.
+ */
+ if (cleanup_fn && !tst_tmpdir_created()) {
+ tst_brkm(TBROK, cleanup_fn,
+ "%s:%d You have to create test temporary directory "
+ "first (call tst_tmpdir())", file, lineno);
+ return;
+ }
+
+ page_size = getpagesize();
+
+ fd = SAFE_OPEN(cleanup_fn, "checkpoint_futex_base_file",
+ O_RDWR | O_CREAT, 0666);
+
+ SAFE_FTRUNCATE(cleanup_fn, fd, page_size);
+
+ tst_futexes = SAFE_MMAP(cleanup_fn, NULL, page_size,
+ PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+
+ tst_max_futexes = page_size / sizeof(uint32_t);
+
+ SAFE_CLOSE(cleanup_fn, fd);
+}
+
+int tst_checkpoint_wait(unsigned int id, unsigned int msec_timeout)
+{
+ struct timespec timeout;
+ int ret;
+
+ if (id >= tst_max_futexes) {
+ errno = EOVERFLOW;
+ return -1;
+ }
+
+ timeout.tv_sec = msec_timeout/1000;
+ timeout.tv_nsec = (msec_timeout%1000) * 1000000;
+
+ do {
+ ret = syscall(SYS_futex, &tst_futexes[id], FUTEX_WAIT,
+ tst_futexes[id], &timeout);
+ } while (ret == -1 && errno == EINTR);
+
+ return ret;
+}
+
+int tst_checkpoint_wake(unsigned int id, unsigned int nr_wake,
+ unsigned int msec_timeout)
+{
+ unsigned int msecs = 0, waked = 0;
+
+ if (id >= tst_max_futexes) {
+ errno = EOVERFLOW;
+ return -1;
+ }
+
+ for (;;) {
+ waked += syscall(SYS_futex, &tst_futexes[id], FUTEX_WAKE,
+ INT_MAX, NULL);
+
+ if (waked == nr_wake)
+ break;
+
+ usleep(1000);
+ msecs++;
+
+ if (msecs >= msec_timeout) {
+ errno = ETIMEDOUT;
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+void tst_safe_checkpoint_wait(const char *file, const int lineno,
+ void (*cleanup_fn)(void), unsigned int id,
+ unsigned int msec_timeout)
+{
+ int ret;
+
+ if (!msec_timeout)
+ msec_timeout = DEFAULT_MSEC_TIMEOUT;
+
+ ret = tst_checkpoint_wait(id, msec_timeout);
+
+ if (ret) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: tst_checkpoint_wait(%u, %i)",
+ file, lineno, id, msec_timeout);
+ }
+}
+
+void tst_safe_checkpoint_wake(const char *file, const int lineno,
+ void (*cleanup_fn)(void), unsigned int id,
+ unsigned int nr_wake)
+{
+ int ret = tst_checkpoint_wake(id, nr_wake, DEFAULT_MSEC_TIMEOUT);
+
+ if (ret) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: tst_checkpoint_wake(%u, %u, %i)",
+ file, lineno, id, nr_wake, DEFAULT_MSEC_TIMEOUT);
+ }
+}
diff --git a/kernel/tests/lib/tst_checksum.c b/kernel/tests/lib/tst_checksum.c
new file mode 100644
index 0000000..903bf3d
--- /dev/null
+++ b/kernel/tests/lib/tst_checksum.c
@@ -0,0 +1,81 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* Copyright (c) 2018 Oracle and/or its affiliates. All Rights Reserved. */
+
+#include "tst_checksum.h"
+
+static const uint32_t crc32c_table[] = {
+ 0x00000000, 0xf26b8303, 0xe13b70f7, 0x1350f3f4,
+ 0xc79a971f, 0x35f1141c, 0x26a1e7e8, 0xd4ca64eb,
+ 0x8ad958cf, 0x78b2dbcc, 0x6be22838, 0x9989ab3b,
+ 0x4d43cfd0, 0xbf284cd3, 0xac78bf27, 0x5e133c24,
+ 0x105ec76f, 0xe235446c, 0xf165b798, 0x030e349b,
+ 0xd7c45070, 0x25afd373, 0x36ff2087, 0xc494a384,
+ 0x9a879fa0, 0x68ec1ca3, 0x7bbcef57, 0x89d76c54,
+ 0x5d1d08bf, 0xaf768bbc, 0xbc267848, 0x4e4dfb4b,
+ 0x20bd8ede, 0xd2d60ddd, 0xc186fe29, 0x33ed7d2a,
+ 0xe72719c1, 0x154c9ac2, 0x061c6936, 0xf477ea35,
+ 0xaa64d611, 0x580f5512, 0x4b5fa6e6, 0xb93425e5,
+ 0x6dfe410e, 0x9f95c20d, 0x8cc531f9, 0x7eaeb2fa,
+ 0x30e349b1, 0xc288cab2, 0xd1d83946, 0x23b3ba45,
+ 0xf779deae, 0x05125dad, 0x1642ae59, 0xe4292d5a,
+ 0xba3a117e, 0x4851927d, 0x5b016189, 0xa96ae28a,
+ 0x7da08661, 0x8fcb0562, 0x9c9bf696, 0x6ef07595,
+ 0x417b1dbc, 0xb3109ebf, 0xa0406d4b, 0x522bee48,
+ 0x86e18aa3, 0x748a09a0, 0x67dafa54, 0x95b17957,
+ 0xcba24573, 0x39c9c670, 0x2a993584, 0xd8f2b687,
+ 0x0c38d26c, 0xfe53516f, 0xed03a29b, 0x1f682198,
+ 0x5125dad3, 0xa34e59d0, 0xb01eaa24, 0x42752927,
+ 0x96bf4dcc, 0x64d4cecf, 0x77843d3b, 0x85efbe38,
+ 0xdbfc821c, 0x2997011f, 0x3ac7f2eb, 0xc8ac71e8,
+ 0x1c661503, 0xee0d9600, 0xfd5d65f4, 0x0f36e6f7,
+ 0x61c69362, 0x93ad1061, 0x80fde395, 0x72966096,
+ 0xa65c047d, 0x5437877e, 0x4767748a, 0xb50cf789,
+ 0xeb1fcbad, 0x197448ae, 0x0a24bb5a, 0xf84f3859,
+ 0x2c855cb2, 0xdeeedfb1, 0xcdbe2c45, 0x3fd5af46,
+ 0x7198540d, 0x83f3d70e, 0x90a324fa, 0x62c8a7f9,
+ 0xb602c312, 0x44694011, 0x5739b3e5, 0xa55230e6,
+ 0xfb410cc2, 0x092a8fc1, 0x1a7a7c35, 0xe811ff36,
+ 0x3cdb9bdd, 0xceb018de, 0xdde0eb2a, 0x2f8b6829,
+ 0x82f63b78, 0x709db87b, 0x63cd4b8f, 0x91a6c88c,
+ 0x456cac67, 0xb7072f64, 0xa457dc90, 0x563c5f93,
+ 0x082f63b7, 0xfa44e0b4, 0xe9141340, 0x1b7f9043,
+ 0xcfb5f4a8, 0x3dde77ab, 0x2e8e845f, 0xdce5075c,
+ 0x92a8fc17, 0x60c37f14, 0x73938ce0, 0x81f80fe3,
+ 0x55326b08, 0xa759e80b, 0xb4091bff, 0x466298fc,
+ 0x1871a4d8, 0xea1a27db, 0xf94ad42f, 0x0b21572c,
+ 0xdfeb33c7, 0x2d80b0c4, 0x3ed04330, 0xccbbc033,
+ 0xa24bb5a6, 0x502036a5, 0x4370c551, 0xb11b4652,
+ 0x65d122b9, 0x97baa1ba, 0x84ea524e, 0x7681d14d,
+ 0x2892ed69, 0xdaf96e6a, 0xc9a99d9e, 0x3bc21e9d,
+ 0xef087a76, 0x1d63f975, 0x0e330a81, 0xfc588982,
+ 0xb21572c9, 0x407ef1ca, 0x532e023e, 0xa145813d,
+ 0x758fe5d6, 0x87e466d5, 0x94b49521, 0x66df1622,
+ 0x38cc2a06, 0xcaa7a905, 0xd9f75af1, 0x2b9cd9f2,
+ 0xff56bd19, 0x0d3d3e1a, 0x1e6dcdee, 0xec064eed,
+ 0xc38d26c4, 0x31e6a5c7, 0x22b65633, 0xd0ddd530,
+ 0x0417b1db, 0xf67c32d8, 0xe52cc12c, 0x1747422f,
+ 0x49547e0b, 0xbb3ffd08, 0xa86f0efc, 0x5a048dff,
+ 0x8ecee914, 0x7ca56a17, 0x6ff599e3, 0x9d9e1ae0,
+ 0xd3d3e1ab, 0x21b862a8, 0x32e8915c, 0xc083125f,
+ 0x144976b4, 0xe622f5b7, 0xf5720643, 0x07198540,
+ 0x590ab964, 0xab613a67, 0xb831c993, 0x4a5a4a90,
+ 0x9e902e7b, 0x6cfbad78, 0x7fab5e8c, 0x8dc0dd8f,
+ 0xe330a81a, 0x115b2b19, 0x020bd8ed, 0xf0605bee,
+ 0x24aa3f05, 0xd6c1bc06, 0xc5914ff2, 0x37faccf1,
+ 0x69e9f0d5, 0x9b8273d6, 0x88d28022, 0x7ab90321,
+ 0xae7367ca, 0x5c18e4c9, 0x4f48173d, 0xbd23943e,
+ 0xf36e6f75, 0x0105ec76, 0x12551f82, 0xe03e9c81,
+ 0x34f4f86a, 0xc69f7b69, 0xd5cf889d, 0x27a40b9e,
+ 0x79b737ba, 0x8bdcb4b9, 0x988c474d, 0x6ae7c44e,
+ 0xbe2da0a5, 0x4c4623a6, 0x5f16d052, 0xad7d5351,
+};
+
+uint32_t tst_crc32c(uint8_t *buf, size_t buf_len)
+{
+ uint32_t crc = 0xffffffff;
+
+ while (buf_len--)
+ crc = crc32c_table[(crc ^ (*buf++)) & 0xff] ^ (crc >> 8);
+
+ return ~crc;
+}
diff --git a/kernel/tests/lib/tst_clocks.c b/kernel/tests/lib/tst_clocks.c
new file mode 100644
index 0000000..cdcb9fc
--- /dev/null
+++ b/kernel/tests/lib/tst_clocks.c
@@ -0,0 +1,144 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#include <time.h>
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+#include "tst_timer.h"
+#include "tst_clocks.h"
+#include "lapi/syscalls.h"
+#include "lapi/posix_clocks.h"
+
+typedef int (*mysyscall)(clockid_t clk_id, void *ts);
+
+int syscall_supported_by_kernel(long sysnr)
+{
+ int ret;
+
+ ret = syscall(sysnr, 0, NULL);
+ if (ret == -1 && errno == ENOSYS)
+ return 0;
+
+ return 1;
+}
+
+int tst_clock_getres(clockid_t clk_id, struct timespec *res)
+{
+ static struct tst_ts tts = { 0, };
+ static mysyscall func;
+ int ret;
+
+#if (__NR_clock_getres_time64 != __LTP__NR_INVALID_SYSCALL)
+ if (!func && syscall_supported_by_kernel(__NR_clock_getres_time64)) {
+ func = sys_clock_getres64;
+ tts.type = TST_KERN_TIMESPEC;
+ }
+#endif
+
+ if (!func && syscall_supported_by_kernel(__NR_clock_getres)) {
+ func = sys_clock_getres;
+ tts.type = TST_KERN_OLD_TIMESPEC;
+ }
+
+ if (!func) {
+ tst_res(TCONF, "clock_getres() not available");
+ errno = ENOSYS;
+ return -1;
+ }
+
+ ret = func(clk_id, tst_ts_get(&tts));
+ res->tv_sec = tst_ts_get_sec(tts);
+ res->tv_nsec = tst_ts_get_nsec(tts);
+ return ret;
+}
+
+int tst_clock_gettime(clockid_t clk_id, struct timespec *ts)
+{
+ static struct tst_ts tts = { 0, };
+ static mysyscall func;
+ int ret;
+
+#if (__NR_clock_gettime64 != __LTP__NR_INVALID_SYSCALL)
+ if (!func && syscall_supported_by_kernel(__NR_clock_gettime64)) {
+ func = sys_clock_gettime64;
+ tts.type = TST_KERN_TIMESPEC;
+ }
+#endif
+
+ if (!func && syscall_supported_by_kernel(__NR_clock_gettime)) {
+ func = sys_clock_gettime;
+ tts.type = TST_KERN_OLD_TIMESPEC;
+ }
+
+ if (!func) {
+ tst_res(TCONF, "clock_gettime() not available");
+ errno = ENOSYS;
+ return -1;
+ }
+
+ ret = func(clk_id, tst_ts_get(&tts));
+ ts->tv_sec = tst_ts_get_sec(tts);
+ ts->tv_nsec = tst_ts_get_nsec(tts);
+ return ret;
+}
+
+int tst_clock_settime(clockid_t clk_id, struct timespec *ts)
+{
+ static struct tst_ts tts = { 0, };
+ static mysyscall func;
+
+#if (__NR_clock_settime64 != __LTP__NR_INVALID_SYSCALL)
+ if (!func && syscall_supported_by_kernel(__NR_clock_settime64)) {
+ func = sys_clock_settime64;
+ tts.type = TST_KERN_TIMESPEC;
+ }
+#endif
+
+ if (!func && syscall_supported_by_kernel(__NR_clock_settime)) {
+ func = sys_clock_settime;
+ tts.type = TST_KERN_OLD_TIMESPEC;
+ }
+
+ if (!func) {
+ tst_res(TCONF, "clock_settime() not available");
+ errno = ENOSYS;
+ return -1;
+ }
+
+ tst_ts_set_sec(&tts, ts->tv_sec);
+ tst_ts_set_nsec(&tts, ts->tv_nsec);
+ return func(clk_id, tst_ts_get(&tts));
+}
+
+const char *tst_clock_name(clockid_t clk_id)
+{
+ switch (clk_id) {
+ case CLOCK_REALTIME:
+ return "CLOCK_REALTIME";
+ case CLOCK_MONOTONIC:
+ return "CLOCK_MONOTONIC";
+ case CLOCK_PROCESS_CPUTIME_ID:
+ return "CLOCK_PROCESS_CPUTIME_ID";
+ case CLOCK_THREAD_CPUTIME_ID:
+ return "CLOCK_THREAD_CPUTIME_ID";
+ case CLOCK_MONOTONIC_RAW:
+ return "CLOCK_MONOTONIC_RAW";
+ case CLOCK_REALTIME_COARSE:
+ return "CLOCK_REALTIME_COARSE";
+ case CLOCK_MONOTONIC_COARSE:
+ return "CLOCK_MONOTONIC_COARSE";
+ case CLOCK_BOOTTIME:
+ return "CLOCK_BOOTTIME";
+ case CLOCK_REALTIME_ALARM:
+ return "CLOCK_REALTIME_ALARM";
+ case CLOCK_BOOTTIME_ALARM:
+ return "CLOCK_BOOTTIME_ALARM";
+ case CLOCK_TAI:
+ return "CLOCK_TAI";
+ default:
+ return "INVALID/UNKNOWN CLOCK";
+ }
+}
diff --git a/kernel/tests/lib/tst_cmd.c b/kernel/tests/lib/tst_cmd.c
new file mode 100644
index 0000000..7446249
--- /dev/null
+++ b/kernel/tests/lib/tst_cmd.c
@@ -0,0 +1,178 @@
+/*
+ * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
+ * Copyright (c) 2020 Petr Vorel <pvorel@suse.cz>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author: Alexey Kodanev <alexey.kodanev@oracle.com>
+ */
+
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <signal.h>
+#include "test.h"
+#include "tst_cmd.h"
+
+#define OPEN_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
+#define OPEN_FLAGS (O_WRONLY | O_APPEND | O_CREAT)
+
+int tst_cmd_fds_(void (cleanup_fn)(void),
+ const char *const argv[],
+ int stdout_fd,
+ int stderr_fd,
+ enum tst_cmd_flags flags)
+{
+ int rc;
+
+ if (argv == NULL || argv[0] == NULL) {
+ tst_brkm(TBROK, cleanup_fn,
+ "argument list is empty at %s:%d", __FILE__, __LINE__);
+ return -1;
+ }
+
+ /*
+ * The tst_sig() install poisoned signal handlers for all signals the
+ * test is not expected to get.
+ *
+ * So we temporarily disable the handler for sigchild we get after our
+ * child exits so that we don't have to disable it in each test that
+ * uses this interface.
+ */
+ void *old_handler = signal(SIGCHLD, SIG_DFL);
+
+ char path[PATH_MAX];
+
+ if (tst_get_path(argv[0], path, sizeof(path))) {
+ if (flags & TST_CMD_TCONF_ON_MISSING)
+ tst_brkm(TCONF, cleanup_fn, "Couldn't find '%s' in $PATH at %s:%d", argv[0],
+ __FILE__, __LINE__);
+ else
+ return 255;
+ }
+
+ pid_t pid = vfork();
+ if (pid == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn, "vfork failed at %s:%d",
+ __FILE__, __LINE__);
+ return -1;
+ }
+ if (!pid) {
+ /* redirecting stdout and stderr if needed */
+ if (stdout_fd != -1) {
+ close(STDOUT_FILENO);
+ dup2(stdout_fd, STDOUT_FILENO);
+ }
+
+ if (stderr_fd != -1) {
+ close(STDERR_FILENO);
+ dup2(stderr_fd, STDERR_FILENO);
+ }
+
+ execvp(argv[0], (char *const *)argv);
+ _exit(254);
+ }
+
+ int ret = -1;
+ if (waitpid(pid, &ret, 0) != pid) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn, "waitpid failed at %s:%d",
+ __FILE__, __LINE__);
+ return -1;
+ }
+
+ signal(SIGCHLD, old_handler);
+
+ if (!WIFEXITED(ret)) {
+ tst_brkm(TBROK, cleanup_fn, "failed to exec cmd '%s' at %s:%d",
+ argv[0], __FILE__, __LINE__);
+ return -1;
+ }
+
+ rc = WEXITSTATUS(ret);
+
+ if (!(flags & TST_CMD_PASS_RETVAL) && rc) {
+ tst_brkm(TBROK, cleanup_fn,
+ "'%s' exited with a non-zero code %d at %s:%d",
+ argv[0], rc, __FILE__, __LINE__);
+ return -1;
+ }
+
+ return rc;
+}
+
+int tst_cmd_(void (cleanup_fn)(void),
+ const char *const argv[],
+ const char *stdout_path,
+ const char *stderr_path,
+ enum tst_cmd_flags flags)
+{
+ int stdout_fd = -1;
+ int stderr_fd = -1;
+ int rc;
+
+ if (stdout_path != NULL) {
+ stdout_fd = open(stdout_path,
+ OPEN_FLAGS, OPEN_MODE);
+
+ if (stdout_fd == -1)
+ tst_resm(TWARN | TERRNO,
+ "open() on %s failed at %s:%d",
+ stdout_path, __FILE__, __LINE__);
+ }
+
+ if (stderr_path != NULL) {
+ stderr_fd = open(stderr_path,
+ OPEN_FLAGS, OPEN_MODE);
+
+ if (stderr_fd == -1)
+ tst_resm(TWARN | TERRNO,
+ "open() on %s failed at %s:%d",
+ stderr_path, __FILE__, __LINE__);
+ }
+
+ rc = tst_cmd_fds(cleanup_fn, argv, stdout_fd, stderr_fd, flags);
+
+ if ((stdout_fd != -1) && (close(stdout_fd) == -1))
+ tst_resm(TWARN | TERRNO,
+ "close() on %s failed at %s:%d",
+ stdout_path, __FILE__, __LINE__);
+
+ if ((stderr_fd != -1) && (close(stderr_fd) == -1))
+ tst_resm(TWARN | TERRNO,
+ "close() on %s failed at %s:%d",
+ stderr_path, __FILE__, __LINE__);
+
+ return rc;
+}
+
+int tst_system(const char *command)
+{
+ int ret = 0;
+
+ /*
+ *Temporarily disable SIGCHLD of user defined handler, so the
+ *system(3) function will not cause unexpected SIGCHLD signal
+ *callback function for test cases.
+ */
+ void *old_handler = signal(SIGCHLD, SIG_DFL);
+
+ ret = system(command);
+
+ signal(SIGCHLD, old_handler);
+ return ret;
+}
diff --git a/kernel/tests/lib/tst_coredump.c b/kernel/tests/lib/tst_coredump.c
new file mode 100644
index 0000000..83aa2c3
--- /dev/null
+++ b/kernel/tests/lib/tst_coredump.c
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Red Hat, Inc.
+ */
+
+#define TST_NO_DEFAULT_MAIN
+
+#include <sys/time.h>
+#include <sys/resource.h>
+
+#include "tst_test.h"
+#include "tst_coredump.h"
+
+void tst_no_corefile(int verbose)
+{
+ struct rlimit new_r, old_r;
+
+ SAFE_GETRLIMIT(RLIMIT_CORE, &old_r);
+ if (old_r.rlim_max >= 1 || geteuid() == 0) {
+ /*
+ * 1 is a special value, that disables core-to-pipe.
+ * At the same time it is small enough value for
+ * core-to-file, so it skips creating cores as well.
+ */
+ new_r.rlim_cur = 1;
+ new_r.rlim_max = 1;
+ SAFE_SETRLIMIT(RLIMIT_CORE, &new_r);
+
+ if (verbose) {
+ tst_res(TINFO,
+ "Avoid dumping corefile for process(pid=%d)",
+ getpid());
+ }
+ }
+}
diff --git a/kernel/tests/lib/tst_cpu.c b/kernel/tests/lib/tst_cpu.c
new file mode 100644
index 0000000..033155e
--- /dev/null
+++ b/kernel/tests/lib/tst_cpu.c
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2012 Fujitsu Ltd.
+ * Author: Wanlong Gao <gaowanlong@cn.fujitsu.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include "test.h"
+#include "safe_macros.h"
+
+long tst_ncpus(void)
+{
+ long ncpus = -1;
+#ifdef _SC_NPROCESSORS_ONLN
+ ncpus = SAFE_SYSCONF(NULL, _SC_NPROCESSORS_ONLN);
+#else
+ tst_brkm(TBROK, NULL, "could not determine number of CPUs online");
+#endif
+ return ncpus;
+}
+
+long tst_ncpus_conf(void)
+{
+ long ncpus_conf = -1;
+#ifdef _SC_NPROCESSORS_CONF
+ ncpus_conf = SAFE_SYSCONF(NULL, _SC_NPROCESSORS_CONF);
+#else
+ tst_brkm(TBROK, NULL, "could not determine number of CPUs configured");
+#endif
+ return ncpus_conf;
+}
+
+#define KERNEL_MAX "/sys/devices/system/cpu/kernel_max"
+
+long tst_ncpus_max(void)
+{
+ long ncpus_max = -1;
+ struct stat buf;
+
+ /* sched_getaffinity() and sched_setaffinity() cares about number of
+ * possible CPUs the OS or hardware can support, which can be larger
+ * than what sysconf(_SC_NPROCESSORS_CONF) currently provides
+ * (by enumarating /sys/devices/system/cpu/cpu* entries).
+ *
+ * Use /sys/devices/system/cpu/kernel_max, if available. This
+ * represents NR_CPUS-1, a compile time option which specifies
+ * "maximum number of CPUs which this kernel will support".
+ * This should provide cpu mask size large enough for any purposes. */
+ if (stat(KERNEL_MAX, &buf) == 0) {
+ SAFE_FILE_SCANF(NULL, KERNEL_MAX, "%ld", &ncpus_max);
+ /* this is maximum CPU index allowed by the kernel
+ * configuration, so # of cpus allowed by config is +1 */
+ ncpus_max++;
+ } else {
+ /* fall back to _SC_NPROCESSORS_CONF */
+ ncpus_max = tst_ncpus_conf();
+ }
+ return ncpus_max;
+}
diff --git a/kernel/tests/lib/tst_crypto.c b/kernel/tests/lib/tst_crypto.c
new file mode 100644
index 0000000..685e087
--- /dev/null
+++ b/kernel/tests/lib/tst_crypto.c
@@ -0,0 +1,110 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2018 Richard Palethorpe <rpalethorpe@suse.com>
+ * Nicolai Stange <nstange@suse.de>
+ */
+
+#include <errno.h>
+#include <stdio.h>
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+#include "tst_crypto.h"
+#include "tst_netlink.h"
+
+void tst_crypto_open(struct tst_crypto_session *ses)
+{
+ TEST(socket(AF_NETLINK, SOCK_DGRAM, NETLINK_CRYPTO));
+ if (TST_RET < 0 && TST_ERR == EPROTONOSUPPORT)
+ tst_brk(TCONF | TTERRNO, "NETLINK_CRYPTO is probably disabled");
+
+ if (TST_RET < 0) {
+ tst_brk(TBROK | TTERRNO,
+ "socket(AF_NETLINK, SOCK_DGRAM, NETLINK_CRYPTO)");
+ }
+
+ ses->fd = TST_RET;
+ ses->seq_num = 0;
+}
+
+void tst_crypto_close(struct tst_crypto_session *ses)
+{
+ SAFE_CLOSE(ses->fd);
+}
+
+static int tst_crypto_recv_ack(struct tst_crypto_session *ses)
+{
+ uint32_t len;
+ char buf[BUFSIZ];
+ struct nlmsghdr *nh;
+
+ len = SAFE_NETLINK_RECV(ses->fd, buf, sizeof(buf));
+
+ for (nh = (struct nlmsghdr *) buf;
+ NLMSG_OK(nh, len);
+ nh = NLMSG_NEXT(nh, len)) {
+ if (nh->nlmsg_seq != ses->seq_num) {
+ tst_brk(TBROK,
+ "Message out of sequence; type=0%hx, seq_num=%u (not %u)",
+ nh->nlmsg_type, nh->nlmsg_seq, ses->seq_num);
+ }
+
+ /* Acks use the error message type with error number set to
+ * zero. Ofcourse we could also receive an actual error.
+ */
+ if (nh->nlmsg_type == NLMSG_ERROR)
+ return ((struct nlmsgerr *)NLMSG_DATA(nh))->error;
+
+ tst_brk(TBROK, "Unexpected message type; type=0x%hx, seq_num=%u",
+ nh->nlmsg_type, nh->nlmsg_seq);
+ }
+
+ tst_brk(TBROK, "Empty message from netlink socket?");
+
+ return ENODATA;
+}
+
+int tst_crypto_add_alg(struct tst_crypto_session *ses,
+ const struct crypto_user_alg *alg)
+{
+ struct nlmsghdr nh = {
+ .nlmsg_len = sizeof(struct nlmsghdr) + sizeof(*alg),
+ .nlmsg_type = CRYPTO_MSG_NEWALG,
+ .nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK,
+ .nlmsg_seq = ++(ses->seq_num),
+ .nlmsg_pid = 0,
+ };
+
+ SAFE_NETLINK_SEND(ses->fd, &nh, alg);
+
+ return tst_crypto_recv_ack(ses);
+}
+
+int tst_crypto_del_alg(struct tst_crypto_session *ses,
+ const struct crypto_user_alg *alg)
+{
+ unsigned int i = 0;
+ struct nlmsghdr nh = {
+ .nlmsg_len = sizeof(struct nlmsghdr) + sizeof(*alg),
+ .nlmsg_type = CRYPTO_MSG_DELALG,
+ .nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK,
+ .nlmsg_pid = 0,
+ };
+
+ while (1) {
+ nh.nlmsg_seq = ++(ses->seq_num),
+
+ SAFE_NETLINK_SEND(ses->fd, &nh, alg);
+
+ TEST(tst_crypto_recv_ack(ses));
+ if (TST_RET != -EBUSY || i >= ses->retries)
+ break;
+
+ if (usleep(1) && errno != EINTR)
+ tst_brk(TBROK | TERRNO, "usleep(1)");
+
+ ++i;
+ }
+
+ return TST_RET;
+}
diff --git a/kernel/tests/lib/tst_device.c b/kernel/tests/lib/tst_device.c
new file mode 100644
index 0000000..0e98a72
--- /dev/null
+++ b/kernel/tests/lib/tst_device.c
@@ -0,0 +1,531 @@
+/*
+ * Copyright (C) 2014 Cyril Hrubis chrubis@suse.cz
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it is
+ * free of the rightful claim of any third person regarding infringement
+ * or the like. Any license provided herein, whether implied or
+ * otherwise, applies only to this software file. Patent licenses, if
+ * any, provided herein do not apply to combinations of this program with
+ * other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <sys/mount.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <linux/loop.h>
+#include <stdint.h>
+#include <inttypes.h>
+#include <sys/sysmacros.h>
+#include "lapi/syscalls.h"
+#include "test.h"
+#include "safe_macros.h"
+
+#ifndef LOOP_CTL_GET_FREE
+# define LOOP_CTL_GET_FREE 0x4C82
+#endif
+
+#define LOOP_CONTROL_FILE "/dev/loop-control"
+
+#define DEV_FILE "test_dev.img"
+#define DEV_SIZE_MB 256u
+
+static char dev_path[1024];
+static int device_acquired;
+static unsigned long prev_dev_sec_write;
+
+static const char *dev_variants[] = {
+ "/dev/loop%i",
+ "/dev/loop/%i",
+ "/dev/block/loop%i"
+};
+
+static int set_dev_path(int dev, char *path, size_t path_len)
+{
+ unsigned int i;
+ struct stat st;
+
+ for (i = 0; i < ARRAY_SIZE(dev_variants); i++) {
+ snprintf(path, path_len, dev_variants[i], dev);
+
+ if (stat(path, &st) == 0 && S_ISBLK(st.st_mode))
+ return 1;
+ }
+
+ return 0;
+}
+
+int tst_find_free_loopdev(char *path, size_t path_len)
+{
+ int ctl_fd, dev_fd, rc, i;
+ struct loop_info loopinfo;
+ char buf[1024];
+
+ /* since Linux 3.1 */
+ ctl_fd = open(LOOP_CONTROL_FILE, O_RDWR);
+
+ if (ctl_fd > 0) {
+ rc = ioctl(ctl_fd, LOOP_CTL_GET_FREE);
+ close(ctl_fd);
+ if (rc >= 0) {
+ if (path)
+ set_dev_path(rc, path, path_len);
+ tst_resm(TINFO, "Found free device %d '%s'",
+ rc, path ?: "");
+ return rc;
+ }
+ tst_resm(TINFO, "Couldn't find free loop device");
+ return -1;
+ }
+
+ switch (errno) {
+ case ENOENT:
+ break;
+ case EACCES:
+ tst_resm(TINFO | TERRNO,
+ "Not allowed to open " LOOP_CONTROL_FILE ". "
+ "Are you root?");
+ break;
+ default:
+ tst_resm(TBROK | TERRNO, "Failed to open " LOOP_CONTROL_FILE);
+ }
+
+ /*
+ * Older way is to iterate over /dev/loop%i and /dev/loop/%i and try
+ * LOOP_GET_STATUS ioctl() which fails for free loop devices.
+ */
+ for (i = 0; i < 256; i++) {
+
+ if (!set_dev_path(i, buf, sizeof(buf)))
+ continue;
+
+ dev_fd = open(buf, O_RDONLY);
+
+ if (dev_fd < 0)
+ continue;
+
+ if (ioctl(dev_fd, LOOP_GET_STATUS, &loopinfo) == 0) {
+ tst_resm(TINFO, "Device '%s' in use", buf);
+ } else {
+ if (errno != ENXIO)
+ continue;
+ tst_resm(TINFO, "Found free device '%s'", buf);
+ close(dev_fd);
+ if (path != NULL) {
+ strncpy(path, buf, path_len);
+ path[path_len-1] = '\0';
+ }
+ return i;
+ }
+
+ close(dev_fd);
+ }
+
+ tst_resm(TINFO, "No free devices found");
+
+ return -1;
+}
+
+int tst_attach_device(const char *dev, const char *file)
+{
+ int dev_fd, file_fd;
+ struct loop_info loopinfo;
+
+ dev_fd = open(dev, O_RDWR);
+ if (dev_fd < 0) {
+ tst_resm(TWARN | TERRNO, "open('%s', O_RDWR) failed", dev);
+ return 1;
+ }
+
+ file_fd = open(file, O_RDWR);
+ if (file_fd < 0) {
+ tst_resm(TWARN | TERRNO, "open('%s', O_RDWR) failed", file);
+ close(dev_fd);
+ return 1;
+ }
+
+ if (ioctl(dev_fd, LOOP_SET_FD, file_fd) < 0) {
+ close(dev_fd);
+ close(file_fd);
+ tst_resm(TWARN | TERRNO, "ioctl(%s, LOOP_SET_FD, %s) failed",
+ dev, file);
+ return 1;
+ }
+
+ /* Old mkfs.btrfs use LOOP_GET_STATUS instead of backing_file to get
+ * associated filename, so we need to set up the device by calling
+ * LOOP_SET_FD and LOOP_SET_STATUS.
+ */
+ memset(&loopinfo, 0, sizeof(loopinfo));
+ strcpy(loopinfo.lo_name, file);
+
+ if (ioctl(dev_fd, LOOP_SET_STATUS, &loopinfo)) {
+ close(dev_fd);
+ close(file_fd);
+ tst_resm(TWARN | TERRNO,
+ "ioctl(%s, LOOP_SET_STATUS, %s) failed", dev, file);
+ return 1;
+ }
+
+ close(dev_fd);
+ close(file_fd);
+ return 0;
+}
+
+int tst_detach_device_by_fd(const char *dev, int dev_fd)
+{
+ int ret, i;
+
+ /* keep trying to clear LOOPDEV until we get ENXIO, a quick succession
+ * of attach/detach might not give udev enough time to complete */
+ for (i = 0; i < 40; i++) {
+ ret = ioctl(dev_fd, LOOP_CLR_FD, 0);
+
+ if (ret && (errno == ENXIO))
+ return 0;
+
+ if (ret && (errno != EBUSY)) {
+ tst_resm(TWARN,
+ "ioctl(%s, LOOP_CLR_FD, 0) unexpectedly failed with: %s",
+ dev, tst_strerrno(errno));
+ return 1;
+ }
+
+ usleep(50000);
+ }
+
+ tst_resm(TWARN,
+ "ioctl(%s, LOOP_CLR_FD, 0) no ENXIO for too long", dev);
+ return 1;
+}
+
+int tst_detach_device(const char *dev)
+{
+ int dev_fd, ret;
+
+ dev_fd = open(dev, O_RDONLY);
+ if (dev_fd < 0) {
+ tst_resm(TWARN | TERRNO, "open(%s) failed", dev);
+ return 1;
+ }
+
+ ret = tst_detach_device_by_fd(dev, dev_fd);
+ close(dev_fd);
+ return ret;
+}
+
+int tst_dev_sync(int fd)
+{
+ return syscall(__NR_syncfs, fd);
+}
+
+const char *tst_acquire_loop_device(unsigned int size, const char *filename)
+{
+ unsigned int acq_dev_size = MAX(size, DEV_SIZE_MB);
+
+ if (tst_prealloc_file(filename, 1024 * 1024, acq_dev_size)) {
+ tst_resm(TWARN | TERRNO, "Failed to create %s", filename);
+ return NULL;
+ }
+
+ if (tst_find_free_loopdev(dev_path, sizeof(dev_path)) == -1)
+ return NULL;
+
+ if (tst_attach_device(dev_path, filename))
+ return NULL;
+
+ return dev_path;
+}
+
+const char *tst_acquire_device__(unsigned int size)
+{
+ int fd;
+ const char *dev;
+ struct stat st;
+ unsigned int acq_dev_size;
+ uint64_t ltp_dev_size;
+
+ acq_dev_size = MAX(size, DEV_SIZE_MB);
+
+ dev = getenv("LTP_DEV");
+
+ if (dev) {
+ tst_resm(TINFO, "Using test device LTP_DEV='%s'", dev);
+
+ if (stat(dev, &st)) {
+ tst_resm(TWARN | TERRNO, "stat() failed");
+ return NULL;
+ }
+
+ if (!S_ISBLK(st.st_mode)) {
+ tst_resm(TWARN, "%s is not a block device", dev);
+ return NULL;
+ }
+
+ fd = open(dev, O_RDONLY);
+ if (fd < 0) {
+ tst_resm(TWARN | TERRNO,
+ "open(%s, O_RDONLY) failed", dev);
+ return NULL;
+ }
+
+ if (ioctl(fd, BLKGETSIZE64, &ltp_dev_size)) {
+ tst_resm(TWARN | TERRNO,
+ "ioctl(fd, BLKGETSIZE64, ...) failed");
+ close(fd);
+ return NULL;
+ }
+
+ if (close(fd)) {
+ tst_resm(TWARN | TERRNO,
+ "close(fd) failed");
+ return NULL;
+ }
+
+ ltp_dev_size = ltp_dev_size/1024/1024;
+
+ if (acq_dev_size <= ltp_dev_size)
+ return dev;
+
+ tst_resm(TINFO, "Skipping $LTP_DEV size %"PRIu64"MB, requested size %uMB",
+ ltp_dev_size, acq_dev_size);
+ }
+
+ dev = tst_acquire_loop_device(acq_dev_size, DEV_FILE);
+
+ if (dev)
+ device_acquired = 1;
+
+ return dev;
+}
+
+const char *tst_acquire_device_(void (cleanup_fn)(void), unsigned int size)
+{
+ const char *device;
+
+ if (device_acquired) {
+ tst_brkm(TBROK, cleanup_fn, "Device already acquired");
+ return NULL;
+ }
+
+ if (!tst_tmpdir_created()) {
+ tst_brkm(TBROK, cleanup_fn,
+ "Cannot acquire device without tmpdir() created");
+ return NULL;
+ }
+
+ device = tst_acquire_device__(size);
+
+ if (!device) {
+ tst_brkm(TBROK, cleanup_fn, "Failed to acquire device");
+ return NULL;
+ }
+
+ return device;
+}
+
+int tst_release_device(const char *dev)
+{
+ int ret;
+
+ if (!device_acquired)
+ return 0;
+
+ /*
+ * Loop device was created -> we need to detach it.
+ *
+ * The file image is deleted in tst_rmdir();
+ */
+ ret = tst_detach_device(dev);
+
+ device_acquired = 0;
+
+ return ret;
+}
+
+int tst_clear_device(const char *dev)
+{
+ if (tst_fill_file(dev, 0, 1024, 512)) {
+ tst_resm(TWARN, "Failed to clear 512k block on %s", dev);
+ return 1;
+ }
+
+ return 0;
+}
+
+int tst_umount(const char *path)
+{
+ int err, ret, i;
+
+ for (i = 0; i < 50; i++) {
+ ret = umount(path);
+ err = errno;
+
+ if (!ret)
+ return 0;
+
+ if (err != EBUSY) {
+ tst_resm(TWARN, "umount('%s') failed with %s",
+ path, tst_strerrno(err));
+ errno = err;
+ return ret;
+ }
+
+ tst_resm(TINFO, "umount('%s') failed with %s, try %2i...",
+ path, tst_strerrno(err), i+1);
+
+ if (i == 0) {
+ tst_resm(TINFO, "Likely gvfsd-trash is probing newly "
+ "mounted fs, kill it to speed up tests.");
+ }
+
+ usleep(100000);
+ }
+
+ tst_resm(TWARN, "Failed to umount('%s') after 50 retries", path);
+ errno = err;
+ return -1;
+}
+
+int tst_is_mounted(const char *path)
+{
+ char line[PATH_MAX];
+ FILE *file;
+ int ret = 0;
+
+ file = SAFE_FOPEN(NULL, "/proc/mounts", "r");
+
+ while (fgets(line, sizeof(line), file)) {
+ if (strstr(line, path) != NULL) {
+ ret = 1;
+ break;
+ }
+ }
+
+ SAFE_FCLOSE(NULL, file);
+
+ if (!ret)
+ tst_resm(TINFO, "No device is mounted at %s", path);
+
+ return ret;
+}
+
+int tst_is_mounted_at_tmpdir(const char *path)
+{
+ char cdir[PATH_MAX], mpath[PATH_MAX];
+ int ret;
+
+ if (!getcwd(cdir, PATH_MAX)) {
+ tst_resm(TWARN | TERRNO, "Failed to find current directory");
+ return 0;
+ }
+
+ ret = snprintf(mpath, PATH_MAX, "%s/%s", cdir, path);
+ if (ret < 0 || ret >= PATH_MAX) {
+ tst_resm(TWARN | TERRNO,
+ "snprintf() should have returned %d instead of %d",
+ PATH_MAX, ret);
+ return 0;
+ }
+
+ return tst_is_mounted(mpath);
+}
+
+int find_stat_file(const char *dev, char *path, size_t path_len)
+{
+ const char *devname = strrchr(dev, '/') + 1;
+
+ snprintf(path, path_len, "/sys/block/%s/stat", devname);
+
+ if (!access(path, F_OK))
+ return 1;
+
+ DIR *dir = SAFE_OPENDIR(NULL, "/sys/block/");
+ struct dirent *ent;
+
+ while ((ent = readdir(dir))) {
+ snprintf(path, path_len, "/sys/block/%s/%s/stat", ent->d_name, devname);
+
+ if (!access(path, F_OK)) {
+ SAFE_CLOSEDIR(NULL, dir);
+ return 1;
+ }
+ }
+
+ SAFE_CLOSEDIR(NULL, dir);
+ return 0;
+}
+
+unsigned long tst_dev_bytes_written(const char *dev)
+{
+ unsigned long dev_sec_write = 0, dev_bytes_written, io_ticks = 0;
+ char dev_stat_path[1024];
+
+ if (!find_stat_file(dev, dev_stat_path, sizeof(dev_stat_path)))
+ tst_brkm(TCONF, NULL, "Test device stat file: %s not found",
+ dev_stat_path);
+
+ SAFE_FILE_SCANF(NULL, dev_stat_path,
+ "%*s %*s %*s %*s %*s %*s %lu %*s %*s %lu",
+ &dev_sec_write, &io_ticks);
+
+ if (!io_ticks)
+ tst_brkm(TCONF, NULL, "Test device stat file: %s broken",
+ dev_stat_path);
+
+ dev_bytes_written = (dev_sec_write - prev_dev_sec_write) * 512;
+
+ prev_dev_sec_write = dev_sec_write;
+
+ return dev_bytes_written;
+}
+
+void tst_find_backing_dev(const char *path, char *dev)
+{
+ char fmt[20];
+ struct stat buf;
+ FILE *file;
+ char line[PATH_MAX];
+ char *pre = NULL;
+ char *next = NULL;
+
+ if (stat(path, &buf) < 0)
+ tst_brkm(TWARN | TERRNO, NULL, "stat() failed");
+
+ snprintf(fmt, sizeof(fmt), "%u:%u", major(buf.st_dev), minor(buf.st_dev));
+ file = SAFE_FOPEN(NULL, "/proc/self/mountinfo", "r");
+
+ while (fgets(line, sizeof(line), file)) {
+ if (strstr(line, fmt) != NULL) {
+ pre = strstr(line, " - ");
+ pre = strtok_r(pre, " ", &next);
+ pre = strtok_r(NULL, " ", &next);
+ pre = strtok_r(NULL, " ", &next);
+ strcpy(dev, pre);
+ break;
+ }
+ }
+
+ SAFE_FCLOSE(NULL, file);
+
+ if (stat(dev, &buf) < 0)
+ tst_brkm(TWARN | TERRNO, NULL, "stat(%s) failed", dev);
+
+ if (S_ISBLK(buf.st_mode) != 1)
+ tst_brkm(TCONF, NULL, "dev(%s) isn't a block dev", dev);
+}
diff --git a/kernel/tests/lib/tst_dir_is_empty.c b/kernel/tests/lib/tst_dir_is_empty.c
new file mode 100644
index 0000000..43764ee
--- /dev/null
+++ b/kernel/tests/lib/tst_dir_is_empty.c
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2016 Oracle and/or its affiliates. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Alexey Kodanev <alexey.kodanev@oracle.com>
+ *
+ */
+
+#include <string.h>
+#include <sys/types.h>
+#include <dirent.h>
+
+#include "test.h"
+#include "safe_macros.h"
+
+int tst_dir_is_empty_(void (cleanup_fn)(void), const char *name, int verbose)
+{
+ struct dirent *entry;
+ DIR *dir = SAFE_OPENDIR(cleanup_fn, name);
+ int ret = 1;
+
+ while ((entry = SAFE_READDIR(cleanup_fn, dir)) != NULL) {
+ const char *file = entry->d_name;
+
+ if (!strcmp(file, "..") || !strcmp(file, "."))
+ continue;
+
+ if (verbose)
+ tst_resm(TINFO, "found a file: %s", file);
+ ret = 0;
+ break;
+ }
+
+ SAFE_CLOSEDIR(cleanup_fn, dir);
+
+ return ret;
+}
diff --git a/kernel/tests/lib/tst_fill_file.c b/kernel/tests/lib/tst_fill_file.c
new file mode 100644
index 0000000..8047200
--- /dev/null
+++ b/kernel/tests/lib/tst_fill_file.c
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
+ *
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include "lapi/fallocate.h"
+
+#include "test.h"
+
+int tst_fill_fd(int fd, char pattern, size_t bs, size_t bcount)
+{
+ size_t i;
+ char *buf;
+
+ /* Filling a memory buffer with provided pattern */
+ buf = malloc(bs);
+ if (buf == NULL)
+ return -1;
+
+ for (i = 0; i < bs; i++)
+ buf[i] = pattern;
+
+ /* Filling the file */
+ for (i = 0; i < bcount; i++) {
+ if (write(fd, buf, bs) != (ssize_t)bs) {
+ free(buf);
+ return -1;
+ }
+ }
+
+ free(buf);
+
+ return 0;
+}
+
+int tst_prealloc_size_fd(int fd, size_t bs, size_t bcount)
+{
+ int ret;
+
+ errno = 0;
+ ret = fallocate(fd, 0, 0, bs * bcount);
+
+ if (ret && errno == ENOSPC)
+ return ret;
+
+ if (ret)
+ ret = tst_fill_fd(fd, 0, bs, bcount);
+
+ return ret;
+}
+
+int tst_fill_file(const char *path, char pattern, size_t bs, size_t bcount)
+{
+ int fd;
+
+ fd = open(path, O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR);
+ if (fd < 0)
+ return -1;
+
+ if (tst_fill_fd(fd, pattern, bs, bcount)) {
+ close(fd);
+ unlink(path);
+ return -1;
+ }
+
+ if (close(fd) < 0) {
+ unlink(path);
+
+ return -1;
+ }
+
+ return 0;
+}
+
+int tst_prealloc_file(const char *path, size_t bs, size_t bcount)
+{
+ int fd;
+
+ fd = open(path, O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR);
+ if (fd < 0)
+ return -1;
+
+ if (tst_prealloc_size_fd(fd, bs, bcount)) {
+ close(fd);
+ unlink(path);
+ return -1;
+ }
+
+ if (close(fd) < 0) {
+ unlink(path);
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/kernel/tests/lib/tst_fill_fs.c b/kernel/tests/lib/tst_fill_fs.c
new file mode 100644
index 0000000..121dd2f
--- /dev/null
+++ b/kernel/tests/lib/tst_fill_fs.c
@@ -0,0 +1,68 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/statvfs.h>
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+#include "tst_fs.h"
+
+void tst_fill_fs(const char *path, int verbose)
+{
+ int i = 0;
+ char file[PATH_MAX];
+ char buf[4096];
+ size_t len;
+ ssize_t ret;
+ int fd;
+ struct statvfs fi;
+ statvfs(path, &fi);
+
+ for (;;) {
+ len = random() % (1024 * 102400);
+
+ snprintf(file, sizeof(file), "%s/file%i", path, i++);
+
+ if (verbose)
+ tst_res(TINFO, "Creating file %s size %zu", file, len);
+
+ fd = open(file, O_WRONLY | O_CREAT, 0700);
+ if (fd == -1) {
+ if (errno != ENOSPC)
+ tst_brk(TBROK | TERRNO, "open()");
+
+ tst_res(TINFO | TERRNO, "open()");
+ return;
+ }
+
+ while (len) {
+ ret = write(fd, buf, MIN(len, sizeof(buf)));
+
+ if (ret < 0) {
+ /* retry on ENOSPC to make sure filesystem is really full */
+ if (errno == ENOSPC && len >= fi.f_bsize/2) {
+ SAFE_FSYNC(fd);
+ len /= 2;
+ continue;
+ }
+
+ SAFE_CLOSE(fd);
+
+ if (errno != ENOSPC)
+ tst_brk(TBROK | TERRNO, "write()");
+
+ tst_res(TINFO | TERRNO, "write()");
+ return;
+ }
+
+ len -= ret;
+ }
+
+ SAFE_CLOSE(fd);
+ }
+}
diff --git a/kernel/tests/lib/tst_fs_has_free.c b/kernel/tests/lib/tst_fs_has_free.c
new file mode 100644
index 0000000..e82dfa8
--- /dev/null
+++ b/kernel/tests/lib/tst_fs_has_free.c
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2014 Fujitsu Ltd.
+ * Author: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/*
+ * DESCRIPTION
+ * Check if the mounted file system has enough free space,
+ * if it is, tst_fs_has_free() returns 1, otherwise 0.
+ */
+
+#include <stdint.h>
+#include <sys/vfs.h>
+#include "test.h"
+#include "tst_fs.h"
+
+int tst_fs_has_free_(void (*cleanup)(void), const char *path,
+ unsigned int size, unsigned int mult)
+{
+ struct statfs sf;
+
+ if (statfs(path, &sf)) {
+ tst_brkm(TBROK | TERRNO, cleanup,
+ "tst_fs_has_free: failed to statfs(%s)", path);
+ return 0;
+ }
+
+ if ((uint64_t)sf.f_bavail * sf.f_bsize >= (uint64_t)size * mult)
+ return 1;
+
+ return 0;
+}
diff --git a/kernel/tests/lib/tst_fs_link_count.c b/kernel/tests/lib/tst_fs_link_count.c
new file mode 100644
index 0000000..860510d
--- /dev/null
+++ b/kernel/tests/lib/tst_fs_link_count.c
@@ -0,0 +1,183 @@
+/*
+ * Copyright (c) 2014 Fujitsu Ltd.
+ * Author: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include "test.h"
+#include "usctest.h"
+#include "safe_macros.h"
+
+#define MAX_SANE_HARD_LINKS 65535
+
+/*
+ * filesystems whose subdir limit is less than MAX_SANE_HARD_LINKS
+ * XXX: we cannot filter ext4 out, because ext2/ext3/ext4 have the
+ * same magic number
+ */
+const long subdir_limit_whitelist[] = {
+ TST_EXT2_OLD_MAGIC, TST_EXT234_MAGIC, TST_MINIX_MAGIC,
+ TST_MINIX_MAGIC2, TST_MINIX2_MAGIC, TST_MINIX2_MAGIC2,
+ TST_MINIX3_MAGIC, TST_UDF_MAGIC, TST_SYSV2_MAGIC,
+ TST_SYSV4_MAGIC, TST_UFS_MAGIC, TST_UFS2_MAGIC,
+ TST_F2FS_MAGIC, TST_NILFS_MAGIC, TST_EXOFS_MAGIC
+};
+
+int tst_fs_fill_hardlinks_(void (*cleanup) (void), const char *dir)
+{
+ unsigned int i, j;
+ char base_filename[PATH_MAX], link_filename[PATH_MAX];
+ struct stat s;
+
+ if (stat(dir, &s) == -1 && errno == ENOENT)
+ SAFE_MKDIR(cleanup, dir, 0744);
+
+ SAFE_STAT(cleanup, dir, &s);
+ if (!S_ISDIR(s.st_mode)) {
+ tst_brkm(TBROK, cleanup, "%s is not directory", dir);
+ return 0;
+ }
+
+ sprintf(base_filename, "%s/testfile0", dir);
+ SAFE_TOUCH(cleanup, base_filename, 0644, NULL);
+
+ for (i = 1; i < MAX_SANE_HARD_LINKS; i++) {
+ sprintf(link_filename, "%s/testfile%d", dir, i);
+
+ if (link(base_filename, link_filename) == 0)
+ continue;
+
+ switch (errno) {
+ case EMLINK:
+ SAFE_STAT(cleanup, base_filename, &s);
+ if (s.st_nlink != i) {
+ tst_brkm(TBROK, cleanup, "wrong number of "
+ "hard links for %s have %i, should be"
+ " %d", base_filename,
+ (int)s.st_nlink, i);
+ return 0;
+ } else {
+ tst_resm(TINFO, "the maximum number of hard "
+ "links to %s is hit: %d",
+ base_filename, (int)s.st_nlink);
+ return s.st_nlink;
+ }
+ case ENOSPC:
+ case EDQUOT:
+ tst_resm(TINFO | TERRNO, "link(%s, %s) failed",
+ base_filename, link_filename);
+ goto max_hardlinks_cleanup;
+ default:
+ tst_brkm(TBROK, cleanup, "link(%s, %s) failed "
+ "unexpectedly: %s", base_filename,
+ link_filename, strerror(errno));
+ return 0;
+ }
+ }
+
+ tst_resm(TINFO, "Failed reach the hardlinks limit");
+
+max_hardlinks_cleanup:
+ for (j = 0; j < i; j++) {
+ sprintf(link_filename, "%s/testfile%d", dir, j);
+ SAFE_UNLINK(cleanup, link_filename);
+ }
+
+ return 0;
+}
+
+int tst_fs_fill_subdirs_(void (*cleanup) (void), const char *dir)
+{
+ unsigned int i, j, whitelist_size;
+ char dirname[PATH_MAX];
+ struct stat s;
+ long fs_type;
+
+ if (stat(dir, &s) == -1 && errno == ENOENT)
+ SAFE_MKDIR(cleanup, dir, 0744);
+
+ SAFE_STAT(cleanup, dir, &s);
+ if (!S_ISDIR(s.st_mode)) {
+ tst_brkm(TBROK, cleanup, "%s is not directory", dir);
+ return 0;
+ }
+
+ /* for current kernel, subdir limit is not availiable for all fs */
+ fs_type = tst_fs_type(cleanup, dir);
+
+ whitelist_size = ARRAY_SIZE(subdir_limit_whitelist);
+ for (i = 0; i < whitelist_size; i++) {
+ if (fs_type == subdir_limit_whitelist[i])
+ break;
+ }
+ if (i == whitelist_size) {
+ tst_resm(TINFO, "subdir limit is not availiable for "
+ "%s filesystem", tst_fs_type_name(fs_type));
+ return 0;
+ }
+
+ for (i = 0; i < MAX_SANE_HARD_LINKS; i++) {
+ sprintf(dirname, "%s/testdir%d", dir, i);
+
+ if (mkdir(dirname, 0755) == 0)
+ continue;
+
+ switch (errno) {
+ case EMLINK:
+ SAFE_STAT(cleanup, dir, &s);
+ /*
+ * i+2 because there are two links to each newly
+ * created directory (the '.' and link from parent dir)
+ */
+ if (s.st_nlink != (i + 2)) {
+ tst_brkm(TBROK, cleanup, "%s link counts have"
+ "%d, should be %d", dir,
+ (int)s.st_nlink, i + 2);
+ return 0;
+ } else {
+ tst_resm(TINFO, "the maximum subdirectories in "
+ "%s is hit: %d", dir, (int)s.st_nlink);
+ return s.st_nlink;
+ }
+ case ENOSPC:
+ case EDQUOT:
+ tst_resm(TINFO | TERRNO, "mkdir(%s, 0755) failed",
+ dirname);
+ goto max_subdirs_cleanup;
+ default:
+ tst_brkm(TBROK, cleanup, "mkdir(%s, 0755) failed "
+ "unexpectedly: %s", dirname,
+ strerror(errno));
+ return 0;
+ }
+
+ }
+
+ tst_resm(TINFO, "Failed reach the subdirs limit on %s filesystem",
+ tst_fs_type_name(fs_type));
+
+max_subdirs_cleanup:
+ for (j = 0; j < i; j++) {
+ sprintf(dirname, "%s/testdir%d", dir, j);
+ SAFE_RMDIR(cleanup, dirname);
+ }
+
+ return 0;
+}
diff --git a/kernel/tests/lib/tst_fs_setup.c b/kernel/tests/lib/tst_fs_setup.c
new file mode 100644
index 0000000..54ea370
--- /dev/null
+++ b/kernel/tests/lib/tst_fs_setup.c
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <dirent.h>
+#include <errno.h>
+#include <sys/mount.h>
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+#include "tst_fs.h"
+
+#define TST_FS_SETUP_OVERLAYFS_MSG "overlayfs is not configured in this kernel"
+#define TST_FS_SETUP_OVERLAYFS_CONFIG "lowerdir="OVL_LOWER",upperdir="OVL_UPPER",workdir="OVL_WORK
+
+void create_overlay_dirs(void)
+{
+ DIR *dir = opendir(OVL_LOWER);
+ if (dir == NULL) {
+ SAFE_MKDIR(OVL_LOWER, 0755);
+ SAFE_MKDIR(OVL_UPPER, 0755);
+ SAFE_MKDIR(OVL_WORK, 0755);
+ SAFE_MKDIR(OVL_MNT, 0755);
+ return;
+ }
+ closedir(dir);
+}
+
+int mount_overlay(const char *file, const int lineno, int skip)
+{
+ int ret;
+
+ create_overlay_dirs();
+ ret = mount("overlay", OVL_MNT, "overlay", 0,
+ TST_FS_SETUP_OVERLAYFS_CONFIG);
+ if (ret == 0)
+ return 0;
+
+ if (errno == ENODEV) {
+ if (skip) {
+ tst_brk(TCONF, "%s:%d: " TST_FS_SETUP_OVERLAYFS_MSG,
+ file, lineno);
+ } else {
+ tst_res(TINFO, "%s:%d: " TST_FS_SETUP_OVERLAYFS_MSG,
+ file, lineno);
+ }
+ } else {
+ tst_brk(TBROK | TERRNO, "overlayfs mount failed");
+ }
+ return ret;
+}
diff --git a/kernel/tests/lib/tst_fs_type.c b/kernel/tests/lib/tst_fs_type.c
new file mode 100644
index 0000000..1d0ac96
--- /dev/null
+++ b/kernel/tests/lib/tst_fs_type.c
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2005-2014 Linux Test Project
+ *
+ * Cyril Hrubis <chrubis@suse.cz> 2014
+ * Michal Simek <monstr@monstr.eu> 2009
+ * Kumar Gala <galak@kernel.crashing.org> 2007
+ * Ricky Ng-Adam <rngadam@yahoo.com> 2005
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it is
+ * free of the rightful claim of any third person regarding infringement
+ * or the like. Any license provided herein, whether implied or
+ * otherwise, applies only to this software file. Patent licenses, if
+ * any, provided herein do not apply to combinations of this program with
+ * other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <sys/vfs.h>
+#include "test.h"
+#include "tst_fs.h"
+
+long tst_fs_type_(void (*cleanup)(void), const char *path)
+{
+ struct statfs sbuf;
+
+ if (statfs(path, &sbuf)) {
+ tst_brkm(TBROK | TERRNO, cleanup,
+ "tst_fs_type: Failed to statfs(%s)", path);
+ return 0;
+ }
+
+ return sbuf.f_type;
+}
+
+const char *tst_fs_type_name(long f_type)
+{
+ switch (f_type) {
+ case TST_TMPFS_MAGIC:
+ return "TMPFS";
+ case TST_NFS_MAGIC:
+ return "NFS";
+ case TST_V9FS_MAGIC:
+ return "9P";
+ case TST_RAMFS_MAGIC:
+ return "RAMFS";
+ case TST_BTRFS_MAGIC:
+ return "BTRFS";
+ case TST_XFS_MAGIC:
+ return "XFS";
+ case TST_EXT2_OLD_MAGIC:
+ return "EXT2";
+ case TST_EXT234_MAGIC:
+ return "EXT2/EXT3/EXT4";
+ case TST_MINIX_MAGIC:
+ case TST_MINIX_MAGIC2:
+ case TST_MINIX2_MAGIC:
+ case TST_MINIX2_MAGIC2:
+ case TST_MINIX3_MAGIC:
+ return "MINIX";
+ case TST_UDF_MAGIC:
+ return "UDF";
+ case TST_SYSV2_MAGIC:
+ case TST_SYSV4_MAGIC:
+ return "SYSV";
+ case TST_UFS_MAGIC:
+ case TST_UFS2_MAGIC:
+ return "UFS";
+ case TST_F2FS_MAGIC:
+ return "F2FS";
+ case TST_NILFS_MAGIC:
+ return "NILFS";
+ case TST_EXOFS_MAGIC:
+ return "EXOFS";
+ case TST_OVERLAYFS_MAGIC:
+ return "OVERLAYFS";
+ default:
+ return "Unknown";
+ }
+}
diff --git a/kernel/tests/lib/tst_get_bad_addr.c b/kernel/tests/lib/tst_get_bad_addr.c
new file mode 100644
index 0000000..098e72b
--- /dev/null
+++ b/kernel/tests/lib/tst_get_bad_addr.c
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <sys/mman.h>
+#include "test.h"
+#include "tst_get_bad_addr.h"
+
+void *tst_get_bad_addr(void (*cleanup_fn) (void))
+{
+ void *bad_addr;
+
+ bad_addr = mmap(0, 1, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+ if (bad_addr == MAP_FAILED)
+ tst_brkm(TBROK, cleanup_fn, "mmap() failed to get bad address");
+
+ return bad_addr;
+}
diff --git a/kernel/tests/lib/tst_hugepage.c b/kernel/tests/lib/tst_hugepage.c
new file mode 100644
index 0000000..1d0e62e
--- /dev/null
+++ b/kernel/tests/lib/tst_hugepage.c
@@ -0,0 +1,61 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Red Hat, Inc.
+ */
+
+#define TST_NO_DEFAULT_MAIN
+
+#include "tst_test.h"
+#include "tst_hugepage.h"
+
+unsigned long tst_hugepages;
+char *nr_opt;
+char *Hopt;
+
+size_t tst_get_hugepage_size(void)
+{
+ if (access(PATH_HUGEPAGES, F_OK))
+ return 0;
+
+ return SAFE_READ_MEMINFO("Hugepagesize:") * 1024;
+}
+
+unsigned long tst_request_hugepages(unsigned long hpages)
+{
+ unsigned long val, max_hpages;
+
+ if (access(PATH_HUGEPAGES, F_OK)) {
+ tst_hugepages = 0;
+ goto out;
+ }
+
+ if (nr_opt)
+ tst_hugepages = SAFE_STRTOL(nr_opt, 1, LONG_MAX);
+ else
+ tst_hugepages = hpages;
+
+ SAFE_FILE_PRINTF("/proc/sys/vm/drop_caches", "3");
+ max_hpages = SAFE_READ_MEMINFO("MemFree:") / SAFE_READ_MEMINFO("Hugepagesize:");
+
+ if (tst_hugepages > max_hpages) {
+ tst_res(TINFO, "Requested number(%lu) of hugepages is too large, "
+ "limiting to 80%% of the max hugepage count %lu",
+ tst_hugepages, max_hpages);
+ tst_hugepages = max_hpages * 0.8;
+
+ if (tst_hugepages < 1)
+ goto out;
+ }
+
+ tst_sys_conf_save("?/proc/sys/vm/nr_hugepages");
+ SAFE_FILE_PRINTF(PATH_NR_HPAGES, "%lu", tst_hugepages);
+ SAFE_FILE_SCANF(PATH_NR_HPAGES, "%lu", &val);
+ if (val != tst_hugepages)
+ tst_brk(TCONF, "nr_hugepages = %lu, but expect %lu. "
+ "Not enough hugepages for testing.",
+ val, tst_hugepages);
+
+ tst_res(TINFO, "%lu hugepage(s) reserved", tst_hugepages);
+out:
+ return tst_hugepages;
+}
diff --git a/kernel/tests/lib/tst_ioctl.c b/kernel/tests/lib/tst_ioctl.c
new file mode 100644
index 0000000..364220b
--- /dev/null
+++ b/kernel/tests/lib/tst_ioctl.c
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <linux/fs.h>
+
+#define TST_NO_DEFAULT_MAIN
+
+#include "tst_test.h"
+
+int tst_fibmap(const char *filename)
+{
+ /* test if FIBMAP ioctl is supported */
+ int fd, block = 0;
+
+ fd = open(filename, O_RDWR | O_CREAT, 0666);
+ if (fd < 0) {
+ tst_res(TWARN | TERRNO,
+ "open(%s, O_RDWR | O_CREAT, 0666) failed", filename);
+ return -1;
+ }
+
+ if (ioctl(fd, FIBMAP, &block)) {
+ tst_res(TINFO | TERRNO, "FIBMAP ioctl is NOT supported");
+ close(fd);
+ return 1;
+ }
+ tst_res(TINFO, "FIBMAP ioctl is supported");
+
+ if (close(fd)) {
+ tst_res(TWARN | TERRNO, "close(fd) failed");
+ return -1;
+ }
+ return 0;
+}
diff --git a/kernel/tests/lib/tst_kconfig.c b/kernel/tests/lib/tst_kconfig.c
new file mode 100644
index 0000000..d49187b
--- /dev/null
+++ b/kernel/tests/lib/tst_kconfig.c
@@ -0,0 +1,285 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2018 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include <sys/utsname.h>
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+#include "tst_kconfig.h"
+
+static const char *kconfig_path(char *path_buf, size_t path_buf_len)
+{
+ const char *path = getenv("KCONFIG_PATH");
+ struct utsname un;
+
+ if (path) {
+ if (!access(path, F_OK))
+ return path;
+
+ tst_res(TWARN, "KCONFIG_PATH='%s' does not exist", path);
+ }
+
+ if (!access("/proc/config.gz", F_OK))
+ return "/proc/config.gz";
+
+ uname(&un);
+
+ /* Debian and derivatives */
+ snprintf(path_buf, path_buf_len, "/boot/config-%s", un.release);
+
+ if (!access(path_buf, F_OK))
+ return path_buf;
+
+ /* Clear Linux */
+ snprintf(path_buf, path_buf_len, "/lib/kernel/config-%s", un.release);
+
+ if (!access(path_buf, F_OK))
+ return path_buf;
+
+ tst_res(TINFO, "Couldn't locate kernel config!");
+
+ return NULL;
+}
+
+static char is_gzip;
+
+static FILE *open_kconfig(void)
+{
+ FILE *fp;
+ char buf[1064];
+ char path_buf[1024];
+ const char *path = kconfig_path(path_buf, sizeof(path_buf));
+
+ if (!path)
+ return NULL;
+
+ tst_res(TINFO, "Parsing kernel config '%s'", path);
+
+ is_gzip = !!strstr(path, ".gz");
+
+ if (is_gzip) {
+ snprintf(buf, sizeof(buf), "zcat '%s'", path);
+ fp = popen(buf, "r");
+ } else {
+ fp = fopen(path, "r");
+ }
+
+ if (!fp)
+ tst_brk(TBROK | TERRNO, "Failed to open '%s'", path);
+
+ return fp;
+}
+
+static void close_kconfig(FILE *fp)
+{
+ if (is_gzip)
+ pclose(fp);
+ else
+ fclose(fp);
+}
+
+struct match {
+ /* match len, string length up to \0 or = */
+ size_t len;
+ /* if set part of conf string after = */
+ const char *val;
+ /* if set the config option was matched already */
+ int match;
+};
+
+static int is_set(const char *str, const char *val)
+{
+ size_t vlen = strlen(val);
+
+ while (isspace(*str))
+ str++;
+
+ if (strncmp(str, val, vlen))
+ return 0;
+
+ switch (str[vlen]) {
+ case ' ':
+ case '\n':
+ case '\0':
+ return 1;
+ break;
+ default:
+ return 0;
+ }
+}
+
+static inline int match(struct match *match, const char *conf,
+ struct tst_kconfig_res *result, const char *line)
+{
+ if (match->match)
+ return 0;
+
+ const char *cfg = strstr(line, "CONFIG_");
+
+ if (!cfg)
+ return 0;
+
+ if (strncmp(cfg, conf, match->len))
+ return 0;
+
+ const char *val = &cfg[match->len];
+
+ switch (cfg[match->len]) {
+ case '=':
+ break;
+ case ' ':
+ if (is_set(val, "is not set")) {
+ result->match = 'n';
+ goto match;
+ }
+ /* fall through */
+ default:
+ return 0;
+ }
+
+ if (is_set(val, "=y")) {
+ result->match = 'y';
+ goto match;
+ }
+
+ if (is_set(val, "=m")) {
+ result->match = 'm';
+ goto match;
+ }
+
+ result->match = 'v';
+ result->value = strndup(val+1, strlen(val)-2);
+
+match:
+ match->match = 1;
+ return 1;
+}
+
+void tst_kconfig_read(const char *const *kconfigs,
+ struct tst_kconfig_res results[], size_t cnt)
+{
+ struct match matches[cnt];
+ FILE *fp;
+ unsigned int i, j;
+ char buf[1024];
+
+ for (i = 0; i < cnt; i++) {
+ const char *val = strchr(kconfigs[i], '=');
+
+ if (strncmp("CONFIG_", kconfigs[i], 7))
+ tst_brk(TBROK, "Invalid config string '%s'", kconfigs[i]);
+
+ matches[i].match = 0;
+ matches[i].len = strlen(kconfigs[i]);
+
+ if (val) {
+ matches[i].val = val + 1;
+ matches[i].len -= strlen(val);
+ }
+
+ results[i].match = 0;
+ results[i].value = NULL;
+ }
+
+ fp = open_kconfig();
+ if (!fp)
+ tst_brk(TBROK, "Cannot parse kernel .config");
+
+ while (fgets(buf, sizeof(buf), fp)) {
+ for (i = 0; i < cnt; i++) {
+ if (match(&matches[i], kconfigs[i], &results[i], buf)) {
+ for (j = 0; j < cnt; j++) {
+ if (matches[j].match)
+ break;
+ }
+
+ if (j == cnt)
+ goto exit;
+ }
+ }
+
+ }
+
+exit:
+ close_kconfig(fp);
+}
+
+static size_t array_len(const char *const kconfigs[])
+{
+ size_t i = 0;
+
+ while (kconfigs[++i]);
+
+ return i;
+}
+
+static int compare_res(struct tst_kconfig_res *res, const char *kconfig,
+ char match, const char *val)
+{
+ if (res->match != match) {
+ tst_res(TINFO, "Needs kernel %s, have %c", kconfig, res->match);
+ return 1;
+ }
+
+ if (match != 'v')
+ return 0;
+
+ if (strcmp(res->value, val)) {
+ tst_res(TINFO, "Needs kernel %s, have %s", kconfig, res->value);
+ return 1;
+ }
+
+ return 0;
+}
+
+void tst_kconfig_check(const char *const kconfigs[])
+{
+ size_t cnt = array_len(kconfigs);
+ struct tst_kconfig_res results[cnt];
+ unsigned int i;
+ int abort_test = 0;
+
+ tst_kconfig_read(kconfigs, results, cnt);
+
+ for (i = 0; i < cnt; i++) {
+ if (results[i].match == 0) {
+ tst_res(TINFO, "Missing kernel %s", kconfigs[i]);
+ abort_test = 1;
+ continue;
+ }
+
+ if (results[i].match == 'n') {
+ tst_res(TINFO, "Kernel %s is not set", kconfigs[i]);
+ abort_test = 1;
+ continue;
+ }
+
+ const char *val = strchr(kconfigs[i], '=');
+
+ if (val) {
+ char match = 'v';
+ val++;
+
+ if (!strcmp(val, "y"))
+ match = 'y';
+
+ if (!strcmp(val, "m"))
+ match = 'm';
+
+ if (compare_res(&results[i], kconfigs[i], match, val))
+ abort_test = 1;
+
+ }
+
+ free(results[i].value);
+ }
+
+ if (abort_test)
+ tst_brk(TCONF, "Aborting due to unsuitable kernel config, see above!");
+}
diff --git a/kernel/tests/lib/tst_kernel.c b/kernel/tests/lib/tst_kernel.c
new file mode 100644
index 0000000..57fa4b2
--- /dev/null
+++ b/kernel/tests/lib/tst_kernel.c
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <sys/personality.h>
+#include <sys/utsname.h>
+#include "test.h"
+#include "tst_kernel.h"
+
+static int get_kernel_bits_from_uname(struct utsname *buf)
+{
+ if (uname(buf)) {
+ tst_brkm(TBROK | TERRNO, NULL, "uname()");
+ return -1;
+ }
+
+ return strstr(buf->machine, "64") ? 64 : 32;
+}
+
+int tst_kernel_bits(void)
+{
+ struct utsname buf;
+ int kernel_bits = get_kernel_bits_from_uname(&buf);
+
+ if (kernel_bits == -1)
+ return -1;
+
+ /*
+ * ARM64 (aarch64) defines 32-bit compatibility modes as
+ * armv8l and armv8b (little and big endian).
+ * s390x is 64bit but not contain 64 in the words.
+ */
+ if (!strcmp(buf.machine, "armv8l") || !strcmp(buf.machine, "armv8b")
+ || !strcmp(buf.machine, "s390x"))
+ kernel_bits = 64;
+
+#ifdef __ANDROID__
+ /* Android's bionic libc sets the PER_LINUX32 personality for all 32-bit
+ * programs. This will cause buf.machine to report as i686 even though
+ * the kernel itself is 64-bit.
+ */
+ if (!strcmp(buf.machine, "i686") &&
+ (personality(0xffffffff) & PER_MASK) == PER_LINUX32) {
+ /* Set the personality back to the default. */
+ if (personality(PER_LINUX) == -1) {
+ tst_brkm(TBROK | TERRNO, NULL, "personality()");
+ return -1;
+ }
+
+ /* Redo the uname check without the PER_LINUX32 personality to
+ * determine the actual kernel bits value.
+ */
+ kernel_bits = get_kernel_bits_from_uname(&buf);
+ if (kernel_bits == -1)
+ return -1;
+
+ /* Set the personality back to PER_LINUX32. */
+ if (personality(PER_LINUX32) == -1) {
+ tst_brkm(TBROK | TERRNO, NULL, "personality()");
+ return -1;
+ }
+ }
+#endif /* __ANDROID__ */
+
+ tst_resm(TINFO, "uname.machine=%s kernel is %ibit",
+ buf.machine, kernel_bits);
+
+ return kernel_bits;
+}
+
+int tst_check_driver(const char *name)
+{
+#ifndef __ANDROID__
+ const char * const argv[] = { "modprobe", "-n", name, NULL };
+ int res = tst_cmd_(NULL, argv, "/dev/null", "/dev/null",
+ TST_CMD_PASS_RETVAL);
+
+ /* 255 - it looks like modprobe not available */
+ return (res == 255) ? 0 : res;
+#else
+ /* Android modprobe may not have '-n', or properly installed
+ * module.*.bin files to determine built-in drivers. Assume
+ * all drivers are available.
+ */
+ return 0;
+#endif
+}
diff --git a/kernel/tests/lib/tst_kvercmp.c b/kernel/tests/lib/tst_kvercmp.c
new file mode 100644
index 0000000..5d56e30
--- /dev/null
+++ b/kernel/tests/lib/tst_kvercmp.c
@@ -0,0 +1,195 @@
+/*
+ * Copyright (c) International Business Machines Corp., 2003
+ * AUTHOR: Paul Larson <plars@linuxtestproject.org>
+ * Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <limits.h>
+#include <sys/utsname.h>
+#include "test.h"
+
+#define OSRELEASE_PATH "/etc/os-release"
+
+static char *parse_digit(const char *str, int *d)
+{
+ unsigned long v;
+ char *end;
+
+ v = strtoul(str, &end, 10);
+ if (str == end)
+ return NULL;
+
+ if (v > INT_MAX)
+ return NULL;
+
+ *d = v;
+
+ return end;
+}
+
+int tst_parse_kver(const char *str_kver, int *v1, int *v2, int *v3)
+{
+ const char *str = str_kver;
+
+ *v1 = 0;
+ *v2 = 0;
+ *v3 = 0;
+
+ if (!(str = parse_digit(str, v1)))
+ return 1;
+
+ if (*(str++) != '.')
+ return 1;
+
+ if (!(str = parse_digit(str, v2)))
+ return 1;
+
+ /*
+ * Check for a short version e.g '2.4'
+ */
+ if (*str == ' ' || *str == '\0')
+ return 0;
+
+ if (*(str++) != '.')
+ return 1;
+
+ /*
+ * Ignore rest of the string in order not to break on versions as
+ * 4.8.1-52-default.
+ */
+ if (!parse_digit(str, v3))
+ return 1;
+
+ return 0;
+}
+
+int tst_kvcmp(const char *cur_kver, int r1, int r2, int r3)
+{
+ int a1, a2, a3;
+ int testver, currver;
+
+ if (tst_parse_kver(cur_kver, &a1, &a2, &a3)) {
+ tst_resm(TWARN,
+ "Invalid kernel version %s, expected %%d.%%d.%%d",
+ cur_kver);
+ }
+
+ testver = (r1 << 16) + (r2 << 8) + r3;
+ currver = (a1 << 16) + (a2 << 8) + a3;
+
+ return currver - testver;
+}
+
+int tst_kvercmp(int r1, int r2, int r3)
+{
+ struct utsname uval;
+
+ uname(&uval);
+
+ return tst_kvcmp(uval.release, r1, r2, r3);
+}
+
+int tst_kvexcmp(const char *tst_exv, const char *cur_ver)
+{
+ int c1 = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0;
+ int t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0;
+ int ret;
+
+ sscanf(cur_ver, "%d.%d.%d-%d.%d", &c1, &c2, &c3, &c4, &c5);
+ sscanf(tst_exv, "%d.%d.%d-%d.%d", &t1, &t2, &t3, &t4, &t5);
+
+ if ((ret = c1 - t1))
+ return ret;
+ if ((ret = c2 - t2))
+ return ret;
+ if ((ret = c3 - t3))
+ return ret;
+ if ((ret = c4 - t4))
+ return ret;
+
+ return c5 - t5;
+}
+
+const char *tst_kvcmp_distname(const char *kver)
+{
+ static char distname[64];
+ char *ret = distname;
+ char *p = distname;
+
+ if (strstr(kver, ".el5uek"))
+ return "OL5UEK";
+
+ if (strstr(kver, ".el5"))
+ return "RHEL5";
+
+ if (strstr(kver, ".el6uek"))
+ return "OL6UEK";
+
+ if (strstr(kver, ".el6"))
+ return "RHEL6";
+
+ if (access(OSRELEASE_PATH, F_OK) != -1) {
+ SAFE_FILE_LINES_SCANF(NULL, OSRELEASE_PATH, "ID=%s", distname);
+
+ if (p[0] == '"') {
+ ret = distname + 1;
+ p = ret;
+ }
+
+ while (*p) {
+ if (*p == '"') {
+ *p = 0;
+ break;
+ }
+ *p = toupper((unsigned char)*p);
+ p++;
+ }
+
+ return ret;
+ }
+
+ return NULL;
+}
+
+int tst_kvercmp2(int r1, int r2, int r3, struct tst_kern_exv *vers)
+{
+ int i;
+ const char *kver;
+ struct utsname uval;
+ const char *cur_dist_name;
+
+ uname(&uval);
+ kver = uval.release;
+ cur_dist_name = tst_kvcmp_distname(kver);
+
+ if (cur_dist_name == NULL)
+ return tst_kvercmp(r1, r2, r3);
+
+ for (i = 0; vers[i].dist_name; i++) {
+ if (!strcmp(vers[i].dist_name, cur_dist_name)) {
+ tst_resm(TINFO, "Detected %s using kernel version %s",
+ cur_dist_name, kver);
+ return tst_kvexcmp(vers[i].extra_ver, kver);
+ }
+ }
+
+ return tst_kvcmp(kver, r1, r2, r3);
+}
diff --git a/kernel/tests/lib/tst_lockdown.c b/kernel/tests/lib/tst_lockdown.c
new file mode 100644
index 0000000..e7c1981
--- /dev/null
+++ b/kernel/tests/lib/tst_lockdown.c
@@ -0,0 +1,30 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#define TST_NO_DEFAULT_MAIN
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/mount.h>
+
+#include "tst_test.h"
+#include "tst_safe_macros.h"
+#include "tst_safe_stdio.h"
+#include "tst_lockdown.h"
+
+int tst_lockdown_enabled(void)
+{
+ char line[BUFSIZ];
+ FILE *file;
+
+ if (access(PATH_LOCKDOWN, F_OK) != 0) {
+ tst_res(TINFO, "Unable to determine system lockdown state");
+ return 0;
+ }
+
+ file = SAFE_FOPEN(PATH_LOCKDOWN, "r");
+ if (!fgets(line, sizeof(line), file))
+ tst_brk(TBROK | TERRNO, "fgets %s", PATH_LOCKDOWN);
+ SAFE_FCLOSE(file);
+
+ return (strstr(line, "[none]") == NULL);
+}
diff --git a/kernel/tests/lib/tst_memutils.c b/kernel/tests/lib/tst_memutils.c
new file mode 100644
index 0000000..f134d90
--- /dev/null
+++ b/kernel/tests/lib/tst_memutils.c
@@ -0,0 +1,62 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 SUSE LLC <mdoucha@suse.cz>
+ */
+
+#include <unistd.h>
+#include <limits.h>
+#include <sys/sysinfo.h>
+#include <stdlib.h>
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+
+#define BLOCKSIZE (16 * 1024 * 1024)
+
+void tst_pollute_memory(size_t maxsize, int fillchar)
+{
+ size_t i, map_count = 0, safety = 0, blocksize = BLOCKSIZE;
+ void **map_blocks;
+ struct sysinfo info;
+
+ SAFE_SYSINFO(&info);
+ safety = 4096 * SAFE_SYSCONF(_SC_PAGESIZE) / info.mem_unit;
+
+ if (info.freeswap > safety)
+ safety = 0;
+
+ /* Not enough free memory to avoid invoking OOM killer */
+ if (info.freeram <= safety)
+ return;
+
+ if (!maxsize)
+ maxsize = SIZE_MAX;
+
+ if (info.freeram - safety < maxsize / info.mem_unit)
+ maxsize = (info.freeram - safety) * info.mem_unit;
+
+ blocksize = MIN(maxsize, blocksize);
+ map_count = maxsize / blocksize;
+ map_blocks = SAFE_MALLOC(map_count * sizeof(void *));
+
+ /*
+ * Keep allocating until the first failure. The address space may be
+ * too fragmented or just smaller than maxsize.
+ */
+ for (i = 0; i < map_count; i++) {
+ map_blocks[i] = mmap(NULL, blocksize, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+
+ if (map_blocks[i] == MAP_FAILED) {
+ map_count = i;
+ break;
+ }
+
+ memset(map_blocks[i], fillchar, blocksize);
+ }
+
+ for (i = 0; i < map_count; i++)
+ SAFE_MUNMAP(map_blocks[i], blocksize);
+
+ free(map_blocks);
+}
diff --git a/kernel/tests/lib/tst_mkfs.c b/kernel/tests/lib/tst_mkfs.c
new file mode 100644
index 0000000..38b2e71
--- /dev/null
+++ b/kernel/tests/lib/tst_mkfs.c
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2013-2016 Cyril Hrubis <chrubis@suse.cz>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "test.h"
+#include "ltp_priv.h"
+#include "tst_mkfs.h"
+#include "tst_device.h"
+
+#define OPTS_MAX 32
+
+void tst_mkfs_(const char *file, const int lineno, void (cleanup_fn)(void),
+ const char *dev, const char *fs_type,
+ const char *const fs_opts[], const char *const extra_opts[])
+{
+ int i, pos = 1, ret;
+ char mkfs[64];
+ const char *argv[OPTS_MAX] = {mkfs};
+ char fs_opts_str[1024] = "";
+ char extra_opts_str[1024] = "";
+
+ if (!dev) {
+ tst_brkm(TBROK, cleanup_fn,
+ "%s:%d: No device specified", file, lineno);
+ return;
+ }
+
+ if (!fs_type) {
+ tst_brkm(TBROK, cleanup_fn,
+ "%s:%d: No fs_type specified", file, lineno);
+ return;
+ }
+
+ snprintf(mkfs, sizeof(mkfs), "mkfs.%s", fs_type);
+
+ if (fs_opts) {
+ for (i = 0; fs_opts[i]; i++) {
+ argv[pos++] = fs_opts[i];
+
+ if (pos + 2 > OPTS_MAX) {
+ tst_brkm(TBROK, cleanup_fn,
+ "%s:%d: Too much mkfs options",
+ file, lineno);
+ return;
+ }
+
+ if (i)
+ strcat(fs_opts_str, " ");
+ strcat(fs_opts_str, fs_opts[i]);
+ }
+ }
+
+ argv[pos++] = dev;
+
+ if (extra_opts) {
+ for (i = 0; extra_opts[i]; i++) {
+ argv[pos++] = extra_opts[i];
+
+ if (pos + 1 > OPTS_MAX) {
+ tst_brkm(TBROK, cleanup_fn,
+ "%s:%d: Too much mkfs options", file, lineno);
+ return;
+ }
+
+ if (i)
+ strcat(extra_opts_str, " ");
+ strcat(extra_opts_str, extra_opts[i]);
+ }
+ }
+
+ argv[pos] = NULL;
+
+ if (tst_clear_device(dev))
+ tst_brkm(TBROK, cleanup_fn, "tst_clear_device() failed");
+
+ tst_resm(TINFO, "Formatting %s with %s opts='%s' extra opts='%s'",
+ dev, fs_type, fs_opts_str, extra_opts_str);
+ ret = tst_cmd(cleanup_fn, argv, "/dev/null", NULL, TST_CMD_PASS_RETVAL |
+ TST_CMD_TCONF_ON_MISSING);
+
+ switch (ret) {
+ case 0:
+ break;
+ case 255:
+ tst_brkm(TCONF, cleanup_fn,
+ "%s:%d: %s not found in $PATH", file, lineno, mkfs);
+ break;
+ default:
+ tst_brkm(TBROK, cleanup_fn,
+ "%s:%d: %s failed with %i", file, lineno, mkfs, ret);
+ }
+}
+
+const char *tst_dev_fs_type(void)
+{
+ const char *fs_type;
+
+ fs_type = getenv("LTP_DEV_FS_TYPE");
+
+ if (fs_type)
+ return fs_type;
+
+ return DEFAULT_FS_TYPE;
+}
diff --git a/kernel/tests/lib/tst_module.c b/kernel/tests/lib/tst_module.c
new file mode 100644
index 0000000..eda6187
--- /dev/null
+++ b/kernel/tests/lib/tst_module.c
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author: Alexey Kodanev <alexey.kodanev@oracle.com>
+ *
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "test.h"
+#include "ltp_priv.h"
+#include "old_module.h"
+
+void tst_module_exists(void (cleanup_fn)(void),
+ const char *mod_name, char **mod_path)
+{
+ /* check current working directory */
+ if (access(mod_name, F_OK) == 0) {
+ if (mod_path != NULL)
+ *mod_path = strdup(mod_name);
+ return;
+ }
+ char *buf = NULL;
+ int err = -1;
+ /* check LTP installation path */
+ const char *ltproot = getenv("LTPROOT");
+ if (ltproot != NULL) {
+ if (asprintf(&buf, "%s/testcases/bin/%s",
+ ltproot, mod_name) == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "asprintf failed at %s:%d",
+ __FILE__, __LINE__);
+ return;
+ }
+ err = access(buf, F_OK);
+ }
+ /* check start working directory */
+ if (err == -1 && tst_tmpdir_created()) {
+ free(buf);
+ if (asprintf(&buf, "%s/%s", tst_get_startwd(),
+ mod_name) == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "asprintf failed at %s:%d",
+ __FILE__, __LINE__);
+ return;
+ }
+ err = access(buf, F_OK);
+ }
+
+ if (err != 0) {
+ free(buf);
+ tst_brkm(TCONF, cleanup_fn, "Failed to find module '%s'",
+ mod_name);
+ return;
+ }
+
+ if (mod_path != NULL)
+ *mod_path = buf;
+ else
+ free(buf);
+}
+
+void tst_module_load(void (cleanup_fn)(void),
+ const char *mod_name, char *const argv[])
+{
+ char *mod_path = NULL;
+ tst_module_exists(cleanup_fn, mod_name, &mod_path);
+
+ const int offset = 2; /* command name & module path */
+ int size = 0;
+ while (argv && argv[size])
+ ++size;
+ size += offset;
+ const char *mod_argv[size + 1]; /* + NULL in the end */
+ mod_argv[size] = NULL;
+ mod_argv[0] = "insmod";
+ mod_argv[1] = mod_path;
+
+ int i;
+ for (i = offset; i < size; ++i)
+ mod_argv[i] = argv[i - offset];
+
+ tst_cmd(cleanup_fn, mod_argv, NULL, NULL, 0);
+ free(mod_path);
+}
+
+void tst_module_unload(void (cleanup_fn)(void), const char *mod_name)
+{
+ int i, rc;
+
+ const char *const argv[] = { "rmmod", mod_name, NULL };
+
+ rc = 1;
+ for (i = 0; i < 50; i++) {
+ rc = tst_cmd(NULL, argv, "/dev/null", "/dev/null",
+ TST_CMD_PASS_RETVAL);
+ if (!rc)
+ break;
+
+ usleep(20000);
+ }
+
+ if (rc) {
+ tst_brkm(TBROK, cleanup_fn,
+ "could not unload %s module", mod_name);
+ }
+}
diff --git a/kernel/tests/lib/tst_net.c b/kernel/tests/lib/tst_net.c
new file mode 100644
index 0000000..8a589b0
--- /dev/null
+++ b/kernel/tests/lib/tst_net.c
@@ -0,0 +1,221 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2017-2019 Petr Vorel <pvorel@suse.cz>
+ * Copyright (c) 2019 Martin Doucha <mdoucha@suse.cz>
+ */
+
+#include <errno.h>
+#include <netdb.h>
+#include <string.h>
+#include <stdlib.h>
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+#include "tst_net.h"
+#include "tst_private.h"
+
+void tst_print_svar(const char *name, const char *val)
+{
+ if (name && val)
+ printf("export %s=\"%s\"\n", name, val);
+}
+
+void tst_print_svar_change(const char *name, const char *val)
+{
+ if (name && val)
+ printf("export %s=\"${%s:-%s}\"\n", name, name, val);
+}
+
+/*
+ * Function bit_count is from ipcalc project, ipcalc.c.
+ */
+static int tst_bit_count(uint32_t i)
+{
+ int c = 0;
+ unsigned int seen_one = 0;
+
+ while (i > 0) {
+ if (i & 1) {
+ seen_one = 1;
+ c++;
+ } else {
+ if (seen_one)
+ return -1;
+ }
+ i >>= 1;
+ }
+
+ return c;
+}
+
+/*
+ * Function mask2prefix is from ipcalc project, ipcalc.c.
+ */
+static int tst_mask2prefix(struct in_addr mask)
+{
+ return tst_bit_count(ntohl(mask.s_addr));
+}
+
+/*
+ * Function ipv4_mask_to_int is from ipcalc project, ipcalc.c.
+ */
+static int tst_ipv4_mask_to_int(const char *prefix)
+{
+ int ret;
+ struct in_addr in;
+
+ ret = inet_pton(AF_INET, prefix, &in);
+ if (ret == 0)
+ return -1;
+
+ return tst_mask2prefix(in);
+}
+
+/*
+ * Function safe_atoi is from ipcalc project, ipcalc.c.
+ */
+static int tst_safe_atoi(const char *s, int *ret_i)
+{
+ char *x = NULL;
+ long l;
+
+ errno = 0;
+ l = strtol(s, &x, 0);
+
+ if (!x || x == s || *x || errno)
+ return errno > 0 ? -errno : -EINVAL;
+
+ if ((long)(int)l != l)
+ return -ERANGE;
+
+ *ret_i = (int)l;
+
+ return 0;
+}
+
+/*
+ * Function get_prefix use code from ipcalc project, str_to_prefix/ipcalc.c.
+ */
+int tst_get_prefix(const char *ip_str, int is_ipv6)
+{
+ char *prefix_str = NULL;
+ int prefix = -1, r;
+
+ prefix_str = strchr(ip_str, '/');
+ if (!prefix_str)
+ return -1;
+
+ *(prefix_str++) = '\0';
+
+ if (!is_ipv6 && strchr(prefix_str, '.'))
+ prefix = tst_ipv4_mask_to_int(prefix_str);
+ else {
+ r = tst_safe_atoi(prefix_str, &prefix);
+ if (r != 0)
+ tst_brk_comment("conversion error: '%s' is not integer",
+ prefix_str);
+ }
+
+ if (prefix < 0 || ((is_ipv6 && prefix > MAX_IPV6_PREFIX) ||
+ (!is_ipv6 && prefix > MAX_IPV4_PREFIX)))
+ tst_brk_comment("bad %s prefix: %s", is_ipv6 ? "IPv6" : "IPv4",
+ prefix_str);
+
+ return prefix;
+}
+
+void tst_get_in_addr(const char *ip_str, struct in_addr *ip)
+{
+ if (inet_pton(AF_INET, ip_str, ip) <= 0)
+ tst_brk_comment("bad IPv4 address: '%s'", ip_str);
+}
+
+void tst_get_in6_addr(const char *ip_str, struct in6_addr *ip6)
+{
+ if (inet_pton(AF_INET6, ip_str, ip6) <= 0)
+ tst_brk_comment("bad IPv6 address: '%s'", ip_str);
+}
+
+socklen_t tst_get_connect_address(int sock, struct sockaddr_storage *addr)
+{
+ struct sockaddr_in *inet_ptr;
+ struct sockaddr_in6 *inet6_ptr;
+ size_t tmp_size;
+ socklen_t ret = sizeof(*addr);
+
+ SAFE_GETSOCKNAME(sock, (struct sockaddr*)addr, &ret);
+
+ /* Sanitize wildcard addresses */
+ switch (addr->ss_family) {
+ case AF_INET:
+ inet_ptr = (struct sockaddr_in*)addr;
+
+ switch (ntohl(inet_ptr->sin_addr.s_addr)) {
+ case INADDR_ANY:
+ case INADDR_BROADCAST:
+ inet_ptr->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ break;
+ }
+
+ break;
+
+ case AF_INET6:
+ inet6_ptr = (struct sockaddr_in6*)addr;
+ tmp_size = sizeof(struct in6_addr);
+
+ if (!memcmp(&inet6_ptr->sin6_addr, &in6addr_any, tmp_size)) {
+ memcpy(&inet6_ptr->sin6_addr, &in6addr_loopback,
+ tmp_size);
+ }
+
+ break;
+ }
+
+ return ret;
+}
+
+void tst_init_sockaddr_inet(struct sockaddr_in *sa, const char *ip_str, uint16_t port)
+{
+ memset(sa, 0, sizeof(struct sockaddr_in));
+ sa->sin_family = AF_INET;
+ sa->sin_port = htons(port);
+ tst_get_in_addr(ip_str, &sa->sin_addr);
+}
+
+void tst_init_sockaddr_inet_bin(struct sockaddr_in *sa, uint32_t ip_val, uint16_t port)
+{
+ memset(sa, 0, sizeof(struct sockaddr_in));
+ sa->sin_family = AF_INET;
+ sa->sin_port = htons(port);
+ sa->sin_addr.s_addr = htonl(ip_val);
+}
+
+void tst_init_sockaddr_inet6(struct sockaddr_in6 *sa, const char *ip_str, uint16_t port)
+{
+ memset(sa, 0, sizeof(struct sockaddr_in6));
+ sa->sin6_family = AF_INET6;
+ sa->sin6_port = htons(port);
+ tst_get_in6_addr(ip_str, &sa->sin6_addr);
+}
+
+void tst_init_sockaddr_inet6_bin(struct sockaddr_in6 *sa, const struct in6_addr *ip_val, uint16_t port)
+{
+ memset(sa, 0, sizeof(struct sockaddr_in6));
+ sa->sin6_family = AF_INET6;
+ sa->sin6_port = htons(port);
+ memcpy(&sa->sin6_addr, ip_val, sizeof(struct in6_addr));
+}
+
+void safe_getaddrinfo(const char *file, const int lineno, const char *src_addr,
+ const char *port, const struct addrinfo *hints,
+ struct addrinfo **addr_info)
+{
+ int err = getaddrinfo(src_addr, port, hints, addr_info);
+
+ if (err)
+ tst_brk(TBROK, "%s:%d: getaddrinfo failed, %s", file, lineno,
+ gai_strerror(err));
+
+ if (!*addr_info)
+ tst_brk(TBROK, "%s:%d: failed to get the address", file, lineno);
+}
diff --git a/kernel/tests/lib/tst_parse_opts.c b/kernel/tests/lib/tst_parse_opts.c
new file mode 100644
index 0000000..94970e1
--- /dev/null
+++ b/kernel/tests/lib/tst_parse_opts.c
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2015 Cyril Hrubis chrubis@suse.cz
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it is
+ * free of the rightful claim of any third person regarding infringement
+ * or the like. Any license provided herein, whether implied or
+ * otherwise, applies only to this software file. Patent licenses, if
+ * any, provided herein do not apply to combinations of this program with
+ * other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "test.h"
+#include "ltp_priv.h"
+
+void tst_parse_opts(int argc, char *argv[], const option_t *user_optarg,
+ void (*user_help)(void))
+{
+ const char *msg;
+
+ msg = parse_opts(argc, argv, user_optarg, user_help);
+
+ if (msg)
+ tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+}
diff --git a/kernel/tests/lib/tst_path_has_mnt_flags.c b/kernel/tests/lib/tst_path_has_mnt_flags.c
new file mode 100644
index 0000000..154bf41
--- /dev/null
+++ b/kernel/tests/lib/tst_path_has_mnt_flags.c
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2014 Fujitsu Ltd.
+ * Author: Xing Gu <gux.fnst@cn.fujitsu.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <unistd.h>
+#include <mntent.h>
+#include <stdio.h>
+#include <string.h>
+#include "test.h"
+
+/*
+ * Check whether a path is on a filesystem that is mounted with
+ * specified flags.
+ */
+int tst_path_has_mnt_flags_(void (cleanup_fn)(void),
+ const char *path, const char *flags[])
+{
+ struct mntent *mnt;
+ size_t prefix_max = 0, prefix_len;
+ int flags_matched = 0;
+ FILE *f;
+ int i;
+ char *tmpdir = NULL;
+
+ /*
+ * Default parameter is test temporary directory
+ */
+ if (path == NULL)
+ path = tmpdir = tst_get_tmpdir();
+
+ if (access(path, F_OK) == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "tst_path_has_mnt_flags: path %s doesn't exist", path);
+ return -1;
+ }
+
+ f = setmntent("/proc/mounts", "r");
+ if (f == NULL) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "tst_path_has_mnt_flags: failed to open /proc/mounts");
+ return -1;
+ }
+
+ while ((mnt = getmntent(f))) {
+ /* ignore duplicit record for root fs */
+ if (!strcmp(mnt->mnt_fsname, "rootfs"))
+ continue;
+
+ prefix_len = strlen(mnt->mnt_dir);
+
+ if (strncmp(path, mnt->mnt_dir, prefix_len) == 0
+ && prefix_len > prefix_max) {
+ prefix_max = prefix_len;
+ flags_matched = 0;
+ i = 0;
+
+ while (flags[i] != NULL) {
+ if (hasmntopt(mnt, flags[i]) != NULL)
+ flags_matched++;
+ i++;
+ }
+ }
+ }
+
+ endmntent(f);
+
+ free(tmpdir);
+
+ return flags_matched;
+}
diff --git a/kernel/tests/lib/tst_pid.c b/kernel/tests/lib/tst_pid.c
new file mode 100644
index 0000000..9568cc9
--- /dev/null
+++ b/kernel/tests/lib/tst_pid.c
@@ -0,0 +1,64 @@
+/*
+ *
+ * Copyright (c) International Business Machines Corp., 2009
+ * Copyright (c) 2014 Oracle and/or its affiliates. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <fcntl.h>
+#include <limits.h>
+#include <sys/types.h>
+#include "test.h"
+#include "tst_pid.h"
+#include "old_safe_file_ops.h"
+
+#define PID_MAX_PATH "/proc/sys/kernel/pid_max"
+
+pid_t tst_get_unused_pid_(void (*cleanup_fn) (void))
+{
+ pid_t pid;
+
+ SAFE_FILE_SCANF(cleanup_fn, PID_MAX_PATH, "%d", &pid);
+
+ return pid;
+}
+
+int tst_get_free_pids_(void (*cleanup_fn) (void))
+{
+ FILE *f;
+ int rc, used_pids, max_pids;
+
+ f = popen("ps -eT | wc -l", "r");
+ if (!f) {
+ tst_resm(TBROK, "Could not run 'ps' to calculate used " "pids");
+ return -1;
+ }
+ rc = fscanf(f, "%i", &used_pids);
+ pclose(f);
+
+ if (rc != 1 || used_pids < 0) {
+ tst_resm(TBROK, "Could not read output of 'ps' to "
+ "calculate used pids");
+ return -1;
+ }
+
+ SAFE_FILE_SCANF(cleanup_fn, PID_MAX_PATH, "%d", &max_pids);
+
+ /* max_pids contains the maximum PID + 1,
+ * used_pids contains used PIDs + 1,
+ * so this additional '1' is eliminated by the substraction */
+ return max_pids - used_pids;
+}
diff --git a/kernel/tests/lib/tst_process_state.c b/kernel/tests/lib/tst_process_state.c
new file mode 100644
index 0000000..11790c9
--- /dev/null
+++ b/kernel/tests/lib/tst_process_state.c
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2012-2014 Cyril Hrubis chrubis@suse.cz
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it is
+ * free of the rightful claim of any third person regarding infringement
+ * or the like. Any license provided herein, whether implied or
+ * otherwise, applies only to this software file. Patent licenses, if
+ * any, provided herein do not apply to combinations of this program with
+ * other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+#include "test.h"
+#include "tst_process_state.h"
+
+int tst_process_state_wait(const char *file, const int lineno,
+ void (*cleanup_fn)(void), pid_t pid,
+ const char state, unsigned int msec_timeout)
+{
+ char proc_path[128], cur_state;
+ unsigned int msecs = 0;
+
+ snprintf(proc_path, sizeof(proc_path), "/proc/%i/stat", pid);
+
+ for (;;) {
+ safe_file_scanf(file, lineno, cleanup_fn, proc_path,
+ "%*i %*s %c", &cur_state);
+
+ if (state == cur_state)
+ break;
+
+ usleep(1000);
+ msecs += 1;
+
+ if (msec_timeout && msecs >= msec_timeout) {
+ errno = ETIMEDOUT;
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+int tst_process_state_wait2(pid_t pid, const char state)
+{
+ char proc_path[128], cur_state;
+
+ snprintf(proc_path, sizeof(proc_path), "/proc/%i/stat", pid);
+
+ for (;;) {
+ FILE *f = fopen(proc_path, "r");
+ if (!f) {
+ fprintf(stderr, "Failed to open '%s': %s\n",
+ proc_path, strerror(errno));
+ return 1;
+ }
+
+ if (fscanf(f, "%*i %*s %c", &cur_state) != 1) {
+ fclose(f);
+ fprintf(stderr, "Failed to read '%s': %s\n",
+ proc_path, strerror(errno));
+ return 1;
+ }
+ fclose(f);
+
+ if (state == cur_state)
+ return 0;
+
+ usleep(10000);
+ }
+}
diff --git a/kernel/tests/lib/tst_res.c b/kernel/tests/lib/tst_res.c
new file mode 100644
index 0000000..c35f41b
--- /dev/null
+++ b/kernel/tests/lib/tst_res.c
@@ -0,0 +1,606 @@
+/*
+ * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
+ * AUTHOR : Kent Rogers (from Dave Fenner's original)
+ * CO-PILOT : Rich Logan
+ * DATE STARTED : 05/01/90 (rewritten 1/96)
+ * Copyright (c) 2009-2016 Cyril Hrubis <chrubis@suse.cz>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it is
+ * free of the rightful claim of any third person regarding infringement
+ * or the like. Any license provided herein, whether implied or
+ * otherwise, applies only to this software file. Patent licenses, if
+ * any, provided herein do not apply to combinations of this program with
+ * other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
+ * Mountain View, CA 94043, or:
+ *
+ * http://www.sgi.com
+ *
+ * For further information regarding this notice, see:
+ *
+ * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
+ */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include "test.h"
+#include "safe_macros.h"
+#include "usctest.h"
+#include "ltp_priv.h"
+#include "tst_ansi_color.h"
+
+long TEST_RETURN;
+int TEST_ERRNO;
+void *TST_RET_PTR;
+
+#define VERBOSE 1
+#define NOPASS 3
+#define DISCARD 4
+
+#define MAXMESG 80 /* max length of internal messages */
+#define USERMESG 2048 /* max length of user message */
+#define TRUE 1
+#define FALSE 0
+
+/*
+ * EXPAND_VAR_ARGS - Expand the variable portion (arg_fmt) of a result
+ * message into the specified string.
+ *
+ * NOTE (garrcoop): arg_fmt _must_ be the last element in each function
+ * argument list that employs this.
+ */
+#define EXPAND_VAR_ARGS(buf, arg_fmt, buf_len) do {\
+ va_list ap; \
+ assert(arg_fmt != NULL); \
+ va_start(ap, arg_fmt); \
+ vsnprintf(buf, buf_len, arg_fmt, ap); \
+ va_end(ap); \
+ assert(strlen(buf) > 0); \
+} while (0)
+
+#ifndef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
+# ifdef __ANDROID__
+# define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
+ PTHREAD_RECURSIVE_MUTEX_INITIALIZER
+# else
+/* MUSL: http://www.openwall.com/lists/musl/2017/02/20/5 */
+# define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP { {PTHREAD_MUTEX_RECURSIVE} }
+# endif
+#endif
+
+static pthread_mutex_t tmutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
+
+static void check_env(void);
+static void tst_condense(int tnum, int ttype, const char *tmesg);
+static void tst_print(const char *tcid, int tnum, int ttype, const char *tmesg);
+
+static int T_exitval = 0; /* exit value used by tst_exit() */
+static int passed_cnt;
+static int T_mode = VERBOSE; /* flag indicating print mode: VERBOSE, */
+ /* NOPASS, DISCARD */
+
+static char Warn_mesg[MAXMESG]; /* holds warning messages */
+
+/*
+ * These are used for condensing output when NOT in verbose mode.
+ */
+static int Buffered = FALSE; /* TRUE if condensed output is currently */
+ /* buffered (i.e. not yet printed) */
+static char *Last_tcid; /* previous test case id */
+static int Last_num; /* previous test case number */
+static int Last_type; /* previous test result type */
+static char *Last_mesg; /* previous test result message */
+
+int tst_count = 0;
+
+/*
+ * These globals must be defined in the test.
+ */
+extern char *TCID; /* Test case identifier from the test source */
+extern int TST_TOTAL; /* Total number of test cases from the test */
+
+
+struct pair {
+ const char *name;
+ int val;
+};
+
+#define PAIR(def) [def] = {.name = #def, .val = def},
+#define STRPAIR(key, value) [key] = {.name = value, .val = key},
+
+#define PAIR_LOOKUP(pair_arr, idx) do { \
+ if (idx < 0 || (size_t)idx >= ARRAY_SIZE(pair_arr) || \
+ pair_arr[idx].name == NULL) \
+ return "???"; \
+ return pair_arr[idx].name; \
+} while (0)
+
+const char *strttype(int ttype)
+{
+ static const struct pair ttype_pairs[] = {
+ PAIR(TPASS)
+ PAIR(TFAIL)
+ PAIR(TBROK)
+ PAIR(TCONF)
+ PAIR(TWARN)
+ PAIR(TINFO)
+ };
+
+ PAIR_LOOKUP(ttype_pairs, TTYPE_RESULT(ttype));
+}
+
+#include "errnos.h"
+#include "signame.h"
+
+static void tst_res__(const char *file, const int lineno, int ttype,
+ const char *arg_fmt, ...)
+{
+ pthread_mutex_lock(&tmutex);
+
+ char tmesg[USERMESG];
+ int len = 0;
+ int ttype_result = TTYPE_RESULT(ttype);
+
+ if (file && (ttype_result != TPASS && ttype_result != TINFO))
+ len = sprintf(tmesg, "%s:%d: ", file, lineno);
+ EXPAND_VAR_ARGS(tmesg + len, arg_fmt, USERMESG - len);
+
+ /*
+ * Save the test result type by ORing ttype into the current exit
+ * value (used by tst_exit()).
+ */
+ T_exitval |= ttype_result;
+
+ if (ttype_result == TPASS)
+ passed_cnt++;
+
+ check_env();
+
+ /*
+ * Set the test case number and print the results, depending on the
+ * display type.
+ */
+ if (ttype_result == TWARN || ttype_result == TINFO) {
+ tst_print(TCID, 0, ttype, tmesg);
+ } else {
+ if (tst_count < 0)
+ tst_print(TCID, 0, TWARN,
+ "tst_res(): tst_count < 0 is not valid");
+
+ /*
+ * Process each display type.
+ */
+ switch (T_mode) {
+ case DISCARD:
+ break;
+ case NOPASS: /* filtered by tst_print() */
+ tst_condense(tst_count + 1, ttype, tmesg);
+ break;
+ default: /* VERBOSE */
+ tst_print(TCID, tst_count + 1, ttype, tmesg);
+ break;
+ }
+
+ tst_count++;
+ }
+
+ pthread_mutex_unlock(&tmutex);
+}
+
+static void tst_condense(int tnum, int ttype, const char *tmesg)
+{
+ int ttype_result = TTYPE_RESULT(ttype);
+
+ /*
+ * If this result is the same as the previous result, return.
+ */
+ if (Buffered == TRUE) {
+ if (strcmp(Last_tcid, TCID) == 0 && Last_type == ttype_result &&
+ strcmp(Last_mesg, tmesg) == 0)
+ return;
+
+ /*
+ * This result is different from the previous result. First,
+ * print the previous result.
+ */
+ tst_print(Last_tcid, Last_num, Last_type, Last_mesg);
+ free(Last_tcid);
+ free(Last_mesg);
+ }
+
+ /*
+ * If a file was specified, print the current result since we have no
+ * way of retaining the file contents for comparing with future
+ * results. Otherwise, buffer the current result info for next time.
+ */
+ Last_tcid = malloc(strlen(TCID) + 1);
+ strcpy(Last_tcid, TCID);
+ Last_num = tnum;
+ Last_type = ttype_result;
+ Last_mesg = malloc(strlen(tmesg) + 1);
+ strcpy(Last_mesg, tmesg);
+ Buffered = TRUE;
+}
+
+void tst_old_flush(void)
+{
+ NO_NEWLIB_ASSERT("Unknown", 0);
+
+ pthread_mutex_lock(&tmutex);
+
+ /*
+ * Print out last line if in NOPASS mode.
+ */
+ if (Buffered == TRUE && T_mode == NOPASS) {
+ tst_print(Last_tcid, Last_num, Last_type, Last_mesg);
+ Buffered = FALSE;
+ }
+
+ fflush(stdout);
+
+ pthread_mutex_unlock(&tmutex);
+}
+
+static void tst_print(const char *tcid, int tnum, int ttype, const char *tmesg)
+{
+ int err = errno;
+ const char *type;
+ int ttype_result = TTYPE_RESULT(ttype);
+ char message[USERMESG];
+ size_t size = 0;
+
+ /*
+ * Save the test result type by ORing ttype into the current exit value
+ * (used by tst_exit()). This is already done in tst_res(), but is
+ * also done here to catch internal warnings. For internal warnings,
+ * tst_print() is called directly with a case of TWARN.
+ */
+ T_exitval |= ttype_result;
+
+ /*
+ * If output mode is DISCARD, or if the output mode is NOPASS and this
+ * result is not one of FAIL, BROK, or WARN, just return. This check
+ * is necessary even though we check for DISCARD mode inside of
+ * tst_res(), since occasionally we get to this point without going
+ * through tst_res() (e.g. internal TWARN messages).
+ */
+ if (T_mode == DISCARD || (T_mode == NOPASS && ttype_result != TFAIL &&
+ ttype_result != TBROK
+ && ttype_result != TWARN))
+ return;
+
+ /*
+ * Build the result line and print it.
+ */
+ type = strttype(ttype);
+
+ if (T_mode == VERBOSE) {
+ size += snprintf(message + size, sizeof(message) - size,
+ "%-8s %4d ", tcid, tnum);
+ } else {
+ size += snprintf(message + size, sizeof(message) - size,
+ "%-8s %4d ", tcid, tnum);
+ }
+
+ if (size >= sizeof(message)) {
+ printf("%s: %i: line too long\n", __func__, __LINE__);
+ abort();
+ }
+
+ if (tst_color_enabled(STDOUT_FILENO))
+ size += snprintf(message + size, sizeof(message) - size,
+ "%s%s%s : %s", tst_ttype2color(ttype), type, ANSI_COLOR_RESET, tmesg);
+ else
+ size += snprintf(message + size, sizeof(message) - size,
+ "%s : %s", type, tmesg);
+
+ if (size >= sizeof(message)) {
+ printf("%s: %i: line too long\n", __func__, __LINE__);
+ abort();
+ }
+
+ if (ttype & TERRNO) {
+ size += snprintf(message + size, sizeof(message) - size,
+ ": errno=%s(%i): %s", tst_strerrno(err),
+ err, strerror(err));
+ }
+
+ if (size >= sizeof(message)) {
+ printf("%s: %i: line too long\n", __func__, __LINE__);
+ abort();
+ }
+
+ if (ttype & TTERRNO) {
+ size += snprintf(message + size, sizeof(message) - size,
+ ": TEST_ERRNO=%s(%i): %s",
+ tst_strerrno(TEST_ERRNO), (int)TEST_ERRNO,
+ strerror(TEST_ERRNO));
+ }
+
+ if (size >= sizeof(message)) {
+ printf("%s: %i: line too long\n", __func__, __LINE__);
+ abort();
+ }
+
+ if (ttype & TRERRNO) {
+ err = TEST_RETURN < 0 ? -(int)TEST_RETURN : (int)TEST_RETURN;
+ size += snprintf(message + size, sizeof(message) - size,
+ ": TEST_RETURN=%s(%i): %s",
+ tst_strerrno(err), err, strerror(err));
+ }
+
+ if (size + 1 >= sizeof(message)) {
+ printf("%s: %i: line too long\n", __func__, __LINE__);
+ abort();
+ }
+
+ message[size] = '\n';
+ message[size + 1] = '\0';
+
+ fputs(message, stdout);
+}
+
+static void check_env(void)
+{
+ static int first_time = 1;
+ char *value;
+
+ if (!first_time)
+ return;
+
+ first_time = 0;
+
+ /* BTOUTPUT not defined, use default */
+ if ((value = getenv(TOUTPUT)) == NULL) {
+ T_mode = VERBOSE;
+ return;
+ }
+
+ if (strcmp(value, TOUT_NOPASS_S) == 0) {
+ T_mode = NOPASS;
+ return;
+ }
+
+ if (strcmp(value, TOUT_DISCARD_S) == 0) {
+ T_mode = DISCARD;
+ return;
+ }
+
+ T_mode = VERBOSE;
+ return;
+}
+
+void tst_exit(void)
+{
+ NO_NEWLIB_ASSERT("Unknown", 0);
+
+ pthread_mutex_lock(&tmutex);
+
+ tst_old_flush();
+
+ T_exitval &= ~TINFO;
+
+ if (T_exitval == TCONF && passed_cnt)
+ T_exitval &= ~TCONF;
+
+ exit(T_exitval);
+}
+
+pid_t tst_fork(void)
+{
+ pid_t child;
+
+ NO_NEWLIB_ASSERT("Unknown", 0);
+
+ tst_old_flush();
+
+ child = fork();
+ if (child == 0)
+ T_exitval = 0;
+
+ return child;
+}
+
+void tst_record_childstatus(void (*cleanup)(void), pid_t child)
+{
+ int status, ttype_result;
+
+ NO_NEWLIB_ASSERT("Unknown", 0);
+
+ SAFE_WAITPID(cleanup, child, &status, 0);
+
+ if (WIFEXITED(status)) {
+ ttype_result = WEXITSTATUS(status);
+ ttype_result = TTYPE_RESULT(ttype_result);
+ T_exitval |= ttype_result;
+
+ if (ttype_result == TPASS)
+ tst_resm(TINFO, "Child process returned TPASS");
+
+ if (ttype_result & TFAIL)
+ tst_resm(TINFO, "Child process returned TFAIL");
+
+ if (ttype_result & TBROK)
+ tst_resm(TINFO, "Child process returned TBROK");
+
+ if (ttype_result & TCONF)
+ tst_resm(TINFO, "Child process returned TCONF");
+
+ } else {
+ tst_brkm(TBROK, cleanup, "child process(%d) killed by "
+ "unexpected signal %s(%d)", child,
+ tst_strsig(WTERMSIG(status)), WTERMSIG(status));
+ }
+}
+
+pid_t tst_vfork(void)
+{
+ NO_NEWLIB_ASSERT("Unknown", 0);
+
+ tst_old_flush();
+ return vfork();
+}
+
+/*
+ * Make tst_brk reentrant so that one can call the SAFE_* macros from within
+ * user-defined cleanup functions.
+ */
+static int tst_brk_entered = 0;
+
+static void tst_brk__(const char *file, const int lineno, int ttype,
+ void (*func)(void), const char *arg_fmt, ...)
+{
+ pthread_mutex_lock(&tmutex);
+
+ char tmesg[USERMESG];
+ int ttype_result = TTYPE_RESULT(ttype);
+
+ EXPAND_VAR_ARGS(tmesg, arg_fmt, USERMESG);
+
+ /*
+ * Only FAIL, BROK, CONF, and RETR are supported by tst_brk().
+ */
+ if (ttype_result != TFAIL && ttype_result != TBROK &&
+ ttype_result != TCONF) {
+ sprintf(Warn_mesg, "%s: Invalid Type: %d. Using TBROK",
+ __func__, ttype_result);
+ tst_print(TCID, 0, TWARN, Warn_mesg);
+ /* Keep TERRNO, TTERRNO, etc. */
+ ttype = (ttype & ~ttype_result) | TBROK;
+ }
+
+ tst_res__(file, lineno, ttype, "%s", tmesg);
+ if (tst_brk_entered == 0) {
+ if (ttype_result == TCONF) {
+ tst_res__(file, lineno, ttype,
+ "Remaining cases not appropriate for "
+ "configuration");
+ } else if (ttype_result == TBROK) {
+ tst_res__(file, lineno, TBROK,
+ "Remaining cases broken");
+ }
+ }
+
+ /*
+ * If no cleanup function was specified, just return to the caller.
+ * Otherwise call the specified function.
+ */
+ if (func != NULL) {
+ tst_brk_entered++;
+ (*func) ();
+ tst_brk_entered--;
+ }
+ if (tst_brk_entered == 0)
+ tst_exit();
+
+ pthread_mutex_unlock(&tmutex);
+}
+
+void tst_resm_(const char *file, const int lineno, int ttype,
+ const char *arg_fmt, ...)
+{
+ char tmesg[USERMESG];
+
+ EXPAND_VAR_ARGS(tmesg, arg_fmt, USERMESG);
+
+ if (tst_test)
+ tst_res_(file, lineno, ttype, "%s", tmesg);
+ else
+ tst_res__(file, lineno, ttype, "%s", tmesg);
+}
+
+typedef void (*tst_res_func_t)(const char *file, const int lineno,
+ int ttype, const char *fmt, ...);
+
+void tst_resm_hexd_(const char *file, const int lineno, int ttype,
+ const void *buf, size_t size, const char *arg_fmt, ...)
+{
+ char tmesg[USERMESG];
+ static const size_t symb_num = 2; /* xx */
+ static const size_t size_max = 16;
+ size_t offset;
+ size_t i;
+ char *pmesg = tmesg;
+ tst_res_func_t res_func;
+
+ if (tst_test)
+ res_func = tst_res_;
+ else
+ res_func = tst_res__;
+
+ EXPAND_VAR_ARGS(tmesg, arg_fmt, USERMESG);
+ offset = strlen(tmesg);
+
+ if (size > size_max || size == 0 ||
+ (offset + size * (symb_num + 1)) >= USERMESG)
+ res_func(file, lineno, ttype, "%s", tmesg);
+ else
+ pmesg += offset;
+
+ for (i = 0; i < size; ++i) {
+ /* add space before byte except first one */
+ if (pmesg != tmesg)
+ *(pmesg++) = ' ';
+
+ sprintf(pmesg, "%02x", ((unsigned char *)buf)[i]);
+ pmesg += symb_num;
+ if ((i + 1) % size_max == 0 || i + 1 == size) {
+ res_func(file, lineno, ttype, "%s", tmesg);
+ pmesg = tmesg;
+ }
+ }
+}
+
+void tst_brkm_(const char *file, const int lineno, int ttype,
+ void (*func)(void), const char *arg_fmt, ...)
+{
+ char tmesg[USERMESG];
+
+ EXPAND_VAR_ARGS(tmesg, arg_fmt, USERMESG);
+
+ if (tst_test) {
+ if (func) {
+ tst_brk_(file, lineno, TBROK,
+ "Non-NULL cleanup in newlib!");
+ }
+
+ tst_brk_(file, lineno, ttype, "%s", tmesg);
+ } else {
+ tst_brk__(file, lineno, ttype, func, "%s", tmesg);
+ }
+
+ /* Shouldn't be reached, but fixes build time warnings about noreturn. */
+ abort();
+}
+
+void tst_require_root(void)
+{
+ NO_NEWLIB_ASSERT("Unknown", 0);
+
+ if (geteuid() != 0)
+ tst_brkm(TCONF, NULL, "Test needs to be run as root");
+}
diff --git a/kernel/tests/lib/tst_resource.c b/kernel/tests/lib/tst_resource.c
new file mode 100644
index 0000000..0b9b381
--- /dev/null
+++ b/kernel/tests/lib/tst_resource.c
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2012 Cyril Hrubis chrubis@suse.cz
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it is
+ * free of the rightful claim of any third person regarding infringement
+ * or the like. Any license provided herein, whether implied or
+ * otherwise, applies only to this software file. Patent licenses, if
+ * any, provided herein do not apply to combinations of this program with
+ * other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <pthread.h>
+#include "test.h"
+#include "old_resource.h"
+#include "ltp_priv.h"
+
+#ifndef PATH_MAX
+#ifdef MAXPATHLEN
+#define PATH_MAX MAXPATHLEN
+#else
+#define PATH_MAX 1024
+#endif
+#endif
+
+static pthread_mutex_t tmutex = PTHREAD_MUTEX_INITIALIZER;
+static char dataroot[PATH_MAX];
+extern char *TCID;
+
+static void tst_dataroot_init(void)
+{
+ const char *ltproot = getenv("LTPROOT");
+ char curdir[PATH_MAX];
+ const char *startdir;
+ int ret;
+
+ /* 1. if LTPROOT is set, use $LTPROOT/testcases/data/$TCID
+ * 2. else if startwd is set by tst_tmpdir(), use $STARWD/datafiles
+ * 3. else use $CWD/datafiles */
+ if (ltproot) {
+ ret = snprintf(dataroot, PATH_MAX, "%s/testcases/data/%s",
+ ltproot, TCID);
+ } else {
+ startdir = tst_get_startwd();
+ if (startdir[0] == 0) {
+ if (getcwd(curdir, PATH_MAX) == NULL) {
+ tst_brkm(TBROK | TERRNO, NULL,
+ "tst_dataroot getcwd");
+ return;
+ }
+ startdir = curdir;
+ }
+ ret = snprintf(dataroot, PATH_MAX, "%s/datafiles", startdir);
+ }
+
+ if (ret < 0 || ret >= PATH_MAX)
+ tst_brkm(TBROK, NULL, "tst_dataroot snprintf: %d", ret);
+}
+
+const char *tst_dataroot(void)
+{
+ if (dataroot[0] == 0) {
+ pthread_mutex_lock(&tmutex);
+ if (dataroot[0] == 0)
+ tst_dataroot_init();
+ pthread_mutex_unlock(&tmutex);
+ }
+ return dataroot;
+}
+
+static int file_copy(const char *file, const int lineno,
+ void (*cleanup_fn)(void), const char *path,
+ const char *filename, const char *dest)
+{
+ size_t len = strlen(path) + strlen(filename) + 2;
+ char buf[len];
+
+ snprintf(buf, sizeof(buf), "%s/%s", path, filename);
+
+ /* check if file exists */
+ if (access(buf, R_OK))
+ return 0;
+
+ safe_cp(file, lineno, cleanup_fn, buf, dest);
+
+ return 1;
+}
+
+void tst_resource_copy(const char *file, const int lineno,
+ void (*cleanup_fn)(void),
+ const char *filename, const char *dest)
+{
+ if (!tst_tmpdir_created()) {
+ tst_brkm(TBROK, cleanup_fn,
+ "Temporary directory doesn't exist at %s:%d",
+ file, lineno);
+ return;
+ }
+
+ if (dest == NULL)
+ dest = ".";
+
+ const char *ltproot = getenv("LTPROOT");
+ const char *dataroot = tst_dataroot();
+
+ /* look for data files in $LTP_DATAROOT, $LTPROOT/testcases/bin
+ * and $CWD */
+ if (file_copy(file, lineno, cleanup_fn, dataroot, filename, dest))
+ return;
+
+ if (ltproot != NULL) {
+ char buf[strlen(ltproot) + 64];
+
+ snprintf(buf, sizeof(buf), "%s/testcases/bin", ltproot);
+
+ if (file_copy(file, lineno, cleanup_fn, buf, filename, dest))
+ return;
+ }
+
+ /* try directory test started in as last resort */
+ const char *startwd = tst_get_startwd();
+ if (file_copy(file, lineno, cleanup_fn, startwd, filename, dest))
+ return;
+
+ tst_brkm(TBROK, cleanup_fn, "Failed to copy resource '%s' at %s:%d",
+ filename, file, lineno);
+}
diff --git a/kernel/tests/lib/tst_safe_macros.c b/kernel/tests/lib/tst_safe_macros.c
new file mode 100644
index 0000000..25c37df
--- /dev/null
+++ b/kernel/tests/lib/tst_safe_macros.c
@@ -0,0 +1,333 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#define _GNU_SOURCE
+#include <unistd.h>
+#include <errno.h>
+#include <sched.h>
+#include <sys/ptrace.h>
+#include "config.h"
+#ifdef HAVE_SYS_FANOTIFY_H
+# include <sys/fanotify.h>
+#endif
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+#include "lapi/setns.h"
+#include "tst_safe_macros.h"
+#include "lapi/personality.h"
+
+int safe_setpgid(const char *file, const int lineno, pid_t pid, pid_t pgid)
+{
+ int rval;
+
+ rval = setpgid(pid, pgid);
+ if (rval) {
+ tst_brk(TBROK | TERRNO,
+ "%s:%d: setpgid(%i, %i) failed",
+ file, lineno, pid, pgid);
+ }
+
+ return rval;
+}
+
+pid_t safe_getpgid(const char *file, const int lineno, pid_t pid)
+{
+ pid_t pgid;
+
+ pgid = getpgid(pid);
+ if (pgid == -1) {
+ tst_brk(TBROK | TERRNO,
+ "%s:%d: getpgid(%i) failed", file, lineno, pid);
+ }
+
+ return pgid;
+}
+
+int safe_fanotify_init(const char *file, const int lineno,
+ unsigned int flags, unsigned int event_f_flags)
+{
+ int rval;
+
+#ifdef HAVE_SYS_FANOTIFY_H
+ rval = fanotify_init(flags, event_f_flags);
+
+ if (rval == -1) {
+ if (errno == ENOSYS) {
+ tst_brk(TCONF,
+ "fanotify is not configured in this kernel.");
+ }
+ tst_brk(TBROK | TERRNO,
+ "%s:%d: fanotify_init() failed", file, lineno);
+ }
+#else
+ tst_brk(TCONF, "Header <sys/fanotify.h> is not present");
+#endif /* HAVE_SYS_FANOTIFY_H */
+
+ return rval;
+}
+
+int safe_personality(const char *filename, unsigned int lineno,
+ unsigned long persona)
+{
+ int prev_persona = personality(persona);
+
+ if (prev_persona < 0) {
+ tst_brk_(filename, lineno, TBROK | TERRNO,
+ "persona(%ld) failed", persona);
+ }
+
+ return prev_persona;
+}
+
+int safe_setregid(const char *file, const int lineno,
+ gid_t rgid, gid_t egid)
+{
+ int rval;
+
+ rval = setregid(rgid, egid);
+ if (rval == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "setregid(%li, %li) failed",
+ (long)rgid, (long)egid);
+ }
+
+ return rval;
+}
+
+
+int safe_setreuid(const char *file, const int lineno,
+ uid_t ruid, uid_t euid)
+{
+ int rval;
+
+ rval = setreuid(ruid, euid);
+ if (rval == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "setreuid(%li, %li) failed",
+ (long)ruid, (long)euid);
+ }
+
+ return rval;
+}
+
+
+int safe_sigaction(const char *file, const int lineno,
+ int signum, const struct sigaction *act,
+ struct sigaction *oldact)
+{
+ int rval;
+
+ rval = sigaction(signum, act, oldact);
+
+ if (rval == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "sigaction(%s (%d), %p, %p) failed",
+ tst_strsig(signum), signum, act, oldact);
+ }
+
+ return rval;
+}
+
+void safe_sigaddset(const char *file, const int lineno,
+ sigset_t *sigs, int signo)
+{
+ int rval;
+
+ rval = sigaddset(sigs, signo);
+ if (rval == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "sigaddset() %s (%i) failed",
+ tst_strsig(signo), signo);
+ }
+}
+
+void safe_sigdelset(const char *file, const int lineno,
+ sigset_t *sigs, int signo)
+{
+ int rval;
+
+ rval = sigdelset(sigs, signo);
+ if (rval == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "sigdelset() %s (%i) failed",
+ tst_strsig(signo), signo);
+ }
+}
+
+void safe_sigemptyset(const char *file, const int lineno,
+ sigset_t *sigs)
+{
+ int rval;
+
+ rval = sigemptyset(sigs);
+ if (rval == -1)
+ tst_brk_(file, lineno, TBROK | TERRNO, "sigemptyset() failed");
+}
+
+void safe_sigfillset(const char *file, const int lineno,
+ sigset_t *sigs)
+{
+ int rval;
+
+ rval = sigfillset(sigs);
+ if (rval == -1)
+ tst_brk_(file, lineno, TBROK | TERRNO, "sigfillset() failed");
+}
+
+static const char *strhow(int how)
+{
+ switch (how) {
+ case SIG_BLOCK:
+ return "SIG_BLOCK";
+ case SIG_UNBLOCK:
+ return "SIG_UNBLOCK";
+ case SIG_SETMASK:
+ return "SIG_SETMASK";
+ default:
+ return "???";
+ }
+}
+
+void safe_sigprocmask(const char *file, const int lineno,
+ int how, sigset_t *set, sigset_t *oldset)
+{
+ int rval;
+
+ rval = sigprocmask(how, set, oldset);
+ if (rval == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "sigprocmask(%s, %p, %p)", strhow(how), set, oldset);
+ }
+}
+
+void safe_sigwait(const char *file, const int lineno,
+ sigset_t *set, int *sig)
+{
+ int rval;
+
+ rval = sigwait(set, sig);
+ if (rval != 0) {
+ errno = rval;
+ tst_brk_(file, lineno, TBROK, "sigwait(%p, %p)", set, sig);
+ }
+}
+
+struct group *safe_getgrnam(const char *file, const int lineno,
+ const char *name)
+{
+ struct group *rval;
+
+ errno = 0;
+ rval = getgrnam(name);
+ if (rval == NULL) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "getgrnam(%s) failed", name);
+ }
+
+ return rval;
+}
+
+struct group *safe_getgrnam_fallback(const char *file, const int lineno,
+ const char *name, const char *fallback)
+{
+ struct group *rval;
+
+ errno = 0;
+ rval = getgrnam(name);
+ if (rval == NULL) {
+ tst_res_(file, lineno, TINFO,
+ "getgrnam(%s) failed - try fallback %s",
+ name, fallback);
+ rval = safe_getgrnam(file, lineno, fallback);
+ }
+
+ return rval;
+}
+
+struct group *safe_getgrgid(const char *file, const int lineno, gid_t gid)
+{
+ struct group *rval;
+
+ errno = 0;
+ rval = getgrgid(gid);
+ if (rval == NULL) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "getgrgid(%li) failed", (long)gid);
+ }
+
+ return rval;
+}
+
+int safe_chroot(const char *file, const int lineno, const char *path)
+{
+ int rval;
+
+ rval = chroot(path);
+ if (rval == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "chroot(%s) failed", path);
+ }
+
+ return rval;
+}
+
+void safe_unshare(const char *file, const int lineno, int flags)
+{
+ int res;
+
+ res = unshare(flags);
+ if (res == -1) {
+ if (errno == EINVAL) {
+ tst_brk_(file, lineno, TCONF | TERRNO,
+ "unshare(%d) unsupported", flags);
+ } else {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "unshare(%d) failed", flags);
+ }
+ }
+}
+
+void safe_setns(const char *file, const int lineno, int fd, int nstype)
+{
+ int ret;
+
+ ret = setns(fd, nstype);
+ if (ret == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO, "setns(%i, %i) failed",
+ fd, nstype);
+ }
+}
+
+long tst_safe_ptrace(const char *file, const int lineno, int req, pid_t pid,
+ void *addr, void *data)
+{
+ long ret;
+
+ errno = 0;
+ ret = ptrace(req, pid, addr, data);
+
+ if (ret == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO, "ptrace() failed");
+ } else if (ret) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "Invalid ptrace() return value %ld", ret);
+ }
+
+ return ret;
+}
+
+int safe_pipe2(const char *file, const int lineno, int fildes[2], int flags)
+{
+ int ret;
+
+ ret = pipe2(fildes, flags);
+ if (ret == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "pipe2({%d,%d}) failed with flag(%d)",
+ fildes[0], fildes[1], flags);
+ }
+
+ return ret;
+}
diff --git a/kernel/tests/lib/tst_safe_sysv_ipc.c b/kernel/tests/lib/tst_safe_sysv_ipc.c
new file mode 100644
index 0000000..30b5f6e
--- /dev/null
+++ b/kernel/tests/lib/tst_safe_sysv_ipc.c
@@ -0,0 +1,145 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2017 Xiao yang <yangx.jy@cn.fujitsu.com>
+ */
+
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <sys/shm.h>
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+#include "tst_safe_sysv_ipc.h"
+
+/*
+ * The IPC_STAT, IPC_SET and IPC_RMID can return either 0 or -1.
+ *
+ * Linux specific cmds either returns -1 on failure or positive integer
+ * either index into an kernel array or shared primitive indentifier.
+ */
+static int ret_check(int cmd, int ret)
+{
+ switch (cmd) {
+ case IPC_STAT:
+ case IPC_SET:
+ case IPC_RMID:
+ return ret != 0;
+ default:
+ return ret == -1;
+ }
+}
+
+int safe_msgget(const char *file, const int lineno, key_t key, int msgflg)
+{
+ int rval;
+
+ rval = msgget(key, msgflg);
+ if (rval == -1) {
+ tst_brk(TBROK | TERRNO, "%s:%d: msgget(%i, %x) failed",
+ file, lineno, (int)key, msgflg);
+ }
+
+ return rval;
+}
+
+int safe_msgsnd(const char *file, const int lineno, int msqid, const void *msgp,
+ size_t msgsz, int msgflg)
+{
+ int rval;
+
+ rval = msgsnd(msqid, msgp, msgsz, msgflg);
+ if (rval == -1) {
+ tst_brk(TBROK | TERRNO,
+ "%s:%d: msgsnd(%i, %p, %zu, %x) failed",
+ file, lineno, msqid, msgp, msgsz, msgflg);
+ }
+
+ return rval;
+}
+
+ssize_t safe_msgrcv(const char *file, const int lineno, int msqid, void *msgp,
+ size_t msgsz, long msgtyp, int msgflg)
+{
+ ssize_t rval;
+
+ rval = msgrcv(msqid, msgp, msgsz, msgtyp, msgflg);
+ if (rval == -1) {
+ tst_brk(TBROK | TERRNO,
+ "%s:%d: msgrcv(%i, %p, %zu, %li, %x) failed",
+ file, lineno, msqid, msgp, msgsz, msgtyp, msgflg);
+ }
+
+ return rval;
+}
+
+int safe_msgctl(const char *file, const int lineno, int msqid, int cmd,
+ struct msqid_ds *buf)
+{
+ int rval;
+
+ rval = msgctl(msqid, cmd, buf);
+ if (ret_check(cmd, rval)) {
+ tst_brk(TBROK | TERRNO,
+ "%s:%d: msgctl(%i, %i, %p) = %i failed",
+ file, lineno, msqid, cmd, buf, rval);
+ }
+
+
+ return rval;
+}
+
+int safe_shmget(const char *file, const int lineno, key_t key, size_t size,
+ int shmflg)
+{
+ int rval;
+
+ rval = shmget(key, size, shmflg);
+ if (rval == -1) {
+ tst_brk(TBROK | TERRNO, "%s:%d: shmget(%i, %zu, %x) failed",
+ file, lineno, (int)key, size, shmflg);
+ }
+
+ return rval;
+}
+
+void *safe_shmat(const char *file, const int lineno, int shmid,
+ const void *shmaddr, int shmflg)
+{
+ void *rval;
+
+ rval = shmat(shmid, shmaddr, shmflg);
+ if (rval == (void *)-1) {
+ tst_brk(TBROK | TERRNO, "%s:%d: shmat(%i, %p, %x) failed",
+ file, lineno, shmid, shmaddr, shmflg);
+ }
+
+ return rval;
+}
+
+int safe_shmdt(const char *file, const int lineno, const void *shmaddr)
+{
+ int rval;
+
+ rval = shmdt(shmaddr);
+ if (rval == -1) {
+ tst_brk(TBROK | TERRNO, "%s:%d: shmdt(%p) failed",
+ file, lineno, shmaddr);
+ }
+
+ return rval;
+}
+
+int safe_shmctl(const char *file, const int lineno, int shmid, int cmd,
+ struct shmid_ds *buf)
+{
+ int rval;
+
+ rval = shmctl(shmid, cmd, buf);
+ if (ret_check(cmd, rval)) {
+ tst_brk(TBROK | TERRNO,
+ "%s:%d: shmctl(%i, %i, %p) = %i failed",
+ file, lineno, shmid, cmd, buf, rval);
+ }
+
+ return rval;
+}
diff --git a/kernel/tests/lib/tst_safe_timerfd.c b/kernel/tests/lib/tst_safe_timerfd.c
new file mode 100644
index 0000000..ffe7b2e
--- /dev/null
+++ b/kernel/tests/lib/tst_safe_timerfd.c
@@ -0,0 +1,56 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Petr Vorel <pvorel@suse.cz>
+ */
+
+#include "tst_safe_timerfd.h"
+#include "lapi/timerfd.h"
+#include "tst_clocks.h"
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+
+#define TTYPE (errno == ENOTSUP ? TCONF : TBROK)
+
+int safe_timerfd_create(const char *file, const int lineno,
+ int clockid, int flags)
+{
+ int fd;
+
+ fd = timerfd_create(clockid, flags);
+ if (fd < 0) {
+ tst_brk(TTYPE | TERRNO, "%s:%d timerfd_create(%s) failed",
+ file, lineno, tst_clock_name(clockid));
+ }
+
+ return fd;
+}
+
+int safe_timerfd_gettime(const char *file, const int lineno,
+ int fd, struct itimerspec *curr_value)
+{
+ int rval;
+
+ rval = timerfd_gettime(fd, curr_value);
+ if (rval != 0) {
+ tst_brk(TTYPE | TERRNO, "%s:%d timerfd_gettime() failed",
+ file, lineno);
+ }
+
+ return rval;
+}
+
+int safe_timerfd_settime(const char *file, const int lineno,
+ int fd, int flags,
+ const struct itimerspec *new_value,
+ struct itimerspec *old_value)
+{
+ int rval;
+
+ rval = timerfd_settime(fd, flags, new_value, old_value);
+ if (rval != 0) {
+ tst_brk(TTYPE | TERRNO, "%s:%d timerfd_settime() failed",
+ file, lineno);
+ }
+
+ return rval;
+}
diff --git a/kernel/tests/lib/tst_sig.c b/kernel/tests/lib/tst_sig.c
new file mode 100644
index 0000000..6d77aea
--- /dev/null
+++ b/kernel/tests/lib/tst_sig.c
@@ -0,0 +1,255 @@
+/*
+ * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it is
+ * free of the rightful claim of any third person regarding infringement
+ * or the like. Any license provided herein, whether implied or
+ * otherwise, applies only to this software file. Patent licenses, if
+ * any, provided herein do not apply to combinations of this program with
+ * other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
+ * Mountain View, CA 94043, or:
+ *
+ * http://www.sgi.com
+ *
+ * For further information regarding this notice, see:
+ *
+ * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
+ */
+
+/* $Id: tst_sig.c,v 1.13 2009/08/28 09:29:01 vapier Exp $ */
+
+/*****************************************************************************
+ OS Testing - Silicon Graphics, Inc.
+
+ FUNCTION IDENTIFIER : tst_sig Set up for unexpected signals.
+
+ AUTHOR : David D. Fenner
+
+ CO-PILOT : Bill Roske
+
+ DATE STARTED : 06/06/90
+
+ This module may be linked with c-modules requiring unexpected
+ signal handling. The parameters to tst_sig are as follows:
+
+ fork_flag - set to FORK or NOFORK depending upon whether the
+ calling program executes a fork() system call. It
+ is normally the case that the calling program treats
+ SIGCHLD as an expected signal if fork() is being used.
+
+ handler - a pointer to the unexpected signal handler to
+ be executed after an unexpected signal has been
+ detected. If handler is set to DEF_HANDLER, a
+ default handler is used. This routine should be
+ declared as function returning an int.
+
+ cleanup - a pointer to a cleanup routine to be executed
+ by the unexpected signal handler before tst_exit is
+ called. This parameter is set to NULL if no cleanup
+ routine is required. An external variable, T_cleanup
+ is set so that other user-defined handlers have
+ access to the cleanup routine. This routine should be
+ declared as returning type void.
+
+***************************************************************************/
+
+#include <errno.h>
+#include <string.h>
+#include <signal.h>
+#include <unistd.h>
+#include "test.h"
+#include "lapi/signal.h"
+
+#define MAXMESG 150 /* size of mesg string sent to tst_res */
+
+static void (*T_cleanup) ();
+
+static void def_handler(); /* default signal handler */
+static void (*tst_setup_signal(int, void (*)(int))) (int);
+
+/****************************************************************************
+ * tst_sig() : set-up to catch unexpected signals. fork_flag is set to NOFORK
+ * if SIGCHLD is to be an "unexpected signal", otherwise it is set to
+ * FORK. cleanup points to a cleanup routine to be executed before
+ * tst_exit is called (cleanup is set to NULL if no cleanup is desired).
+ * handler is a pointer to the signal handling routine (if handler is
+ * set to NULL, a default handler is used).
+ ***************************************************************************/
+
+void tst_sig(int fork_flag, void (*handler) (), void (*cleanup) ())
+{
+ int sig;
+#ifdef _SC_SIGRT_MIN
+ long sigrtmin, sigrtmax;
+#endif
+
+ /*
+ * save T_cleanup and handler function pointers
+ */
+ T_cleanup = cleanup; /* used by default handler */
+
+ if (handler == DEF_HANDLER) {
+ /* use default handler */
+ handler = def_handler;
+ }
+#ifdef _SC_SIGRT_MIN
+ sigrtmin = sysconf(_SC_SIGRT_MIN);
+ sigrtmax = sysconf(_SC_SIGRT_MAX);
+#endif
+
+ /*
+ * now loop through all signals and set the handlers
+ */
+
+ for (sig = 1; sig < NSIG; sig++) {
+ /*
+ * SIGKILL is never unexpected.
+ * SIGCHLD is only unexpected when
+ * no forking is being done.
+ * SIGINFO is used for file quotas and should be expected
+ */
+
+#ifdef _SC_SIGRT_MIN
+ if (sig >= sigrtmin && sig <= sigrtmax)
+ continue;
+#endif
+
+ switch (sig) {
+ case SIGKILL:
+ case SIGSTOP:
+ case SIGCONT:
+#if !defined(_SC_SIGRT_MIN) && defined(__SIGRTMIN) && defined(__SIGRTMAX)
+ /* Ignore all real-time signals */
+ case __SIGRTMIN:
+ case __SIGRTMIN + 1:
+ case __SIGRTMIN + 2:
+ case __SIGRTMIN + 3:
+ case __SIGRTMIN + 4:
+ case __SIGRTMIN + 5:
+ case __SIGRTMIN + 6:
+ case __SIGRTMIN + 7:
+ case __SIGRTMIN + 8:
+ case __SIGRTMIN + 9:
+ case __SIGRTMIN + 10:
+ case __SIGRTMIN + 11:
+ case __SIGRTMIN + 12:
+ case __SIGRTMIN + 13:
+ case __SIGRTMIN + 14:
+ case __SIGRTMIN + 15:
+/* __SIGRTMIN is 37 on HPPA rather than 32 *
+ * as on i386, etc. */
+#if !defined(__hppa__)
+ case __SIGRTMAX - 15:
+ case __SIGRTMAX - 14:
+ case __SIGRTMAX - 13:
+ case __SIGRTMAX - 12:
+ case __SIGRTMAX - 11:
+#endif
+ case __SIGRTMAX - 10:
+ case __SIGRTMAX - 9:
+ case __SIGRTMAX - 8:
+ case __SIGRTMAX - 7:
+ case __SIGRTMAX - 6:
+ case __SIGRTMAX - 5:
+ case __SIGRTMAX - 4:
+ case __SIGRTMAX - 3:
+ case __SIGRTMAX - 2:
+ case __SIGRTMAX - 1:
+ case __SIGRTMAX:
+#endif
+#ifdef SIGSWAP
+ case SIGSWAP:
+#endif /* SIGSWAP */
+
+#ifdef SIGCKPT
+ case SIGCKPT:
+#endif
+#ifdef SIGRESTART
+ case SIGRESTART:
+#endif
+ /*
+ * pthread-private signals SIGPTINTR and SIGPTRESCHED.
+ * Setting a handler for these signals is disallowed when
+ * the binary is linked against libpthread.
+ */
+#ifdef SIGPTINTR
+ case SIGPTINTR:
+#endif /* SIGPTINTR */
+#ifdef SIGPTRESCHED
+ case SIGPTRESCHED:
+#endif /* SIGPTRESCHED */
+#ifdef _SIGRESERVE
+ case _SIGRESERVE:
+#endif
+#ifdef _SIGDIL
+ case _SIGDIL:
+#endif
+#ifdef _SIGCANCEL
+ case _SIGCANCEL:
+#endif
+#ifdef _SIGGFAULT
+ case _SIGGFAULT:
+#endif
+ break;
+
+ case SIGCHLD:
+ if (fork_flag == FORK)
+ continue;
+
+ default:
+ if (tst_setup_signal(sig, handler) == SIG_ERR)
+ tst_resm(TWARN | TERRNO,
+ "signal failed for signal %d", sig);
+ break;
+ }
+ }
+}
+
+/****************************************************************************
+ * def_handler() : default signal handler that is invoked when
+ * an unexpected signal is caught.
+ ***************************************************************************/
+
+static void def_handler(int sig)
+{
+ /*
+ * Break remaining test cases, do any cleanup, then exit
+ */
+ tst_brkm(TBROK, T_cleanup,
+ "unexpected signal %s(%d) received (pid = %d).",
+ tst_strsig(sig), sig, getpid());
+}
+
+/*
+ * tst_setup_signal - A function like signal(), but we have
+ * control over its personality.
+ */
+static void (*tst_setup_signal(int sig, void (*handler) (int))) (int) {
+ struct sigaction my_act, old_act;
+ int ret;
+
+ my_act.sa_handler = handler;
+ my_act.sa_flags = SA_RESTART;
+ sigemptyset(&my_act.sa_mask);
+
+ ret = sigaction(sig, &my_act, &old_act);
+
+ if (ret == 0)
+ return old_act.sa_handler;
+ else
+ return SIG_ERR;
+}
diff --git a/kernel/tests/lib/tst_sig_proc.c b/kernel/tests/lib/tst_sig_proc.c
new file mode 100644
index 0000000..509418a
--- /dev/null
+++ b/kernel/tests/lib/tst_sig_proc.c
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2016 Linux Test Project
+ */
+
+#include <stdlib.h>
+#include <sys/types.h>
+
+#include "tst_sig_proc.h"
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+
+pid_t create_sig_proc(int sig, int count, unsigned int usec)
+{
+ pid_t pid, cpid;
+
+ pid = getpid();
+ cpid = SAFE_FORK();
+
+ if (cpid == 0) {
+ while (count-- > 0) {
+ usleep(usec);
+ if (kill(pid, sig) == -1)
+ break;
+ }
+ exit(0);
+ }
+
+ return cpid;
+}
diff --git a/kernel/tests/lib/tst_status.c b/kernel/tests/lib/tst_status.c
new file mode 100644
index 0000000..f1affea
--- /dev/null
+++ b/kernel/tests/lib/tst_status.c
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <stdio.h>
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+
+static char buf[32];
+
+const char *exited(int status)
+{
+ snprintf(buf, sizeof(buf), "exited with %i", WEXITSTATUS(status));
+
+ return buf;
+}
+
+const char *signaled(int status)
+{
+ snprintf(buf, sizeof(buf), "killed by %s", tst_strsig(status));
+
+ return buf;
+}
+
+const char *invalid(int status)
+{
+ snprintf(buf, sizeof(buf), "invalid status 0x%x", status);
+
+ return buf;
+}
+
+const char *tst_strstatus(int status)
+{
+ if (WIFEXITED(status))
+ return exited(status);
+
+ if (WIFSIGNALED(status))
+ return signaled(status);
+
+ if (WIFSTOPPED(status))
+ return "is stopped";
+
+ if (WIFCONTINUED(status))
+ return "is resumed";
+
+ return invalid(status);
+}
diff --git a/kernel/tests/lib/tst_supported_fs_types.c b/kernel/tests/lib/tst_supported_fs_types.c
new file mode 100644
index 0000000..00ede54
--- /dev/null
+++ b/kernel/tests/lib/tst_supported_fs_types.c
@@ -0,0 +1,111 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <sys/mount.h>
+#include <sys/wait.h>
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+#include "tst_fs.h"
+
+static const char *const fs_type_whitelist[] = {
+ "ext2",
+ "ext3",
+ "ext4",
+ "xfs",
+ "btrfs",
+ "vfat",
+ "exfat",
+ "ntfs",
+ NULL
+};
+
+static const char *fs_types[ARRAY_SIZE(fs_type_whitelist)];
+
+static int has_mkfs(const char *fs_type)
+{
+ char buf[128];
+ int ret;
+
+ sprintf(buf, "mkfs.%s >/dev/null 2>&1", fs_type);
+
+ ret = tst_system(buf);
+
+ if (WEXITSTATUS(ret) == 127) {
+ tst_res(TINFO, "mkfs.%s does not exist", fs_type);
+ return 0;
+ }
+
+ tst_res(TINFO, "mkfs.%s does exist", fs_type);
+ return 1;
+}
+
+static int has_kernel_support(const char *fs_type, int flags)
+{
+ static int fuse_supported = -1;
+ const char *tmpdir = getenv("TMPDIR");
+ char buf[128];
+ int ret;
+
+ if (!tmpdir)
+ tmpdir = "/tmp";
+
+ mount("/dev/zero", tmpdir, fs_type, 0, NULL);
+ if (errno != ENODEV) {
+ tst_res(TINFO, "Kernel supports %s", fs_type);
+ return 1;
+ }
+
+ /* Is FUSE supported by kernel? */
+ if (fuse_supported == -1) {
+ ret = open("/dev/fuse", O_RDWR);
+ if (ret < 0) {
+ fuse_supported = 0;
+ } else {
+ fuse_supported = 1;
+ SAFE_CLOSE(ret);
+ }
+ }
+
+ if (!fuse_supported)
+ return 0;
+
+ /* Is FUSE implementation installed? */
+ sprintf(buf, "mount.%s >/dev/null 2>&1", fs_type);
+
+ ret = tst_system(buf);
+ if (WEXITSTATUS(ret) == 127) {
+ tst_res(TINFO, "Filesystem %s is not supported", fs_type);
+ return 0;
+ }
+
+ if (flags & TST_FS_SKIP_FUSE) {
+ tst_res(TINFO, "Skipping FUSE as requested by the test");
+ return 0;
+ }
+
+ tst_res(TINFO, "FUSE does support %s", fs_type);
+ return 1;
+}
+
+int tst_fs_is_supported(const char *fs_type, int flags)
+{
+ return has_kernel_support(fs_type, flags) && has_mkfs(fs_type);
+}
+
+const char **tst_get_supported_fs_types(int flags)
+{
+ unsigned int i, j = 0;
+
+ for (i = 0; fs_type_whitelist[i]; i++) {
+ if (tst_fs_is_supported(fs_type_whitelist[i], flags))
+ fs_types[j++] = fs_type_whitelist[i];
+ }
+
+ return fs_types;
+}
diff --git a/kernel/tests/lib/tst_sys_conf.c b/kernel/tests/lib/tst_sys_conf.c
new file mode 100644
index 0000000..4ad9f8b
--- /dev/null
+++ b/kernel/tests/lib/tst_sys_conf.c
@@ -0,0 +1,105 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2018 Jan Stancek <jstancek@redhat.com>
+ */
+
+#include <limits.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+#include "tst_sys_conf.h"
+
+static struct tst_sys_conf *save_restore_data;
+
+void tst_sys_conf_dump(void)
+{
+ struct tst_sys_conf *i;
+
+ for (i = save_restore_data; i; i = i->next)
+ tst_res(TINFO, "%s = %s", i->path, i->value);
+}
+
+int tst_sys_conf_save_str(const char *path, const char *value)
+{
+ struct tst_sys_conf *n = SAFE_MALLOC(sizeof(*n));
+
+ strncpy(n->path, path, sizeof(n->path)-1);
+ strncpy(n->value, value, sizeof(n->value)-1);
+
+ n->path[sizeof(n->path) - 1] = 0;
+ n->value[sizeof(n->value) - 1] = 0;
+
+ n->next = save_restore_data;
+ save_restore_data = n;
+
+ return 0;
+}
+
+int tst_sys_conf_save(const char *path)
+{
+ char line[PATH_MAX];
+ FILE *fp;
+ void *ret;
+ char flag;
+
+ if (!path)
+ tst_brk(TBROK, "path is empty");
+
+ flag = path[0];
+ if (flag == '?' || flag == '!')
+ path++;
+
+ if (access(path, F_OK) != 0) {
+ switch (flag) {
+ case '?':
+ tst_res(TINFO, "Path not found: '%s'", path);
+ break;
+ case '!':
+ tst_brk(TBROK|TERRNO, "Path not found: '%s'", path);
+ break;
+ default:
+ tst_brk(TCONF|TERRNO, "Path not found: '%s'", path);
+ }
+ return 1;
+ }
+
+ fp = fopen(path, "r");
+ if (fp == NULL) {
+ if (flag == '?')
+ return 1;
+
+ tst_brk(TBROK | TERRNO, "Failed to open FILE '%s' for reading",
+ path);
+ return 1;
+ }
+
+ ret = fgets(line, sizeof(line), fp);
+ fclose(fp);
+
+ if (ret == NULL) {
+ if (flag == '?')
+ return 1;
+
+ tst_brk(TBROK | TERRNO, "Failed to read anything from '%s'",
+ path);
+ }
+
+ return tst_sys_conf_save_str(path, line);
+}
+
+void tst_sys_conf_restore(int verbose)
+{
+ struct tst_sys_conf *i;
+
+ for (i = save_restore_data; i; i = i->next) {
+ if (verbose) {
+ tst_res(TINFO, "Restoring conf.: %s -> %s\n",
+ i->path, i->value);
+ }
+ FILE_PRINTF(i->path, "%s", i->value);
+ }
+}
+
diff --git a/kernel/tests/lib/tst_taint.c b/kernel/tests/lib/tst_taint.c
new file mode 100644
index 0000000..49146aa
--- /dev/null
+++ b/kernel/tests/lib/tst_taint.c
@@ -0,0 +1,107 @@
+#define TST_NO_DEFAULT_MAIN
+
+#include "tst_test.h"
+#include "tst_taint.h"
+#include "tst_safe_stdio.h"
+
+#define TAINT_FILE "/proc/sys/kernel/tainted"
+
+static unsigned int taint_mask = -1;
+
+static unsigned int tst_taint_read(void)
+{
+ unsigned int val;
+
+ SAFE_FILE_SCANF(TAINT_FILE, "%u", &val);
+
+ return val;
+}
+
+static int tst_taint_check_kver(unsigned int mask)
+{
+ int r1;
+ int r2;
+ int r3 = 0;
+
+ if (mask & TST_TAINT_X) {
+ r1 = 4;
+ r2 = 15;
+ } else if (mask & TST_TAINT_K) {
+ r1 = 4;
+ r2 = 0;
+ } else if (mask & TST_TAINT_L) {
+ r1 = 3;
+ r2 = 17;
+ } else if (mask & TST_TAINT_E) {
+ r1 = 3;
+ r2 = 15;
+ } else if (mask & TST_TAINT_O) {
+ r1 = 3;
+ r2 = 2;
+ } else if (mask & TST_TAINT_I) {
+ r1 = 2;
+ r2 = 6;
+ r3 = 35;
+ } else if (mask & TST_TAINT_C) {
+ r1 = 2;
+ r2 = 6;
+ r3 = 28;
+ } else if (mask & TST_TAINT_W) {
+ r1 = 2;
+ r2 = 6;
+ r3 = 26;
+ } else if (mask & TST_TAINT_A) {
+ r1 = 2;
+ r2 = 6;
+ r3 = 25;
+ } else if (mask & TST_TAINT_D) {
+ r1 = 2;
+ r2 = 6;
+ r3 = 23;
+ } else if (mask & TST_TAINT_U) {
+ r1 = 2;
+ r2 = 6;
+ r3 = 21;
+ } else {
+ r1 = 2;
+ r2 = 6;
+ r3 = 16;
+ }
+
+ return tst_kvercmp(r1, r2, r3);
+}
+
+void tst_taint_init(unsigned int mask)
+{
+ unsigned int taint = -1;
+
+ if (mask == 0)
+ tst_brk(TBROK, "mask is not allowed to be 0");
+
+ if (tst_taint_check_kver(mask) < 0)
+ tst_res(TCONF, "Kernel is too old for requested mask");
+
+ taint_mask = mask;
+ taint = tst_taint_read();
+
+ if (taint & TST_TAINT_W) {
+ tst_res(TCONF, "Ignoring already set kernel warning taint");
+ taint_mask &= ~TST_TAINT_W;
+ }
+
+ if ((taint & taint_mask) != 0)
+ tst_brk(TBROK, "Kernel is already tainted: %u", taint);
+}
+
+
+unsigned int tst_taint_check(void)
+{
+ unsigned int taint = -1;
+
+ if (taint_mask == (unsigned int) -1)
+ tst_brk(TBROK, "need to call tst_taint_init() first");
+
+ taint = tst_taint_read();
+
+ return (taint & taint_mask);
+}
diff --git a/kernel/tests/lib/tst_test.c b/kernel/tests/lib/tst_test.c
new file mode 100644
index 0000000..135cd4e
--- /dev/null
+++ b/kernel/tests/lib/tst_test.c
@@ -0,0 +1,1387 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2015-2016 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#include <limits.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/mount.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+#include "tst_device.h"
+#include "lapi/futex.h"
+#include "lapi/syscalls.h"
+#include "tst_ansi_color.h"
+#include "tst_safe_stdio.h"
+#include "tst_timer_test.h"
+#include "tst_clocks.h"
+#include "tst_timer.h"
+#include "tst_wallclock.h"
+#include "tst_sys_conf.h"
+#include "tst_kconfig.h"
+
+#include "old_resource.h"
+#include "old_device.h"
+#include "old_tmpdir.h"
+
+/*
+ * Hack to get TCID defined in newlib tests
+ */
+const char *TCID __attribute__((weak));
+
+#define LINUX_GIT_URL "https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id="
+#define CVE_DB_URL "https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-"
+
+struct tst_test *tst_test;
+
+static const char *tid;
+static int iterations = 1;
+static float duration = -1;
+static float timeout_mul = -1;
+static pid_t main_pid, lib_pid;
+static int mntpoint_mounted;
+static int ovl_mounted;
+static struct timespec tst_start_time; /* valid only for test pid */
+
+struct results {
+ int passed;
+ int skipped;
+ int failed;
+ int warnings;
+ unsigned int timeout;
+};
+
+static struct results *results;
+
+static int ipc_fd;
+
+extern void *tst_futexes;
+extern unsigned int tst_max_futexes;
+
+#define IPC_ENV_VAR "LTP_IPC_PATH"
+
+static char ipc_path[1064];
+const char *tst_ipc_path = ipc_path;
+
+static char shm_path[1024];
+
+int TST_ERR;
+long TST_RET;
+
+static void do_cleanup(void);
+static void do_exit(int ret) __attribute__ ((noreturn));
+
+static void setup_ipc(void)
+{
+ size_t size = getpagesize();
+
+ if (access("/dev/shm", F_OK) == 0) {
+ snprintf(shm_path, sizeof(shm_path), "/dev/shm/ltp_%s_%d",
+ tid, getpid());
+ } else {
+ char *tmpdir;
+
+ if (!tst_tmpdir_created())
+ tst_tmpdir();
+
+ tmpdir = tst_get_tmpdir();
+ snprintf(shm_path, sizeof(shm_path), "%s/ltp_%s_%d",
+ tmpdir, tid, getpid());
+ free(tmpdir);
+ }
+
+ ipc_fd = open(shm_path, O_CREAT | O_EXCL | O_RDWR, 0600);
+ if (ipc_fd < 0)
+ tst_brk(TBROK | TERRNO, "open(%s)", shm_path);
+ SAFE_CHMOD(shm_path, 0666);
+
+ SAFE_FTRUNCATE(ipc_fd, size);
+
+ results = SAFE_MMAP(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, ipc_fd, 0);
+
+ /* Checkpoints needs to be accessible from processes started by exec() */
+ if (tst_test->needs_checkpoints || tst_test->child_needs_reinit) {
+ sprintf(ipc_path, IPC_ENV_VAR "=%s", shm_path);
+ putenv(ipc_path);
+ } else {
+ SAFE_UNLINK(shm_path);
+ }
+
+ SAFE_CLOSE(ipc_fd);
+
+ if (tst_test->needs_checkpoints) {
+ tst_futexes = (char*)results + sizeof(struct results);
+ tst_max_futexes = (size - sizeof(struct results))/sizeof(futex_t);
+ }
+}
+
+static void cleanup_ipc(void)
+{
+ size_t size = getpagesize();
+
+ if (ipc_fd > 0 && close(ipc_fd))
+ tst_res(TWARN | TERRNO, "close(ipc_fd) failed");
+
+ if (shm_path[0] && !access(shm_path, F_OK) && unlink(shm_path))
+ tst_res(TWARN | TERRNO, "unlink(%s) failed", shm_path);
+
+ if (results) {
+ msync((void*)results, size, MS_SYNC);
+ munmap((void*)results, size);
+ results = NULL;
+ }
+}
+
+void tst_reinit(void)
+{
+ const char *path = getenv(IPC_ENV_VAR);
+ size_t size = getpagesize();
+ int fd;
+
+ if (!path)
+ tst_brk(TBROK, IPC_ENV_VAR" is not defined");
+
+ if (access(path, F_OK))
+ tst_brk(TBROK, "File %s does not exist!", path);
+
+ fd = SAFE_OPEN(path, O_RDWR);
+
+ results = SAFE_MMAP(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+ tst_futexes = (char*)results + sizeof(struct results);
+ tst_max_futexes = (size - sizeof(struct results))/sizeof(futex_t);
+
+ SAFE_CLOSE(fd);
+}
+
+static void update_results(int ttype)
+{
+ if (!results)
+ return;
+
+ switch (ttype) {
+ case TCONF:
+ tst_atomic_inc(&results->skipped);
+ break;
+ case TPASS:
+ tst_atomic_inc(&results->passed);
+ break;
+ case TWARN:
+ tst_atomic_inc(&results->warnings);
+ break;
+ case TFAIL:
+ tst_atomic_inc(&results->failed);
+ break;
+ }
+}
+
+static void print_result(const char *file, const int lineno, int ttype,
+ const char *fmt, va_list va)
+{
+ char buf[1024];
+ char *str = buf;
+ int ret, size = sizeof(buf), ssize, int_errno, buflen;
+ const char *str_errno = NULL;
+ const char *res;
+
+ switch (TTYPE_RESULT(ttype)) {
+ case TPASS:
+ res = "PASS";
+ break;
+ case TFAIL:
+ res = "FAIL";
+ break;
+ case TBROK:
+ res = "BROK";
+ break;
+ case TCONF:
+ res = "CONF";
+ break;
+ case TWARN:
+ res = "WARN";
+ break;
+ case TINFO:
+ res = "INFO";
+ break;
+ default:
+ tst_brk(TBROK, "Invalid ttype value %i", ttype);
+ abort();
+ }
+
+ if (ttype & TERRNO) {
+ str_errno = tst_strerrno(errno);
+ int_errno = errno;
+ }
+
+ if (ttype & TTERRNO) {
+ str_errno = tst_strerrno(TST_ERR);
+ int_errno = TST_ERR;
+ }
+
+ if (ttype & TRERRNO) {
+ int_errno = TST_RET < 0 ? -(int)TST_RET : (int)TST_RET;
+ str_errno = tst_strerrno(int_errno);
+ }
+
+ ret = snprintf(str, size, "%s:%i: ", file, lineno);
+ str += ret;
+ size -= ret;
+
+ if (tst_color_enabled(STDERR_FILENO))
+ ret = snprintf(str, size, "%s%s: %s", tst_ttype2color(ttype),
+ res, ANSI_COLOR_RESET);
+ else
+ ret = snprintf(str, size, "%s: ", res);
+ str += ret;
+ size -= ret;
+
+ ssize = size - 2;
+ ret = vsnprintf(str, size, fmt, va);
+ str += MIN(ret, ssize);
+ size -= MIN(ret, ssize);
+ if (ret >= ssize) {
+ tst_res_(file, lineno, TWARN,
+ "Next message is too long and truncated:");
+ } else if (str_errno) {
+ ssize = size - 2;
+ ret = snprintf(str, size, ": %s (%d)", str_errno, int_errno);
+ str += MIN(ret, ssize);
+ size -= MIN(ret, ssize);
+ if (ret >= ssize)
+ tst_res_(file, lineno, TWARN,
+ "Next message is too long and truncated:");
+ }
+
+ snprintf(str, size, "\n");
+
+ /* we might be called from signal handler, so use write() */
+ buflen = str - buf + 1;
+ str = buf;
+ while (buflen) {
+ ret = write(STDERR_FILENO, str, buflen);
+ if (ret <= 0)
+ break;
+
+ str += ret;
+ buflen -= ret;
+ }
+}
+
+void tst_vres_(const char *file, const int lineno, int ttype,
+ const char *fmt, va_list va)
+{
+ print_result(file, lineno, ttype, fmt, va);
+
+ update_results(TTYPE_RESULT(ttype));
+}
+
+void tst_vbrk_(const char *file, const int lineno, int ttype,
+ const char *fmt, va_list va);
+
+static void (*tst_brk_handler)(const char *file, const int lineno, int ttype,
+ const char *fmt, va_list va) = tst_vbrk_;
+
+static void tst_cvres(const char *file, const int lineno, int ttype,
+ const char *fmt, va_list va)
+{
+ if (TTYPE_RESULT(ttype) == TBROK) {
+ ttype &= ~TTYPE_MASK;
+ ttype |= TWARN;
+ }
+
+ print_result(file, lineno, ttype, fmt, va);
+ update_results(TTYPE_RESULT(ttype));
+}
+
+static void do_test_cleanup(void)
+{
+ tst_brk_handler = tst_cvres;
+
+ if (tst_test->cleanup)
+ tst_test->cleanup();
+
+ tst_free_all();
+
+ tst_brk_handler = tst_vbrk_;
+}
+
+void tst_vbrk_(const char *file, const int lineno, int ttype,
+ const char *fmt, va_list va)
+{
+ print_result(file, lineno, ttype, fmt, va);
+ update_results(TTYPE_RESULT(ttype));
+
+ /*
+ * The getpid implementation in some C library versions may cause cloned
+ * test threads to show the same pid as their parent when CLONE_VM is
+ * specified but CLONE_THREAD is not. Use direct syscall to avoid
+ * cleanup running in the child.
+ */
+ if (syscall(SYS_getpid) == main_pid)
+ do_test_cleanup();
+
+ if (getpid() == lib_pid)
+ do_exit(TTYPE_RESULT(ttype));
+
+ exit(TTYPE_RESULT(ttype));
+}
+
+void tst_res_(const char *file, const int lineno, int ttype,
+ const char *fmt, ...)
+{
+ va_list va;
+
+ va_start(va, fmt);
+ tst_vres_(file, lineno, ttype, fmt, va);
+ va_end(va);
+}
+
+void tst_brk_(const char *file, const int lineno, int ttype,
+ const char *fmt, ...)
+{
+ va_list va;
+
+ va_start(va, fmt);
+ tst_brk_handler(file, lineno, ttype, fmt, va);
+ va_end(va);
+}
+
+static void check_child_status(pid_t pid, int status)
+{
+ int ret;
+
+ if (WIFSIGNALED(status)) {
+ tst_brk(TBROK, "Child (%i) killed by signal %s",
+ pid, tst_strsig(WTERMSIG(status)));
+ }
+
+ if (!(WIFEXITED(status)))
+ tst_brk(TBROK, "Child (%i) exited abnormally", pid);
+
+ ret = WEXITSTATUS(status);
+ switch (ret) {
+ case TPASS:
+ break;
+ case TBROK:
+ case TCONF:
+ tst_brk(ret, "Reported by child (%i)", pid);
+ break;
+ default:
+ tst_brk(TBROK, "Invalid child (%i) exit value %i", pid, ret);
+ }
+}
+
+void tst_reap_children(void)
+{
+ int status;
+ pid_t pid;
+
+ for (;;) {
+ pid = wait(&status);
+
+ if (pid > 0) {
+ check_child_status(pid, status);
+ continue;
+ }
+
+ if (errno == ECHILD)
+ break;
+
+ if (errno == EINTR)
+ continue;
+
+ tst_brk(TBROK | TERRNO, "wait() failed");
+ }
+}
+
+
+pid_t safe_fork(const char *filename, unsigned int lineno)
+{
+ pid_t pid;
+
+ if (!tst_test->forks_child)
+ tst_brk(TBROK, "test.forks_child must be set!");
+
+ tst_flush();
+
+ pid = fork();
+ if (pid < 0)
+ tst_brk_(filename, lineno, TBROK | TERRNO, "fork() failed");
+
+ if (!pid)
+ atexit(tst_free_all);
+
+ return pid;
+}
+
+static struct option {
+ char *optstr;
+ char *help;
+} options[] = {
+ {"h", "-h Prints this help"},
+ {"i:", "-i n Execute test n times"},
+ {"I:", "-I x Execute test for n seconds"},
+ {"C:", "-C ARG Run child process with ARG arguments (used internally)"},
+};
+
+static void print_help(void)
+{
+ unsigned int i;
+
+ fprintf(stderr, "Options\n");
+ fprintf(stderr, "-------\n");
+
+ for (i = 0; i < ARRAY_SIZE(options); i++)
+ fprintf(stderr, "%s\n", options[i].help);
+
+ if (!tst_test->options)
+ return;
+
+ for (i = 0; tst_test->options[i].optstr; i++)
+ fprintf(stderr, "%s\n", tst_test->options[i].help);
+}
+
+static void print_test_tags(void)
+{
+ unsigned int i;
+ const struct tst_tag *tags = tst_test->tags;
+
+ if (!tags)
+ return;
+
+ printf("\nTags\n");
+ printf("----\n");
+
+ for (i = 0; tags[i].name; i++) {
+ if (!strcmp(tags[i].name, "CVE"))
+ printf(CVE_DB_URL "%s\n", tags[i].value);
+ else if (!strcmp(tags[i].name, "linux-git"))
+ printf(LINUX_GIT_URL "%s\n", tags[i].value);
+ else
+ printf("%s: %s\n", tags[i].name, tags[i].value);
+ }
+
+ printf("\n");
+}
+
+static void check_option_collision(void)
+{
+ unsigned int i, j;
+ struct tst_option *toptions = tst_test->options;
+
+ if (!toptions)
+ return;
+
+ for (i = 0; toptions[i].optstr; i++) {
+ for (j = 0; j < ARRAY_SIZE(options); j++) {
+ if (toptions[i].optstr[0] == options[j].optstr[0]) {
+ tst_brk(TBROK, "Option collision '%s'",
+ options[j].help);
+ }
+ }
+ }
+}
+
+static unsigned int count_options(void)
+{
+ unsigned int i;
+
+ if (!tst_test->options)
+ return 0;
+
+ for (i = 0; tst_test->options[i].optstr; i++);
+
+ return i;
+}
+
+static void parse_topt(unsigned int topts_len, int opt, char *optarg)
+{
+ unsigned int i;
+ struct tst_option *toptions = tst_test->options;
+
+ for (i = 0; i < topts_len; i++) {
+ if (toptions[i].optstr[0] == opt)
+ break;
+ }
+
+ if (i >= topts_len)
+ tst_brk(TBROK, "Invalid option '%c' (should not happen)", opt);
+
+ if (*toptions[i].arg)
+ tst_res(TWARN, "Option -%c passed multiple times", opt);
+
+ *(toptions[i].arg) = optarg ? optarg : "";
+}
+
+/* see self_exec.c */
+#ifdef UCLINUX
+extern char *child_args;
+#endif
+
+static void parse_opts(int argc, char *argv[])
+{
+ unsigned int i, topts_len = count_options();
+ char optstr[2 * ARRAY_SIZE(options) + 2 * topts_len];
+ int opt;
+
+ check_option_collision();
+
+ optstr[0] = 0;
+
+ for (i = 0; i < ARRAY_SIZE(options); i++)
+ strcat(optstr, options[i].optstr);
+
+ for (i = 0; i < topts_len; i++)
+ strcat(optstr, tst_test->options[i].optstr);
+
+ while ((opt = getopt(argc, argv, optstr)) > 0) {
+ switch (opt) {
+ case '?':
+ print_help();
+ tst_brk(TBROK, "Invalid option");
+ break;
+ case 'h':
+ print_help();
+ print_test_tags();
+ exit(0);
+ case 'i':
+ iterations = atoi(optarg);
+ break;
+ case 'I':
+ duration = atof(optarg);
+ break;
+ case 'C':
+#ifdef UCLINUX
+ child_args = optarg;
+#endif
+ break;
+ default:
+ parse_topt(topts_len, opt, optarg);
+ }
+ }
+
+ if (optind < argc)
+ tst_brk(TBROK, "Unexpected argument(s) '%s'...", argv[optind]);
+}
+
+int tst_parse_int(const char *str, int *val, int min, int max)
+{
+ long rval;
+
+ if (!str)
+ return 0;
+
+ int ret = tst_parse_long(str, &rval, min, max);
+
+ if (ret)
+ return ret;
+
+ *val = (int)rval;
+ return 0;
+}
+
+int tst_parse_long(const char *str, long *val, long min, long max)
+{
+ long rval;
+ char *end;
+
+ if (!str)
+ return 0;
+
+ errno = 0;
+ rval = strtol(str, &end, 10);
+
+ if (str == end || *end != '\0')
+ return EINVAL;
+
+ if (errno)
+ return errno;
+
+ if (rval > max || rval < min)
+ return ERANGE;
+
+ *val = rval;
+ return 0;
+}
+
+int tst_parse_float(const char *str, float *val, float min, float max)
+{
+ double rval;
+ char *end;
+
+ if (!str)
+ return 0;
+
+ errno = 0;
+ rval = strtod(str, &end);
+
+ if (str == end || *end != '\0')
+ return EINVAL;
+
+ if (errno)
+ return errno;
+
+ if (rval > (double)max || rval < (double)min)
+ return ERANGE;
+
+ *val = (float)rval;
+ return 0;
+}
+
+static void print_colored(const char *str)
+{
+ if (tst_color_enabled(STDOUT_FILENO))
+ printf("%s%s%s", ANSI_COLOR_YELLOW, str, ANSI_COLOR_RESET);
+ else
+ printf("%s", str);
+}
+
+static void print_failure_hints(void)
+{
+ unsigned int i;
+ const struct tst_tag *tags = tst_test->tags;
+
+ if (!tags)
+ return;
+
+ int hint_printed = 0;
+ for (i = 0; tags[i].name; i++) {
+ if (!strcmp(tags[i].name, "linux-git")) {
+ if (!hint_printed) {
+ hint_printed = 1;
+ printf("\n");
+ print_colored("HINT: ");
+ printf("You _MAY_ be missing kernel fixes, see:\n\n");
+ }
+
+ printf(LINUX_GIT_URL "%s\n", tags[i].value);
+ }
+
+ }
+
+ hint_printed = 0;
+ for (i = 0; tags[i].name; i++) {
+ if (!strcmp(tags[i].name, "CVE")) {
+ if (!hint_printed) {
+ hint_printed = 1;
+ printf("\n");
+ print_colored("HINT: ");
+ printf("You _MAY_ be vulnerable to CVE(s), see:\n\n");
+ }
+
+ printf(CVE_DB_URL "%s\n", tags[i].value);
+ }
+ }
+}
+
+static void do_exit(int ret)
+{
+ if (results) {
+ if (results->passed && ret == TCONF)
+ ret = 0;
+
+ if (results->failed) {
+ ret |= TFAIL;
+ print_failure_hints();
+ }
+
+ if (results->skipped && !results->passed)
+ ret |= TCONF;
+
+ if (results->warnings)
+ ret |= TWARN;
+
+ printf("\nSummary:\n");
+ printf("passed %d\n", results->passed);
+ printf("failed %d\n", results->failed);
+ printf("skipped %d\n", results->skipped);
+ printf("warnings %d\n", results->warnings);
+ }
+
+ do_cleanup();
+
+ exit(ret);
+}
+
+void check_kver(void)
+{
+ int v1, v2, v3;
+
+ if (tst_parse_kver(tst_test->min_kver, &v1, &v2, &v3)) {
+ tst_res(TWARN,
+ "Invalid kernel version %s, expected %%d.%%d.%%d",
+ tst_test->min_kver);
+ }
+
+ if (tst_kvercmp(v1, v2, v3) < 0) {
+ tst_brk(TCONF, "The test requires kernel %s or newer",
+ tst_test->min_kver);
+ }
+}
+
+static int results_equal(struct results *a, struct results *b)
+{
+ if (a->passed != b->passed)
+ return 0;
+
+ if (a->failed != b->failed)
+ return 0;
+
+ if (a->skipped != b->skipped)
+ return 0;
+
+ return 1;
+}
+
+static int needs_tmpdir(void)
+{
+ return tst_test->needs_tmpdir ||
+ tst_test->needs_device ||
+ tst_test->mntpoint ||
+ tst_test->resource_files ||
+ tst_test->needs_checkpoints;
+}
+
+static void copy_resources(void)
+{
+ unsigned int i;
+
+ for (i = 0; tst_test->resource_files[i]; i++)
+ TST_RESOURCE_COPY(NULL, tst_test->resource_files[i], NULL);
+}
+
+static const char *get_tid(char *argv[])
+{
+ char *p;
+
+ if (!argv[0] || !argv[0][0]) {
+ tst_res(TINFO, "argv[0] is empty!");
+ return "ltp_empty_argv";
+ }
+
+ p = strrchr(argv[0], '/');
+ if (p)
+ return p+1;
+
+ return argv[0];
+}
+
+static struct tst_device tdev;
+struct tst_device *tst_device;
+
+static void assert_test_fn(void)
+{
+ int cnt = 0;
+
+ if (tst_test->test)
+ cnt++;
+
+ if (tst_test->test_all)
+ cnt++;
+
+ if (tst_test->sample)
+ cnt++;
+
+ if (!cnt)
+ tst_brk(TBROK, "No test function specified");
+
+ if (cnt != 1)
+ tst_brk(TBROK, "You can define only one test function");
+
+ if (tst_test->test && !tst_test->tcnt)
+ tst_brk(TBROK, "Number of tests (tcnt) must be > 0");
+
+ if (!tst_test->test && tst_test->tcnt)
+ tst_brk(TBROK, "You can define tcnt only for test()");
+}
+
+static int prepare_and_mount_ro_fs(const char *dev,
+ const char *mntpoint,
+ const char *fs_type)
+{
+ char buf[PATH_MAX];
+
+ if (mount(dev, mntpoint, fs_type, 0, NULL)) {
+ tst_res(TINFO | TERRNO, "Can't mount %s at %s (%s)",
+ dev, mntpoint, fs_type);
+ return 1;
+ }
+
+ mntpoint_mounted = 1;
+
+ snprintf(buf, sizeof(buf), "%s/dir/", mntpoint);
+ SAFE_MKDIR(buf, 0777);
+
+ snprintf(buf, sizeof(buf), "%s/file", mntpoint);
+ SAFE_FILE_PRINTF(buf, "file content");
+ SAFE_CHMOD(buf, 0777);
+
+ SAFE_MOUNT(dev, mntpoint, fs_type, MS_REMOUNT | MS_RDONLY, NULL);
+
+ return 0;
+}
+
+static void prepare_and_mount_dev_fs(const char *mntpoint)
+{
+ const char *flags[] = {"nodev", NULL};
+ int mounted_nodev;
+
+ mounted_nodev = tst_path_has_mnt_flags(NULL, flags);
+ if (mounted_nodev) {
+ tst_res(TINFO, "tmpdir isn't suitable for creating devices, "
+ "mounting tmpfs without nodev on %s", mntpoint);
+ SAFE_MOUNT(NULL, mntpoint, "tmpfs", 0, NULL);
+ mntpoint_mounted = 1;
+ }
+}
+
+static void prepare_device(void)
+{
+ if (tst_test->format_device) {
+ SAFE_MKFS(tdev.dev, tdev.fs_type, tst_test->dev_fs_opts,
+ tst_test->dev_extra_opts);
+ }
+
+ if (tst_test->needs_rofs) {
+ prepare_and_mount_ro_fs(tdev.dev, tst_test->mntpoint,
+ tdev.fs_type);
+ return;
+ }
+
+ if (tst_test->mount_device) {
+ SAFE_MOUNT(tdev.dev, tst_test->mntpoint, tdev.fs_type,
+ tst_test->mnt_flags, tst_test->mnt_data);
+ mntpoint_mounted = 1;
+ }
+}
+
+static void do_setup(int argc, char *argv[])
+{
+ if (!tst_test)
+ tst_brk(TBROK, "No tests to run");
+
+ if (tst_test->tconf_msg)
+ tst_brk(TCONF, "%s", tst_test->tconf_msg);
+
+ if (tst_test->needs_kconfigs)
+ tst_kconfig_check(tst_test->needs_kconfigs);
+
+ assert_test_fn();
+
+ tid = get_tid(argv);
+
+ if (tst_test->sample)
+ tst_test = tst_timer_test_setup(tst_test);
+
+ parse_opts(argc, argv);
+
+ if (tst_test->needs_root && geteuid() != 0)
+ tst_brk(TCONF, "Test needs to be run as root");
+
+ if (tst_test->min_kver)
+ check_kver();
+
+ if (tst_test->needs_cmds) {
+ const char *cmd;
+ char path[PATH_MAX];
+ int i;
+
+ for (i = 0; (cmd = tst_test->needs_cmds[i]); ++i)
+ if (tst_get_path(cmd, path, sizeof(path)))
+ tst_brk(TCONF, "Couldn't find '%s' in $PATH", cmd);
+ }
+
+ if (tst_test->needs_drivers) {
+ const char *name;
+ int i;
+
+ for (i = 0; (name = tst_test->needs_drivers[i]); ++i)
+ if (tst_check_driver(name))
+ tst_brk(TCONF, "%s driver not available", name);
+ }
+
+ if (tst_test->format_device)
+ tst_test->needs_device = 1;
+
+ if (tst_test->mount_device) {
+ tst_test->needs_device = 1;
+ tst_test->format_device = 1;
+ }
+
+ if (tst_test->all_filesystems)
+ tst_test->needs_device = 1;
+
+ if (tst_test->request_hugepages)
+ tst_request_hugepages(tst_test->request_hugepages);
+
+ setup_ipc();
+
+ if (tst_test->bufs)
+ tst_buffers_alloc(tst_test->bufs);
+
+ if (needs_tmpdir() && !tst_tmpdir_created())
+ tst_tmpdir();
+
+ if (tst_test->save_restore) {
+ const char * const *name = tst_test->save_restore;
+
+ while (*name) {
+ tst_sys_conf_save(*name);
+ name++;
+ }
+ }
+
+ if (tst_test->mntpoint)
+ SAFE_MKDIR(tst_test->mntpoint, 0777);
+
+ if ((tst_test->needs_devfs || tst_test->needs_rofs ||
+ tst_test->mount_device || tst_test->all_filesystems) &&
+ !tst_test->mntpoint) {
+ tst_brk(TBROK, "tst_test->mntpoint must be set!");
+ }
+
+ if (!!tst_test->needs_rofs + !!tst_test->needs_devfs +
+ !!tst_test->needs_device > 1) {
+ tst_brk(TBROK,
+ "Two or more of needs_{rofs, devfs, device} are set");
+ }
+
+ if (tst_test->needs_devfs)
+ prepare_and_mount_dev_fs(tst_test->mntpoint);
+
+ if (tst_test->needs_rofs) {
+ /* If we failed to mount read-only tmpfs. Fallback to
+ * using a device with read-only filesystem.
+ */
+ if (prepare_and_mount_ro_fs(NULL, tst_test->mntpoint, "tmpfs")) {
+ tst_res(TINFO, "Can't mount tmpfs read-only, "
+ "falling back to block device...");
+ tst_test->needs_device = 1;
+ tst_test->format_device = 1;
+ }
+ }
+
+ if (tst_test->needs_device && !mntpoint_mounted) {
+ tdev.dev = tst_acquire_device_(NULL, tst_test->dev_min_size);
+
+ if (!tdev.dev)
+ tst_brk(TCONF, "Failed to acquire device");
+
+ tst_device = &tdev;
+
+ if (tst_test->dev_fs_type)
+ tdev.fs_type = tst_test->dev_fs_type;
+ else
+ tdev.fs_type = tst_dev_fs_type();
+
+ if (!tst_test->all_filesystems)
+ prepare_device();
+ }
+
+ if (tst_test->needs_overlay && !tst_test->mount_device) {
+ tst_brk(TBROK, "tst_test->mount_device must be set");
+ }
+ if (tst_test->needs_overlay && !mntpoint_mounted) {
+ tst_brk(TBROK, "tst_test->mntpoint must be mounted");
+ }
+ if (tst_test->needs_overlay && !ovl_mounted) {
+ SAFE_MOUNT_OVERLAY();
+ ovl_mounted = 1;
+ }
+
+ if (tst_test->resource_files)
+ copy_resources();
+
+ if (tst_test->restore_wallclock)
+ tst_wallclock_save();
+
+ if (tst_test->taint_check)
+ tst_taint_init(tst_test->taint_check);
+}
+
+static void do_test_setup(void)
+{
+ main_pid = getpid();
+
+ if (tst_test->caps)
+ tst_cap_setup(tst_test->caps, TST_CAP_REQ);
+
+ if (tst_test->setup)
+ tst_test->setup();
+
+ if (main_pid != getpid())
+ tst_brk(TBROK, "Runaway child in setup()!");
+
+ if (tst_test->caps)
+ tst_cap_setup(tst_test->caps, TST_CAP_DROP);
+}
+
+static void do_cleanup(void)
+{
+ if (ovl_mounted)
+ SAFE_UMOUNT(OVL_MNT);
+
+ if (mntpoint_mounted)
+ tst_umount(tst_test->mntpoint);
+
+ if (tst_test->needs_device && tdev.dev)
+ tst_release_device(tdev.dev);
+
+ if (tst_tmpdir_created()) {
+ /* avoid munmap() on wrong pointer in tst_rmdir() */
+ tst_futexes = NULL;
+ tst_rmdir();
+ }
+
+ tst_sys_conf_restore(0);
+
+ if (tst_test->restore_wallclock)
+ tst_wallclock_restore();
+
+ cleanup_ipc();
+}
+
+static void run_tests(void)
+{
+ unsigned int i;
+ struct results saved_results;
+
+ if (!tst_test->test) {
+ saved_results = *results;
+ tst_test->test_all();
+
+ if (getpid() != main_pid) {
+ exit(0);
+ }
+
+ tst_reap_children();
+
+ if (results_equal(&saved_results, results))
+ tst_brk(TBROK, "Test haven't reported results!");
+ return;
+ }
+
+ for (i = 0; i < tst_test->tcnt; i++) {
+ saved_results = *results;
+ tst_test->test(i);
+
+ if (getpid() != main_pid) {
+ exit(0);
+ }
+
+ tst_reap_children();
+
+ if (results_equal(&saved_results, results))
+ tst_brk(TBROK, "Test %i haven't reported results!", i);
+ }
+}
+
+static unsigned long long get_time_ms(void)
+{
+ struct timespec ts;
+
+ if (tst_clock_gettime(CLOCK_MONOTONIC, &ts))
+ tst_brk(TBROK | TERRNO, "tst_clock_gettime()");
+
+ return tst_timespec_to_ms(ts);
+}
+
+static void add_paths(void)
+{
+ char *old_path = getenv("PATH");
+ const char *start_dir;
+ char *new_path;
+
+ start_dir = tst_get_startwd();
+
+ if (old_path)
+ SAFE_ASPRINTF(&new_path, "%s::%s", old_path, start_dir);
+ else
+ SAFE_ASPRINTF(&new_path, "::%s", start_dir);
+
+ SAFE_SETENV("PATH", new_path, 1);
+ free(new_path);
+}
+
+static void heartbeat(void)
+{
+ if (tst_clock_gettime(CLOCK_MONOTONIC, &tst_start_time))
+ tst_res(TWARN | TERRNO, "tst_clock_gettime() failed");
+
+ kill(getppid(), SIGUSR1);
+}
+
+static void testrun(void)
+{
+ unsigned int i = 0;
+ unsigned long long stop_time = 0;
+ int cont = 1;
+
+ heartbeat();
+ add_paths();
+ do_test_setup();
+
+ if (duration > 0)
+ stop_time = get_time_ms() + (unsigned long long)(duration * 1000);
+
+ for (;;) {
+ cont = 0;
+
+ if (i < (unsigned int)iterations) {
+ i++;
+ cont = 1;
+ }
+
+ if (stop_time && get_time_ms() < stop_time)
+ cont = 1;
+
+ if (!cont)
+ break;
+
+ run_tests();
+ heartbeat();
+ }
+
+ do_test_cleanup();
+ exit(0);
+}
+
+static pid_t test_pid;
+
+
+static volatile sig_atomic_t sigkill_retries;
+
+#define WRITE_MSG(msg) do { \
+ if (write(2, msg, sizeof(msg) - 1)) { \
+ /* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425 */ \
+ } \
+} while (0)
+
+static void alarm_handler(int sig LTP_ATTRIBUTE_UNUSED)
+{
+ WRITE_MSG("Test timeouted, sending SIGKILL!\n");
+ kill(-test_pid, SIGKILL);
+ alarm(5);
+
+ if (++sigkill_retries > 10) {
+ WRITE_MSG("Cannot kill test processes!\n");
+ WRITE_MSG("Congratulation, likely test hit a kernel bug.\n");
+ WRITE_MSG("Exitting uncleanly...\n");
+ _exit(TFAIL);
+ }
+}
+
+static void heartbeat_handler(int sig LTP_ATTRIBUTE_UNUSED)
+{
+ alarm(results->timeout);
+ sigkill_retries = 0;
+}
+
+static void sigint_handler(int sig LTP_ATTRIBUTE_UNUSED)
+{
+ if (test_pid > 0) {
+ WRITE_MSG("Sending SIGKILL to test process...\n");
+ kill(-test_pid, SIGKILL);
+ }
+}
+
+unsigned int tst_timeout_remaining(void)
+{
+ static struct timespec now;
+ unsigned int elapsed;
+
+ if (tst_clock_gettime(CLOCK_MONOTONIC, &now))
+ tst_res(TWARN | TERRNO, "tst_clock_gettime() failed");
+
+ elapsed = (tst_timespec_diff_ms(now, tst_start_time) + 500) / 1000;
+ if (results->timeout > elapsed)
+ return results->timeout - elapsed;
+
+ return 0;
+}
+
+unsigned int tst_multiply_timeout(unsigned int timeout)
+{
+ char *mul;
+ int ret;
+
+ if (timeout_mul == -1) {
+ mul = getenv("LTP_TIMEOUT_MUL");
+ if (mul) {
+ if ((ret = tst_parse_float(mul, &timeout_mul, 1, 10000))) {
+ tst_brk(TBROK, "Failed to parse LTP_TIMEOUT_MUL: %s",
+ tst_strerrno(ret));
+ }
+ } else {
+ timeout_mul = 1;
+ }
+ }
+ if (timeout_mul < 1)
+ tst_brk(TBROK, "LTP_TIMEOUT_MUL must to be int >= 1! (%.2f)",
+ timeout_mul);
+
+ if (timeout < 1)
+ tst_brk(TBROK, "timeout must to be >= 1! (%d)", timeout);
+
+ return timeout * timeout_mul;
+}
+
+void tst_set_timeout(int timeout)
+{
+ if (timeout == -1) {
+ tst_res(TINFO, "Timeout per run is disabled");
+ return;
+ }
+
+ if (timeout < 1)
+ tst_brk(TBROK, "timeout must to be >= 1! (%d)", timeout);
+
+ results->timeout = tst_multiply_timeout(timeout);
+
+ tst_res(TINFO, "Timeout per run is %uh %02um %02us",
+ results->timeout/3600, (results->timeout%3600)/60,
+ results->timeout % 60);
+
+ if (getpid() == lib_pid)
+ alarm(results->timeout);
+ else
+ heartbeat();
+}
+
+static int fork_testrun(void)
+{
+ int status;
+
+ if (tst_test->timeout)
+ tst_set_timeout(tst_test->timeout);
+ else
+ tst_set_timeout(300);
+
+ SAFE_SIGNAL(SIGINT, sigint_handler);
+
+ test_pid = fork();
+ if (test_pid < 0)
+ tst_brk(TBROK | TERRNO, "fork()");
+
+ if (!test_pid) {
+ SAFE_SIGNAL(SIGALRM, SIG_DFL);
+ SAFE_SIGNAL(SIGUSR1, SIG_DFL);
+ SAFE_SIGNAL(SIGINT, SIG_DFL);
+ SAFE_SETPGID(0, 0);
+ testrun();
+ }
+
+ SAFE_WAITPID(test_pid, &status, 0);
+ alarm(0);
+ SAFE_SIGNAL(SIGINT, SIG_DFL);
+
+ if (tst_test->taint_check && tst_taint_check()) {
+ tst_res(TFAIL, "Kernel is now tainted.");
+ return TFAIL;
+ }
+
+ if (WIFEXITED(status) && WEXITSTATUS(status))
+ return WEXITSTATUS(status);
+
+ if (WIFSIGNALED(status) && WTERMSIG(status) == SIGKILL) {
+ tst_res(TINFO, "If you are running on slow machine, "
+ "try exporting LTP_TIMEOUT_MUL > 1");
+ tst_brk(TBROK, "Test killed! (timeout?)");
+ }
+
+ if (WIFSIGNALED(status))
+ tst_brk(TBROK, "Test killed by %s!", tst_strsig(WTERMSIG(status)));
+
+ return 0;
+}
+
+static int run_tcases_per_fs(void)
+{
+ int ret = 0;
+ unsigned int i;
+ const char *const *filesystems = tst_get_supported_fs_types(tst_test->dev_fs_flags);
+
+ if (!filesystems[0])
+ tst_brk(TCONF, "There are no supported filesystems");
+
+ for (i = 0; filesystems[i]; i++) {
+
+ tst_res(TINFO, "Testing on %s", filesystems[i]);
+ tdev.fs_type = filesystems[i];
+
+ prepare_device();
+
+ ret = fork_testrun();
+
+ if (mntpoint_mounted) {
+ tst_umount(tst_test->mntpoint);
+ mntpoint_mounted = 0;
+ }
+
+ if (ret == TCONF)
+ continue;
+
+ if (ret == 0)
+ continue;
+
+ do_exit(ret);
+ }
+
+ return ret;
+}
+
+unsigned int tst_variant;
+
+void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
+{
+ int ret = 0;
+ unsigned int test_variants = 1;
+
+ lib_pid = getpid();
+ tst_test = self;
+
+ do_setup(argc, argv);
+
+ TCID = tid;
+
+ SAFE_SIGNAL(SIGALRM, alarm_handler);
+ SAFE_SIGNAL(SIGUSR1, heartbeat_handler);
+
+ if (tst_test->test_variants)
+ test_variants = tst_test->test_variants;
+
+ for (tst_variant = 0; tst_variant < test_variants; tst_variant++) {
+ if (tst_test->all_filesystems)
+ ret |= run_tcases_per_fs();
+ else
+ ret |= fork_testrun();
+
+ if (ret & ~(TCONF))
+ goto exit;
+ }
+
+exit:
+ do_exit(ret);
+}
+
+
+void tst_flush(void)
+{
+ int rval;
+
+ rval = fflush(stderr);
+ if (rval != 0)
+ tst_brk(TBROK | TERRNO, "fflush(stderr) failed");
+
+ rval = fflush(stdout);
+ if (rval != 0)
+ tst_brk(TBROK | TERRNO, "fflush(stdout) failed");
+
+}
diff --git a/kernel/tests/lib/tst_timer.c b/kernel/tests/lib/tst_timer.c
new file mode 100644
index 0000000..62d8f90
--- /dev/null
+++ b/kernel/tests/lib/tst_timer.c
@@ -0,0 +1,59 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2015 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#include <errno.h>
+
+#define TST_NO_DEFAULT_MAIN
+
+#include "tst_test.h"
+#include "tst_timer.h"
+#include "tst_clocks.h"
+#include "lapi/posix_clocks.h"
+
+static struct timespec start_time, stop_time;
+static clockid_t clock_id;
+
+void tst_timer_check(clockid_t clk_id)
+{
+ if (tst_clock_gettime(clk_id, &start_time)) {
+ if (errno == EINVAL) {
+ tst_brk(TCONF,
+ "Clock id %s(%u) not supported by kernel",
+ tst_clock_name(clk_id), clk_id);
+ return;
+ }
+
+ tst_brk(TBROK | TERRNO, "tst_clock_gettime() failed");
+ }
+}
+
+void tst_timer_start(clockid_t clk_id)
+{
+ clock_id = clk_id;
+
+ if (tst_clock_gettime(clock_id, &start_time))
+ tst_res(TWARN | TERRNO, "tst_clock_gettime() failed");
+}
+
+int tst_timer_expired_ms(long long ms)
+{
+ struct timespec cur_time;
+
+ if (tst_clock_gettime(clock_id, &cur_time))
+ tst_res(TWARN | TERRNO, "tst_clock_gettime() failed");
+
+ return tst_timespec_diff_ms(cur_time, start_time) >= ms;
+}
+
+void tst_timer_stop(void)
+{
+ if (tst_clock_gettime(clock_id, &stop_time))
+ tst_res(TWARN | TERRNO, "tst_clock_gettime() failed");
+}
+
+struct timespec tst_timer_elapsed(void)
+{
+ return tst_timespec_diff(stop_time, start_time);
+}
diff --git a/kernel/tests/lib/tst_timer_test.c b/kernel/tests/lib/tst_timer_test.c
new file mode 100644
index 0000000..196c512
--- /dev/null
+++ b/kernel/tests/lib/tst_timer_test.c
@@ -0,0 +1,472 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#include <sys/prctl.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <limits.h>
+#include <string.h>
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+#include "tst_clocks.h"
+#include "tst_timer_test.h"
+
+#define MAX_SAMPLES 500
+
+static const char *scall;
+static void (*setup)(void);
+static void (*cleanup)(void);
+static int (*sample)(int clk_id, long long usec);
+static struct tst_test *test;
+
+static long long *samples;
+static unsigned int cur_sample;
+static unsigned int monotonic_resolution;
+static unsigned int timerslack;
+static int virt_env;
+
+static char *print_frequency_plot;
+static char *file_name;
+static char *str_sleep_time;
+static char *str_sample_cnt;
+static int sleep_time = -1;
+static int sample_cnt;
+
+static void print_line(char c, int len)
+{
+ while (len-- > 0)
+ fputc(c, stderr);
+}
+
+static unsigned int ceilu(float f)
+{
+ if (f - (int)f > 0)
+ return (unsigned int)f + 1;
+
+ return (unsigned int)f;
+}
+
+static unsigned int flooru(float f)
+{
+ return (unsigned int)f;
+}
+
+static float bucket_len(unsigned int bucket, unsigned int max_bucket,
+ unsigned int cols)
+{
+ return 1.00 * bucket * cols / max_bucket;
+}
+
+static const char *table_heading = " Time: us ";
+
+/*
+ * Line Header: '10023 | '
+ */
+static unsigned int header_len(long long max_sample)
+{
+ unsigned int l = 1;
+
+ while (max_sample/=10)
+ l++;
+
+ return MAX(strlen(table_heading) + 2, l + 3);
+}
+
+static void frequency_plot(void)
+{
+ unsigned int cols = 80;
+ unsigned int rows = 20;
+ unsigned int i, buckets[rows];
+ long long max_sample = samples[0];
+ long long min_sample = samples[cur_sample-1];
+ unsigned int line_header_len = header_len(max_sample);
+ unsigned int plot_line_len = cols - line_header_len;
+ unsigned int bucket_size;
+
+ memset(buckets, 0, sizeof(buckets));
+
+ /*
+ * We work with discrete data buckets smaller than 1 does not make
+ * sense as well as it's a good idea to keep buckets integer sized
+ * to avoid scaling artifacts.
+ */
+ bucket_size = MAX(1u, ceilu(1.00 * (max_sample - min_sample)/(rows-1)));
+
+ for (i = 0; i < cur_sample; i++) {
+ unsigned int bucket;
+ bucket = flooru(1.00 * (samples[i] - min_sample)/bucket_size);
+ buckets[bucket]++;
+ }
+
+ unsigned int max_bucket = buckets[0];
+ for (i = 1; i < rows; i++)
+ max_bucket = MAX(max_bucket, buckets[i]);
+
+ fprintf(stderr, "\n%*s| Frequency\n", line_header_len - 2, table_heading);
+
+ print_line('-', cols);
+ fputc('\n', stderr);
+
+ unsigned int l, r;
+
+ for (l = 0; l < rows; l++) {
+ if (buckets[l])
+ break;
+ }
+
+ for (r = rows-1; r > l; r--) {
+ if (buckets[r])
+ break;
+ }
+
+ for (i = l; i <= r; i++) {
+ float len = bucket_len(buckets[i], max_bucket, plot_line_len);
+
+ fprintf(stderr, "%*lli | ",
+ line_header_len - 3, min_sample + bucket_size*i);
+ print_line('*', len);
+
+ if ((len - (int)len) >= 0.5)
+ fputc('+', stderr);
+ else if ((len - (int)len) >= 0.25)
+ fputc('-', stderr);
+ else if (len < 0.25 && buckets[i])
+ fputc('.', stderr);
+
+ fputc('\n', stderr);
+ }
+
+ print_line('-', cols);
+ fputc('\n', stderr);
+
+ float scale = 1.00 * plot_line_len / max_bucket;
+
+ fprintf(stderr,
+ "%*uus | 1 sample = %.5f '*', %.5f '+', %.5f '-', non-zero '.'\n",
+ line_header_len - 5, bucket_size, scale, scale * 2, scale * 4);
+
+ fputc('\n', stderr);
+}
+
+void tst_timer_sample(void)
+{
+ samples[cur_sample++] = tst_timer_elapsed_us();
+}
+
+static int cmp(const void *a, const void *b)
+{
+ const long long *aa = a, *bb = b;
+
+ return (*bb - *aa);
+}
+
+/*
+ * The threshold per one syscall is computed as a sum of:
+ *
+ * 400 us - accomodates for context switches, process
+ * migrations between CPUs on SMP, etc.
+ * 2*monotonic_resolution - accomodates for granurality of the CLOCK_MONOTONIC
+ * slack_per_scall - max of 0.1% of the sleep capped on 100ms or
+ * current->timer_slack_ns, which is slack allowed
+ * in kernel
+ *
+ * The formula for slack_per_scall applies to select() and *poll*() syscalls,
+ * the futex and *nanosleep() use only the timer_slack_ns, so we are a bit
+ * less strict here that we could be for these two for longer sleep times...
+ *
+ * We also allow for outliners, i.e. add some number to the threshold in case
+ * that the number of iteration is small. For large enoung number of iterations
+ * outliners are discarded and averaged out.
+ */
+static long long compute_threshold(long long requested_us,
+ unsigned int nsamples)
+{
+ unsigned int slack_per_scall = MIN(100000, requested_us / 1000);
+
+ slack_per_scall = MAX(slack_per_scall, timerslack);
+
+ return (400 + 2 * monotonic_resolution + slack_per_scall) * nsamples
+ + 3000/nsamples;
+}
+
+/*
+ * Returns number of samples to discard.
+ *
+ * We set it to either at least 1 if number of samples > 1 or 5%.
+ */
+static unsigned int compute_discard(unsigned int nsamples)
+{
+ if (nsamples == 1)
+ return 0;
+
+ return MAX(1u, nsamples / 20);
+}
+
+static void write_to_file(void)
+{
+ unsigned int i;
+ FILE *f;
+
+ if (!file_name)
+ return;
+
+ f = fopen(file_name, "w");
+
+ if (!f) {
+ tst_res(TWARN | TERRNO,
+ "Failed to open '%s'", file_name);
+ return;
+ }
+
+ for (i = 0; i < cur_sample; i++)
+ fprintf(f, "%lli\n", samples[i]);
+
+ if (fclose(f)) {
+ tst_res(TWARN | TERRNO,
+ "Failed to close file '%s'", file_name);
+ }
+}
+
+
+/*
+ * Timer testing function.
+ *
+ * What we do here is:
+ *
+ * * Take nsamples measurements of the timer function, the function
+ * to be sampled is defined in the the actual test.
+ *
+ * * We sort the array of samples, then:
+ *
+ * - look for outliners which are samples where the sleep time has exceeded
+ * requested sleep time by an order of magnitude and, at the same time, are
+ * greater than clock resolution multiplied by three.
+ *
+ * - check for samples where the call has woken up too early which is a plain
+ * old bug
+ *
+ * - then we compute truncated mean and compare that with the requested sleep
+ * time increased by a threshold
+ */
+void do_timer_test(long long usec, unsigned int nsamples)
+{
+ long long trunc_mean, median;
+ unsigned int discard = compute_discard(nsamples);
+ unsigned int keep_samples = nsamples - discard;
+ long long threshold = compute_threshold(usec, keep_samples);
+ int i;
+ int failed = 0;
+
+ tst_res(TINFO,
+ "%s sleeping for %llius %u iterations, threshold %.2fus",
+ scall, usec, nsamples, 1.00 * threshold / (keep_samples));
+
+ cur_sample = 0;
+ for (i = 0; i < (int)nsamples; i++) {
+ if (sample(CLOCK_MONOTONIC, usec)) {
+ tst_res(TINFO, "sampling function failed, exitting");
+ return;
+ }
+ }
+
+ qsort(samples, nsamples, sizeof(samples[0]), cmp);
+
+ write_to_file();
+
+ for (i = 0; samples[i] > 10 * usec && i < (int)nsamples; i++) {
+ if (samples[i] <= 3 * monotonic_resolution)
+ break;
+ }
+
+ if (i > 0) {
+ tst_res(TINFO, "Found %i outliners in [%lli,%lli] range",
+ i, samples[0], samples[i-1]);
+ }
+
+ for (i = nsamples - 1; samples[i] < usec && i > -1; i--);
+
+ if (i < (int)nsamples - 1) {
+ tst_res(TFAIL, "%s woken up early %u times range: [%lli,%lli]",
+ scall, nsamples - 1 - i,
+ samples[i+1], samples[nsamples-1]);
+ failed = 1;
+ }
+
+ median = samples[nsamples/2];
+
+ trunc_mean = 0;
+
+ for (i = discard; i < (int)nsamples; i++)
+ trunc_mean += samples[i];
+
+ tst_res(TINFO,
+ "min %llius, max %llius, median %llius, trunc mean %.2fus (discarded %u)",
+ samples[nsamples-1], samples[0], median,
+ 1.00 * trunc_mean / keep_samples, discard);
+
+ if (virt_env) {
+ tst_res(TINFO,
+ "Virtualisation detected, skipping oversleep checks");
+ } else if (trunc_mean > (nsamples - discard) * usec + threshold) {
+ tst_res(TFAIL, "%s slept for too long", scall);
+
+ if (!print_frequency_plot)
+ frequency_plot();
+
+ failed = 1;
+ }
+
+ if (print_frequency_plot)
+ frequency_plot();
+
+ if (!failed)
+ tst_res(TPASS, "Measured times are within thresholds");
+}
+
+static void parse_timer_opts(void);
+
+static int set_latency(void)
+{
+ int fd, latency = 0;
+
+ fd = open("/dev/cpu_dma_latency", O_WRONLY);
+ if (fd < 0)
+ return fd;
+
+ return write(fd, &latency, sizeof(latency));
+}
+
+static void timer_setup(void)
+{
+ struct timespec t;
+ int ret;
+
+ if (setup)
+ setup();
+
+ /*
+ * Running tests in VM may cause timing issues, disable upper bound
+ * checks if any hypervisor is detected.
+ */
+ virt_env = tst_is_virt(VIRT_ANY);
+ tst_clock_getres(CLOCK_MONOTONIC, &t);
+
+ tst_res(TINFO, "CLOCK_MONOTONIC resolution %lins", (long)t.tv_nsec);
+
+ monotonic_resolution = t.tv_nsec / 1000;
+ timerslack = 50;
+
+#ifdef PR_GET_TIMERSLACK
+ ret = prctl(PR_GET_TIMERSLACK);
+ if (ret < 0) {
+ tst_res(TINFO, "prctl(PR_GET_TIMERSLACK) = -1, using %uus",
+ timerslack);
+ } else {
+ timerslack = ret / 1000;
+ tst_res(TINFO, "prctl(PR_GET_TIMERSLACK) = %ius", timerslack);
+ }
+#else
+ tst_res(TINFO, "PR_GET_TIMERSLACK not defined, using %uus",
+ timerslack);
+#endif /* PR_GET_TIMERSLACK */
+ parse_timer_opts();
+
+ samples = SAFE_MALLOC(sizeof(long long) * MAX(MAX_SAMPLES, sample_cnt));
+ if (set_latency() < 0)
+ tst_res(TINFO, "Failed to set zero latency constraint: %m");
+}
+
+static void timer_cleanup(void)
+{
+ free(samples);
+
+ if (cleanup)
+ cleanup();
+}
+
+static struct tst_timer_tcase {
+ long long usec;
+ unsigned int samples;
+} tcases[] = {
+ {1000, 500},
+ {2000, 500},
+ {5000, 300},
+ {10000, 100},
+ {25000, 50},
+ {100000, 10},
+ {1000000, 2},
+};
+
+static void timer_test_fn(unsigned int n)
+{
+ do_timer_test(tcases[n].usec, tcases[n].samples);
+}
+
+static void single_timer_test(void)
+{
+ do_timer_test(sleep_time, sample_cnt);
+}
+
+static struct tst_option options[] = {
+ {"p", &print_frequency_plot, "-p Print frequency plot"},
+ {"s:", &str_sleep_time, "-s us Sleep time"},
+ {"n:", &str_sample_cnt, "-n uint Number of samples to take"},
+ {"f:", &file_name, "-f fname Write measured samples into a file"},
+ {NULL, NULL, NULL}
+};
+
+static void parse_timer_opts(void)
+{
+ if (str_sleep_time) {
+ if (tst_parse_int(str_sleep_time, &sleep_time, 0, INT_MAX)) {
+ tst_brk(TBROK,
+ "Invalid sleep time '%s'", str_sleep_time);
+ }
+ }
+
+ if (str_sample_cnt) {
+ if (tst_parse_int(str_sample_cnt, &sample_cnt, 1, INT_MAX)) {
+ tst_brk(TBROK,
+ "Invalid sample count '%s'", str_sample_cnt);
+ }
+ }
+
+ if (str_sleep_time || str_sample_cnt) {
+ if (sleep_time < 0)
+ sleep_time = 10000;
+
+ if (!sample_cnt)
+ sample_cnt = 500;
+
+ long long timeout = sleep_time * sample_cnt / 1000000;
+
+ tst_set_timeout(timeout + timeout/10);
+
+ test->test_all = single_timer_test;
+ test->test = NULL;
+ test->tcnt = 0;
+ }
+}
+
+struct tst_test *tst_timer_test_setup(struct tst_test *timer_test)
+{
+ setup = timer_test->setup;
+ cleanup = timer_test->cleanup;
+ scall = timer_test->scall;
+ sample = timer_test->sample;
+
+ timer_test->scall = NULL;
+ timer_test->setup = timer_setup;
+ timer_test->cleanup = timer_cleanup;
+ timer_test->test = timer_test_fn;
+ timer_test->tcnt = ARRAY_SIZE(tcases);
+ timer_test->sample = NULL;
+ timer_test->options = options;
+
+ test = timer_test;
+
+ return timer_test;
+}
diff --git a/kernel/tests/lib/tst_tmpdir.c b/kernel/tests/lib/tst_tmpdir.c
new file mode 100644
index 0000000..0c39eb8
--- /dev/null
+++ b/kernel/tests/lib/tst_tmpdir.c
@@ -0,0 +1,347 @@
+/**********************************************************
+ * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it is
+ * free of the rightful claim of any third person regarding infringement
+ * or the like. Any license provided herein, whether implied or
+ * otherwise, applies only to this software file. Patent licenses, if
+ * any, provided herein do not apply to combinations of this program with
+ * other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
+ * Mountain View, CA 94043, or:
+ *
+ * http://www.sgi.com
+ *
+ * For further information regarding this notice, see:
+ *
+ * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
+ *********************************************************/
+
+/**********************************************************
+ *
+ * OS Testing - Silicon Graphics, Inc.
+ *
+ * FUNCTION NAME : tst_tmpdir, tst_rmdir
+ *
+ * FUNCTION TITLE : Create/remove a testing temp dir
+ *
+ * SYNOPSIS:
+ * void tst_tmpdir();
+ * void tst_rmdir();
+ *
+ * AUTHOR : Dave Fenner
+ *
+ * INITIAL RELEASE : UNICOS 8.0
+ *
+ * DESCRIPTION
+ * tst_tmpdir() is used to create a unique, temporary testing
+ * directory, and make it the current working directory.
+ * tst_rmdir() is used to remove the directory created by
+ * tst_tmpdir().
+ *
+ * RETURN VALUE
+ * Neither tst_tmpdir() or tst_rmdir() has a return value.
+ *
+ *********************************************************/
+#define _GNU_SOURCE
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <assert.h>
+#include <errno.h>
+#include <libgen.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <fcntl.h>
+
+#include "test.h"
+#include "safe_macros.h"
+#include "ltp_priv.h"
+#include "lapi/futex.h"
+
+/*
+ * Define some useful macros.
+ */
+#define DIR_MODE (S_IRWXU|S_IRWXG|S_IRWXO)
+
+#ifndef PATH_MAX
+#ifdef MAXPATHLEN
+#define PATH_MAX MAXPATHLEN
+#else
+#define PATH_MAX 1024
+#endif
+#endif
+
+/*
+ * Define global variables.
+ */
+extern char *TCID; /* defined/initialized in main() */
+static char *TESTDIR = NULL; /* the directory created */
+
+static char test_start_work_dir[PATH_MAX];
+
+/* lib/tst_checkpoint.c */
+extern futex_t *tst_futexes;
+
+static int rmobj(const char *obj, char **errmsg);
+
+int tst_tmpdir_created(void)
+{
+ return TESTDIR != NULL;
+}
+
+char *tst_get_tmpdir(void)
+{
+ if (TESTDIR == NULL) {
+ tst_brkm(TBROK, NULL, "you must call tst_tmpdir() first");
+ return NULL;
+ }
+
+ return strdup(TESTDIR);
+}
+
+const char *tst_get_startwd(void)
+{
+ return test_start_work_dir;
+}
+
+static int purge_dir(const char *path, char **errptr)
+{
+ int ret_val = 0;
+ DIR *dir;
+ struct dirent *dir_ent;
+ char dirobj[PATH_MAX];
+ static char err_msg[PATH_MAX + 1280];
+
+ /* Do NOT perform the request if the directory is "/" */
+ if (!strcmp(path, "/")) {
+ if (errptr) {
+ strcpy(err_msg, "Cannot purge system root directory");
+ *errptr = err_msg;
+ }
+
+ return -1;
+ }
+
+ errno = 0;
+
+ /* Open the directory to get access to what is in it */
+ if (!(dir = opendir(path))) {
+ if (errptr) {
+ sprintf(err_msg,
+ "Cannot open directory %s; errno=%d: %s",
+ path, errno, tst_strerrno(errno));
+ *errptr = err_msg;
+ }
+ return -1;
+ }
+
+ /* Loop through the entries in the directory, removing each one */
+ for (dir_ent = readdir(dir); dir_ent; dir_ent = readdir(dir)) {
+ /* Don't remove "." or ".." */
+ if (!strcmp(dir_ent->d_name, ".")
+ || !strcmp(dir_ent->d_name, ".."))
+ continue;
+
+ /* Recursively remove the current entry */
+ sprintf(dirobj, "%s/%s", path, dir_ent->d_name);
+ if (rmobj(dirobj, errptr) != 0)
+ ret_val = -1;
+ }
+
+ closedir(dir);
+ return ret_val;
+}
+
+static int rmobj(const char *obj, char **errmsg)
+{
+ int ret_val = 0;
+ struct stat statbuf;
+ static char err_msg[PATH_MAX + 1280];
+ int fd;
+
+ fd = open(obj, O_DIRECTORY | O_NOFOLLOW);
+ if (fd >= 0) {
+ close(fd);
+ ret_val = purge_dir(obj, errmsg);
+
+ /* If there were problems removing an entry, don't attempt to
+ remove the directory itself */
+ if (ret_val == -1)
+ return -1;
+
+ /* Get the link count, now that all the entries have been removed */
+ if (lstat(obj, &statbuf) < 0) {
+ if (errmsg != NULL) {
+ sprintf(err_msg,
+ "lstat(%s) failed; errno=%d: %s", obj,
+ errno, tst_strerrno(errno));
+ *errmsg = err_msg;
+ }
+ return -1;
+ }
+
+ /* Remove the directory itself */
+ if (statbuf.st_nlink >= 3) {
+ /* The directory is linked; unlink() must be used */
+ if (unlink(obj) < 0) {
+ if (errmsg != NULL) {
+ sprintf(err_msg,
+ "unlink(%s) failed; errno=%d: %s",
+ obj, errno, tst_strerrno(errno));
+ *errmsg = err_msg;
+ }
+ return -1;
+ }
+ } else {
+ /* The directory is not linked; remove() can be used */
+ if (remove(obj) < 0) {
+ if (errmsg != NULL) {
+ sprintf(err_msg,
+ "remove(%s) failed; errno=%d: %s",
+ obj, errno, tst_strerrno(errno));
+ *errmsg = err_msg;
+ }
+ return -1;
+ }
+ }
+ } else {
+ if (unlink(obj) < 0) {
+ if (errmsg != NULL) {
+ sprintf(err_msg,
+ "unlink(%s) failed; errno=%d: %s", obj,
+ errno, tst_strerrno(errno));
+ *errmsg = err_msg;
+ }
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+void tst_tmpdir(void)
+{
+ char template[PATH_MAX];
+ char *env_tmpdir;
+ char *errmsg, *c;
+
+ /*
+ * Create a template for the temporary directory. Use the
+ * environment variable TMPDIR if it is available, otherwise
+ * use our default TEMPDIR.
+ */
+ env_tmpdir = getenv("TMPDIR");
+ if (env_tmpdir) {
+ c = strchr(env_tmpdir, '/');
+ /*
+ * Now we force environment variable TMPDIR to be an absolute
+ * pathname, which dose not make much sense, but it will
+ * greatly simplify code in tst_rmdir().
+ */
+ if (c != env_tmpdir) {
+ tst_brkm(TBROK, NULL, "You must specify an absolute "
+ "pathname for environment variable TMPDIR");
+ return;
+ }
+ snprintf(template, PATH_MAX, "%s/%.3sXXXXXX", env_tmpdir, TCID);
+ } else {
+ snprintf(template, PATH_MAX, "%s/%.3sXXXXXX", TEMPDIR, TCID);
+ }
+
+ /* Make the temporary directory in one shot using mkdtemp. */
+ if (mkdtemp(template) == NULL) {
+ tst_brkm(TBROK | TERRNO, NULL,
+ "%s: mkdtemp(%s) failed", __func__, template);
+ return;
+ }
+
+ if ((TESTDIR = strdup(template)) == NULL) {
+ tst_brkm(TBROK | TERRNO, NULL,
+ "%s: strdup(%s) failed", __func__, template);
+ return;
+ }
+
+ SAFE_CHOWN(NULL, TESTDIR, -1, getgid());
+
+ SAFE_CHMOD(NULL, TESTDIR, DIR_MODE);
+
+ if (getcwd(test_start_work_dir, sizeof(test_start_work_dir)) == NULL) {
+ tst_resm(TINFO, "Failed to record test working dir");
+ test_start_work_dir[0] = '\0';
+ }
+
+ /*
+ * Change to the temporary directory. If the chdir() fails, issue
+ * TBROK messages for all test cases, attempt to remove the
+ * directory (if it was created), and exit. If the removal also
+ * fails, also issue a TWARN message.
+ */
+ if (chdir(TESTDIR) == -1) {
+ tst_resm(TERRNO, "%s: chdir(%s) failed", __func__, TESTDIR);
+
+ /* Try to remove the directory */
+ if (rmobj(TESTDIR, &errmsg) == -1) {
+ tst_resm(TWARN, "%s: rmobj(%s) failed: %s",
+ __func__, TESTDIR, errmsg);
+ }
+
+ tst_exit();
+ }
+}
+
+void tst_rmdir(void)
+{
+ char *errmsg;
+
+ /*
+ * Check that TESTDIR is not NULL.
+ */
+ if (TESTDIR == NULL) {
+ tst_resm(TWARN,
+ "%s: TESTDIR was NULL; no removal attempted",
+ __func__);
+ return;
+ }
+
+ /*
+ * Unmap the backend file.
+ * This is needed to overcome the NFS "silly rename" feature.
+ */
+ if (tst_futexes) {
+ msync((void *)tst_futexes, getpagesize(), MS_SYNC);
+ munmap((void *)tst_futexes, getpagesize());
+ }
+
+ /*
+ * Attempt to remove the "TESTDIR" directory, using rmobj().
+ */
+ if (rmobj(TESTDIR, &errmsg) == -1) {
+ tst_resm(TWARN, "%s: rmobj(%s) failed: %s",
+ __func__, TESTDIR, errmsg);
+ }
+}
+
+void tst_purge_dir(const char *path)
+{
+ char *err;
+
+ if (purge_dir(path, &err))
+ tst_brkm(TBROK, NULL, "%s: %s", __func__, err);
+}
diff --git a/kernel/tests/lib/tst_virt.c b/kernel/tests/lib/tst_virt.c
new file mode 100644
index 0000000..53d33e6
--- /dev/null
+++ b/kernel/tests/lib/tst_virt.c
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2013 Linux Test Project
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it
+ * is free of the rightful claim of any third person regarding
+ * infringement or the like. Any license provided herein, whether
+ * implied or otherwise, applies only to this software file. Patent
+ * licenses, if any, provided herein do not apply to combinations of
+ * this program with other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <unistd.h>
+#include "test.h"
+#include "safe_macros.h"
+
+static int is_kvm(void)
+{
+ FILE *cpuinfo;
+ char line[64];
+ int found;
+
+ /* this doesn't work with custom -cpu values, since there's
+ * no easy, reasonable or reliable way to work around those */
+ cpuinfo = SAFE_FOPEN(NULL, "/proc/cpuinfo", "r");
+ found = 0;
+ while (fgets(line, sizeof(line), cpuinfo) != NULL) {
+ if (strstr(line, "QEMU Virtual CPU")) {
+ found = 1;
+ break;
+ }
+ }
+
+ SAFE_FCLOSE(NULL, cpuinfo);
+ return found;
+}
+
+static int is_xen(void)
+{
+ char hypervisor_type[4];
+
+ if (access("/proc/xen", F_OK) == 0)
+ return 1;
+
+ if (access("/sys/hypervisor/type", F_OK) == 0) {
+ SAFE_FILE_SCANF(NULL, "/sys/hypervisor/type", "%3s",
+ hypervisor_type);
+ return strncmp("xen", hypervisor_type,
+ sizeof(hypervisor_type)) == 0;
+ }
+
+ return 0;
+}
+
+static int try_systemd_detect_virt(void)
+{
+ FILE *f;
+ char virt_type[64];
+ int ret;
+
+ /* See tst_cmd.c */
+ void *old_handler = signal(SIGCHLD, SIG_DFL);
+
+ f = popen("systemd-detect-virt", "r");
+ if (!f) {
+ signal(SIGCHLD, old_handler);
+ return 0;
+ }
+
+ if (!fgets(virt_type, sizeof(virt_type), f))
+ virt_type[0] = '\0';
+
+ ret = pclose(f);
+
+ signal(SIGCHLD, old_handler);
+
+ /*
+ * systemd-detect-virt not found by shell or no virtualization detected
+ * (systemd-detect-virt returns non-zero)
+ */
+ if (ret < 0 || (WIFEXITED(ret) && WEXITSTATUS(ret) == 127))
+ return -1;
+
+ if (ret)
+ return 0;
+
+ if (!strncmp("kvm", virt_type, 3))
+ return VIRT_KVM;
+
+ if (!strncmp("xen", virt_type, 3))
+ return VIRT_XEN;
+
+ return VIRT_OTHER;
+}
+
+int tst_is_virt(int virt_type)
+{
+ int ret = try_systemd_detect_virt();
+
+ if (ret >= 0) {
+ if (virt_type == VIRT_ANY)
+ return ret != 0;
+ else
+ return ret == virt_type;
+ }
+
+ switch (virt_type) {
+ case VIRT_ANY:
+ return is_xen() || is_kvm();
+ case VIRT_XEN:
+ return is_xen();
+ case VIRT_KVM:
+ return is_kvm();
+ case VIRT_OTHER:
+ return 0;
+ }
+
+ tst_brkm(TBROK, NULL, "invalid virt_type flag: %d", virt_type);
+ return -1;
+}
diff --git a/kernel/tests/lib/tst_wallclock.c b/kernel/tests/lib/tst_wallclock.c
new file mode 100644
index 0000000..282d6ad
--- /dev/null
+++ b/kernel/tests/lib/tst_wallclock.c
@@ -0,0 +1,60 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Linaro Limited. All rights reserved.
+ * Author: Rafael David Tinoco <rafael.tinoco@linaro.org>
+ */
+
+#include <errno.h>
+
+#define TST_NO_DEFAULT_MAIN
+
+#include "tst_test.h"
+#include "tst_timer.h"
+#include "tst_clocks.h"
+#include "tst_wallclock.h"
+#include "lapi/posix_clocks.h"
+
+static struct timespec real_begin, mono_begin;
+
+static int clock_saved;
+
+void tst_wallclock_save(void)
+{
+ /* save initial monotonic time to restore it when needed */
+
+ if (tst_clock_gettime(CLOCK_REALTIME, &real_begin))
+ tst_brk(TBROK | TERRNO, "tst_clock_gettime() realtime failed");
+
+ if (tst_clock_gettime(CLOCK_MONOTONIC_RAW, &mono_begin)) {
+ if (errno == EINVAL) {
+ tst_brk(TCONF | TERRNO,
+ "tst_clock_gettime() didn't support CLOCK_MONOTONIC_RAW");
+ }
+
+ tst_brk(TBROK | TERRNO, "tst_clock_gettime() monotonic failed");
+ }
+
+ clock_saved = 1;
+}
+
+void tst_wallclock_restore(void)
+{
+ static struct timespec mono_end, elapsed, adjust;
+
+ if (!clock_saved)
+ return;
+
+ clock_saved = 0;
+
+ if (tst_clock_gettime(CLOCK_MONOTONIC_RAW, &mono_end))
+ tst_brk(TBROK | TERRNO, "tst_clock_gettime() monotonic failed");
+
+ elapsed = tst_timespec_diff(mono_end, mono_begin);
+
+ adjust = tst_timespec_add(real_begin, elapsed);
+
+ /* restore realtime clock based on monotonic delta */
+
+ if (tst_clock_settime(CLOCK_REALTIME, &adjust))
+ tst_brk(TBROK | TERRNO, "tst_clock_settime() realtime failed");
+}
diff --git a/kernel/tests/testcases/kernel/syscalls/ioctl/CMakeLists.txt b/kernel/tests/testcases/kernel/syscalls/ioctl/CMakeLists.txt
new file mode 100644
index 0000000..e0687ec
--- /dev/null
+++ b/kernel/tests/testcases/kernel/syscalls/ioctl/CMakeLists.txt
@@ -0,0 +1,32 @@
+cmake_minimum_required(VERSION 3.12)
+
+project(xloop-kernel-test-ioctl-xloop)
+
+# test ioctl_xloop01
+add_executable(tst_ioctl_xloop01 ${CMAKE_CURRENT_SOURCE_DIR}/ioctl_loop01.c)
+target_link_libraries(tst_ioctl_xloop01 LINK_PUBLIC libltp)
+install(TARGETS tst_ioctl_xloop01 DESTINATION bin)
+
+# test ioctl_xloop02
+add_executable(tst_ioctl_xloop02 ${CMAKE_CURRENT_SOURCE_DIR}/ioctl_loop02.c)
+target_link_libraries(tst_ioctl_xloop02 LINK_PUBLIC libltp)
+
+# test ioctl_xloop03
+add_executable(tst_ioctl_xloop03 ${CMAKE_CURRENT_SOURCE_DIR}/ioctl_loop03.c)
+target_link_libraries(tst_ioctl_xloop03 LINK_PUBLIC libltp)
+
+# test ioctl_xloop04
+add_executable(tst_ioctl_xloop04 ${CMAKE_CURRENT_SOURCE_DIR}/ioctl_loop04.c)
+target_link_libraries(tst_ioctl_xloop04 LINK_PUBLIC libltp)
+
+# test ioctl_xloop05
+add_executable(tst_ioctl_xloop05 ${CMAKE_CURRENT_SOURCE_DIR}/ioctl_loop05.c)
+target_link_libraries(tst_ioctl_xloop05 LINK_PUBLIC libltp)
+
+# test ioctl_xloop06
+add_executable(tst_ioctl_xloop06 ${CMAKE_CURRENT_SOURCE_DIR}/ioctl_loop06.c)
+target_link_libraries(tst_ioctl_xloop06 LINK_PUBLIC libltp)
+
+# test ioctl_xloop07
+add_executable(tst_ioctl_xloop07 ${CMAKE_CURRENT_SOURCE_DIR}/ioctl_loop07.c)
+target_link_libraries(tst_ioctl_xloop07 LINK_PUBLIC libltp) \ No newline at end of file
diff --git a/kernel/tests/testcases/kernel/syscalls/ioctl/ioctl_loop01.c b/kernel/tests/testcases/kernel/syscalls/ioctl/ioctl_loop01.c
new file mode 100644
index 0000000..cf71184
--- /dev/null
+++ b/kernel/tests/testcases/kernel/syscalls/ioctl/ioctl_loop01.c
@@ -0,0 +1,155 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@cn.jujitsu.com>
+ *
+ * This is a basic ioctl test about loopdevice.
+ * It is designed to test LO_FLAGS_AUTOCLEAR and LO_FLAGS_PARTSCAN flag.
+ *
+ * For LO_FLAGS_AUTOCLEAR flag, we only check autoclear field value in sys
+ * directory and also get lo_flags by using LOOP_GET_STATUS.
+ *
+ * For LO_FLAGS_PARTSCAN flag, it is the same as LO_FLAGS_AUTOCLEAR flag.
+ * But we also check whether we can scan partition table correctly ie check
+ * whether /dev/loopnp1 and /sys/bloclk/loop0/loop0p1 existed.
+ *
+ * For LO_FLAGS_AUTOCLEAR flag, it can be clear. For LO_FLAGS_PARTSCAN flag,
+ * it cannot be clear. We also check this.
+ *
+ * It is also a regression test for kernel
+ * commit 10c70d95c0f2 ("block: remove the bd_openers checks in blk_drop_partitions")
+ * commit 6ac92fb5cdff ("loop: Fix wrong masking of status flags").
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include "lapi/loop.h"
+#include "tst_test.h"
+
+static char dev_path[1024], backing_path[1024], backing_file_path[1024];
+static int dev_num, attach_flag, dev_fd, parted_sup;
+
+/*
+ * In drivers/block/loop.c code, set status function doesn't handle
+ * LO_FLAGS_READ_ONLY flag and ingore it. Only loop_set_fd with read only mode
+ * file_fd, lo_flags will include LO_FLAGS_READ_ONLY and it's the same for
+ * LO_FLAGS_DIRECT_IO.
+ */
+#define SET_FLAGS (LO_FLAGS_AUTOCLEAR | LO_FLAGS_PARTSCAN | LO_FLAGS_READ_ONLY | LO_FLAGS_DIRECT_IO)
+#define GET_FLAGS (LO_FLAGS_AUTOCLEAR | LO_FLAGS_PARTSCAN)
+
+static char partscan_path[1024], autoclear_path[1024];
+static char loop_partpath[1026], sys_loop_partpath[1026];
+
+static void check_loop_value(int set_flag, int get_flag, int autoclear_field)
+{
+ struct loop_info loopinfo = {0}, loopinfoget = {0};
+ int ret;
+
+ loopinfo.lo_flags = set_flag;
+ SAFE_IOCTL(dev_fd, LOOP_SET_STATUS, &loopinfo);
+ SAFE_IOCTL(dev_fd, LOOP_GET_STATUS, &loopinfoget);
+
+ if (loopinfoget.lo_flags & ~get_flag)
+ tst_res(TFAIL, "expect %d but got %d", get_flag, loopinfoget.lo_flags);
+ else
+ tst_res(TPASS, "get expected lo_flag %d", loopinfoget.lo_flags);
+
+ TST_ASSERT_INT(partscan_path, 1);
+ TST_ASSERT_INT(autoclear_path, autoclear_field);
+
+ if (!parted_sup) {
+ tst_res(TINFO, "Current environment doesn't have parted disk, skip it");
+ return;
+ }
+
+ ret = TST_RETRY_FN_EXP_BACKOFF(access(loop_partpath, F_OK), TST_RETVAL_EQ0, 30);
+ if (ret == 0)
+ tst_res(TPASS, "access %s succeeds", loop_partpath);
+ else
+ tst_res(TFAIL, "access %s fails", loop_partpath);
+
+ ret = TST_RETRY_FN_EXP_BACKOFF(access(sys_loop_partpath, F_OK), TST_RETVAL_EQ0, 30);
+ if (ret == 0)
+ tst_res(TPASS, "access %s succeeds", sys_loop_partpath);
+ else
+ tst_res(TFAIL, "access %s fails", sys_loop_partpath);
+}
+
+static void verify_ioctl_loop(void)
+{
+ tst_attach_device(dev_path, "test.img");
+ attach_flag = 1;
+
+ TST_ASSERT_INT(partscan_path, 0);
+ TST_ASSERT_INT(autoclear_path, 0);
+ TST_ASSERT_STR(backing_path, backing_file_path);
+
+ check_loop_value(SET_FLAGS, GET_FLAGS, 1);
+
+ tst_res(TINFO, "Test flag can be clear");
+ check_loop_value(0, LO_FLAGS_PARTSCAN, 0);
+
+ tst_detach_device_by_fd(dev_path, dev_fd);
+ attach_flag = 0;
+}
+
+static void setup(void)
+{
+ int ret;
+ const char *const cmd_parted[] = {"parted", "-s", "test.img", "mklabel", "msdos", "mkpart",
+ "primary", "ext4", "1M", "10M", NULL};
+
+ dev_num = tst_find_free_loopdev(dev_path, sizeof(dev_path));
+ if (dev_num < 0)
+ tst_brk(TBROK, "Failed to find free loop device");
+
+ tst_fill_file("test.img", 0, 1024 * 1024, 10);
+
+ ret = tst_cmd(cmd_parted, NULL, NULL, TST_CMD_PASS_RETVAL);
+ switch (ret) {
+ case 0:
+ parted_sup = 1;
+ break;
+ case 255:
+ tst_res(TCONF, "parted binary not installed or failed");
+ break;
+ default:
+ tst_res(TCONF, "parted exited with %i", ret);
+ break;
+ }
+
+ sprintf(partscan_path, "/sys/block/loop%d/loop/partscan", dev_num);
+ sprintf(autoclear_path, "/sys/block/loop%d/loop/autoclear", dev_num);
+ sprintf(backing_path, "/sys/block/loop%d/loop/backing_file", dev_num);
+ sprintf(sys_loop_partpath, "/sys/block/loop%d/loop%dp1", dev_num, dev_num);
+ sprintf(backing_file_path, "%s/test.img", tst_get_tmpdir());
+ sprintf(loop_partpath, "%sp1", dev_path);
+ dev_fd = SAFE_OPEN(dev_path, O_RDWR);
+}
+
+static void cleanup(void)
+{
+ if (dev_fd > 0)
+ SAFE_CLOSE(dev_fd);
+ if (attach_flag)
+ tst_detach_device(dev_path);
+}
+
+static struct tst_test test = {
+ .setup = setup,
+ .cleanup = cleanup,
+ .test_all = verify_ioctl_loop,
+ .needs_root = 1,
+ .needs_drivers = (const char *const []) {
+ "loop",
+ NULL
+ },
+ .tags = (const struct tst_tag[]) {
+ {"linux-git", "10c70d95c0f2"},
+ {"linux-git", "6ac92fb5cdff"},
+ {}
+ },
+ .needs_tmpdir = 1,
+};
diff --git a/kernel/tests/testcases/kernel/syscalls/ioctl/ioctl_loop02.c b/kernel/tests/testcases/kernel/syscalls/ioctl/ioctl_loop02.c
new file mode 100644
index 0000000..ac61842
--- /dev/null
+++ b/kernel/tests/testcases/kernel/syscalls/ioctl/ioctl_loop02.c
@@ -0,0 +1,164 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@cn.jujitsu.com>
+ *
+ * This is a basic ioctl test about loopdevice.
+ *
+ * It is designed to test LO_FLAGS_READ_ONLY (similar as losetup -r)
+ * and LOOP_CHANGE_FD.
+ *
+ * For LOOP_CHANGE_FD, this operation is possible only if the loop device
+ * is read-only and the new backing store is the same size and type as the
+ * old backing store.
+ *
+ * If using LOOP_CONFIGURE ioctl, we can set LO_FLAGS_READ_ONLY
+ * flag even though backing file with write mode.
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include "lapi/loop.h"
+#include "tst_test.h"
+
+static int file_fd, file_change_fd, file_fd_invalid;
+static char backing_path[1024], backing_file_path[1024], backing_file_change_path[1024];
+static int attach_flag, dev_fd, loop_configure_sup = 1;
+static char loop_ro_path[1024], dev_path[1024];
+static struct loop_config loopconfig;
+
+static struct tcase {
+ int mode;
+ int ioctl;
+ char *message;
+} tcases[] = {
+ {O_RDONLY, LOOP_SET_FD, "Using LOOP_SET_FD to setup loopdevice"},
+ {O_RDWR, LOOP_CONFIGURE, "Using LOOP_CONFIGURE with read_only flag"},
+};
+
+static void verify_ioctl_loop(unsigned int n)
+{
+ struct tcase *tc = &tcases[n];
+ struct loop_info loopinfoget;
+
+ if (tc->ioctl == LOOP_CONFIGURE && !loop_configure_sup) {
+ tst_res(TCONF, "LOOP_CONFIGURE ioctl not supported");
+ return;
+ }
+
+ tst_res(TINFO, "%s", tc->message);
+ file_fd = SAFE_OPEN("test.img", tc->mode);
+
+ if (tc->ioctl == LOOP_SET_FD) {
+ SAFE_IOCTL(dev_fd, LOOP_SET_FD, file_fd);
+ } else {
+ loopconfig.fd = file_fd;
+ SAFE_IOCTL(dev_fd, LOOP_CONFIGURE, &loopconfig);
+ }
+ attach_flag = 1;
+
+ TST_ASSERT_INT(loop_ro_path, 1);
+ TST_ASSERT_STR(backing_path, backing_file_path);
+
+ memset(&loopinfoget, 0, sizeof(loopinfoget));
+
+ SAFE_IOCTL(dev_fd, LOOP_GET_STATUS, &loopinfoget);
+
+ if (loopinfoget.lo_flags & ~LO_FLAGS_READ_ONLY)
+ tst_res(TFAIL, "lo_flags has unexpected %d flag", loopinfoget.lo_flags);
+ else
+ tst_res(TPASS, "lo_flags only has default LO_FLAGS_READ_ONLY flag");
+
+ TEST(write(dev_fd, "xx", 2));
+ if (TST_RET != -1)
+ tst_res(TFAIL, "write succeed unexpectedly");
+ else
+ tst_res(TPASS | TTERRNO, "Can not write data in RO mode");
+
+ TEST(ioctl(dev_fd, LOOP_CHANGE_FD, file_change_fd));
+ if (TST_RET) {
+ tst_res(TFAIL | TTERRNO, "LOOP_CHANGE_FD failed");
+ } else {
+ tst_res(TPASS, "LOOP_CHANGE_FD succeeded");
+ TST_ASSERT_INT(loop_ro_path, 1);
+ TST_ASSERT_STR(backing_path, backing_file_change_path);
+ }
+
+ TEST(ioctl(dev_fd, LOOP_CHANGE_FD, file_fd_invalid));
+ if (TST_RET) {
+ if (TST_ERR == EINVAL)
+ tst_res(TPASS | TTERRNO, "LOOP_CHANGE_FD failed as expected");
+ else
+ tst_res(TFAIL | TTERRNO, "LOOP_CHANGE_FD failed expected EINVAL got");
+ } else {
+ tst_res(TFAIL, "LOOP_CHANGE_FD succeeded");
+ }
+
+ SAFE_CLOSE(file_fd);
+ tst_detach_device_by_fd(dev_path, dev_fd);
+ attach_flag = 0;
+}
+
+static void setup(void)
+{
+ int dev_num;
+ int ret;
+
+ char *tmpdir = tst_get_tmpdir();
+ dev_num = tst_find_free_loopdev(dev_path, sizeof(dev_path));
+ if (dev_num < 0)
+ tst_brk(TBROK, "Failed to find free loop device");
+
+ tst_fill_file("test.img", 0, 1024, 10);
+ tst_fill_file("test1.img", 0, 1024, 10);
+ tst_fill_file("test2.img", 0, 2048, 20);
+
+ sprintf(backing_path, "/sys/block/loop%d/loop/backing_file", dev_num);
+ sprintf(backing_file_path, "%s/test.img", tmpdir);
+ sprintf(backing_file_change_path, "%s/test1.img", tmpdir);
+ sprintf(loop_ro_path, "/sys/block/loop%d/ro", dev_num);
+
+ free(tmpdir);
+
+ file_change_fd = SAFE_OPEN("test1.img", O_RDWR);
+ file_fd_invalid = SAFE_OPEN("test2.img", O_RDWR);
+
+ dev_fd = SAFE_OPEN(dev_path, O_RDWR);
+ loopconfig.fd = -1;
+ ret = ioctl(dev_fd, LOOP_CONFIGURE, &loopconfig);
+
+ if (ret && errno != EBADF) {
+ tst_res(TINFO | TERRNO, "LOOP_CONFIGURE is not supported");
+ loop_configure_sup = 0;
+ }
+ loopconfig.info.lo_flags = LO_FLAGS_READ_ONLY;
+}
+
+static void cleanup(void)
+{
+ if (dev_fd > 0)
+ SAFE_CLOSE(dev_fd);
+ if (file_fd > 0)
+ SAFE_CLOSE(file_fd);
+ if (file_change_fd > 0)
+ SAFE_CLOSE(file_change_fd);
+ if (file_fd_invalid > 0)
+ SAFE_CLOSE(file_fd_invalid);
+ if (attach_flag)
+ tst_detach_device(dev_path);
+}
+
+static struct tst_test test = {
+ .setup = setup,
+ .cleanup = cleanup,
+ .tcnt = ARRAY_SIZE(tcases),
+ .test = verify_ioctl_loop,
+ .needs_root = 1,
+ .needs_tmpdir = 1,
+ .needs_drivers = (const char *const []) {
+ "loop",
+ NULL
+ }
+};
diff --git a/kernel/tests/testcases/kernel/syscalls/ioctl/ioctl_loop03.c b/kernel/tests/testcases/kernel/syscalls/ioctl/ioctl_loop03.c
new file mode 100644
index 0000000..9cf5a41
--- /dev/null
+++ b/kernel/tests/testcases/kernel/syscalls/ioctl/ioctl_loop03.c
@@ -0,0 +1,75 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@cn.jujitsu.com>
+ *
+ * This is a basic ioctl test about loopdevice.
+ *
+ * It is designed to test LOOP_CHANGE_FD can not succeed (get EINVAL error)
+ * when loop_dev is not read only.
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include "lapi/loop.h"
+#include "tst_test.h"
+
+static char dev_path[1024];
+static int dev_num, dev_fd, file_fd, attach_flag;
+
+static void verify_ioctl_loop(void)
+{
+ TEST(ioctl(dev_fd, LOOP_CHANGE_FD, file_fd));
+ if (TST_RET == 0) {
+ tst_res(TFAIL, "LOOP_CHANGE_FD succeeded unexpectedly");
+ return;
+ }
+ if (TST_ERR == EINVAL)
+ tst_res(TPASS | TTERRNO, "LOOP_CHANGE_FD failed as expected");
+ else
+ tst_res(TFAIL | TTERRNO, "LOOP_CHANGE_FD failed expected EINVAL got");
+}
+
+static void setup(void)
+{
+ struct loop_info loopinfoget;
+
+ memset(&loopinfoget, 0, sizeof(loopinfoget));
+ dev_num = tst_find_free_loopdev(dev_path, sizeof(dev_path));
+ if (dev_num < 0)
+ tst_brk(TBROK, "Failed to find free loop device");
+
+ tst_fill_file("test.img", 0, 1024, 10);
+ tst_attach_device(dev_path, "test.img");
+ attach_flag = 1;
+
+ dev_fd = SAFE_OPEN(dev_path, O_RDWR);
+ file_fd = SAFE_OPEN("test.img", O_RDWR);
+ SAFE_IOCTL(dev_fd, LOOP_GET_STATUS, &loopinfoget);
+
+ if (loopinfoget.lo_flags & LO_FLAGS_READ_ONLY)
+ tst_brk(TCONF, "Current environment has unexpected LO_FLAGS_READ_ONLY flag");
+}
+
+static void cleanup(void)
+{
+ if (dev_fd > 0)
+ SAFE_CLOSE(dev_fd);
+ if (file_fd > 0)
+ SAFE_CLOSE(file_fd);
+ if (attach_flag)
+ tst_detach_device(dev_path);
+}
+
+static struct tst_test test = {
+ .setup = setup,
+ .cleanup = cleanup,
+ .test_all = verify_ioctl_loop,
+ .needs_root = 1,
+ .needs_tmpdir = 1,
+ .needs_drivers = (const char *const []) {
+ "loop",
+ NULL
+ }
+};
diff --git a/kernel/tests/testcases/kernel/syscalls/ioctl/ioctl_loop04.c b/kernel/tests/testcases/kernel/syscalls/ioctl/ioctl_loop04.c
new file mode 100644
index 0000000..b4ab44a
--- /dev/null
+++ b/kernel/tests/testcases/kernel/syscalls/ioctl/ioctl_loop04.c
@@ -0,0 +1,98 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@cn.jujitsu.com>
+ *
+ * This is a basic ioctl test about loopdevice.
+ *
+ * It is designed to test LOOP_SET_CAPACITY can update a live
+ * loop device size when we change the size of the underlying
+ * backing file. Also check sys value.
+ */
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include "lapi/loop.h"
+#include "tst_test.h"
+
+#define OLD_SIZE 10240
+#define NEW_SIZE 5120
+
+static char dev_path[1024], sys_loop_sizepath[1024];
+static char *wrbuf;
+static int dev_num, dev_fd, file_fd, attach_flag;
+
+static void verify_ioctl_loop(void)
+{
+ struct loop_info loopinfoget;
+
+ memset(&loopinfoget, 0, sizeof(loopinfoget));
+ tst_fill_file("test.img", 0, 1024, OLD_SIZE/1024);
+ tst_attach_device(dev_path, "test.img");
+ attach_flag = 1;
+
+ TST_ASSERT_INT(sys_loop_sizepath, OLD_SIZE/512);
+ file_fd = SAFE_OPEN("test.img", O_RDWR);
+ SAFE_IOCTL(dev_fd, LOOP_GET_STATUS, &loopinfoget);
+
+ if (loopinfoget.lo_flags & LO_FLAGS_READ_ONLY)
+ tst_brk(TCONF, "Current environment has unexpected LO_FLAGS_READ_ONLY flag");
+
+ SAFE_TRUNCATE("test.img", NEW_SIZE);
+ SAFE_IOCTL(dev_fd, LOOP_SET_CAPACITY);
+
+ SAFE_LSEEK(dev_fd, 0, SEEK_SET);
+
+ /*check that we can't write data beyond 5K into loop device*/
+ TEST(write(dev_fd, wrbuf, OLD_SIZE));
+ if (TST_RET == NEW_SIZE) {
+ tst_res(TPASS, "LOOP_SET_CAPACITY set loop size to %d", NEW_SIZE);
+ } else {
+ tst_res(TFAIL, "LOOP_SET_CAPACITY didn't set loop size to %d, its size is %ld",
+ NEW_SIZE, TST_RET);
+ }
+
+ TST_ASSERT_INT(sys_loop_sizepath, NEW_SIZE/512);
+
+ SAFE_CLOSE(file_fd);
+ tst_detach_device_by_fd(dev_path, dev_fd);
+ unlink("test.img");
+ attach_flag = 0;
+}
+
+static void setup(void)
+{
+ dev_num = tst_find_free_loopdev(dev_path, sizeof(dev_path));
+ if (dev_num < 0)
+ tst_brk(TBROK, "Failed to find free loop device");
+
+ wrbuf = SAFE_MALLOC(OLD_SIZE);
+ memset(wrbuf, 'x', OLD_SIZE);
+ sprintf(sys_loop_sizepath, "/sys/block/loop%d/size", dev_num);
+ dev_fd = SAFE_OPEN(dev_path, O_RDWR);
+}
+
+static void cleanup(void)
+{
+ if (dev_fd > 0)
+ SAFE_CLOSE(dev_fd);
+ if (file_fd > 0)
+ SAFE_CLOSE(file_fd);
+ if (wrbuf)
+ free(wrbuf);
+ if (attach_flag)
+ tst_detach_device(dev_path);
+}
+
+static struct tst_test test = {
+ .setup = setup,
+ .cleanup = cleanup,
+ .test_all = verify_ioctl_loop,
+ .needs_root = 1,
+ .needs_tmpdir = 1,
+ .needs_drivers = (const char *const []) {
+ "loop",
+ NULL
+ }
+};
diff --git a/kernel/tests/testcases/kernel/syscalls/ioctl/ioctl_loop05.c b/kernel/tests/testcases/kernel/syscalls/ioctl/ioctl_loop05.c
new file mode 100644
index 0000000..e3c14fa
--- /dev/null
+++ b/kernel/tests/testcases/kernel/syscalls/ioctl/ioctl_loop05.c
@@ -0,0 +1,155 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@cn.jujitsu.com>
+ *
+ * This is a basic ioctl test about loopdevice.
+ *
+ * It is designed to test LOOP_SET_DIRECT_IO can update a live
+ * loop device dio mode. It needs the backing file also supports
+ * dio mode and the lo_offset is aligned with the logical block size.
+ *
+ * The direct I/O error handling is a bit messy on Linux, some filesystems
+ * return error when it coudln't be enabled, some silently fall back to regular
+ * buffered I/O.
+ *
+ * The LOOP_SET_DIRECT_IO ioctl() may ignore all checks if it cannot get the
+ * logical block size which is the case if the block device pointer in the
+ * backing file inode is not set. In this case the direct I/O appears to be
+ * enabled but falls back to buffered I/O later on. This is the case at least
+ * for Btrfs. Because of that the test passes both with failure as well as
+ * success with non-zero offset.
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/mount.h>
+#include "lapi/loop.h"
+#include "tst_test.h"
+
+#define DIO_MESSAGE "In dio mode"
+#define NON_DIO_MESSAGE "In non dio mode"
+
+static char dev_path[1024], sys_loop_diopath[1024], backing_file_path[1024];;
+static int dev_num, dev_fd, block_devfd, attach_flag, logical_block_size;
+
+static void check_dio_value(int flag)
+{
+ struct loop_info loopinfoget;
+
+ memset(&loopinfoget, 0, sizeof(loopinfoget));
+
+ SAFE_IOCTL(dev_fd, LOOP_GET_STATUS, &loopinfoget);
+ tst_res(TINFO, "%s", flag ? DIO_MESSAGE : NON_DIO_MESSAGE);
+
+ if (loopinfoget.lo_flags & LO_FLAGS_DIRECT_IO)
+ tst_res(flag ? TPASS : TFAIL, "lo_flags has LO_FLAGS_DIRECT_IO flag");
+ else
+ tst_res(flag ? TFAIL : TPASS, "lo_flags doesn't have LO_FLAGS_DIRECT_IO flag");
+
+ TST_ASSERT_INT(sys_loop_diopath, flag);
+}
+
+static void verify_ioctl_loop(void)
+{
+ struct loop_info loopinfo;
+
+ memset(&loopinfo, 0, sizeof(loopinfo));
+ TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_STATUS, &loopinfo), TST_RETVAL_EQ0);
+
+ tst_res(TINFO, "Without setting lo_offset or sizelimit");
+ SAFE_IOCTL(dev_fd, LOOP_SET_DIRECT_IO, 1);
+ check_dio_value(1);
+
+ SAFE_IOCTL(dev_fd, LOOP_SET_DIRECT_IO, 0);
+ check_dio_value(0);
+
+ tst_res(TINFO, "With offset equal to logical_block_size");
+ loopinfo.lo_offset = logical_block_size;
+ TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_STATUS, &loopinfo), TST_RETVAL_EQ0);
+ TEST(ioctl(dev_fd, LOOP_SET_DIRECT_IO, 1));
+ if (TST_RET == 0) {
+ tst_res(TPASS, "LOOP_SET_DIRECT_IO succeeded");
+ check_dio_value(1);
+ SAFE_IOCTL(dev_fd, LOOP_SET_DIRECT_IO, 0);
+ } else {
+ tst_res(TFAIL | TTERRNO, "LOOP_SET_DIRECT_IO failed");
+ }
+
+ tst_res(TINFO, "With nonzero offset less than logical_block_size");
+ loopinfo.lo_offset = logical_block_size / 2;
+ TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_STATUS, &loopinfo), TST_RETVAL_EQ0);
+
+ TEST(ioctl(dev_fd, LOOP_SET_DIRECT_IO, 1));
+ if (TST_RET == 0) {
+ tst_res(TPASS, "LOOP_SET_DIRECT_IO succeeded, offset is ignored");
+ SAFE_IOCTL(dev_fd, LOOP_SET_DIRECT_IO, 0);
+ return;
+ }
+ if (TST_ERR == EINVAL)
+ tst_res(TPASS | TTERRNO, "LOOP_SET_DIRECT_IO failed as expected");
+ else
+ tst_res(TFAIL | TTERRNO, "LOOP_SET_DIRECT_IO failed expected EINVAL got");
+}
+
+static void setup(void)
+{
+ char bd_path[100];
+
+ if (tst_fs_type(".") == TST_TMPFS_MAGIC)
+ tst_brk(TCONF, "tmpfd doesn't support O_DIRECT flag");
+
+ dev_num = tst_find_free_loopdev(dev_path, sizeof(dev_path));
+ if (dev_num < 0)
+ tst_brk(TBROK, "Failed to find free loop device");
+
+ sprintf(sys_loop_diopath, "/sys/block/loop%d/loop/dio", dev_num);
+ tst_fill_file("test.img", 0, 1024, 1024);
+
+ tst_attach_device(dev_path, "test.img");
+ attach_flag = 1;
+ dev_fd = SAFE_OPEN(dev_path, O_RDWR);
+
+ if (ioctl(dev_fd, LOOP_SET_DIRECT_IO, 0) && errno == EINVAL)
+ tst_brk(TCONF, "LOOP_SET_DIRECT_IO is not supported");
+
+ /*
+ * from __loop_update_dio():
+ * We support direct I/O only if lo_offset is aligned with the
+ * logical I/O size of backing device, and the logical block
+ * size of loop is bigger than the backing device's and the loop
+ * needn't transform transfer.
+ */
+ sprintf(backing_file_path, "%s/test.img", tst_get_tmpdir());
+ tst_find_backing_dev(backing_file_path, bd_path);
+ block_devfd = SAFE_OPEN(bd_path, O_RDWR);
+ SAFE_IOCTL(block_devfd, BLKSSZGET, &logical_block_size);
+ tst_res(TINFO, "backing dev(%s) logical_block_size is %d", bd_path, logical_block_size);
+ SAFE_CLOSE(block_devfd);
+ if (logical_block_size > 512)
+ TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_BLOCK_SIZE, logical_block_size), TST_RETVAL_EQ0);
+}
+
+static void cleanup(void)
+{
+ if (dev_fd > 0)
+ SAFE_CLOSE(dev_fd);
+ if (block_devfd > 0)
+ SAFE_CLOSE(block_devfd);
+ if (attach_flag)
+ tst_detach_device(dev_path);
+}
+
+static struct tst_test test = {
+ .setup = setup,
+ .cleanup = cleanup,
+ .test_all = verify_ioctl_loop,
+ .needs_root = 1,
+ .needs_tmpdir = 1,
+ .needs_drivers = (const char *const []) {
+ "loop",
+ NULL
+ }
+};
diff --git a/kernel/tests/testcases/kernel/syscalls/ioctl/ioctl_loop06.c b/kernel/tests/testcases/kernel/syscalls/ioctl/ioctl_loop06.c
new file mode 100644
index 0000000..bd0d289
--- /dev/null
+++ b/kernel/tests/testcases/kernel/syscalls/ioctl/ioctl_loop06.c
@@ -0,0 +1,143 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@cn.jujitsu.com>
+ *
+ * This is a basic error test about the invalid block size of loopdevice
+ * by using LOOP_SET_BLOCK_SIZE or LOOP_CONFIGURE ioctl.
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <stdlib.h>
+#include "lapi/loop.h"
+#include "tst_test.h"
+
+static char dev_path[1024];
+static int dev_num, dev_fd, file_fd, attach_flag, loop_configure_sup = 1;
+static unsigned int invalid_value, half_value, unalign_value;
+static struct loop_config loopconfig;
+
+static struct tcase {
+ unsigned int *setvalue;
+ int ioctl_flag;
+ char *message;
+} tcases[] = {
+ {&half_value, LOOP_SET_BLOCK_SIZE,
+ "Using LOOP_SET_BLOCK_SIZE with arg < 512"},
+
+ {&invalid_value, LOOP_SET_BLOCK_SIZE,
+ "Using LOOP_SET_BLOCK_SIZE with arg > PAGE_SIZE"},
+
+ {&unalign_value, LOOP_SET_BLOCK_SIZE,
+ "Using LOOP_SET_BLOCK_SIZE with arg != power_of_2"},
+
+ {&half_value, LOOP_CONFIGURE,
+ "Using LOOP_CONFIGURE with block_size < 512"},
+
+ {&invalid_value, LOOP_CONFIGURE,
+ "Using LOOP_CONFIGURE with block_size > PAGE_SIZE"},
+
+ {&unalign_value, LOOP_CONFIGURE,
+ "Using LOOP_CONFIGURE with block_size != power_of_2"},
+};
+
+static void verify_ioctl_loop(unsigned int n)
+{
+ if (tcases[n].ioctl_flag == LOOP_CONFIGURE)
+ TEST(ioctl(dev_fd, LOOP_CONFIGURE, &loopconfig));
+ else
+ TEST(ioctl(dev_fd, LOOP_SET_BLOCK_SIZE, *(tcases[n].setvalue)));
+
+ if (TST_RET == 0) {
+ tst_res(TFAIL, "Set block size succeed unexpectedly");
+ if (tcases[n].ioctl_flag == LOOP_CONFIGURE)
+ tst_detach_device_by_fd(dev_path, dev_fd);
+ return;
+ }
+ if (TST_ERR == EINVAL)
+ tst_res(TPASS | TTERRNO, "Set block size failed as expected");
+ else
+ tst_res(TFAIL | TTERRNO, "Set block size failed expected EINVAL got");
+}
+
+static void run(unsigned int n)
+{
+ struct tcase *tc = &tcases[n];
+
+ tst_res(TINFO, "%s", tc->message);
+ if (tc->ioctl_flag == LOOP_SET_BLOCK_SIZE) {
+ if (!attach_flag) {
+ tst_attach_device(dev_path, "test.img");
+ attach_flag = 1;
+ }
+ verify_ioctl_loop(n);
+ return;
+ }
+
+ if (tc->ioctl_flag == LOOP_CONFIGURE && !loop_configure_sup) {
+ tst_res(TCONF, "LOOP_CONFIGURE ioctl not supported");
+ return;
+ }
+ if (attach_flag) {
+ tst_detach_device_by_fd(dev_path, dev_fd);
+ attach_flag = 0;
+ }
+ loopconfig.block_size = *(tc->setvalue);
+ verify_ioctl_loop(n);
+}
+
+static void setup(void)
+{
+ unsigned int pg_size;
+ int ret;
+
+ dev_num = tst_find_free_loopdev(dev_path, sizeof(dev_path));
+ if (dev_num < 0)
+ tst_brk(TBROK, "Failed to find free loop device");
+
+ tst_fill_file("test.img", 0, 1024, 1024);
+ half_value = 256;
+ pg_size = getpagesize();
+ invalid_value = pg_size * 2 ;
+ unalign_value = pg_size - 1;
+
+ dev_fd = SAFE_OPEN(dev_path, O_RDWR);
+
+ if (ioctl(dev_fd, LOOP_SET_BLOCK_SIZE, 512) && errno == EINVAL)
+ tst_brk(TCONF, "LOOP_SET_BLOCK_SIZE is not supported");
+
+ file_fd = SAFE_OPEN("test.img", O_RDWR);
+ loopconfig.fd = -1;
+ ret = ioctl(dev_fd, LOOP_CONFIGURE, &loopconfig);
+ if (ret && errno != EBADF) {
+ tst_res(TINFO | TERRNO, "LOOP_CONFIGURE is not supported");
+ loop_configure_sup = 0;
+ return;
+ }
+ loopconfig.fd = file_fd;
+}
+
+static void cleanup(void)
+{
+ if (dev_fd > 0)
+ SAFE_CLOSE(dev_fd);
+ if (file_fd > 0)
+ SAFE_CLOSE(file_fd);
+ if (attach_flag)
+ tst_detach_device(dev_path);
+}
+
+static struct tst_test test = {
+ .setup = setup,
+ .cleanup = cleanup,
+ .test = run,
+ .tcnt = ARRAY_SIZE(tcases),
+ .needs_root = 1,
+ .needs_tmpdir = 1,
+ .needs_drivers = (const char *const []) {
+ "loop",
+ NULL
+ }
+};
diff --git a/kernel/tests/testcases/kernel/syscalls/ioctl/ioctl_loop07.c b/kernel/tests/testcases/kernel/syscalls/ioctl/ioctl_loop07.c
new file mode 100644
index 0000000..ce4b476
--- /dev/null
+++ b/kernel/tests/testcases/kernel/syscalls/ioctl/ioctl_loop07.c
@@ -0,0 +1,95 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@cn.jujitsu.com>
+ *
+ * This is a basic ioctl test about loopdevice LOOP_SET_STATUS64
+ * and LOOP_GET_STATUS64.
+ * Test its lo_sizelimit field. If lo_sizelimit is 0,it means max
+ * available. If sizelimit is less than loop_size, loopsize will
+ * be truncated.
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <stdlib.h>
+#include "lapi/loop.h"
+#include "tst_test.h"
+
+static char dev_path[1024], sys_loop_sizepath[1024], sys_loop_sizelimitpath[1024];
+static int dev_num, dev_fd, file_fd, attach_flag;
+
+static struct tcase {
+ unsigned int set_sizelimit;
+ unsigned int exp_loopsize;
+ char *message;
+} tcases[] = {
+ {1024 * 4096, 2048, "When sizelimit is greater than loopsize "},
+ {1024 * 512, 1024, "When sizelimit is less than loopsize"},
+};
+
+static void verify_ioctl_loop(unsigned int n)
+{
+ struct tcase *tc = &tcases[n];
+ struct loop_info64 loopinfo, loopinfoget;
+
+ tst_res(TINFO, "%s", tc->message);
+ memset(&loopinfo, 0, sizeof(loopinfo));
+ memset(&loopinfoget, 0, sizeof(loopinfoget));
+
+ loopinfo.lo_sizelimit = tc->set_sizelimit;
+ TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_STATUS64, &loopinfo), TST_RETVAL_EQ0);
+
+ TST_ASSERT_INT(sys_loop_sizepath, tc->exp_loopsize);
+ TST_ASSERT_INT(sys_loop_sizelimitpath, tc->set_sizelimit);
+ SAFE_IOCTL(dev_fd, LOOP_GET_STATUS64, &loopinfoget);
+ if (loopinfoget.lo_sizelimit == tc->set_sizelimit)
+ tst_res(TPASS, "LOOP_GET_STATUS64 gets correct lo_sizelimit(%d)", tc->set_sizelimit);
+ else
+ tst_res(TFAIL, "LOOP_GET_STATUS64 gets wrong lo_sizelimit(%llu), expect %d",
+ loopinfoget.lo_sizelimit, tc->set_sizelimit);
+ /*Reset*/
+ loopinfo.lo_sizelimit = 0;
+ TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_STATUS, &loopinfo), TST_RETVAL_EQ0);
+}
+
+static void setup(void)
+{
+ dev_num = tst_find_free_loopdev(dev_path, sizeof(dev_path));
+ if (dev_num < 0)
+ tst_brk(TBROK, "Failed to find free loop device");
+
+ tst_fill_file("test.img", 0, 1024 * 1024, 1);
+ tst_attach_device(dev_path, "test.img");
+ attach_flag = 1;
+
+ sprintf(sys_loop_sizepath, "/sys/block/loop%d/size", dev_num);
+ sprintf(sys_loop_sizelimitpath, "/sys/block/loop%d/loop/sizelimit", dev_num);
+
+ dev_fd = SAFE_OPEN(dev_path, O_RDWR);
+ tst_res(TINFO, "original loop size 2048 sectors");
+}
+
+static void cleanup(void)
+{
+ if (dev_fd > 0)
+ SAFE_CLOSE(dev_fd);
+ if (file_fd > 0)
+ SAFE_CLOSE(file_fd);
+ if (attach_flag)
+ tst_detach_device(dev_path);
+}
+
+static struct tst_test test = {
+ .setup = setup,
+ .cleanup = cleanup,
+ .test = verify_ioctl_loop,
+ .tcnt = ARRAY_SIZE(tcases),
+ .needs_root = 1,
+ .needs_tmpdir = 1,
+ .needs_drivers = (const char *const []) {
+ "loop",
+ NULL
+ }
+};
diff --git a/utils/lib/CMakeLists.txt b/utils/lib/CMakeLists.txt
index b84dc3f..e5fa459 100644
--- a/utils/lib/CMakeLists.txt
+++ b/utils/lib/CMakeLists.txt
@@ -42,4 +42,3 @@ add_library(libcommon STATIC ${CMAKE_CURRENT_SOURCE_DIR}/blkdev.c
${CMAKE_CURRENT_SOURCE_DIR}/timer.c
${CMAKE_CURRENT_SOURCE_DIR}/timeutils.c
${CMAKE_CURRENT_SOURCE_DIR}/ttyutils.c)
-target_include_directories(libcommon PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)