From 8e74ebb5165a2e0acb66fddb59284d437adc4bbe Mon Sep 17 00:00:00 2001 From: Xu Shaohua Date: Tue, 30 Jul 2024 10:18:12 +0800 Subject: [PATCH] calls: Update params in openat2() --- src/calls/getfsstat.rs | 4 +++- src/calls/getvfsstat.rs | 4 +++- src/calls/{openat2_linux.rs => openat2.rs} | 8 +++----- src/platform/linux-aarch64/call.rs | 8 +++----- src/platform/linux-arm/call.rs | 8 +++----- src/platform/linux-mips/call.rs | 8 +++----- src/platform/linux-mips64/call.rs | 8 +++----- src/platform/linux-ppc64/call.rs | 8 +++----- src/platform/linux-riscv64/call.rs | 8 +++----- src/platform/linux-s390x/call.rs | 8 +++----- src/platform/linux-x86/call.rs | 8 +++----- src/platform/linux-x86_64/call.rs | 8 +++----- 12 files changed, 36 insertions(+), 52 deletions(-) rename src/calls/{openat2_linux.rs => openat2.rs} (71%) diff --git a/src/calls/getfsstat.rs b/src/calls/getfsstat.rs index 2d85ec0c..5bc45aef 100644 --- a/src/calls/getfsstat.rs +++ b/src/calls/getfsstat.rs @@ -5,7 +5,9 @@ pub unsafe fn getfsstat(buf: Option<&mut [statfs_t]>, mode: i32) -> Result()); - let buf_ptr = buf.map_or(0, |buf| buf.as_mut_ptr() as usize); + let buf_ptr = buf.map_or(core::mem::null_mut::() as usize, |buf| { + buf.as_mut_ptr() as usize + }); let mode = mode as usize; syscall3(SYS_GETFSSTAT, buf_ptr, buf_size, mode).map(|val| val as i32) } diff --git a/src/calls/getvfsstat.rs b/src/calls/getvfsstat.rs index e442f3ba..cd150270 100644 --- a/src/calls/getvfsstat.rs +++ b/src/calls/getvfsstat.rs @@ -5,7 +5,9 @@ pub unsafe fn getvfsstat(buf: Option<&mut [statvfs_t]>, mode: i32) -> Result()); - let buf_ptr = buf.map_or(0, |buf| buf.as_mut_ptr() as usize); + let buf_ptr = buf.map_or(core::mem::null_mut::() as usize, |buf| { + buf.as_mut_ptr() as usize + }); let mode = mode as usize; syscall3(SYS_GETVFSSTAT, buf_ptr, buf_size, mode).map(|val| val as i32) } diff --git a/src/calls/openat2_linux.rs b/src/calls/openat2.rs similarity index 71% rename from src/calls/openat2_linux.rs rename to src/calls/openat2.rs index 1479c6a5..de500be3 100644 --- a/src/calls/openat2_linux.rs +++ b/src/calls/openat2.rs @@ -3,14 +3,12 @@ /// # Examples /// /// ``` -/// use core::mem::size_of; /// let path = "/etc/passwd"; /// let mut how = nc::open_how_t{ /// flags: nc::O_RDONLY as u64, /// ..nc::open_how_t::default() /// }; -/// let how_size = size_of::(); -/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how, how_size) }; +/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how) }; /// assert!(ret.is_ok()); /// let fd = ret.unwrap(); /// let ret = unsafe { nc::close(fd) }; @@ -20,11 +18,11 @@ pub unsafe fn openat2>( dirfd: i32, pathname: P, how: &mut open_how_t, - size: size_t, ) -> Result { let dirfd = dirfd as usize; let pathname = CString::new(pathname.as_ref()); let pathname_ptr = pathname.as_ptr() as usize; let how_ptr = how as *mut open_how_t as usize; - syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, size).map(|ret| ret as i32) + let how_size = core::mem::size_of::(); + syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, how_size).map(|ret| ret as i32) } diff --git a/src/platform/linux-aarch64/call.rs b/src/platform/linux-aarch64/call.rs index c7ba47df..b32dde0f 100644 --- a/src/platform/linux-aarch64/call.rs +++ b/src/platform/linux-aarch64/call.rs @@ -3959,14 +3959,12 @@ pub unsafe fn openat>( /// # Examples /// /// ``` -/// use core::mem::size_of; /// let path = "/etc/passwd"; /// let mut how = nc::open_how_t{ /// flags: nc::O_RDONLY as u64, /// ..nc::open_how_t::default() /// }; -/// let how_size = size_of::(); -/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how, how_size) }; +/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how) }; /// assert!(ret.is_ok()); /// let fd = ret.unwrap(); /// let ret = unsafe { nc::close(fd) }; @@ -3976,13 +3974,13 @@ pub unsafe fn openat2>( dirfd: i32, pathname: P, how: &mut open_how_t, - size: size_t, ) -> Result { let dirfd = dirfd as usize; let pathname = CString::new(pathname.as_ref()); let pathname_ptr = pathname.as_ptr() as usize; let how_ptr = how as *mut open_how_t as usize; - syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, size).map(|ret| ret as i32) + let how_size = core::mem::size_of::(); + syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, how_size).map(|ret| ret as i32) } /// Obtain handle for an open file diff --git a/src/platform/linux-arm/call.rs b/src/platform/linux-arm/call.rs index 66cd96fd..d3097167 100644 --- a/src/platform/linux-arm/call.rs +++ b/src/platform/linux-arm/call.rs @@ -4534,14 +4534,12 @@ pub unsafe fn openat>( /// # Examples /// /// ``` -/// use core::mem::size_of; /// let path = "/etc/passwd"; /// let mut how = nc::open_how_t{ /// flags: nc::O_RDONLY as u64, /// ..nc::open_how_t::default() /// }; -/// let how_size = size_of::(); -/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how, how_size) }; +/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how) }; /// assert!(ret.is_ok()); /// let fd = ret.unwrap(); /// let ret = unsafe { nc::close(fd) }; @@ -4551,13 +4549,13 @@ pub unsafe fn openat2>( dirfd: i32, pathname: P, how: &mut open_how_t, - size: size_t, ) -> Result { let dirfd = dirfd as usize; let pathname = CString::new(pathname.as_ref()); let pathname_ptr = pathname.as_ptr() as usize; let how_ptr = how as *mut open_how_t as usize; - syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, size).map(|ret| ret as i32) + let how_size = core::mem::size_of::(); + syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, how_size).map(|ret| ret as i32) } /// Obtain handle for an open file diff --git a/src/platform/linux-mips/call.rs b/src/platform/linux-mips/call.rs index 23586e1c..6afed569 100644 --- a/src/platform/linux-mips/call.rs +++ b/src/platform/linux-mips/call.rs @@ -4699,14 +4699,12 @@ pub unsafe fn openat>( /// # Examples /// /// ``` -/// use core::mem::size_of; /// let path = "/etc/passwd"; /// let mut how = nc::open_how_t{ /// flags: nc::O_RDONLY as u64, /// ..nc::open_how_t::default() /// }; -/// let how_size = size_of::(); -/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how, how_size) }; +/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how) }; /// assert!(ret.is_ok()); /// let fd = ret.unwrap(); /// let ret = unsafe { nc::close(fd) }; @@ -4716,13 +4714,13 @@ pub unsafe fn openat2>( dirfd: i32, pathname: P, how: &mut open_how_t, - size: size_t, ) -> Result { let dirfd = dirfd as usize; let pathname = CString::new(pathname.as_ref()); let pathname_ptr = pathname.as_ptr() as usize; let how_ptr = how as *mut open_how_t as usize; - syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, size).map(|ret| ret as i32) + let how_size = core::mem::size_of::(); + syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, how_size).map(|ret| ret as i32) } /// Obtain handle for an open file diff --git a/src/platform/linux-mips64/call.rs b/src/platform/linux-mips64/call.rs index 05111a82..56d0e24b 100644 --- a/src/platform/linux-mips64/call.rs +++ b/src/platform/linux-mips64/call.rs @@ -4449,14 +4449,12 @@ pub unsafe fn openat>( /// # Examples /// /// ``` -/// use core::mem::size_of; /// let path = "/etc/passwd"; /// let mut how = nc::open_how_t{ /// flags: nc::O_RDONLY as u64, /// ..nc::open_how_t::default() /// }; -/// let how_size = size_of::(); -/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how, how_size) }; +/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how) }; /// assert!(ret.is_ok()); /// let fd = ret.unwrap(); /// let ret = unsafe { nc::close(fd) }; @@ -4466,13 +4464,13 @@ pub unsafe fn openat2>( dirfd: i32, pathname: P, how: &mut open_how_t, - size: size_t, ) -> Result { let dirfd = dirfd as usize; let pathname = CString::new(pathname.as_ref()); let pathname_ptr = pathname.as_ptr() as usize; let how_ptr = how as *mut open_how_t as usize; - syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, size).map(|ret| ret as i32) + let how_size = core::mem::size_of::(); + syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, how_size).map(|ret| ret as i32) } /// Obtain handle for an open file diff --git a/src/platform/linux-ppc64/call.rs b/src/platform/linux-ppc64/call.rs index 410d809c..2539190c 100644 --- a/src/platform/linux-ppc64/call.rs +++ b/src/platform/linux-ppc64/call.rs @@ -4570,14 +4570,12 @@ pub unsafe fn openat>( /// # Examples /// /// ``` -/// use core::mem::size_of; /// let path = "/etc/passwd"; /// let mut how = nc::open_how_t{ /// flags: nc::O_RDONLY as u64, /// ..nc::open_how_t::default() /// }; -/// let how_size = size_of::(); -/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how, how_size) }; +/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how) }; /// assert!(ret.is_ok()); /// let fd = ret.unwrap(); /// let ret = unsafe { nc::close(fd) }; @@ -4587,13 +4585,13 @@ pub unsafe fn openat2>( dirfd: i32, pathname: P, how: &mut open_how_t, - size: size_t, ) -> Result { let dirfd = dirfd as usize; let pathname = CString::new(pathname.as_ref()); let pathname_ptr = pathname.as_ptr() as usize; let how_ptr = how as *mut open_how_t as usize; - syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, size).map(|ret| ret as i32) + let how_size = core::mem::size_of::(); + syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, how_size).map(|ret| ret as i32) } /// Obtain handle for an open file diff --git a/src/platform/linux-riscv64/call.rs b/src/platform/linux-riscv64/call.rs index 297a5187..f5af4bfb 100644 --- a/src/platform/linux-riscv64/call.rs +++ b/src/platform/linux-riscv64/call.rs @@ -3959,14 +3959,12 @@ pub unsafe fn openat>( /// # Examples /// /// ``` -/// use core::mem::size_of; /// let path = "/etc/passwd"; /// let mut how = nc::open_how_t{ /// flags: nc::O_RDONLY as u64, /// ..nc::open_how_t::default() /// }; -/// let how_size = size_of::(); -/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how, how_size) }; +/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how) }; /// assert!(ret.is_ok()); /// let fd = ret.unwrap(); /// let ret = unsafe { nc::close(fd) }; @@ -3976,13 +3974,13 @@ pub unsafe fn openat2>( dirfd: i32, pathname: P, how: &mut open_how_t, - size: size_t, ) -> Result { let dirfd = dirfd as usize; let pathname = CString::new(pathname.as_ref()); let pathname_ptr = pathname.as_ptr() as usize; let how_ptr = how as *mut open_how_t as usize; - syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, size).map(|ret| ret as i32) + let how_size = core::mem::size_of::(); + syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, how_size).map(|ret| ret as i32) } /// Obtain handle for an open file diff --git a/src/platform/linux-s390x/call.rs b/src/platform/linux-s390x/call.rs index b99c4445..728d0bbc 100644 --- a/src/platform/linux-s390x/call.rs +++ b/src/platform/linux-s390x/call.rs @@ -4532,14 +4532,12 @@ pub unsafe fn openat>( /// # Examples /// /// ``` -/// use core::mem::size_of; /// let path = "/etc/passwd"; /// let mut how = nc::open_how_t{ /// flags: nc::O_RDONLY as u64, /// ..nc::open_how_t::default() /// }; -/// let how_size = size_of::(); -/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how, how_size) }; +/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how) }; /// assert!(ret.is_ok()); /// let fd = ret.unwrap(); /// let ret = unsafe { nc::close(fd) }; @@ -4549,13 +4547,13 @@ pub unsafe fn openat2>( dirfd: i32, pathname: P, how: &mut open_how_t, - size: size_t, ) -> Result { let dirfd = dirfd as usize; let pathname = CString::new(pathname.as_ref()); let pathname_ptr = pathname.as_ptr() as usize; let how_ptr = how as *mut open_how_t as usize; - syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, size).map(|ret| ret as i32) + let how_size = core::mem::size_of::(); + syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, how_size).map(|ret| ret as i32) } /// Obtain handle for an open file diff --git a/src/platform/linux-x86/call.rs b/src/platform/linux-x86/call.rs index d4372d81..09fcda34 100644 --- a/src/platform/linux-x86/call.rs +++ b/src/platform/linux-x86/call.rs @@ -4714,14 +4714,12 @@ pub unsafe fn openat>( /// # Examples /// /// ``` -/// use core::mem::size_of; /// let path = "/etc/passwd"; /// let mut how = nc::open_how_t{ /// flags: nc::O_RDONLY as u64, /// ..nc::open_how_t::default() /// }; -/// let how_size = size_of::(); -/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how, how_size) }; +/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how) }; /// assert!(ret.is_ok()); /// let fd = ret.unwrap(); /// let ret = unsafe { nc::close(fd) }; @@ -4731,13 +4729,13 @@ pub unsafe fn openat2>( dirfd: i32, pathname: P, how: &mut open_how_t, - size: size_t, ) -> Result { let dirfd = dirfd as usize; let pathname = CString::new(pathname.as_ref()); let pathname_ptr = pathname.as_ptr() as usize; let how_ptr = how as *mut open_how_t as usize; - syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, size).map(|ret| ret as i32) + let how_size = core::mem::size_of::(); + syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, how_size).map(|ret| ret as i32) } /// Obtain handle for an open file diff --git a/src/platform/linux-x86_64/call.rs b/src/platform/linux-x86_64/call.rs index b0107709..18ed0d21 100644 --- a/src/platform/linux-x86_64/call.rs +++ b/src/platform/linux-x86_64/call.rs @@ -4497,14 +4497,12 @@ pub unsafe fn openat>( /// # Examples /// /// ``` -/// use core::mem::size_of; /// let path = "/etc/passwd"; /// let mut how = nc::open_how_t{ /// flags: nc::O_RDONLY as u64, /// ..nc::open_how_t::default() /// }; -/// let how_size = size_of::(); -/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how, how_size) }; +/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how) }; /// assert!(ret.is_ok()); /// let fd = ret.unwrap(); /// let ret = unsafe { nc::close(fd) }; @@ -4514,13 +4512,13 @@ pub unsafe fn openat2>( dirfd: i32, pathname: P, how: &mut open_how_t, - size: size_t, ) -> Result { let dirfd = dirfd as usize; let pathname = CString::new(pathname.as_ref()); let pathname_ptr = pathname.as_ptr() as usize; let how_ptr = how as *mut open_how_t as usize; - syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, size).map(|ret| ret as i32) + let how_size = core::mem::size_of::(); + syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, how_size).map(|ret| ret as i32) } /// Obtain handle for an open file