From b1b2138753be4a0c9dc50975b080f8e7743b78a9 Mon Sep 17 00:00:00 2001 From: Peter Maydell Date: Fri, 14 Jan 2022 15:37:30 +0000 Subject: [PATCH 1/8] linux-user: Remove unnecessary 'aligned' attribute from TaskState The linux-user struct TaskState has an 'aligned(16)' attribute. When the struct was first added in commit 851e67a1b46f in 2003, there was a justification in a comment (still present in the source today): /* NOTE: we force a big alignment so that the stack stored after is aligned too */ because the final field in the struct was "uint8_t stack[0];" But that field was removed in commit 48e15fc2d in 2010 which switched us to allocating the stack and the TaskState separately. Because we allocate the structure with g_new0() rather than as a local variable, the attribute made no difference to the alignment of the structure anyway. Remove the unnecessary attribute, and the corresponding comment. Signed-off-by: Peter Maydell Message-Id: <20220114153732.3767229-2-peter.maydell@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/qemu.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 7910ce59cc..9d2b3119d1 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -94,10 +94,6 @@ struct emulated_sigtable { target_siginfo_t info; }; -/* - * NOTE: we force a big alignment so that the stack stored after is - * aligned too - */ typedef struct TaskState { pid_t ts_tid; /* tid (or pid) of this task */ #ifdef TARGET_ARM @@ -158,7 +154,7 @@ typedef struct TaskState { /* This thread's sigaltstack, if it has one */ struct target_sigaltstack sigaltstack_used; -} __attribute__((aligned(16))) TaskState; +} TaskState; abi_long do_brk(abi_ulong new_brk); From ca9946d734147155d6c27b348920125f623a588f Mon Sep 17 00:00:00 2001 From: Serge Belyshev Date: Sat, 15 Jan 2022 14:32:35 +0300 Subject: [PATCH 2/8] linux-user/alpha: Fix target rlimits for alpha and rearrange for clarity Alpha uses different values of some TARGET_RLIMIT_* constants, which were missing and caused bugs like #577, fixed thus. Also rearranged all three (alpha, mips and sparc) that differ from everyone else for clarity. Signed-off-by: Serge Belyshev Resolves: https://gitlab.com/qemu-project/qemu/-/issues/577 Reviewed-by: Laurent Vivier Message-Id: <87y236lpwb.fsf@depni.sinp.msu.ru> [lv: replace tabs by spaces] Signed-off-by: Laurent Vivier --- linux-user/syscall_defs.h | 67 +++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index f23f0a2178..c8690688b5 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -730,44 +730,41 @@ struct target_rlimit { #define TARGET_RLIM_INFINITY ((abi_ulong)-1) #endif +#define TARGET_RLIMIT_CPU 0 +#define TARGET_RLIMIT_FSIZE 1 +#define TARGET_RLIMIT_DATA 2 +#define TARGET_RLIMIT_STACK 3 +#define TARGET_RLIMIT_CORE 4 #if defined(TARGET_MIPS) -#define TARGET_RLIMIT_CPU 0 -#define TARGET_RLIMIT_FSIZE 1 -#define TARGET_RLIMIT_DATA 2 -#define TARGET_RLIMIT_STACK 3 -#define TARGET_RLIMIT_CORE 4 -#define TARGET_RLIMIT_RSS 7 -#define TARGET_RLIMIT_NPROC 8 -#define TARGET_RLIMIT_NOFILE 5 -#define TARGET_RLIMIT_MEMLOCK 9 -#define TARGET_RLIMIT_AS 6 -#define TARGET_RLIMIT_LOCKS 10 -#define TARGET_RLIMIT_SIGPENDING 11 -#define TARGET_RLIMIT_MSGQUEUE 12 -#define TARGET_RLIMIT_NICE 13 -#define TARGET_RLIMIT_RTPRIO 14 +#define TARGET_RLIMIT_NOFILE 5 +#define TARGET_RLIMIT_AS 6 +#define TARGET_RLIMIT_RSS 7 +#define TARGET_RLIMIT_NPROC 8 +#define TARGET_RLIMIT_MEMLOCK 9 +#elif defined(TARGET_ALPHA) +#define TARGET_RLIMIT_RSS 5 +#define TARGET_RLIMIT_NOFILE 6 +#define TARGET_RLIMIT_AS 7 +#define TARGET_RLIMIT_NPROC 8 +#define TARGET_RLIMIT_MEMLOCK 9 +#elif defined(TARGET_SPARC) +#define TARGET_RLIMIT_RSS 5 +#define TARGET_RLIMIT_NOFILE 6 +#define TARGET_RLIMIT_NPROC 7 +#define TARGET_RLIMIT_MEMLOCK 8 +#define TARGET_RLIMIT_AS 9 #else -#define TARGET_RLIMIT_CPU 0 -#define TARGET_RLIMIT_FSIZE 1 -#define TARGET_RLIMIT_DATA 2 -#define TARGET_RLIMIT_STACK 3 -#define TARGET_RLIMIT_CORE 4 -#define TARGET_RLIMIT_RSS 5 -#if defined(TARGET_SPARC) -#define TARGET_RLIMIT_NOFILE 6 -#define TARGET_RLIMIT_NPROC 7 -#else -#define TARGET_RLIMIT_NPROC 6 -#define TARGET_RLIMIT_NOFILE 7 -#endif -#define TARGET_RLIMIT_MEMLOCK 8 -#define TARGET_RLIMIT_AS 9 -#define TARGET_RLIMIT_LOCKS 10 -#define TARGET_RLIMIT_SIGPENDING 11 -#define TARGET_RLIMIT_MSGQUEUE 12 -#define TARGET_RLIMIT_NICE 13 -#define TARGET_RLIMIT_RTPRIO 14 +#define TARGET_RLIMIT_RSS 5 +#define TARGET_RLIMIT_NPROC 6 +#define TARGET_RLIMIT_NOFILE 7 +#define TARGET_RLIMIT_MEMLOCK 8 +#define TARGET_RLIMIT_AS 9 #endif +#define TARGET_RLIMIT_LOCKS 10 +#define TARGET_RLIMIT_SIGPENDING 11 +#define TARGET_RLIMIT_MSGQUEUE 12 +#define TARGET_RLIMIT_NICE 13 +#define TARGET_RLIMIT_RTPRIO 14 struct target_pollfd { int fd; /* file descriptor */ From 33f53ac52ab664f3d6ec34047c0ae21e32fa26b4 Mon Sep 17 00:00:00 2001 From: Paul Brook Date: Wed, 26 Jan 2022 20:26:36 +0000 Subject: [PATCH 3/8] linux-user: Fix inotify on aarch64 The inotify implementation originally called the raw host syscalls. Commit 3b3f24add0 changed this to use the glibc wrappers. However ifdefs in syscall.c still test for presence of the raw syscalls. This causes a problem on e.g. aarch64 hosts which never had the inotify_init syscall - it had been obsoleted by inotify_init1 before aarch64 was invented! However it does have a perfectly good glibc implementation of inotify_wait. Fix this by removing all the raw __NR_inotify_* tests, and instead check CONFIG_INOTIFY, which already tests for the glibc functionality we use. Also remove the now-pointless sys_inotify* wrappers. Tested using x86-64 inotifywatch on aarch64 host, and vice-versa Signed-off-by: Paul Brook Reviewed-by: Laurent Vivier Message-Id: <20220126202636.655289-1-paul@nowt.org> Signed-off-by: Laurent Vivier --- linux-user/fd-trans.c | 5 ++--- linux-user/syscall.c | 50 +++++++++---------------------------------- 2 files changed, 12 insertions(+), 43 deletions(-) diff --git a/linux-user/fd-trans.c b/linux-user/fd-trans.c index a17d05c079..7b25468d02 100644 --- a/linux-user/fd-trans.c +++ b/linux-user/fd-trans.c @@ -1644,9 +1644,8 @@ TargetFdTrans target_eventfd_trans = { .target_to_host_data = swap_data_eventfd, }; -#if (defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)) || \ - (defined(CONFIG_INOTIFY1) && defined(TARGET_NR_inotify_init1) && \ - defined(__NR_inotify_init1)) +#if defined(CONFIG_INOTIFY) && (defined(TARGET_NR_inotify_init) || \ + defined(TARGET_NR_inotify_init1)) static abi_long host_to_target_data_inotify(void *buf, size_t len) { struct inotify_event *ev; diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 5950222a77..2ca0f086db 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -272,9 +272,6 @@ static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, \ #if defined(__NR_futex_time64) # define __NR_sys_futex_time64 __NR_futex_time64 #endif -#define __NR_sys_inotify_init __NR_inotify_init -#define __NR_sys_inotify_add_watch __NR_inotify_add_watch -#define __NR_sys_inotify_rm_watch __NR_inotify_rm_watch #define __NR_sys_statx __NR_statx #if defined(__alpha__) || defined(__x86_64__) || defined(__s390x__) @@ -477,33 +474,6 @@ static int sys_renameat2(int oldfd, const char *old, #ifdef CONFIG_INOTIFY #include - -#if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init) -static int sys_inotify_init(void) -{ - return (inotify_init()); -} -#endif -#if defined(TARGET_NR_inotify_add_watch) && defined(__NR_inotify_add_watch) -static int sys_inotify_add_watch(int fd,const char *pathname, int32_t mask) -{ - return (inotify_add_watch(fd, pathname, mask)); -} -#endif -#if defined(TARGET_NR_inotify_rm_watch) && defined(__NR_inotify_rm_watch) -static int sys_inotify_rm_watch(int fd, int32_t wd) -{ - return (inotify_rm_watch(fd, wd)); -} -#endif -#ifdef CONFIG_INOTIFY1 -#if defined(TARGET_NR_inotify_init1) && defined(__NR_inotify_init1) -static int sys_inotify_init1(int flags) -{ - return (inotify_init1(flags)); -} -#endif -#endif #else /* Userspace can usually survive runtime without inotify */ #undef TARGET_NR_inotify_init @@ -12341,35 +12311,35 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, case TARGET_NR_futex_time64: return do_futex_time64(cpu, arg1, arg2, arg3, arg4, arg5, arg6); #endif -#if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init) +#ifdef CONFIG_INOTIFY +#if defined(TARGET_NR_inotify_init) case TARGET_NR_inotify_init: - ret = get_errno(sys_inotify_init()); + ret = get_errno(inotify_init()); if (ret >= 0) { fd_trans_register(ret, &target_inotify_trans); } return ret; #endif -#ifdef CONFIG_INOTIFY1 -#if defined(TARGET_NR_inotify_init1) && defined(__NR_inotify_init1) +#if defined(TARGET_NR_inotify_init1) && defined(CONFIG_INOTIFY1) case TARGET_NR_inotify_init1: - ret = get_errno(sys_inotify_init1(target_to_host_bitmask(arg1, + ret = get_errno(inotify_init1(target_to_host_bitmask(arg1, fcntl_flags_tbl))); if (ret >= 0) { fd_trans_register(ret, &target_inotify_trans); } return ret; #endif -#endif -#if defined(TARGET_NR_inotify_add_watch) && defined(__NR_inotify_add_watch) +#if defined(TARGET_NR_inotify_add_watch) case TARGET_NR_inotify_add_watch: p = lock_user_string(arg2); - ret = get_errno(sys_inotify_add_watch(arg1, path(p), arg3)); + ret = get_errno(inotify_add_watch(arg1, path(p), arg3)); unlock_user(p, arg2, 0); return ret; #endif -#if defined(TARGET_NR_inotify_rm_watch) && defined(__NR_inotify_rm_watch) +#if defined(TARGET_NR_inotify_rm_watch) case TARGET_NR_inotify_rm_watch: - return get_errno(sys_inotify_rm_watch(arg1, arg2)); + return get_errno(inotify_rm_watch(arg1, arg2)); +#endif #endif #if defined(TARGET_NR_mq_open) && defined(__NR_mq_open) From d3ced2a59a543b3c3fc7dee2e64ee360e9a698cd Mon Sep 17 00:00:00 2001 From: Shu-Chun Weng Date: Wed, 26 Jan 2022 13:25:58 -0800 Subject: [PATCH 4/8] linux-user: rt_sigprocmask, check read perms first Linux kernel does it this way (checks read permission before validating `how`) and the latest version of ABSL's `AddressIsReadable()` depends on this behavior. c.f. https://github.com/torvalds/linux/blob/9539ba4308ad5bdca6cb41c7b73cbb9f796dcdd7/kernel/signal.c#L3147 Reviewed-by: Patrick Venture Signed-off-by: Shu-Chun Weng Reviewed-by: Laurent Vivier Signed-off-by: Patrick Venture Message-Id: <20220126212559.1936290-2-venture@google.com> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 2ca0f086db..9f8b497fa3 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -9478,6 +9478,13 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, } if (arg2) { + p = lock_user(VERIFY_READ, arg2, sizeof(target_sigset_t), 1); + if (!p) { + return -TARGET_EFAULT; + } + target_to_host_sigset(&set, p); + unlock_user(p, arg2, 0); + set_ptr = &set; switch(how) { case TARGET_SIG_BLOCK: how = SIG_BLOCK; @@ -9491,11 +9498,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, default: return -TARGET_EINVAL; } - if (!(p = lock_user(VERIFY_READ, arg2, sizeof(target_sigset_t), 1))) - return -TARGET_EFAULT; - target_to_host_sigset(&set, p); - unlock_user(p, arg2, 0); - set_ptr = &set; } else { how = 0; set_ptr = NULL; From ebce1719ac0a2a71b64742ecf1c9ec2497a65a55 Mon Sep 17 00:00:00 2001 From: Patrick Venture Date: Wed, 26 Jan 2022 13:25:59 -0800 Subject: [PATCH 5/8] linux-user: sigprocmask check read perms first Linux kernel now checks the read permissions before validating `how` Suggested-by: Laurent Vivier Signed-off-by: Patrick Venture Reviewed-by: Laurent Vivier Message-Id: <20220126212559.1936290-3-venture@google.com> [lv: remove unneeded ")"] Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 9f8b497fa3..84cfa223df 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -9435,6 +9435,13 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, int how; if (arg2) { + p = lock_user(VERIFY_READ, arg2, sizeof(target_sigset_t), 1); + if (!p) { + return -TARGET_EFAULT; + } + target_to_host_old_sigset(&set, p); + unlock_user(p, arg2, 0); + set_ptr = &set; switch (arg1) { case TARGET_SIG_BLOCK: how = SIG_BLOCK; @@ -9448,11 +9455,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, default: return -TARGET_EINVAL; } - if (!(p = lock_user(VERIFY_READ, arg2, sizeof(target_sigset_t), 1))) - return -TARGET_EFAULT; - target_to_host_old_sigset(&set, p); - unlock_user(p, arg2, 0); - set_ptr = &set; } else { how = 0; set_ptr = NULL; From eb33cdaeda55d951f915152ad23816d47aca9955 Mon Sep 17 00:00:00 2001 From: Cameron Esfahani Date: Thu, 27 Jan 2022 16:12:51 -0800 Subject: [PATCH 6/8] linux-user: Implement starttime field in self stat emulation Instead of always returning 0, return actual starttime. Signed-off-by: Cameron Esfahani Reviewed-by: Laurent Vivier Message-Id: <20220128001251.45165-1-dirty@apple.com> Signed-off-by: Laurent Vivier --- linux-user/main.c | 14 ++++++++++++++ linux-user/qemu.h | 3 +++ linux-user/syscall.c | 3 +++ 3 files changed, 20 insertions(+) diff --git a/linux-user/main.c b/linux-user/main.c index 16def5215d..fbc9bcfd5f 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -190,12 +190,26 @@ void stop_all_tasks(void) /* Assumes contents are already zeroed. */ void init_task_state(TaskState *ts) { + long ticks_per_sec; + struct timespec bt; + ts->used = 1; ts->sigaltstack_used = (struct target_sigaltstack) { .ss_sp = 0, .ss_size = 0, .ss_flags = TARGET_SS_DISABLE, }; + + /* Capture task start time relative to system boot */ + + ticks_per_sec = sysconf(_SC_CLK_TCK); + + if ((ticks_per_sec > 0) && !clock_gettime(CLOCK_BOOTTIME, &bt)) { + /* start_boottime is expressed in clock ticks */ + ts->start_boottime = bt.tv_sec * (uint64_t) ticks_per_sec; + ts->start_boottime += bt.tv_nsec * (uint64_t) ticks_per_sec / + NANOSECONDS_PER_SECOND; + } } CPUArchState *cpu_copy(CPUArchState *env) diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 9d2b3119d1..98dfbf2096 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -154,6 +154,9 @@ typedef struct TaskState { /* This thread's sigaltstack, if it has one */ struct target_sigaltstack sigaltstack_used; + + /* Start time of task after system boot in clock ticks */ + uint64_t start_boottime; } TaskState; abi_long do_brk(abi_ulong new_brk); diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 84cfa223df..b3948d13a9 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8077,6 +8077,9 @@ static int open_self_stat(void *cpu_env, int fd) } else if (i == 3) { /* ppid */ g_string_printf(buf, FMT_pid " ", getppid()); + } else if (i == 21) { + /* starttime */ + g_string_printf(buf, "%" PRIu64 " ", ts->start_boottime); } else if (i == 27) { /* stack bottom */ g_string_printf(buf, TARGET_ABI_FMT_ld " ", ts->info->start_stack); From b13e49bc86961c6725b2ebddd53898fe1366f6dc Mon Sep 17 00:00:00 2001 From: Serge Belyshev Date: Sat, 29 Jan 2022 22:46:59 +0300 Subject: [PATCH 7/8] linux-user: Move generic TARGET_RLIMIT* definitions to generic/target_resource.h Signed-off-by: Serge Belyshev Message-Id: <87ee4ql3yk.fsf_-_@depni.sinp.msu.ru> Signed-off-by: Laurent Vivier --- linux-user/aarch64/target_resource.h | 1 + linux-user/alpha/target_resource.h | 21 ++++++++++ linux-user/arm/target_resource.h | 1 + linux-user/cris/target_resource.h | 1 + linux-user/generic/target_resource.h | 37 +++++++++++++++++ linux-user/hexagon/target_resource.h | 1 + linux-user/hppa/target_resource.h | 1 + linux-user/i386/target_resource.h | 1 + linux-user/m68k/target_resource.h | 1 + linux-user/microblaze/target_resource.h | 1 + linux-user/mips/target_resource.h | 24 +++++++++++ linux-user/mips64/target_resource.h | 1 + linux-user/nios2/target_resource.h | 1 + linux-user/openrisc/target_resource.h | 1 + linux-user/ppc/target_resource.h | 1 + linux-user/riscv/target_resource.h | 1 + linux-user/s390x/target_resource.h | 1 + linux-user/sh4/target_resource.h | 1 + linux-user/sparc/target_resource.h | 17 ++++++++ linux-user/syscall_defs.h | 53 +------------------------ linux-user/x86_64/target_resource.h | 1 + linux-user/xtensa/target_resource.h | 1 + 22 files changed, 117 insertions(+), 52 deletions(-) create mode 100644 linux-user/aarch64/target_resource.h create mode 100644 linux-user/alpha/target_resource.h create mode 100644 linux-user/arm/target_resource.h create mode 100644 linux-user/cris/target_resource.h create mode 100644 linux-user/generic/target_resource.h create mode 100644 linux-user/hexagon/target_resource.h create mode 100644 linux-user/hppa/target_resource.h create mode 100644 linux-user/i386/target_resource.h create mode 100644 linux-user/m68k/target_resource.h create mode 100644 linux-user/microblaze/target_resource.h create mode 100644 linux-user/mips/target_resource.h create mode 100644 linux-user/mips64/target_resource.h create mode 100644 linux-user/nios2/target_resource.h create mode 100644 linux-user/openrisc/target_resource.h create mode 100644 linux-user/ppc/target_resource.h create mode 100644 linux-user/riscv/target_resource.h create mode 100644 linux-user/s390x/target_resource.h create mode 100644 linux-user/sh4/target_resource.h create mode 100644 linux-user/sparc/target_resource.h create mode 100644 linux-user/x86_64/target_resource.h create mode 100644 linux-user/xtensa/target_resource.h diff --git a/linux-user/aarch64/target_resource.h b/linux-user/aarch64/target_resource.h new file mode 100644 index 0000000000..227259594c --- /dev/null +++ b/linux-user/aarch64/target_resource.h @@ -0,0 +1 @@ +#include "../generic/target_resource.h" diff --git a/linux-user/alpha/target_resource.h b/linux-user/alpha/target_resource.h new file mode 100644 index 0000000000..c9b082faee --- /dev/null +++ b/linux-user/alpha/target_resource.h @@ -0,0 +1,21 @@ +#ifndef ALPHA_TARGET_RESOURCE_H +#define ALPHA_TARGET_RESOURCE_H + +#include "../generic/target_resource.h" + +#undef TARGET_RLIM_INFINITY +#define TARGET_RLIM_INFINITY 0x7fffffffffffffffull + +#undef TARGET_RLIMIT_NOFILE +#define TARGET_RLIMIT_NOFILE 6 + +#undef TARGET_RLIMIT_AS +#define TARGET_RLIMIT_AS 7 + +#undef TARGET_RLIMIT_NPROC +#define TARGET_RLIMIT_NPROC 8 + +#undef TARGET_RLIMIT_MEMLOCK +#define TARGET_RLIMIT_MEMLOCK 9 + +#endif diff --git a/linux-user/arm/target_resource.h b/linux-user/arm/target_resource.h new file mode 100644 index 0000000000..227259594c --- /dev/null +++ b/linux-user/arm/target_resource.h @@ -0,0 +1 @@ +#include "../generic/target_resource.h" diff --git a/linux-user/cris/target_resource.h b/linux-user/cris/target_resource.h new file mode 100644 index 0000000000..227259594c --- /dev/null +++ b/linux-user/cris/target_resource.h @@ -0,0 +1 @@ +#include "../generic/target_resource.h" diff --git a/linux-user/generic/target_resource.h b/linux-user/generic/target_resource.h new file mode 100644 index 0000000000..f04c93b125 --- /dev/null +++ b/linux-user/generic/target_resource.h @@ -0,0 +1,37 @@ +/* + * Target definitions of RLIMIT_* constants. These may be overridden by an + * architecture specific header if needed. + */ + +#ifndef GENERIC_TARGET_RESOURCE_H +#define GENERIC_TARGET_RESOURCE_H + +struct target_rlimit { + abi_ulong rlim_cur; + abi_ulong rlim_max; +}; + +struct target_rlimit64 { + uint64_t rlim_cur; + uint64_t rlim_max; +}; + +#define TARGET_RLIM_INFINITY ((abi_ulong)-1) + +#define TARGET_RLIMIT_CPU 0 +#define TARGET_RLIMIT_FSIZE 1 +#define TARGET_RLIMIT_DATA 2 +#define TARGET_RLIMIT_STACK 3 +#define TARGET_RLIMIT_CORE 4 +#define TARGET_RLIMIT_RSS 5 +#define TARGET_RLIMIT_NPROC 6 +#define TARGET_RLIMIT_NOFILE 7 +#define TARGET_RLIMIT_MEMLOCK 8 +#define TARGET_RLIMIT_AS 9 +#define TARGET_RLIMIT_LOCKS 10 +#define TARGET_RLIMIT_SIGPENDING 11 +#define TARGET_RLIMIT_MSGQUEUE 12 +#define TARGET_RLIMIT_NICE 13 +#define TARGET_RLIMIT_RTPRIO 14 + +#endif diff --git a/linux-user/hexagon/target_resource.h b/linux-user/hexagon/target_resource.h new file mode 100644 index 0000000000..227259594c --- /dev/null +++ b/linux-user/hexagon/target_resource.h @@ -0,0 +1 @@ +#include "../generic/target_resource.h" diff --git a/linux-user/hppa/target_resource.h b/linux-user/hppa/target_resource.h new file mode 100644 index 0000000000..227259594c --- /dev/null +++ b/linux-user/hppa/target_resource.h @@ -0,0 +1 @@ +#include "../generic/target_resource.h" diff --git a/linux-user/i386/target_resource.h b/linux-user/i386/target_resource.h new file mode 100644 index 0000000000..227259594c --- /dev/null +++ b/linux-user/i386/target_resource.h @@ -0,0 +1 @@ +#include "../generic/target_resource.h" diff --git a/linux-user/m68k/target_resource.h b/linux-user/m68k/target_resource.h new file mode 100644 index 0000000000..227259594c --- /dev/null +++ b/linux-user/m68k/target_resource.h @@ -0,0 +1 @@ +#include "../generic/target_resource.h" diff --git a/linux-user/microblaze/target_resource.h b/linux-user/microblaze/target_resource.h new file mode 100644 index 0000000000..227259594c --- /dev/null +++ b/linux-user/microblaze/target_resource.h @@ -0,0 +1 @@ +#include "../generic/target_resource.h" diff --git a/linux-user/mips/target_resource.h b/linux-user/mips/target_resource.h new file mode 100644 index 0000000000..6d131b041d --- /dev/null +++ b/linux-user/mips/target_resource.h @@ -0,0 +1,24 @@ +#ifndef MIPS_TARGET_RESOURCE_H +#define MIPS_TARGET_RESOURCE_H + +#include "../generic/target_resource.h" + +#undef TARGET_RLIM_INFINITY +#define TARGET_RLIM_INFINITY 0x7fffffffUL + +#undef TARGET_RLIMIT_NOFILE +#define TARGET_RLIMIT_NOFILE 5 + +#undef TARGET_RLIMIT_AS +#define TARGET_RLIMIT_AS 6 + +#undef TARGET_RLIMIT_RSS +#define TARGET_RLIMIT_RSS 7 + +#undef TARGET_RLIMIT_NPROC +#define TARGET_RLIMIT_NPROC 8 + +#undef TARGET_RLIMIT_MEMLOCK +#define TARGET_RLIMIT_MEMLOCK 9 + +#endif diff --git a/linux-user/mips64/target_resource.h b/linux-user/mips64/target_resource.h new file mode 100644 index 0000000000..fe29002a12 --- /dev/null +++ b/linux-user/mips64/target_resource.h @@ -0,0 +1 @@ +#include "../mips/target_resource.h" diff --git a/linux-user/nios2/target_resource.h b/linux-user/nios2/target_resource.h new file mode 100644 index 0000000000..227259594c --- /dev/null +++ b/linux-user/nios2/target_resource.h @@ -0,0 +1 @@ +#include "../generic/target_resource.h" diff --git a/linux-user/openrisc/target_resource.h b/linux-user/openrisc/target_resource.h new file mode 100644 index 0000000000..227259594c --- /dev/null +++ b/linux-user/openrisc/target_resource.h @@ -0,0 +1 @@ +#include "../generic/target_resource.h" diff --git a/linux-user/ppc/target_resource.h b/linux-user/ppc/target_resource.h new file mode 100644 index 0000000000..227259594c --- /dev/null +++ b/linux-user/ppc/target_resource.h @@ -0,0 +1 @@ +#include "../generic/target_resource.h" diff --git a/linux-user/riscv/target_resource.h b/linux-user/riscv/target_resource.h new file mode 100644 index 0000000000..227259594c --- /dev/null +++ b/linux-user/riscv/target_resource.h @@ -0,0 +1 @@ +#include "../generic/target_resource.h" diff --git a/linux-user/s390x/target_resource.h b/linux-user/s390x/target_resource.h new file mode 100644 index 0000000000..227259594c --- /dev/null +++ b/linux-user/s390x/target_resource.h @@ -0,0 +1 @@ +#include "../generic/target_resource.h" diff --git a/linux-user/sh4/target_resource.h b/linux-user/sh4/target_resource.h new file mode 100644 index 0000000000..227259594c --- /dev/null +++ b/linux-user/sh4/target_resource.h @@ -0,0 +1 @@ +#include "../generic/target_resource.h" diff --git a/linux-user/sparc/target_resource.h b/linux-user/sparc/target_resource.h new file mode 100644 index 0000000000..d9a2fb814a --- /dev/null +++ b/linux-user/sparc/target_resource.h @@ -0,0 +1,17 @@ +#ifndef SPARC_TARGET_RESOURCE_H +#define SPARC_TARGET_RESOURCE_H + +#include "../generic/target_resource.h" + +#if TARGET_ABI_BITS == 32 +#undef TARGET_RLIM_INFINITY +#define TARGET_RLIM_INFINITY 0x7fffffffUL +#endif + +#undef TARGET_RLIMIT_NOFILE +#define TARGET_RLIMIT_NOFILE 6 + +#undef TARGET_RLIMIT_NPROC +#define TARGET_RLIMIT_NPROC 7 + +#endif diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index c8690688b5..78607effe8 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -717,54 +717,7 @@ typedef struct target_siginfo { #define TARGET_TRAP_HWBKPT (4) /* hardware breakpoint/watchpoint */ #define TARGET_TRAP_UNK (5) /* undiagnosed trap */ -struct target_rlimit { - abi_ulong rlim_cur; - abi_ulong rlim_max; -}; - -#if defined(TARGET_ALPHA) -#define TARGET_RLIM_INFINITY 0x7fffffffffffffffull -#elif defined(TARGET_MIPS) || (defined(TARGET_SPARC) && TARGET_ABI_BITS == 32) -#define TARGET_RLIM_INFINITY 0x7fffffffUL -#else -#define TARGET_RLIM_INFINITY ((abi_ulong)-1) -#endif - -#define TARGET_RLIMIT_CPU 0 -#define TARGET_RLIMIT_FSIZE 1 -#define TARGET_RLIMIT_DATA 2 -#define TARGET_RLIMIT_STACK 3 -#define TARGET_RLIMIT_CORE 4 -#if defined(TARGET_MIPS) -#define TARGET_RLIMIT_NOFILE 5 -#define TARGET_RLIMIT_AS 6 -#define TARGET_RLIMIT_RSS 7 -#define TARGET_RLIMIT_NPROC 8 -#define TARGET_RLIMIT_MEMLOCK 9 -#elif defined(TARGET_ALPHA) -#define TARGET_RLIMIT_RSS 5 -#define TARGET_RLIMIT_NOFILE 6 -#define TARGET_RLIMIT_AS 7 -#define TARGET_RLIMIT_NPROC 8 -#define TARGET_RLIMIT_MEMLOCK 9 -#elif defined(TARGET_SPARC) -#define TARGET_RLIMIT_RSS 5 -#define TARGET_RLIMIT_NOFILE 6 -#define TARGET_RLIMIT_NPROC 7 -#define TARGET_RLIMIT_MEMLOCK 8 -#define TARGET_RLIMIT_AS 9 -#else -#define TARGET_RLIMIT_RSS 5 -#define TARGET_RLIMIT_NPROC 6 -#define TARGET_RLIMIT_NOFILE 7 -#define TARGET_RLIMIT_MEMLOCK 8 -#define TARGET_RLIMIT_AS 9 -#endif -#define TARGET_RLIMIT_LOCKS 10 -#define TARGET_RLIMIT_SIGPENDING 11 -#define TARGET_RLIMIT_MSGQUEUE 12 -#define TARGET_RLIMIT_NICE 13 -#define TARGET_RLIMIT_RTPRIO 14 +#include "target_resource.h" struct target_pollfd { int fd; /* file descriptor */ @@ -2769,10 +2722,6 @@ struct target_epoll_event { #define TARGET_EP_MAX_EVENTS (INT_MAX / sizeof(struct target_epoll_event)) #endif -struct target_rlimit64 { - uint64_t rlim_cur; - uint64_t rlim_max; -}; struct target_ucred { uint32_t pid; diff --git a/linux-user/x86_64/target_resource.h b/linux-user/x86_64/target_resource.h new file mode 100644 index 0000000000..227259594c --- /dev/null +++ b/linux-user/x86_64/target_resource.h @@ -0,0 +1 @@ +#include "../generic/target_resource.h" diff --git a/linux-user/xtensa/target_resource.h b/linux-user/xtensa/target_resource.h new file mode 100644 index 0000000000..227259594c --- /dev/null +++ b/linux-user/xtensa/target_resource.h @@ -0,0 +1 @@ +#include "../generic/target_resource.h" From 244fd08323088db73590ff2317dfe86f810b51d7 Mon Sep 17 00:00:00 2001 From: Serge Belyshev Date: Sat, 29 Jan 2022 22:48:23 +0300 Subject: [PATCH 8/8] linux-user/syscall: Translate TARGET_RLIMIT_RTTIME Signed-off-by: Serge Belyshev Reviewed-by: Laurent Vivier Reviewed-by: Laurent Vivier Message-Id: <87a6fel3w8.fsf_-_@depni.sinp.msu.ru> Signed-off-by: Laurent Vivier --- linux-user/generic/target_resource.h | 1 + linux-user/syscall.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/linux-user/generic/target_resource.h b/linux-user/generic/target_resource.h index f04c93b125..539d8c4677 100644 --- a/linux-user/generic/target_resource.h +++ b/linux-user/generic/target_resource.h @@ -33,5 +33,6 @@ struct target_rlimit64 { #define TARGET_RLIMIT_MSGQUEUE 12 #define TARGET_RLIMIT_NICE 13 #define TARGET_RLIMIT_RTPRIO 14 +#define TARGET_RLIMIT_RTTIME 15 #endif diff --git a/linux-user/syscall.c b/linux-user/syscall.c index b3948d13a9..b9b18a7eaf 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -1053,6 +1053,8 @@ static inline int target_to_host_resource(int code) return RLIMIT_RSS; case TARGET_RLIMIT_RTPRIO: return RLIMIT_RTPRIO; + case TARGET_RLIMIT_RTTIME: + return RLIMIT_RTTIME; case TARGET_RLIMIT_SIGPENDING: return RLIMIT_SIGPENDING; case TARGET_RLIMIT_STACK: