Skip to content

Commit d41d013

Browse files
yannhamclaude
andcommitted
fix(otel-process-ctx): use raw syscall for memfd_create to support old glibc
libc::memfd_create requires glibc >= 2.27, causing a link error on CentOS 7 (glibc 2.17). Use libc::syscall(SYS_memfd_create, ...) instead, which bypasses the glibc wrapper and works with any glibc version, matching the previous rustix behavior. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 60d6541 commit d41d013

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

libdd-library-config/src/otel_process_ctx.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,13 @@ pub mod linux {
340340

341341
/// Creates a `memfd` file descriptor with the given name and flags.
342342
fn try_memfd(name: &CStr, flags: libc::c_uint) -> anyhow::Result<OwnedFd> {
343+
// We use the raw syscall rather than `libc::memfd_create` because the latter requires
344+
// glibc >= 2.27, while `syscall()` + `SYS_memfd_create` works with any glibc version.
343345
// Safety: name is a valid NUL-terminated string; flags are constant bit flags.
344-
let fd = unsafe { libc::memfd_create(name.as_ptr(), flags) };
346+
let fd = unsafe {
347+
libc::syscall(libc::SYS_memfd_create, name.as_ptr(), flags as libc::c_long)
348+
as libc::c_int
349+
};
345350
check_syscall_retval(fd, "memfd_create failed")?;
346351
// Safety: fd is a valid file descriptor just returned by memfd_create.
347352
Ok(unsafe { OwnedFd::from_raw_fd(fd) })

0 commit comments

Comments
 (0)