Explorar o código

Initialize pthreads if it is linked

Jeremy Soller %!s(int64=6) %!d(string=hai) anos
pai
achega
756a0d2edc
Modificáronse 1 ficheiros con 11 adicións e 0 borrados
  1. 11 0
      src/start.rs

+ 11 - 0
src/start.rs

@@ -44,6 +44,13 @@ unsafe fn copy_string_array(array: *const *const c_char, len: usize) -> Vec<*mut
     vec
 }
 
+// In the case that pthread is not linked, pthread_init can be replaced
+#[linkage = "weak"]
+#[no_mangle]
+extern "C" fn pthread_init() -> c_int {
+    0
+}
+
 #[inline(never)]
 #[no_mangle]
 pub unsafe extern "C" fn relibc_start(sp: &'static Stack) -> ! {
@@ -53,6 +60,7 @@ pub unsafe extern "C" fn relibc_start(sp: &'static Stack) -> ! {
         static __init_array_start: extern "C" fn();
         static __init_array_end: extern "C" fn();
 
+        fn pthread_init() -> c_int;
         fn _init();
         fn main(argc: isize, argv: *mut *mut c_char, envp: *mut *mut c_char) -> c_int;
     }
@@ -77,6 +85,9 @@ pub unsafe extern "C" fn relibc_start(sp: &'static Stack) -> ! {
     stdio::stdout = stdio::default_stdout.get();
     stdio::stderr = stdio::default_stderr.get();
 
+    // Initialize pthreads
+    pthread_init();
+
     // Call init section
     _init();