From 599dee1c204ab59e16e29a783601ffabf0aa7cd9 Mon Sep 17 00:00:00 2001 From: Robert Swiecki Date: Wed, 10 Jan 2018 02:21:58 +0100 Subject: Different way of pasing data to persistent process, now as a memory-file-descriptor and not through the socket --- libhfcommon/files.c | 22 +++++++++++++++++----- libhfcommon/util.c | 16 ---------------- libhfcommon/util.h | 2 -- 3 files changed, 17 insertions(+), 23 deletions(-) (limited to 'libhfcommon') diff --git a/libhfcommon/files.c b/libhfcommon/files.c index b9bd460a..b27bbfe6 100644 --- a/libhfcommon/files.c +++ b/libhfcommon/files.c @@ -358,17 +358,29 @@ uint8_t* files_mapFileShared(const char* fileName, off_t* fileSz, int* fd) { void* files_mapSharedMem(size_t sz, int* fd, const char* dir) { *fd = -1; -#if defined(_HF_ARCH_LINUX) && defined(__NR_memfd_create) -#if !defined(MFD_CLOEXEC) /* It's not defined as we didn't include sys/memfd.h, but it's \ - present with some Linux distros only */ + +#if defined(_HF_ARCH_LINUX) + +#if !defined(MFD_CLOEXEC) /* sys/memfd.h is not always present */ #define MFD_CLOEXEC 0x0001U #endif /* !defined(MFD_CLOEXEC) */ + +#if !defined(__NR_memfd_create) +#if defined(__x86_64__) +#define __NR_memfd_create 319 +#endif /* defined(__x86_64__) */ +#endif /* !defined(__NR_memfd_create) */ + +#if defined(__NR_memfd_create) *fd = syscall(__NR_memfd_create, "honggfuzz", (uintptr_t)MFD_CLOEXEC); -#endif /* defined(_HF_ARCH_LINUX) && defined(__NR_memfd_create) */ +#endif /* defined__NR_memfd_create) */ + +#endif /* defined(_HF_ARCH_LINUX) */ + if (*fd == -1) { char template[PATH_MAX]; snprintf(template, sizeof(template), "%s/hfuzz.XXXXXX", dir); - if ((*fd = mkstemp(template)) == -1) { + if ((*fd = mkostemp(template, O_CLOEXEC)) == -1) { PLOG_W("mkstemp('%s')", template); return MAP_FAILED; } diff --git a/libhfcommon/util.c b/libhfcommon/util.c index 5745a4b2..046eb430 100644 --- a/libhfcommon/util.c +++ b/libhfcommon/util.c @@ -199,22 +199,6 @@ void util_nullifyStdio(void) { } } -bool util_redirectStdin(const char* inputFile) { - int fd = open(inputFile, O_RDONLY); - - if (fd == -1) { - PLOG_W("Couldn't open '%s'", inputFile); - return false; - } - - dup2(fd, 0); - if (fd != 0) { - close(fd); - } - - return true; -} - /* * This is not a cryptographically secure hash */ diff --git a/libhfcommon/util.h b/libhfcommon/util.h index 26fe6e66..bd3bd12d 100644 --- a/libhfcommon/util.h +++ b/libhfcommon/util.h @@ -97,8 +97,6 @@ extern void util_getLocalTime(const char* fmt, char* buf, size_t len, time_t tm) extern void util_nullifyStdio(void); -extern bool util_redirectStdin(const char* inputFile); - extern uint64_t util_hash(const char* buf, size_t len); extern int64_t util_timeNowMillis(void); -- cgit v1.2.3