mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-13 06:29:11 +00:00
Clean up some code
This commit is contained in:
parent
a51edaa0db
commit
83d41e4588
114 changed files with 172 additions and 279 deletions
|
@ -17,7 +17,6 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/stdio/rand.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/sysv/consts/clock.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
|
|
@ -45,22 +45,20 @@ TEST(fcntl_getfl, testRemembersAccessMode) {
|
|||
}
|
||||
|
||||
TEST(fcntl_setfl, testChangeAppendStatus) {
|
||||
if (IsWindows()) {
|
||||
// no obvious way to do fcntl(fd, F_SETFL, O_APPEND)
|
||||
return;
|
||||
}
|
||||
int fd;
|
||||
if (IsWindows()) return; // Can't ReOpenFile() w/ O_APPEND
|
||||
char buf[8] = {0};
|
||||
ASSERT_NE(-1, (fd = open("foo", O_CREAT | O_RDWR, 0644)));
|
||||
EXPECT_EQ(3, write(fd, "foo", 3));
|
||||
EXPECT_NE(-1, lseek(fd, 0, SEEK_SET));
|
||||
EXPECT_NE(-1, fcntl(fd, F_SETFL, O_APPEND));
|
||||
EXPECT_EQ(3, write(fd, "bar", 3));
|
||||
EXPECT_NE(-1, lseek(fd, 0, SEEK_SET));
|
||||
EXPECT_NE(-1, fcntl(fd, F_SETFL, 0));
|
||||
EXPECT_EQ(6, read(fd, buf, 6));
|
||||
ASSERT_SYS(0, 3, open("foo", O_CREAT | O_WRONLY, 0644));
|
||||
EXPECT_SYS(0, 3, write(3, "foo", 3));
|
||||
EXPECT_SYS(0, 0, lseek(3, 0, SEEK_SET));
|
||||
EXPECT_SYS(0, 0, fcntl(3, F_SETFL, O_APPEND));
|
||||
EXPECT_SYS(0, 3, write(3, "bar", 3));
|
||||
EXPECT_SYS(0, 0, lseek(3, 0, SEEK_SET));
|
||||
EXPECT_SYS(0, 0, fcntl(3, F_SETFL, 0));
|
||||
EXPECT_SYS(0, 0, close(3));
|
||||
ASSERT_SYS(0, 3, open("foo", 0));
|
||||
EXPECT_SYS(0, 6, read(3, buf, 6));
|
||||
EXPECT_STREQ("foobar", buf);
|
||||
EXPECT_NE(-1, close(fd));
|
||||
EXPECT_SYS(0, 0, close(3));
|
||||
}
|
||||
|
||||
TEST(fcntl, getfd) {
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/sysv/consts/itimer.h"
|
||||
#include "libc/sysv/consts/sa.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "libc/calls/internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/runtime/gc.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
|
@ -107,14 +106,16 @@ TEST(open, testOpenExistingForReadWrite_seeksToStart) {
|
|||
}
|
||||
|
||||
TEST(open, testOpenExistingForAppendWriteOnly_seeksToEnd) {
|
||||
char buf[8] = {0};
|
||||
char buf[16] = {0};
|
||||
ASSERT_SYS(0, 0, xbarf("hello.txt", "hell", -1));
|
||||
ASSERT_SYS(0, 3, open("hello.txt", O_WRONLY | O_APPEND));
|
||||
EXPECT_SYS(0, 1, write(3, "o", 1));
|
||||
EXPECT_SYS(0, 0, lseek(3, 0, SEEK_SET));
|
||||
EXPECT_SYS(0, 1, write(3, "!", 1));
|
||||
EXPECT_SYS(0, 0, close(3));
|
||||
ASSERT_SYS(0, 3, open("hello.txt", O_RDONLY));
|
||||
EXPECT_SYS(0, 5, read(3, buf, 7));
|
||||
EXPECT_STREQ("hello", buf);
|
||||
EXPECT_SYS(0, 6, read(3, buf, 8));
|
||||
EXPECT_STREQ("hello!", buf);
|
||||
EXPECT_SYS(0, 0, close(3));
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include "libc/calls/syscall_support-sysv.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/intrin/promises.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/sock/sock.h"
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
#include "libc/calls/syscall_support-sysv.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/mem/io.h"
|
||||
#include "libc/mem/mem.h"
|
||||
|
@ -37,6 +36,7 @@
|
|||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/sock/sock.h"
|
||||
#include "libc/sock/struct/sockaddr.h"
|
||||
#include "libc/stdio/lock.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/sysv/consts/af.h"
|
||||
#include "libc/sysv/consts/at.h"
|
||||
|
@ -110,7 +110,6 @@ TEST(pledge, default_allowsExit) {
|
|||
EXPECT_SYS(0, 0, munmap(job, FRAMESIZE));
|
||||
}
|
||||
|
||||
#if 0
|
||||
TEST(pledge, execpromises_notok) {
|
||||
if (IsOpenbsd()) return; // b/c testing linux bpf
|
||||
int ws, pid;
|
||||
|
@ -167,7 +166,7 @@ TEST(pledge, stdio_forbidsOpeningPasswd2) {
|
|||
}
|
||||
EXPECT_NE(-1, wait(&ws));
|
||||
EXPECT_TRUE(WIFSIGNALED(ws));
|
||||
EXPECT_EQ(SIGABRT, WTERMSIG(ws));
|
||||
EXPECT_EQ(IsOpenbsd() ? SIGABRT : SIGSYS, WTERMSIG(ws));
|
||||
}
|
||||
|
||||
TEST(pledge, multipleCalls_canOnlyBecomeMoreRestrictive1) {
|
||||
|
@ -375,24 +374,6 @@ TEST(pledge, mmapProtExec) {
|
|||
EXPECT_TRUE(WIFEXITED(ws) && !WEXITSTATUS(ws));
|
||||
}
|
||||
|
||||
TEST(pledge, msyscall) {
|
||||
if (IsOpenbsd()) return; // b/c testing linux bpf
|
||||
int ax, ws, pid;
|
||||
ASSERT_NE(-1, (pid = fork()));
|
||||
if (!pid) {
|
||||
ASSERT_SYS(0, 0, pledge("stdio", 0));
|
||||
// now issue authorized syscall where rip isn't privileged
|
||||
asm volatile("syscall"
|
||||
: "=a"(ax)
|
||||
: "0"(__NR_linux_dup), "D"(2)
|
||||
: "rcx", "r11", "memory");
|
||||
_Exit(1);
|
||||
}
|
||||
EXPECT_NE(-1, wait(&ws));
|
||||
EXPECT_TRUE(WIFSIGNALED(ws));
|
||||
EXPECT_EQ(SIGSYS, WTERMSIG(ws));
|
||||
}
|
||||
|
||||
TEST(pledge, chmod_ignoresDangerBits) {
|
||||
if (IsOpenbsd()) return; // b/c testing linux bpf
|
||||
int ws, pid;
|
||||
|
@ -467,21 +448,6 @@ TEST(pledge, open_cpath) {
|
|||
EXPECT_TRUE(WIFEXITED(ws) && !WEXITSTATUS(ws));
|
||||
}
|
||||
|
||||
TEST(pledge, sigaction_isFineButForbidsSigsys) {
|
||||
if (IsOpenbsd()) return; // b/c testing linux bpf
|
||||
int ws, pid;
|
||||
ASSERT_NE(-1, (pid = fork()));
|
||||
if (!pid) {
|
||||
ASSERT_SYS(0, 0, pledge("stdio", 0));
|
||||
struct sigaction sa = {.sa_handler = OnSig};
|
||||
ASSERT_SYS(0, 0, sigaction(SIGINT, &sa, 0));
|
||||
ASSERT_SYS(EPERM, -1, sigaction(SIGSYS, &sa, 0));
|
||||
_Exit(0);
|
||||
}
|
||||
EXPECT_NE(-1, wait(&ws));
|
||||
EXPECT_TRUE(WIFEXITED(ws) && !WEXITSTATUS(ws));
|
||||
}
|
||||
|
||||
TEST(pledge, execpromises_ok) {
|
||||
if (IsOpenbsd()) return; // b/c testing linux bpf
|
||||
int ws, pid;
|
||||
|
@ -618,7 +584,7 @@ TEST(pledge, threadWithLocks_canCodeMorph) {
|
|||
TEST(pledge, everything) {
|
||||
int ws, pid;
|
||||
if (!fork()) {
|
||||
// contains 548 bpf instructions [2022-07-24]
|
||||
// contains 591 bpf instructions [2022-07-24]
|
||||
ASSERT_SYS(0, 0,
|
||||
pledge("stdio rpath wpath cpath dpath "
|
||||
"flock fattr inet unix dns tty "
|
||||
|
@ -665,4 +631,3 @@ BENCH(pledge, bench) {
|
|||
}
|
||||
wait(0);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
#include "libc/calls/pledge.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/log/libfatal.internal.h"
|
||||
#include "libc/nexgen32e/rdtsc.h"
|
||||
#include "libc/nexgen32e/rdtscp.h"
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include "libc/calls/struct/rlimit.h"
|
||||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/intrin/spinlock.h"
|
||||
#include "libc/intrin/wait0.internal.h"
|
||||
#include "libc/macros.internal.h"
|
||||
|
|
|
@ -16,12 +16,11 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/midpoint.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/sched_param.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/intrin/midpoint.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/sysv/consts/sched.h"
|
||||
|
|
|
@ -103,6 +103,12 @@ o/$(MODE)/test/libc/calls/poll_test.com.runs: \
|
|||
o/$(MODE)/test/libc/calls/fcntl_test.com.runs: \
|
||||
private .PLEDGE = stdio rpath wpath cpath fattr proc flock
|
||||
|
||||
# TODO(jart): Update nointernet() to allow AF_INET6
|
||||
o/$(MODE)/test/libc/calls/pledge_test.com.runs: \
|
||||
private .INTERNET = 1
|
||||
o/$(MODE)/test/libc/calls/pledge_test.com.runs: \
|
||||
private .PLEDGE =
|
||||
|
||||
.PHONY: o/$(MODE)/test/libc/calls
|
||||
o/$(MODE)/test/libc/calls: \
|
||||
$(TEST_LIBC_CALLS_BINS) \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue