Linux-user pull request 20220207

Fix target rlimits for alpha
 Add startime in /proc/self/stat
 -----BEGIN PGP SIGNATURE-----
 
 iQJGBAABCAAwFiEEzS913cjjpNwuT1Fz8ww4vT8vvjwFAmIA1+8SHGxhdXJlbnRA
 dml2aWVyLmV1AAoJEPMMOL0/L748WBgP/1eXts9XNdAbcrAcWbH2DTRxFPdv4HDm
 9FvU+kFjuRFkv72vaXgdkyrqO9O/Pl0eooo4uYlAeY1xSTUbX8EwqAbgLB0zVdb9
 D51gQTCok87Z/qrbf3QpZAca3hGzYwqYumvvKfNRaaH5iH2ElSe50+QNMnW6P2zG
 yRtjAl5Wi0GkJNipAgr+9JcrQPDLnVjSe0VMPS9Q4yUdnBJvW/KcBswcRdXxH9BK
 AG+aopElApZnnkZnwdhcRZSx+juUANB2vCGX4pUbixxcY+oFsXumup5T3GeaoKWs
 kpvS7tf1GKUdT08oCu0LlSoh6vLKUgkpBo93IsCvc2wF+f9roG0OAtrC7fSNJopa
 AJnHIvJAYj1zJRsDbGWCK629gRDjEE7Y0rykVkI1ZCp7OIHJngQT0MUrF6OYTXjX
 5G6B9iPw3oL2sfRG3eINw20fM1NdQHvGkQq/+UnvWdDfNy6FWFk8dDGyFamg9iBm
 tFtCTATbe2u75KJdv2qcQeo3Pd1YZySjuWzx2mgud552t8UyBcsQUewIAxL2Yw87
 oDI4yMPw5oJvVsSSxYAZKAwGK05ofCrGqbr0maXQ01L9LwCvgIs9wIECQjmKPfqD
 vdBRTq4muys65mv17/U2mGmDPpgf0xAgUFnWpXF/BygClVv0TsRVkZuF9+MoCU1r
 TreVmVoyGq3c
 =ClMx
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/lvivier-gitlab/tags/linux-user-for-7.0-pull-request' into staging

Linux-user pull request 20220207

Fix target rlimits for alpha
Add startime in /proc/self/stat

# gpg: Signature made Mon 07 Feb 2022 08:27:27 GMT
# gpg:                using RSA key CD2F75DDC8E3A4DC2E4F5173F30C38BD3F2FBE3C
# gpg:                issuer "laurent@vivier.eu"
# gpg: Good signature from "Laurent Vivier <lvivier@redhat.com>" [full]
# gpg:                 aka "Laurent Vivier <laurent@vivier.eu>" [full]
# gpg:                 aka "Laurent Vivier (Red Hat) <lvivier@redhat.com>" [full]
# Primary key fingerprint: CD2F 75DD C8E3 A4DC 2E4F  5173 F30C 38BD 3F2F BE3C

* remotes/lvivier-gitlab/tags/linux-user-for-7.0-pull-request:
  linux-user/syscall: Translate TARGET_RLIMIT_RTTIME
  linux-user: Move generic TARGET_RLIMIT* definitions to generic/target_resource.h
  linux-user: Implement starttime field in self stat emulation
  linux-user: sigprocmask check read perms first
  linux-user: rt_sigprocmask, check read perms first
  linux-user: Fix inotify on aarch64
  linux-user/alpha: Fix target rlimits for alpha and rearrange for clarity
  linux-user: Remove unnecessary 'aligned' attribute from TaskState

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell 2022-02-07 10:48:25 +00:00
commit 55ef0b702b
26 changed files with 167 additions and 113 deletions

View File

@ -0,0 +1 @@
#include "../generic/target_resource.h"

View File

@ -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

View File

@ -0,0 +1 @@
#include "../generic/target_resource.h"

View File

@ -0,0 +1 @@
#include "../generic/target_resource.h"

View File

@ -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;

View File

@ -0,0 +1,38 @@
/*
* 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
#define TARGET_RLIMIT_RTTIME 15
#endif

View File

@ -0,0 +1 @@
#include "../generic/target_resource.h"

View File

@ -0,0 +1 @@
#include "../generic/target_resource.h"

View File

@ -0,0 +1 @@
#include "../generic/target_resource.h"

View File

@ -0,0 +1 @@
#include "../generic/target_resource.h"

View File

@ -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)

View File

@ -0,0 +1 @@
#include "../generic/target_resource.h"

View File

@ -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

View File

@ -0,0 +1 @@
#include "../mips/target_resource.h"

View File

@ -0,0 +1 @@
#include "../generic/target_resource.h"

View File

@ -0,0 +1 @@
#include "../generic/target_resource.h"

View File

@ -0,0 +1 @@
#include "../generic/target_resource.h"

View File

@ -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,10 @@ typedef struct TaskState {
/* This thread's sigaltstack, if it has one */
struct target_sigaltstack sigaltstack_used;
} __attribute__((aligned(16))) TaskState;
/* Start time of task after system boot in clock ticks */
uint64_t start_boottime;
} TaskState;
abi_long do_brk(abi_ulong new_brk);

View File

@ -0,0 +1 @@
#include "../generic/target_resource.h"

View File

@ -0,0 +1 @@
#include "../generic/target_resource.h"

View File

@ -0,0 +1 @@
#include "../generic/target_resource.h"

View File

@ -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

View File

@ -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 <sys/inotify.h>
#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
@ -1083,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:
@ -8107,6 +8079,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);
@ -9465,6 +9440,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;
@ -9478,11 +9460,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;
@ -9508,6 +9485,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;
@ -9521,11 +9505,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;
@ -12341,35 +12320,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)

View File

@ -717,57 +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
#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
#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
#endif
#include "target_resource.h"
struct target_pollfd {
int fd; /* file descriptor */
@ -2772,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;

View File

@ -0,0 +1 @@
#include "../generic/target_resource.h"

View File

@ -0,0 +1 @@
#include "../generic/target_resource.h"