Skip to content

Commit

Permalink
Rollup merge of rust-lang#22862 - vhbit:broken-open, r=alexcrichton
Browse files Browse the repository at this point in the history
 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.
  • Loading branch information
Manishearth committed Mar 6, 2015
2 parents b0746ff + 3f4181a commit e80fc10
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/liblibc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4999,9 +4999,36 @@ pub mod funcs {
use types::os::arch::c95::{c_char, c_int};
use types::os::arch::posix88::mode_t;

mod open_shim {
extern {
#[cfg(any(target_os = "macos",
target_os = "ios"))]
pub fn open(path: *const ::c_char, oflag: ::c_int, ...)
-> ::c_int;

#[cfg(not(any(target_os = "macos",
target_os = "ios")))]
pub fn open(path: *const ::c_char, oflag: ::c_int, mode: ::mode_t)
-> ::c_int;
}
}

#[cfg(any(target_os = "macos",
target_os = "ios"))]
#[inline]
pub unsafe extern fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int {
use types::os::arch::c95::c_uint;
open_shim::open(path, oflag, mode as c_uint)
}

#[cfg(not(any(target_os = "macos",
target_os = "ios")))]
#[inline]
pub unsafe extern fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int {
open_shim::open(path, oflag, mode)
}

extern {
pub fn open(path: *const c_char, oflag: c_int, mode: mode_t)
-> c_int;
pub fn creat(path: *const c_char, mode: mode_t) -> c_int;
pub fn fcntl(fd: c_int, cmd: c_int, ...) -> c_int;
}
Expand Down

0 comments on commit e80fc10

Please sign in to comment.