Skip to content

Commit ed09ee7

Browse files
jbachorikclaude
andcommitted
Fix memfd_create build failure on CentOS 7 / glibc < 2.27
Add #ifndef guards for MFD_CLOEXEC and MFD_ALLOW_SEALING, and a syscall-based memfd_create fallback for systems without the libc wrapper. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
1 parent 416d62c commit ed09ee7

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

ddprof-lib/src/main/cpp/otel_process_ctx.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ static const otel_process_ctx_data empty_data = {
6363
#include <string.h>
6464
#include <sys/mman.h>
6565
#include <sys/prctl.h>
66+
#include <sys/syscall.h>
6667
#include <time.h>
6768
#include <unistd.h>
6869

@@ -75,10 +76,23 @@ static const otel_process_ctx_data empty_data = {
7576
#define PR_SET_VMA_ANON_NAME 0
7677
#endif
7778

79+
#ifndef MFD_CLOEXEC
80+
#define MFD_CLOEXEC 1U
81+
#endif
82+
#ifndef MFD_ALLOW_SEALING
83+
#define MFD_ALLOW_SEALING 2U
84+
#endif
7885
#ifndef MFD_NOEXEC_SEAL
7986
#define MFD_NOEXEC_SEAL 8U
8087
#endif
8188

89+
// memfd_create(2) libc wrapper was added in glibc 2.27; provide a syscall fallback for older systems (e.g. CentOS 7 / glibc 2.17)
90+
#if defined(__NR_memfd_create) && defined(__GLIBC__) && (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 27))
91+
static inline int memfd_create(const char *name, unsigned int flags) {
92+
return (int) syscall(__NR_memfd_create, name, flags);
93+
}
94+
#endif
95+
8296
/**
8397
* The process context data that's written into the published anonymous mapping.
8498
*

0 commit comments

Comments
 (0)