path
stringlengths
14
112
content
stringlengths
0
6.32M
size
int64
0
6.32M
max_lines
int64
1
100k
repo_name
stringclasses
2 values
autogenerated
bool
1 class
cosmopolitan/libc/intrin/psllw.h
#ifndef COSMOPOLITAN_LIBC_INTRIN_PSLLW_H_ #define COSMOPOLITAN_LIBC_INTRIN_PSLLW_H_ #include "libc/intrin/macros.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ void psllw(uint16_t[8], const uint16_t[8], unsigned char); void psllwv(uint16_t[8], const uint16_t[8], const uint64_t[2]); #define psllw(A, B, I) INTRIN_SSEVEX_X_I_(psllw, SSE2, "psllw", A, B, I) #define psllwv(A, B, C) \ INTRIN_SSEVEX_X_X_X_(psllwv, SSE2, "psllw", INTRIN_NONCOMMUTATIVE, A, B, C) COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_INTRIN_PSLLW_H_ */
593
17
jart/cosmopolitan
false
cosmopolitan/libc/intrin/pminsw.c
/*-*- 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 2020 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/pminsw.h" #include "libc/macros.internal.h" #include "libc/str/str.h" /** * Gets minimum of signed 16-bit integers. * * @param 𝑎 [w/o] receives result * @param 𝑏 [r/o] supplies first input vector * @param 𝑐 [r/o] supplies second input vector * @mayalias */ void(pminsw)(int16_t a[8], const int16_t b[8], const int16_t c[8]) { unsigned i; int16_t r[8]; for (i = 0; i < 8; ++i) { r[i] = MIN(b[i], c[i]); } __builtin_memcpy(a, r, 16); }
2,323
39
jart/cosmopolitan
false
cosmopolitan/libc/intrin/describegidlist.c
/*-*- 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 2021 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/groups.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" #include "libc/intrin/kprintf.h" #include "libc/intrin/popcnt.h" #include "libc/macros.internal.h" #include "libc/str/str.h" #define N 128 const char *(DescribeGidList)(char buf[N], int rc, int size, const uint32_t list[]) { if ((rc == -1) || (size < 0)) return "n/a"; if (!size) return "{}"; if (!list) return "NULL"; if ((!IsAsan() && kisdangerous(list)) || (IsAsan() && !__asan_is_valid(list, size * sizeof(list[0])))) { ksnprintf(buf, N, "%p", list); return buf; } int i = 0, n = N; i += ksnprintf(buf + i, MAX(0, n - i), "{"); unsigned c; for (c = 0; c < size && MAX(0, n - i) > 0; c++) { i += ksnprintf(buf + i, MAX(0, n - i), "%u, ", list[c]); } if (c == size) { if (buf[i - 1] == ' ') i--; if (buf[i - 1] == ',') i--; i += ksnprintf(buf + i, MAX(0, n - i), "}"); } return buf; }
2,812
52
jart/cosmopolitan
false
cosmopolitan/libc/intrin/have_fsgsbase.c
/*-*- 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 2022 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/dce.h" #include "libc/errno.h" #include "libc/intrin/fsgsbase.h" #include "libc/nexgen32e/x86feature.h" #ifdef __x86_64__ /** * Returns true if FSGSBASE ISA can be used. * * If this function returns true (Linux 5.9+ or FreeBSD) then you should * be able to read/write to the %gs / %fs x86 segment registers in about * one or two clock cycles which gives you a free addition operation for * all assembly ops that reference memory. * * The FSGSBASE ISA was introduced by Intel with Ivybridge (c. 2012) but * the Linux Kernel didn't authorize us to use it until 2020, once Intel * had to start backdooring customer kernels so that they could have it. * AMD introduced support for the FSGSBASE ISA in Excavator, aka bdver4. * * @return boolean indicating if feature can be used * @see _rdfsbase() * @see _rdgsbase() * @see _wrfsbase() * @see _wrgsbase() */ privileged int _have_fsgsbase(void) { // Linux 5.9 (c. 2020) introduced close_range() and fsgsbase support. // it's cheaper to test for close_range() than handle an op crashing. // Windows lets us use these instructions but they don't really work. int ax; if (X86_HAVE(FSGSBASE)) { if (IsLinux()) { asm volatile("syscall" : "=a"(ax) : "0"(436 /* close_range */), "D"(-1), "S"(-2), "d"(0) : "rcx", "r11", "memory"); return ax == -22; // EINVAL } else if (IsFreebsd()) { return 1; } else { return 0; } } else { return 0; } } #endif /* __x86_64__ */
3,387
67
jart/cosmopolitan
false
cosmopolitan/libc/intrin/sys_umtx_timedwait_uint.c
/*-*- 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 2022 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/atomic.h" #include "libc/sysv/consts/clock.h" #include "libc/thread/freebsd.internal.h" #ifdef __x86_64__ int sys_umtx_timedwait_uint_cp(atomic_int *, int, int, size_t, struct _umtx_time *) asm("sys_futex_cp"); int sys_umtx_timedwait_uint(atomic_int *p, int expect, bool pshare, const struct timespec *abstime) { int op; size_t size; struct _umtx_time *tm_p, timo; if (!abstime) { tm_p = 0; size = 0; } else { timo._clockid = CLOCK_REALTIME; timo._flags = UMTX_ABSTIME; timo._timeout = *abstime; tm_p = &timo; size = sizeof(timo); } if (pshare) { op = UMTX_OP_WAIT_UINT; } else { op = UMTX_OP_WAIT_UINT_PRIVATE; } return sys_umtx_timedwait_uint_cp(p, op, expect, size, tm_p); } #endif
2,654
51
jart/cosmopolitan
false
cosmopolitan/libc/intrin/describewhichprio.c
/*-*- 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 2022 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/fmt/itoa.h" #include "libc/intrin/describeflags.internal.h" #include "libc/sysv/consts/prio.h" const char *(DescribeWhichPrio)(char buf[12], int x) { if (x == PRIO_PROCESS) return "PRIO_PROCESS"; if (x == PRIO_PGRP) return "PRIO_PGRP"; if (x == PRIO_USER) return "PRIO_USER"; FormatInt32(buf, x); return buf; }
2,173
30
jart/cosmopolitan
false
cosmopolitan/libc/intrin/describeopenflags.c
/*-*- 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 2022 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/fmt/itoa.h" #include "libc/fmt/magnumstrs.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/macros.internal.h" #include "libc/sysv/consts/sol.h" #define N (PAGESIZE / 2 / sizeof(struct DescribeFlags)) /** * Describes clock_gettime() clock argument. */ const char *(DescribeOpenFlags)(char buf[128], int x) { char *s; int i, n; struct DescribeFlags d[N]; if (x == -1) return "-1"; // TODO(jart): unify DescribeFlags and MagnumStr data structures for (n = 0; kOpenFlags[n].x != MAGNUM_TERMINATOR; ++n) { if (n == N) notpossible; } for (i = 0; i < n; ++i) { d[i].flag = MAGNUM_NUMBER(kOpenFlags, i); d[i].name = MAGNUM_STRING(kOpenFlags, i); } return DescribeFlags(buf, 128, d, n, "O_", x); }
2,627
46
jart/cosmopolitan
false
cosmopolitan/libc/intrin/mpsadbw.c
/*-*- 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 2020 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/mpsadbw.h" #include "libc/macros.internal.h" #include "libc/str/str.h" /** * Computes multiple sum of absolute differences. * * This appears to be intended for video encoding motion estimation. It * can be combined with phminposuw. That allows us to search for an int * overlapping inside 𝑏 that's nearest to an aligned int in 𝑎. * * @note goes fast w/ sse4 cf. core c. 2006 cf. bulldozer c. 2011 * @mayalias */ void(mpsadbw)(uint16_t c[8], const uint8_t b[16], const uint8_t a[16], uint8_t control) { unsigned i, j; uint16_t r[8]; for (i = 0; i < 8; ++i) { r[i] = 0; for (j = 0; j < 4; ++j) { r[i] += ABS(b[(control & 4) + i + j] - a[(control & 3) * 4 + j]); } } __builtin_memcpy(c, r, 16); }
2,610
45
jart/cosmopolitan
false
cosmopolitan/libc/intrin/asan.internal.h
#ifndef COSMOPOLITAN_LIBC_INTRIN_ASAN_H_ #define COSMOPOLITAN_LIBC_INTRIN_ASAN_H_ #include "libc/calls/struct/iovec.h" #include "libc/intrin/asancodes.h" #include "libc/macros.internal.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ #define SHADOW(x) ((signed char *)(((intptr_t)(x) >> kAsanScale) + kAsanMagic)) #define UNSHADOW(x) ((void *)(MAX(0, (intptr_t)(x)-kAsanMagic) << kAsanScale)) typedef void __asan_die_f(void); struct AsanFault { signed char kind; const signed char *shadow; }; void __asan_unpoison(void *, long); void __asan_poison(void *, long, signed char); void __asan_verify(const void *, size_t); void __asan_verify_str(const char *); void __asan_map_shadow(uintptr_t, size_t); bool __asan_is_valid(const void *, long) nosideeffect; bool __asan_is_valid_str(const char *) nosideeffect; bool __asan_is_valid_strlist(char *const *) nosideeffect; bool __asan_is_valid_iov(const struct iovec *, int) nosideeffect; struct AsanFault __asan_check(const void *, long) nosideeffect; struct AsanFault __asan_check_str(const char *) nosideeffect; void __asan_free(void *); void *__asan_malloc(size_t); int __asan_is_leaky(void *); int __asan_malloc_trim(size_t); int __asan_print_trace(void *); void *__asan_calloc(size_t, size_t); void *__asan_realloc(void *, size_t); void *__asan_memalign(size_t, size_t); size_t __asan_get_heap_size(const void *); void *__asan_realloc_in_place(void *, size_t); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_INTRIN_ASAN_H_ */
1,548
45
jart/cosmopolitan
false
cosmopolitan/libc/intrin/pcmpeqb.c
/*-*- 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 2020 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/pcmpeqb.h" #include "libc/str/str.h" /** * Compares signed 8-bit integers w/ equal to predicate. * * @param 𝑎 [w/o] receives result * @param 𝑏 [r/o] supplies first input vector * @param 𝑐 [r/o] supplies second input vector * @mayalias */ void(pcmpeqb)(uint8_t a[16], const uint8_t b[16], const uint8_t c[16]) { unsigned i; uint8_t r[16]; for (i = 0; i < 16; ++i) r[i] = -(b[i] == c[i]); __builtin_memcpy(a, r, 16); }
2,300
36
jart/cosmopolitan
false
cosmopolitan/libc/intrin/palignrs.S
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ │vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 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/macros.internal.h" // Jump table for palignr() with non-constexpr immediate parameter. // // @note needs ssse3 cf. prescott c. 2004 cf. bulldozer c. 2011 // @see palignr() .balign 8 __palignrs: palignr $0,%xmm1,%xmm0 ret nop palignr $1,%xmm1,%xmm0 ret nop palignr $2,%xmm1,%xmm0 ret nop palignr $3,%xmm1,%xmm0 ret nop palignr $4,%xmm1,%xmm0 ret nop palignr $5,%xmm1,%xmm0 ret nop palignr $6,%xmm1,%xmm0 ret nop palignr $7,%xmm1,%xmm0 ret nop palignr $8,%xmm1,%xmm0 ret nop palignr $9,%xmm1,%xmm0 ret nop palignr $10,%xmm1,%xmm0 ret nop palignr $11,%xmm1,%xmm0 ret nop palignr $12,%xmm1,%xmm0 ret nop palignr $13,%xmm1,%xmm0 ret nop palignr $14,%xmm1,%xmm0 ret nop palignr $15,%xmm1,%xmm0 ret nop palignr $16,%xmm1,%xmm0 ret nop palignr $17,%xmm1,%xmm0 ret nop palignr $18,%xmm1,%xmm0 ret nop palignr $19,%xmm1,%xmm0 ret nop palignr $20,%xmm1,%xmm0 ret nop palignr $21,%xmm1,%xmm0 ret nop palignr $22,%xmm1,%xmm0 ret nop palignr $23,%xmm1,%xmm0 ret nop palignr $24,%xmm1,%xmm0 ret nop palignr $25,%xmm1,%xmm0 ret nop palignr $26,%xmm1,%xmm0 ret nop palignr $27,%xmm1,%xmm0 ret nop palignr $28,%xmm1,%xmm0 ret nop palignr $29,%xmm1,%xmm0 ret nop palignr $30,%xmm1,%xmm0 ret nop palignr $31,%xmm1,%xmm0 ret .if . - __palignrs != 8 * 32 - 1 .error "bad assemblage" .endif .endfn __palignrs,globl
3,308
126
jart/cosmopolitan
false
cosmopolitan/libc/intrin/describeclockname.c
/*-*- 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 2022 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/fmt/magnumstrs.internal.h" #include "libc/intrin/describeflags.internal.h" /** * Describes clock_gettime() clock argument. */ const char *(DescribeClockName)(char buf[32], int x) { return DescribeMagnum(buf, kClockNames, "CLOCK_", x); }
2,093
28
jart/cosmopolitan
false
cosmopolitan/libc/intrin/pshufd.h
#ifndef COSMOPOLITAN_LIBC_INTRIN_PSHUFD_H_ #define COSMOPOLITAN_LIBC_INTRIN_PSHUFD_H_ #include "libc/intrin/macros.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ void pshufd(int32_t[4], const int32_t[4], uint8_t); #define pshufd(A, B, I) INTRIN_SSEVEX_X_X_I_(pshufd, SSE2, "pshufd", A, B, I) COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_INTRIN_PSHUFD_H_ */
426
14
jart/cosmopolitan
false
cosmopolitan/libc/intrin/por.h
#ifndef COSMOPOLITAN_LIBC_INTRIN_POR_H_ #define COSMOPOLITAN_LIBC_INTRIN_POR_H_ #include "libc/intrin/macros.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ void por(uint64_t[2], const uint64_t[2], const uint64_t[2]); #define por(A, B, C) \ INTRIN_SSEVEX_X_X_X_(por, SSE2, "por", INTRIN_COMMUTATIVE, A, B, C) COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_INTRIN_POR_H_ */
441
15
jart/cosmopolitan
false
cosmopolitan/libc/intrin/paddd.h
#ifndef COSMOPOLITAN_LIBC_INTRIN_PADDD_H_ #define COSMOPOLITAN_LIBC_INTRIN_PADDD_H_ #include "libc/intrin/macros.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ void paddd(uint32_t[4], const uint32_t[4], const uint32_t[4]); #define paddd(A, B, C) \ INTRIN_SSEVEX_X_X_X_(paddd, SSE2, "paddd", INTRIN_COMMUTATIVE, A, B, C) COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_INTRIN_PADDD_H_ */
455
15
jart/cosmopolitan
false
cosmopolitan/libc/intrin/getauxval.c
/*-*- 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 2020 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/runtime/runtime.h" #include "libc/sysv/errfuns.h" /** * Returns auxiliary value, or zero if kernel didn't provide it. * * This function is typically regarded as a libc implementation detail; * thus, the source code is the documentation. * * @return auxiliary value or 0 if `at` not found * @see libc/sysv/consts.sh * @see System Five Application Binary Interface § 3.4.3 * @error ENOENT when value not found * @asyncsignalsafe */ unsigned long getauxval(unsigned long at) { unsigned long res, *ap; for (ap = __auxv; ap[0]; ap += 2) { if (at == ap[0]) { return ap[1]; } } enoent(); return 0; }
2,481
44
jart/cosmopolitan
false
cosmopolitan/libc/intrin/pcmpgtd.c
/*-*- 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 2020 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/pcmpgtd.h" #include "libc/str/str.h" /** * Compares signed 32-bit integers w/ greater than predicate. * * @param 𝑎 [w/o] receives result * @param 𝑏 [r/o] supplies first input vector * @param 𝑐 [r/o] supplies second input vector * @mayalias */ void(pcmpgtd)(int32_t a[4], const int32_t b[4], const int32_t c[4]) { unsigned i; int32_t r[4]; for (i = 0; i < 4; ++i) r[i] = -(b[i] > c[i]); __builtin_memcpy(a, r, 16); }
2,299
36
jart/cosmopolitan
false
cosmopolitan/libc/intrin/psrad.h
#ifndef COSMOPOLITAN_LIBC_INTRIN_PSRAD_H_ #define COSMOPOLITAN_LIBC_INTRIN_PSRAD_H_ #include "libc/intrin/macros.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ void psrad(int32_t[4], const int32_t[4], unsigned char); void psradv(int32_t[4], const int32_t[4], const uint64_t[2]); #define psrad(A, B, I) INTRIN_SSEVEX_X_I_(psrad, SSE2, "psrad", A, B, I) #define psradv(A, B, C) \ INTRIN_SSEVEX_X_X_X_(psradv, SSE2, "psrad", INTRIN_NONCOMMUTATIVE, A, B, C) COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_INTRIN_PSRAD_H_ */
589
17
jart/cosmopolitan
false
cosmopolitan/libc/intrin/describentmovfileinpflags.c
/*-*- 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 2022 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/describeflags.internal.h" #include "libc/macros.internal.h" #include "libc/nt/enum/movefileexflags.h" static const struct DescribeFlags kMoveFileInputFlags[] = { {kNtMovefileReplaceExisting, "ReplaceExisting"}, // {kNtMovefileCopyAllowed, "CopyAllowed"}, // {kNtMovefileDelayUntilReboot, "DelayUntilReboot"}, // {kNtMovefileWriteThrough, "WriteThrough"}, // {kNtMovefileCreateHardlink, "CreateHardlink"}, // {kNtMovefileFailIfNotTrackable, "FailIfNotTrackable"}, // }; const char *(DescribeNtMovFileInpFlags)(char buf[256], uint32_t x) { return DescribeFlags(buf, 256, kMoveFileInputFlags, ARRAYLEN(kMoveFileInputFlags), "kNtMovefile", x); }
2,601
36
jart/cosmopolitan
false
cosmopolitan/libc/intrin/assertfail.greg.c
/*-*- 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 2020 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/atomic.h" #include "libc/calls/state.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/errno.h" #include "libc/intrin/atomic.h" #include "libc/intrin/kprintf.h" #include "libc/intrin/weaken.h" #include "libc/log/backtrace.internal.h" #include "libc/log/internal.h" #include "libc/runtime/runtime.h" #include "libc/runtime/symbols.internal.h" #include "libc/thread/thread.h" #include "libc/thread/tls.h" relegated void __assert_fail(const char *expr, const char *file, int line) { int me, owner; static atomic_int once; if (!__assert_disable) { strace_enabled(-1); ftrace_enabled(-1); owner = 0; me = __tls_enabled ? __get_tls()->tib_tid : sys_gettid(); pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, 0); kprintf("%s:%d: assert(%s) failed (tid %d) %m\n", file, line, expr, me); if (__vforked || atomic_compare_exchange_strong_explicit( &once, &owner, me, memory_order_relaxed, memory_order_relaxed)) { __restore_tty(); if (_weaken(ShowBacktrace)) { _weaken(ShowBacktrace)(2, __builtin_frame_address(0)); } else if (_weaken(PrintBacktraceUsingSymbols) && _weaken(GetSymbolTable)) { _weaken(PrintBacktraceUsingSymbols)(2, __builtin_frame_address(0), _weaken(GetSymbolTable)()); } else { kprintf("can't backtrace b/c `ShowCrashReports` not linked\n"); } _Exitr(23); } else if (owner == me) { kprintf("assert failed while failing\n"); _Exitr(24); } else { _Exit1(25); } } }
3,476
66
jart/cosmopolitan
false
cosmopolitan/libc/intrin/describentsymlinkflags.c
/*-*- 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 2022 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/describeflags.internal.h" #include "libc/macros.internal.h" #include "libc/nt/enum/symboliclink.h" static const struct DescribeFlags kSymbolicLinkflags[] = { {kNtSymbolicLinkFlagDirectory, "Directory"}, // {kNtSymbolicLinkFlagAllowUnprivilegedCreate, "AllowUnprivilegedCreate"}, // }; const char *(DescribeNtSymlinkFlags)(char buf[64], uint32_t x) { return DescribeFlags(buf, 64, kSymbolicLinkflags, ARRAYLEN(kSymbolicLinkflags), "kNtSymbolicLinkFlag", x); }
2,382
32
jart/cosmopolitan
false
cosmopolitan/libc/intrin/openprocess.c
/*-*- 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 2022 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/syscall_support-nt.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/nt/memory.h" #include "libc/nt/process.h" #include "libc/nt/struct/securityattributes.h" #include "libc/nt/thunk/msabi.h" __msabi extern typeof(OpenProcess) *const __imp_OpenProcess; /** * Creates file mapping object on the New Technology. * * @param dwDesiredAccess should be kNtProcess... combination * @return ehandle, or 0 on failure * @note this wrapper takes care of ABI, STRACE(), and __winerr() * @see MapViewOfFileEx() */ textwindows int64_t OpenProcess(uint32_t dwDesiredAccess, bool32 bInheritHandle, uint32_t dwProcessId) { int64_t hHandle; hHandle = __imp_OpenProcess(dwDesiredAccess, bInheritHandle, dwProcessId); if (!hHandle) __winerr(); NTTRACE("OpenProcess(%s, %hhhd, %u) → %ld% m", DescribeNtProcAccessFlags(dwDesiredAccess), bInheritHandle, dwProcessId, hHandle); return hHandle; }
2,867
47
jart/cosmopolitan
false
cosmopolitan/libc/intrin/punpckhdq.c
/*-*- 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 2020 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/punpckhdq.h" /** * Interleaves high doublewords. * * 0 1 2 3 * B aaaa bbbb CCCC DDDD * C eeee ffff GGGG HHHH * └┬─┘ └─┬┘ * ┌────┘ │ * ┌─────┴─┐ ┌──────┴┐ * → A CCCC GGGG DDDD HHHH * * @param 𝑎 [w/o] receives reduced 𝑏 and 𝑐 interleaved * @param 𝑏 [r/o] supplies four doublewords * @param 𝑐 [r/o] supplies four doublewords * @mayalias */ void(punpckhdq)(uint32_t a[4], const uint32_t b[4], const uint32_t c[4]) { a[0] = b[2]; a[1] = c[2]; a[2] = b[3]; a[3] = c[3]; }
2,515
43
jart/cosmopolitan
false
cosmopolitan/libc/intrin/punpckldq.c
/*-*- 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 2020 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/punpckldq.h" /** * Interleaves low doublewords. * * 0 1 2 3 * B AAAA BBBB cccc dddd * C EEEE FFFF gggg hhhh * └┬─┘ └─┬┘ * │ └───┐ * ┌┴──────┐ ┌┴──────┐ * → A AAAA EEEE BBBB FFFF * * @param 𝑎 [w/o] receives reduced 𝑏 and 𝑐 interleaved * @param 𝑏 [r/o] supplies four doublewords * @param 𝑐 [r/o] supplies four doublewords * @mayalias */ void(punpckldq)(uint32_t a[4], const uint32_t b[4], const uint32_t c[4]) { a[3] = c[1]; a[2] = b[1]; a[1] = c[0]; a[0] = b[0]; }
2,496
43
jart/cosmopolitan
false
cosmopolitan/libc/intrin/psrlw.c
/*-*- 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 2020 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/psrlw.h" #include "libc/str/str.h" /** * Divides unsigned shorts by two power. * * @note c needs to be a literal, asmconstexpr, or linkconstsym * @note logical shift does not sign extend negatives * @mayalias */ void(psrlw)(uint16_t a[8], const uint16_t b[8], unsigned char c) { unsigned i; if (c < 16) { for (i = 0; i < 8; ++i) { a[i] = b[i] >> c; } } else { __builtin_memset(a, 0, 16); } }
2,283
39
jart/cosmopolitan
false
cosmopolitan/libc/intrin/describeflags.c
/*-*- 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 2022 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/describeflags.internal.h" // TODO(jart): Fork this function into ASAN and non-ASAN versions. const char *DescribeFlags(char *p, size_t n, struct DescribeFlags *d, size_t m, const char *prefix, unsigned x) { bool t; char b[21]; size_t i, j, k; for (t = i = j = 0; j < m; ++j) { if (d[j].flag && d[j].flag != -1 && (x & d[j].flag) == d[j].flag) { x &= ~d[j].flag; if (t) { if (i + 1 < n) p[i++] = '|'; } else { t = true; } for (k = 0; prefix && prefix[k]; ++k) { if (i + 1 < n) p[i++] = prefix[k]; } for (k = 0; d[j].name[k]; ++k) { if (i + 1 < n) p[i++] = d[j].name[k]; } } } if (x || !t) { if (t && i + 1 < n) p[i++] = '|'; if (i + 1 < n) p[i++] = '0'; if (x) { if (i + 1 < n) p[i++] = 'x'; k = 0; do { if (i + 1 < n) b[k++] = "0123456789abcdef"[x % 16]; } while ((x /= 16)); while (k--) { if (i + 1 < n) p[i++] = b[k]; } } } if (i < n) p[i] = 0; return p; }
2,918
60
jart/cosmopolitan
false
cosmopolitan/libc/intrin/restorewintty.c
/*-*- 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 2022 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/dce.h" #include "libc/nt/console.h" #include "libc/nt/process.h" #include "libc/nt/runtime.h" #include "libc/runtime/internal.h" __msabi extern typeof(GetCurrentProcessId) *const __imp_GetCurrentProcessId; __msabi extern typeof(SetConsoleMode) *const __imp_SetConsoleMode; __msabi extern typeof(GetStdHandle) *const __imp_GetStdHandle; extern uint32_t __pid_exec; const unsigned char kConsoleHandles[3] = { kNtStdInputHandle, kNtStdOutputHandle, kNtStdErrorHandle, }; // Puts cmd.exe gui back the way it was. noinstrument void _restorewintty(void) { if (!IsWindows()) return; if (__imp_GetCurrentProcessId() != __pid_exec) return; for (int i = 0; i < 3; ++i) { __imp_SetConsoleMode(__imp_GetStdHandle(kConsoleHandles[i]), __ntconsolemode[i]); } }
2,651
46
jart/cosmopolitan
false
cosmopolitan/libc/intrin/nomultics.internal.h
#ifndef COSMOPOLITAN_LIBC_INTRIN_NOMULTICS_INTERNAL_H_ #define COSMOPOLITAN_LIBC_INTRIN_NOMULTICS_INTERNAL_H_ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ extern char __replmode; extern char __replstderr; COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_INTRIN_NOMULTICS_INTERNAL_H_ */
349
12
jart/cosmopolitan
false
cosmopolitan/libc/intrin/pslldv.c
/*-*- 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 2020 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/pslld.h" #include "libc/str/str.h" /** * Multiplies ints by two power. * @mayalias */ void(pslldv)(uint32_t a[4], const uint32_t b[4], const uint64_t c[2]) { unsigned i; if (c[0] <= 31) { for (i = 0; i < 4; ++i) { a[i] = b[i] << c[0]; } } else { __builtin_memset(a, 0, 16); } }
2,166
36
jart/cosmopolitan
false
cosmopolitan/libc/intrin/bt.c
/*-*- 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 2022 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/errno.h" #include "libc/intrin/kprintf.h" #include "libc/intrin/weaken.h" #include "libc/log/backtrace.internal.h" #include "libc/runtime/symbols.internal.h" static _Thread_local bool noreentry; /** * Shows backtrace if crash reporting facilities are linked. */ void _bt(const char *fmt, ...) { int e; va_list va; if (!noreentry) { noreentry = true; } else { return; } if (fmt) { va_start(va, fmt); kvprintf(fmt, va); va_end(va); } if (_weaken(ShowBacktrace) && _weaken(GetSymbolTable)) { e = errno; _weaken(ShowBacktrace)(2, __builtin_frame_address(0)); errno = e; } else { kprintf("_bt() can't show backtrace because you need:\n" "\tSTATIC_YOINK(\"ShowBacktrace\");\n" "to be linked.\n"); if (_weaken(PrintBacktraceUsingSymbols) && _weaken(GetSymbolTable)) { e = errno; _weaken(PrintBacktraceUsingSymbols)(2, __builtin_frame_address(0), _weaken(GetSymbolTable)()); errno = e; } else { kprintf("_bt() can't show backtrace because you need:\n" "\tSTATIC_YOINK(\"PrintBacktraceUsingSymbols\");\n" "\tSTATIC_YOINK(\"GetSymbolTable\");\n" "to be linked.\n"); } } noreentry = false; }
3,142
69
jart/cosmopolitan
false
cosmopolitan/libc/intrin/findclose.c
/*-*- 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 2022 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/syscall_support-nt.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/nt/files.h" #include "libc/nt/thunk/msabi.h" __msabi extern typeof(FindClose) *const __imp_FindClose; /** * Finds more files in directory. * @note this wrapper takes care of ABI, STRACE(), and __winerr() */ textwindows bool32 FindClose(int64_t hFindFile) { bool32 ok; ok = __imp_FindClose(hFindFile); if (!ok) __winerr(); NTTRACE("FindClose(%ld) → %hhhd% m", hFindFile, ok); return ok; }
2,349
37
jart/cosmopolitan
false
cosmopolitan/libc/intrin/pmaxsw.c
/*-*- 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 2020 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/pmaxsw.h" #include "libc/macros.internal.h" #include "libc/str/str.h" /** * Gets maximum of signed 16-bit integers. * * @param 𝑎 [w/o] receives result * @param 𝑏 [r/o] supplies first input vector * @param 𝑐 [r/o] supplies second input vector * @mayalias */ void(pmaxsw)(int16_t a[8], const int16_t b[8], const int16_t c[8]) { unsigned i; int16_t r[8]; for (i = 0; i < 8; ++i) { r[i] = MAX(b[i], c[i]); } __builtin_memcpy(a, r, 16); }
2,323
39
jart/cosmopolitan
false
cosmopolitan/libc/intrin/punpcklbw.c
/*-*- 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 2020 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/punpcklbw.h" /** * Interleaves low bytes. * * 0 1 2 3 4 5 6 7 8 9 A B C D E F * B A B C D E F G H i j k l m n o p * C Q R S T U V W X y z α σ π μ τ ε * │ │ │ │ │ │ │ │ * │ │ │ └─────┐ * │ │ └───┐ │ etc... * │ └─┐ │ │ * ├─┐ ├─┐ ├─┐ ├─┐ * → A A Q B R C S D T E U F V G W H X * * @param 𝑎 [w/o] receives reduced 𝑏 and 𝑐 interleaved * @param 𝑏 [r/o] supplies eight words * @param 𝑐 [r/o] supplies eight words * @mayalias */ void(punpcklbw)(uint8_t a[16], const uint8_t b[16], const uint8_t c[16]) { a[0xf] = c[7]; a[0xe] = b[7]; a[0xd] = c[6]; a[0xc] = b[6]; a[0xb] = c[5]; a[0xa] = b[5]; a[0x9] = c[4]; a[0x8] = b[4]; a[0x7] = c[3]; a[0x6] = b[3]; a[0x5] = c[2]; a[0x4] = b[2]; a[0x3] = c[1]; a[0x2] = b[1]; a[0x1] = c[0]; a[0x0] = b[0]; }
2,836
57
jart/cosmopolitan
false
cosmopolitan/libc/intrin/describentconsolemodeinputflags.c
/*-*- 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 2022 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/describeflags.internal.h" #include "libc/macros.internal.h" #include "libc/nt/enum/consolemodeflags.h" static const struct DescribeFlags kConsoleModeInputFlags[] = { {kNtEnableProcessedInput, "ProcessedInput"}, // {kNtEnableLineInput, "LineInput"}, // {kNtEnableEchoInput, "EchoInput"}, // {kNtEnableWindowInput, "WindowInput"}, // {kNtEnableMouseInput, "MouseInput"}, // {kNtEnableInsertMode, "InsertMode"}, // {kNtEnableQuickEditMode, "QuickEditMode"}, // {kNtEnableExtendedFlags, "ExtendedFlags"}, // {kNtEnableAutoPosition, "AutoPosition"}, // {kNtEnableVirtualTerminalInput, "VirtualTerminalInput"}, // }; const char *(DescribeNtConsoleInFlags)(char buf[256], uint32_t x) { return DescribeFlags(buf, 256, kConsoleModeInputFlags, ARRAYLEN(kConsoleModeInputFlags), "kNtEnable", x); }
2,880
40
jart/cosmopolitan
false
cosmopolitan/libc/intrin/pthread_mutex_lock.c
/*-*- 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 2022 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/state.internal.h" #include "libc/errno.h" #include "libc/intrin/atomic.h" #include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/runtime/internal.h" #include "libc/thread/thread.h" #include "libc/thread/tls.h" #include "third_party/nsync/mu.h" /** * Locks mutex. * * Here's an example of using a normal mutex: * * pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; * pthread_mutex_lock(&lock); * // do work... * pthread_mutex_unlock(&lock); * pthread_mutex_destroy(&lock); * * Cosmopolitan permits succinct notation for normal mutexes: * * pthread_mutex_t lock = {0}; * pthread_mutex_lock(&lock); * // do work... * pthread_mutex_unlock(&lock); * * Here's an example of the proper way to do recursive mutexes: * * pthread_mutex_t lock; * pthread_mutexattr_t attr; * pthread_mutexattr_init(&attr); * pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); * pthread_mutex_init(&lock, &attr); * pthread_mutexattr_destroy(&attr); * pthread_mutex_lock(&lock); * // do work... * pthread_mutex_unlock(&lock); * pthread_mutex_destroy(&lock); * * This function does nothing in vfork() children. * * @return 0 on success, or error number on failure * @see pthread_spin_lock() * @vforksafe */ int pthread_mutex_lock(pthread_mutex_t *mutex) { int c, d, t; if (__vforked) return 0; LOCKTRACE("pthread_mutex_lock(%t)", mutex); if (__tls_enabled && // mutex->_type == PTHREAD_MUTEX_NORMAL && // mutex->_pshared == PTHREAD_PROCESS_PRIVATE && // _weaken(nsync_mu_lock)) { _weaken(nsync_mu_lock)((nsync_mu *)mutex); return 0; } if (mutex->_type == PTHREAD_MUTEX_NORMAL) { while (atomic_exchange_explicit(&mutex->_lock, 1, memory_order_acquire)) { pthread_yield(); } return 0; } t = gettid(); if (mutex->_owner == t) { if (mutex->_type != PTHREAD_MUTEX_ERRORCHECK) { if (mutex->_depth < 63) { ++mutex->_depth; return 0; } else { return EAGAIN; } } else { return EDEADLK; } } while (atomic_exchange_explicit(&mutex->_lock, 1, memory_order_acquire)) { pthread_yield(); } mutex->_depth = 0; mutex->_owner = t; mutex->_pid = __pid; return 0; }
4,242
113
jart/cosmopolitan
false
cosmopolitan/libc/intrin/pmaddubsw.c
/*-*- 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 2020 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/pmaddubsw.h" #include "libc/limits.h" #include "libc/macros.internal.h" #include "libc/str/str.h" /** * Multiplies bytes and adds adjacent results w/ short saturation. * * 𝑤ᵢ ← CLAMP[ 𝑏₂ᵢ𝑐₂ᵢ + 𝑏₍₂ᵢ₊₁₎𝑐₍₂ᵢ₊₁₎ ] * * @param 𝑤 [w/o] receives shorts * @param 𝑏 [r/o] is your byte data * @param 𝑐 [r/o] are your int8 coefficients * @note SSSE3 w/ Prescott c. 2004, Bulldozer c. 2011 * @note greatest simd op, like, ever * @mayalias */ void(pmaddubsw)(int16_t w[8], const uint8_t b[16], const int8_t c[16]) { unsigned i; for (i = 0; i < 8; ++i) { w[i] = MIN(SHRT_MAX, MAX(SHRT_MIN, (c[i * 2 + 0] * b[i * 2 + 0] + c[i * 2 + 1] * b[i * 2 + 1]))); } }
2,626
43
jart/cosmopolitan
false
cosmopolitan/libc/intrin/setcurrentdirectory.c
/*-*- 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 2022 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/syscall_support-nt.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/nt/files.h" #include "libc/nt/memory.h" #include "libc/nt/thunk/msabi.h" __msabi extern typeof(SetCurrentDirectory) *const __imp_SetCurrentDirectoryW; /** * Sets current directory. * @note this wrapper takes care of ABI, STRACE(), and __winerr() */ textwindows bool32 SetCurrentDirectory(const char16_t *lpPathName) { bool32 ok; ok = __imp_SetCurrentDirectoryW(lpPathName); if (!ok) __winerr(); NTTRACE("SetCurrentDirectory(%#hs) → %hhhd% m", lpPathName, ok); return ok; }
2,434
38
jart/cosmopolitan
false
cosmopolitan/libc/intrin/packssdw.h
#ifndef COSMOPOLITAN_LIBC_INTRIN_PACKSSDW_H_ #define COSMOPOLITAN_LIBC_INTRIN_PACKSSDW_H_ #include "libc/intrin/macros.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ void packssdw(int16_t[8], const int32_t[4], const int32_t[4]); #define packssdw(A, B, C) \ INTRIN_SSEVEX_X_X_X_(packssdw, SSE2, "packssdw", INTRIN_NONCOMMUTATIVE, A, \ B, C) COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_INTRIN_PACKSSDW_H_ */
552
16
jart/cosmopolitan
false
cosmopolitan/libc/intrin/pthread_spin_trylock.c
/*-*- 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 2022 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/intrin/atomic.h" #include "libc/thread/thread.h" /** * Acquires spin lock if available. * * This function has undefined behavior when `spin` wasn't intialized, * was destroyed, or if the lock's already held by the calling thread. * * @return 0 on success, or errno on error * @raise EBUSY if lock is already held */ errno_t(pthread_spin_trylock)(pthread_spinlock_t *spin) { int x; x = atomic_exchange_explicit(&spin->_lock, 1, memory_order_acquire); if (!x) return 0; _unassert(x == 1); return EBUSY; }
2,422
40
jart/cosmopolitan
false
cosmopolitan/libc/intrin/pmaddwd.h
#ifndef COSMOPOLITAN_LIBC_INTRIN_PMADDWD_H_ #define COSMOPOLITAN_LIBC_INTRIN_PMADDWD_H_ #include "libc/intrin/macros.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ void pmaddwd(int32_t[4], const int16_t[8], const int16_t[8]); #define pmaddwd(A, B, C) \ INTRIN_SSEVEX_X_X_X_(pmaddwd, SSE2, "pmaddwd", INTRIN_COMMUTATIVE, A, B, C) COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_INTRIN_PMADDWD_H_ */
466
15
jart/cosmopolitan
false
cosmopolitan/libc/intrin/asmflag.h
#ifndef COSMOPOLITAN_LIBC_BITS_ASMFLAG_H_ #define COSMOPOLITAN_LIBC_BITS_ASMFLAG_H_ #if !(__ASSEMBLER__ + __LINKER__ + 0) /* * Constraints for virtual machine flags. * @note we beseech clang devs for flag constraints */ #ifdef __GCC_ASM_FLAG_OUTPUTS__ /* GCC6+ CLANG10+ */ #define CFLAG_CONSTRAINT "=@ccc" #define CFLAG_ASM(OP) OP #define ZFLAG_CONSTRAINT "=@ccz" #define ZFLAG_ASM(OP) OP #define OFLAG_CONSTRAINT "=@cco" #define OFLAG_ASM(OP) OP #define SFLAG_CONSTRAINT "=@ccs" #define SFLAG_ASM(SP) SP #define ABOVE_CONSTRAINT "=@cca" /* i.e. !ZF && !CF */ #define ABOVEFLAG_ASM(OP) OP #else #define CFLAG_CONSTRAINT "=q" #define CFLAG_ASM(OP) OP "\n\tsetc\t%b0" #define ZFLAG_CONSTRAINT "=q" #define ZFLAG_ASM(OP) OP "\n\tsetz\t%b0" #define OFLAG_CONSTRAINT "=q" #define OFLAG_ASM(OP) OP "\n\tseto\t%b0" #define SFLAG_CONSTRAINT "=q" #define SFLAG_ASM(SP) OP "\n\tsets\t%b0" #define ABOVE_CONSTRAINT "=@cca" #define ABOVEFLAG_ASM(OP) OP "\n\tseta\t%b0" #endif #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_BITS_ASMFLAG_H_ */
1,105
35
jart/cosmopolitan
false
cosmopolitan/libc/intrin/describesockoptname.c
/*-*- 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 2022 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/fmt/itoa.h" #include "libc/fmt/magnumstrs.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/str/str.h" #include "libc/sysv/consts/sol.h" /** * Describes setsockopt() optname arguments. */ const char *(DescribeSockOptname)(char buf[32], int l, int x) { int i; char *s, *p; const struct MagnumStr *ms; p = buf; if (x) { if (l == SOL_SOCKET) { *p++ = 'S'; *p++ = 'O'; *p++ = '_'; *p = 0; ms = kSockOptnames; } else if (l == SOL_TCP) { *p++ = 'T'; *p++ = 'C'; *p++ = 'P'; *p++ = '_'; ms = kTcpOptnames; } else if (l == SOL_IP) { *p++ = 'I'; *p++ = 'P'; *p++ = '_'; *p = 0; ms = kIpOptnames; } else { ms = 0; } } else { ms = 0; } if (ms && (s = GetMagnumStr(ms, x))) { stpcpy(p, s); } else { FormatInt32(p, x); } return buf; }
2,751
65
jart/cosmopolitan
false
cosmopolitan/libc/intrin/palignr.h
#ifndef COSMOPOLITAN_LIBC_INTRIN_PALIGNR_H_ #define COSMOPOLITAN_LIBC_INTRIN_PALIGNR_H_ #include "libc/intrin/macros.h" #include "libc/str/str.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ void palignr(void *, const void *, const void *, unsigned long); #if !defined(__STRICT_ANSI__) && !defined(__chibicc__) && defined(__x86_64__) __intrin_xmm_t __palignrs(__intrin_xmm_t, __intrin_xmm_t); #define palignr(C, B, A, I) \ do { \ if (__builtin_expect(!IsModeDbg() && X86_NEED(SSE) && X86_HAVE(SSSE3), \ 1)) { \ __intrin_xmm_t *Xmm0 = (void *)(C); \ const __intrin_xmm_t *Xmm1 = (const __intrin_xmm_t *)(B); \ const __intrin_xmm_t *Xmm2 = (const __intrin_xmm_t *)(A); \ if (__builtin_constant_p(I)) { \ if (!X86_NEED(AVX)) { \ asm("palignr\t%2,%1,%0" \ : "=x"(*Xmm0) \ : "x"(*Xmm2), "i"(I), "0"(*Xmm1)); \ } else { \ asm("vpalignr\t%3,%2,%1,%0" \ : "=x"(*Xmm0) \ : "x"(*Xmm1), "x"(*Xmm2), "i"(I)); \ } \ } else { \ unsigned long Vimm = (I); \ typeof(__palignrs) *Fn; \ if (__builtin_expect(Vimm < 32, 1)) { \ Fn = (typeof(__palignrs) *)((uintptr_t)&__palignrs + Vimm * 8); \ *Xmm0 = Fn(*Xmm1, *Xmm2); \ } else { \ memset(Xmm0, 0, 16); \ } \ } \ } else { \ palignr(C, B, A, I); \ } \ } while (0) #endif COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_INTRIN_PALIGNR_H_ */
2,858
48
jart/cosmopolitan
false
cosmopolitan/libc/intrin/xadd.h
#ifndef COSMOPOLITAN_LIBC_BITS_XADD_H_ #define COSMOPOLITAN_LIBC_BITS_XADD_H_ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ #define _xadd(p, v) \ ({ \ typeof(*(p)) Res; \ autotype(Res) Val = (v); \ asm volatile("xadd\t%0,%1" : "=r"(Res), "+m"(*(p)) : "0"(Val)); \ Res + Val; \ }) COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_BITS_XADD_H_ */
676
17
jart/cosmopolitan
false
cosmopolitan/libc/intrin/pext.h
#ifndef COSMOPOLITAN_LIBC_INTRIN_PEXT_H_ #define COSMOPOLITAN_LIBC_INTRIN_PEXT_H_ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ uint64_t pext(uint64_t, uint64_t) pureconst; #define PEXT(NUMBER, BITMASK) \ ({ \ typeof(BITMASK) ShuffledBits, Number = (NUMBER); \ asm("pext\t%2,%1,%0" : "=r"(ShuffledBits) : "r"(Number), "rm"(BITMASK)); \ ShuffledBits; \ }) #define pext(NUMBER, BITMASK) \ (!X86_HAVE(BMI2) ? pext(NUMBER, BITMASK) : PEXT(NUMBER, BITMASK)) COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_INTRIN_PEXT_H_ */
804
21
jart/cosmopolitan
false
cosmopolitan/libc/intrin/sigcountset.c
/*-*- 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 2020 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/struct/sigset.h" #include "libc/intrin/popcnt.h" #include "libc/macros.internal.h" #include "libc/sysv/consts/limits.h" /** * Returns population count of signal set. * * @return value greater than or equal to zero * @asyncsignalsafe */ int sigcountset(const sigset_t *set) { int r, i, x, y; switch (_NSIG) { case 32: x = (uint32_t)set->__bits[0]; y = 0; break; case 64: x = set->__bits[0]; y = 0; break; case 128: x = set->__bits[0]; y = set->__bits[1]; break; default: notpossible; } return popcnt(x) + popcnt(y); }
2,464
50
jart/cosmopolitan
false
cosmopolitan/libc/intrin/ksignalnames.S
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ │vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2022 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/fmt/magnumstrs.internal.h" #include "libc/macros.internal.h" .macro .e e s .long \e - kSignalNames .long .L\@ - kSignalNames .rodata.str1.1 .L\@: .string "\s" .previous .endm .section .rodata .balign 4 .underrun kSignalNames: .e SIGHUP,"SIGHUP" .e SIGINT,"SIGINT" .e SIGQUIT,"SIGQUIT" .e SIGILL,"SIGILL" .e SIGTRAP,"SIGTRAP" .e SIGABRT,"SIGABRT" .e SIGBUS,"SIGBUS" .e SIGFPE,"SIGFPE" .e SIGKILL,"SIGKILL" .e SIGUSR1,"SIGUSR1" .e SIGSEGV,"SIGSEGV" .e SIGUSR2,"SIGUSR2" .e SIGPIPE,"SIGPIPE" .e SIGALRM,"SIGALRM" .e SIGTERM,"SIGTERM" .e SIGSTKFLT,"SIGSTKFLT" .e SIGCHLD,"SIGCHLD" .e SIGCONT,"SIGCONT" .e SIGSTOP,"SIGSTOP" .e SIGTSTP,"SIGTSTP" .e SIGTTIN,"SIGTTIN" .e SIGTTOU,"SIGTTOU" .e SIGURG,"SIGURG" .e SIGXCPU,"SIGXCPU" .e SIGXFSZ,"SIGXFSZ" .e SIGVTALRM,"SIGVTALRM" .e SIGPROF,"SIGPROF" .e SIGWINCH,"SIGWINCH" .e SIGIO,"SIGIO" .e SIGSYS,"SIGSYS" .e SIGPWR,"SIGPWR" .e SIGINFO,"SIGINFO" // order matters .e SIGTHR,"SIGTHR" // order matters .e SIGRTMAX,"SIGRTMAX" .e SIGRTMIN,"SIGRTMIN" .e SIGEMT,"SIGEMT" // order matters .long MAGNUM_TERMINATOR .endobj kSignalNames,globl,hidden .overrun
2,996
73
jart/cosmopolitan
false
cosmopolitan/libc/intrin/describentstartflags.c
/*-*- 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 2022 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/describeflags.internal.h" #include "libc/macros.internal.h" #include "libc/nt/enum/startf.h" #include "libc/sysv/consts/prot.h" static const struct DescribeFlags kNtStartFlags[] = { {kNtStartfUseshowwindow, "Useshowwindow"}, // {kNtStartfUsesize, "Usesize"}, // {kNtStartfUseposition, "Useposition"}, // {kNtStartfUsecountchars, "Usecountchars"}, // {kNtStartfUsefillattribute, "Usefillattribute"}, // {kNtStartfRunfullscreen, "Runfullscreen"}, // {kNtStartfForceonfeedback, "Forceonfeedback"}, // {kNtStartfForceofffeedback, "Forceofffeedback"}, // {kNtStartfUsestdhandles, "Usestdhandles"}, // {kNtStartfUsehotkey, "Usehotkey"}, // {kNtStartfTitleislinkname, "Titleislinkname"}, // {kNtStartfTitleisappid, "Titleisappid"}, // {kNtStartfPreventpinning, "Preventpinning"}, // {kNtStartfUntrustedsource, "Untrustedsource"}, // }; const char *(DescribeNtStartFlags)(char buf[128], uint32_t x) { return DescribeFlags(buf, 128, kNtStartFlags, ARRAYLEN(kNtStartFlags), "kNtStartf", x); }
3,022
45
jart/cosmopolitan
false
cosmopolitan/libc/intrin/fmaxl.c
/*-*- 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 2020 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/math.h" #if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) /** * Returns maximum of two long doubles. * * If one argument is NAN then the other is returned. * This function is designed to do the right thing with * signed zeroes. */ long double fmaxl(long double x, long double y) { if (isnan(x)) return y; if (isnan(y)) return x; if (signbit(x) != signbit(y)) { return signbit(x) ? y : x; /* C99 Annex F.9.9.2 */ } return x < y ? y : x; } #endif /* long double is long */
2,345
39
jart/cosmopolitan
false
cosmopolitan/libc/intrin/unlockfileex.c
/*-*- 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 2022 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/syscall_support-nt.internal.h" #include "libc/errno.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describentoverlapped.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/nt/files.h" #include "libc/str/str.h" __msabi extern typeof(UnlockFileEx) *const __imp_UnlockFileEx; /** * Unlocks file on the New Technology. * * @return handle, or -1 on failure * @note this wrapper takes care of ABI, STRACE(), and __winerr() */ bool32 UnlockFileEx(int64_t hFile, uint32_t dwReserved, uint32_t nNumberOfBytesToUnlockLow, uint32_t nNumberOfBytesToUnlockHigh, struct NtOverlapped *lpOverlapped) { bool32 ok; ok = __imp_UnlockFileEx(hFile, dwReserved, nNumberOfBytesToUnlockLow, nNumberOfBytesToUnlockHigh, lpOverlapped); if (!ok) __winerr(); NTTRACE( "UnlockFileEx(%ld, %#x, %'zu, [%s]) → %hhhd% m", hFile, dwReserved, (uint64_t)nNumberOfBytesToUnlockHigh << 32 | nNumberOfBytesToUnlockLow, DescribeNtOverlapped(lpOverlapped), ok); return ok; }
2,956
49
jart/cosmopolitan
false
cosmopolitan/libc/intrin/psrlqv.c
/*-*- 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 2020 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/psrlq.h" #include "libc/str/str.h" /** * Divides unsigned longs by two power. * * @note logical shift does not sign extend negatives * @mayalias */ void(psrlqv)(uint64_t a[2], const uint64_t b[2], const uint64_t c[2]) { unsigned i; if (c[0] <= 63) { for (i = 0; i < 2; ++i) { a[i] = b[i] >> c[0]; } } else { __builtin_memset(a, 0, 16); } }
2,230
38
jart/cosmopolitan
false
cosmopolitan/libc/intrin/pshufhw.c
/*-*- 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 2020 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/pshufhw.h" /** * Shuffles lower half of word vector. * @param 𝑚 needs to be a literal, constexpr, or embedding * @mayalias */ void(pshufhw)(int16_t b[8], const int16_t a[8], uint8_t m) { int16_t t[4]; t[0] = a[4 + ((m & 0b00000011) >> 0)]; t[1] = a[4 + ((m & 0b00001100) >> 2)]; t[2] = a[4 + ((m & 0b00110000) >> 4)]; t[3] = a[4 + ((m & 0b11000000) >> 6)]; b[0] = a[0]; b[1] = a[1]; b[2] = a[2]; b[3] = a[3]; b[4] = t[0]; b[5] = t[1]; b[6] = t[2]; b[7] = t[3]; }
2,355
41
jart/cosmopolitan
false
cosmopolitan/libc/intrin/likely.h
#ifndef COSMOPOLITAN_LIBC_BITS_LIKELY_H_ #define COSMOPOLITAN_LIBC_BITS_LIKELY_H_ #if !(__ASSEMBLER__ + __LINKER__ + 0) #define LIKELY(x) __builtin_expect(!!(x), 1) #define UNLIKELY(x) __builtin_expect(!!(x), 0) #if __GNUC__ + 0 >= 9 && !defined(__chibicc__) #define VERY_LIKELY(x) __builtin_expect_with_probability(!!(x), 1, 0.999) #else #define VERY_LIKELY(x) LIKELY(x) #endif #if __GNUC__ + 0 >= 9 && !defined(__chibicc__) #define VERY_UNLIKELY(x) __builtin_expect_with_probability(!!(x), 0, 0.999) #else #define VERY_UNLIKELY(x) UNLIKELY(x) #endif #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_BITS_LIKELY_H_ */
651
22
jart/cosmopolitan
false
cosmopolitan/libc/intrin/createsymboliclink.c
/*-*- 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 2022 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/syscall_support-nt.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/nt/files.h" __msabi extern typeof(CreateSymbolicLink) *const __imp_CreateSymbolicLinkW; /** * Creates symbolic link on the New Technology. * @note you need to elevate process privileges before calling this * @note this wrapper takes care of ABI, STRACE(), and __winerr() */ bool32 CreateSymbolicLink(const char16_t *lpSymlinkFileName, const char16_t *lpTargetPathName, uint32_t dwFlags) { bool32 ok; ok = __imp_CreateSymbolicLinkW(lpSymlinkFileName, lpTargetPathName, dwFlags); if (!ok) __winerr(); NTTRACE("CreateSymbolicLink(%#hs, %#hs, %s) → %hhhd% m", lpSymlinkFileName, lpTargetPathName, DescribeNtSymlinkFlags(dwFlags), ok); return ok; }
2,690
40
jart/cosmopolitan
false
cosmopolitan/libc/intrin/pthread_key_delete.c
/*-*- 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 2022 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/intrin/atomic.h" #include "libc/thread/posixthread.internal.h" #include "libc/thread/thread.h" /** * Deletes TLS slot. * * This function should only be called if all threads have finished * using the key registration. If a key is used after being deleted * then the behavior is undefined. If `k` was not registered by the * pthread_key_create() function then the behavior is undefined. * * @param key was created by pthread_key_create() * @return 0 on success, or errno on error */ int pthread_key_delete(pthread_key_t k) { uint64_t mask; _unassert(0 <= k && k < PTHREAD_KEYS_MAX); _unassert(atomic_load_explicit(_pthread_key_dtor + k, memory_order_acquire)); atomic_store_explicit(_pthread_key_dtor + k, 0, memory_order_release); return 0; }
2,664
43
jart/cosmopolitan
false
cosmopolitan/libc/intrin/describentprocaccessflags.c
/*-*- 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 2022 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/describeflags.internal.h" #include "libc/macros.internal.h" #include "libc/nt/enum/processaccess.h" static const struct DescribeFlags kProcessAccessflags[] = { {kNtProcessAllAccess, "AllAccess"}, // {kNtProcessCreateProcess, "CreateProcess"}, // {kNtProcessCreateThread, "CreateThread"}, // {kNtProcessDupHandle, "DupHandle"}, // {kNtProcessQueryInformation, "QueryInformation"}, // {kNtProcessQueryLimitedInformation, "QueryLimitedInformation"}, // {kNtProcessSetInformation, "SetInformation"}, // {kNtProcessSetQuota, "SetQuota"}, // {kNtProcessSuspendResume, "SuspendResume"}, // {kNtProcessTerminate, "Terminate"}, // {kNtProcessVmOperation, "VmOperation"}, // {kNtProcessVmRead, "VmRead"}, // {kNtProcessVmWrite, "VmWrite"}, // {kNtProcessSynchronize, "Synchronize"}, // }; const char *(DescribeNtProcAccessFlags)(char buf[256], uint32_t x) { return DescribeFlags(buf, 256, kProcessAccessflags, ARRAYLEN(kProcessAccessflags), "kNtProcess", x); }
3,228
44
jart/cosmopolitan
false
cosmopolitan/libc/intrin/pthread_atfork.c
/*-*- 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 2022 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/weaken.h" #include "libc/thread/posixthread.internal.h" #include "libc/thread/thread.h" /** * Registers fork() handlers. * * Parent and child functions are called in the same order they're * registered. Prepare functions are called in reverse order. * * Here's an example of how pthread_atfork() can be used: * * static struct { * pthread_once_t once; * pthread_mutex_t lock; * // data structures... * } g_lib; * * static void lib_lock(void) { * pthread_mutex_lock(&g_lib.lock); * } * * static void lib_unlock(void) { * pthread_mutex_unlock(&g_lib.lock); * } * * static void lib_funlock(void) { * pthread_mutex_init(&g_lib.lock, 0); * } * * static void lib_setup(void) { * lib_funlock(); * pthread_atfork(lib_lock, lib_unlock, lib_funlock); * } * * static void lib_init(void) { * pthread_once(&g_lib.once, lib_setup); * } * * void lib(void) { * lib_init(); * lib_lock(); * // do stuff... * lib_unlock(); * } * * This won't actually aspect fork() until pthread_create() is called, * since we don't want normal non-threaded programs to have to acquire * exclusive locks on every resource in the entire app just to fork(). * * The vfork() function is *never* aspected. What happens instead is a * global variable named `__vforked` is set to true in the child which * causes lock functions to do nothing. So far, it works like a charm. * * @param prepare is run by fork() before forking happens * @param parent is run by fork() after forking happens in parent process * @param child is run by fork() after forking happens in childe process * @return 0 on success, or errno on error * @raise ENOMEM if we require more vespene gas */ int pthread_atfork(atfork_f prepare, atfork_f parent, atfork_f child) { if (_weaken(_pthread_atfork)) { return _weaken(_pthread_atfork)(prepare, parent, child); } else { return 0; } }
3,874
86
jart/cosmopolitan
false
cosmopolitan/libc/intrin/mmi_lock.c
/*-*- 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 2022 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/runtime/memtrack.internal.h" #include "libc/str/str.h" #include "libc/thread/thread.h" // this lock currently needs to be (1) recursive and (2) not nsync extern pthread_mutex_t __mmi_lock_obj; void(__mmi_lock)(void) { pthread_mutex_lock(&__mmi_lock_obj); } void(__mmi_unlock)(void) { pthread_mutex_unlock(&__mmi_lock_obj); }
2,184
34
jart/cosmopolitan
false
cosmopolitan/libc/intrin/mempcpy.c
/*-*- 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 2021 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/str/str.h" void *mempcpy(void *dst, const void *src, size_t n) { memmove(dst, src, n); return (char *)dst + n; }
1,969
25
jart/cosmopolitan
false
cosmopolitan/libc/intrin/printsystemmappings.greg.c
/*-*- 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 2021 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/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/runtime/memtrack.internal.h" #include "libc/sysv/consts/at.h" #include "libc/sysv/consts/o.h" privileged void PrintSystemMappings(int outfd) { int infd; ssize_t rc; char buf[64]; if (!IsWindows()) { if ((infd = __sys_openat(AT_FDCWD, "/proc/self/maps", O_RDONLY, 0)) >= 0) { sys_write(outfd, "\n", 1); while ((rc = sys_read(infd, buf, sizeof(buf))) > 0) { sys_write(outfd, buf, rc); } } sys_close(infd); } }
2,376
39
jart/cosmopolitan
false
cosmopolitan/libc/intrin/terminateprocess.c
/*-*- 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 2022 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/syscall_support-nt.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/nt/console.h" #include "libc/nt/runtime.h" #include "libc/nt/thunk/msabi.h" __msabi extern typeof(TerminateProcess) *const __imp_TerminateProcess; /** * Terminates the specified process and all of its threads. * @note this wrapper takes care of ABI, STRACE(), and __winerr() */ textwindows bool32 TerminateProcess(int64_t hProcess, uint32_t uExitCode) { bool32 ok; ok = __imp_TerminateProcess(hProcess, uExitCode); if (!ok) __winerr(); NTTRACE("TerminateProcess(%ld, %u) → %hhhd% m", hProcess, uExitCode, ok); return ok; }
2,484
38
jart/cosmopolitan
false
cosmopolitan/libc/intrin/morton.c
/*-*- 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 2020 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/morton.h" /** * Interleaves bits. * @see https://en.wikipedia.org/wiki/Z-order_curve * @see unmorton() */ unsigned long(morton)(unsigned long y, unsigned long x) { x = (x | x << 020) & 0x0000FFFF0000FFFF; x = (x | x << 010) & 0x00FF00FF00FF00FF; x = (x | x << 004) & 0x0F0F0F0F0F0F0F0F; x = (x | x << 002) & 0x3333333333333333; x = (x | x << 001) & 0x5555555555555555; y = (y | y << 020) & 0x0000FFFF0000FFFF; y = (y | y << 010) & 0x00FF00FF00FF00FF; y = (y | y << 004) & 0x0F0F0F0F0F0F0F0F; y = (y | y << 002) & 0x3333333333333333; y = (y | y << 001) & 0x5555555555555555; return x | y << 1; }
2,480
39
jart/cosmopolitan
false
cosmopolitan/libc/intrin/ftrace_enabled.c
/*-*- 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 2022 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/runtime/runtime.h" #include "libc/thread/tls.h" /** * Changes function call logging state for current thread. * * @param delta is added to enabled state * @return enabled state before `delta` was applied */ int ftrace_enabled(int delta) { int res; struct CosmoTib *tib; if (__tls_enabled) { tib = __get_tls(); res = tib->tib_ftrace; tib->tib_ftrace += delta; if (!__ftrace && tib->tib_ftrace > 0) { __ftrace = 1; } } else { res = __ftrace; __ftrace += delta; } return res; }
2,378
44
jart/cosmopolitan
false
cosmopolitan/libc/intrin/flushers.c
/*-*- 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 2021 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/stdio/fflush.internal.h" pthread_mutex_t __fflush_lock_obj; struct StdioFlush __fflush;
1,940
23
jart/cosmopolitan
false
cosmopolitan/libc/intrin/describentlockfileflags.c
/*-*- 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 2022 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/describeflags.internal.h" #include "libc/macros.internal.h" #include "libc/nt/enum/filelockflags.h" static const struct DescribeFlags kNtLockFileFlags[] = { {kNtLockfileFailImmediately, "FailImmediately"}, // {kNtLockfileExclusiveLock, "ExclusiveLock"}, // }; const char *(DescribeNtLockFileFlags)(char buf[64], uint32_t x) { return DescribeFlags(buf, 64, kNtLockFileFlags, ARRAYLEN(kNtLockFileFlags), "kNtLockfile", x); }
2,322
32
jart/cosmopolitan
false
cosmopolitan/libc/intrin/describerlimitname.c
/*-*- 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 2021 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/fmt/magnumstrs.internal.h" #include "libc/intrin/describeflags.internal.h" /** * Describes setrlimit() / getrlimit() argument. */ const char *(DescribeRlimitName)(char buf[20], int x) { if (x == 127) return "n/a"; return DescribeMagnum(buf, kRlimitNames, "RLIMIT_", x); }
2,130
29
jart/cosmopolitan
false
cosmopolitan/libc/intrin/psubusb.h
#ifndef COSMOPOLITAN_LIBC_INTRIN_PSUBUSB_H_ #define COSMOPOLITAN_LIBC_INTRIN_PSUBUSB_H_ #include "libc/intrin/macros.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ void psubusb(uint8_t[16], const uint8_t[16], const uint8_t[16]); #define psubusb(A, B, C) \ INTRIN_SSEVEX_X_X_X_(psubusb, SSE2, "psubusb", INTRIN_NONCOMMUTATIVE, A, B, C) COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_INTRIN_PSUBUSB_H_ */
472
15
jart/cosmopolitan
false
cosmopolitan/libc/intrin/gettid.c
/*-*- 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 2020 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/state.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/intrin/atomic.h" #include "libc/intrin/likely.h" #include "libc/thread/tls.h" /** * Returns current thread id. * * On Linux, and Linux only, this is guaranteed to be equal to getpid() * if this is the main thread. On NetBSD, gettid() for the main thread * is always 1. * * @return thread id greater than zero or -1 w/ errno * @asyncsignalsafe * @threadsafe * @vforksafe */ int gettid(void) { int tid; if (VERY_LIKELY(__tls_enabled && !__vforked)) { tid = atomic_load_explicit(&__get_tls()->tib_tid, memory_order_acquire); if (VERY_LIKELY(tid > 0)) { return tid; } } return sys_gettid(); }
2,593
48
jart/cosmopolitan
false
cosmopolitan/libc/intrin/palignr.c
/*-*- 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 2020 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/palignr.h" #include "libc/assert.h" #include "libc/macros.internal.h" /** * Overlaps vectors. * * 𝑖= 0 means 𝑐←𝑎 * 0<𝑖<16 means 𝑐←𝑎║𝑏 * 𝑖=16 means 𝑐←𝑏 * 16<𝑖<32 means 𝑐←𝑏║0 * 𝑖≥32 means 𝑐←0 * * @param 𝑖 goes faster as constexpr * @note not compatible with mmx * @see pvalignr() * @mayalias */ void(palignr)(void *c, const void *b, const void *a, unsigned long i) { char t[48]; __builtin_memcpy(t, a, 16); __builtin_memcpy(t + 16, b, 16); __builtin_memset(t + 32, 0, 16); __builtin_memcpy(c, t + MIN(i, 32), 16); }
2,475
44
jart/cosmopolitan
false
cosmopolitan/libc/intrin/pslld.c
/*-*- 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 2020 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/pslld.h" #include "libc/str/str.h" /** * Multiplies ints by two power. * * @note c needs to be a literal, asmconstexpr, or linkconstsym * @mayalias */ void(pslld)(uint32_t a[4], const uint32_t b[4], unsigned char c) { unsigned i; if (c <= 31) { for (i = 0; i < 4; ++i) { a[i] = b[i] << c; } } else { __builtin_memset(a, 0, 16); } }
2,222
38
jart/cosmopolitan
false
cosmopolitan/libc/intrin/exit1.greg.c
/*-*- 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 2022 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/dce.h" #include "libc/intrin/asmflag.h" #include "libc/nt/thread.h" #include "libc/runtime/runtime.h" #include "libc/runtime/syslib.internal.h" #include "libc/sysv/consts/nr.h" #include "libc/thread/tls.h" __msabi extern typeof(ExitThread) *const __imp_ExitThread; /** * Terminates thread with raw system call. * * The function you want is pthread_exit(). If you call this function * whilst using the pthreads then your joiners might not get woken up * on non-Linux platforms where we zero __get_tls()->tib_tid manually * * If this is the main thread, or an orphaned child thread, then this * function is equivalent to exiting the process; however, `rc` shall * only be reported to the parent process on Linux, FreeBSD & Windows * whereas on other platforms, it'll be silently coerced to zero. * * @param rc only works on Linux and Windows * @see cthread_exit() * @threadsafe * @noreturn */ privileged wontreturn void _Exit1(int rc) { #ifdef __x86_64__ char cf; int ax, dx, di, si; if (!IsWindows() && !IsMetal()) { // exit() on Linux // thr_exit() on FreeBSD // __threxit() on OpenBSD // __lwp_exit() on NetBSD // __bsdthread_terminate() on XNU asm volatile(CFLAG_ASM("xor\t%%r10d,%%r10d\n\t" "syscall") : CFLAG_CONSTRAINT(cf), "=a"(ax), "=d"(dx), "=D"(di), "=S"(si) : "1"(__NR_exit), "3"(IsLinux() ? rc : 0), "4"(0), "2"(0) : "rcx", "r8", "r9", "r10", "r11", "memory"); if ((IsFreebsd() && !cf && !ax) || (SupportsFreebsd() && IsTiny())) { // FreeBSD checks if this is either the main thread by itself, or // the last running child thread in which case thr_exit() returns // zero with an error. In that case we'll exit the whole process. // FreeBSD thr_exit() can even clobber registers, like r8 and r9! asm volatile("syscall" : /* no outputs */ : "a"(__NR_exit_group), "D"(rc) : "rcx", "r11", "memory"); unreachable; } } else if (IsWindows()) { __imp_ExitThread(rc); unreachable; } notpossible; #elif defined(__aarch64__) if (IsLinux()) { register long r0 asm("x0") = rc; asm volatile("mov\tx8,%0\n\t" "svc\t0" : /* no outputs */ : "i"(93), "r"(r0) : "x8", "memory"); } else if (IsXnu()) { __syslib->pthread_exit(0); } notpossible; #else #error "arch unsupported" #endif }
4,356
93
jart/cosmopolitan
false
cosmopolitan/libc/intrin/describeptraceevent.c
/*-*- 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 2022 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/fmt/itoa.h" #include "libc/intrin/describeflags.internal.h" #include "libc/sysv/consts/ptrace.h" const char *(DescribePtraceEvent)(char buf[32], int x) { if (x == PTRACE_EVENT_FORK) return "PTRACE_EVENT_FORK"; if (x == PTRACE_EVENT_VFORK) return "PTRACE_EVENT_VFORK"; if (x == PTRACE_EVENT_CLONE) return "PTRACE_EVENT_CLONE"; if (x == PTRACE_EVENT_EXEC) return "PTRACE_EVENT_EXEC"; if (x == PTRACE_EVENT_VFORK_DONE) return "PTRACE_EVENT_VFORK_DONE"; if (x == PTRACE_EVENT_EXIT) return "PTRACE_EVENT_EXIT"; if (x == PTRACE_EVENT_SECCOMP) return "PTRACE_EVENT_SECCOMP"; if (x == PTRACE_EVENT_STOP) return "PTRACE_EVENT_STOP"; FormatInt32(buf, x); return buf; }
2,531
35
jart/cosmopolitan
false
cosmopolitan/libc/intrin/psubw.h
#ifndef COSMOPOLITAN_LIBC_INTRIN_PSUBW_H_ #define COSMOPOLITAN_LIBC_INTRIN_PSUBW_H_ #include "libc/intrin/macros.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ void psubw(int16_t[8], const int16_t[8], const int16_t[8]); #define psubw(A, B, C) \ INTRIN_SSEVEX_X_X_X_(psubw, SSE2, "psubw", INTRIN_NONCOMMUTATIVE, A, B, C) COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_INTRIN_PSUBW_H_ */
455
15
jart/cosmopolitan
false
cosmopolitan/libc/intrin/putenv.c
/*-*- 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 2020 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/_getenv.internal.h" #include "libc/intrin/kmalloc.h" #include "libc/intrin/strace.internal.h" #include "libc/macros.internal.h" #include "libc/mem/internal.h" #include "libc/runtime/runtime.h" #define ToUpper(c) ((c) >= 'a' && (c) <= 'z' ? (c) - 'a' + 'A' : (c)) static char **expected; static size_t capacity; static size_t GetEnvironLen(char **env) { char **p = env; while (*p) ++p; return p - env; } static char **GrowEnviron(char **a) { size_t n, c; char **b, **p; if (!a) a = environ; n = a ? GetEnvironLen(a) : 0; c = MAX(16ul, n) << 1; if ((b = kmalloc(c * sizeof(char *)))) { if (a) { for (p = b; *a;) { *p++ = *a++; } } environ = b; expected = b; capacity = c; return b; } else { return 0; } } int PutEnvImpl(char *s, bool overwrite) { char **p; struct Env e; if (!(p = environ)) { if (!(p = GrowEnviron(0))) { return -1; } } e = _getenv(p, s); if (e.s && !overwrite) { return 0; } if (e.s) { p[e.i] = s; return 0; } if (p != expected) { capacity = e.i; } if (e.i + 1 >= capacity) { if (!(p = GrowEnviron(p))) { return -1; } } p[e.i + 1] = 0; p[e.i] = s; return 0; } /** * Emplaces environment key=value. * * @param s should be a string that looks like `"name=value"` and it'll * become part of the environment; changes to its memory will change * the environment too * @return 0 on success, or non-zero w/ errno on error * @raise ENOMEM if we require more vespene gas * @see setenv(), getenv() */ int putenv(char *s) { int rc; rc = PutEnvImpl(s, true); STRACE("putenv(%#s) → %d% m", s, rc); return rc; }
3,551
103
jart/cosmopolitan
false
cosmopolitan/libc/intrin/psrldq.c
/*-*- 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 2020 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/psrldq.h" #include "libc/str/str.h" /** * Shifts vector left by n bytes w/ zero-fill. * * @param a is input vector * @param b receives output * @mayalias */ void(psrldq)(uint8_t b[16], const uint8_t a[16], unsigned long n) { if (n > 16) { n = 16; } else { __builtin_memcpy(b, a + n, 16 - n); } __builtin_memset(b + (16 - n), 0, n); }
2,215
37
jart/cosmopolitan
false
cosmopolitan/libc/intrin/krlimitnames.S
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ │vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2021 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/fmt/magnumstrs.internal.h" #include "libc/macros.internal.h" .macro .e e s .long \e - kRlimitNames .long .L\@ - kRlimitNames .rodata.str1.1 .L\@: .string "\s" .previous .endm .section .rodata .balign 4 .underrun kRlimitNames: .e RLIMIT_AS,"AS" .e RLIMIT_CPU,"CPU" .e RLIMIT_FSIZE,"FSIZE" .e RLIMIT_NPROC,"NPROC" .e RLIMIT_NOFILE,"NOFILE" .e RLIMIT_RSS,"RSS" .e RLIMIT_DATA,"DATA" .e RLIMIT_CORE,"CORE" .e RLIMIT_STACK,"STACK" .e RLIMIT_SIGPENDING,"SIGPENDING" .e RLIMIT_MEMLOCK,"MEMLOCK" .e RLIMIT_LOCKS,"LOCKS" .e RLIMIT_MSGQUEUE,"MSGQUEUE" .e RLIMIT_NICE,"NICE" .e RLIMIT_RTPRIO,"RTPRIO" .e RLIMIT_RTTIME,"RTTIME" .e RLIMIT_SWAP,"SWAP" .e RLIMIT_SBSIZE,"SBSIZE" .e RLIMIT_NPTS,"NPTS" .long MAGNUM_TERMINATOR .endobj kRlimitNames,globl,hidden .overrun
2,637
56
jart/cosmopolitan
false
cosmopolitan/libc/intrin/describesigaltstack.c
/*-*- 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 2021 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/struct/sigaltstack.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/kprintf.h" const char *(DescribeSigaltstk)(char buf[128], int rc, const struct sigaltstack *ss) { if (rc == -1) return "n/a"; if (!ss) return "NULL"; if ((!IsAsan() && kisdangerous(ss)) || (IsAsan() && !__asan_is_valid(ss, sizeof(*ss)))) { ksnprintf(buf, 128, "%p", ss); } else { ksnprintf(buf, 128, "{.ss_sp=%p, .ss_flags=%#lx, .ss_size=%'zu}", ss->ss_sp, ss->ss_flags, ss->ss_size); } return buf; }
2,484
38
jart/cosmopolitan
false
cosmopolitan/libc/intrin/shufpsjt.S
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ │vi: set et ft=asm ts=8 tw=8 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/macros.internal.h" .balign 8 shufpsjt: i=0 .rept 256 shufps $i,%xmm1,%xmm0 ret .balign 8 i=i+1 .endr .endfn shufpsjt,globl
1,984
31
jart/cosmopolitan
false
cosmopolitan/libc/intrin/ungray.c
/*-*- 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 2020 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/bits.h" /** * Decodes gray code. * @see https://en.wikipedia.org/wiki/Gray_code * @see gray() */ uint32_t ungray(uint32_t x) { x ^= x >> 16; x ^= x >> 8; x ^= x >> 4; x ^= x >> 2; x ^= x >> 1; return x; }
2,080
34
jart/cosmopolitan
false
cosmopolitan/libc/intrin/mapviewoffileex.c
/*-*- 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 2022 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/calls/syscall_support-nt.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/nt/enum/filemapflags.h" #include "libc/nt/memory.h" __msabi extern typeof(MapViewOfFileEx) *const __imp_MapViewOfFileEx; /** * Maps view of file mapping into memory on the New Technology. * * @param hFileMappingObject was returned by CreateFileMapping() * @param dwDesiredAccess has kNtFileMap... flags * @param opt_lpDesiredBaseAddress may be NULL to let o/s choose * @return base address, or NULL on failure * @note this wrapper takes care of ABI, STRACE(), and __winerr() */ textwindows void *MapViewOfFileEx(int64_t hFileMappingObject, uint32_t dwDesiredAccess, uint32_t dwFileOffsetHigh, uint32_t dwFileOffsetLow, size_t dwNumberOfBytesToMap, void *opt_lpDesiredBaseAddress) { void *pStartingAddress; pStartingAddress = __imp_MapViewOfFileEx( hFileMappingObject, dwDesiredAccess, dwFileOffsetHigh, dwFileOffsetLow, dwNumberOfBytesToMap, opt_lpDesiredBaseAddress); if (!pStartingAddress) __winerr(); NTTRACE("MapViewOfFileEx(%ld, %s, %'ld, %'zu, %p) → %p% m", hFileMappingObject, DescribeNtFileMapFlags(dwDesiredAccess), (uint64_t)dwFileOffsetHigh << 32 | dwFileOffsetLow, dwNumberOfBytesToMap, opt_lpDesiredBaseAddress, pStartingAddress); return pStartingAddress; }
3,422
54
jart/cosmopolitan
false
cosmopolitan/libc/intrin/psignb.c
/*-*- 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 2020 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/psignb.h" #include "libc/str/str.h" /** * Conditionally negates or zeroes signed bytes. * @note goes fast w/ ssse3 (intel c. 2004, amd c. 2011) */ void(psignb)(int8_t a[16], const int8_t b[16], const int8_t c[16]) { unsigned i; for (i = 0; i < 16; ++i) { if (!c[i]) { a[i] = 0; } else if (c[i] < 0) { a[i] = -b[i]; } else { a[i] = b[i]; } } }
2,245
38
jart/cosmopolitan
false
cosmopolitan/libc/intrin/psubsb.c
/*-*- 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 2020 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/psubsb.h" #include "libc/limits.h" #include "libc/macros.internal.h" #include "libc/str/str.h" /** * Subtracts signed 8-bit integers w/ saturation. * * @param 𝑎 [w/o] receives result * @param 𝑏 [r/o] supplies first input vector * @param 𝑐 [r/o] supplies second input vector * @mayalias */ void(psubsb)(int8_t a[16], const int8_t b[16], const int8_t c[16]) { unsigned i; int8_t r[16]; for (i = 0; i < 16; ++i) r[i] = MIN(INT8_MAX, MAX(INT8_MIN, b[i] - c[i])); __builtin_memcpy(a, r, 16); }
2,372
38
jart/cosmopolitan
false
cosmopolitan/libc/intrin/pandn.c
/*-*- 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 2020 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/pandn.h" /** * Nands 128-bit integers. * * @param 𝑎 [w/o] receives result * @param 𝑏 [r/o] supplies first input vector * @param 𝑐 [r/o] supplies second input vector * @mayalias */ void(pandn)(uint64_t a[2], const uint64_t b[2], const uint64_t c[2]) { unsigned i; for (i = 0; i < 2; ++i) { a[i] = ~b[i] & c[i]; } }
2,199
35
jart/cosmopolitan
false
cosmopolitan/libc/intrin/directmap.internal.h
#ifndef COSMOPOLITAN_LIBC_INTRIN_DIRECTMAP_H_ #define COSMOPOLITAN_LIBC_INTRIN_DIRECTMAP_H_ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ struct ProtectNt { uint32_t flags1; uint32_t flags2; }; struct DirectMap { void *addr; int64_t maphandle; }; struct DirectMap sys_mmap(void *, size_t, int, int, int, int64_t); struct DirectMap sys_mmap_nt(void *, size_t, int, int, int, int64_t); struct DirectMap sys_mmap_metal(void *, size_t, int, int, int, int64_t); int sys_munmap_metal(void *, size_t); int __prot2nt(int, int); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_INTRIN_DIRECTMAP_H_ */
664
25
jart/cosmopolitan
false
cosmopolitan/libc/intrin/gray.c
/*-*- 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 2020 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/bits.h" /** * Returns gray code for x. * @see https://en.wikipedia.org/wiki/Gray_code * @see ungray() */ uint32_t gray(uint32_t x) { return x ^ (x >> 1); }
2,021
29
jart/cosmopolitan
false
cosmopolitan/libc/intrin/createnamedpipe.c
/*-*- 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 2022 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/syscall_support-nt.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/nt/ipc.h" #include "libc/nt/struct/securityattributes.h" #include "libc/nt/thunk/msabi.h" __msabi extern typeof(CreateNamedPipe) *const __imp_CreateNamedPipeW; /** * Creates pipe. * * @return handle to server end * @note this wrapper takes care of ABI, STRACE(), and __winerr() */ textwindows int64_t CreateNamedPipe( const char16_t *lpName, uint32_t dwOpenMode, uint32_t dwPipeMode, uint32_t nMaxInstances, uint32_t nOutBufferSize, uint32_t nInBufferSize, uint32_t nDefaultTimeOutMs, const struct NtSecurityAttributes *opt_lpSecurityAttributes) { int64_t hServer; hServer = __imp_CreateNamedPipeW(lpName, dwOpenMode, dwPipeMode, nMaxInstances, nOutBufferSize, nInBufferSize, nDefaultTimeOutMs, opt_lpSecurityAttributes); if (hServer == -1) __winerr(); NTTRACE("CreateNamedPipe(%#hs, %s, %s, %u, %'u, %'u, %'u, %s) → %ld% m", lpName, DescribeNtPipeOpenFlags(dwOpenMode), DescribeNtPipeModeFlags(dwPipeMode), nMaxInstances, nOutBufferSize, nInBufferSize, nDefaultTimeOutMs, DescribeNtSecurityAttributes(opt_lpSecurityAttributes), hServer); return hServer; }
3,194
51
jart/cosmopolitan
false
cosmopolitan/libc/intrin/pshuflw.h
#ifndef COSMOPOLITAN_LIBC_INTRIN_PSHUFLW_H_ #define COSMOPOLITAN_LIBC_INTRIN_PSHUFLW_H_ #include "libc/intrin/macros.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ void pshuflw(int16_t[8], const int16_t[8], uint8_t); #define pshuflw(A, B, I) INTRIN_SSEVEX_X_X_I_(pshuflw, SSE2, "pshuflw", A, B, I) COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_INTRIN_PSHUFLW_H_ */
433
14
jart/cosmopolitan
false
cosmopolitan/libc/intrin/paddq.c
/*-*- 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 2020 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/paddq.h" #include "libc/str/str.h" /** * Adds 64-bit integers. * * @param 𝑎 [w/o] receives result * @param 𝑏 [r/o] supplies first input vector * @param 𝑐 [r/o] supplies second input vector * @mayalias */ void(paddq)(uint64_t a[2], const uint64_t b[2], const uint64_t c[2]) { unsigned i; uint64_t r[2]; for (i = 0; i < 2; ++i) r[i] = b[i] + c[i]; __builtin_memcpy(a, r, 16); }
2,259
36
jart/cosmopolitan
false
cosmopolitan/libc/intrin/ftrapv.c
/*-*- 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/limits.h" #include "libc/runtime/internal.h" /** * Returns -𝑥, aborting on overflow. * * @see __on_arithmetic_overflow() * @see -ftrapv to enable */ int __negvsi2(int x) { if (x == INT_MIN) { __on_arithmetic_overflow(); } return -x; } /** * Returns -𝑥 on overflow. * * @see __on_arithmetic_overflow() * @see -ftrapv to enable */ long __negvdi2(long x) { if (x == LONG_MIN) { __on_arithmetic_overflow(); } return -x; } /** * Returns -𝑥, aborting on overflow. * * @see __on_arithmetic_overflow() * @see -ftrapv to enable */ int128_t __negvti2(int128_t x) { if (x == INT128_MIN) { __on_arithmetic_overflow(); } return -x; } /** * Returns 𝑥+𝑦, aborting on overflow. * * @see __on_arithmetic_overflow() * @see -ftrapv to enable */ int __addvsi3(int x, int y) { int z; if (__builtin_add_overflow(x, y, &z)) { __on_arithmetic_overflow(); } return z; } /** * Returns 𝑥+𝑦, aborting on overflow. * * @see __on_arithmetic_overflow() * @see -ftrapv to enable */ long __addvdi3(long x, long y) { long z; if (__builtin_add_overflow(x, y, &z)) { __on_arithmetic_overflow(); } return z; } /** * Returns 𝑥+𝑦, aborting on overflow. * * @see __on_arithmetic_overflow() * @see -ftrapv to enable */ int128_t __addvti3(int128_t x, int128_t y) { int128_t z; if (__builtin_add_overflow(x, y, &z)) { __on_arithmetic_overflow(); } return z; } /** * Returns 𝑥-𝑦, aborting on overflow. * * @see __on_arithmetic_overflow() * @see -ftrapv to enable */ int __subvsi3(int x, int y) { int z; if (__builtin_sub_overflow(x, y, &z)) { __on_arithmetic_overflow(); } return z; } /** * Returns 𝑥-𝑦, aborting on overflow. * * @see __on_arithmetic_overflow() * @see -ftrapv to enable */ long __subvdi3(long x, long y) { long z; if (__builtin_sub_overflow(x, y, &z)) { __on_arithmetic_overflow(); } return z; } /** * Returns 𝑥-𝑦, aborting on overflow. * * @see __on_arithmetic_overflow() * @see -ftrapv to enable */ int128_t __subvti3(int128_t x, int128_t y) { int128_t z; if (__builtin_sub_overflow(x, y, &z)) { __on_arithmetic_overflow(); } return z; } /** * Returns 𝑥*𝑦, aborting on overflow. * * @see __on_arithmetic_overflow() * @see -ftrapv to enable */ int __mulvsi3(int x, int y) { int z; if (__builtin_mul_overflow(x, y, &z)) { __on_arithmetic_overflow(); } return z; } /** * Returns 𝑥*𝑦, aborting on overflow. * * @see __on_arithmetic_overflow() * @see -ftrapv to enable */ long __mulvdi3(long x, long y) { long z; if (__builtin_mul_overflow(x, y, &z)) { __on_arithmetic_overflow(); } return z; } /** * Returns 𝑥*𝑦, aborting on overflow. * * @see __on_arithmetic_overflow() * @see -ftrapv to enable */ int128_t __mulvti3(int128_t x, int128_t y) { int128_t z; if (__builtin_mul_overflow(x, y, &z)) { __on_arithmetic_overflow(); } return z; }
4,833
186
jart/cosmopolitan
false
cosmopolitan/libc/intrin/pcmpgtb.c
/*-*- 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 2020 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/pcmpgtb.h" #include "libc/str/str.h" /** * Compares signed 8-bit integers w/ greater than predicate. * * Note that operands can be xor'd with 0x80 for unsigned compares. * * @param 𝑎 [w/o] receives result * @param 𝑏 [r/o] supplies first input vector * @param 𝑐 [r/o] supplies second input vector * @mayalias */ void(pcmpgtb)(int8_t a[16], const int8_t b[16], const int8_t c[16]) { unsigned i; int8_t r[16]; for (i = 0; i < 16; ++i) r[i] = -(b[i] > c[i]); __builtin_memcpy(a, r, 16); }
2,370
38
jart/cosmopolitan
false
cosmopolitan/libc/intrin/x86gradenames.c
/*-*- 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 2020 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/nexgen32e/x86info.h" #include "tool/decode/lib/x86idnames.h" const struct IdName kX86GradeNames[] = { {X86_GRADE_UNKNOWN, "Unknown"}, // {X86_GRADE_APPLIANCE, "Appliance"}, // {X86_GRADE_MOBILE, "Mobile"}, // {X86_GRADE_TABLET, "Tablet"}, // {X86_GRADE_DESKTOP, "Desktop"}, // {X86_GRADE_CLIENT, "Client"}, // {X86_GRADE_DENSITY, "Density"}, // {X86_GRADE_SERVER, "Server"}, // {X86_GRADE_SCIENCE, "Science"}, // {0}, // };
2,397
34
jart/cosmopolitan
false
cosmopolitan/libc/intrin/pthread_cleanup_pop.c
/*-*- 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 2022 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/thread/posixthread.internal.h" #include "libc/thread/thread.h" #include "libc/thread/tls.h" void(pthread_cleanup_pop)(struct _pthread_cleanup_buffer *cb, int execute) { struct PosixThread *pt; if (__tls_enabled && (pt = (struct PosixThread *)__get_tls()->tib_pthread)) { _unassert(cb == pt->cleanup); pt->cleanup = cb->__prev; } if (execute) { cb->__routine(cb->__arg); } }
2,273
34
jart/cosmopolitan
false
cosmopolitan/libc/intrin/psignw.c
/*-*- 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 2020 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/psignw.h" #include "libc/str/str.h" /** * Conditionally negates or zeroes shorts. * @note goes fast w/ ssse3 (intel c. 2004, amd c. 2011) */ void(psignw)(int16_t a[8], const int16_t b[8], const int16_t c[8]) { unsigned i; for (i = 0; i < 8; ++i) { if (!c[i]) { a[i] = 0; } else if (c[i] < 0) { a[i] = -b[i]; } else { a[i] = b[i]; } } }
2,238
38
jart/cosmopolitan
false
cosmopolitan/libc/intrin/psllq.c
/*-*- 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 2020 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/psllq.h" #include "libc/str/str.h" /** * Multiplies longs by two power. * * @note c needs to be a literal, asmconstexpr, or linkconstsym * @mayalias */ void(psllq)(uint64_t a[2], const uint64_t b[2], unsigned char c) { unsigned i; if (c <= 63) { for (i = 0; i < 2; ++i) { a[i] = b[i] << c; } } else { __builtin_memset(a, 0, 16); } }
2,223
38
jart/cosmopolitan
false
cosmopolitan/libc/intrin/describentfiletypeflags.c
/*-*- 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 2022 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/describeflags.internal.h" #include "libc/macros.internal.h" #include "libc/nt/enum/filetype.h" #include "libc/sysv/consts/mremap.h" static const struct DescribeFlags kFiletypeFlags[] = { {kNtFileTypeRemote, "Remote"}, // {kNtFileTypePipe, "Pipe"}, // order matters {kNtFileTypeDisk, "Disk"}, // {kNtFileTypeChar, "Char"}, // }; const char *(DescribeNtFiletypeFlags)(char buf[64], uint32_t x) { return DescribeFlags(buf, 64, kFiletypeFlags, ARRAYLEN(kFiletypeFlags), "kNtFileType", x); }
2,404
35
jart/cosmopolitan
false
cosmopolitan/libc/intrin/strerror_wr.greg.c
/*-*- 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 2022 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/dce.h" #include "libc/fmt/fmt.h" #include "libc/intrin/kprintf.h" #include "libc/intrin/safemacros.internal.h" #include "libc/macros.internal.h" #include "libc/nt/enum/formatmessageflags.h" #include "libc/nt/enum/lang.h" #include "libc/nt/process.h" #include "libc/str/str.h" /** * Converts errno value to string with explicit windows errno too. * * @param err is error number or zero if unknown * @return 0 on success, or error code */ privileged int strerror_wr(int err, uint32_t winerr, char *buf, size_t size) { /* kprintf() weakly depends on this function */ int c, n; bool wanting; char16_t winmsg[256]; const char *sym, *msg; wanting = false; sym = firstnonnull(_strerrno(err), (wanting = true, "EUNKNOWN")); msg = firstnonnull(_strerdoc(err), (wanting = true, "No error information")); if (IsTiny()) { if (!sym) sym = "EUNKNOWN"; for (; (c = *sym++); --size) if (size > 1) *buf++ = c; if (size) *buf = 0; } else if (!IsWindows() || ((err == winerr || !winerr) && !wanting)) { ksnprintf(buf, size, "%s/%d/%s", sym, err, msg); } else { if ((n = FormatMessage( kNtFormatMessageFromSystem | kNtFormatMessageIgnoreInserts, 0, winerr, MAKELANGID(kNtLangNeutral, kNtSublangDefault), winmsg, ARRAYLEN(winmsg), 0))) { while ((n && winmsg[n - 1] <= ' ') || winmsg[n - 1] == '.') --n; ksnprintf(buf, size, "%s/%d/%s/%d/%.*hs", sym, err, msg, winerr, n, winmsg); } else { ksnprintf(buf, size, "%s/%d/%s/%d", sym, err, msg, winerr); } } return 0; }
3,434
65
jart/cosmopolitan
false
cosmopolitan/libc/intrin/describeiovnt.c
/*-*- 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 2022 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/dce.h" #include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/kprintf.h" #include "libc/macros.internal.h" #include "libc/nt/winsock.h" void DescribeIovNt(const struct NtIovec *iov, uint32_t iovlen, ssize_t rem) { int i; if ((!IsAsan() && kisdangerous(iov)) || (IsAsan() && !__asan_is_valid(iov, iovlen * sizeof(struct NtIovec)))) { kprintf("%p", iov); return; } kprintf("{"); for (i = 0; rem && i < MIN(5, iovlen); ++i) { kprintf("%s{%#.*hhs%s, %'zu}", i ? ", " : "", MAX(0, MIN(40, MIN(rem, iov[i].len))), iov[i].buf, MAX(0, MIN(40, MIN(rem, iov[i].len))) < iov[i].len ? "..." : "", iov[i].len); rem -= iov[i].len; } kprintf("%s}", iovlen > 5 ? "..." : ""); }
2,640
43
jart/cosmopolitan
false
cosmopolitan/libc/intrin/wsarecvfrom.c
/*-*- 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 2022 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/syscall_support-nt.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describentoverlapped.internal.h" #include "libc/intrin/kprintf.h" #include "libc/intrin/strace.internal.h" #include "libc/nt/thunk/msabi.h" #include "libc/nt/winsock.h" #include "libc/runtime/runtime.h" __msabi extern typeof(WSARecvFrom) *const __imp_WSARecvFrom; /** * Receives data from Windows socket. * * @return 0 on success, or -1 on failure * @note this wrapper takes care of ABI, STRACE(), and __winerr() */ textwindows int WSARecvFrom( uint64_t s, const struct NtIovec *inout_lpBuffers, uint32_t dwBufferCount, uint32_t *opt_out_lpNumberOfBytesRecvd, uint32_t *inout_lpFlags, void *opt_out_fromsockaddr, uint32_t *opt_inout_fromsockaddrlen, struct NtOverlapped *opt_inout_lpOverlapped, const NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine) { int rc; #if defined(SYSDEBUG) && _NTTRACE uint32_t NumberOfBytesRecvd; if (opt_out_lpNumberOfBytesRecvd) { NumberOfBytesRecvd = *opt_out_lpNumberOfBytesRecvd; } rc = __imp_WSARecvFrom(s, inout_lpBuffers, dwBufferCount, &NumberOfBytesRecvd, inout_lpFlags, opt_out_fromsockaddr, opt_inout_fromsockaddrlen, opt_inout_lpOverlapped, opt_lpCompletionRoutine); if (opt_out_lpNumberOfBytesRecvd) { *opt_out_lpNumberOfBytesRecvd = NumberOfBytesRecvd; } if (rc == -1) { __winerr(); } if (UNLIKELY(__strace > 0) && strace_enabled(0) > 0) { kprintf(STRACE_PROLOGUE "WSARecvFrom(%lu, [", s); DescribeIovNt(inout_lpBuffers, dwBufferCount, rc != -1 ? NumberOfBytesRecvd : 0); kprintf("], %u, [%'u], %p, %p, %p, %s, %p) → %d% lm\n", dwBufferCount, NumberOfBytesRecvd, opt_out_fromsockaddr, opt_inout_fromsockaddrlen, inout_lpFlags, DescribeNtOverlapped(opt_inout_lpOverlapped), opt_lpCompletionRoutine, rc); } #else rc = __imp_WSARecvFrom(s, inout_lpBuffers, dwBufferCount, opt_out_lpNumberOfBytesRecvd, opt_out_fromsockaddr, opt_inout_fromsockaddrlen, inout_lpFlags, opt_inout_lpOverlapped, opt_lpCompletionRoutine); #endif return rc; }
4,124
75
jart/cosmopolitan
false
cosmopolitan/libc/intrin/leaky.S
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ │vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2022 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/macros.internal.h" // Decentralized section for leaky functions. .section .piro.relo.sort.leaky.1,"aw",@nobits .type _leaky_start,@object .type _leaky_end,@object .globl _leaky_start,_leaky_end .hidden _leaky_start,_leaky_end .byte 0 .balign __SIZEOF_POINTER__ .underrun _leaky_start: .previous/* ... decentralized content ... */.section .piro.relo.sort.leaky.3,"aw",@nobits _leaky_end: .quad 0 .overrun .previous
2,282
40
jart/cosmopolitan
false
cosmopolitan/libc/intrin/strace.internal.h
#ifndef COSMOPOLITAN_LIBC_CALLS_STRACE_INTERNAL_H_ #define COSMOPOLITAN_LIBC_CALLS_STRACE_INTERNAL_H_ #include "libc/intrin/likely.h" #include "libc/runtime/runtime.h" #define _KERNTRACE 0 /* not configurable w/ flag yet */ #define _POLLTRACE 0 /* not configurable w/ flag yet */ #define _DATATRACE 1 /* not configurable w/ flag yet */ #define _STDIOTRACE 0 /* not configurable w/ flag yet */ #define _LOCKTRACE 0 /* not configurable w/ flag yet */ #define _NTTRACE 0 /* not configurable w/ flag yet */ #define STRACE_PROLOGUE "%rSYS %6P %'18T " #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ #ifdef SYSDEBUG #define STRACE(FMT, ...) \ do { \ if (UNLIKELY(__strace > 0) && strace_enabled(0) > 0) { \ __stracef(STRACE_PROLOGUE FMT "\n", ##__VA_ARGS__); \ } \ } while (0) #else #define STRACE(FMT, ...) (void)0 #endif #if defined(SYSDEBUG) && _DATATRACE #define DATATRACE(FMT, ...) STRACE(FMT, ##__VA_ARGS__) #else #define DATATRACE(FMT, ...) (void)0 #endif #if defined(SYSDEBUG) && _POLLTRACE #define POLLTRACE(FMT, ...) STRACE(FMT, ##__VA_ARGS__) #else #define POLLTRACE(FMT, ...) (void)0 #endif #if defined(SYSDEBUG) && _KERNTRACE #define KERNTRACE(FMT, ...) STRACE(FMT, ##__VA_ARGS__) #else #define KERNTRACE(FMT, ...) (void)0 #endif #if defined(SYSDEBUG) && _STDIOTRACE #define STDIOTRACE(FMT, ...) STRACE(FMT, ##__VA_ARGS__) #else #define STDIOTRACE(FMT, ...) (void)0 #endif #if defined(SYSDEBUG) && _NTTRACE #define NTTRACE(FMT, ...) STRACE(FMT, ##__VA_ARGS__) #else #define NTTRACE(FMT, ...) (void)0 #endif #if defined(SYSDEBUG) && _LOCKTRACE #define LOCKTRACE(FMT, ...) STRACE(FMT, ##__VA_ARGS__) #else #define LOCKTRACE(FMT, ...) (void)0 #endif void __stracef(const char *, ...); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_CALLS_STRACE_INTERNAL_H_ */
2,001
70
jart/cosmopolitan
false