File tree 3 files changed +21
-2
lines changed 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/).
10
10
([ #1804 ] ( https://github.com/nix-rust/nix/pull/1804 ) )
11
11
- Added ` line_discipline ` field to ` Termios ` on Linux, Android and Haiku
12
12
([ #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 ) )
13
15
14
16
### Changed
15
17
Original file line number Diff line number Diff line change 1
1
//! Interfaces for managing memory-backed files.
2
2
3
3
use std:: os:: unix:: io:: RawFd ;
4
+ use cfg_if:: cfg_if;
5
+
4
6
use crate :: Result ;
5
7
use crate :: errno:: Errno ;
6
8
use std:: ffi:: CStr ;
@@ -40,7 +42,22 @@ libc_bitflags!(
40
42
/// [`memfd_create(2)`]: https://man7.org/linux/man-pages/man2/memfd_create.2.html
41
43
pub fn memfd_create ( name : & CStr , flags : MemFdCreateFlag ) -> Result < RawFd > {
42
44
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
+ }
44
61
} ;
45
62
46
63
Errno :: result ( res) . map ( |r| r as RawFd )
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ feature! {
50
50
#[ macro_use]
51
51
pub mod ioctl;
52
52
53
- #[ cfg( any( target_os = "android" , target_os = "linux" ) ) ]
53
+ #[ cfg( any( target_os = "android" , target_os = "freebsd" , target_os = " linux") ) ]
54
54
feature ! {
55
55
#![ feature = "fs" ]
56
56
pub mod memfd;
You can’t perform that action at this time.
0 commit comments