Skip to content

Commit e80fc10

Browse files
committed
Rollup merge of #22862 - vhbit:broken-open, r=alexcrichton
According to Apple's [arm64 calling convention](https://developer.apple.com/library/ios/documentation/Xcode/Conceptual/iPhoneOSABIReference/Articles/ARM64FunctionCallingConventions.html#//apple_ref/doc/uid/TP40013702-SW1) varargs always are passed through stack. Since `open` is actually a vararg function on Darwin, 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.
2 parents b0746ff + 3f4181a commit e80fc10

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
@@ -4999,9 +4999,36 @@ pub mod funcs {
49994999
use types::os::arch::c95::{c_char, c_int};
50005000
use types::os::arch::posix88::mode_t;
50015001

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

0 commit comments

Comments
 (0)