mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-02 09:18:31 +00:00
fexecve: renable and fix, assimilate via running shell script instead of running it
fexecve_test.c: fix zipread.com. renable tinyelf test (x86_64) only fexecve_test.c: make memfd_create test work on all archs cosmopolitan is compiled to (f)execve_test.c add checking for /proc/self/fd/ for fexecve fexecve_test: get /zip/echo working again move execve test out of fexecve_test.c assimilate via running embedded shell script instead of parsing it satisfy -Werror=discarded-qualifiers fexecve: fix zipos when executable is not an APE comment out broken tests get most fexecve tests working again switch memfd_create test back to vfork add life.elf back into zipread.c, move zipread into proc get zipos execve working again
This commit is contained in:
parent
33418f6742
commit
893edc8983
9 changed files with 182 additions and 62 deletions
|
@ -18,6 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/rusage.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
#include "libc/calls/syscall_support-sysv.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
|
@ -26,6 +27,8 @@
|
|||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/consts/s.h"
|
||||
#include "libc/temp.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/subprocess.h"
|
||||
|
@ -35,6 +38,9 @@ __static_yoink("zipos");
|
|||
|
||||
#define N 16
|
||||
|
||||
int fds[2];
|
||||
char buf[8];
|
||||
bool HasProcFSAndMemfd = false;
|
||||
void SetUpOnce(void) {
|
||||
testlib_enable_tmp_setup_teardown();
|
||||
}
|
||||
|
@ -48,6 +54,21 @@ void GenBuf(char buf[8], int x) {
|
|||
}
|
||||
}
|
||||
|
||||
__attribute__((__constructor__)) static void init(void) {
|
||||
char buf[8];
|
||||
if (__argc == 4 && !strcmp(__argv[1], "-")) {
|
||||
GenBuf(buf, atoi(__argv[2]));
|
||||
ASSERT_STREQ(buf, __argv[3]);
|
||||
exit(0);
|
||||
}
|
||||
// zipos execve requires /proc and memfd_create
|
||||
// TODO check for memfd
|
||||
if (IsLinux()) {
|
||||
struct stat st;
|
||||
HasProcFSAndMemfd = stat("/proc/self/fd", &st) == 0 && S_ISDIR(st.st_mode);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(execve, testArgPassing) {
|
||||
int i;
|
||||
char ibuf[12], buf[8];
|
||||
|
@ -64,10 +85,28 @@ TEST(execve, testArgPassing) {
|
|||
}
|
||||
}
|
||||
|
||||
TEST(execve, elfIsUnreadable_mayBeExecuted) {
|
||||
if (IsWindows() || IsXnu()) return;
|
||||
testlib_extract("/zip/echo.elf", "echo", 0111);
|
||||
ASSERT_SYS(0, 0, pipe2(fds, O_CLOEXEC));
|
||||
SPAWN(vfork);
|
||||
ASSERT_SYS(0, 1, dup2(4, 1));
|
||||
ASSERT_SYS(
|
||||
0, 0,
|
||||
execve("echo", (char *const[]){"echo", "hi", 0}, (char *const[]){0}));
|
||||
exit(1);
|
||||
EXITS(0);
|
||||
bzero(buf, 8);
|
||||
ASSERT_SYS(0, 0, close(4));
|
||||
ASSERT_SYS(0, 3, read(3, buf, 7));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
ASSERT_STREQ("hi\n", buf);
|
||||
}
|
||||
|
||||
TEST(execve, ziposELF) {
|
||||
if (1) return; // TODO: rewrite
|
||||
if (IsFreebsd()) return; // TODO: fixme on freebsd
|
||||
if (IsLinux() && !__is_linux_2_6_23()) return; // TODO: fixme on old linux
|
||||
if (IsLinux() && !HasProcFSAndMemfd) return;
|
||||
if (!IsLinux() && !IsFreebsd()) {
|
||||
EXPECT_SYS(ENOSYS, -1,
|
||||
execve("/zip/life.elf", (char *const[]){0}, (char *const[]){0}));
|
||||
|
@ -80,9 +119,9 @@ TEST(execve, ziposELF) {
|
|||
}
|
||||
|
||||
TEST(execve, ziposAPE) {
|
||||
if (1) return; // TODO: rewrite
|
||||
if (IsFreebsd()) return; // TODO: fixme on freebsd
|
||||
if (IsLinux() && !__is_linux_2_6_23()) return; // TODO: fixme on old linux
|
||||
if (IsLinux() && !HasProcFSAndMemfd) return;
|
||||
if (!IsLinux() && !IsFreebsd()) {
|
||||
EXPECT_EQ(-1, execve("/zip/life-nomod.com", (char *const[]){0},
|
||||
(char *const[]){0}));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue