mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-01 00:38:31 +00:00
Make improvements
- Introduce portable sched_getcpu() api - Support GCC's __target_clones__ feature - Make fma() go faster on x86 in default mode - Remove some asan checks from core libraries - WinMain() now ensures $HOME and $USER are defined
This commit is contained in:
parent
d5225a693b
commit
2ab9e9f7fd
192 changed files with 2809 additions and 932 deletions
|
@ -24,6 +24,7 @@
|
|||
#include "libc/limits.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/nexgen32e/rdtsc.h"
|
||||
#include "libc/nt/accounting.h"
|
||||
#include "libc/nt/console.h"
|
||||
#include "libc/nt/enum/consolemodeflags.h"
|
||||
#include "libc/nt/enum/filemapflags.h"
|
||||
|
@ -59,6 +60,7 @@ __msabi extern typeof(GetEnvironmentStrings) *const __imp_GetEnvironmentStringsW
|
|||
__msabi extern typeof(GetEnvironmentVariable) *const __imp_GetEnvironmentVariableW;
|
||||
__msabi extern typeof(GetFileAttributes) *const __imp_GetFileAttributesW;
|
||||
__msabi extern typeof(GetStdHandle) *const __imp_GetStdHandle;
|
||||
__msabi extern typeof(GetUserName) *const __imp_GetUserNameW;
|
||||
__msabi extern typeof(MapViewOfFileEx) *const __imp_MapViewOfFileEx;
|
||||
__msabi extern typeof(SetConsoleCP) *const __imp_SetConsoleCP;
|
||||
__msabi extern typeof(SetConsoleMode) *const __imp_SetConsoleMode;
|
||||
|
@ -142,6 +144,11 @@ static abi void DeduplicateStdioHandles(void) {
|
|||
}
|
||||
}
|
||||
|
||||
static bool32 HasEnvironmentVariable(const char16_t *name) {
|
||||
char16_t buf[4];
|
||||
return __imp_GetEnvironmentVariableW(name, buf, ARRAYLEN(buf));
|
||||
}
|
||||
|
||||
// main function of windows init process
|
||||
// i.e. first process spawned that isn't forked
|
||||
static abi wontreturn void WinInit(const char16_t *cmdline) {
|
||||
|
@ -168,12 +175,6 @@ static abi wontreturn void WinInit(const char16_t *cmdline) {
|
|||
}
|
||||
}
|
||||
|
||||
// avoid programs like emacs nagging the user to define this
|
||||
char16_t var[8];
|
||||
if (!__imp_GetEnvironmentVariableW(u"TERM", var, 8)) {
|
||||
__imp_SetEnvironmentVariableW(u"TERM", u"xterm-256color");
|
||||
}
|
||||
|
||||
// allocate memory for stack and argument block
|
||||
_mmi.p = _mmi.s;
|
||||
_mmi.n = ARRAYLEN(_mmi.s);
|
||||
|
@ -200,6 +201,34 @@ static abi wontreturn void WinInit(const char16_t *cmdline) {
|
|||
struct WinArgs *wa =
|
||||
(struct WinArgs *)(stackaddr + (stacksize - sizeof(struct WinArgs)));
|
||||
|
||||
// define $TERM if it's not already present
|
||||
// programs like emacs will stop the world and nag if it's not set
|
||||
if (!HasEnvironmentVariable(u"TERM")) {
|
||||
__imp_SetEnvironmentVariableW(u"TERM", u"xterm-256color");
|
||||
}
|
||||
|
||||
// define $USER as GetUserName() if not set
|
||||
// Windows doesn't define this environment variable by default
|
||||
uint32_t vsize = ARRAYLEN(wa->tmp16);
|
||||
if (!HasEnvironmentVariable(u"USER") &&
|
||||
__imp_GetUserNameW(&wa->tmp16, &vsize)) {
|
||||
__imp_SetEnvironmentVariableW(u"USER", wa->tmp16);
|
||||
}
|
||||
|
||||
// define $HOME as $HOMEDRIVE$HOMEPATH if not set
|
||||
// Windows doesn't define this environment variable by default
|
||||
uint32_t vlen;
|
||||
if (!HasEnvironmentVariable(u"HOME") &&
|
||||
(vlen = __imp_GetEnvironmentVariableW(u"HOMEDRIVE", wa->tmp16,
|
||||
ARRAYLEN(wa->tmp16))) <
|
||||
ARRAYLEN(wa->tmp16) &&
|
||||
(vlen += __imp_GetEnvironmentVariableW(u"HOMEPATH", wa->tmp16 + vlen,
|
||||
ARRAYLEN(wa->tmp16) - vlen)) <
|
||||
ARRAYLEN(wa->tmp16) &&
|
||||
vlen) {
|
||||
__imp_SetEnvironmentVariableW(u"HOME", wa->tmp16);
|
||||
}
|
||||
|
||||
// parse utf-16 command into utf-8 argv array in argument block
|
||||
int count = GetDosArgv(cmdline, wa->argblock, ARRAYLEN(wa->argblock),
|
||||
wa->argv, ARRAYLEN(wa->argv));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue