mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-01 15:30:29 +00:00
Make improvements for Actually Portable Emacs
- Get SIGWINCH working again on the New Technology - Correctly handle O_NOFOLLOW in open() on Windows - Implement synthetic umask() functionality on Windows - Do a better job managing file execute access on Windows - Fill in `st_uid` and `st_gid` with username hash on Windows - Munge UNICODE control pictures into control codes on Windows - Do a better job ensuring Windows console settings are restored - Introduce KPRINTF_LOG environment variable to log kprintf to a file
This commit is contained in:
parent
9c7b81ee0f
commit
965516e313
108 changed files with 1126 additions and 807 deletions
|
@ -148,11 +148,11 @@ static int PrintBacktraceUsingAddr2line(int fd, const struct StackFrame *bp) {
|
|||
strlen(" (discriminator ") - 1)) &&
|
||||
(p3 = memchr(p2, '\n', got - (p2 - p1)))) {
|
||||
if (p3 > p2 && p3[-1] == '\r') --p3;
|
||||
_klog(p1, p2 - p1);
|
||||
klog(p1, p2 - p1);
|
||||
got -= p3 - p1;
|
||||
p1 += p3 - p1;
|
||||
} else {
|
||||
_klog(p1, got);
|
||||
klog(p1, got);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ static relegated wontreturn void __check_fail_ndebug(uint64_t want, //
|
|||
}
|
||||
kprintf("\n");
|
||||
if (_weaken(__die)) _weaken(__die)();
|
||||
_Exitr(68);
|
||||
_Exit(68);
|
||||
}
|
||||
|
||||
void __check_fail_eq(uint64_t want, uint64_t got, const char *file, int line,
|
||||
|
|
|
@ -55,10 +55,10 @@ relegated wontreturn void __die(void) {
|
|||
DebugBreak();
|
||||
}
|
||||
ShowBacktrace(2, __builtin_frame_address(0));
|
||||
_Exitr(77);
|
||||
_Exit(77);
|
||||
} else if (owner == me) {
|
||||
kprintf("die failed while dying\n");
|
||||
_Exitr(79);
|
||||
_Exit(79);
|
||||
} else {
|
||||
_Exit1(79);
|
||||
}
|
||||
|
|
|
@ -115,6 +115,6 @@ dontasan void CheckForMemoryLeaks(void) {
|
|||
/* __print_maps(); */
|
||||
/* PrintSystemMappings(2); */
|
||||
/* PrintGarbage(); */
|
||||
_Exitr(78);
|
||||
_Exit(78);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,6 @@ void _meminfo(int); /* shows malloc statistics &c. */
|
|||
void _memsummary(int); /* light version of same thing */
|
||||
bool IsTerminalInarticulate(void) nosideeffect;
|
||||
const char *commandvenv(const char *, const char *);
|
||||
int LogKprintfToFile(const char *);
|
||||
const char *GetAddr2linePath(void);
|
||||
const char *GetGdbPath(void);
|
||||
bool32 IsDebuggerPresent(bool);
|
||||
|
|
|
@ -20,5 +20,5 @@
|
|||
#include "libc/runtime/runtime.h"
|
||||
|
||||
wontreturn void _log_exit(int exitcode) {
|
||||
_Exitr(exitcode);
|
||||
_Exit(exitcode);
|
||||
}
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2023 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/sysv/consts/f.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
|
||||
static int __klog_fd;
|
||||
extern long __klog_handle;
|
||||
|
||||
/**
|
||||
* Redirects kprintf(), `--strace`, etc. output to file.
|
||||
*
|
||||
* @param path is filename to append to; if null is specified then
|
||||
* this file logging facility will be disabled; when the empty
|
||||
* string is specified, then the default path shall be used
|
||||
* @return 0 on success, or -1 w/ errno
|
||||
*/
|
||||
int LogKprintfToFile(const char *path) {
|
||||
int fd, dd;
|
||||
if (!path) {
|
||||
if (__klog_fd) {
|
||||
__klog_handle = 0;
|
||||
close(__klog_fd);
|
||||
__klog_fd = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (!*path) path = "/tmp/kprintf.log";
|
||||
fd = open(path, O_WRONLY | O_APPEND | O_CREAT, 0644);
|
||||
if (fd == -1) return -1;
|
||||
dd = fcntl(fd, F_DUPFD_CLOEXEC, 100);
|
||||
close(fd);
|
||||
if (dd == -1) return -1;
|
||||
if (__klog_fd) close(__klog_fd);
|
||||
__klog_fd = dd;
|
||||
__klog_handle = IsWindows() ? g_fds.p[dd].handle : dd;
|
||||
return 0;
|
||||
}
|
|
@ -239,11 +239,11 @@ relegated void ShowCrashReport(int err, int sig, struct siginfo *si,
|
|||
p = ShowGeneralRegisters(p, ctx);
|
||||
p = ShowSseRegisters(p, ctx);
|
||||
*p++ = '\n';
|
||||
_klog(buf, p - buf);
|
||||
klog(buf, p - buf);
|
||||
ShowFunctionCalls(ctx);
|
||||
} else {
|
||||
*p++ = '\n';
|
||||
_klog(buf, p - buf);
|
||||
klog(buf, p - buf);
|
||||
}
|
||||
kprintf("\n");
|
||||
if (!IsWindows()) __print_maps();
|
||||
|
@ -275,7 +275,7 @@ static wontreturn relegated dontinstrument void __minicrash(int sig,
|
|||
kind, sig, __argv[0], ctx ? ctx->uc_mcontext.rip : 0,
|
||||
ctx ? ctx->uc_mcontext.rsp : 0, ctx ? ctx->uc_mcontext.rbp : 0, __pid,
|
||||
__tls_enabled ? __get_tls()->tib_tid : sys_gettid());
|
||||
_Exitr(119);
|
||||
_Exit(119);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -334,7 +334,7 @@ relegated void __oncrash_amd64(int sig, struct siginfo *si, void *arg) {
|
|||
if (!(gdbpid > 0 && (sig == SIGTRAP || sig == SIGQUIT))) {
|
||||
__restore_tty();
|
||||
ShowCrashReport(err, sig, si, ctx);
|
||||
_Exitr(128 + sig);
|
||||
_Exit(128 + sig);
|
||||
}
|
||||
atomic_store_explicit(&once, 0, memory_order_relaxed);
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue