about summary refs log tree commit diff
path: root/src/libstd/sys/unix/weak.rs
diff options
context:
space:
mode:
authorAdrian Budau <budau.adi@gmail.com>2018-12-19 16:13:43 +0200
committerAdrian Budau <budau.adi@gmail.com>2018-12-20 13:22:31 +0200
commitcc53f4e9f48747d44718bb1b51e549437edae916 (patch)
treecb0894bd5157859ec8cef514fa3178085074b273 /src/libstd/sys/unix/weak.rs
parente7b4bc35e99ee3c5b2b42a1b8b3f9cd6eca1f0b2 (diff)
downloadrust-cc53f4e9f48747d44718bb1b51e549437edae916.tar.gz
rust-cc53f4e9f48747d44718bb1b51e549437edae916.zip
Fix pipe2 and accept4 on static linked executables on linux (like musl).
Diffstat (limited to 'src/libstd/sys/unix/weak.rs')
-rw-r--r--src/libstd/sys/unix/weak.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/libstd/sys/unix/weak.rs b/src/libstd/sys/unix/weak.rs
index 18944be58ee..3b73e3b7c50 100644
--- a/src/libstd/sys/unix/weak.rs
+++ b/src/libstd/sys/unix/weak.rs
@@ -77,3 +77,55 @@ unsafe fn fetch(name: &str) -> usize {
     };
     libc::dlsym(libc::RTLD_DEFAULT, name.as_ptr()) as usize
 }
+
+#[cfg(not(target_os = "linux"))]
+macro_rules! syscall {
+    (fn $name:ident($($arg_name:ident: $t:ty),*) -> $ret:ty) => (
+        unsafe fn $name($($arg_name: $t),*) -> $ret {
+            use libc;
+
+            weak! { fn $name($($t),*) -> $ret }
+
+            if let Some(fun) = $name.get() {
+                fun($($arg_name),*)
+            } else {
+                libc::ENOSYS
+            }
+        }
+    )
+}
+
+#[cfg(target_os = "linux")]
+macro_rules! syscall {
+    (fn $name:ident($($arg_name:ident: $t:ty),*) -> $ret:ty) => (
+        unsafe fn $name($($arg_name:$t),*) -> $ret {
+            // This like a hack, but concat_idents only accepts idents
+            // (not paths).
+            use libc::*;
+
+            syscall(
+                concat_idents!(SYS_, $name),
+                $(::sys::weak::SyscallParam::to_param($arg_name)),*
+            ) as $ret
+        }
+    )
+}
+
+#[cfg(target_os = "linux")]
+pub trait SyscallParam {
+    fn to_param(self) -> libc::c_long;
+}
+
+#[cfg(target_os = "linux")]
+impl SyscallParam for libc::c_int {
+    fn to_param(self) -> libc::c_long {
+        self as libc::c_long
+    }
+}
+
+#[cfg(target_os = "linux")]
+impl<T> SyscallParam for *mut T {
+    fn to_param(self) -> libc::c_long {
+        unsafe { mem::transmute(self) }
+    }
+}