mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] Add getrandom syscall wrapper function
@ 2018-01-01 20:31 Hauke Mehrtens
  2018-01-01 20:47 ` Rich Felker
  0 siblings, 1 reply; 7+ messages in thread
From: Hauke Mehrtens @ 2018-01-01 20:31 UTC (permalink / raw)
  To: musl; +Cc: Hauke Mehrtens

This syscall is available since Linux 3.17 and was also implemented in
glibc in version 2.25. This is a pure syscall wrapper liker glibc does
it.
---
 include/sys/random.h  | 19 +++++++++++++++++++
 src/linux/getrandom.c | 11 +++++++++++
 2 files changed, 30 insertions(+)
 create mode 100644 include/sys/random.h
 create mode 100644 src/linux/getrandom.c

diff --git a/include/sys/random.h b/include/sys/random.h
new file mode 100644
index 00000000..5540f877
--- /dev/null
+++ b/include/sys/random.h
@@ -0,0 +1,19 @@
+#ifndef _SYS_RANDOM_H
+#define _SYS_RANDOM_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define __NEED_size_t
+#define __NEED_ssize_t
+#include <bits/alltypes.h>
+
+#define GRND_NONBLOCK	0x0001
+#define GRND_RANDOM	0x0002
+
+ssize_t getrandom(void *buf, size_t buflen, unsigned int flags);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/src/linux/getrandom.c b/src/linux/getrandom.c
new file mode 100644
index 00000000..50b07df9
--- /dev/null
+++ b/src/linux/getrandom.c
@@ -0,0 +1,11 @@
+#include <sys/random.h>
+#include "syscall.h"
+
+ssize_t getrandom(void *buf, size_t buflen, unsigned int flags)
+{
+#ifdef SYS_getrandom
+	return syscall_cp(SYS_getrandom, buf, buflen, flags);
+#else
+	return __syscall_ret(-ENOSYS);
+#endif
+}
-- 
2.11.0



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-01-02 18:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-01 20:31 [PATCH] Add getrandom syscall wrapper function Hauke Mehrtens
2018-01-01 20:47 ` Rich Felker
2018-01-01 21:51   ` Hauke Mehrtens
2018-01-01 22:03     ` Rich Felker
2018-01-02  2:14       ` Rich Felker
2018-01-02 15:27         ` Szabolcs Nagy
2018-01-02 18:09           ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).