diff mbox series

linux-user: implement the semtimedop syscall

Message ID mvmy2nn7ms3.fsf@suse.de (mailing list archive)
State New, archived
Headers show
Series linux-user: implement the semtimedop syscall | expand

Commit Message

Andreas Schwab July 13, 2020, 10:05 a.m. UTC
Signed-off-by: Andreas Schwab <schwab@suse.de>
---
 linux-user/syscall.c | 32 +++++++++++++++++++++++++++-----
 1 file changed, 27 insertions(+), 5 deletions(-)

Comments

Laurent Vivier July 13, 2020, 4:18 p.m. UTC | #1
Thank you but we have already a series pending to fix that:

https://patchew.org/QEMU/20200626124612.58593-1-mkysel@tachyum.com/

Laurent

Le 13/07/2020 à 12:05, Andreas Schwab a écrit :
> Signed-off-by: Andreas Schwab <schwab@suse.de>
> ---
>  linux-user/syscall.c | 32 +++++++++++++++++++++++++++-----
>  1 file changed, 27 insertions(+), 5 deletions(-)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 9ec03a889d..7c0f5b83ff 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -3877,23 +3877,37 @@ static inline abi_long target_to_host_sembuf(struct sembuf *host_sembuf,
>      return 0;
>  }
>  
> -static inline abi_long do_semop(int semid, abi_long ptr, unsigned nsops)
> +static inline abi_long do_semtimedop(int semid, abi_long ptr, unsigned nsops,
> +    abi_long timeout)
>  {
>      struct sembuf sops[nsops];
> +    struct timespec ts, *pts;
>      abi_long ret;
>  
>      if (target_to_host_sembuf(sops, ptr, nsops))
>          return -TARGET_EFAULT;
>  
> +    if (timeout) {
> +        pts = &ts;
> +        if (target_to_host_timespec(pts, timeout)) {
> +            return -TARGET_EFAULT;
> +        }
> +    } else {
> +        pts = NULL;
> +    }
> +
>      ret = -TARGET_ENOSYS;
>  #ifdef __NR_semtimedop
> -    ret = get_errno(safe_semtimedop(semid, sops, nsops, NULL));
> +    ret = get_errno(safe_semtimedop(semid, sops, nsops, pts));
>  #endif
>  #ifdef __NR_ipc
>      if (ret == -TARGET_ENOSYS) {
> -        ret = get_errno(safe_ipc(IPCOP_semtimedop, semid, nsops, 0, sops, 0));
> +        ret = get_errno(safe_ipc(IPCOP_semtimedop, semid, nsops, 0, sops, pts));
>      }
>  #endif
> +    if (!is_error(ret) && timeout) {
> +        ret = host_to_target_timespec(timeout, pts);
> +    }
>      return ret;
>  }
>  
> @@ -4371,7 +4385,11 @@ static abi_long do_ipc(CPUArchState *cpu_env,
>  
>      switch (call) {
>      case IPCOP_semop:
> -        ret = do_semop(first, ptr, second);
> +        ret = do_semtimedop(first, ptr, second, 0);
> +        break;
> +
> +    case IPCOP_semtimedop:
> +        ret = do_semtimedop(first, ptr, second, third);
>          break;
>  
>      case IPCOP_semget:
> @@ -9683,7 +9701,11 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
>  #endif
>  #ifdef TARGET_NR_semop
>      case TARGET_NR_semop:
> -        return do_semop(arg1, arg2, arg3);
> +        return do_semtimedop(arg1, arg2, arg3, 0);
> +#endif
> +#ifdef TARGET_NR_semtimedop
> +    case TARGET_NR_semtimedop:
> +        return do_semtimedop(arg1, arg2, arg3, arg4);
>  #endif
>  #ifdef TARGET_NR_semctl
>      case TARGET_NR_semctl:
>
diff mbox series

Patch

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 9ec03a889d..7c0f5b83ff 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -3877,23 +3877,37 @@  static inline abi_long target_to_host_sembuf(struct sembuf *host_sembuf,
     return 0;
 }
 
-static inline abi_long do_semop(int semid, abi_long ptr, unsigned nsops)
+static inline abi_long do_semtimedop(int semid, abi_long ptr, unsigned nsops,
+    abi_long timeout)
 {
     struct sembuf sops[nsops];
+    struct timespec ts, *pts;
     abi_long ret;
 
     if (target_to_host_sembuf(sops, ptr, nsops))
         return -TARGET_EFAULT;
 
+    if (timeout) {
+        pts = &ts;
+        if (target_to_host_timespec(pts, timeout)) {
+            return -TARGET_EFAULT;
+        }
+    } else {
+        pts = NULL;
+    }
+
     ret = -TARGET_ENOSYS;
 #ifdef __NR_semtimedop
-    ret = get_errno(safe_semtimedop(semid, sops, nsops, NULL));
+    ret = get_errno(safe_semtimedop(semid, sops, nsops, pts));
 #endif
 #ifdef __NR_ipc
     if (ret == -TARGET_ENOSYS) {
-        ret = get_errno(safe_ipc(IPCOP_semtimedop, semid, nsops, 0, sops, 0));
+        ret = get_errno(safe_ipc(IPCOP_semtimedop, semid, nsops, 0, sops, pts));
     }
 #endif
+    if (!is_error(ret) && timeout) {
+        ret = host_to_target_timespec(timeout, pts);
+    }
     return ret;
 }
 
@@ -4371,7 +4385,11 @@  static abi_long do_ipc(CPUArchState *cpu_env,
 
     switch (call) {
     case IPCOP_semop:
-        ret = do_semop(first, ptr, second);
+        ret = do_semtimedop(first, ptr, second, 0);
+        break;
+
+    case IPCOP_semtimedop:
+        ret = do_semtimedop(first, ptr, second, third);
         break;
 
     case IPCOP_semget:
@@ -9683,7 +9701,11 @@  static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
 #endif
 #ifdef TARGET_NR_semop
     case TARGET_NR_semop:
-        return do_semop(arg1, arg2, arg3);
+        return do_semtimedop(arg1, arg2, arg3, 0);
+#endif
+#ifdef TARGET_NR_semtimedop
+    case TARGET_NR_semtimedop:
+        return do_semtimedop(arg1, arg2, arg3, arg4);
 #endif
 #ifdef TARGET_NR_semctl
     case TARGET_NR_semctl: