From b13e96ffb8631b1d81d4c55b98c89b87094daf57 Mon Sep 17 00:00:00 2001
From: Jeremy Soller <jackpot51@gmail.com>
Date: Fri, 11 Nov 2022 09:42:47 -0700
Subject: [PATCH] Ensure there is a stub Tcb for dynamically linked binaries

---
 src/ld_so/start.rs | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/ld_so/start.rs b/src/ld_so/start.rs
index 4a395ffec..b19b4ac41 100644
--- a/src/ld_so/start.rs
+++ b/src/ld_so/start.rs
@@ -17,7 +17,7 @@ use crate::{
     ALLOCATOR,
 };
 
-use super::{access::accessible, debug::_r_debug, linker::Linker, tcb::Tcb, PATH_SEP};
+use super::{access::accessible, debug::_r_debug, linker::Linker, tcb::Tcb, ExpectTlsFree, PATH_SEP};
 use crate::header::sys_auxv::{AT_ENTRY, AT_PHDR};
 use goblin::elf::header::header64::SIZEOF_EHDR;
 
@@ -213,6 +213,12 @@ pub extern "C" fn relibc_ld_so_start(sp: &'static mut Stack, ld_entry: usize) ->
         }
     };
 
+    // Ensure there is a stub Tcb
+    unsafe {
+        let tcb = Tcb::new(0).expect_notls("failed to allocate TCB");
+        tcb.activate();
+    }
+
     // if we are not running in manual mode, then the main
     // program is already loaded by the kernel and we want
     // to use it. on redox, we treat it the same.
-- 
GitLab