Skip to content

Commit d8035d4

Browse files
vapierRiku Voipio
authored andcommitted
linux-user: add ppoll syscall support
Some architectures (like Blackfin) only implement ppoll (and skip poll). So add support for it using existing poll code. Reviewed-by: Peter Maydell <[email protected]> Signed-off-by: Mike Frysinger <[email protected]> Signed-off-by: Riku Voipio <[email protected]>
1 parent 1af02e8 commit d8035d4

File tree

1 file changed

+55
-2
lines changed

1 file changed

+55
-2
lines changed

linux-user/syscall.c

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,15 @@ static int sys_inotify_init1(int flags)
529529
#undef TARGET_NR_inotify_rm_watch
530530
#endif /* CONFIG_INOTIFY */
531531

532+
#if defined(TARGET_NR_ppoll)
533+
#ifndef __NR_ppoll
534+
# define __NR_ppoll -1
535+
#endif
536+
#define __NR_sys_ppoll __NR_ppoll
537+
_syscall5(int, sys_ppoll, struct pollfd *, fds, nfds_t, nfds,
538+
struct timespec *, timeout, const __sigset_t *, sigmask,
539+
size_t, sigsetsize)
540+
#endif
532541

533542
extern int personality(int);
534543
extern int flock(int, int);
@@ -6230,8 +6239,13 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
62306239
ret = do_select(arg1, arg2, arg3, arg4, arg5);
62316240
break;
62326241
#endif
6233-
#ifdef TARGET_NR_poll
6242+
#if defined(TARGET_NR_poll) || defined(TARGET_NR_ppoll)
6243+
# ifdef TARGET_NR_poll
62346244
case TARGET_NR_poll:
6245+
# endif
6246+
# ifdef TARGET_NR_ppoll
6247+
case TARGET_NR_ppoll:
6248+
# endif
62356249
{
62366250
struct target_pollfd *target_pfd;
62376251
unsigned int nfds = arg2;
@@ -6242,12 +6256,51 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
62426256
target_pfd = lock_user(VERIFY_WRITE, arg1, sizeof(struct target_pollfd) * nfds, 1);
62436257
if (!target_pfd)
62446258
goto efault;
6259+
62456260
pfd = alloca(sizeof(struct pollfd) * nfds);
62466261
for(i = 0; i < nfds; i++) {
62476262
pfd[i].fd = tswap32(target_pfd[i].fd);
62486263
pfd[i].events = tswap16(target_pfd[i].events);
62496264
}
6250-
ret = get_errno(poll(pfd, nfds, timeout));
6265+
6266+
# ifdef TARGET_NR_ppoll
6267+
if (num == TARGET_NR_ppoll) {
6268+
struct timespec _timeout_ts, *timeout_ts = &_timeout_ts;
6269+
target_sigset_t *target_set;
6270+
sigset_t _set, *set = &_set;
6271+
6272+
if (arg3) {
6273+
if (target_to_host_timespec(timeout_ts, arg3)) {
6274+
unlock_user(target_pfd, arg1, 0);
6275+
goto efault;
6276+
}
6277+
} else {
6278+
timeout_ts = NULL;
6279+
}
6280+
6281+
if (arg4) {
6282+
target_set = lock_user(VERIFY_READ, arg4, sizeof(target_sigset_t), 1);
6283+
if (!target_set) {
6284+
unlock_user(target_pfd, arg1, 0);
6285+
goto efault;
6286+
}
6287+
target_to_host_sigset(set, target_set);
6288+
} else {
6289+
set = NULL;
6290+
}
6291+
6292+
ret = get_errno(sys_ppoll(pfd, nfds, timeout_ts, set, _NSIG/8));
6293+
6294+
if (!is_error(ret) && arg3) {
6295+
host_to_target_timespec(arg3, timeout_ts);
6296+
}
6297+
if (arg4) {
6298+
unlock_user(target_set, arg4, 0);
6299+
}
6300+
} else
6301+
# endif
6302+
ret = get_errno(poll(pfd, nfds, timeout));
6303+
62516304
if (!is_error(ret)) {
62526305
for(i = 0; i < nfds; i++) {
62536306
target_pfd[i].revents = tswap16(pfd[i].revents);

0 commit comments

Comments
 (0)