memory_manager: use MFD_CLOEXEC flag when creating memory fd

Until there is a need for sharing the memory fd with a child process, we
should err on the safe side to close it on exec.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
Wei Liu 2022-10-26 16:22:34 +00:00 committed by Sebastien Boeuf
parent 0cd6d96874
commit b99b2bc990

View File

@ -1252,9 +1252,8 @@ impl MemoryManager {
}
}
None => {
let fd = Self::memfd_create(
&ffi::CString::new("ch_ram").unwrap(),
if hugepages {
let flags = libc::MFD_CLOEXEC
| if hugepages {
libc::MFD_HUGETLB
| if let Some(hugepage_size) = hugepage_size {
/*
@ -1274,9 +1273,9 @@ impl MemoryManager {
}
} else {
0
},
)
.map_err(Error::SharedFileCreate)?;
};
let fd = Self::memfd_create(&ffi::CString::new("ch_ram").unwrap(), flags)
.map_err(Error::SharedFileCreate)?;
let f = unsafe { File::from_raw_fd(fd) };
f.set_len(size as u64).map_err(Error::SharedFileSetLen)?;