From 0d88aa7e0fa9453e736ef6fb3bfb8ef47f727e0a Mon Sep 17 00:00:00 2001 From: Dmitrii Kuvaiskii Date: Thu, 21 Jul 2022 06:50:29 -0700 Subject: [PATCH] fixup! Support running scripts as the entrypoint Signed-off-by: Dmitrii Kuvaiskii --- libos/include/libos_internal.h | 2 +- libos/src/arch/x86_64/start.S | 6 +++--- libos/src/libos_init.c | 3 +-- libos/test/regression/shebang_test_script.sh | 4 ++-- libos/test/regression/test_libos.py | 8 ++++---- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/libos/include/libos_internal.h b/libos/include/libos_internal.h index e77ce6123a..4a9ecc72da 100644 --- a/libos/include/libos_internal.h +++ b/libos/include/libos_internal.h @@ -18,7 +18,7 @@ #include "pal.h" #include "pal_error.h" -noreturn void* libos_init(int argc, const char** argv, const char** envp); +noreturn void* libos_init(const char** argv, const char** envp); /* important macros and static inline functions */ diff --git a/libos/src/arch/x86_64/start.S b/libos/src/arch/x86_64/start.S index 5e2e9bc4d6..af2f812577 100644 --- a/libos/src/arch/x86_64/start.S +++ b/libos/src/arch/x86_64/start.S @@ -13,9 +13,9 @@ libos_start: xorq %rbp, %rbp # Arguments for libos_init: - movq 0(%rsp), %rdi # argc - leaq 8(%rsp), %rsi # argv - leaq 8(%rsi,%rdi,8), %rdx # envp, after all args (including argv[argc] = NULL) + movq 0(%rsp), %r8 # argc, unused by libos_init, used to calculate location of envp + leaq 8(%rsp), %rdi # argv + leaq 8(%rdi,%r8,8), %rsi # envp, after all args (including argv[argc] = NULL) # Required by System V AMD64 ABI. andq $~0xF, %rsp diff --git a/libos/src/libos_init.c b/libos/src/libos_init.c index 3ddc3552de..b559b8b2c0 100644 --- a/libos/src/libos_init.c +++ b/libos/src/libos_init.c @@ -366,8 +366,7 @@ static int read_environs(const char** envp) { } \ } while (0) -noreturn void* libos_init(int argc, const char** argv, const char** envp) { - __UNUSED(argc); +noreturn void* libos_init(const char** argv, const char** envp) { g_pal_public_state = PalGetPalPublicState(); assert(g_pal_public_state); diff --git a/libos/test/regression/shebang_test_script.sh b/libos/test/regression/shebang_test_script.sh index 523a1e16f1..c7c8a9d778 100755 --- a/libos/test/regression/shebang_test_script.sh +++ b/libos/test/regression/shebang_test_script.sh @@ -1,2 +1,2 @@ -#! /bin/sh -scripts/foo.sh +#!/bin/sh +exec scripts/foo.sh diff --git a/libos/test/regression/test_libos.py b/libos/test/regression/test_libos.py index bc4b1318cf..b6e0e2d82c 100644 --- a/libos/test/regression/test_libos.py +++ b/libos/test/regression/test_libos.py @@ -214,8 +214,8 @@ def test_210_exec_invalid_args(self): self.assertIn('execve(invalid-argv) correctly returned error', stdout) self.assertIn('execve(invalid-envp) correctly returned error', stdout) - @unittest.skipIf(USES_MUSL, 'Test uses /bin/sh from the host which is usually built against' - 'glibc') + @unittest.skipIf(USES_MUSL, + 'Test uses /bin/sh from the host which is usually built against glibc') def test_211_exec_script(self): stdout, _ = self.run_binary(['exec_script']) self.assertIn('Printing Args: ' @@ -223,8 +223,8 @@ def test_211_exec_script(self): 'ALPHA BRAVO CHARLIE DELTA ' 'scripts/foo.sh STRING FROM EXECVE', stdout) - @unittest.skipIf(USES_MUSL, 'Test uses /bin/sh from the host which is usually built against' - 'glibc') + @unittest.skipIf(USES_MUSL, + 'Test uses /bin/sh from the host which is usually built against glibc') def test_212_shebang_test_script(self): stdout, _ = self.run_binary(['shebang_test_script']) self.assertIn('Printing Args: '