[PATCH v2 2/2] linux-user: implement epoll_pwait2 syscall

Michael Tokarev posted 2 patches 1 month ago
Maintainers: Laurent Vivier <laurent@vivier.eu>
[PATCH v2 2/2] linux-user: implement epoll_pwait2 syscall
Posted by Michael Tokarev 1 month ago
epoll_pwait2 is the same as epoll_pwait but with timeout being
(a pointer to) struct timespec instead of an integer.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3210
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
 linux-user/syscall.c | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index d89c36382e..8f41cdb94b 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -708,8 +708,11 @@ safe_syscall5(int, ppoll, struct pollfd *, ufds, unsigned int, nfds,
               size_t, sigsetsize)
 #endif
 safe_syscall6(int, epoll_pwait, int, epfd, struct epoll_event *, events,
-              int, maxevents, int, timeout, const sigset_t *, sigmask,
-              size_t, sigsetsize)
+              int, maxevents, int, timeout,
+              const sigset_t *, sigmask, size_t, sigsetsize)
+safe_syscall6(int, epoll_pwait2, int, epfd, struct epoll_event *, events,
+              int, maxevents, struct timespec *, timeout_ts,
+              const sigset_t *, sigmask, size_t, sigsetsize)
 #if defined(__NR_futex)
 safe_syscall6(int,futex,int *,uaddr,int,op,int,val, \
               const struct timespec *,timeout,int *,uaddr2,int,val3)
@@ -13619,12 +13622,20 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
     case TARGET_NR_epoll_wait:
 #endif
     case TARGET_NR_epoll_pwait:
+    case TARGET_NR_epoll_pwait2:
     {
         struct target_epoll_event *target_ep;
         struct epoll_event *ep;
         int epfd = arg1;
         int maxevents = arg3;
-        int timeout = arg4;
+        struct timespec ts, *timeout_ts = NULL;
+
+        if (num == TARGET_NR_epoll_pwait2 && arg4 != 0) {
+            if (target_to_host_timespec(&ts, arg4)) {
+                return -TARGET_EFAULT;
+            }
+            timeout_ts = &ts;
+        }
 
         if (maxevents <= 0 || maxevents > TARGET_EP_MAX_EVENTS) {
             return -TARGET_EINVAL;
@@ -13644,6 +13655,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
 
         switch (num) {
         case TARGET_NR_epoll_pwait:
+        case TARGET_NR_epoll_pwait2:
         {
             sigset_t *set = NULL;
 
@@ -13654,8 +13666,13 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
                 }
             }
 
-            ret = get_errno(safe_epoll_pwait(epfd, ep, maxevents, timeout,
-                                             set, SIGSET_T_SIZE));
+            if (num == TARGET_NR_epoll_pwait) {
+                ret = get_errno(safe_epoll_pwait(epfd, ep, maxevents, arg4,
+                                                 set, SIGSET_T_SIZE));
+            } else {
+                ret = get_errno(safe_epoll_pwait2(epfd, ep, maxevents, timeout_ts,
+                                                  set, SIGSET_T_SIZE));
+            }
 
             if (set) {
                 finish_sigsuspend_mask(ret);
@@ -13664,7 +13681,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
         }
 #if defined(TARGET_NR_epoll_wait)
         case TARGET_NR_epoll_wait:
-            ret = get_errno(safe_epoll_pwait(epfd, ep, maxevents, timeout,
+            ret = get_errno(safe_epoll_pwait(epfd, ep, maxevents, arg4,
                                              NULL, 0));
             break;
 #endif
-- 
2.47.3
Re: [PATCH v2 2/2] linux-user: implement epoll_pwait2 syscall
Posted by Richard Henderson 1 month ago
On 1/9/26 20:09, Michael Tokarev wrote:
> epoll_pwait2 is the same as epoll_pwait but with timeout being
> (a pointer to) struct timespec instead of an integer.
> 
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3210
> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
> ---
>   linux-user/syscall.c | 29 +++++++++++++++++++++++------
>   1 file changed, 23 insertions(+), 6 deletions(-)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index d89c36382e..8f41cdb94b 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -708,8 +708,11 @@ safe_syscall5(int, ppoll, struct pollfd *, ufds, unsigned int, nfds,
>                 size_t, sigsetsize)
>   #endif
>   safe_syscall6(int, epoll_pwait, int, epfd, struct epoll_event *, events,
> -              int, maxevents, int, timeout, const sigset_t *, sigmask,
> -              size_t, sigsetsize)
> +              int, maxevents, int, timeout,
> +              const sigset_t *, sigmask, size_t, sigsetsize)
> +safe_syscall6(int, epoll_pwait2, int, epfd, struct epoll_event *, events,
> +              int, maxevents, struct timespec *, timeout_ts,
> +              const sigset_t *, sigmask, size_t, sigsetsize)
>   #if defined(__NR_futex)
>   safe_syscall6(int,futex,int *,uaddr,int,op,int,val, \
>                 const struct timespec *,timeout,int *,uaddr2,int,val3)
> @@ -13619,12 +13622,20 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
>       case TARGET_NR_epoll_wait:
>   #endif
>       case TARGET_NR_epoll_pwait:
> +    case TARGET_NR_epoll_pwait2:
>       {
>           struct target_epoll_event *target_ep;
>           struct epoll_event *ep;
>           int epfd = arg1;
>           int maxevents = arg3;
> -        int timeout = arg4;
> +        struct timespec ts, *timeout_ts = NULL;
> +
> +        if (num == TARGET_NR_epoll_pwait2 && arg4 != 0) {
> +            if (target_to_host_timespec(&ts, arg4)) {
> +                return -TARGET_EFAULT;
> +            }
> +            timeout_ts = &ts;
> +        }
>   
>           if (maxevents <= 0 || maxevents > TARGET_EP_MAX_EVENTS) {
>               return -TARGET_EINVAL;
> @@ -13644,6 +13655,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
>   
>           switch (num) {
>           case TARGET_NR_epoll_pwait:
> +        case TARGET_NR_epoll_pwait2:
>           {
>               sigset_t *set = NULL;
>   
> @@ -13654,8 +13666,13 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
>                   }
>               }
>   
> -            ret = get_errno(safe_epoll_pwait(epfd, ep, maxevents, timeout,
> -                                             set, SIGSET_T_SIZE));
> +            if (num == TARGET_NR_epoll_pwait) {
> +                ret = get_errno(safe_epoll_pwait(epfd, ep, maxevents, arg4,
> +                                                 set, SIGSET_T_SIZE));
> +            } else {
> +                ret = get_errno(safe_epoll_pwait2(epfd, ep, maxevents, timeout_ts,
> +                                                  set, SIGSET_T_SIZE));
> +            }

This second test needs to be vs pwait2, lest you break epoll_wait.


r~
Re: [PATCH v2 2/2] linux-user: implement epoll_pwait2 syscall
Posted by Richard Henderson 1 month ago
On 1/11/26 10:20, Richard Henderson wrote:
>> @@ -13644,6 +13655,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, 
>> abi_long arg1,
>>           switch (num) {
>>           case TARGET_NR_epoll_pwait:
>> +        case TARGET_NR_epoll_pwait2:
>>           {
>>               sigset_t *set = NULL;
>> @@ -13654,8 +13666,13 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, 
>> abi_long arg1,
>>                   }
>>               }
>> -            ret = get_errno(safe_epoll_pwait(epfd, ep, maxevents, timeout,
>> -                                             set, SIGSET_T_SIZE));
>> +            if (num == TARGET_NR_epoll_pwait) {
>> +                ret = get_errno(safe_epoll_pwait(epfd, ep, maxevents, arg4,
>> +                                                 set, SIGSET_T_SIZE));
>> +            } else {
>> +                ret = get_errno(safe_epoll_pwait2(epfd, ep, maxevents, timeout_ts,
>> +                                                  set, SIGSET_T_SIZE));
>> +            }
> 
> This second test needs to be vs pwait2, lest you break epoll_wait.

Bah, seconds later I noticed the switch in the context.

r~

Re: [PATCH v2 2/2] linux-user: implement epoll_pwait2 syscall
Posted by Pierrick Bouvier 1 month ago
On 1/9/26 1:09 AM, Michael Tokarev wrote:
> epoll_pwait2 is the same as epoll_pwait but with timeout being
> (a pointer to) struct timespec instead of an integer.
> 
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3210
> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
> ---
>   linux-user/syscall.c | 29 +++++++++++++++++++++++------
>   1 file changed, 23 insertions(+), 6 deletions(-)
> 

Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>