Work around memfd_create linker issues

This commit is contained in:
Nigel Tao committed 2019-02-02 17:09:14 +11:00
1 parent 54a112a130
commit 6729715c48
1 file changed
+9 -5
+9 -5
View File
@@ -55,16 +55,20 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/syscall.h>
#include <unistd.h> #include <unistd.h>
// We should be able to do: // We should be able to do:
// //
// #include <sys/memfd.h> // #include <sys/memfd.h>
// //
// but for some reason, this hits "No such file or directory" on Ubuntu 18.04 // to get the memfd_create function signature, but memfd_create is relatively
// (linux 4.15, glibc 2.27). Instead, we explicitly declare this function // recent. For some reason, this #include hits "No such file or directory" on
// signature, copy/pasted from "man memfd_create". // Ubuntu 18.04 (linux 4.15, glibc 2.27), and there's also been problems on
int memfd_create(const char* name, unsigned int flags); // Debian systems. Instead, we explicitly define our own memfd_create.
static int my_memfd_create(const char* name, unsigned int flags) {
return syscall(__NR_memfd_create, name, flags);
}
#define N (128 * 1024) #define N (128 * 1024)
@@ -74,7 +78,7 @@ void* make_ring_buffer() {
return NULL; return NULL;
} }
int memfd = memfd_create("ring", 0); int memfd = my_memfd_create("ring", 0);
if (memfd == -1) { if (memfd == -1) {
return NULL; return NULL;
} }