Add ppoll_time64() and pselect6_time64()

Some fixes for for elfload, fcntl, termbits and btrfs
 -----BEGIN PGP SIGNATURE-----
 
 iQJGBAABCAAwFiEEzS913cjjpNwuT1Fz8ww4vT8vvjwFAl9V+qQSHGxhdXJlbnRA
 dml2aWVyLmV1AAoJEPMMOL0/L748fSwQAJJFV7a9zFDGA2wmiu4mLffFN4FUwkE6
 Ov4/pzE8O6By5AnaBN8JiuoIYLKD5vdIjz/vuMwxxVUbwqBeqLGir+LmrGMhGNWO
 Ghu/SyDhGiot+WU3rAvn3cr2ceZgn+eZtDHdYO3pFcthe18JP1wJIYtYISL7I4Tm
 ulsp0JiL0+UqBQeJHwA+ttmL1kNDqnvwJqDLLX2cZ4QaMhmg/c825CXmvaP7gXUO
 FOhBBdSrCl8sPr/A4Lem8lvCJpZSPt3cZvmpRm/7H9Oe2FRMhaizIDuPhrJoWqui
 NH1UwOig0Sy9vBTAzpNCNjKOwXYFTePOB3QQcmaQSqWjSSReUHdcD/Fx2Dw9BYot
 9mv8QWZukyYOaO6Py4LmtFOc2uupDIEqkOnD0mVlGYjMlCd2LI6AG3eI1VDZNtiL
 mc4Mv6nZfn+/c7jXMg9ZrhR5Hm7lbBEtSSLs7hczgMoE2o9RyD4mILLdUKm+VZYn
 DfnwlrLtDAQvP3ANYemdSuMODQnFzcbz348m6MQr/6p98+9q9yxehE1SoDIBLSmk
 3xfSiTTv1nolTYdBG6/5h3pI7r3b76iHICKJVU0XTCd+XFs9o+MfRrtQ95f7T5hJ
 BRkyDHi/HDD8XFYbmCd3Zdy+/SlyL4TYsNLflSP9wwcFOX4odL7L9RN4T2bpcS1a
 t4qgCgCJxrNH
 =edT0
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/vivier2/tags/linux-user-for-5.2-pull-request' into staging

Add ppoll_time64() and pselect6_time64()
Some fixes for for elfload, fcntl, termbits and btrfs

# gpg: Signature made Mon 07 Sep 2020 10:17:24 BST
# 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/vivier2/tags/linux-user-for-5.2-pull-request:
  linux-user: Protect btrfs ioctl target definitions
  linux-user: fix ppc/termbits.h
  linux-user: Map signal numbers in fcntl
  linux-user: Correctly start brk after executable
  linux-user: Add support for ppoll_time64() and pselect6_time64()

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell 2020-09-07 15:31:04 +01:00
commit 9d5589bb3f
4 changed files with 264 additions and 217 deletions

View File

@ -2580,9 +2580,9 @@ static void load_elf_image(const char *image_name, int image_fd,
if (vaddr_ef > info->end_data) {
info->end_data = vaddr_ef;
}
if (vaddr_em > info->brk) {
info->brk = vaddr_em;
}
}
if (vaddr_em > info->brk) {
info->brk = vaddr_em;
}
} else if (eppnt->p_type == PT_INTERP && pinterp_name) {
char *interp_name;
@ -2637,7 +2637,6 @@ static void load_elf_image(const char *image_name, int image_fd,
if (info->end_data == 0) {
info->start_data = info->end_code;
info->end_data = info->end_code;
info->brk = info->end_code;
}
if (qemu_log_enabled()) {

View File

@ -14,8 +14,8 @@ struct target_termios {
target_tcflag_t c_oflag; /* output mode flags */
target_tcflag_t c_cflag; /* control mode flags */
target_tcflag_t c_lflag; /* local mode flags */
target_cc_t c_line; /* line discipline */
target_cc_t c_cc[TARGET_NCCS]; /* control characters */
target_cc_t c_line; /* line discipline */
target_speed_t c_ispeed; /* input speed */
target_speed_t c_ospeed; /* output speed */
};

View File

@ -728,11 +728,11 @@ safe_syscall5(int, waitid, idtype_t, idtype, id_t, id, siginfo_t *, infop, \
int, options, struct rusage *, rusage)
safe_syscall3(int, execve, const char *, filename, char **, argv, char **, envp)
#if defined(TARGET_NR_select) || defined(TARGET_NR__newselect) || \
defined(TARGET_NR_pselect6)
defined(TARGET_NR_pselect6) || defined(TARGET_NR_pselect6_time64)
safe_syscall6(int, pselect6, int, nfds, fd_set *, readfds, fd_set *, writefds, \
fd_set *, exceptfds, struct timespec *, timeout, void *, sig)
#endif
#if defined(TARGET_NR_ppoll) || defined(TARGET_NR_poll)
#if defined(TARGET_NR_ppoll) || defined(TARGET_NR_ppoll_time64)
safe_syscall5(int, ppoll, struct pollfd *, ufds, unsigned int, nfds,
struct timespec *, tsp, const sigset_t *, sigmask,
size_t, sigsetsize)
@ -952,7 +952,7 @@ abi_long do_brk(abi_ulong new_brk)
}
#if defined(TARGET_NR_select) || defined(TARGET_NR__newselect) || \
defined(TARGET_NR_pselect6)
defined(TARGET_NR_pselect6) || defined(TARGET_NR_pselect6_time64)
static inline abi_long copy_from_user_fdset(fd_set *fds,
abi_ulong target_fds_addr,
int n)
@ -1250,7 +1250,8 @@ static inline abi_long target_to_host_timespec(struct timespec *host_ts,
defined(TARGET_NR_rt_sigtimedwait_time64) || \
defined(TARGET_NR_utimensat) || \
defined(TARGET_NR_utimensat_time64) || \
defined(TARGET_NR_semtimedop_time64)
defined(TARGET_NR_semtimedop_time64) || \
defined(TARGET_NR_pselect6_time64) || defined(TARGET_NR_ppoll_time64)
static inline abi_long target_to_host_timespec64(struct timespec *host_ts,
abi_ulong target_addr)
{
@ -1458,6 +1459,237 @@ static abi_long do_old_select(abi_ulong arg1)
#endif
#endif
#if defined(TARGET_NR_pselect6) || defined(TARGET_NR_pselect6_time64)
static abi_long do_pselect6(abi_long arg1, abi_long arg2, abi_long arg3,
abi_long arg4, abi_long arg5, abi_long arg6,
bool time64)
{
abi_long rfd_addr, wfd_addr, efd_addr, n, ts_addr;
fd_set rfds, wfds, efds;
fd_set *rfds_ptr, *wfds_ptr, *efds_ptr;
struct timespec ts, *ts_ptr;
abi_long ret;
/*
* The 6th arg is actually two args smashed together,
* so we cannot use the C library.
*/
sigset_t set;
struct {
sigset_t *set;
size_t size;
} sig, *sig_ptr;
abi_ulong arg_sigset, arg_sigsize, *arg7;
target_sigset_t *target_sigset;
n = arg1;
rfd_addr = arg2;
wfd_addr = arg3;
efd_addr = arg4;
ts_addr = arg5;
ret = copy_from_user_fdset_ptr(&rfds, &rfds_ptr, rfd_addr, n);
if (ret) {
return ret;
}
ret = copy_from_user_fdset_ptr(&wfds, &wfds_ptr, wfd_addr, n);
if (ret) {
return ret;
}
ret = copy_from_user_fdset_ptr(&efds, &efds_ptr, efd_addr, n);
if (ret) {
return ret;
}
/*
* This takes a timespec, and not a timeval, so we cannot
* use the do_select() helper ...
*/
if (ts_addr) {
if (time64) {
if (target_to_host_timespec64(&ts, ts_addr)) {
return -TARGET_EFAULT;
}
} else {
if (target_to_host_timespec(&ts, ts_addr)) {
return -TARGET_EFAULT;
}
}
ts_ptr = &ts;
} else {
ts_ptr = NULL;
}
/* Extract the two packed args for the sigset */
if (arg6) {
sig_ptr = &sig;
sig.size = SIGSET_T_SIZE;
arg7 = lock_user(VERIFY_READ, arg6, sizeof(*arg7) * 2, 1);
if (!arg7) {
return -TARGET_EFAULT;
}
arg_sigset = tswapal(arg7[0]);
arg_sigsize = tswapal(arg7[1]);
unlock_user(arg7, arg6, 0);
if (arg_sigset) {
sig.set = &set;
if (arg_sigsize != sizeof(*target_sigset)) {
/* Like the kernel, we enforce correct size sigsets */
return -TARGET_EINVAL;
}
target_sigset = lock_user(VERIFY_READ, arg_sigset,
sizeof(*target_sigset), 1);
if (!target_sigset) {
return -TARGET_EFAULT;
}
target_to_host_sigset(&set, target_sigset);
unlock_user(target_sigset, arg_sigset, 0);
} else {
sig.set = NULL;
}
} else {
sig_ptr = NULL;
}
ret = get_errno(safe_pselect6(n, rfds_ptr, wfds_ptr, efds_ptr,
ts_ptr, sig_ptr));
if (!is_error(ret)) {
if (rfd_addr && copy_to_user_fdset(rfd_addr, &rfds, n)) {
return -TARGET_EFAULT;
}
if (wfd_addr && copy_to_user_fdset(wfd_addr, &wfds, n)) {
return -TARGET_EFAULT;
}
if (efd_addr && copy_to_user_fdset(efd_addr, &efds, n)) {
return -TARGET_EFAULT;
}
if (time64) {
if (ts_addr && host_to_target_timespec64(ts_addr, &ts)) {
return -TARGET_EFAULT;
}
} else {
if (ts_addr && host_to_target_timespec(ts_addr, &ts)) {
return -TARGET_EFAULT;
}
}
}
return ret;
}
#endif
#if defined(TARGET_NR_poll) || defined(TARGET_NR_ppoll) || \
defined(TARGET_NR_ppoll_time64)
static abi_long do_ppoll(abi_long arg1, abi_long arg2, abi_long arg3,
abi_long arg4, abi_long arg5, bool ppoll, bool time64)
{
struct target_pollfd *target_pfd;
unsigned int nfds = arg2;
struct pollfd *pfd;
unsigned int i;
abi_long ret;
pfd = NULL;
target_pfd = NULL;
if (nfds) {
if (nfds > (INT_MAX / sizeof(struct target_pollfd))) {
return -TARGET_EINVAL;
}
target_pfd = lock_user(VERIFY_WRITE, arg1,
sizeof(struct target_pollfd) * nfds, 1);
if (!target_pfd) {
return -TARGET_EFAULT;
}
pfd = alloca(sizeof(struct pollfd) * nfds);
for (i = 0; i < nfds; i++) {
pfd[i].fd = tswap32(target_pfd[i].fd);
pfd[i].events = tswap16(target_pfd[i].events);
}
}
if (ppoll) {
struct timespec _timeout_ts, *timeout_ts = &_timeout_ts;
target_sigset_t *target_set;
sigset_t _set, *set = &_set;
if (arg3) {
if (time64) {
if (target_to_host_timespec64(timeout_ts, arg3)) {
unlock_user(target_pfd, arg1, 0);
return -TARGET_EFAULT;
}
} else {
if (target_to_host_timespec(timeout_ts, arg3)) {
unlock_user(target_pfd, arg1, 0);
return -TARGET_EFAULT;
}
}
} else {
timeout_ts = NULL;
}
if (arg4) {
if (arg5 != sizeof(target_sigset_t)) {
unlock_user(target_pfd, arg1, 0);
return -TARGET_EINVAL;
}
target_set = lock_user(VERIFY_READ, arg4,
sizeof(target_sigset_t), 1);
if (!target_set) {
unlock_user(target_pfd, arg1, 0);
return -TARGET_EFAULT;
}
target_to_host_sigset(set, target_set);
} else {
set = NULL;
}
ret = get_errno(safe_ppoll(pfd, nfds, timeout_ts,
set, SIGSET_T_SIZE));
if (!is_error(ret) && arg3) {
if (time64) {
if (host_to_target_timespec64(arg3, timeout_ts)) {
return -TARGET_EFAULT;
}
} else {
if (host_to_target_timespec(arg3, timeout_ts)) {
return -TARGET_EFAULT;
}
}
}
if (arg4) {
unlock_user(target_set, arg4, 0);
}
} else {
struct timespec ts, *pts;
if (arg3 >= 0) {
/* Convert ms to secs, ns */
ts.tv_sec = arg3 / 1000;
ts.tv_nsec = (arg3 % 1000) * 1000000LL;
pts = &ts;
} else {
/* -ve poll() timeout means "infinite" */
pts = NULL;
}
ret = get_errno(safe_ppoll(pfd, nfds, pts, NULL, 0));
}
if (!is_error(ret)) {
for (i = 0; i < nfds; i++) {
target_pfd[i].revents = tswap16(pfd[i].revents);
}
}
unlock_user(target_pfd, arg1, sizeof(struct target_pollfd) * nfds);
return ret;
}
#endif
static abi_long do_pipe2(int host_pipe[], int flags)
{
#ifdef CONFIG_PIPE2
@ -6642,10 +6874,16 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
break;
#endif
case TARGET_F_SETSIG:
ret = get_errno(safe_fcntl(fd, host_cmd, target_to_host_signal(arg)));
break;
case TARGET_F_GETSIG:
ret = host_to_target_signal(get_errno(safe_fcntl(fd, host_cmd, arg)));
break;
case TARGET_F_SETOWN:
case TARGET_F_GETOWN:
case TARGET_F_SETSIG:
case TARGET_F_GETSIG:
case TARGET_F_SETLEASE:
case TARGET_F_GETLEASE:
case TARGET_F_SETPIPE_SZ:
@ -9256,106 +9494,11 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
#endif
#ifdef TARGET_NR_pselect6
case TARGET_NR_pselect6:
{
abi_long rfd_addr, wfd_addr, efd_addr, n, ts_addr;
fd_set rfds, wfds, efds;
fd_set *rfds_ptr, *wfds_ptr, *efds_ptr;
struct timespec ts, *ts_ptr;
/*
* The 6th arg is actually two args smashed together,
* so we cannot use the C library.
*/
sigset_t set;
struct {
sigset_t *set;
size_t size;
} sig, *sig_ptr;
abi_ulong arg_sigset, arg_sigsize, *arg7;
target_sigset_t *target_sigset;
n = arg1;
rfd_addr = arg2;
wfd_addr = arg3;
efd_addr = arg4;
ts_addr = arg5;
ret = copy_from_user_fdset_ptr(&rfds, &rfds_ptr, rfd_addr, n);
if (ret) {
return ret;
}
ret = copy_from_user_fdset_ptr(&wfds, &wfds_ptr, wfd_addr, n);
if (ret) {
return ret;
}
ret = copy_from_user_fdset_ptr(&efds, &efds_ptr, efd_addr, n);
if (ret) {
return ret;
}
/*
* This takes a timespec, and not a timeval, so we cannot
* use the do_select() helper ...
*/
if (ts_addr) {
if (target_to_host_timespec(&ts, ts_addr)) {
return -TARGET_EFAULT;
}
ts_ptr = &ts;
} else {
ts_ptr = NULL;
}
/* Extract the two packed args for the sigset */
if (arg6) {
sig_ptr = &sig;
sig.size = SIGSET_T_SIZE;
arg7 = lock_user(VERIFY_READ, arg6, sizeof(*arg7) * 2, 1);
if (!arg7) {
return -TARGET_EFAULT;
}
arg_sigset = tswapal(arg7[0]);
arg_sigsize = tswapal(arg7[1]);
unlock_user(arg7, arg6, 0);
if (arg_sigset) {
sig.set = &set;
if (arg_sigsize != sizeof(*target_sigset)) {
/* Like the kernel, we enforce correct size sigsets */
return -TARGET_EINVAL;
}
target_sigset = lock_user(VERIFY_READ, arg_sigset,
sizeof(*target_sigset), 1);
if (!target_sigset) {
return -TARGET_EFAULT;
}
target_to_host_sigset(&set, target_sigset);
unlock_user(target_sigset, arg_sigset, 0);
} else {
sig.set = NULL;
}
} else {
sig_ptr = NULL;
}
ret = get_errno(safe_pselect6(n, rfds_ptr, wfds_ptr, efds_ptr,
ts_ptr, sig_ptr));
if (!is_error(ret)) {
if (rfd_addr && copy_to_user_fdset(rfd_addr, &rfds, n))
return -TARGET_EFAULT;
if (wfd_addr && copy_to_user_fdset(wfd_addr, &wfds, n))
return -TARGET_EFAULT;
if (efd_addr && copy_to_user_fdset(efd_addr, &efds, n))
return -TARGET_EFAULT;
if (ts_addr && host_to_target_timespec(ts_addr, &ts))
return -TARGET_EFAULT;
}
}
return ret;
return do_pselect6(arg1, arg2, arg3, arg4, arg5, arg6, false);
#endif
#ifdef TARGET_NR_pselect6_time64
case TARGET_NR_pselect6_time64:
return do_pselect6(arg1, arg2, arg3, arg4, arg5, arg6, true);
#endif
#ifdef TARGET_NR_symlink
case TARGET_NR_symlink:
@ -10306,114 +10449,17 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
case TARGET_NR__newselect:
return do_select(arg1, arg2, arg3, arg4, arg5);
#endif
#if defined(TARGET_NR_poll) || defined(TARGET_NR_ppoll)
# ifdef TARGET_NR_poll
#ifdef TARGET_NR_poll
case TARGET_NR_poll:
# endif
# ifdef TARGET_NR_ppoll
return do_ppoll(arg1, arg2, arg3, arg4, arg5, false, false);
#endif
#ifdef TARGET_NR_ppoll
case TARGET_NR_ppoll:
# endif
{
struct target_pollfd *target_pfd;
unsigned int nfds = arg2;
struct pollfd *pfd;
unsigned int i;
pfd = NULL;
target_pfd = NULL;
if (nfds) {
if (nfds > (INT_MAX / sizeof(struct target_pollfd))) {
return -TARGET_EINVAL;
}
target_pfd = lock_user(VERIFY_WRITE, arg1,
sizeof(struct target_pollfd) * nfds, 1);
if (!target_pfd) {
return -TARGET_EFAULT;
}
pfd = alloca(sizeof(struct pollfd) * nfds);
for (i = 0; i < nfds; i++) {
pfd[i].fd = tswap32(target_pfd[i].fd);
pfd[i].events = tswap16(target_pfd[i].events);
}
}
switch (num) {
# ifdef TARGET_NR_ppoll
case TARGET_NR_ppoll:
{
struct timespec _timeout_ts, *timeout_ts = &_timeout_ts;
target_sigset_t *target_set;
sigset_t _set, *set = &_set;
if (arg3) {
if (target_to_host_timespec(timeout_ts, arg3)) {
unlock_user(target_pfd, arg1, 0);
return -TARGET_EFAULT;
}
} else {
timeout_ts = NULL;
}
if (arg4) {
if (arg5 != sizeof(target_sigset_t)) {
unlock_user(target_pfd, arg1, 0);
return -TARGET_EINVAL;
}
target_set = lock_user(VERIFY_READ, arg4, sizeof(target_sigset_t), 1);
if (!target_set) {
unlock_user(target_pfd, arg1, 0);
return -TARGET_EFAULT;
}
target_to_host_sigset(set, target_set);
} else {
set = NULL;
}
ret = get_errno(safe_ppoll(pfd, nfds, timeout_ts,
set, SIGSET_T_SIZE));
if (!is_error(ret) && arg3) {
host_to_target_timespec(arg3, timeout_ts);
}
if (arg4) {
unlock_user(target_set, arg4, 0);
}
break;
}
# endif
# ifdef TARGET_NR_poll
case TARGET_NR_poll:
{
struct timespec ts, *pts;
if (arg3 >= 0) {
/* Convert ms to secs, ns */
ts.tv_sec = arg3 / 1000;
ts.tv_nsec = (arg3 % 1000) * 1000000LL;
pts = &ts;
} else {
/* -ve poll() timeout means "infinite" */
pts = NULL;
}
ret = get_errno(safe_ppoll(pfd, nfds, pts, NULL, 0));
break;
}
# endif
default:
g_assert_not_reached();
}
if (!is_error(ret)) {
for(i = 0; i < nfds; i++) {
target_pfd[i].revents = tswap16(pfd[i].revents);
}
}
unlock_user(target_pfd, arg1, sizeof(struct target_pollfd) * nfds);
}
return ret;
return do_ppoll(arg1, arg2, arg3, arg4, arg5, true, false);
#endif
#ifdef TARGET_NR_ppoll_time64
case TARGET_NR_ppoll_time64:
return do_ppoll(arg1, arg2, arg3, arg4, arg5, true, true);
#endif
case TARGET_NR_flock:
/* NOTE: the flock constant seems to be the same for every

View File

@ -1006,6 +1006,7 @@ struct target_rtc_pll_info {
#define TARGET_FS_IOC32_SETVERSION TARGET_IOW('v', 2, int)
/* btrfs ioctls */
#ifdef CONFIG_BTRFS
#define TARGET_BTRFS_IOC_SNAP_CREATE TARGET_IOWU(BTRFS_IOCTL_MAGIC, 1)
#define TARGET_BTRFS_IOC_SCAN_DEV TARGET_IOWU(BTRFS_IOCTL_MAGIC, 4)
#define TARGET_BTRFS_IOC_FORGET_DEV TARGET_IOWU(BTRFS_IOCTL_MAGIC, 5)
@ -1041,6 +1042,7 @@ struct target_rtc_pll_info {
#define TARGET_BTRFS_IOC_GET_SUBVOL_INFO TARGET_IORU(BTRFS_IOCTL_MAGIC, 60)
#define TARGET_BTRFS_IOC_GET_SUBVOL_ROOTREF TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 61)
#define TARGET_BTRFS_IOC_INO_LOOKUP_USER TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 62)
#endif
/* usb ioctls */
#define TARGET_USBDEVFS_CONTROL TARGET_IOWRU('U', 0)