Skip to content

Commit

Permalink
Perform some code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jart committed Feb 27, 2021
1 parent 3e17c7b commit 19d0c15
Show file tree
Hide file tree
Showing 41 changed files with 321 additions and 459 deletions.
3 changes: 1 addition & 2 deletions .vscode/vscode.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ typedef struct { int ax, dx; } axdx_t;
#define offsetof(x, y) 0
#define INITIALIZER(...) struct _dummy
#define __far
#define tinystrstr(...) 0
#define BENCHLOOP(...) 0
#define BENCHLOOP(...) 0

#ifdef __hook
#undef __hook
Expand Down
14 changes: 0 additions & 14 deletions NOTICE

This file was deleted.

8 changes: 1 addition & 7 deletions ape/ape.S
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#include "libc/runtime/pc.internal.h"
#include "libc/sysv/consts/prot.h"

#define USE_SYMBOL_HACK 0
#define USE_SYMBOL_HACK 1

.section .text,"ax",@progbits
.align __SIZEOF_POINTER__
Expand Down Expand Up @@ -1486,12 +1486,6 @@ ape_pad_text:
ape_pad_privileged:
.previous

.section .ape.pad.test,"a",@progbits
.type ape_pad_test,@object
.hidden ape_pad_test
ape_pad_test:
.previous

.section .ape.pad.rodata,"a",@progbits
.type ape_pad_rodata,@object
.hidden ape_pad_rodata
Expand Down
13 changes: 7 additions & 6 deletions ape/ape.lds
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,8 @@ SECTIONS {
/* Code that needs to be addressable in Real Mode */
*(.text.real)
KEEP(*(SORT_BY_NAME(.sort.text.real.*)))
/**(.rodata.real)
KEEP(*(SORT_BY_NAME(.sort.rodata.real.*)))*/
HIDDEN(_ereal = .);
. += 1;

/*END: realmode addressability guarantee */

Expand Down Expand Up @@ -273,16 +272,17 @@ SECTIONS {
KEEP(*(SORT_BY_NAME(.sort.text.*)))

KEEP(*(.ape.pad.test));
HIDDEN(__test_start = .);
*(.test.unlikely)
*(.test .test.*)

/* Privileged code invulnerable to magic */
KEEP(*(.ape.pad.privileged));
. += . > 0 ? 1 : 0;
HIDDEN(__privileged_start = .);
HIDDEN(__test_end = .);
. += . > 0 ? 1 : 0;
*(.privileged)
HIDDEN(__privileged_end = .);
. += . > 0 ? 1 : 0;

/*BEGIN: Read Only Data */

Expand All @@ -302,7 +302,7 @@ SECTIONS {
KEEP(*(.comment))
KEEP(*(.commentepilogue))
#endif

/* Windows DLL Import Directory */
KEEP(*(.idata.ro));
KEEP(*(SORT_BY_NAME(.idata.ro.*)))
Expand Down Expand Up @@ -369,6 +369,7 @@ SECTIONS {
*(.piro.bss)
KEEP(*(SORT_BY_NAME(.piro.bss.sort.*)))
HIDDEN(__piro_end = .);
. += . > 0 ? 1 : 0;
/*END: Post-Initialization Read-Only */

/* Statically Allocated Empty Space */
Expand All @@ -378,7 +379,7 @@ SECTIONS {

KEEP(*(SORT_BY_NAME(.sort.bss.*)))

. = ALIGN(0x10000); /* for brk()/sbrk() allocation */
. = ALIGN(FRAMESIZE); /* for brk()/sbrk() allocation */
HIDDEN(_end = .);
PROVIDE_HIDDEN(end = .);
} :Ram
Expand Down
8 changes: 4 additions & 4 deletions build/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ endif

# Linux-Only Tiny Mode
#
# - `make MODE=tiny`
# - `make MODE=tinylinux`
# - No checks
# - No asserts
# - No canaries
Expand Down Expand Up @@ -158,7 +158,7 @@ endif

# Linux+BSD Tiny Mode
#
# - `make MODE=tiny`
# - `make MODE=tinylinuxbsd`
# - No apple
# - No checks
# - No asserts
Expand Down Expand Up @@ -187,7 +187,7 @@ endif

# Unix Tiny Mode
#
# - `make MODE=tiny`
# - `make MODE=tinysysv`
# - No checks
# - No asserts
# - No canaries
Expand Down Expand Up @@ -215,7 +215,7 @@ endif

# Tiny Metallic Unix Mode
#
# - `make MODE=tiny`
# - `make MODE=tinynowin`
# - No checks
# - No asserts
# - No canaries
Expand Down
5 changes: 4 additions & 1 deletion libc/calls/calls.mk
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ o/$(MODE)/libc/calls/siggy.o: \
OVERRIDE_COPTS += \
-ffunction-sections

o/$(MODE)/libc/calls/xnutrampoline.o \
o/$(MODE)/libc/calls/sigenter-freebsd.o \
o/$(MODE)/libc/calls/sigenter-netbsd.o \
o/$(MODE)/libc/calls/sigenter-openbsd.o \
o/$(MODE)/libc/calls/sigenter-xnu.o \
o/$(MODE)/libc/calls/ntcontext2linux.o: \
OVERRIDE_COPTS += \
-O3
Expand Down
42 changes: 21 additions & 21 deletions libc/calls/sigenter-freebsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ struct siginfo_freebsd {
union sigval_freebsd si_value;
union {
struct {
int _trapno;
int32_t _trapno;
} _fault;
struct {
int _timerid;
int _overrun;
int32_t _timerid;
int32_t _overrun;
} _timer;
struct {
int _mqd;
int32_t _mqd;
} _mesgq;
struct {
long _band;
int64_t _band;
} _poll;
struct {
long __spare1__;
int __spare2__[7];
int64_t __spare1__;
int32_t __spare2__[7];
} __spare__;
} _reason;
};
Expand Down Expand Up @@ -106,7 +106,7 @@ struct mcontext_freebsd {
int64_t mc_gsbase;
int64_t mc_xfpustate;
int64_t mc_xfpustate_len;
long mc_spare[4];
int64_t mc_spare[4];
};

struct ucontext_freebsd {
Expand All @@ -118,8 +118,8 @@ struct ucontext_freebsd {
int32_t __spare__[4];
};

hidden void __sigenter_freebsd(int sig, struct siginfo_freebsd *si,
struct ucontext_freebsd *ctx) {
void __sigenter_freebsd(int sig, struct siginfo_freebsd *si,
struct ucontext_freebsd *ctx) {
int rva;
ucontext_t uc;
rva = __sighandrvas[sig & (NSIG - 1)];
Expand All @@ -133,28 +133,28 @@ hidden void __sigenter_freebsd(int sig, struct siginfo_freebsd *si,
uc.uc_flags = ctx->uc_flags;
memcpy(&uc.uc_sigmask, &ctx->uc_sigmask,
MIN(sizeof(uc.uc_sigmask), sizeof(ctx->uc_sigmask)));
uc.uc_mcontext.rdi = ctx->uc_mcontext.mc_rdi;
uc.uc_mcontext.rsi = ctx->uc_mcontext.mc_rsi;
uc.uc_mcontext.rdx = ctx->uc_mcontext.mc_rdx;
uc.uc_mcontext.rcx = ctx->uc_mcontext.mc_rcx;
uc.uc_mcontext.r8 = ctx->uc_mcontext.mc_r8;
uc.uc_mcontext.r9 = ctx->uc_mcontext.mc_r9;
uc.uc_mcontext.rax = ctx->uc_mcontext.mc_rax;
uc.uc_mcontext.rbx = ctx->uc_mcontext.mc_rbx;
uc.uc_mcontext.rbp = ctx->uc_mcontext.mc_rbp;
uc.uc_mcontext.r10 = ctx->uc_mcontext.mc_r10;
uc.uc_mcontext.r11 = ctx->uc_mcontext.mc_r11;
uc.uc_mcontext.r12 = ctx->uc_mcontext.mc_r12;
uc.uc_mcontext.r13 = ctx->uc_mcontext.mc_r13;
uc.uc_mcontext.r14 = ctx->uc_mcontext.mc_r14;
uc.uc_mcontext.r15 = ctx->uc_mcontext.mc_r15;
uc.uc_mcontext.trapno = ctx->uc_mcontext.mc_trapno;
uc.uc_mcontext.rdi = ctx->uc_mcontext.mc_rdi;
uc.uc_mcontext.rsi = ctx->uc_mcontext.mc_rsi;
uc.uc_mcontext.rbp = ctx->uc_mcontext.mc_rbp;
uc.uc_mcontext.rbx = ctx->uc_mcontext.mc_rbx;
uc.uc_mcontext.rdx = ctx->uc_mcontext.mc_rdx;
uc.uc_mcontext.rax = ctx->uc_mcontext.mc_rax;
uc.uc_mcontext.rcx = ctx->uc_mcontext.mc_rcx;
uc.uc_mcontext.rsp = ctx->uc_mcontext.mc_rsp;
uc.uc_mcontext.rip = ctx->uc_mcontext.mc_rip;
uc.uc_mcontext.eflags = ctx->uc_mcontext.mc_flags;
uc.uc_mcontext.fs = ctx->uc_mcontext.mc_fs;
uc.uc_mcontext.gs = ctx->uc_mcontext.mc_gs;
uc.uc_mcontext.eflags = ctx->uc_mcontext.mc_flags;
uc.uc_mcontext.err = ctx->uc_mcontext.mc_err;
uc.uc_mcontext.rip = ctx->uc_mcontext.mc_rip;
uc.uc_mcontext.rsp = ctx->uc_mcontext.mc_rsp;
uc.uc_mcontext.trapno = ctx->uc_mcontext.mc_trapno;
}
((sigaction_f)(_base + rva))(sig, (void *)si, &uc);
if (ctx) {
Expand Down
4 changes: 2 additions & 2 deletions libc/calls/sigenter-netbsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ struct ucontext_netbsd {
struct mcontext_netbsd uc_mcontext;
};

hidden void __sigenter_netbsd(int sig, struct siginfo_netbsd *si,
struct ucontext_netbsd *ctx) {
void __sigenter_netbsd(int sig, struct siginfo_netbsd *si,
struct ucontext_netbsd *ctx) {
int rva;
ucontext_t uc;
struct siginfo si2;
Expand Down
4 changes: 2 additions & 2 deletions libc/calls/sigenter-openbsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ struct ucontext_openbsd {
int64_t sc_cookie;
};

hidden void __sigenter_openbsd(int sig, struct siginfo_openbsd *si,
struct ucontext_openbsd *ctx) {
void __sigenter_openbsd(int sig, struct siginfo_openbsd *si,
struct ucontext_openbsd *ctx) {
int rva;
ucontext_t uc;
struct siginfo si2;
Expand Down
File renamed without changes.
12 changes: 6 additions & 6 deletions libc/log/commandvenv.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
* that spawn subprocesses can use this function to determine the path
* at startup. Here's an example how you could use it:
*
* if ((strace = commandvenv("STRACE", "strace"))) {
* strace = strdup(strace);
* } else {
* fprintf(stderr, "error: please install strace\n");
* exit(1);
* }
* if ((strace = commandvenv("STRACE", "strace"))) {
* strace = strdup(strace);
* } else {
* fprintf(stderr, "error: please install strace\n");
* exit(1);
* }
*
* @param var is environment variable which may be used to override
* PATH search, and it can force a NULL result if it's empty
Expand Down
1 change: 0 additions & 1 deletion libc/runtime/efimain.greg.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ static const EFI_GUID kEfiLoadedImageProtocol = LOADED_IMAGE_PROTOCOL;
*/
__msabi noasan EFI_STATUS EfiMain(EFI_HANDLE ImageHandle,
EFI_SYSTEM_TABLE *SystemTable) {
bool ispml5t;
int type, x87cw;
struct mman *mm;
uint32_t DescVersion;
Expand Down
4 changes: 3 additions & 1 deletion libc/runtime/exit3.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "libc/nt/thunk/msabi.h"
#include "libc/sysv/consts/nr.h"

extern void(__msabi* __imp_ExitProcess)(uint32_t);

/**
* Terminates process, ignoring destructors and atexit() handlers.
*
Expand All @@ -41,10 +43,10 @@ privileged wontreturn void _Exit(int exitcode) {
: "a"(__NR_exit_group), "D"(exitcode)
: "memory");
} else if (IsWindows()) {
extern void(__msabi * __imp_ExitProcess)(uint32_t);
__imp_ExitProcess(exitcode & 0xff);
}
asm("push\t$0\n\t"
"push\t$0\n\t"
"cli\n\t"
"lidt\t(%rsp)");
for (;;) asm("ud2");
Expand Down
19 changes: 10 additions & 9 deletions libc/runtime/runtime.mk
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,22 @@ $(LIBC_RUNTIME_A).pkg: \
$(foreach x,$(LIBC_RUNTIME_A_DIRECTDEPS),$($(x)_A).pkg)

o/$(MODE)/libc/runtime/abort-nt.o \
o/$(MODE)/libc/runtime/assertfail.o \
o/$(MODE)/libc/runtime/memtrack.o \
o/$(MODE)/libc/runtime/memtracknt.o \
o/$(MODE)/libc/runtime/findmemoryinterval.o \
o/$(MODE)/libc/runtime/arememoryintervalsok.o \
o/$(MODE)/libc/runtime/isheap.o \
o/$(MODE)/libc/runtime/assertfail.o \
o/$(MODE)/libc/runtime/directmap.o \
o/$(MODE)/libc/runtime/directmapnt.o \
o/$(MODE)/libc/runtime/stackchkfail.o \
o/$(MODE)/libc/runtime/stackchkfaillocal.o \
o/$(MODE)/libc/runtime/hook.greg.o \
o/$(MODE)/libc/runtime/print.greg.o \
o/$(MODE)/libc/runtime/findmemoryinterval.o \
o/$(MODE)/libc/runtime/ftrace.greg.o \
o/$(MODE)/libc/runtime/getdosargv.o \
o/$(MODE)/libc/runtime/getdosenviron.o \
o/$(MODE)/libc/runtime/hook.greg.o \
o/$(MODE)/libc/runtime/isheap.o \
o/$(MODE)/libc/runtime/memtrack.o \
o/$(MODE)/libc/runtime/memtracknt.o \
o/$(MODE)/libc/runtime/mman.greg.o \
o/$(MODE)/libc/runtime/print.greg.o \
o/$(MODE)/libc/runtime/stackchkfail.o \
o/$(MODE)/libc/runtime/stackchkfaillocal.o \
o/$(MODE)/libc/runtime/winmain.greg.o: \
OVERRIDE_CFLAGS += \
$(NO_MAGIC)
Expand Down
10 changes: 2 additions & 8 deletions libc/runtime/winmain.greg.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ struct WinArgs {
char envblock[ARG_MAX];
};

static noasan textwindows void SetTrueColor(void) {
SetEnvironmentVariable(u"TERM", u"xterm-truecolor");
}

static noasan textwindows void MakeLongDoubleLongAgain(void) {
/* 8087 FPU Control Word
IM: Invalid Operation ───────────────┐
Expand Down Expand Up @@ -92,7 +88,6 @@ static noasan textwindows void NormalizeCmdExe(int version) {
hstdout = GetStdHandle(pushpop(kNtStdOutputHandle));
hstderr = GetStdHandle(pushpop(kNtStdErrorHandle));
if (GetFileType((handle = hstdin)) == kNtFileTypeChar) {
/* SetTrueColor(); */
SetConsoleCP(kNtCpUtf8);
GetConsoleMode(handle, &mode);
SetConsoleMode(handle, mode | kNtEnableProcessedInput |
Expand All @@ -102,7 +97,6 @@ static noasan textwindows void NormalizeCmdExe(int version) {
}
if (GetFileType((handle = hstdout)) == kNtFileTypeChar ||
GetFileType((handle = hstderr)) == kNtFileTypeChar) {
/* SetTrueColor(); */
SetConsoleOutputCP(kNtCpUtf8);
GetConsoleMode(handle, &mode);
SetConsoleMode(
Expand Down Expand Up @@ -135,7 +129,7 @@ static noasan textwindows wontreturn void WinMainNew(void) {
_mmi.p[0].y = (addr >> 16) + ((size >> 16) - 1);
_mmi.p[0].prot = PROT_READ | PROT_WRITE | PROT_EXEC;
_mmi.p[0].flags = MAP_PRIVATE | MAP_ANONYMOUS;
_mmi.i = pushpop(1L);
_mmi.i = 1;
wa = (struct WinArgs *)(addr + size - sizeof(struct WinArgs));
count = GetDosArgv(GetCommandLine(), wa->argblock, ARRAYLEN(wa->argblock),
wa->argv, ARRAYLEN(wa->argv));
Expand Down Expand Up @@ -193,7 +187,7 @@ static noasan textwindows wontreturn void WinMainNew(void) {
noasan textwindows int64_t WinMain(int64_t hInstance, int64_t hPrevInstance,
const char *lpCmdLine, int nCmdShow) {
MakeLongDoubleLongAgain();
if (weaken(__winsockinit)) weaken(__winsockinit)();
if (weaken(WinSockInit)) weaken(WinSockInit)();
if (weaken(WinMainForked)) weaken(WinMainForked)();
WinMainNew();
}
2 changes: 1 addition & 1 deletion libc/sock/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ ssize_t sys_sendto_nt(struct Fd *, const struct iovec *, size_t, uint32_t,
ssize_t sys_recvfrom_nt(struct Fd *, const struct iovec *, size_t, uint32_t,
void *, uint32_t *) hidden;

void __winsockinit(void) hidden;
void WinSockInit(void) hidden;
int64_t __winsockerr(void) nocallback hidden;
int __fixupnewsockfd(int, int) hidden;
int64_t __winsockblock(int64_t, unsigned, int64_t) hidden;
Expand Down
Loading

0 comments on commit 19d0c15

Please sign in to comment.