mirror of
https://github.com/jart/cosmopolitan.git
synced 2026-11-10 02:31:35 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
df68a6362b | ||
|
|
19c81863a3 | ||
|
|
7d31fc311a | ||
|
|
57c0b065c8 | ||
|
|
a6ecbb747d | ||
|
|
3bf95ae7ec | ||
|
|
5fd7b07fac | ||
|
|
317c8bc312 | ||
|
|
2a1f352622 | ||
|
|
06d916b449 | ||
|
|
9ea64725b6 | ||
|
|
f9fc7eb49f | ||
|
|
b0df6c1fce | ||
|
|
d5ebb1fa5b |
No files matched your search
@@ -258,7 +258,7 @@ include libc/thread/BUILD.mk # │ You can finally call malloc()
|
||||
include third_party/zlib/BUILD.mk # │
|
||||
include libc/stdio/BUILD.mk # │
|
||||
include tool/hello/BUILD.mk # │
|
||||
include libc/time/BUILD.mk # │
|
||||
include third_party/tz/BUILD.mk # │
|
||||
include net/BUILD.mk # │
|
||||
include third_party/vqsort/BUILD.mk # │
|
||||
include libc/log/BUILD.mk # │
|
||||
@@ -440,7 +440,7 @@ COSMOPOLITAN_OBJECTS = \
|
||||
LIBC_X \
|
||||
THIRD_PARTY_GETOPT \
|
||||
LIBC_LOG \
|
||||
LIBC_TIME \
|
||||
THIRD_PARTY_TZ \
|
||||
THIRD_PARTY_OPENMP \
|
||||
THIRD_PARTY_MUSL \
|
||||
THIRD_PARTY_ZLIB_GZ \
|
||||
@@ -505,7 +505,6 @@ COSMOPOLITAN_H_PKGS = \
|
||||
LIBC_STR \
|
||||
LIBC_SYSV \
|
||||
LIBC_THREAD \
|
||||
LIBC_TIME \
|
||||
LIBC_TINYMATH \
|
||||
LIBC_X \
|
||||
LIBC_VGA \
|
||||
|
||||
+8
-1
@@ -146,6 +146,9 @@ struct Syslib {
|
||||
#define AT_RANDOM 25
|
||||
#define AT_EXECFN 31
|
||||
|
||||
#define EF_APE_MODERN 0x101ca75
|
||||
#define EF_APE_MODERN_MASK 0x1ffffff
|
||||
|
||||
#define AUXV_WORDS 31
|
||||
|
||||
/* from the xnu codebase */
|
||||
@@ -799,7 +802,7 @@ __attribute__((__noreturn__)) static void Spawn(const char *exe, int fd,
|
||||
}
|
||||
|
||||
static const char *TryElf(struct ApeLoader *M, union ElfEhdrBuf *ebuf,
|
||||
const char *exe, int fd, long *sp, long *auxv,
|
||||
char *exe, int fd, long *sp, long *auxv,
|
||||
char *execfn) {
|
||||
long i, rc;
|
||||
unsigned size;
|
||||
@@ -820,6 +823,10 @@ static const char *TryElf(struct ApeLoader *M, union ElfEhdrBuf *ebuf,
|
||||
if (e->e_machine != EM_AARCH64) {
|
||||
return "couldn't find ELF header with ARM64 machine type";
|
||||
}
|
||||
if ((e->e_flags & EF_APE_MODERN_MASK) != EF_APE_MODERN && sp[0] > 0) {
|
||||
/* change argv[0] to resolved path for older binaries */
|
||||
((char **)(sp + 1))[0] = exe;
|
||||
}
|
||||
if (e->e_phentsize != sizeof(struct ElfPhdr)) {
|
||||
Pexit(exe, 0, "e_phentsize is wrong");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│ vi: set noet ft=asm ts=8 sw=8 fenc=utf-8 :vi │
|
||||
│ vi: set noet ft=asm ts=8 sw=8 fenc=utf-8 nofixeol :vi │
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
@@ -196,7 +196,7 @@ ape_mz:
|
||||
.quad ape_elf_entry // 18: e_entry
|
||||
.quad ape_elf_phoff // 20: e_phoff
|
||||
.quad ape_elf_shoff // 28: e_shoff
|
||||
.long 0 // 30: e_flags
|
||||
.long 0x101ca75 // 30: ape e_flags
|
||||
.short 64 // 34: e_ehsize
|
||||
.short 56 // 36: e_phentsize
|
||||
.short ape_elf_phnum // 38: e_phnum
|
||||
@@ -669,7 +669,7 @@ apesh: .ascii "\n@\n#'\"\n" // sixth edition shebang
|
||||
.shstub ape_elf_entry,8 // 18: e_entry
|
||||
.shstub ape_elf_phoff,8 // 20: e_phoff
|
||||
.shstub ape_elf_shoff,8 // 28: e_shoff
|
||||
.ascii "\\0\\0\\0\\0" // 30: e_flags
|
||||
.ascii "\\165\\312\\1\\1" // 30: ape e_flags
|
||||
.ascii "\\100\\0" // 34: e_ehsize
|
||||
.ascii "\\070\\0" // 36: e_phentsize
|
||||
.shstub ape_elf_phnum,2 // 38: e_phnum
|
||||
|
||||
@@ -152,6 +152,9 @@
|
||||
#define PR_SET_MM 35
|
||||
#define PR_SET_MM_EXE_FILE 13
|
||||
|
||||
#define EF_APE_MODERN 0x101ca75
|
||||
#define EF_APE_MODERN_MASK 0x1ffffff
|
||||
|
||||
#define READ32(S) \
|
||||
((unsigned)(255 & (S)[3]) << 030 | (unsigned)(255 & (S)[2]) << 020 | \
|
||||
(unsigned)(255 & (S)[1]) << 010 | (unsigned)(255 & (S)[0]) << 000)
|
||||
@@ -834,6 +837,10 @@ static const char *TryElf(struct ApeLoader *M, union ElfEhdrBuf *ebuf,
|
||||
return "couldn't find ELF header with x86-64 machine type";
|
||||
}
|
||||
#endif
|
||||
if ((e->e_flags & EF_APE_MODERN_MASK) != EF_APE_MODERN && sp[0] > 0) {
|
||||
/* change argv[0] to resolved path for older binaries */
|
||||
((char **)(sp + 1))[0] = exe;
|
||||
}
|
||||
if (e->e_phentsize != sizeof(struct ElfPhdr)) {
|
||||
Pexit(os, exe, 0, "e_phentsize is wrong");
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -35,7 +35,6 @@ DSP_MPEG_A_DIRECTDEPS = \
|
||||
LIBC_STDIO \
|
||||
LIBC_STR \
|
||||
LIBC_SYSV \
|
||||
LIBC_TIME \
|
||||
LIBC_TINYMATH \
|
||||
THIRD_PARTY_COMPILER_RT
|
||||
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@
|
||||
#include "libc/math.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
#include "libc/x/x.h"
|
||||
__static_yoink("pl_mpeg_notice");
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ DSP_SCALE_A_DIRECTDEPS = \
|
||||
LIBC_NEXGEN32E \
|
||||
LIBC_RUNTIME \
|
||||
LIBC_STR \
|
||||
LIBC_TIME \
|
||||
LIBC_TINYMATH \
|
||||
LIBC_X
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@ DSP_TTY_A_DIRECTDEPS = \
|
||||
LIBC_SOCK \
|
||||
LIBC_SYSV \
|
||||
LIBC_TINYMATH \
|
||||
LIBC_TIME \
|
||||
LIBC_X
|
||||
|
||||
DSP_TTY_A_DEPS := \
|
||||
|
||||
+3
-2
@@ -65,7 +65,6 @@ EXAMPLES_DIRECTDEPS = \
|
||||
LIBC_SYSV_CALLS \
|
||||
LIBC_TESTLIB \
|
||||
LIBC_THREAD \
|
||||
LIBC_TIME \
|
||||
LIBC_TINYMATH \
|
||||
LIBC_VGA \
|
||||
LIBC_X \
|
||||
@@ -89,6 +88,7 @@ EXAMPLES_DIRECTDEPS = \
|
||||
THIRD_PARTY_SED \
|
||||
THIRD_PARTY_STB \
|
||||
THIRD_PARTY_TR \
|
||||
THIRD_PARTY_TZ \
|
||||
THIRD_PARTY_VQSORT \
|
||||
THIRD_PARTY_XED \
|
||||
THIRD_PARTY_ZLIB \
|
||||
@@ -154,7 +154,8 @@ o/$(MODE)/examples/picol.dbg: \
|
||||
@$(APELINK)
|
||||
|
||||
o/$(MODE)/usr/share/dict/words.zip.o: private ZIPOBJ_FLAGS += -C2
|
||||
o/$(MODE)/examples/wut.o: private COPTS += -fopenmp
|
||||
|
||||
o/$(MODE)/examples/blas.o: private COPTS += -O3 -fopenmp
|
||||
|
||||
$(EXAMPLES_OBJS): examples/BUILD.mk
|
||||
|
||||
|
||||
@@ -0,0 +1,221 @@
|
||||
// Copyright 2024 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 <unistd.h>
|
||||
#include <cinttypes>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include "libc/assert.h"
|
||||
|
||||
// high performance high accuracy matrix multiplication in ansi c
|
||||
|
||||
#define MATH __target_clones("avx512f,fma")
|
||||
|
||||
namespace {
|
||||
namespace ansiBLAS {
|
||||
|
||||
static constexpr int KN = 8;
|
||||
|
||||
struct Vector {
|
||||
double v[KN];
|
||||
};
|
||||
|
||||
Vector load(const float *p) {
|
||||
Vector x;
|
||||
for (int i = 0; i < KN; ++i)
|
||||
x.v[i] = p[i];
|
||||
return x;
|
||||
}
|
||||
|
||||
Vector madd(Vector x, Vector y, Vector s) {
|
||||
for (int i = 0; i < KN; ++i)
|
||||
s.v[i] = fma(x.v[i], y.v[i], s.v[i]);
|
||||
return s;
|
||||
}
|
||||
|
||||
float hsum(Vector x) {
|
||||
double s = 0;
|
||||
for (int i = 0; i < KN; ++i)
|
||||
s += x.v[i];
|
||||
return s;
|
||||
}
|
||||
|
||||
struct ansiBLAS {
|
||||
public:
|
||||
ansiBLAS(int k, const float *A, int lda, const float *B, int ldb, float *C,
|
||||
int ldc, int ith, int nth)
|
||||
: k(k),
|
||||
A(A),
|
||||
lda(lda),
|
||||
B(B),
|
||||
ldb(ldb),
|
||||
C(C),
|
||||
ldc(ldc),
|
||||
ith(ith),
|
||||
nth(nth) {
|
||||
}
|
||||
|
||||
void matmul(int m, int n) {
|
||||
mnpack(0, m, 0, n);
|
||||
}
|
||||
|
||||
private:
|
||||
void mnpack(int m0, int m, int n0, int n) {
|
||||
int mc, nc, mp, np;
|
||||
if (m - m0 <= 0 || n - n0 <= 0)
|
||||
return;
|
||||
if (m - m0 >= 4 && n - n0 >= 3) {
|
||||
mc = 4;
|
||||
nc = 3;
|
||||
gemm<4, 3>(m0, m, n0, n);
|
||||
} else {
|
||||
mc = 1;
|
||||
nc = 1;
|
||||
gemm<1, 1>(m0, m, n0, n);
|
||||
}
|
||||
mp = m0 + (m - m0) / mc * mc;
|
||||
np = n0 + (n - n0) / nc * nc;
|
||||
mnpack(mp, m, n0, np);
|
||||
mnpack(m0, m, np, n);
|
||||
}
|
||||
|
||||
template <int RM, int RN>
|
||||
MATH void gemm(int m0, int m, int n0, int n) {
|
||||
int ytiles = (m - m0) / RM;
|
||||
int xtiles = (n - n0) / RN;
|
||||
int tiles = xtiles * ytiles;
|
||||
int duty = (tiles + nth - 1) / nth;
|
||||
int start = duty * ith;
|
||||
int end = start + duty;
|
||||
if (end > tiles)
|
||||
end = tiles;
|
||||
for (int job = start; job < end; ++job) {
|
||||
int ii = m0 + job / xtiles * RM;
|
||||
int jj = n0 + job % xtiles * RN;
|
||||
Vector Cv[RN][RM] = {};
|
||||
for (int l = 0; l < k; l += KN)
|
||||
for (int j = 0; j < RN; ++j)
|
||||
for (int i = 0; i < RM; ++i)
|
||||
Cv[j][i] = madd(load(A + lda * (ii + i) + l), //
|
||||
load(B + ldb * (jj + j) + l), //
|
||||
Cv[j][i]);
|
||||
for (int j = 0; j < RN; ++j)
|
||||
for (int i = 0; i < RM; ++i)
|
||||
C[ldc * (jj + j) + (ii + i)] = hsum(Cv[j][i]);
|
||||
}
|
||||
}
|
||||
|
||||
const int k;
|
||||
const float *const A;
|
||||
const int lda;
|
||||
const float *const B;
|
||||
const int ldb;
|
||||
float *const C;
|
||||
const int ldc;
|
||||
const int ith;
|
||||
const int nth;
|
||||
};
|
||||
|
||||
void sgemm(int m, int n, int k, //
|
||||
const float *A, int lda, //
|
||||
const float *B, int ldb, //
|
||||
float *C, int ldc) {
|
||||
int nth = sysconf(_SC_NPROCESSORS_ONLN);
|
||||
#pragma omp parallel for
|
||||
for (int ith = 0; ith < nth; ++ith) {
|
||||
ansiBLAS tb{k, A, lda, B, ldb, C, ldc, ith, nth};
|
||||
tb.matmul(m, n);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ansiBLAS
|
||||
|
||||
long micros(void) {
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_REALTIME, &ts);
|
||||
return ts.tv_sec * 1000000 + (ts.tv_nsec + 999) / 1000;
|
||||
}
|
||||
|
||||
unsigned rand32(void) {
|
||||
/* Knuth, D.E., "The Art of Computer Programming," Vol 2,
|
||||
Seminumerical Algorithms, Third Edition, Addison-Wesley, 1998,
|
||||
p. 106 (line 26) & p. 108 */
|
||||
static unsigned long long lcg = 1;
|
||||
lcg *= 6364136223846793005;
|
||||
lcg += 1442695040888963407;
|
||||
return lcg >> 32;
|
||||
}
|
||||
|
||||
float float01(unsigned x) { // (0,1)
|
||||
return 1.f / 8388608 * ((x >> 9) + .5f);
|
||||
}
|
||||
|
||||
float numba(void) { // (-1,1)
|
||||
return float01(rand32()) * 2 - 1;
|
||||
}
|
||||
|
||||
void fill(int m, int n, float *A, int lda) {
|
||||
for (int j = 0; j < n; ++j)
|
||||
for (int i = 0; i < m; ++i)
|
||||
A[lda * j + i] = numba();
|
||||
}
|
||||
|
||||
float *new_matrix(int m, int n, int *lda) {
|
||||
void *ptr = 0;
|
||||
int b = 64 / sizeof(float);
|
||||
*lda = (n + b - 1) & -b;
|
||||
posix_memalign(&ptr, 4096, sizeof(float) * m * *lda);
|
||||
return (float *)ptr;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void barrier(void) {
|
||||
}
|
||||
void (*pBarrier)(void) = barrier;
|
||||
|
||||
#define BENCH(x) \
|
||||
do { \
|
||||
x; \
|
||||
int N = 10; \
|
||||
long t1 = micros(); \
|
||||
for (long i = 0; i < N; ++i) { \
|
||||
pBarrier(); \
|
||||
x; \
|
||||
} \
|
||||
long t2 = micros(); \
|
||||
printf("%8" PRId64 " µs %s %g gigaflops\n", (t2 - t1 + N - 1) / N, #x, \
|
||||
1e6 / ((t2 - t1 + N - 1) / N) * m * n * k * 2 * 1e-9); \
|
||||
} while (0)
|
||||
|
||||
int main() {
|
||||
int m = 1024;
|
||||
int n = 1024;
|
||||
int k = 1024;
|
||||
int lda, ldb, ldc;
|
||||
float *A = new_matrix(m, k, &lda);
|
||||
float *B = new_matrix(n, k, &ldb);
|
||||
float *C = new_matrix(n, m, &ldc);
|
||||
fill(k, n, A, lda);
|
||||
fill(k, m, B, ldb);
|
||||
BENCH(ansiBLAS::sgemm(m, n, k, A, lda, B, ldb, C, ldc));
|
||||
assert(C[0] == -0x1.20902ap+4);
|
||||
assert(C[1] == -0x1.bf7726p+4);
|
||||
free(C);
|
||||
free(B);
|
||||
free(A);
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
||||
@@ -18,6 +19,17 @@ void crash(long x0, long x1, long x2, //
|
||||
void (*pCrash)(long, long, long, double, double, double) = crash;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
// // by default we launch an addr2line subprocess to print backtraces
|
||||
// // with line numbers. you can force it to use the embedded solution
|
||||
// setenv("ADDR2LINE", "", true);
|
||||
|
||||
// // using a seccomp sandbox is another way to force embedded backtraces
|
||||
// pledge("stdio", NULL);
|
||||
|
||||
// enable the crash reporting feature
|
||||
ShowCrashReports();
|
||||
|
||||
// time to die
|
||||
pCrash(1, 2, 3, NAN, NAN, NAN);
|
||||
}
|
||||
+25
-4
@@ -9,19 +9,30 @@
|
||||
#endif
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/nt/enum/timezoneid.h"
|
||||
#include "libc/nt/struct/timezoneinformation.h"
|
||||
#include "libc/nt/time.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/time/struct/tm.h"
|
||||
#include "libc/thread/threads.h"
|
||||
#include "libc/time.h"
|
||||
|
||||
/**
|
||||
* @fileoverview High performance ISO-8601 timestamp formatter.
|
||||
*
|
||||
* The strftime() function is very slow. This goes much faster.
|
||||
* Consider using something like this instead for your loggers.
|
||||
*/
|
||||
|
||||
char *GetTimestamp(void) {
|
||||
int x;
|
||||
struct timespec ts;
|
||||
_Thread_local static long last;
|
||||
_Thread_local static char s[27];
|
||||
_Thread_local static struct tm tm;
|
||||
thread_local static long last;
|
||||
thread_local static char s[32];
|
||||
thread_local static struct tm tm;
|
||||
clock_gettime(0, &ts);
|
||||
if (ts.tv_sec != last) {
|
||||
localtime_r(&ts.tv_sec, &tm);
|
||||
@@ -61,11 +72,21 @@ char *GetTimestamp(void) {
|
||||
s[23] = '0' + x / 100000 % 10;
|
||||
s[24] = '0' + x / 10000 % 10;
|
||||
s[25] = '0' + x / 1000 % 10;
|
||||
s[26] = tm.tm_gmtoff < 0 ? '-' : '+';
|
||||
x = ABS(tm.tm_gmtoff) / 60 / 60;
|
||||
s[27] = '0' + x / 10 % 10;
|
||||
s[28] = '0' + x % 10;
|
||||
x = ABS(tm.tm_gmtoff) / 60 % 60;
|
||||
s[29] = '0' + x / 10 % 10;
|
||||
s[30] = '0' + x % 10;
|
||||
return s;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char buf[128], *p = buf;
|
||||
// setenv("TZ", "UTC", true);
|
||||
// setenv("TZ", "US/Eastern", true);
|
||||
// setenv("TZ", "Asia/Kolkata", true);
|
||||
p = stpcpy(p, GetTimestamp());
|
||||
p = stpcpy(p, "\n");
|
||||
write(1, buf, p - buf);
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@
|
||||
#include "libc/stdio/rand.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
#include "third_party/zlib/zlib.h"
|
||||
// clang-format off
|
||||
|
||||
|
||||
+1
-1
@@ -71,7 +71,7 @@ Contact: [email protected]");
|
||||
#include "libc/sysv/consts/fileno.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/consts/termios.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
|
||||
/* Syntax highlight types */
|
||||
#define HL_NORMAL 0
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
#if 0
|
||||
/*─────────────────────────────────────────────────────────────────╗
|
||||
│ To the extent possible under law, Justine Tunney has waived │
|
||||
│ all copyright and related or neighboring rights to this file, │
|
||||
│ as it is written in the following disclaimers: │
|
||||
│ • http://unlicense.org/ │
|
||||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "libc/time.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int64_t t = 0;
|
||||
localtime(&t);
|
||||
}
|
||||
+1
-1
@@ -44,7 +44,7 @@
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/sysv/consts/w.h"
|
||||
#include "libc/thread/thread.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
#include "libc/x/xasprintf.h"
|
||||
#include "libc/x/xsigaction.h"
|
||||
#include "libc/zip.internal.h"
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@
|
||||
#include "libc/sysv/consts/fileno.h"
|
||||
#include "libc/sysv/consts/s.h"
|
||||
#include "libc/sysv/consts/termios.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
#include "third_party/getopt/getopt.internal.h"
|
||||
// clang-format off
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include "libc/sysv/consts/itimer.h"
|
||||
#include "libc/sysv/consts/sa.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
|
||||
volatile bool gotalrm;
|
||||
|
||||
|
||||
+30
-11
@@ -8,16 +8,18 @@
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "libc/calls/struct/stat.h"
|
||||
#include "libc/assert.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/mem/gc.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/s.h"
|
||||
#include "libc/x/xiso8601.h"
|
||||
#include "libc/time.h"
|
||||
|
||||
/**
|
||||
* @fileoverview File metadata viewer.
|
||||
@@ -27,6 +29,23 @@
|
||||
|
||||
bool numeric;
|
||||
|
||||
char *xiso8601(struct timespec ts) {
|
||||
struct tm tm;
|
||||
if (!localtime_r(&ts.tv_sec, &tm))
|
||||
return 0;
|
||||
int len = 128;
|
||||
char *res = malloc(len);
|
||||
char *ptr = res;
|
||||
char *end = res + len;
|
||||
if (!res)
|
||||
return 0;
|
||||
ptr += strftime(ptr, end - ptr, "%Y-%m-%d %H:%M:%S", &tm);
|
||||
ptr += snprintf(ptr, end - ptr, ".%09ld", ts.tv_nsec);
|
||||
ptr += strftime(ptr, end - ptr, "%z %Z", &tm);
|
||||
unassert(ptr + 1 <= end);
|
||||
return res;
|
||||
}
|
||||
|
||||
const char *DescribeFileType(unsigned mode) {
|
||||
switch (mode & S_IFMT) {
|
||||
case S_IFIFO:
|
||||
@@ -74,16 +93,16 @@ void PrintFileMetadata(const char *pathname, struct stat *st) {
|
||||
"%-32s%s\n"
|
||||
"%-32s%s\n"
|
||||
"%-32s%s\n",
|
||||
"bytes in file", st->st_size, "physical bytes", st->st_blocks * 512,
|
||||
"device id w/ file", st->st_dev, "inode", st->st_ino,
|
||||
"hard link count", st->st_nlink, "mode / permissions", st->st_mode,
|
||||
DescribeFileType(st->st_mode), "owner id", st->st_uid, "group id",
|
||||
st->st_gid, "flags", st->st_flags, "gen", st->st_gen,
|
||||
"device id (if special)", st->st_rdev, "block size", st->st_blksize,
|
||||
"access time", gc(xiso8601(&st->st_atim)), "modified time",
|
||||
gc(xiso8601(&st->st_mtim)), "c[omplicated]time",
|
||||
gc(xiso8601(&st->st_ctim)), "birthtime",
|
||||
gc(xiso8601(&st->st_birthtim)));
|
||||
"bytes in file:", st->st_size, "physical bytes:", st->st_blocks * 512,
|
||||
"device id w/ file:", st->st_dev, "inode:", st->st_ino,
|
||||
"hard link count:", st->st_nlink, "mode / permissions:", st->st_mode,
|
||||
DescribeFileType(st->st_mode), "owner id:", st->st_uid,
|
||||
"group id:", st->st_gid, "flags:", st->st_flags, "gen:", st->st_gen,
|
||||
"device id (if special):", st->st_rdev, "block size:", st->st_blksize,
|
||||
"access time:", gc(xiso8601(st->st_atim)),
|
||||
"modified time:", gc(xiso8601(st->st_mtim)),
|
||||
"c[omplicated]time:", gc(xiso8601(st->st_ctim)),
|
||||
"[birthtime]:", gc(xiso8601(st->st_birthtim)));
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/time/struct/tm.h"
|
||||
#include "libc/time.h"
|
||||
#include "third_party/getopt/getopt.internal.h"
|
||||
#include "third_party/musl/passwd.h"
|
||||
|
||||
|
||||
@@ -300,7 +300,6 @@ o/$(MODE)/libc: o/$(MODE)/libc/calls \
|
||||
o/$(MODE)/libc/sysv \
|
||||
o/$(MODE)/libc/testlib \
|
||||
o/$(MODE)/libc/thread \
|
||||
o/$(MODE)/libc/time \
|
||||
o/$(MODE)/libc/tinymath \
|
||||
o/$(MODE)/libc/vga \
|
||||
o/$(MODE)/libc/x \
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/sysv/consts/clock.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
|
||||
static int sys_clock_getres_poly(int clock, struct timespec *ts, int64_t real,
|
||||
int64_t real_coarse, int64_t boot) {
|
||||
|
||||
File renamed without changes.
@@ -19,7 +19,7 @@
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/calls/struct/timeval.h"
|
||||
#include "libc/sysv/consts/clock.h"
|
||||
#include "libc/time/struct/timezone.h"
|
||||
#include "libc/time.h"
|
||||
|
||||
/**
|
||||
* Returns system wall time in microseconds, e.g.
|
||||
|
||||
+16
-12
@@ -24,11 +24,13 @@
|
||||
#include "libc/calls/syscall-sysv.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/kprintf.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/runtime/runtime.h"
|
||||
#include "libc/runtime/symbols.internal.h"
|
||||
#include "libc/runtime/zipos.internal.h"
|
||||
#include "libc/sysv/consts/pr.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
@@ -199,22 +201,22 @@
|
||||
* `__pledge_mode` is available to improve the experience of pledge() on
|
||||
* Linux. It should specify one of the following penalties:
|
||||
*
|
||||
* - `PLEDGE_PENALTY_RETURN_EPERM` causes system calls to just return an
|
||||
* `EPERM` error instead of killing. This is the default on Linux.
|
||||
* This is a gentler solution that allows code to display a friendly
|
||||
* warning. Please note this may lead to weird behaviors if the
|
||||
* software being sandboxed is lazy about checking error results.
|
||||
*
|
||||
* - `PLEDGE_PENALTY_KILL_THREAD` causes the violating thread to be
|
||||
* killed. This is the default on Linux. It's effectively the same as
|
||||
* killing the process, since redbean has no threads. The termination
|
||||
* signal can't be caught and will be either `SIGSYS` or `SIGABRT`.
|
||||
* Consider enabling stderr logging below so you'll know why your
|
||||
* program failed. Otherwise check the system log.
|
||||
* killed. It's effectively the same as killing the process, since
|
||||
* redbean has no threads. The termination signal can't be caught and
|
||||
* will be either `SIGSYS` or `SIGABRT`. Consider enabling stderr
|
||||
* logging below so you'll know why your program failed. Otherwise
|
||||
* check the system log.
|
||||
*
|
||||
* - `PLEDGE_PENALTY_KILL_PROCESS` causes the process and all its
|
||||
* threads to be killed. This is always the case on OpenBSD.
|
||||
*
|
||||
* - `PLEDGE_PENALTY_RETURN_EPERM` causes system calls to just return an
|
||||
* `EPERM` error instead of killing. This is a gentler solution that
|
||||
* allows code to display a friendly warning. Please note this may
|
||||
* lead to weird behaviors if the software being sandboxed is lazy
|
||||
* about checking error results.
|
||||
*
|
||||
* `mode` may optionally bitwise or the following flags:
|
||||
*
|
||||
* - `PLEDGE_STDERR_LOGGING` enables friendly error message logging
|
||||
@@ -240,6 +242,8 @@
|
||||
int pledge(const char *promises, const char *execpromises) {
|
||||
int e, rc;
|
||||
unsigned long ipromises, iexecpromises;
|
||||
if (_weaken(GetSymbolTable))
|
||||
_weaken(GetSymbolTable)();
|
||||
if (!promises) {
|
||||
// OpenBSD says NULL argument means it doesn't change, i.e.
|
||||
// pledge(0,0) on OpenBSD does nothing. The Cosmopolitan Libc
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
#include "libc/time/struct/timezone.h"
|
||||
#include "libc/time.h"
|
||||
|
||||
/**
|
||||
* Changes time.
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@
|
||||
#include "libc/sysv/consts/clock.h"
|
||||
#include "libc/thread/posixthread.internal.h"
|
||||
#include "libc/thread/thread.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
|
||||
/**
|
||||
* Sleeps for particular number of seconds.
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/struct/timeval.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
|
||||
/**
|
||||
* Changes time, the old fashioned way.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMEVAL_H_
|
||||
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMEVAL_H_
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/time/struct/timezone.h"
|
||||
#include "libc/time.h"
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
struct timeval {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMEVAL_INTERNAL_H_
|
||||
#include "libc/calls/struct/timeval.h"
|
||||
#include "libc/mem/alloca.h"
|
||||
#include "libc/time/struct/timezone.h"
|
||||
#include "libc/time.h"
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
int sys_settimeofday(const struct timeval *, const struct timezone *);
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
#include "libc/calls/struct/timeval.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/asan.internal.h"
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/sysv/consts/clock.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
|
||||
/**
|
||||
* Returns high-precision timestamp, the C11 way.
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/sysv/consts/clock.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
|
||||
/**
|
||||
* Returns high-precision timestamp granularity, the C23 way.
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@
|
||||
#include "libc/sysv/consts/clock.h"
|
||||
#include "libc/sysv/consts/utime.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
|
||||
/**
|
||||
* Sleeps for particular number of microseconds.
|
||||
|
||||
+1
-1
@@ -16,8 +16,8 @@
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/utime.h"
|
||||
#include "libc/calls/struct/timeval.h"
|
||||
#include "libc/time/struct/utimbuf.h"
|
||||
|
||||
/**
|
||||
* Changes last accessed/modified times on file.
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
#include "libc/sysv/consts/at.h"
|
||||
#include "libc/sysv/consts/utime.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
|
||||
static textwindows int sys_utimensat_nt_impl(int dirfd, const char *path,
|
||||
const struct timespec ts[2],
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/runtime/zipos.internal.h"
|
||||
#include "libc/sysv/consts/at.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
|
||||
int sys_utimensat(int dirfd, const char *path, const struct timespec ts[2],
|
||||
int flags) {
|
||||
|
||||
@@ -6,6 +6,8 @@ errno_t cosmo_once(_Atomic(uint32_t) *, void (*)(void));
|
||||
int systemvpe(const char *, char *const[], char *const[]) libcesque;
|
||||
char *GetProgramExecutableName(void);
|
||||
void unleaf(void);
|
||||
int __demangle(char *, const char *, size_t);
|
||||
int __is_mangled(const char *);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* COSMOPOLITAN_LIBC_COSMO_H_ */
|
||||
@@ -85,6 +85,10 @@
|
||||
#define EM_RISCV 243
|
||||
#define EM_BPF 247
|
||||
|
||||
/* the ape flag, "lol cat 5" */
|
||||
#define EF_APE_MODERN 0x101ca75
|
||||
#define EF_APE_MODERN_MASK 0x1ffffff
|
||||
|
||||
#define GRP_COMDAT 1
|
||||
#define STN_UNDEF 0
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#define __COSMOPOLITAN_MAJOR__ 3
|
||||
#define __COSMOPOLITAN_MINOR__ 3
|
||||
#define __COSMOPOLITAN_PATCH__ 4
|
||||
#define __COSMOPOLITAN_PATCH__ 5
|
||||
#define __COSMOPOLITAN__ \
|
||||
(100000000 * __COSMOPOLITAN_MAJOR__ + 1000000 * __COSMOPOLITAN_MINOR__ + \
|
||||
__COSMOPOLITAN_PATCH__)
|
||||
|
||||
@@ -132,6 +132,14 @@ o/$(MODE)/libc/intrin/ktcpoptnames.o: libc/intrin/ktcpoptnames.S
|
||||
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
|
||||
o/$(MODE)/libc/intrin/stackcall.o: libc/intrin/stackcall.S
|
||||
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
|
||||
o/$(MODE)/libc/intrin/kmonthname.o: libc/intrin/kmonthname.S
|
||||
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
|
||||
o/$(MODE)/libc/intrin/kmonthnameshort.o: libc/intrin/kmonthnameshort.S
|
||||
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
|
||||
o/$(MODE)/libc/intrin/kweekdayname.o: libc/intrin/kweekdayname.S
|
||||
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
|
||||
o/$(MODE)/libc/intrin/kweekdaynameshort.o: libc/intrin/kweekdaynameshort.S
|
||||
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
|
||||
|
||||
LIBC_INTRIN_LIBS = $(foreach x,$(LIBC_INTRIN_ARTIFACTS),$($(x)))
|
||||
LIBC_INTRIN_HDRS = $(foreach x,$(LIBC_INTRIN_ARTIFACTS),$($(x)_HDRS))
|
||||
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -21,6 +21,6 @@
|
||||
|
||||
// XXX: should be inherited thread local
|
||||
// see also sys_pledge_linux() which is 100% pure
|
||||
int __pledge_mode;
|
||||
int __pledge_mode = PLEDGE_PENALTY_RETURN_EPERM;
|
||||
unsigned long __promises;
|
||||
unsigned long __execpromises;
|
||||
@@ -16,6 +16,7 @@
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/ubsan.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/intrin/pushpop.internal.h"
|
||||
@@ -241,6 +242,8 @@ static void __ubsan_warning(const struct UbsanSourceLocation *loc,
|
||||
const char *description) {
|
||||
kprintf("%s:%d: %subsan warning: %s is undefined behavior%s\n", loc->file,
|
||||
loc->line, SUBTLE, description, RESET);
|
||||
if (__ubsan_strict)
|
||||
__ubsan_die()();
|
||||
}
|
||||
|
||||
__wur __ubsan_die_f *__ubsan_abort(const struct UbsanSourceLocation *loc,
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef COSMOPOLITAN_LIBC_INTRIN_UBSAN_H_
|
||||
#define COSMOPOLITAN_LIBC_INTRIN_UBSAN_H_
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
extern bool32 __ubsan_strict;
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* COSMOPOLITAN_LIBC_INTRIN_UBSAN_H_ */
|
||||
@@ -1,7 +1,7 @@
|
||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2022 Justine Alexandra Roberts Tunney │
|
||||
│ Copyright 2024 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 │
|
||||
@@ -16,8 +16,8 @@
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/time/time.h"
|
||||
|
||||
char *tzname[2];
|
||||
long timezone;
|
||||
int daylight;
|
||||
/**
|
||||
* If set to true, UBSAN warnings will become fatal.
|
||||
*/
|
||||
bool32 __ubsan_strict = false;
|
||||
+2
-135
@@ -12,135 +12,9 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
#if defined(__x86_64__) && (defined(__GNUC__) || defined(__clang__))
|
||||
#include "libc/intrin/x86.h"
|
||||
|
||||
enum VendorSignatures {
|
||||
SIG_INTEL = 0x756e6547, // Genu
|
||||
SIG_AMD = 0x68747541, // Auth
|
||||
};
|
||||
|
||||
enum ProcessorVendors {
|
||||
VENDOR_INTEL = 1,
|
||||
VENDOR_AMD,
|
||||
VENDOR_OTHER,
|
||||
VENDOR_MAX
|
||||
};
|
||||
|
||||
enum ProcessorTypes {
|
||||
INTEL_BONNELL = 1,
|
||||
INTEL_CORE2,
|
||||
INTEL_COREI7,
|
||||
AMDFAM10H,
|
||||
AMDFAM15H,
|
||||
INTEL_SILVERMONT,
|
||||
INTEL_KNL,
|
||||
AMD_BTVER1,
|
||||
AMD_BTVER2,
|
||||
AMDFAM17H,
|
||||
INTEL_KNM,
|
||||
INTEL_GOLDMONT,
|
||||
INTEL_GOLDMONT_PLUS,
|
||||
INTEL_TREMONT,
|
||||
AMDFAM19H,
|
||||
ZHAOXIN_FAM7H,
|
||||
INTEL_SIERRAFOREST,
|
||||
INTEL_GRANDRIDGE,
|
||||
INTEL_CLEARWATERFOREST,
|
||||
CPU_TYPE_MAX
|
||||
};
|
||||
|
||||
enum ProcessorSubtypes {
|
||||
INTEL_COREI7_NEHALEM = 1,
|
||||
INTEL_COREI7_WESTMERE,
|
||||
INTEL_COREI7_SANDYBRIDGE,
|
||||
AMDFAM10H_BARCELONA,
|
||||
AMDFAM10H_SHANGHAI,
|
||||
AMDFAM10H_ISTANBUL,
|
||||
AMDFAM15H_BDVER1,
|
||||
AMDFAM15H_BDVER2,
|
||||
AMDFAM15H_BDVER3,
|
||||
AMDFAM15H_BDVER4,
|
||||
AMDFAM17H_ZNVER1,
|
||||
INTEL_COREI7_IVYBRIDGE,
|
||||
INTEL_COREI7_HASWELL,
|
||||
INTEL_COREI7_BROADWELL,
|
||||
INTEL_COREI7_SKYLAKE,
|
||||
INTEL_COREI7_SKYLAKE_AVX512,
|
||||
INTEL_COREI7_CANNONLAKE,
|
||||
INTEL_COREI7_ICELAKE_CLIENT,
|
||||
INTEL_COREI7_ICELAKE_SERVER,
|
||||
AMDFAM17H_ZNVER2,
|
||||
INTEL_COREI7_CASCADELAKE,
|
||||
INTEL_COREI7_TIGERLAKE,
|
||||
INTEL_COREI7_COOPERLAKE,
|
||||
INTEL_COREI7_SAPPHIRERAPIDS,
|
||||
INTEL_COREI7_ALDERLAKE,
|
||||
AMDFAM19H_ZNVER3,
|
||||
INTEL_COREI7_ROCKETLAKE,
|
||||
ZHAOXIN_FAM7H_LUJIAZUI,
|
||||
AMDFAM19H_ZNVER4,
|
||||
INTEL_COREI7_GRANITERAPIDS,
|
||||
INTEL_COREI7_GRANITERAPIDS_D,
|
||||
INTEL_COREI7_ARROWLAKE,
|
||||
INTEL_COREI7_ARROWLAKE_S,
|
||||
INTEL_COREI7_PANTHERLAKE,
|
||||
CPU_SUBTYPE_MAX
|
||||
};
|
||||
|
||||
enum ProcessorFeatures {
|
||||
FEATURE_CMOV = 0,
|
||||
FEATURE_MMX,
|
||||
FEATURE_POPCNT,
|
||||
FEATURE_SSE,
|
||||
FEATURE_SSE2,
|
||||
FEATURE_SSE3,
|
||||
FEATURE_SSSE3,
|
||||
FEATURE_SSE4_1,
|
||||
FEATURE_SSE4_2,
|
||||
FEATURE_AVX,
|
||||
FEATURE_AVX2,
|
||||
FEATURE_SSE4_A,
|
||||
FEATURE_FMA4,
|
||||
FEATURE_XOP,
|
||||
FEATURE_FMA,
|
||||
FEATURE_AVX512F,
|
||||
FEATURE_BMI,
|
||||
FEATURE_BMI2,
|
||||
FEATURE_AES,
|
||||
FEATURE_PCLMUL,
|
||||
FEATURE_AVX512VL,
|
||||
FEATURE_AVX512BW,
|
||||
FEATURE_AVX512DQ,
|
||||
FEATURE_AVX512CD,
|
||||
FEATURE_AVX512ER,
|
||||
FEATURE_AVX512PF,
|
||||
FEATURE_AVX512VBMI,
|
||||
FEATURE_AVX512IFMA,
|
||||
FEATURE_AVX5124VNNIW,
|
||||
FEATURE_AVX5124FMAPS,
|
||||
FEATURE_AVX512VPOPCNTDQ,
|
||||
FEATURE_AVX512VBMI2,
|
||||
FEATURE_GFNI,
|
||||
FEATURE_VPCLMULQDQ,
|
||||
FEATURE_AVX512VNNI,
|
||||
FEATURE_AVX512BITALG,
|
||||
FEATURE_AVX512BF16,
|
||||
FEATURE_AVX512VP2INTERSECT,
|
||||
|
||||
FEATURE_CMPXCHG16B = 46,
|
||||
FEATURE_F16C = 49,
|
||||
FEATURE_LAHF_LM = 54,
|
||||
FEATURE_LM,
|
||||
FEATURE_WP,
|
||||
FEATURE_LZCNT,
|
||||
FEATURE_MOVBE,
|
||||
|
||||
FEATURE_AVX512FP16 = 94,
|
||||
FEATURE_X86_64_BASELINE,
|
||||
FEATURE_X86_64_V2,
|
||||
FEATURE_X86_64_V3,
|
||||
FEATURE_X86_64_V4,
|
||||
CPU_FEATURE_MAX
|
||||
};
|
||||
struct __processor_model __cpu_model;
|
||||
|
||||
// The check below for i386 was copied from clang's cpuid.h (__get_cpuid_max).
|
||||
// Check motivated by bug reports for OpenSSL crashing on CPUs without CPUID
|
||||
@@ -782,13 +656,6 @@ static void getAvailableFeatures(unsigned ECX, unsigned EDX, unsigned MaxLeaf,
|
||||
#undef setFeature
|
||||
}
|
||||
|
||||
struct __processor_model {
|
||||
unsigned int __cpu_vendor;
|
||||
unsigned int __cpu_type;
|
||||
unsigned int __cpu_subtype;
|
||||
unsigned int __cpu_features[1];
|
||||
} __cpu_model = {0, 0, 0, {0}};
|
||||
|
||||
unsigned __cpu_features2[(CPU_FEATURE_MAX - 1) / 32];
|
||||
|
||||
// A constructor function that is sets __cpu_model and __cpu_features2 with
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
#ifndef COSMOPOLITAN_LIBC_INTRIN_X86_H_
|
||||
#define COSMOPOLITAN_LIBC_INTRIN_X86_H_
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
enum VendorSignatures {
|
||||
SIG_INTEL = 0x756e6547, /* Genu */
|
||||
SIG_AMD = 0x68747541, /* Auth */
|
||||
};
|
||||
|
||||
enum ProcessorVendors {
|
||||
VENDOR_INTEL = 1,
|
||||
VENDOR_AMD,
|
||||
VENDOR_OTHER,
|
||||
VENDOR_MAX
|
||||
};
|
||||
|
||||
enum ProcessorTypes {
|
||||
INTEL_BONNELL = 1,
|
||||
INTEL_CORE2,
|
||||
INTEL_COREI7,
|
||||
AMDFAM10H,
|
||||
AMDFAM15H,
|
||||
INTEL_SILVERMONT,
|
||||
INTEL_KNL,
|
||||
AMD_BTVER1,
|
||||
AMD_BTVER2,
|
||||
AMDFAM17H,
|
||||
INTEL_KNM,
|
||||
INTEL_GOLDMONT,
|
||||
INTEL_GOLDMONT_PLUS,
|
||||
INTEL_TREMONT,
|
||||
AMDFAM19H,
|
||||
ZHAOXIN_FAM7H,
|
||||
INTEL_SIERRAFOREST,
|
||||
INTEL_GRANDRIDGE,
|
||||
INTEL_CLEARWATERFOREST,
|
||||
CPU_TYPE_MAX
|
||||
};
|
||||
|
||||
enum ProcessorSubtypes {
|
||||
INTEL_COREI7_NEHALEM = 1,
|
||||
INTEL_COREI7_WESTMERE,
|
||||
INTEL_COREI7_SANDYBRIDGE,
|
||||
AMDFAM10H_BARCELONA,
|
||||
AMDFAM10H_SHANGHAI,
|
||||
AMDFAM10H_ISTANBUL,
|
||||
AMDFAM15H_BDVER1,
|
||||
AMDFAM15H_BDVER2,
|
||||
AMDFAM15H_BDVER3,
|
||||
AMDFAM15H_BDVER4,
|
||||
AMDFAM17H_ZNVER1,
|
||||
INTEL_COREI7_IVYBRIDGE,
|
||||
INTEL_COREI7_HASWELL,
|
||||
INTEL_COREI7_BROADWELL,
|
||||
INTEL_COREI7_SKYLAKE,
|
||||
INTEL_COREI7_SKYLAKE_AVX512,
|
||||
INTEL_COREI7_CANNONLAKE,
|
||||
INTEL_COREI7_ICELAKE_CLIENT,
|
||||
INTEL_COREI7_ICELAKE_SERVER,
|
||||
AMDFAM17H_ZNVER2,
|
||||
INTEL_COREI7_CASCADELAKE,
|
||||
INTEL_COREI7_TIGERLAKE,
|
||||
INTEL_COREI7_COOPERLAKE,
|
||||
INTEL_COREI7_SAPPHIRERAPIDS,
|
||||
INTEL_COREI7_ALDERLAKE,
|
||||
AMDFAM19H_ZNVER3,
|
||||
INTEL_COREI7_ROCKETLAKE,
|
||||
ZHAOXIN_FAM7H_LUJIAZUI,
|
||||
AMDFAM19H_ZNVER4,
|
||||
INTEL_COREI7_GRANITERAPIDS,
|
||||
INTEL_COREI7_GRANITERAPIDS_D,
|
||||
INTEL_COREI7_ARROWLAKE,
|
||||
INTEL_COREI7_ARROWLAKE_S,
|
||||
INTEL_COREI7_PANTHERLAKE,
|
||||
CPU_SUBTYPE_MAX
|
||||
};
|
||||
|
||||
enum ProcessorFeatures {
|
||||
FEATURE_CMOV = 0,
|
||||
FEATURE_MMX,
|
||||
FEATURE_POPCNT,
|
||||
FEATURE_SSE,
|
||||
FEATURE_SSE2,
|
||||
FEATURE_SSE3,
|
||||
FEATURE_SSSE3,
|
||||
FEATURE_SSE4_1,
|
||||
FEATURE_SSE4_2,
|
||||
FEATURE_AVX,
|
||||
FEATURE_AVX2,
|
||||
FEATURE_SSE4_A,
|
||||
FEATURE_FMA4,
|
||||
FEATURE_XOP,
|
||||
FEATURE_FMA,
|
||||
FEATURE_AVX512F,
|
||||
FEATURE_BMI,
|
||||
FEATURE_BMI2,
|
||||
FEATURE_AES,
|
||||
FEATURE_PCLMUL,
|
||||
FEATURE_AVX512VL,
|
||||
FEATURE_AVX512BW,
|
||||
FEATURE_AVX512DQ,
|
||||
FEATURE_AVX512CD,
|
||||
FEATURE_AVX512ER,
|
||||
FEATURE_AVX512PF,
|
||||
FEATURE_AVX512VBMI,
|
||||
FEATURE_AVX512IFMA,
|
||||
FEATURE_AVX5124VNNIW,
|
||||
FEATURE_AVX5124FMAPS,
|
||||
FEATURE_AVX512VPOPCNTDQ,
|
||||
FEATURE_AVX512VBMI2,
|
||||
FEATURE_GFNI,
|
||||
FEATURE_VPCLMULQDQ,
|
||||
FEATURE_AVX512VNNI,
|
||||
FEATURE_AVX512BITALG,
|
||||
FEATURE_AVX512BF16,
|
||||
FEATURE_AVX512VP2INTERSECT,
|
||||
|
||||
FEATURE_CMPXCHG16B = 46,
|
||||
FEATURE_F16C = 49,
|
||||
FEATURE_LAHF_LM = 54,
|
||||
FEATURE_LM,
|
||||
FEATURE_WP,
|
||||
FEATURE_LZCNT,
|
||||
FEATURE_MOVBE,
|
||||
|
||||
FEATURE_AVX512FP16 = 94,
|
||||
FEATURE_X86_64_BASELINE,
|
||||
FEATURE_X86_64_V2,
|
||||
FEATURE_X86_64_V3,
|
||||
FEATURE_X86_64_V4,
|
||||
CPU_FEATURE_MAX
|
||||
};
|
||||
|
||||
struct __processor_model {
|
||||
unsigned __cpu_vendor;
|
||||
unsigned __cpu_type;
|
||||
unsigned __cpu_subtype;
|
||||
unsigned __cpu_features[1];
|
||||
const char *__cpu_march;
|
||||
};
|
||||
|
||||
extern struct __processor_model __cpu_model;
|
||||
|
||||
const char *__cpu_march(unsigned);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* COSMOPOLITAN_LIBC_INTRIN_X86_H_ */
|
||||
@@ -0,0 +1,94 @@
|
||||
// Copyright 2024 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/intrin/x86.h"
|
||||
|
||||
/**
|
||||
* Returns microarchitecture name, e.g.
|
||||
*
|
||||
* puts(__cpu_march(__cpu_model.__cpu_subtype));
|
||||
*
|
||||
*/
|
||||
const char *__cpu_march(unsigned subtype) {
|
||||
switch (subtype) {
|
||||
case INTEL_COREI7_NEHALEM:
|
||||
return "nehalem";
|
||||
case INTEL_COREI7_WESTMERE:
|
||||
return "westmere";
|
||||
case INTEL_COREI7_SANDYBRIDGE:
|
||||
return "sandybridge";
|
||||
case AMDFAM10H_BARCELONA:
|
||||
return "amdfam10";
|
||||
case AMDFAM10H_SHANGHAI:
|
||||
return "amdfam10";
|
||||
case AMDFAM10H_ISTANBUL:
|
||||
return "amdfam10";
|
||||
case AMDFAM15H_BDVER1:
|
||||
return "bdver2";
|
||||
case AMDFAM15H_BDVER2:
|
||||
return "bdver2";
|
||||
case AMDFAM15H_BDVER3:
|
||||
return "bdver3";
|
||||
case AMDFAM15H_BDVER4:
|
||||
return "bdver4";
|
||||
case AMDFAM17H_ZNVER1:
|
||||
return "znver2";
|
||||
case INTEL_COREI7_IVYBRIDGE:
|
||||
return "ivybridge";
|
||||
case INTEL_COREI7_HASWELL:
|
||||
return "haswell";
|
||||
case INTEL_COREI7_BROADWELL:
|
||||
return "broadwell";
|
||||
case INTEL_COREI7_SKYLAKE:
|
||||
return "skylake";
|
||||
case INTEL_COREI7_SKYLAKE_AVX512:
|
||||
return "skylake-avx512";
|
||||
case INTEL_COREI7_CANNONLAKE:
|
||||
return "cannonlake";
|
||||
case INTEL_COREI7_ICELAKE_CLIENT:
|
||||
return "icelake-client";
|
||||
case INTEL_COREI7_ICELAKE_SERVER:
|
||||
return "icelake-server";
|
||||
case AMDFAM17H_ZNVER2:
|
||||
return "znver2";
|
||||
case INTEL_COREI7_CASCADELAKE:
|
||||
return "cascadelake";
|
||||
case INTEL_COREI7_TIGERLAKE:
|
||||
return "tigerlake";
|
||||
case INTEL_COREI7_COOPERLAKE:
|
||||
return "cooperlake";
|
||||
case INTEL_COREI7_SAPPHIRERAPIDS:
|
||||
return "sapphirerapids";
|
||||
case INTEL_COREI7_ALDERLAKE:
|
||||
return "alderlake";
|
||||
case AMDFAM19H_ZNVER3:
|
||||
return "znver3";
|
||||
case INTEL_COREI7_ROCKETLAKE:
|
||||
return "rocketlake";
|
||||
case AMDFAM19H_ZNVER4:
|
||||
return "znver4";
|
||||
case INTEL_COREI7_GRANITERAPIDS:
|
||||
return "graniterapids";
|
||||
case INTEL_COREI7_GRANITERAPIDS_D:
|
||||
return "graniterapids-d";
|
||||
case INTEL_COREI7_ARROWLAKE:
|
||||
return "arrowlake";
|
||||
case INTEL_COREI7_ARROWLAKE_S:
|
||||
return "arrowlake-s";
|
||||
case INTEL_COREI7_PANTHERLAKE:
|
||||
return "pantherlake";
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -7,5 +7,5 @@
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/sysv/consts/s.h"
|
||||
#include "libc/sysv/consts/utime.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
#endif
|
||||
@@ -6,6 +6,5 @@
|
||||
#include "libc/sock/select.h"
|
||||
#include "libc/sysv/consts/clock.h"
|
||||
#include "libc/sysv/consts/itimer.h"
|
||||
#include "libc/time/struct/timezone.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
#endif
|
||||
+1
-2
@@ -7,6 +7,5 @@
|
||||
#include "libc/sysv/consts/clock.h"
|
||||
#include "libc/sysv/consts/sched.h"
|
||||
#include "libc/sysv/consts/timer.h"
|
||||
#include "libc/time/struct/tm.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
#endif /* _TIME_H */
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "libc/sysv/consts/fileno.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/consts/ok.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
#include "libc/unistd.h"
|
||||
#include "third_party/getopt/long1.h"
|
||||
#include "third_party/musl/crypt.h"
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef _UTIME_H
|
||||
#define _UTIME_H
|
||||
#include "libc/time/struct/utimbuf.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/utime.h"
|
||||
#endif /* _UTIME_H */
|
||||
@@ -5,5 +5,5 @@
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/str/unicode.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
#endif /* _WCHAR_H */
|
||||
+2
-2
@@ -39,11 +39,11 @@ LIBC_LOG_A_DIRECTDEPS = \
|
||||
LIBC_SYSV \
|
||||
LIBC_SYSV_CALLS \
|
||||
LIBC_THREAD \
|
||||
LIBC_TIME \
|
||||
LIBC_TINYMATH \
|
||||
THIRD_PARTY_COMPILER_RT \
|
||||
THIRD_PARTY_DLMALLOC \
|
||||
THIRD_PARTY_GDTOA
|
||||
THIRD_PARTY_GDTOA \
|
||||
THIRD_PARTY_TZ
|
||||
|
||||
LIBC_LOG_A_DEPS := \
|
||||
$(call uniq,$(foreach x,$(LIBC_LOG_A_DIRECTDEPS),$($(x))))
|
||||
|
||||
@@ -37,9 +37,14 @@ static struct {
|
||||
} g_addr2line;
|
||||
|
||||
void GetAddr2linePathInit(void) {
|
||||
char *res;
|
||||
int e = errno;
|
||||
const char *path;
|
||||
if (!(path = getenv("ADDR2LINE"))) {
|
||||
const char *env, *cmd, *path;
|
||||
if ((env = getenv("ADDR2LINE"))) {
|
||||
cmd = env;
|
||||
path = env;
|
||||
} else {
|
||||
cmd = "addr2line";
|
||||
path = ADDR2LINE;
|
||||
}
|
||||
char *buf = g_addr2line.buf;
|
||||
@@ -48,12 +53,11 @@ void GetAddr2linePathInit(void) {
|
||||
strlcat(buf, "/", PATH_MAX);
|
||||
}
|
||||
strlcat(buf, path, PATH_MAX);
|
||||
}
|
||||
if (*buf) {
|
||||
g_addr2line.res = buf;
|
||||
res = buf;
|
||||
} else {
|
||||
g_addr2line.res = commandv("addr2line", buf, PATH_MAX);
|
||||
res = commandv(cmd, buf, PATH_MAX);
|
||||
}
|
||||
g_addr2line.res = res;
|
||||
errno = e;
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ static int PrintBacktraceUsingAddr2line(int fd, const struct StackFrame *bp) {
|
||||
}
|
||||
|
||||
if (!PLEDGED(STDIO) || !PLEDGED(EXEC) || !PLEDGED(EXEC)) {
|
||||
ShowHint("won't print addr2line backtrace because pledge");
|
||||
ShowHint("pledge() sandboxing makes backtraces not as good");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
+14
-2
@@ -18,6 +18,7 @@
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/cosmo.h"
|
||||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/intrin/weaken.h"
|
||||
@@ -29,6 +30,7 @@
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/runtime/symbols.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/thread/thread.h"
|
||||
#include "libc/thread/tls.h"
|
||||
|
||||
#define LIMIT 100
|
||||
@@ -47,8 +49,11 @@ dontinstrument dontasan int PrintBacktraceUsingSymbols(
|
||||
int fd, const struct StackFrame *bp, struct SymbolTable *st) {
|
||||
size_t gi;
|
||||
intptr_t addr;
|
||||
const char *name;
|
||||
int i, symbol, addend;
|
||||
static char cxxbuf[8192];
|
||||
struct Garbages *garbage;
|
||||
static pthread_spinlock_t lock;
|
||||
const struct StackFrame *frame;
|
||||
(void)gi;
|
||||
if (!bp)
|
||||
@@ -83,8 +88,15 @@ dontinstrument dontasan int PrintBacktraceUsingSymbols(
|
||||
symbol = 0;
|
||||
addend = 0;
|
||||
}
|
||||
kprintf("%012lx %lx %s%+d\n", frame, addr, __get_symbol_name(st, symbol),
|
||||
addend);
|
||||
if ((name = __get_symbol_name(st, symbol)) && __is_mangled(name)) {
|
||||
pthread_spin_lock(&lock);
|
||||
__demangle(cxxbuf, name, sizeof(cxxbuf));
|
||||
kprintf("%012lx %lx %s%+d\n", frame, addr, cxxbuf, addend);
|
||||
pthread_spin_unlock(&lock);
|
||||
name = cxxbuf;
|
||||
} else {
|
||||
kprintf("%012lx %lx %s%+d\n", frame, addr, name, addend);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
+13
-16
@@ -31,6 +31,7 @@
|
||||
#include "libc/calls/struct/utsname.h"
|
||||
#include "libc/calls/syscall-sysv.internal.h"
|
||||
#include "libc/calls/ucontext.h"
|
||||
#include "libc/cosmo.h"
|
||||
#include "libc/cxxabi.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/atomic.h"
|
||||
@@ -40,7 +41,6 @@
|
||||
#include "libc/log/internal.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/nexgen32e/stackframe.h"
|
||||
#include "libc/runtime/memtrack.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
@@ -178,15 +178,15 @@ static relegated bool AppendFileLine(struct Buffer *b, const char *addr2line,
|
||||
}
|
||||
}
|
||||
|
||||
static relegated char *GetSymbolName(struct SymbolTable *st, int symbol,
|
||||
char **mem, size_t *memsz) {
|
||||
char *s, *t;
|
||||
if ((s = __get_symbol_name(st, symbol)) && //
|
||||
s[0] == '_' && s[1] == 'Z' && //
|
||||
(t = __cxa_demangle(s, *mem, memsz, 0))) {
|
||||
*mem = s = t;
|
||||
}
|
||||
return s;
|
||||
static relegated char *GetSymbolName(struct SymbolTable *st, int symbol) {
|
||||
char *str;
|
||||
static char buf[8192];
|
||||
if (!(str = __get_symbol_name(st, symbol)))
|
||||
return str;
|
||||
if (!__is_mangled(str))
|
||||
return str;
|
||||
__demangle(buf, str, sizeof(buf));
|
||||
return buf;
|
||||
}
|
||||
|
||||
static relegated void __oncrash_impl(int sig, struct siginfo *si,
|
||||
@@ -241,8 +241,6 @@ static relegated void __oncrash_impl(int sig, struct siginfo *si,
|
||||
: (struct StackFrame *)__builtin_frame_address(0)));
|
||||
if (ctx) {
|
||||
long pc;
|
||||
char *mem = 0;
|
||||
size_t memsz = 0;
|
||||
int addend, symbol;
|
||||
const char *debugbin;
|
||||
const char *addr2line;
|
||||
@@ -305,7 +303,7 @@ static relegated void __oncrash_impl(int sig, struct siginfo *si,
|
||||
addend -= st->symbols[symbol].x;
|
||||
Append(b, " ");
|
||||
if (!AppendFileLine(b, addr2line, debugbin, pc)) {
|
||||
Append(b, "%s", GetSymbolName(st, symbol, &mem, &memsz));
|
||||
Append(b, "%s", GetSymbolName(st, symbol));
|
||||
if (addend)
|
||||
Append(b, "%+d", addend);
|
||||
}
|
||||
@@ -327,7 +325,7 @@ static relegated void __oncrash_impl(int sig, struct siginfo *si,
|
||||
addend -= st->symbols[symbol].x;
|
||||
Append(b, " ");
|
||||
if (!AppendFileLine(b, addr2line, debugbin, pc)) {
|
||||
Append(b, "%s", GetSymbolName(st, symbol, &mem, &memsz));
|
||||
Append(b, "%s", GetSymbolName(st, symbol));
|
||||
if (addend)
|
||||
Append(b, "%+d", addend);
|
||||
}
|
||||
@@ -367,13 +365,12 @@ static relegated void __oncrash_impl(int sig, struct siginfo *si,
|
||||
}
|
||||
Append(b, " %016lx fp %lx lr ", fp, pc);
|
||||
if (!AppendFileLine(b, addr2line, debugbin, pc) && st) {
|
||||
Append(b, "%s", GetSymbolName(st, symbol, &mem, &memsz));
|
||||
Append(b, "%s", GetSymbolName(st, symbol));
|
||||
if (addend)
|
||||
Append(b, "%+d", addend);
|
||||
}
|
||||
Append(b, "\n");
|
||||
}
|
||||
free(mem);
|
||||
}
|
||||
b->p[b->n - 1] = '\n';
|
||||
klog(b->p, MIN(b->i, b->n));
|
||||
|
||||
+1
-2
@@ -37,8 +37,7 @@
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/fileno.h"
|
||||
#include "libc/time/struct/tm.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
|
||||
#define kNontrivialSize (8 * 1000 * 1000)
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ LIBC_MEM = $(LIBC_MEM_A_DEPS) $(LIBC_MEM_A)
|
||||
LIBC_MEM_A = o/$(MODE)/libc/mem/mem.a
|
||||
LIBC_MEM_A_FILES := $(wildcard libc/mem/*)
|
||||
LIBC_MEM_A_HDRS = $(filter %.h,$(LIBC_MEM_A_FILES))
|
||||
LIBC_MEM_A_INCS = $(filter %.inc,$(LIBC_MEM_A_FILES))
|
||||
LIBC_MEM_A_SRCS = $(filter %.c,$(LIBC_MEM_A_FILES))
|
||||
LIBC_MEM_A_OBJS = $(LIBC_MEM_A_SRCS:%.c=o/$(MODE)/%.o)
|
||||
|
||||
@@ -46,6 +47,7 @@ $(LIBC_MEM_A_OBJS): private \
|
||||
LIBC_MEM_LIBS = $(foreach x,$(LIBC_MEM_ARTIFACTS),$($(x)))
|
||||
LIBC_MEM_SRCS = $(foreach x,$(LIBC_MEM_ARTIFACTS),$($(x)_SRCS))
|
||||
LIBC_MEM_HDRS = $(foreach x,$(LIBC_MEM_ARTIFACTS),$($(x)_HDRS))
|
||||
LIBC_MEM_INCS = $(foreach x,$(LIBC_MEM_ARTIFACTS),$($(x)_INCS))
|
||||
LIBC_MEM_BINS = $(foreach x,$(LIBC_MEM_ARTIFACTS),$($(x)_BINS))
|
||||
LIBC_MEM_CHECKS = $(foreach x,$(LIBC_MEM_ARTIFACTS),$($(x)_CHECKS))
|
||||
LIBC_MEM_OBJS = $(foreach x,$(LIBC_MEM_ARTIFACTS),$($(x)_OBJS))
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
// Copyright 2024 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/assert.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/stdckdint.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
#ifndef TINYMALLOC_MAX_BYTES
|
||||
#define TINYMALLOC_MAX_BYTES 1073741824
|
||||
#endif
|
||||
|
||||
#ifndef TINYMALLOC_MAX_ALIGN
|
||||
#define TINYMALLOC_MAX_ALIGN 4096
|
||||
#endif
|
||||
|
||||
#ifndef MODE_DBG /* don't interfere with asan dlmalloc hooking */
|
||||
|
||||
_Alignas(TINYMALLOC_MAX_ALIGN) static struct {
|
||||
char memory[TINYMALLOC_MAX_BYTES];
|
||||
unsigned used, last, free;
|
||||
} heap;
|
||||
|
||||
static inline bool isheap(char *mem) {
|
||||
return heap.memory <= mem && mem < heap.memory + heap.used;
|
||||
}
|
||||
|
||||
void free(void *ptr) {
|
||||
char *mem;
|
||||
unsigned base;
|
||||
if (ptr) {
|
||||
mem = (char *)ptr;
|
||||
unassert(isheap(mem));
|
||||
base = mem - heap.memory;
|
||||
*(unsigned *)mem = heap.free;
|
||||
heap.free = base;
|
||||
}
|
||||
}
|
||||
|
||||
size_t malloc_usable_size(void *ptr) {
|
||||
char *mem = (char *)ptr;
|
||||
unassert(isheap(mem));
|
||||
return ((unsigned *)mem)[-1];
|
||||
}
|
||||
|
||||
void *memalign(size_t align, size_t need) {
|
||||
char *res;
|
||||
unsigned next, next2, base, toto, *link, *link2;
|
||||
|
||||
// normalize arguments
|
||||
while (align & (align - 1))
|
||||
++align;
|
||||
if (need < sizeof(unsigned))
|
||||
need = sizeof(unsigned);
|
||||
if (align < sizeof(unsigned))
|
||||
align = sizeof(unsigned);
|
||||
if (align > TINYMALLOC_MAX_ALIGN)
|
||||
goto InvalidArgument;
|
||||
if (ckd_add(&need, need, sizeof(unsigned) - 1))
|
||||
goto OutOfMemory;
|
||||
need &= -sizeof(unsigned);
|
||||
|
||||
// allocate from free list
|
||||
next = heap.free;
|
||||
link = &heap.free;
|
||||
while (next) {
|
||||
next2 = *(unsigned *)(heap.memory + next);
|
||||
link2 = (unsigned *)(heap.memory + next);
|
||||
if (need <= ((unsigned *)(heap.memory + next))[-1]) {
|
||||
*link = next2;
|
||||
return (void *)(heap.memory + next);
|
||||
}
|
||||
next = next2;
|
||||
link = link2;
|
||||
}
|
||||
|
||||
// allocate new static memory
|
||||
base = heap.used;
|
||||
base += sizeof(unsigned);
|
||||
base += align - 1;
|
||||
base &= -align;
|
||||
if (ckd_add(&toto, base, need))
|
||||
goto OutOfMemory;
|
||||
if (toto > TINYMALLOC_MAX_BYTES)
|
||||
goto OutOfMemory;
|
||||
res = heap.memory + base;
|
||||
((unsigned *)res)[-1] = need;
|
||||
heap.used = toto;
|
||||
heap.last = base;
|
||||
return res;
|
||||
|
||||
// we require more vespene gas
|
||||
OutOfMemory:
|
||||
errno = ENOMEM;
|
||||
return 0;
|
||||
InvalidArgument:
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *malloc(size_t need) {
|
||||
return memalign(sizeof(max_align_t), need);
|
||||
}
|
||||
|
||||
void *calloc(size_t count, size_t size) {
|
||||
char *res;
|
||||
unsigned need, used;
|
||||
if (ckd_mul(&need, count, size))
|
||||
need = -1;
|
||||
used = heap.used;
|
||||
if ((res = (char *)malloc(need)))
|
||||
if (res - heap.memory < used)
|
||||
bzero(res, need);
|
||||
return res;
|
||||
}
|
||||
|
||||
void *realloc(void *ptr, size_t need) {
|
||||
char *res, *mem;
|
||||
unsigned base, have, toto;
|
||||
if (!ptr) {
|
||||
res = (char *)malloc(need);
|
||||
} else {
|
||||
mem = (char *)ptr;
|
||||
unassert(isheap(mem));
|
||||
have = ((unsigned *)mem)[-1];
|
||||
base = mem - heap.memory;
|
||||
if (need < have) {
|
||||
res = mem;
|
||||
} else if (base == heap.last) {
|
||||
if (need < sizeof(unsigned))
|
||||
need = sizeof(unsigned);
|
||||
if (ckd_add(&need, need, sizeof(unsigned) - 1))
|
||||
goto OutOfMemory;
|
||||
need &= -sizeof(unsigned);
|
||||
if (ckd_add(&toto, base, need))
|
||||
goto OutOfMemory;
|
||||
if (toto > TINYMALLOC_MAX_BYTES)
|
||||
goto OutOfMemory;
|
||||
((unsigned *)mem)[-1] = need;
|
||||
heap.used = toto;
|
||||
res = mem;
|
||||
} else if ((res = (char *)malloc(need))) {
|
||||
if (have > need)
|
||||
have = need;
|
||||
memcpy(res, mem, have);
|
||||
free(mem);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
OutOfMemory:
|
||||
errno = ENOMEM;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* MODE_DBG */
|
||||
@@ -93,18 +93,37 @@ kCpuids:.long 0,0,0,0 // EAX=0 (Basic Processor Info)
|
||||
add $4*4,%rdi
|
||||
jmp 2b
|
||||
3: nop
|
||||
#if !X86_NEED(AVX2)
|
||||
|
||||
// test if cpu supports avx
|
||||
testb X86_HAVE(AVX)(%r8)
|
||||
jz 5f
|
||||
jz 7f
|
||||
testb X86_HAVE(OSXSAVE)(%r8)
|
||||
jz 4f
|
||||
jz 5f
|
||||
xor %ecx,%ecx
|
||||
xgetbv
|
||||
mov %eax,%ecx
|
||||
|
||||
// test if operating system saves avx registers
|
||||
and $XCR0_SSE|XCR0_AVX,%eax
|
||||
cmp $XCR0_SSE|XCR0_AVX,%eax
|
||||
je 5f
|
||||
4: btr $X86_BIT(AVX),X86_WORD(AVX)(%r8)
|
||||
jne 5f
|
||||
|
||||
// test if operating system saves avx512 registers
|
||||
and $XCR0_OPMASK|XCR0_ZMM_HI256|XCR0_HI16_ZMM,%ecx
|
||||
cmp $XCR0_OPMASK|XCR0_ZMM_HI256|XCR0_HI16_ZMM,%ecx
|
||||
jne 6f
|
||||
je 7f
|
||||
|
||||
// operating system doesn't support avx
|
||||
5: btr $X86_BIT(AVX),X86_WORD(AVX)(%r8)
|
||||
btr $X86_BIT(AVX2),X86_WORD(AVX2)(%r8)
|
||||
#endif
|
||||
5: pop %rbx
|
||||
|
||||
// operating system supports avx but not avx512
|
||||
6: andl $~(1<<30|1<<28|1<<17|1<<27|1<<16|1<<21|1<<26|1<<31),KCPUIDS(7H, EBX)(%r8)
|
||||
andl $~(1<<1|1<<12|1<<6|1<<11|1<<14),KCPUIDS(7H, ECX)(%r8)
|
||||
andl $~(1<<2|1<<3|1<<8),KCPUIDS(7H, EDX)(%r8)
|
||||
andl $~(1<<5),KCPUIDS(7H_1H, EAX)(%r8)
|
||||
|
||||
// we're done
|
||||
7: pop %rbx
|
||||
.init.end 201,_init_kCpuids
|
||||
@@ -16,4 +16,6 @@
|
||||
#define kNtMemLargePages 0x20000000
|
||||
#define kNtMem4mbPages 0x80000000
|
||||
|
||||
#define kNtMemReplacePlaceholder 0x00004000
|
||||
|
||||
#endif /* COSMOPOLITAN_LIBC_NT_ENUM_MEMFLAGS_H_ */
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef COSMOPOLITAN_LIBC_NT_ENUM_TIMEZONEID_H_
|
||||
#define COSMOPOLITAN_LIBC_NT_ENUM_TIMEZONEID_H_
|
||||
|
||||
#define kNtTimeZoneIdUnknown 0
|
||||
#define kNtTimeZoneIdStandard 1
|
||||
#define kNtTimeZoneIdDaylight 2
|
||||
|
||||
#endif /* COSMOPOLITAN_LIBC_NT_ENUM_TIMEZONEID_H_ */
|
||||
@@ -0,0 +1,20 @@
|
||||
#include "libc/nt/codegen.h"
|
||||
.imp kernel32,__imp_GetDynamicTimeZoneInformation,GetDynamicTimeZoneInformation
|
||||
|
||||
.text.windows
|
||||
.ftrace1
|
||||
GetDynamicTimeZoneInformation:
|
||||
.ftrace2
|
||||
#ifdef __x86_64__
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
mov %rdi,%rcx
|
||||
sub $32,%rsp
|
||||
call *__imp_GetDynamicTimeZoneInformation(%rip)
|
||||
leave
|
||||
#elif defined(__aarch64__)
|
||||
mov x0,#0
|
||||
#endif
|
||||
ret
|
||||
.endfn GetDynamicTimeZoneInformation,globl
|
||||
.previous
|
||||
@@ -0,0 +1,20 @@
|
||||
#include "libc/nt/codegen.h"
|
||||
.imp kernel32,__imp_GetTimeZoneInformation,GetTimeZoneInformation
|
||||
|
||||
.text.windows
|
||||
.ftrace1
|
||||
GetTimeZoneInformation:
|
||||
.ftrace2
|
||||
#ifdef __x86_64__
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
mov %rdi,%rcx
|
||||
sub $32,%rsp
|
||||
call *__imp_GetTimeZoneInformation(%rip)
|
||||
leave
|
||||
#elif defined(__aarch64__)
|
||||
mov x0,#0
|
||||
#endif
|
||||
ret
|
||||
.endfn GetTimeZoneInformation,globl
|
||||
.previous
|
||||
@@ -0,0 +1,18 @@
|
||||
#include "libc/nt/codegen.h"
|
||||
.imp kernel32,__imp_MapViewOfFile3,MapViewOfFile3
|
||||
|
||||
.text.windows
|
||||
.ftrace1
|
||||
MapViewOfFile3:
|
||||
.ftrace2
|
||||
#ifdef __x86_64__
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
mov __imp_MapViewOfFile3(%rip),%rax
|
||||
jmp __sysv2nt10
|
||||
#elif defined(__aarch64__)
|
||||
mov x0,#0
|
||||
ret
|
||||
#endif
|
||||
.endfn MapViewOfFile3,globl
|
||||
.previous
|
||||
@@ -0,0 +1,18 @@
|
||||
#include "libc/nt/codegen.h"
|
||||
.imp kernel32,__imp_VirtualAlloc2,VirtualAlloc2
|
||||
|
||||
.text.windows
|
||||
.ftrace1
|
||||
VirtualAlloc2:
|
||||
.ftrace2
|
||||
#ifdef __x86_64__
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
mov __imp_VirtualAlloc2(%rip),%rax
|
||||
jmp __sysv2nt8
|
||||
#elif defined(__aarch64__)
|
||||
mov x0,#0
|
||||
ret
|
||||
#endif
|
||||
.endfn VirtualAlloc2,globl
|
||||
.previous
|
||||
@@ -168,6 +168,8 @@ imp 'GetSystemTimePreciseAsFileTime' GetSystemTimePreciseAsFileTime kernel3
|
||||
imp 'GetSystemTimes' GetSystemTimes kernel32 3
|
||||
imp 'GetTempPath' GetTempPathW kernel32 2
|
||||
imp 'GetTempPathA' GetTempPathA kernel32 2
|
||||
imp 'GetDynamicTimeZoneInformation' GetDynamicTimeZoneInformation kernel32 1
|
||||
imp 'GetTimeZoneInformation' GetTimeZoneInformation kernel32 1
|
||||
imp 'GetThreadContext' GetThreadContext kernel32 2
|
||||
imp 'GetThreadDescription' GetThreadDescription kernel32 2
|
||||
imp 'GetThreadIOPendingFlag' GetThreadIOPendingFlag kernel32 2
|
||||
@@ -203,6 +205,7 @@ imp 'LoadResource' LoadResource kernel32 2
|
||||
imp 'LocalFree' LocalFree kernel32 1
|
||||
imp 'LockFile' LockFile kernel32 5
|
||||
imp 'LockResource' LockResource kernel32 1
|
||||
imp 'MapViewOfFile3' MapViewOfFile3 kernel32 9
|
||||
imp 'MoveFile' MoveFileW kernel32 2
|
||||
imp 'MultiByteToWideChar' MultiByteToWideChar kernel32 6
|
||||
imp 'OfferVirtualMemory' OfferVirtualMemory kernel32 3
|
||||
@@ -293,6 +296,7 @@ imp 'UnmapViewOfFile2' UnmapViewOfFile2 kernel32 2
|
||||
imp 'UnmapViewOfFileEx' UnmapViewOfFileEx kernel32 3
|
||||
imp 'UpdateProcThreadAttribute' UpdateProcThreadAttribute kernel32 7
|
||||
imp 'VirtualAlloc' VirtualAlloc kernel32 4
|
||||
imp 'VirtualAlloc2' VirtualAlloc2 kernel32 7
|
||||
imp 'VirtualAllocEx' VirtualAllocEx kernel32 5
|
||||
imp 'VirtualFree' VirtualFree kernel32 3
|
||||
imp 'VirtualLock' VirtualLock kernel32 2
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#ifndef COSMOPOLITAN_LIBC_NT_MEMORY_H_
|
||||
#define COSMOPOLITAN_LIBC_NT_MEMORY_H_
|
||||
#include "libc/nt/struct/memextendedparameter.h"
|
||||
#include "libc/nt/struct/memorybasicinformation.h"
|
||||
#include "libc/nt/struct/memoryrangeentry.h"
|
||||
#include "libc/nt/struct/securityattributes.h"
|
||||
@@ -82,6 +83,25 @@ void *HeapReAlloc(int64_t hHeap, uint32_t dwFlags, void *lpMem,
|
||||
void *GlobalAlloc(uint32_t uFlags, uint64_t dwBytes) __wur;
|
||||
void *GlobalFree(void *hMem);
|
||||
|
||||
/**
|
||||
* @param AllocationType
|
||||
* - kNtMemReserve
|
||||
* - kNtMemReplacePlaceholder
|
||||
* - kNtMemLargePages
|
||||
*/
|
||||
void *MapViewOfFile3(
|
||||
intptr_t FileMapping, intptr_t Process, void *opt_BaseAddress,
|
||||
uint64_t Offset, size_t ViewSize, unsigned AllocationType,
|
||||
unsigned PageProtection,
|
||||
struct NtMemExtendedParameter *in_out_opt_ExtendedParameters,
|
||||
unsigned ParameterCount);
|
||||
|
||||
void *VirtualAlloc2(
|
||||
intptr_t opt_Process, void *opt_BaseAddress, size_t Size,
|
||||
unsigned AllocationType, unsigned PageProtection,
|
||||
struct NtMemExtendedParameter *in_out_opt_ExtendedParameters,
|
||||
unsigned ParameterCount);
|
||||
|
||||
#if ShouldUseMsabiAttribute()
|
||||
#include "libc/nt/thunk/memory.inc"
|
||||
#endif /* ShouldUseMsabiAttribute() */
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef COSMOPOLITAN_LIBC_NT_STRUCT_DYNAMICTIMEZONEINFORMATION_H_
|
||||
#define COSMOPOLITAN_LIBC_NT_STRUCT_DYNAMICTIMEZONEINFORMATION_H_
|
||||
#include "libc/nt/struct/systemtime.h"
|
||||
|
||||
struct NtDynamicTimeZoneInformation {
|
||||
int32_t Bias;
|
||||
char16_t StandardName[32];
|
||||
struct NtSystemTime StandardDate;
|
||||
int32_t StandardBias;
|
||||
char16_t DaylightName[32];
|
||||
struct NtSystemTime DaylightDate;
|
||||
int32_t DaylightBias;
|
||||
char16_t TimeZoneKeyName[128];
|
||||
bool32 DynamicDaylightTimeDisabled;
|
||||
};
|
||||
|
||||
#endif /* COSMOPOLITAN_LIBC_NT_STRUCT_DYNAMICTIMEZONEINFORMATION_H_ */
|
||||
@@ -0,0 +1,34 @@
|
||||
#ifndef COSMOPOLITAN_LIBC_NT_STRUCT_MEMEXTENDEDPARAMETER_H_
|
||||
#define COSMOPOLITAN_LIBC_NT_STRUCT_MEMEXTENDEDPARAMETER_H_
|
||||
|
||||
#define kNtMemExtendedParameterTypeBits 8
|
||||
|
||||
#define kNtMemExtendedParameterInvalidType 0
|
||||
#define kNtMemExtendedParameterAddressRequirements 1
|
||||
#define kNtMemExtendedParameterNumaNode 2
|
||||
#define kNtMemExtendedParameterPartitionHandle 3
|
||||
#define kNtMemExtendedParameterUserPhysicalHandle 4
|
||||
#define kNtMemExtendedParameterAttributeFlags 5
|
||||
#define kNtMemExtendedParameterMax 6
|
||||
|
||||
#define kNtMemExtendedParameterGraphics 0x00000001
|
||||
#define kNtMemExtendedParameterNonpaged 0x00000002
|
||||
#define kNtMemExtendedParameterZeroPagesOptional 0x00000004
|
||||
#define kNtMemExtendedParameterNonpagedLarge 0x00000008
|
||||
#define kNtMemExtendedParameterNonpagedHuge 0x00000010
|
||||
|
||||
struct NtMemExtendedParameter {
|
||||
struct {
|
||||
uint64_t Type : kNtMemExtendedParameterTypeBits;
|
||||
uint64_t Reserved : 64 - kNtMemExtendedParameterTypeBits;
|
||||
} DUMMYSTRUCTNAME;
|
||||
union {
|
||||
uint64_t ULong64;
|
||||
void *Pointer;
|
||||
size_t Size;
|
||||
intptr_t Handle;
|
||||
unsigned ULong;
|
||||
} DUMMYUNIONNAME;
|
||||
};
|
||||
|
||||
#endif /* COSMOPOLITAN_LIBC_NT_STRUCT_MEMEXTENDEDPARAMETER_H_ */
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef COSMOPOLITAN_LIBC_NT_STRUCT_TIMEZONEINFORMATION_H_
|
||||
#define COSMOPOLITAN_LIBC_NT_STRUCT_TIMEZONEINFORMATION_H_
|
||||
#include "libc/nt/struct/systemtime.h"
|
||||
|
||||
struct NtTimeZoneInformation {
|
||||
int Bias; /* in minutes e.g. +480 for -8:00 */
|
||||
char16_t StandardName[32]; /* e.g. "Pacific Standard Time" */
|
||||
struct NtSystemTime StandardDate;
|
||||
int StandardBias;
|
||||
char16_t DaylightName[32]; /* e.g. "Pacific Daylight Time" */
|
||||
struct NtSystemTime DaylightDate;
|
||||
int DaylightBias; /* e.g. -60 */
|
||||
};
|
||||
|
||||
#endif /* COSMOPOLITAN_LIBC_NT_STRUCT_TIMEZONEINFORMATION_H_ */
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef COSMOPOLITAN_LIBC_NT_TIME_H_
|
||||
#define COSMOPOLITAN_LIBC_NT_TIME_H_
|
||||
#include "libc/nt/struct/dynamictimezoneinformation.h"
|
||||
#include "libc/nt/struct/timezoneinformation.h"
|
||||
COSMOPOLITAN_C_START_
|
||||
/* ░░░░
|
||||
▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
|
||||
▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
|
||||
▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓ ▒▓░
|
||||
▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓ ▓▓▓▓▓▓▒ ▒▒▒▓▓█
|
||||
▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
|
||||
░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓ █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
|
||||
▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░ ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
|
||||
▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓ ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
|
||||
▒▒▒▒▓▓ ▓▒▒▓▓▓▓ ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
|
||||
▒▓ ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
|
||||
░░░░░░░░░░░▒▒▒▒ ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
|
||||
▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓ ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
|
||||
░▒░░░░░░░░░░░▒▒▒▒▒▓▓ ▓░ ░▓███▓
|
||||
▒▒░░░░░░░░░░▒▒▒▒▒▓▓░ ▒▓▓▓▒▒▒ ░▒▒▒▓ ████████████
|
||||
▒▒░░░░░░░░░░░▒▒▒▒▒▓▓ ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░ ░███
|
||||
▒░░░░░░░░░░░▒▒▒▒▒▓▓ ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓ ███
|
||||
▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓ ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒ ▓██
|
||||
▒░░░░░░░░░░░▒▒▒▒▒▓▓ ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓ ▓██
|
||||
▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒ ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒ ███
|
||||
░▒▓ ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓ ▓██
|
||||
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
|
||||
│ cosmopolitan § new technology » time ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
|
||||
uint32_t GetTimeZoneInformation(
|
||||
struct NtTimeZoneInformation *out_lpTimeZoneInformation);
|
||||
uint32_t GetDynamicTimeZoneInformation(
|
||||
struct NtDynamicTimeZoneInformation *out_lpTimeZoneInformation);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* COSMOPOLITAN_LIBC_NT_TIME_H_ */
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
#include "libc/calls/struct/timeval.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/sysv/consts/rusage.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
|
||||
/**
|
||||
* Returns sum of CPU time consumed by current process since birth.
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@
|
||||
#include "libc/runtime/clktck.h"
|
||||
#include "libc/runtime/sysconf.h"
|
||||
#include "libc/sysv/consts/rusage.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
|
||||
static dontinline long ConvertMicros(struct timeval tv) {
|
||||
return tv.tv_sec * CLK_TCK + tv.tv_usec / (1000000 / CLK_TCK);
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/promises.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/intrin/weaken.h"
|
||||
@@ -124,6 +125,7 @@ struct SymbolTable *GetSymbolTable(void) {
|
||||
struct Zipos *z;
|
||||
if (pthread_spin_trylock(&g_lock))
|
||||
return 0;
|
||||
int e = errno;
|
||||
if (!__symtab && !__isworker) {
|
||||
if (_weaken(__zipos_get) && (z = _weaken(__zipos_get)())) {
|
||||
if ((__symtab = GetSymbolTableFromZip(z))) {
|
||||
@@ -137,6 +139,7 @@ struct SymbolTable *GetSymbolTable(void) {
|
||||
__symtab = GetSymbolTableFromElf();
|
||||
}
|
||||
}
|
||||
errno = e;
|
||||
pthread_spin_unlock(&g_lock);
|
||||
return __symtab;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
for i, c in enumerate("Asia/Kolkata"):
|
||||
print("buf[%d] = '%c';" % (i, c))
|
||||
@@ -29,7 +29,7 @@
|
||||
* @assume stack memory isn't stored beneath %rsp (-mno-red-zone)
|
||||
* @deprecated
|
||||
*/
|
||||
optimizesize bool32 _isheap(void *p) {
|
||||
optimizesize bool32 _isheap(const void *p) {
|
||||
intptr_t x, y;
|
||||
x = kAutomapStart;
|
||||
y = x + kAutomapSize;
|
||||
|
||||
@@ -110,9 +110,9 @@ void *_mapanon(size_t) attributeallocsize((1)) mallocesque;
|
||||
void *_mapshared(size_t) attributeallocsize((1)) mallocesque;
|
||||
void CheckForMemoryLeaks(void);
|
||||
void CheckForFileLeaks(void);
|
||||
bool32 _isheap(const void *);
|
||||
void __enable_threads(void);
|
||||
void __oom_hook(size_t);
|
||||
bool32 _isheap(void *);
|
||||
/* code morphing */
|
||||
void __morph_begin(void);
|
||||
void __morph_end(void);
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ LIBC_SOCK_A_DIRECTDEPS = \
|
||||
LIBC_STR \
|
||||
LIBC_SYSV \
|
||||
LIBC_SYSV_CALLS \
|
||||
LIBC_TIME
|
||||
THIRD_PARTY_TZ
|
||||
|
||||
LIBC_SOCK_A_DEPS := \
|
||||
$(call uniq,$(foreach x,$(LIBC_SOCK_A_DIRECTDEPS),$($(x))))
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@
|
||||
#include "libc/sysv/consts/log.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/consts/sock.h"
|
||||
#include "libc/time/struct/tm.h"
|
||||
#include "libc/time.h"
|
||||
|
||||
/* Note: log_facility should be initialized with LOG_USER by default,
|
||||
* but since LOG_USER is not a constant value, we cannot initialize it
|
||||
|
||||
@@ -53,6 +53,12 @@ $(LIBC_STDIO_A).pkg: \
|
||||
# offer assurances about the stack safety of cosmo libc
|
||||
$(LIBC_STDIO_A_OBJS): private COPTS += -Wframe-larger-than=4096 -Walloca-larger-than=4096
|
||||
|
||||
$(LIBC_STDIO_A_OBJS): private \
|
||||
CFLAGS += \
|
||||
-fno-sanitize=all \
|
||||
-Wframe-larger-than=4096 \
|
||||
-Walloca-larger-than=4096
|
||||
|
||||
o/$(MODE)/libc/stdio/fputc.o: private \
|
||||
CFLAGS += \
|
||||
-O3
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/fmt/internal.h"
|
||||
#include "libc/stdckdint.h"
|
||||
|
||||
@@ -87,6 +87,13 @@ o/$(MODE)/libc/str/windowstimetotimespec.o: private \
|
||||
CFLAGS += \
|
||||
-O2
|
||||
|
||||
# we need -O3 because:
|
||||
# we're dividing by constants
|
||||
o/$(MODE)/libc/str/iso8601.o \
|
||||
o/$(MODE)/libc/str/iso8601us.o: private \
|
||||
CFLAGS += \
|
||||
-O3
|
||||
|
||||
$(LIBC_STR_A_OBJS): private \
|
||||
CFLAGS += \
|
||||
-fno-sanitize=all \
|
||||
|
||||
+1770
-1990
File diff suppressed because it is too large.
Load diff
@@ -18,7 +18,7 @@
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
|
||||
/**
|
||||
* Converts MS-DOS timestamp to UNIX.
|
||||
|
||||
@@ -17,8 +17,7 @@
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/time/struct/tm.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
|
||||
/**
|
||||
* Converts timestamp to ISO-8601 formatted string.
|
||||
@@ -17,8 +17,7 @@
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/time/struct/tm.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
|
||||
/**
|
||||
* Converts timestamp to ISO-8601 formatted string.
|
||||
@@ -16,7 +16,7 @@
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
|
||||
const unsigned short kMonthYearDay[2][12] = {
|
||||
{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334},
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
#ifndef COSMOPOLITAN_LIBC_STR_LOCALE_H_
|
||||
#define COSMOPOLITAN_LIBC_STR_LOCALE_H_
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/time/struct/tm.h"
|
||||
#include "libc/time.h"
|
||||
|
||||
#define LC_CTYPE 0
|
||||
#define LC_NUMERIC 1
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
#define LC_GLOBAL_LOCALE ((locale_t)-1)
|
||||
#define LC_GLOBAL_LOCALE ((locale_t) - 1)
|
||||
|
||||
struct __locale_map {
|
||||
const void *map;
|
||||
|
||||
Loaded 100 of 682 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user