Make improvements

- Fix unused local variable errors
- Remove yoinks from sigaction() header
- Add nox87 and aarch64 to github actions
- Fix cosmocc -fportcosmo in linking mode
- It's now possible to build `make m=llvm o/llvm/libc`
This commit is contained in:
Justine Tunney 2023-07-10 04:29:46 -07:00
parent 3dc86ce154
commit f7ae50462a
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
118 changed files with 342 additions and 392 deletions

View file

@ -191,7 +191,8 @@ o/$(MODE)/libc/calls/pledge-linux.o \
o/$(MODE)/libc/calls/siginfo2cosmo.o: private \
CFLAGS += \
-ffreestanding \
-fno-sanitize=all
-fno-sanitize=all \
-fno-stack-protector
o/$(MODE)/libc/calls/pledge-linux.o \
o/$(MODE)/libc/calls/unveil.o: private \

View file

@ -23,6 +23,7 @@
#include "libc/calls/state.internal.h"
#include "libc/calls/struct/fd.internal.h"
#include "libc/calls/struct/sigaction.h"
#include "libc/calls/struct/sigaction.internal.h"
#include "libc/calls/syscall_support-nt.internal.h"
#include "libc/dce.h"
#include "libc/errno.h"

View file

@ -59,7 +59,6 @@ static int ioctl_siocgifconf_sysv(int fd, struct ifconf *ifc) {
char *b, *p, *e;
char ifcBsd[16];
struct ifreq *req;
struct ifreq *end;
uint32_t bufLen, ip;
size_t numReq, bufMax;
if (IsLinux()) return sys_ioctl(fd, SIOCGIFCONF, ifc);
@ -77,7 +76,6 @@ static int ioctl_siocgifconf_sysv(int fd, struct ifconf *ifc) {
*/
memcpy(&bufLen, b, 4);
req = ifc->ifc_req;
end = req + ifc->ifc_len / sizeof(*req);
for (p = b, e = p + MIN(bufMax, READ32LE(ifcBsd)); p + 16 + 16 <= e;
p += IsBsd() ? 16 + MAX(16, p[16] & 255) : 40) {
fam = p[IsBsd() ? 17 : 16] & 255;

View file

@ -26,9 +26,6 @@
#include "libc/sysv/errfuns.h"
textwindows int sys_pause_nt(void) {
long ms, totoms;
ms = 0;
totoms = 0;
for (;;) {
if (_check_interrupts(false, g_fds.p)) {
@ -40,7 +37,8 @@ textwindows int sys_pause_nt(void) {
continue;
}
#if defined(SYSDEBUG) && defined(_POLLTRACE)
#if defined(SYSDEBUG) && _POLLTRACE
long ms = 0, totoms = 0;
ms += __SIG_POLLING_INTERVAL_MS;
if (ms >= __SIG_LOGGING_INTERVAL_MS) {
totoms += ms, ms = 0;

View file

@ -25,6 +25,7 @@
#include "libc/calls/struct/seccomp.internal.h"
#include "libc/calls/struct/sigaction.h"
#include "libc/calls/syscall_support-sysv.internal.h"
#include "libc/calls/ucontext.h"
#include "libc/intrin/bsr.h"
#include "libc/intrin/likely.h"
#include "libc/intrin/promises.internal.h"

View file

@ -24,6 +24,7 @@
#include "libc/calls/internal.h"
#include "libc/calls/sig.internal.h"
#include "libc/calls/state.internal.h"
#include "libc/calls/struct/sigaction.h"
#include "libc/calls/struct/sigaction.internal.h"
#include "libc/calls/struct/siginfo.internal.h"
#include "libc/calls/struct/sigset.h"
@ -53,6 +54,12 @@
STATIC_YOINK("strsignal"); // for kprintf()
#endif
#if SupportsWindows()
STATIC_YOINK("_init_onntconsoleevent");
STATIC_YOINK("_check_sigwinch");
STATIC_YOINK("_init_wincrash");
#endif
#define SA_RESTORER 0x04000000
static void sigaction_cosmo2native(union metasigaction *sa) {

View file

@ -74,7 +74,8 @@ privileged void __sigenter_netbsd(int sig, struct siginfo_netbsd *si,
uc.uc_mcontext.err = ctx->uc_mcontext.err;
uc.uc_mcontext.rip = ctx->uc_mcontext.rip;
uc.uc_mcontext.rsp = ctx->uc_mcontext.rsp;
*uc.uc_mcontext.fpregs = ctx->uc_mcontext.__fpregs;
__repmovsb(uc.uc_mcontext.fpregs, &ctx->uc_mcontext.__fpregs,
sizeof(ctx->uc_mcontext.__fpregs));
((sigaction_f)(__executable_start + rva))(sig, &si2, &uc);
ctx->uc_stack.ss_sp = uc.uc_stack.ss_sp;
ctx->uc_stack.ss_size = uc.uc_stack.ss_size;
@ -102,7 +103,8 @@ privileged void __sigenter_netbsd(int sig, struct siginfo_netbsd *si,
ctx->uc_mcontext.err = uc.uc_mcontext.err;
ctx->uc_mcontext.rip = uc.uc_mcontext.rip;
ctx->uc_mcontext.rsp = uc.uc_mcontext.rsp;
ctx->uc_mcontext.__fpregs = *uc.uc_mcontext.fpregs;
__repmovsb(&ctx->uc_mcontext.__fpregs, uc.uc_mcontext.fpregs,
sizeof(ctx->uc_mcontext.__fpregs));
}
}
/*

View file

@ -74,7 +74,8 @@ privileged void __sigenter_openbsd(int sig, struct siginfo_openbsd *openbsdinfo,
g.uc.uc_mcontext.rip = ctx->sc_rip;
g.uc.uc_mcontext.rsp = ctx->sc_rsp;
if (ctx->sc_fpstate) {
*g.uc.uc_mcontext.fpregs = *ctx->sc_fpstate;
__repmovsb(g.uc.uc_mcontext.fpregs, ctx->sc_fpstate,
sizeof(*ctx->sc_fpstate));
}
((sigaction_f)(__executable_start + rva))(sig, &g.si, &g.uc);
ctx->sc_mask = g.uc.uc_sigmask.__bits[0];
@ -100,7 +101,8 @@ privileged void __sigenter_openbsd(int sig, struct siginfo_openbsd *openbsdinfo,
ctx->sc_rip = g.uc.uc_mcontext.rip;
ctx->sc_rsp = g.uc.uc_mcontext.rsp;
if (ctx->sc_fpstate) {
*ctx->sc_fpstate = *g.uc.uc_mcontext.fpregs;
__repmovsb(ctx->sc_fpstate, g.uc.uc_mcontext.fpregs,
sizeof(*ctx->sc_fpstate));
}
}
}

View file

@ -27,5 +27,5 @@ int sigignore(int sig) {
struct sigaction sa;
bzero(&sa, sizeof(sa));
sa.sa_handler = SIG_IGN;
return (sigaction)(sig, &sa, 0);
return sigaction(sig, &sa, 0);
}

View file

@ -96,6 +96,8 @@ privileged void __siginfo2cosmo(struct siginfo *si,
si_signo == SIGBUS || //
si_signo == SIGTRAP) {
si->si_addr = si_addr;
} else if (si_signo == SIGCHLD) {
si->si_status = si_status;
} else if (si_signo == SIGALRM) {
si->si_timerid = si_timerid;
si->si_overrun = si_overrun;

View file

@ -30,9 +30,9 @@
* @note this function has BSD semantics, i.e. SA_RESTART
* @see sigaction() which has more features and docs
*/
sighandler_t(signal)(int sig, sighandler_t func) {
sighandler_t signal(int sig, sighandler_t func) {
struct sigaction old, sa = {.sa_handler = func, .sa_flags = SA_RESTART};
if ((sigaction)(sig, &sa, &old) != -1) {
if (sigaction(sig, &sa, &old) != -1) {
return old.sa_handler;
} else {
return SIG_ERR;

View file

@ -47,7 +47,6 @@
*/
int sigsuspend(const sigset_t *ignore) {
int rc;
long ms, totoms;
sigset_t save, *arg, mask = {0};
STRACE("sigsuspend(%s) → ...", DescribeSigset(0, ignore));
BEGIN_CANCELLATION_POINT;
@ -73,8 +72,10 @@ int sigsuspend(const sigset_t *ignore) {
rc = sys_sigsuspend(arg, 8);
} else {
__sig_mask(SIG_SETMASK, arg, &save);
ms = 0;
totoms = 0;
#if defined(SYSDEBUG) && _POLLTRACE
long ms = 0;
long totoms = 0;
#endif
do {
if ((rc = _check_interrupts(false, g_fds.p))) {
break;
@ -83,7 +84,7 @@ int sigsuspend(const sigset_t *ignore) {
POLLTRACE("IOCP EINTR");
continue;
}
#if defined(SYSDEBUG) && defined(_POLLTRACE)
#if defined(SYSDEBUG) && _POLLTRACE
ms += __SIG_POLLING_INTERVAL_MS;
if (ms >= __SIG_LOGGING_INTERVAL_MS) {
totoms += ms, ms = 0;

View file

@ -31,7 +31,6 @@
#include "libc/sysv/consts/sicode.h"
#include "libc/sysv/consts/sig.h"
#include "libc/thread/tls.h"
#ifdef __x86_64__
static struct winsize __ws;

View file

@ -299,5 +299,6 @@ void statfs2cosmo(struct statfs *f, const union statfs_meta *m) {
f->f_namelen = f_namelen;
f->f_frsize = f_frsize;
f->f_flags = f_flags;
f->f_owner = f_owner;
memcpy(f->f_fstypename, f_fstypename, 16);
}

View file

@ -2,15 +2,11 @@
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_H_
#include "libc/calls/struct/siginfo.h"
#include "libc/calls/struct/sigset.h"
#include "libc/calls/ucontext.h"
#include "libc/dce.h"
#include "libc/sysv/consts/sig.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
typedef void (*sighandler_t)(int);
typedef void (*sigaction_f)(int, struct siginfo *,
void * /*struct ucontext **/);
typedef void (*sigaction_f)(int, struct siginfo *, void *);
struct sigaction { /* cosmo abi */
union {
@ -25,60 +21,6 @@ struct sigaction { /* cosmo abi */
sighandler_t signal(int, sighandler_t);
int sigaction(int, const struct sigaction *, struct sigaction *);
#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(COSMO)
void _init_onntconsoleevent(void);
void _init_wincrash(void);
void _check_sigwinch();
#ifndef __SIGACTION_YOINK
#define __SIGACTION_YOINK(SIG) \
do { \
if (SupportsWindows()) { \
if (__builtin_constant_p(SIG)) { \
switch (SIG) { \
case SIGINT: \
case SIGQUIT: \
case SIGHUP: \
case SIGTERM: \
YOINK(_init_onntconsoleevent); \
break; \
case SIGTRAP: \
case SIGILL: \
case SIGSEGV: \
case SIGABRT: \
case SIGFPE: \
YOINK(_init_wincrash); \
break; \
case SIGWINCH: \
YOINK(_check_sigwinch); \
break; \
default: \
break; \
} \
} else { \
YOINK(_init_onntconsoleevent); \
YOINK(_init_wincrash); \
YOINK(_check_sigwinch); \
} \
} \
} while (0)
#endif
#define sigaction(SIG, ACT, OLD) \
({ \
__SIGACTION_YOINK(SIG); \
sigaction(SIG, (ACT), OLD); \
})
#define signal(SIG, HAND) \
({ \
__SIGACTION_YOINK(SIG); \
signal(SIG, HAND); \
})
#endif /* GNU && !ANSI */
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_H_ */

View file

@ -63,6 +63,10 @@ void __sigenter_openbsd(int, struct siginfo *, void *) _Hide;
const char *DescribeSigaction(char[256], int, const struct sigaction *);
#define DescribeSigaction(rc, sa) DescribeSigaction(alloca(256), rc, sa)
void _init_onntconsoleevent(void);
void _init_wincrash(void);
void _check_sigwinch();
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_INTERNAL_H_ */

View file

@ -61,6 +61,7 @@ textwindows int tcsetattr_nt(int ignored, int opt, const struct termios *tio) {
inmode |= kNtEnableVirtualTerminalInput;
}
ok = SetConsoleMode(in, inmode);
(void)ok;
NTTRACE("SetConsoleMode(%p, %s) → %hhhd", in,
DescribeNtConsoleInFlags(inmode), ok);
}
@ -75,6 +76,7 @@ textwindows int tcsetattr_nt(int ignored, int opt, const struct termios *tio) {
outmode |= kNtEnableVirtualTerminalProcessing;
}
ok = SetConsoleMode(out, outmode);
(void)ok;
NTTRACE("SetConsoleMode(%p, %s) → %hhhd", out,
DescribeNtConsoleOutFlags(outmode), ok);
}