Skip to content

Commit

Permalink
fixup! Support running scripts as the entrypoint
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitrii Kuvaiskii <[email protected]>
  • Loading branch information
Dmitrii Kuvaiskii committed Jul 21, 2022
1 parent ebf1a47 commit 0d88aa7
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion libos/include/libos_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
6 changes: 3 additions & 3 deletions libos/src/arch/x86_64/start.S
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions libos/src/libos_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions libos/test/regression/shebang_test_script.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#! /bin/sh
scripts/foo.sh
#!/bin/sh
exec scripts/foo.sh
8 changes: 4 additions & 4 deletions libos/test/regression/test_libos.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,17 @@ 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: '
'scripts/baz.sh ECHO FOXTROT GOLF scripts/bar.sh '
'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: '
Expand Down

0 comments on commit 0d88aa7

Please sign in to comment.