Skip to content

Commit 3f4181a

Browse files
committed
iOS: open file on aarch64 breaks permissions
According to Apple arm64 calling convention varargs always are passed through stack. Since `open` is actually a vararg function on Darwin's, it means that older declaration caused permissions to be taken from stack, while passed through register => it set file permissions to garbage and it was simply impossible to read/delete files after they were created. They way this commit handles it is to preserve compatibility with existing code - it simply creates a shim unsafe function so all existing callers continue work as nothing happened.
1 parent dd077d5 commit 3f4181a

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

src/liblibc/lib.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5003,9 +5003,36 @@ pub mod funcs {
50035003
use types::os::arch::c95::{c_char, c_int};
50045004
use types::os::arch::posix88::mode_t;
50055005

5006+
mod open_shim {
5007+
extern {
5008+
#[cfg(any(target_os = "macos",
5009+
target_os = "ios"))]
5010+
pub fn open(path: *const ::c_char, oflag: ::c_int, ...)
5011+
-> ::c_int;
5012+
5013+
#[cfg(not(any(target_os = "macos",
5014+
target_os = "ios")))]
5015+
pub fn open(path: *const ::c_char, oflag: ::c_int, mode: ::mode_t)
5016+
-> ::c_int;
5017+
}
5018+
}
5019+
5020+
#[cfg(any(target_os = "macos",
5021+
target_os = "ios"))]
5022+
#[inline]
5023+
pub unsafe extern fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int {
5024+
use types::os::arch::c95::c_uint;
5025+
open_shim::open(path, oflag, mode as c_uint)
5026+
}
5027+
5028+
#[cfg(not(any(target_os = "macos",
5029+
target_os = "ios")))]
5030+
#[inline]
5031+
pub unsafe extern fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int {
5032+
open_shim::open(path, oflag, mode)
5033+
}
5034+
50065035
extern {
5007-
pub fn open(path: *const c_char, oflag: c_int, mode: mode_t)
5008-
-> c_int;
50095036
pub fn creat(path: *const c_char, mode: mode_t) -> c_int;
50105037
pub fn fcntl(fd: c_int, cmd: c_int, ...) -> c_int;
50115038
}

0 commit comments

Comments
 (0)