@@ -11,7 +11,7 @@ use bincode;
1111use fnv:: FnvHasher ;
1212use libc:: { self , MAP_FAILED , MAP_SHARED , PROT_READ , PROT_WRITE , SOCK_SEQPACKET , SOL_SOCKET } ;
1313use libc:: { SO_LINGER , S_IFMT , S_IFSOCK , c_char, c_int, c_void, getsockopt} ;
14- use libc:: { iovec, mode_t, msghdr, off_t , recvmsg, sendmsg} ;
14+ use libc:: { iovec, mode_t, msghdr, recvmsg, sendmsg} ;
1515use libc:: { setsockopt, size_t, sockaddr, sockaddr_un, socketpair, socklen_t, sa_family_t} ;
1616use std:: cell:: Cell ;
1717use std:: cmp;
@@ -32,6 +32,7 @@ use std::thread;
3232use mio:: unix:: EventedFd ;
3333use mio:: { Poll , Token , Events , Ready , PollOpt } ;
3434use tempfile:: { Builder , TempDir } ;
35+ use shmemfdrs:: create_shmem;
3536
3637const MAX_FDS_IN_CMSG : u32 = 64 ;
3738
@@ -953,31 +954,6 @@ fn recv(fd: c_int, blocking_mode: BlockingMode)
953954 Ok ( ( main_data_buffer, channels, shared_memory_regions) )
954955}
955956
956- #[ cfg( not( all( target_os="linux" , feature="memfd" ) ) ) ]
957- fn create_shmem ( name : CString , length : usize ) -> c_int {
958- unsafe {
959- // NB: the FreeBSD man page for shm_unlink states that it requires
960- // write permissions, but testing shows that read-write is required.
961- let fd = libc:: shm_open ( name. as_ptr ( ) ,
962- libc:: O_CREAT | libc:: O_RDWR | libc:: O_EXCL ,
963- 0o600 ) ;
964- assert ! ( fd >= 0 ) ;
965- assert ! ( libc:: shm_unlink( name. as_ptr( ) ) == 0 ) ;
966- assert ! ( libc:: ftruncate( fd, length as off_t) == 0 ) ;
967- fd
968- }
969- }
970-
971- #[ cfg( all( feature="memfd" , target_os="linux" ) ) ]
972- fn create_shmem ( name : CString , length : usize ) -> c_int {
973- unsafe {
974- let fd = memfd_create ( name. as_ptr ( ) , 0 ) ;
975- assert ! ( fd >= 0 ) ;
976- assert ! ( libc:: ftruncate( fd, length as off_t) == 0 ) ;
977- fd
978- }
979- }
980-
981957struct UnixCmsg {
982958 cmsg_buffer : * mut cmsghdr ,
983959 msghdr : msghdr ,
@@ -1053,11 +1029,6 @@ fn is_socket(fd: c_int) -> bool {
10531029
10541030// FFI stuff follows:
10551031
1056- #[ cfg( all( feature="memfd" , target_os="linux" ) ) ]
1057- unsafe fn memfd_create ( name : * const c_char , flags : usize ) -> c_int {
1058- syscall ! ( MEMFD_CREATE , name, flags) as c_int
1059- }
1060-
10611032#[ allow( non_snake_case) ]
10621033fn CMSG_LEN ( length : size_t ) -> size_t {
10631034 CMSG_ALIGN ( mem:: size_of :: < cmsghdr > ( ) ) + length
0 commit comments