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:
Justine Tunney 2023-08-19 06:41:06 -07:00
parent 9c7b81ee0f
commit 965516e313
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
108 changed files with 1126 additions and 807 deletions

View file

@ -19,29 +19,30 @@
#include "libc/dce.h"
#include "libc/intrin/promises.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h"
#include "libc/nexgen32e/vendor.internal.h"
#include "libc/nt/enum/status.h"
#include "libc/nt/runtime.h"
#include "libc/runtime/internal.h"
#include "libc/runtime/runtime.h"
#include "libc/sysv/consts/nr.h"
/**
* Terminates process, ignoring destructors and atexit() handlers.
*
* When running on bare metal, this function will reboot your computer
* by hosing the interrupt descriptors and triple faulting the system.
*
* Exit codes are narrowed to an unsigned char on most platforms. The
* exceptions would be Windows, NetBSD, and OpenBSD, which should let
* you have larger exit codes.
*
* When running on bare metal, this function will reboot your computer
* by hosing the interrupt descriptors and triple faulting the system.
*
* @asyncsignalsafe
* @threadsafe
* @vforksafe
* @noreturn
*/
wontreturn void _Exit(int exitcode) {
int i;
STRACE("_Exit(%d)", exitcode);
if (!IsWindows() && !IsMetal()) {
// On Linux _Exit1 (exit) must be called in pledge("") mode. If we
@ -84,19 +85,24 @@ wontreturn void _Exit(int exitcode) {
#endif
} else if (IsWindows()) {
uint32_t waitstatus;
// Restoring the CMD.EXE program to its original state is critical.
if (_weaken(__restore_console_win32)) {
_weaken(__restore_console_win32)();
}
// What Microsoft calls an exit code, POSIX calls a status code. See
// also the WEXITSTATUS() and WIFEXITED() macros that POSIX defines.
waitstatus = exitcode;
waitstatus <<= 8;
// "The GetExitCodeProcess function returns a valid error code
// defined by the application only after the thread terminates.
// Therefore, an application should not use kNtStillActive (259) as
// an error code (kNtStillActive is a macro for kNtStatusPending).
// If a thread returns kNtStillActive (259) as an error code, then
// applications that test for that value could interpret it to mean
// that the thread is still running, and continue to test for the
// completion of the thread after the thread has terminated, which
// could put the application into an infinite loop." -Quoth MSDN
if (waitstatus == kNtStillActive) {
// The GetExitCodeProcess function returns a valid error code
// defined by the application only after the thread terminates.
// Therefore, an application should not use STILL_ACTIVE (259) as
// an error code (STILL_ACTIVE is a macro for STATUS_PENDING
// (minwinbase.h)). If a thread returns STILL_ACTIVE (259) as an
// error code, then applications that test for that value could
// interpret it to mean that the thread is still running, and
// continue to test for the completion of the thread after the
// thread has terminated, which could put the application into an
// infinite loop. -Quoth MSDN (see also libc/calls/wait4-nt.c)
waitstatus = 0xc9af3d51u;
}
ExitProcess(waitstatus);