Skip to contentSkip to conversation

linux-user: add getrandom() syscall

PATCH Applied Laurent Vivier 2 participants 2 messages Feb 5, 2016 – Feb 15, 2016

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: add getrandom() syscall

getrandom() has been introduced in kernel 3.17 and is now used during the boot sequence of Debian unstable (stretch/sid).

---
 linux-user/syscall.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
linux-user/syscall.c +13 -0
index dac5518..6801fa2 100644
@@ -249,6 +249,9 @@ _syscall2(int, ioprio_get, int, which, int, who)
 #if defined(TARGET_NR_ioprio_set) && defined(__NR_ioprio_set)
 _syscall3(int, ioprio_set, int, which, int, who, int, ioprio)
 #endif
+#ifdef TARGET_NR_getrandom
+_syscall3(int, getrandom, void *, buf, size_t, buflen, unsigned int, flags)
+#endif
 
 static bitmask_transtbl fcntl_flags_tbl[] = {
   { TARGET_O_ACCMODE,   TARGET_O_WRONLY,    O_ACCMODE,   O_WRONLY,    },
@@ -7541,6 +7544,16 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         ret = get_errno(shutdown(arg1, arg2));
         break;
 #endif
+#ifdef TARGET_NR_getrandom
+    case TARGET_NR_getrandom:
+        p = lock_user(VERIFY_WRITE, arg1, arg2, 0);
+        if (!p) {
+            goto efault;
+        }
+        ret = get_errno(getrandom(p, arg2, arg3));
+        unlock_user(p, arg1, ret);
+        break;
+#endif
 #ifdef TARGET_NR_socket
     case TARGET_NR_socket:
         ret = do_socket(arg1, arg2, arg3);
Signature · 1 line
2.5.0
Applied
#1 lore raw
Quoted 2 lines · Laurent Vivier

getrandom() has been introduced in kernel 3.17 and is now used during the boot sequence of Debian unstable (stretch/sid).

Applied, thanks

Quoted 37 lines
---
 linux-user/syscall.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
linux-user/syscall.c +13 -0
index dac5518..6801fa2 100644
@@ -249,6 +249,9 @@ _syscall2(int, ioprio_get, int, which, int, who)
 #if defined(TARGET_NR_ioprio_set) && defined(__NR_ioprio_set)
 _syscall3(int, ioprio_set, int, which, int, who, int, ioprio)
 #endif
+#ifdef TARGET_NR_getrandom
+_syscall3(int, getrandom, void *, buf, size_t, buflen, unsigned int, flags)
+#endif
 
 static bitmask_transtbl fcntl_flags_tbl[] = {
   { TARGET_O_ACCMODE,   TARGET_O_WRONLY,    O_ACCMODE,   O_WRONLY,    },
@@ -7541,6 +7544,16 @@ abi_long do_syscall(void *cpu_env, int 
 num, abi_long arg1,
         ret = get_errno(shutdown(arg1, arg2));
         break;
 #endif
+#ifdef TARGET_NR_getrandom
+    case TARGET_NR_getrandom:
+        p = lock_user(VERIFY_WRITE, arg1, arg2, 0);
+        if (!p) {
+            goto efault;
+        }
+        ret = get_errno(getrandom(p, arg2, arg3));
+        unlock_user(p, arg1, ret);
+        break;
+#endif
 #ifdef TARGET_NR_socket
     case TARGET_NR_socket:
         ret = do_socket(arg1, arg2, arg3);