Update to ONDK r29.2

This commit is contained in:
topjohnwu
2025-08-28 16:15:59 -07:00
parent c4e2985677
commit 484d53ef7e
17 changed files with 93 additions and 76 deletions

View File

@@ -12,7 +12,6 @@ LOCAL_C_INCLUDES := \
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)
LOCAL_EXPORT_STATIC_LIBRARIES := libcxx
LOCAL_STATIC_LIBRARIES := libcxx
LOCAL_CFLAGS := -DRUST_CXX_NO_EXCEPTIONS
LOCAL_SRC_FILES := \
base.cpp \
base-rs.cpp \

View File

@@ -56,7 +56,7 @@ pub mod buf {
}
#[inline(always)]
pub fn wrap(buf: &mut [u8]) -> Utf8CStrBufRef {
pub fn wrap(buf: &mut [u8]) -> Utf8CStrBufRef<'_> {
Utf8CStrBufRef::from(buf)
}

View File

@@ -110,11 +110,10 @@ pub(crate) unsafe fn readlinkat(
#[unsafe(export_name = "cp_afc")]
unsafe extern "C" fn cp_afc_for_cxx(src: *const c_char, dest: *const c_char) -> bool {
unsafe {
if let Ok(src) = Utf8CStr::from_ptr(src) {
if let Ok(dest) = Utf8CStr::from_ptr(dest) {
if let Ok(src) = Utf8CStr::from_ptr(src)
&& let Ok(dest) = Utf8CStr::from_ptr(dest) {
return src.copy_to(dest).log_cxx().is_ok();
}
}
false
}
}
@@ -122,11 +121,10 @@ unsafe extern "C" fn cp_afc_for_cxx(src: *const c_char, dest: *const c_char) ->
#[unsafe(export_name = "mv_path")]
unsafe extern "C" fn mv_path_for_cxx(src: *const c_char, dest: *const c_char) -> bool {
unsafe {
if let Ok(src) = Utf8CStr::from_ptr(src) {
if let Ok(dest) = Utf8CStr::from_ptr(dest) {
if let Ok(src) = Utf8CStr::from_ptr(src)
&& let Ok(dest) = Utf8CStr::from_ptr(dest) {
return src.move_to(dest).log_cxx().is_ok();
}
}
false
}
}
@@ -134,11 +132,10 @@ unsafe extern "C" fn mv_path_for_cxx(src: *const c_char, dest: *const c_char) ->
#[unsafe(export_name = "link_path")]
unsafe extern "C" fn link_path_for_cxx(src: *const c_char, dest: *const c_char) -> bool {
unsafe {
if let Ok(src) = Utf8CStr::from_ptr(src) {
if let Ok(dest) = Utf8CStr::from_ptr(dest) {
if let Ok(src) = Utf8CStr::from_ptr(src)
&& let Ok(dest) = Utf8CStr::from_ptr(dest) {
return src.link_to(dest).log_cxx().is_ok();
}
}
false
}
}
@@ -146,11 +143,10 @@ unsafe extern "C" fn link_path_for_cxx(src: *const c_char, dest: *const c_char)
#[unsafe(export_name = "clone_attr")]
unsafe extern "C" fn clone_attr_for_cxx(src: *const c_char, dest: *const c_char) -> bool {
unsafe {
if let Ok(src) = Utf8CStr::from_ptr(src) {
if let Ok(dest) = Utf8CStr::from_ptr(dest) {
if let Ok(src) = Utf8CStr::from_ptr(src)
&& let Ok(dest) = Utf8CStr::from_ptr(dest) {
return clone_attr(src, dest).log_cxx().is_ok();
}
}
false
}
}

View File

@@ -63,16 +63,16 @@ impl DirEntry<'_> {
self.d_type == libc::DT_SOCK
}
pub fn unlink(&self) -> OsResult<()> {
pub fn unlink(&self) -> OsResult<'_, ()> {
let flag = if self.is_dir() { libc::AT_REMOVEDIR } else { 0 };
self.dir.unlink_at(self.name(), flag)
}
pub fn read_link(&self, buf: &mut dyn Utf8CStrBuf) -> OsResult<()> {
pub fn read_link(&self, buf: &mut dyn Utf8CStrBuf) -> OsResult<'_, ()> {
self.dir.read_link_at(self.name(), buf)
}
pub fn open_as_dir(&self) -> OsResult<Directory> {
pub fn open_as_dir(&self) -> OsResult<'_, Directory> {
if !self.is_dir() {
return Err(OsError::with_os_error(
libc::ENOTDIR,
@@ -84,7 +84,7 @@ impl DirEntry<'_> {
self.dir.open_as_dir_at(self.name())
}
pub fn open_as_file(&self, flags: i32) -> OsResult<File> {
pub fn open_as_file(&self, flags: i32) -> OsResult<'_, File> {
if self.is_dir() {
return Err(OsError::with_os_error(
libc::EISDIR,
@@ -141,7 +141,7 @@ pub enum WalkResult {
}
impl Directory {
fn borrow(&self) -> BorrowedDirectory {
fn borrow(&self) -> BorrowedDirectory<'_> {
BorrowedDirectory {
inner: self.inner,
phantom: PhantomData,
@@ -164,13 +164,13 @@ impl Directory {
}
impl Directory {
pub fn open(path: &Utf8CStr) -> OsResult<Directory> {
pub fn open(path: &Utf8CStr) -> OsResult<'_, Directory> {
let dirp = unsafe { libc::opendir(path.as_ptr()) };
let dirp = dirp.as_os_result("opendir", Some(path), None)?;
Ok(Directory { inner: dirp })
}
pub fn read(&mut self) -> OsResult<'static, Option<DirEntry>> {
pub fn read(&mut self) -> OsResult<'static, Option<DirEntry<'_>>> {
*errno() = 0;
let e = unsafe { libc::readdir(self.inner.as_ptr()) };
if e.is_null() {
@@ -481,7 +481,7 @@ impl AsRawFd for Directory {
}
impl AsFd for Directory {
fn as_fd(&self) -> BorrowedFd {
fn as_fd(&self) -> BorrowedFd<'_> {
unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) }
}
}

View File

@@ -139,7 +139,7 @@ impl FileOrStd {
}
}
fn open_fd(path: &Utf8CStr, flags: i32, mode: mode_t) -> OsResult<OwnedFd> {
fn open_fd(path: &Utf8CStr, flags: i32, mode: mode_t) -> OsResult<'_, OwnedFd> {
unsafe {
let fd = libc::open(path.as_ptr(), flags, mode as c_uint).as_os_result(
"open",
@@ -224,11 +224,11 @@ impl Utf8CStr {
unsafe { mem::transmute(self) }
}
pub fn open(&self, flags: i32) -> OsResult<File> {
pub fn open(&self, flags: i32) -> OsResult<'_, File> {
Ok(File::from(open_fd(self, flags, 0)?))
}
pub fn create(&self, flags: i32, mode: mode_t) -> OsResult<File> {
pub fn create(&self, flags: i32, mode: mode_t) -> OsResult<'_, File> {
Ok(File::from(open_fd(self, O_CREAT | flags, mode)?))
}
@@ -249,7 +249,7 @@ impl Utf8CStr {
}
}
pub fn remove(&self) -> OsResult<()> {
pub fn remove(&self) -> OsResult<'_, ()> {
unsafe { libc::remove(self.as_ptr()).check_os_err("remove", Some(self), None) }
}
@@ -263,7 +263,7 @@ impl Utf8CStr {
}
#[allow(clippy::unnecessary_cast)]
pub fn read_link(&self, buf: &mut dyn Utf8CStrBuf) -> OsResult<()> {
pub fn read_link(&self, buf: &mut dyn Utf8CStrBuf) -> OsResult<'_, ()> {
buf.clear();
unsafe {
let r = libc::readlink(self.as_ptr(), buf.as_mut_ptr(), buf.capacity() - 1)
@@ -274,7 +274,7 @@ impl Utf8CStr {
Ok(())
}
pub fn mkdir(&self, mode: mode_t) -> OsResult<()> {
pub fn mkdir(&self, mode: mode_t) -> OsResult<'_, ()> {
unsafe {
if libc::mkdir(self.as_ptr(), mode) < 0 {
if *errno() == EEXIST {
@@ -317,7 +317,7 @@ impl Utf8CStr {
}
// Inspired by https://android.googlesource.com/platform/bionic/+/master/libc/bionic/realpath.cpp
pub fn realpath(&self, buf: &mut dyn Utf8CStrBuf) -> OsResult<()> {
pub fn realpath(&self, buf: &mut dyn Utf8CStrBuf) -> OsResult<'_, ()> {
let fd = self.open(O_PATH | O_CLOEXEC)?;
let mut st1: libc::stat;
let mut st2: libc::stat;
@@ -341,7 +341,7 @@ impl Utf8CStr {
Ok(())
}
pub fn get_attr(&self) -> OsResult<FileAttr> {
pub fn get_attr(&self) -> OsResult<'_, FileAttr> {
let mut attr = FileAttr::new();
unsafe {
libc::lstat(self.as_ptr(), &mut attr.st).check_os_err("lstat", Some(self), None)?;
@@ -375,7 +375,7 @@ impl Utf8CStr {
Ok(())
}
pub fn get_secontext(&self, con: &mut dyn Utf8CStrBuf) -> OsResult<()> {
pub fn get_secontext(&self, con: &mut dyn Utf8CStrBuf) -> OsResult<'_, ()> {
unsafe {
let sz = libc::lgetxattr(
self.as_ptr(),
@@ -500,7 +500,7 @@ impl Utf8CStr {
}
}
pub fn mkfifo(&self, mode: mode_t) -> OsResult<()> {
pub fn mkfifo(&self, mode: mode_t) -> OsResult<'_, ()> {
unsafe { libc::mkfifo(self.as_ptr(), mode).check_os_err("mkfifo", Some(self), None) }
}
}
@@ -510,7 +510,7 @@ impl FsPathFollow {
unsafe { libc::access(self.as_ptr(), F_OK) == 0 }
}
pub fn get_attr(&self) -> OsResult<FileAttr> {
pub fn get_attr(&self) -> OsResult<'_, FileAttr> {
let mut attr = FileAttr::new();
unsafe {
libc::stat(self.as_ptr(), &mut attr.st).check_os_err("stat", Some(self), None)?;
@@ -542,7 +542,7 @@ impl FsPathFollow {
Ok(())
}
pub fn get_secontext(&self, con: &mut dyn Utf8CStrBuf) -> OsResult<()> {
pub fn get_secontext(&self, con: &mut dyn Utf8CStrBuf) -> OsResult<'_, ()> {
unsafe {
let sz = libc::getxattr(
self.as_ptr(),
@@ -640,7 +640,7 @@ pub fn fd_get_attr(fd: RawFd) -> OsResult<'static, FileAttr> {
Ok(attr)
}
pub fn fd_set_attr(fd: RawFd, attr: &FileAttr) -> OsResult<()> {
pub fn fd_set_attr(fd: RawFd, attr: &FileAttr) -> OsResult<'_, ()> {
unsafe {
libc::fchmod(fd, (attr.st.st_mode & 0o777).as_()).check_os_err("fchmod", None, None)?;
libc::fchown(fd, attr.st.st_uid, attr.st.st_gid).check_os_err("fchown", None, None)?;
@@ -672,7 +672,7 @@ pub fn fd_get_secontext(fd: RawFd, con: &mut dyn Utf8CStrBuf) -> OsResult<'stati
Ok(())
}
pub fn fd_set_secontext(fd: RawFd, con: &Utf8CStr) -> OsResult<()> {
pub fn fd_set_secontext(fd: RawFd, con: &Utf8CStr) -> OsResult<'_, ()> {
unsafe {
libc::fsetxattr(
fd,
@@ -698,11 +698,11 @@ pub fn fclone_attr(a: RawFd, b: RawFd) -> OsResult<'static, ()> {
pub struct MappedFile(&'static mut [u8]);
impl MappedFile {
pub fn open(path: &Utf8CStr) -> OsResult<MappedFile> {
pub fn open(path: &Utf8CStr) -> OsResult<'_, MappedFile> {
Ok(MappedFile(map_file(path, false)?))
}
pub fn open_rw(path: &Utf8CStr) -> OsResult<MappedFile> {
pub fn open_rw(path: &Utf8CStr) -> OsResult<'_, MappedFile> {
Ok(MappedFile(map_file(path, true)?))
}
@@ -745,7 +745,7 @@ unsafe extern "C" {
}
// We mark the returned slice static because it is valid until explicitly unmapped
pub(crate) fn map_file(path: &Utf8CStr, rw: bool) -> OsResult<&'static mut [u8]> {
pub(crate) fn map_file(path: &Utf8CStr, rw: bool) -> OsResult<'_, &'static mut [u8]> {
unsafe { map_file_at(BorrowedFd::borrow_raw(libc::AT_FDCWD), path, rw) }
}

View File

@@ -17,7 +17,7 @@ impl Utf8CStr {
}
}
pub fn remount_mount_point_flags(&self, flags: c_ulong) -> OsResult<()> {
pub fn remount_mount_point_flags(&self, flags: c_ulong) -> OsResult<'_, ()> {
unsafe {
libc::mount(
ptr::null(),
@@ -30,7 +30,7 @@ impl Utf8CStr {
}
}
pub fn remount_mount_flags(&self, flags: c_ulong) -> OsResult<()> {
pub fn remount_mount_flags(&self, flags: c_ulong) -> OsResult<'_, ()> {
unsafe {
libc::mount(
ptr::null(),
@@ -43,7 +43,7 @@ impl Utf8CStr {
}
}
pub fn remount_with_data(&self, data: &Utf8CStr) -> OsResult<()> {
pub fn remount_with_data(&self, data: &Utf8CStr) -> OsResult<'_, ()> {
unsafe {
libc::mount(
ptr::null(),
@@ -69,13 +69,13 @@ impl Utf8CStr {
}
}
pub fn unmount(&self) -> OsResult<()> {
pub fn unmount(&self) -> OsResult<'_, ()> {
unsafe {
libc::umount2(self.as_ptr(), libc::MNT_DETACH).check_os_err("unmount", Some(self), None)
}
}
pub fn set_mount_private(&self, recursive: bool) -> OsResult<()> {
pub fn set_mount_private(&self, recursive: bool) -> OsResult<'_, ()> {
let flag = if recursive { libc::MS_REC } else { 0 };
unsafe {
libc::mount(