[libc-commits] [PATCH] D134665: Implement `getrandom` function for linux targets.

Michael Jones via Phabricator via libc-commits libc-commits at lists.llvm.org
Mon Sep 26 13:23:59 PDT 2022


michaelrj added a comment.

Overall this patch is almost there, it just needs a couple more mechanical things since it adds a new header. Specifically, you should add the header definition to `spec/linux.td`. You can look at how `HeaderSpec`s are defined in `spec/stdc.td`, I would recommend looking at the one for `string.h` as an example, or feel free to reach out if you need help figuring it out.



================
Comment at: libc/include/CMakeLists.txt:216
+    .llvm_libc_common_h
+    .llvm-libc-macros.sys_random_macros
+    .llvm-libc-types.ssize_t
----------------
you need to add this target to include/llvm-libc-macros/CMakeLists.txt (it should be the same as the others in there) as well as the cmake file in the linux subfolder.


================
Comment at: libc/src/sys/CMakeLists.txt:7
+add_subdirectory(random)
\ No newline at end of file

----------------
nit: please fix


================
Comment at: libc/src/sys/random/getrandom.h:1-2
+//===-- Implementation header for getrandom ----------------------*- C++
+//-*-===//
+//
----------------
nit: this should all be on one line


================
Comment at: libc/src/sys/random/linux/CMakeLists.txt:13
+)
\ No newline at end of file

----------------
nit: please fix


================
Comment at: libc/src/sys/random/linux/getrandom.cpp:21
+                   (void *buf, size_t buflen, unsigned int flags)) {
+#ifdef SYS_getrandom
+  long ret = __llvm_libc::syscall(SYS_getrandom, buf, buflen, flags);
----------------
if there's only one possible syscall, we usually don't bother with checking if it's defined, since the compiler will do that for us.


================
Comment at: libc/test/src/sys/random/linux/getrandom_test.cpp:49
+}
\ No newline at end of file

----------------
nit: please fix


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134665/new/

https://reviews.llvm.org/D134665



More information about the libc-commits mailing list