Keep the session preload loadable when spare static TLS runs out

The syscall-dispatch selector pointer in the zram preload used the
initial-exec TLS model. That marks the whole libddsession TLS block
(about 1.8 KB) as static, so loading it at runtime needs that much spare
static TLS. Under proot there is not enough, and every guest program
failed with "cannot allocate memory in static TLS block". The default
model keeps the same per-thread behaviour without that requirement.
This commit is contained in:
maxjivi05 committed 2026-12-05 15:22:30 -05:00
1 parent caae385924
commit eb3acb2ce6
2 files changed
+15 -1

No files matched your search

+1 -1
View File
@@ -542,7 +542,7 @@ static int zr_start(void) {
return 0;
}
static __thread volatile unsigned char *zr_dispatch __attribute__((tls_model("initial-exec")));
static __thread volatile unsigned char *zr_dispatch;
int prctl(int option, ...) {
va_list ap;
+14
View File
@@ -773,6 +773,20 @@ class ZramPreloadTest(unittest.TestCase):
self.assertEqual([1], out["trimmed"], out)
self.assertEqual([1], out["named"], out)
def test_loads_at_runtime_without_spare_static_tls(self):
loader = self.dir / "loader"
source = self.dir / "loader.c"
source.write_text("#include <dlfcn.h>\n#include <stdio.h>\n"
"int main(int c, char **v) { (void)c; void *h = dlopen(v[1], RTLD_NOW);"
" puts(h ? \"loaded\" : dlerror()); return h == NULL; }\n")
subprocess.run(["cc", "-O2", "-o", str(loader), str(source), "-ldl"], check=True)
environment = dict(os.environ, GLIBC_TUNABLES="glibc.rtld.optional_static_tls=0")
environment.pop("LD_PRELOAD", None)
result = subprocess.run([str(loader), str(self.lib)], env=environment, capture_output=True, text=True,
timeout=60)
self.assertEqual(0, result.returncode, result.stdout + result.stderr)
self.assertEqual("loaded", result.stdout.strip())
if __name__ == "__main__":
unittest.main()