File tree Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
1010 ([ #1804 ] ( https://github.com/nix-rust/nix/pull/1804 ) )
1111- Added ` line_discipline ` field to ` Termios ` on Linux, Android and Haiku
1212 ([ #1805 ] ( https://github.com/nix-rust/nix/pull/1805 ) )
13+ - Expose the memfd module on FreeBSD (memfd was added in FreeBSD 13)
14+ ([ #1808 ] ( https://github.com/nix-rust/nix/pull/1808 ) )
1315
1416### Changed
1517
Original file line number Diff line number Diff line change 11//! Interfaces for managing memory-backed files.
22
33use std:: os:: unix:: io:: RawFd ;
4+ use cfg_if:: cfg_if;
5+
46use crate :: Result ;
57use crate :: errno:: Errno ;
68use std:: ffi:: CStr ;
@@ -40,7 +42,22 @@ libc_bitflags!(
4042/// [`memfd_create(2)`]: https://man7.org/linux/man-pages/man2/memfd_create.2.html
4143pub fn memfd_create ( name : & CStr , flags : MemFdCreateFlag ) -> Result < RawFd > {
4244 let res = unsafe {
43- libc:: syscall ( libc:: SYS_memfd_create , name. as_ptr ( ) , flags. bits ( ) )
45+ cfg_if ! {
46+ if #[ cfg( all(
47+ // Android does not have a memfd_create symbol
48+ not( target_os = "android" ) ,
49+ any(
50+ target_os = "freebsd" ,
51+ // If the OS is Linux, gnu and musl expose a memfd_create symbol but not uclibc
52+ target_env = "gnu" ,
53+ target_env = "musl" ,
54+ ) ) ) ]
55+ {
56+ libc:: memfd_create( name. as_ptr( ) , flags. bits( ) )
57+ } else {
58+ libc:: syscall( libc:: SYS_memfd_create , name. as_ptr( ) , flags. bits( ) )
59+ }
60+ }
4461 } ;
4562
4663 Errno :: result ( res) . map ( |r| r as RawFd )
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ feature! {
5050#[ macro_use]
5151pub mod ioctl;
5252
53- #[ cfg( any( target_os = "android" , target_os = "linux" ) ) ]
53+ #[ cfg( any( target_os = "android" , target_os = "freebsd" , target_os = " linux") ) ]
5454feature ! {
5555 #![ feature = "fs" ]
5656 pub mod memfd;
You can’t perform that action at this time.
0 commit comments