about summary refs log tree commit diff
diff options
context:
space:
mode:
authorValerii Hiora <valerii.hiora@gmail.com>2015-02-26 20:26:36 +0200
committerValerii Hiora <valerii.hiora@gmail.com>2015-03-05 12:41:59 +0200
commit3f4181a6e5c41a8d9d8ee434e6b75e7bef315998 (patch)
tree11383c7b9a5e1199b30c04b5edd3ac2c441a97b7
parentdd077d5decbc3e462a9fe2feb1a0af0486897acb (diff)
downloadrust-3f4181a6e5c41a8d9d8ee434e6b75e7bef315998.tar.gz
rust-3f4181a6e5c41a8d9d8ee434e6b75e7bef315998.zip
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.
-rw-r--r--src/liblibc/lib.rs31
1 files changed, 29 insertions, 2 deletions
diff --git a/src/liblibc/lib.rs b/src/liblibc/lib.rs
index 74a95b3aba0..1a500016175 100644
--- a/src/liblibc/lib.rs
+++ b/src/liblibc/lib.rs
@@ -5003,9 +5003,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;
             }