mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-05 17:30:27 +00:00
Merge branch 'master' into ctl-shared
This commit is contained in:
commit
17589367b1
936 changed files with 6268 additions and 2180 deletions
|
@ -27,3 +27,5 @@ da8baf2aa5ce93b958aca90a0ae69f537806324b
|
||||||
369f9740de4534c28d0e81ab2afc99decbb9a3e6
|
369f9740de4534c28d0e81ab2afc99decbb9a3e6
|
||||||
# Get rid of .internal.h convention in LIBC_INTRIN
|
# Get rid of .internal.h convention in LIBC_INTRIN
|
||||||
86d884cce24d773e298a2714c1e3d91ecab9be45
|
86d884cce24d773e298a2714c1e3d91ecab9be45
|
||||||
|
# Remove .internal from more header filenames
|
||||||
|
31194165d2afca36c2315a6e7ca2f0797dde09e3
|
||||||
|
|
24
.github/workflows/nightly-cosmocc.yml
vendored
Normal file
24
.github/workflows/nightly-cosmocc.yml
vendored
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
name: Nightly cosmocc
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
# https://crontab.guru/#37_4_*_*_*
|
||||||
|
- cron: "37 4 * * *"
|
||||||
|
workflow_dispatch:
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
jobs:
|
||||||
|
build-cosmocc:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- run: |
|
||||||
|
sudo cp build/bootstrap/ape.elf /usr/bin/ape
|
||||||
|
sudo sh -c "echo ':APE:M::MZqFpD::/usr/bin/ape:' >/proc/sys/fs/binfmt_misc/register"
|
||||||
|
- run: tool/cosmocc/package.sh
|
||||||
|
# https://github.com/actions/upload-artifact/issues/590
|
||||||
|
- uses: actions/upload-artifact@v4.3.5
|
||||||
|
with:
|
||||||
|
name: cosmocc
|
||||||
|
path: cosmocc
|
||||||
|
compression-level: 9
|
36
.vscode/settings.json
vendored
Normal file
36
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
{
|
||||||
|
"C_Cpp.default.compilerPath": ".cosmocc/3.7.1/bin/aarch64-linux-cosmo-c++",
|
||||||
|
"C_Cpp.default.compilerArgs": [
|
||||||
|
"-nostdinc",
|
||||||
|
"-nostdlib",
|
||||||
|
"-iquote.",
|
||||||
|
"-isystemlibc/isystem",
|
||||||
|
"-isystemthird_party/libcxx",
|
||||||
|
"-includelibc/integral/normalize.inc",
|
||||||
|
"-D_COSMO_SOURCE",
|
||||||
|
"-D__aarch64__"
|
||||||
|
],
|
||||||
|
"[c]": {
|
||||||
|
"editor.tabSize": 2,
|
||||||
|
"editor.insertSpaces": true
|
||||||
|
},
|
||||||
|
"[cpp]": {
|
||||||
|
"editor.tabSize": 2,
|
||||||
|
"editor.insertSpaces": true
|
||||||
|
},
|
||||||
|
"[makefile]": {
|
||||||
|
"editor.tabSize": 8,
|
||||||
|
"editor.insertSpaces": false
|
||||||
|
},
|
||||||
|
"[make]": {
|
||||||
|
"editor.tabSize": 8,
|
||||||
|
"editor.insertSpaces": false
|
||||||
|
},
|
||||||
|
"[assembly]": {
|
||||||
|
"editor.tabSize": 8,
|
||||||
|
"editor.insertSpaces": true
|
||||||
|
},
|
||||||
|
"files.associations": {
|
||||||
|
"log.h": "c"
|
||||||
|
}
|
||||||
|
}
|
6
Makefile
6
Makefile
|
@ -132,7 +132,7 @@ endif
|
||||||
|
|
||||||
ifneq ($(findstring aarch64,$(MODE)),)
|
ifneq ($(findstring aarch64,$(MODE)),)
|
||||||
ARCH = aarch64
|
ARCH = aarch64
|
||||||
HOSTS ?= pi studio freebsdarm
|
HOSTS ?= pi pi5 studio freebsdarm
|
||||||
else
|
else
|
||||||
ARCH = x86_64
|
ARCH = x86_64
|
||||||
HOSTS ?= freebsd rhel7 xnu openbsd netbsd win10
|
HOSTS ?= freebsd rhel7 xnu openbsd netbsd win10
|
||||||
|
@ -147,10 +147,10 @@ export MODE
|
||||||
export SOURCE_DATE_EPOCH
|
export SOURCE_DATE_EPOCH
|
||||||
export TMPDIR
|
export TMPDIR
|
||||||
|
|
||||||
COSMOCC = .cosmocc/3.6.2
|
COSMOCC = .cosmocc/3.7.1
|
||||||
BOOTSTRAP = $(COSMOCC)/bin
|
BOOTSTRAP = $(COSMOCC)/bin
|
||||||
TOOLCHAIN = $(COSMOCC)/bin/$(ARCH)-linux-cosmo-
|
TOOLCHAIN = $(COSMOCC)/bin/$(ARCH)-linux-cosmo-
|
||||||
DOWNLOAD := $(shell build/download-cosmocc.sh $(COSMOCC) 3.6.2 268aa82d9bfd774f76951b250f87b8edcefd5c754b8b409e1639641e8bd8d5bc)
|
DOWNLOAD := $(shell build/download-cosmocc.sh $(COSMOCC) 3.7.1 13b65b0e659b493bd82f3d0a319d0265d66f849839e484aa2a54191024711e85)
|
||||||
|
|
||||||
IGNORE := $(shell $(MKDIR) $(TMPDIR))
|
IGNORE := $(shell $(MKDIR) $(TMPDIR))
|
||||||
|
|
||||||
|
|
20
ape/BUILD.mk
20
ape/BUILD.mk
|
@ -45,10 +45,10 @@ o/$(MODE)/ape: $(APE)
|
||||||
|
|
||||||
o/$(MODE)/ape/aarch64.lds: \
|
o/$(MODE)/ape/aarch64.lds: \
|
||||||
ape/aarch64.lds \
|
ape/aarch64.lds \
|
||||||
libc/zip.internal.h \
|
libc/zip.h \
|
||||||
libc/thread/tls.h \
|
libc/thread/tls.h \
|
||||||
libc/calls/struct/timespec.h \
|
libc/calls/struct/timespec.h \
|
||||||
libc/macros.internal.h \
|
libc/macros.h \
|
||||||
libc/str/str.h
|
libc/str/str.h
|
||||||
|
|
||||||
APE_LOADER_LDFLAGS = \
|
APE_LOADER_LDFLAGS = \
|
||||||
|
@ -162,8 +162,8 @@ o/$(MODE)/ape/ape-no-modify-self.o: \
|
||||||
libc/dce.h \
|
libc/dce.h \
|
||||||
libc/elf/def.h \
|
libc/elf/def.h \
|
||||||
libc/thread/tls.h \
|
libc/thread/tls.h \
|
||||||
libc/macho.internal.h \
|
libc/macho.h \
|
||||||
libc/macros.internal.h \
|
libc/macros.h \
|
||||||
libc/nexgen32e/uart.internal.h \
|
libc/nexgen32e/uart.internal.h \
|
||||||
libc/calls/metalfile.internal.h \
|
libc/calls/metalfile.internal.h \
|
||||||
libc/nt/pedef.internal.h \
|
libc/nt/pedef.internal.h \
|
||||||
|
@ -188,8 +188,8 @@ o/$(MODE)/ape/ape-copy-self.o: \
|
||||||
libc/dce.h \
|
libc/dce.h \
|
||||||
libc/elf/def.h \
|
libc/elf/def.h \
|
||||||
libc/thread/tls.h \
|
libc/thread/tls.h \
|
||||||
libc/macho.internal.h \
|
libc/macho.h \
|
||||||
libc/macros.internal.h \
|
libc/macros.h \
|
||||||
libc/nexgen32e/uart.internal.h \
|
libc/nexgen32e/uart.internal.h \
|
||||||
libc/calls/metalfile.internal.h \
|
libc/calls/metalfile.internal.h \
|
||||||
libc/nt/pedef.internal.h \
|
libc/nt/pedef.internal.h \
|
||||||
|
@ -259,8 +259,8 @@ o/$(MODE)/ape/ape.o: \
|
||||||
libc/thread/tls.h \
|
libc/thread/tls.h \
|
||||||
ape/ape.internal.h \
|
ape/ape.internal.h \
|
||||||
ape/macros.internal.h \
|
ape/macros.internal.h \
|
||||||
libc/macho.internal.h \
|
libc/macho.h \
|
||||||
libc/macros.internal.h \
|
libc/macros.h \
|
||||||
libc/sysv/consts/prot.h \
|
libc/sysv/consts/prot.h \
|
||||||
libc/nt/pedef.internal.h \
|
libc/nt/pedef.internal.h \
|
||||||
libc/runtime/pc.internal.h \
|
libc/runtime/pc.internal.h \
|
||||||
|
@ -281,7 +281,7 @@ o/$(MODE)/ape/ape.lds: \
|
||||||
libc/dce.h \
|
libc/dce.h \
|
||||||
libc/elf/def.h \
|
libc/elf/def.h \
|
||||||
libc/elf/pf2prot.internal.h \
|
libc/elf/pf2prot.internal.h \
|
||||||
libc/macros.internal.h \
|
libc/macros.h \
|
||||||
libc/nt/pedef.internal.h \
|
libc/nt/pedef.internal.h \
|
||||||
libc/str/str.h \
|
libc/str/str.h \
|
||||||
libc/zip.internal.h
|
libc/zip.h
|
||||||
|
|
|
@ -16,6 +16,12 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
|
#ifndef __APPLE__
|
||||||
|
#error "ape/ape-m1.c is for apple silicon. chances you want ape/loader.c"
|
||||||
|
#endif
|
||||||
|
#ifndef __aarch64__
|
||||||
|
#error "ape/ape-m1.c is for apple silicon; you want: make o//ape/ape.macho"
|
||||||
|
#endif
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <dispatch/dispatch.h>
|
#include <dispatch/dispatch.h>
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
#include "libc/calls/metalfile.internal.h"
|
#include "libc/calls/metalfile.internal.h"
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
#include "libc/elf/def.h"
|
#include "libc/elf/def.h"
|
||||||
#include "libc/macho.internal.h"
|
#include "libc/macho.h"
|
||||||
#include "libc/nexgen32e/uart.internal.h"
|
#include "libc/nexgen32e/uart.internal.h"
|
||||||
#include "libc/nt/pedef.internal.h"
|
#include "libc/nt/pedef.internal.h"
|
||||||
#include "libc/runtime/pc.internal.h"
|
#include "libc/runtime/pc.internal.h"
|
||||||
|
|
|
@ -310,7 +310,7 @@ SECTIONS {
|
||||||
. = ALIGN(__privileged_end > __privileged_start ? CONSTANT(COMMONPAGESIZE) : 0);
|
. = ALIGN(__privileged_end > __privileged_start ? CONSTANT(COMMONPAGESIZE) : 0);
|
||||||
/*END: morphable code */
|
/*END: morphable code */
|
||||||
__privileged_start = .;
|
__privileged_start = .;
|
||||||
*(.privileged)
|
*(.privileged .privileged.*)
|
||||||
__privileged_end = .;
|
__privileged_end = .;
|
||||||
|
|
||||||
KEEP(*(.ape.pad.text))
|
KEEP(*(.ape.pad.text))
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
|
|
||||||
// Calls _start() function of loaded program.
|
// Calls _start() function of loaded program.
|
||||||
//
|
//
|
||||||
|
|
|
@ -16,10 +16,10 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macho.internal.h"
|
#include "libc/macho.h"
|
||||||
#include "libc/sysv/consts/prot.h"
|
#include "libc/sysv/consts/prot.h"
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
|
|
||||||
// Apple Mach-O Executable Headers
|
// Apple Mach-O Executable Headers
|
||||||
// Fixups are applied by objbincopy
|
// Fixups are applied by objbincopy
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#ifndef APE_MACROS_H_
|
#ifndef APE_MACROS_H_
|
||||||
#define APE_MACROS_H_
|
#define APE_MACROS_H_
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#ifdef __ASSEMBLER__
|
#ifdef __ASSEMBLER__
|
||||||
/* clang-format off */
|
/* clang-format off */
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
#include "ape/ape.h"
|
#include "ape/ape.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
|
|
||||||
#ifdef __aarch64__
|
#ifdef __aarch64__
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
|
|
||||||
// Invokes system call.
|
// Invokes system call.
|
||||||
//
|
//
|
||||||
|
|
|
@ -115,14 +115,10 @@ ifeq ($(ARCH), aarch64)
|
||||||
# - Cosmopolitan Libc uses x28 for thread-local storage because Apple
|
# - Cosmopolitan Libc uses x28 for thread-local storage because Apple
|
||||||
# forbids us from using tpidr_el0 too.
|
# forbids us from using tpidr_el0 too.
|
||||||
#
|
#
|
||||||
# - Cosmopolitan currently lacks an implementation of the runtime
|
|
||||||
# libraries needed by the -moutline-atomics flag
|
|
||||||
#
|
|
||||||
DEFAULT_COPTS += \
|
DEFAULT_COPTS += \
|
||||||
-ffixed-x18 \
|
-ffixed-x18 \
|
||||||
-ffixed-x28 \
|
-ffixed-x28 \
|
||||||
-fsigned-char \
|
-fsigned-char
|
||||||
-mno-outline-atomics
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
MATHEMATICAL = \
|
MATHEMATICAL = \
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#ifndef COSMOPOLITAN_DSP_CORE_C161_H_
|
#ifndef COSMOPOLITAN_DSP_CORE_C161_H_
|
||||||
#define COSMOPOLITAN_DSP_CORE_C161_H_
|
#define COSMOPOLITAN_DSP_CORE_C161_H_
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
|
|
||||||
#define EXTRA_SHARP 2
|
#define EXTRA_SHARP 2
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef COSMOPOLITAN_DSP_CORE_C161S_H_
|
#ifndef COSMOPOLITAN_DSP_CORE_C161S_H_
|
||||||
#define COSMOPOLITAN_DSP_CORE_C161S_H_
|
#define COSMOPOLITAN_DSP_CORE_C161S_H_
|
||||||
#include "dsp/core/c161.h"
|
#include "dsp/core/c161.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
|
|
||||||
__funline signed char C161S(signed char al, signed char bl, signed char cl) {
|
__funline signed char C161S(signed char al, signed char bl, signed char cl) {
|
||||||
short ax, bx, cx;
|
short ax, bx, cx;
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "dsp/core/core.h"
|
#include "dsp/core/core.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/math.h"
|
#include "libc/math.h"
|
||||||
#include "libc/mem/mem.h"
|
#include "libc/mem/mem.h"
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/limits.h"
|
#include "libc/limits.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/math.h"
|
#include "libc/math.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#include "libc/assert.h"
|
#include "libc/assert.h"
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
#include "libc/limits.h"
|
#include "libc/limits.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/math.h"
|
#include "libc/math.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#include "dsp/core/core.h"
|
#include "dsp/core/core.h"
|
||||||
#include "dsp/core/q.h"
|
#include "dsp/core/q.h"
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/math.h"
|
#include "libc/math.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#ifndef COSMOPOLITAN_DSP_CORE_HALF_H_
|
#ifndef COSMOPOLITAN_DSP_CORE_HALF_H_
|
||||||
#define COSMOPOLITAN_DSP_CORE_HALF_H_
|
#define COSMOPOLITAN_DSP_CORE_HALF_H_
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Divides integer in half w/ rounding.
|
* Divides integer in half w/ rounding.
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#ifndef COSMOPOLITAN_DSP_CORE_KS8_H_
|
#ifndef COSMOPOLITAN_DSP_CORE_KS8_H_
|
||||||
#define COSMOPOLITAN_DSP_CORE_KS8_H_
|
#define COSMOPOLITAN_DSP_CORE_KS8_H_
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs 16-bit scaled rounded madd w/ eight coefficients or fewer.
|
* Performs 16-bit scaled rounded madd w/ eight coefficients or fewer.
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef COSMOPOLITAN_DSP_CORE_KSS8_H_
|
#ifndef COSMOPOLITAN_DSP_CORE_KSS8_H_
|
||||||
#define COSMOPOLITAN_DSP_CORE_KSS8_H_
|
#define COSMOPOLITAN_DSP_CORE_KSS8_H_
|
||||||
#include "libc/limits.h"
|
#include "libc/limits.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs 16-bit scaled rounded saturated madd w/ eight coefficients or fewer.
|
* Performs 16-bit scaled rounded saturated madd w/ eight coefficients or fewer.
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef COSMOPOLITAN_DSP_CORE_Q_H_
|
#ifndef COSMOPOLITAN_DSP_CORE_Q_H_
|
||||||
#define COSMOPOLITAN_DSP_CORE_Q_H_
|
#define COSMOPOLITAN_DSP_CORE_Q_H_
|
||||||
#include "libc/limits.h"
|
#include "libc/limits.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/math.h"
|
#include "libc/math.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "dsp/core/core.h"
|
#include "dsp/core/core.h"
|
||||||
#include "libc/limits.h"
|
#include "libc/limits.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "third_party/aarch64/arm_neon.internal.h"
|
#include "third_party/aarch64/arm_neon.internal.h"
|
||||||
#include "third_party/intel/emmintrin.internal.h"
|
#include "third_party/intel/emmintrin.internal.h"
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
|
|
||||||
clamp4int256$core:
|
clamp4int256$core:
|
||||||
.leafprologue
|
.leafprologue
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
#include "libc/calls/struct/timespec.h"
|
#include "libc/calls/struct/timespec.h"
|
||||||
#include "libc/fmt/conv.h"
|
#include "libc/fmt/conv.h"
|
||||||
#include "libc/log/log.h"
|
#include "libc/log/log.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/math.h"
|
#include "libc/math.h"
|
||||||
#include "libc/mem/mem.h"
|
#include "libc/mem/mem.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
│ SOFTWARE. │
|
│ SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "dsp/mpeg/mpeg.h"
|
#include "dsp/mpeg/mpeg.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
__static_yoink("pl_mpeg_notice");
|
__static_yoink("pl_mpeg_notice");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -45,6 +45,12 @@ $(DSP_SCALE_A).pkg: \
|
||||||
$(DSP_SCALE_A_OBJS) \
|
$(DSP_SCALE_A_OBJS) \
|
||||||
$(foreach x,$(DSP_SCALE_A_DIRECTDEPS),$($(x)_A).pkg)
|
$(foreach x,$(DSP_SCALE_A_DIRECTDEPS),$($(x)_A).pkg)
|
||||||
|
|
||||||
|
ifeq ($(ARCH),x86_64)
|
||||||
|
o/$(MODE)/dsp/scale/cdecimate2xuint8x8.o: private \
|
||||||
|
CFLAGS += \
|
||||||
|
-mssse3
|
||||||
|
endif
|
||||||
|
|
||||||
o/$(MODE)/dsp/scale/cdecimate2xuint8x8.o \
|
o/$(MODE)/dsp/scale/cdecimate2xuint8x8.o \
|
||||||
o/$(MODE)/dsp/scale/gyarados.o \
|
o/$(MODE)/dsp/scale/gyarados.o \
|
||||||
o/$(MODE)/dsp/scale/magikarp.o \
|
o/$(MODE)/dsp/scale/magikarp.o \
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
#include "libc/limits.h"
|
#include "libc/limits.h"
|
||||||
#include "libc/log/check.h"
|
#include "libc/log/check.h"
|
||||||
#include "libc/log/log.h"
|
#include "libc/log/log.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/math.h"
|
#include "libc/math.h"
|
||||||
#include "libc/mem/gc.h"
|
#include "libc/mem/gc.h"
|
||||||
#include "libc/mem/mem.h"
|
#include "libc/mem/mem.h"
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#include "dsp/core/ks8.h"
|
#include "dsp/core/ks8.h"
|
||||||
#include "dsp/core/kss8.h"
|
#include "dsp/core/kss8.h"
|
||||||
#include "dsp/scale/cdecimate2xuint8x8.h"
|
#include "dsp/scale/cdecimate2xuint8x8.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/nexgen32e/x86feature.h"
|
#include "libc/nexgen32e/x86feature.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
#include "libc/x/x.h"
|
#include "libc/x/x.h"
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
|
|
||||||
// TODO(jart): write me
|
// TODO(jart): write me
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#include "libc/assert.h"
|
#include "libc/assert.h"
|
||||||
#include "libc/limits.h"
|
#include "libc/limits.h"
|
||||||
#include "libc/log/log.h"
|
#include "libc/log/log.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/math.h"
|
#include "libc/math.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "dsp/tty/quant.h"
|
#include "dsp/tty/quant.h"
|
||||||
#include "libc/log/check.h"
|
#include "libc/log/check.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
|
|
||||||
struct TtyRgb rgb2ttyi2f_(int r, int g, int b) {
|
struct TtyRgb rgb2ttyi2f_(int r, int g, int b) {
|
||||||
return rgb2ttyf((ttyrgb_m128){r, g, b} / 255);
|
return rgb2ttyf((ttyrgb_m128){r, g, b} / 255);
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "dsp/tty/quant.h"
|
#include "dsp/tty/quant.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
|
|
||||||
struct TtyRgb rgb2xterm24_(int r, int g, int b) {
|
struct TtyRgb rgb2xterm24_(int r, int g, int b) {
|
||||||
return (struct TtyRgb){MAX(MIN(r, 255), 0), MAX(MIN(g, 255), 0),
|
return (struct TtyRgb){MAX(MIN(r, 255), 0), MAX(MIN(g, 255), 0),
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "dsp/tty/quant.h"
|
#include "dsp/tty/quant.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/math.h"
|
#include "libc/math.h"
|
||||||
#include "third_party/intel/xmmintrin.internal.h"
|
#include "third_party/intel/xmmintrin.internal.h"
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#include "libc/limits.h"
|
#include "libc/limits.h"
|
||||||
#include "libc/log/check.h"
|
#include "libc/log/check.h"
|
||||||
#include "libc/log/log.h"
|
#include "libc/log/log.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/math.h"
|
#include "libc/math.h"
|
||||||
#include "libc/nexgen32e/x86feature.h"
|
#include "libc/nexgen32e/x86feature.h"
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#include "libc/calls/termios.h"
|
#include "libc/calls/termios.h"
|
||||||
#include "libc/calls/ucontext.h"
|
#include "libc/calls/ucontext.h"
|
||||||
#include "libc/log/log.h"
|
#include "libc/log/log.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/mem/gc.h"
|
#include "libc/mem/gc.h"
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
|
|
||||||
// Returns index of minimum uint16 in array.
|
// Returns index of minimum uint16 in array.
|
||||||
//
|
//
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
|
|
||||||
// Returns index of minimum positive int16 in array.
|
// Returns index of minimum positive int16 in array.
|
||||||
//
|
//
|
||||||
|
|
|
@ -53,6 +53,7 @@ EXAMPLES_DIRECTDEPS = \
|
||||||
LIBC_NEXGEN32E \
|
LIBC_NEXGEN32E \
|
||||||
LIBC_NT_ADVAPI32 \
|
LIBC_NT_ADVAPI32 \
|
||||||
LIBC_NT_IPHLPAPI \
|
LIBC_NT_IPHLPAPI \
|
||||||
|
LIBC_NT_MEMORY \
|
||||||
LIBC_NT_KERNEL32 \
|
LIBC_NT_KERNEL32 \
|
||||||
LIBC_NT_NTDLL \
|
LIBC_NT_NTDLL \
|
||||||
LIBC_NT_USER32 \
|
LIBC_NT_USER32 \
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
#include "libc/calls/struct/timespec.h"
|
#include "libc/calls/struct/timespec.h"
|
||||||
#include "libc/intrin/kprintf.h"
|
#include "libc/intrin/kprintf.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/nt/enum/timezoneid.h"
|
#include "libc/nt/enum/timezoneid.h"
|
||||||
#include "libc/nt/struct/timezoneinformation.h"
|
#include "libc/nt/struct/timezoneinformation.h"
|
||||||
#include "libc/nt/time.h"
|
#include "libc/nt/time.h"
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
#include "libc/fmt/conv.h"
|
#include "libc/fmt/conv.h"
|
||||||
#include "libc/log/log.h"
|
#include "libc/log/log.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
#include "libc/sock/sock.h"
|
#include "libc/sock/sock.h"
|
||||||
#include "libc/sock/struct/linger.h"
|
#include "libc/sock/struct/linger.h"
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
#include "libc/inttypes.h"
|
#include "libc/inttypes.h"
|
||||||
#include "libc/log/check.h"
|
#include "libc/log/check.h"
|
||||||
#include "libc/log/log.h"
|
#include "libc/log/log.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/math.h"
|
#include "libc/math.h"
|
||||||
#include "libc/mem/arraylist2.internal.h"
|
#include "libc/mem/arraylist2.internal.h"
|
||||||
#include "libc/mem/mem.h"
|
#include "libc/mem/mem.h"
|
||||||
|
@ -47,7 +47,7 @@
|
||||||
#include "libc/time.h"
|
#include "libc/time.h"
|
||||||
#include "libc/x/xasprintf.h"
|
#include "libc/x/xasprintf.h"
|
||||||
#include "libc/x/xsigaction.h"
|
#include "libc/x/xsigaction.h"
|
||||||
#include "libc/zip.internal.h"
|
#include "libc/zip.h"
|
||||||
#include "third_party/getopt/getopt.internal.h"
|
#include "third_party/getopt/getopt.internal.h"
|
||||||
#include "third_party/libcxx/vector"
|
#include "third_party/libcxx/vector"
|
||||||
#include "tool/viz/lib/knobs.h"
|
#include "tool/viz/lib/knobs.h"
|
||||||
|
|
15
examples/nproc.c
Normal file
15
examples/nproc.c
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#if 0
|
||||||
|
/*─────────────────────────────────────────────────────────────────╗
|
||||||
|
│ To the extent possible under law, Justine Tunney has waived │
|
||||||
|
│ all copyright and related or neighboring rights to this file, │
|
||||||
|
│ as it is written in the following disclaimers: │
|
||||||
|
│ • http://unlicense.org/ │
|
||||||
|
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||||
|
╚─────────────────────────────────────────────────────────────────*/
|
||||||
|
#endif
|
||||||
|
#include <cosmo.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
printf("%d\n", __get_cpu_count());
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
|
|
||||||
// Example assembly function.
|
// Example assembly function.
|
||||||
//
|
//
|
||||||
|
|
1021
examples/romanize.c
Normal file
1021
examples/romanize.c
Normal file
File diff suppressed because it is too large
Load diff
|
@ -41,7 +41,7 @@
|
||||||
#include "libc/fmt/conv.h"
|
#include "libc/fmt/conv.h"
|
||||||
#include "libc/intrin/bswap.h"
|
#include "libc/intrin/bswap.h"
|
||||||
#include "libc/log/bsd.h"
|
#include "libc/log/bsd.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/mem/mem.h"
|
#include "libc/mem/mem.h"
|
||||||
#include "libc/paths.h"
|
#include "libc/paths.h"
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/struct/cpuset.h"
|
#include "libc/calls/struct/cpuset.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
|
|
||||||
void CPU_AND(cpu_set_t *d, cpu_set_t *x, cpu_set_t *y) {
|
void CPU_AND(cpu_set_t *d, cpu_set_t *x, cpu_set_t *y) {
|
||||||
int i;
|
int i;
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/struct/cpuset.h"
|
#include "libc/calls/struct/cpuset.h"
|
||||||
#include "libc/intrin/popcnt.h"
|
#include "libc/intrin/popcnt.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
|
|
||||||
int CPU_COUNT(cpu_set_t *set) {
|
int CPU_COUNT(cpu_set_t *set) {
|
||||||
int i, c;
|
int i, c;
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/struct/cpuset.h"
|
#include "libc/calls/struct/cpuset.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
|
|
||||||
void CPU_OR(cpu_set_t *d, cpu_set_t *x, cpu_set_t *y) {
|
void CPU_OR(cpu_set_t *d, cpu_set_t *x, cpu_set_t *y) {
|
||||||
int i;
|
int i;
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/struct/cpuset.h"
|
#include "libc/calls/struct/cpuset.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
|
|
||||||
void CPU_XOR(cpu_set_t *d, cpu_set_t *x, cpu_set_t *y) {
|
void CPU_XOR(cpu_set_t *d, cpu_set_t *x, cpu_set_t *y) {
|
||||||
int i;
|
int i;
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/syscall_support-nt.internal.h"
|
#include "libc/calls/syscall_support-nt.internal.h"
|
||||||
#include "libc/errno.h"
|
#include "libc/errno.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/nt/errors.h"
|
#include "libc/nt/errors.h"
|
||||||
#include "libc/nt/files.h"
|
#include "libc/nt/files.h"
|
||||||
#include "libc/nt/process.h"
|
#include "libc/nt/process.h"
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#include "libc/calls/struct/timeval.h"
|
#include "libc/calls/struct/timeval.h"
|
||||||
#include "libc/calls/struct/timeval.internal.h"
|
#include "libc/calls/struct/timeval.internal.h"
|
||||||
#include "libc/errno.h"
|
#include "libc/errno.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/sysv/consts/clock.h"
|
#include "libc/sysv/consts/clock.h"
|
||||||
#ifdef __x86_64__
|
#ifdef __x86_64__
|
||||||
|
|
||||||
|
|
|
@ -17,13 +17,14 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/internal.h"
|
#include "libc/calls/internal.h"
|
||||||
#include "libc/intrin/fds.h"
|
|
||||||
#include "libc/calls/syscall-nt.internal.h"
|
#include "libc/calls/syscall-nt.internal.h"
|
||||||
#include "libc/calls/syscall_support-nt.internal.h"
|
#include "libc/calls/syscall_support-nt.internal.h"
|
||||||
|
#include "libc/intrin/fds.h"
|
||||||
#include "libc/intrin/weaken.h"
|
#include "libc/intrin/weaken.h"
|
||||||
#include "libc/nt/enum/filetype.h"
|
#include "libc/nt/enum/filetype.h"
|
||||||
#include "libc/nt/files.h"
|
#include "libc/nt/files.h"
|
||||||
#include "libc/nt/runtime.h"
|
#include "libc/nt/runtime.h"
|
||||||
|
#include "libc/runtime/runtime.h"
|
||||||
#include "libc/runtime/zipos.internal.h"
|
#include "libc/runtime/zipos.internal.h"
|
||||||
#include "libc/sock/syscall_fd.internal.h"
|
#include "libc/sock/syscall_fd.internal.h"
|
||||||
#include "libc/sysv/consts/o.h"
|
#include "libc/sysv/consts/o.h"
|
||||||
|
@ -64,5 +65,7 @@ textwindows int sys_close_nt(int fd, int fildes) {
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (f->cursor)
|
||||||
|
__cursor_unref(f->cursor);
|
||||||
return CloseHandle(f->handle) ? 0 : __winerr();
|
return CloseHandle(f->handle) ? 0 : __winerr();
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "libc/calls/struct/sigset.internal.h"
|
#include "libc/calls/struct/sigset.internal.h"
|
||||||
#include "libc/calls/syscall_support-nt.internal.h"
|
#include "libc/calls/syscall_support-nt.internal.h"
|
||||||
#include "libc/errno.h"
|
#include "libc/errno.h"
|
||||||
|
#include "libc/intrin/fds.h"
|
||||||
#include "libc/intrin/kprintf.h"
|
#include "libc/intrin/kprintf.h"
|
||||||
#include "libc/intrin/weaken.h"
|
#include "libc/intrin/weaken.h"
|
||||||
#include "libc/nt/files.h"
|
#include "libc/nt/files.h"
|
||||||
|
@ -82,6 +83,7 @@ static textwindows int sys_dup_nt_impl(int oldfd, int newfd, int flags,
|
||||||
|
|
||||||
g_fds.p[newfd] = g_fds.p[oldfd];
|
g_fds.p[newfd] = g_fds.p[oldfd];
|
||||||
g_fds.p[newfd].handle = handle;
|
g_fds.p[newfd].handle = handle;
|
||||||
|
__cursor_ref(g_fds.p[newfd].cursor);
|
||||||
if (flags & _O_CLOEXEC) {
|
if (flags & _O_CLOEXEC) {
|
||||||
g_fds.p[newfd].flags |= _O_CLOEXEC;
|
g_fds.p[newfd].flags |= _O_CLOEXEC;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -20,18 +20,18 @@
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
#include "libc/calls/createfileflags.internal.h"
|
#include "libc/calls/createfileflags.internal.h"
|
||||||
#include "libc/calls/internal.h"
|
#include "libc/calls/internal.h"
|
||||||
#include "libc/intrin/fds.h"
|
|
||||||
#include "libc/calls/struct/flock.h"
|
#include "libc/calls/struct/flock.h"
|
||||||
#include "libc/calls/struct/sigset.internal.h"
|
#include "libc/calls/struct/sigset.internal.h"
|
||||||
#include "libc/calls/syscall-nt.internal.h"
|
#include "libc/calls/syscall-nt.internal.h"
|
||||||
#include "libc/calls/syscall_support-nt.internal.h"
|
#include "libc/calls/syscall_support-nt.internal.h"
|
||||||
#include "libc/calls/wincrash.internal.h"
|
#include "libc/calls/wincrash.internal.h"
|
||||||
#include "libc/errno.h"
|
#include "libc/errno.h"
|
||||||
|
#include "libc/intrin/fds.h"
|
||||||
#include "libc/intrin/kprintf.h"
|
#include "libc/intrin/kprintf.h"
|
||||||
#include "libc/intrin/weaken.h"
|
#include "libc/intrin/weaken.h"
|
||||||
#include "libc/limits.h"
|
#include "libc/limits.h"
|
||||||
#include "libc/log/backtrace.internal.h"
|
#include "libc/log/backtrace.internal.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/mem/leaks.h"
|
#include "libc/mem/leaks.h"
|
||||||
#include "libc/mem/mem.h"
|
#include "libc/mem/mem.h"
|
||||||
#include "libc/nt/createfile.h"
|
#include "libc/nt/createfile.h"
|
||||||
|
@ -151,7 +151,7 @@ static textwindows int sys_fcntl_nt_lock(struct Fd *f, int fd, int cmd,
|
||||||
case SEEK_SET:
|
case SEEK_SET:
|
||||||
break;
|
break;
|
||||||
case SEEK_CUR:
|
case SEEK_CUR:
|
||||||
off = f->pointer + off;
|
off = f->cursor->shared->pointer + off;
|
||||||
break;
|
break;
|
||||||
case SEEK_END: {
|
case SEEK_END: {
|
||||||
int64_t size;
|
int64_t size;
|
||||||
|
@ -351,9 +351,14 @@ textwindows int sys_fcntl_nt(int fd, int cmd, uintptr_t arg) {
|
||||||
}
|
}
|
||||||
rc = 0;
|
rc = 0;
|
||||||
} else if (cmd == F_SETLK || cmd == F_SETLKW || cmd == F_GETLK) {
|
} else if (cmd == F_SETLK || cmd == F_SETLKW || cmd == F_GETLK) {
|
||||||
pthread_mutex_lock(&g_locks.mu);
|
struct Fd *f = g_fds.p + fd;
|
||||||
rc = sys_fcntl_nt_lock(g_fds.p + fd, fd, cmd, arg);
|
if (f->cursor) {
|
||||||
pthread_mutex_unlock(&g_locks.mu);
|
pthread_mutex_lock(&g_locks.mu);
|
||||||
|
rc = sys_fcntl_nt_lock(f, fd, cmd, arg);
|
||||||
|
pthread_mutex_unlock(&g_locks.mu);
|
||||||
|
} else {
|
||||||
|
rc = ebadf();
|
||||||
|
}
|
||||||
} else if (cmd == F_DUPFD || cmd == F_DUPFD_CLOEXEC) {
|
} else if (cmd == F_DUPFD || cmd == F_DUPFD_CLOEXEC) {
|
||||||
rc = sys_fcntl_nt_dupfd(fd, cmd, arg);
|
rc = sys_fcntl_nt_dupfd(fd, cmd, arg);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
#include "libc/intrin/atomic.h"
|
#include "libc/intrin/atomic.h"
|
||||||
#include "libc/intrin/bsr.h"
|
#include "libc/intrin/bsr.h"
|
||||||
#include "libc/intrin/strace.h"
|
#include "libc/intrin/strace.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/mem/alloca.h"
|
#include "libc/mem/alloca.h"
|
||||||
#include "libc/nt/enum/fileflagandattributes.h"
|
#include "libc/nt/enum/fileflagandattributes.h"
|
||||||
#include "libc/nt/enum/fileinfobyhandleclass.h"
|
#include "libc/nt/enum/fileinfobyhandleclass.h"
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
#include "libc/calls/struct/statfs.internal.h"
|
#include "libc/calls/struct/statfs.internal.h"
|
||||||
#include "libc/calls/syscall_support-nt.internal.h"
|
#include "libc/calls/syscall_support-nt.internal.h"
|
||||||
#include "libc/limits.h"
|
#include "libc/limits.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/nt/enum/fsinformationclass.h"
|
#include "libc/nt/enum/fsinformationclass.h"
|
||||||
#include "libc/nt/enum/status.h"
|
#include "libc/nt/enum/status.h"
|
||||||
#include "libc/nt/files.h"
|
#include "libc/nt/files.h"
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
|
|
||||||
// Gets machine state.
|
// Gets machine state.
|
||||||
//
|
//
|
||||||
|
|
|
@ -30,39 +30,63 @@
|
||||||
|
|
||||||
int sys_getcpu(unsigned *opt_cpu, unsigned *opt_node, void *tcache);
|
int sys_getcpu(unsigned *opt_cpu, unsigned *opt_node, void *tcache);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines ID of CPU on which thread is currently scheduled.
|
||||||
|
*
|
||||||
|
* This is the same as sched_getcpu(), except it also supports returning
|
||||||
|
* the ID of the current NUMA node. On some platforms this functionality
|
||||||
|
* isn't available, in which case `out_opt_node` is always be set to 0.
|
||||||
|
*/
|
||||||
int getcpu(unsigned *out_opt_cpu, unsigned *out_opt_node) {
|
int getcpu(unsigned *out_opt_cpu, unsigned *out_opt_node) {
|
||||||
unsigned cpu;
|
|
||||||
unsigned node;
|
if (IsWindows()) {
|
||||||
if (X86_HAVE(RDTSCP)) {
|
struct NtProcessorNumber pn;
|
||||||
|
if (out_opt_cpu) {
|
||||||
|
GetCurrentProcessorNumberEx(&pn);
|
||||||
|
*out_opt_cpu = 64 * pn.Group + pn.Number;
|
||||||
|
}
|
||||||
|
if (out_opt_node) {
|
||||||
|
unsigned short node16;
|
||||||
|
if (GetNumaProcessorNodeEx(&pn, &node16)) {
|
||||||
|
*out_opt_node = node16;
|
||||||
|
} else {
|
||||||
|
return __winerr();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __x86_64__
|
||||||
|
if (X86_HAVE(RDTSCP) && (IsLinux() || IsFreebsd())) {
|
||||||
unsigned tsc_aux;
|
unsigned tsc_aux;
|
||||||
rdtscp(&tsc_aux);
|
rdtscp(&tsc_aux);
|
||||||
cpu = TSC_AUX_CORE(tsc_aux);
|
if (out_opt_cpu)
|
||||||
node = TSC_AUX_NODE(tsc_aux);
|
*out_opt_cpu = TSC_AUX_CORE(tsc_aux);
|
||||||
} else if (IsWindows()) {
|
if (out_opt_node)
|
||||||
struct NtProcessorNumber pn;
|
*out_opt_node = TSC_AUX_NODE(tsc_aux);
|
||||||
GetCurrentProcessorNumberEx(&pn);
|
return 0;
|
||||||
cpu = 64 * pn.Group + pn.Number;
|
}
|
||||||
unsigned short node16;
|
#endif
|
||||||
if (GetNumaProcessorNodeEx(&pn, &node16)) {
|
|
||||||
node = node16;
|
if (IsXnu() || IsOpenbsd() || IsNetbsd() || IsFreebsd()) {
|
||||||
} else {
|
if (out_opt_cpu) {
|
||||||
return __winerr();
|
int rc = sched_getcpu();
|
||||||
|
if (rc == -1)
|
||||||
|
return -1;
|
||||||
|
*out_opt_cpu = rc;
|
||||||
}
|
}
|
||||||
} else if (IsAarch64()) {
|
if (out_opt_node)
|
||||||
long tpidr_el0;
|
*out_opt_node = 0;
|
||||||
asm("mrs\t%0,tpidr_el0" : "=r"(tpidr_el0));
|
return 0;
|
||||||
cpu = tpidr_el0 & 255;
|
|
||||||
node = 0;
|
|
||||||
} else {
|
|
||||||
int rc = sys_getcpu(&cpu, &node, 0);
|
|
||||||
if (rc == -1)
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
if (out_opt_cpu) {
|
|
||||||
|
unsigned cpu, node;
|
||||||
|
int rc = sys_getcpu(&cpu, &node, 0);
|
||||||
|
if (rc == -1)
|
||||||
|
return -1;
|
||||||
|
if (out_opt_cpu)
|
||||||
*out_opt_cpu = cpu;
|
*out_opt_cpu = cpu;
|
||||||
}
|
if (out_opt_node)
|
||||||
if (out_opt_node) {
|
|
||||||
*out_opt_node = node;
|
*out_opt_node = node;
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#include "libc/calls/syscall_support-sysv.internal.h"
|
#include "libc/calls/syscall_support-sysv.internal.h"
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
#include "libc/intrin/strace.h"
|
#include "libc/intrin/strace.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/nt/enum/computernameformat.h"
|
#include "libc/nt/enum/computernameformat.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/struct/rlimit.h"
|
#include "libc/calls/struct/rlimit.h"
|
||||||
#include "libc/limits.h"
|
#include "libc/limits.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
#include "libc/sysv/consts/rlimit.h"
|
#include "libc/sysv/consts/rlimit.h"
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
#include "libc/calls/syscall_support-nt.internal.h"
|
#include "libc/calls/syscall_support-nt.internal.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/nt/enum/computernameformat.h"
|
#include "libc/nt/enum/computernameformat.h"
|
||||||
#include "libc/nt/systeminfo.h"
|
#include "libc/nt/systeminfo.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#include "libc/calls/syscall_support-nt.internal.h"
|
#include "libc/calls/syscall_support-nt.internal.h"
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
#include "libc/fmt/conv.h"
|
#include "libc/fmt/conv.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/nt/accounting.h"
|
#include "libc/nt/accounting.h"
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
#include "libc/thread/thread.h"
|
#include "libc/thread/thread.h"
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
|
|
||||||
// Obtains WIN32 magic path, e.g. GetTempPathA.
|
// Obtains WIN32 magic path, e.g. GetTempPathA.
|
||||||
//
|
//
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
#include "libc/intrin/getenv.h"
|
#include "libc/intrin/getenv.h"
|
||||||
#include "libc/intrin/strace.h"
|
#include "libc/intrin/strace.h"
|
||||||
#include "libc/limits.h"
|
#include "libc/limits.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/nt/runtime.h"
|
#include "libc/nt/runtime.h"
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
#include "libc/serialize.h"
|
#include "libc/serialize.h"
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
#include "libc/intrin/asmflag.h"
|
#include "libc/intrin/asmflag.h"
|
||||||
#include "libc/intrin/strace.h"
|
#include "libc/intrin/strace.h"
|
||||||
#include "libc/intrin/weaken.h"
|
#include "libc/intrin/weaken.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/nexgen32e/kcpuids.h"
|
#include "libc/nexgen32e/kcpuids.h"
|
||||||
#include "libc/nexgen32e/rdtsc.h"
|
#include "libc/nexgen32e/rdtsc.h"
|
||||||
#include "libc/nexgen32e/vendor.internal.h"
|
#include "libc/nexgen32e/vendor.internal.h"
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/internal.h"
|
#include "libc/calls/internal.h"
|
||||||
#include "libc/intrin/atomic.h"
|
#include "libc/intrin/atomic.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/nt/accounting.h"
|
#include "libc/nt/accounting.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
#include "libc/intrin/atomic.h"
|
#include "libc/intrin/atomic.h"
|
||||||
#include "libc/intrin/strace.h"
|
#include "libc/intrin/strace.h"
|
||||||
#include "libc/limits.h"
|
#include "libc/limits.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,9 @@ COSMOPOLITAN_C_START_
|
||||||
int sys_getgroups(int size, uint32_t list[]);
|
int sys_getgroups(int size, uint32_t list[]);
|
||||||
int sys_setgroups(size_t size, const uint32_t list[]);
|
int sys_setgroups(size_t size, const uint32_t list[]);
|
||||||
|
|
||||||
const char *DescribeGidList(char[128], int, int, const uint32_t list[]);
|
const char *_DescribeGidList(char[128], int, int, const uint32_t list[]);
|
||||||
#define DescribeGidList(rc, length, gidlist) \
|
#define DescribeGidList(rc, length, gidlist) \
|
||||||
DescribeGidList(alloca(128), rc, length, gidlist)
|
_DescribeGidList(alloca(128), rc, length, gidlist)
|
||||||
|
|
||||||
COSMOPOLITAN_C_END_
|
COSMOPOLITAN_C_END_
|
||||||
#endif /* COSMOPOLITAN_LIBC_CALLS_GROUPS_INTERNAL_H_ */
|
#endif /* COSMOPOLITAN_LIBC_CALLS_GROUPS_INTERNAL_H_ */
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include "libc/intrin/fds.h"
|
#include "libc/intrin/fds.h"
|
||||||
#include "libc/calls/struct/sigval.h"
|
#include "libc/calls/struct/sigval.h"
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/stdbool.h"
|
#include "libc/stdbool.h"
|
||||||
|
|
||||||
#define kSigactionMinRva 8 /* >SIG_{ERR,DFL,IGN,...} */
|
#define kSigactionMinRva 8 /* >SIG_{ERR,DFL,IGN,...} */
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
#include "libc/intrin/fds.h"
|
#include "libc/intrin/fds.h"
|
||||||
#include "libc/intrin/strace.h"
|
#include "libc/intrin/strace.h"
|
||||||
#include "libc/intrin/weaken.h"
|
#include "libc/intrin/weaken.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/mem/alloca.h"
|
#include "libc/mem/alloca.h"
|
||||||
#include "libc/mem/mem.h"
|
#include "libc/mem/mem.h"
|
||||||
#include "libc/nt/console.h"
|
#include "libc/nt/console.h"
|
||||||
|
|
|
@ -25,6 +25,5 @@
|
||||||
bool IsApeLoadable(char buf[8]) {
|
bool IsApeLoadable(char buf[8]) {
|
||||||
return READ32LE(buf) == READ32LE("\177ELF") ||
|
return READ32LE(buf) == READ32LE("\177ELF") ||
|
||||||
READ64LE(buf) == READ64LE("MZqFpD='") ||
|
READ64LE(buf) == READ64LE("MZqFpD='") ||
|
||||||
READ64LE(buf) == READ64LE("jartsr='") ||
|
READ64LE(buf) == READ64LE("jartsr='");
|
||||||
READ64LE(buf) == READ64LE("APEDBG='");
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
|
|
||||||
#define BYTES 64
|
#define BYTES 64
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
|
|
||||||
#define BYTES 64
|
#define BYTES 64
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
#include "libc/calls/internal.h"
|
#include "libc/calls/internal.h"
|
||||||
#include "libc/calls/syscall_support-nt.internal.h"
|
#include "libc/calls/syscall_support-nt.internal.h"
|
||||||
|
#include "libc/intrin/fds.h"
|
||||||
#include "libc/nt/enum/filetype.h"
|
#include "libc/nt/enum/filetype.h"
|
||||||
#include "libc/nt/files.h"
|
#include "libc/nt/files.h"
|
||||||
#include "libc/nt/struct/byhandlefileinformation.h"
|
#include "libc/nt/struct/byhandlefileinformation.h"
|
||||||
|
@ -31,7 +32,7 @@ static textwindows int64_t GetPosition(struct Fd *f, int whence) {
|
||||||
case SEEK_SET:
|
case SEEK_SET:
|
||||||
return 0;
|
return 0;
|
||||||
case SEEK_CUR:
|
case SEEK_CUR:
|
||||||
return f->pointer;
|
return f->cursor->shared->pointer;
|
||||||
case SEEK_END: {
|
case SEEK_END: {
|
||||||
struct NtByHandleFileInformation wst;
|
struct NtByHandleFileInformation wst;
|
||||||
if (!GetFileInformationByHandle(f->handle, &wst)) {
|
if (!GetFileInformationByHandle(f->handle, &wst)) {
|
||||||
|
@ -67,11 +68,14 @@ textwindows int64_t sys_lseek_nt(int fd, int64_t offset, int whence) {
|
||||||
} else if (__isfdkind(fd, kFdFile)) {
|
} else if (__isfdkind(fd, kFdFile)) {
|
||||||
struct Fd *f = g_fds.p + fd;
|
struct Fd *f = g_fds.p + fd;
|
||||||
int filetype = GetFileType(f->handle);
|
int filetype = GetFileType(f->handle);
|
||||||
if (filetype != kNtFileTypePipe && filetype != kNtFileTypeChar) {
|
if (filetype != kNtFileTypePipe && //
|
||||||
|
filetype != kNtFileTypeChar && //
|
||||||
|
f->cursor->shared) {
|
||||||
int64_t res;
|
int64_t res;
|
||||||
if ((res = Seek(f, offset, whence)) != -1) {
|
__cursor_lock(f->cursor);
|
||||||
f->pointer = res;
|
if ((res = Seek(f, offset, whence)) != -1)
|
||||||
}
|
f->cursor->shared->pointer = res;
|
||||||
|
__cursor_unlock(f->cursor);
|
||||||
return res;
|
return res;
|
||||||
} else {
|
} else {
|
||||||
return espipe();
|
return espipe();
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
#include "libc/intrin/directmap.h"
|
#include "libc/intrin/directmap.h"
|
||||||
#include "libc/intrin/kprintf.h"
|
#include "libc/intrin/kprintf.h"
|
||||||
#include "libc/intrin/weaken.h"
|
#include "libc/intrin/weaken.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/mem/mem.h"
|
#include "libc/mem/mem.h"
|
||||||
#include "libc/runtime/pc.internal.h"
|
#include "libc/runtime/pc.internal.h"
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
│ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR │
|
│ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR │
|
||||||
│ OTHER DEALINGS IN THE SOFTWARE. │
|
│ OTHER DEALINGS IN THE SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/calls/metalfile.internal.h"
|
#include "libc/calls/metalfile.internal.h"
|
||||||
|
|
||||||
.init.start 102,_init_metalfile
|
.init.start 102,_init_metalfile
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
#include "libc/intrin/kprintf.h"
|
#include "libc/intrin/kprintf.h"
|
||||||
#include "libc/intrin/strace.h"
|
#include "libc/intrin/strace.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/nt/systeminfo.h"
|
#include "libc/nt/systeminfo.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
#include "libc/sysv/consts/o.h"
|
#include "libc/sysv/consts/o.h"
|
||||||
|
@ -55,6 +55,19 @@ textwindows size_t __normntpath(char16_t *p, size_t n) {
|
||||||
// matched "/../" or "/..$"
|
// matched "/../" or "/..$"
|
||||||
while (j && p[j - 1] == '\\')
|
while (j && p[j - 1] == '\\')
|
||||||
--j;
|
--j;
|
||||||
|
if (j && p[j - 1] == '.') {
|
||||||
|
// matched "." before
|
||||||
|
if (j >= 2 && p[j - 2] == '.' && //
|
||||||
|
(j == 2 || p[j - 3] == '\\')) {
|
||||||
|
// matched "^.." or "/.." before
|
||||||
|
p[++j] = '.';
|
||||||
|
++j;
|
||||||
|
continue;
|
||||||
|
} else if (j == 1 || p[j - 2] == '\\') {
|
||||||
|
// matched "^." or "/." before
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
while (j && p[j - 1] != '\\')
|
while (j && p[j - 1] != '\\')
|
||||||
--j;
|
--j;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#include "libc/calls/internal.h"
|
#include "libc/calls/internal.h"
|
||||||
#include "libc/calls/syscall_support-nt.internal.h"
|
#include "libc/calls/syscall_support-nt.internal.h"
|
||||||
#include "libc/intrin/strace.h"
|
#include "libc/intrin/strace.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/nt/enum/fileflagandattributes.h"
|
#include "libc/nt/enum/fileflagandattributes.h"
|
||||||
#include "libc/nt/files.h"
|
#include "libc/nt/files.h"
|
||||||
#include "libc/nt/thunk/msabi.h"
|
#include "libc/nt/thunk/msabi.h"
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
.privileged
|
.privileged
|
||||||
|
|
||||||
__restore_rt_netbsd:
|
__restore_rt_netbsd:
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
#include "libc/nt/struct/startupinfo.h"
|
#include "libc/nt/struct/startupinfo.h"
|
||||||
#include "libc/nt/struct/startupinfoex.h"
|
#include "libc/nt/struct/startupinfoex.h"
|
||||||
#include "libc/proc/ntspawn.h"
|
#include "libc/proc/ntspawn.h"
|
||||||
#include "libc/stdalign.internal.h"
|
#include "libc/stdalign.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
#ifdef __x86_64__
|
#ifdef __x86_64__
|
||||||
|
|
|
@ -24,7 +24,8 @@
|
||||||
#include "libc/calls/syscall-nt.internal.h"
|
#include "libc/calls/syscall-nt.internal.h"
|
||||||
#include "libc/calls/syscall_support-nt.internal.h"
|
#include "libc/calls/syscall_support-nt.internal.h"
|
||||||
#include "libc/errno.h"
|
#include "libc/errno.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/intrin/fds.h"
|
||||||
|
#include "libc/macros.h"
|
||||||
#include "libc/nt/console.h"
|
#include "libc/nt/console.h"
|
||||||
#include "libc/nt/createfile.h"
|
#include "libc/nt/createfile.h"
|
||||||
#include "libc/nt/enum/accessmask.h"
|
#include "libc/nt/enum/accessmask.h"
|
||||||
|
@ -138,6 +139,7 @@ static textwindows int sys_open_nt_file(int dirfd, const char *file,
|
||||||
int64_t handle;
|
int64_t handle;
|
||||||
if ((handle = sys_open_nt_impl(dirfd, file, flags, mode,
|
if ((handle = sys_open_nt_impl(dirfd, file, flags, mode,
|
||||||
kNtFileFlagOverlapped)) != -1) {
|
kNtFileFlagOverlapped)) != -1) {
|
||||||
|
g_fds.p[fd].cursor = __cursor_new();
|
||||||
g_fds.p[fd].handle = handle;
|
g_fds.p[fd].handle = handle;
|
||||||
g_fds.p[fd].kind = kFdFile;
|
g_fds.p[fd].kind = kFdFile;
|
||||||
g_fds.p[fd].flags = flags;
|
g_fds.p[fd].flags = flags;
|
||||||
|
@ -170,15 +172,15 @@ static textwindows int sys_open_nt_no_handle(int fd, int flags, int mode,
|
||||||
|
|
||||||
static textwindows int sys_open_nt_dup(int fd, int flags, int mode, int oldfd) {
|
static textwindows int sys_open_nt_dup(int fd, int flags, int mode, int oldfd) {
|
||||||
int64_t handle;
|
int64_t handle;
|
||||||
if (!__isfdopen(oldfd)) {
|
if (!__isfdopen(oldfd))
|
||||||
return enoent();
|
return enoent();
|
||||||
}
|
|
||||||
if (DuplicateHandle(GetCurrentProcess(), g_fds.p[oldfd].handle,
|
if (DuplicateHandle(GetCurrentProcess(), g_fds.p[oldfd].handle,
|
||||||
GetCurrentProcess(), &handle, 0, true,
|
GetCurrentProcess(), &handle, 0, true,
|
||||||
kNtDuplicateSameAccess)) {
|
kNtDuplicateSameAccess)) {
|
||||||
g_fds.p[fd] = g_fds.p[oldfd];
|
g_fds.p[fd] = g_fds.p[oldfd];
|
||||||
g_fds.p[fd].handle = handle;
|
g_fds.p[fd].handle = handle;
|
||||||
g_fds.p[fd].mode = mode;
|
g_fds.p[fd].mode = mode;
|
||||||
|
__cursor_ref(g_fds.p[fd].cursor);
|
||||||
if (!sys_fcntl_nt_setfl(fd, flags)) {
|
if (!sys_fcntl_nt_setfl(fd, flags)) {
|
||||||
return fd;
|
return fd;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
#include "libc/calls/metalfile.internal.h"
|
#include "libc/calls/metalfile.internal.h"
|
||||||
#include "libc/intrin/directmap.h"
|
#include "libc/intrin/directmap.h"
|
||||||
#include "libc/intrin/weaken.h"
|
#include "libc/intrin/weaken.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/mem/mem.h"
|
#include "libc/mem/mem.h"
|
||||||
#include "libc/runtime/pc.internal.h"
|
#include "libc/runtime/pc.internal.h"
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/pledge.internal.h"
|
#include "libc/calls/pledge.internal.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
|
|
||||||
static int FindPromise(const char *name) {
|
static int FindPromise(const char *name) {
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
#include "libc/intrin/bsr.h"
|
#include "libc/intrin/bsr.h"
|
||||||
#include "libc/intrin/likely.h"
|
#include "libc/intrin/likely.h"
|
||||||
#include "libc/intrin/promises.h"
|
#include "libc/intrin/promises.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
#include "libc/runtime/stack.h"
|
#include "libc/runtime/stack.h"
|
||||||
#include "libc/sysv/consts/audit.h"
|
#include "libc/sysv/consts/audit.h"
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
#include "libc/errno.h"
|
#include "libc/errno.h"
|
||||||
#include "libc/intrin/atomic.h"
|
#include "libc/intrin/atomic.h"
|
||||||
#include "libc/intrin/strace.h"
|
#include "libc/intrin/strace.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/mem/mem.h"
|
#include "libc/mem/mem.h"
|
||||||
#include "libc/nt/console.h"
|
#include "libc/nt/console.h"
|
||||||
#include "libc/nt/enum/filetype.h"
|
#include "libc/nt/enum/filetype.h"
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
#include "libc/intrin/strace.h"
|
#include "libc/intrin/strace.h"
|
||||||
#include "libc/intrin/weaken.h"
|
#include "libc/intrin/weaken.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
#include "libc/runtime/zipos.internal.h"
|
#include "libc/runtime/zipos.internal.h"
|
||||||
#include "libc/stdio/sysparam.h"
|
#include "libc/stdio/sysparam.h"
|
||||||
|
|
|
@ -18,8 +18,8 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/internal.h"
|
#include "libc/calls/internal.h"
|
||||||
#include "libc/calls/state.internal.h"
|
#include "libc/calls/state.internal.h"
|
||||||
#include "libc/intrin/fds.h"
|
|
||||||
#include "libc/intrin/describeflags.h"
|
#include "libc/intrin/describeflags.h"
|
||||||
|
#include "libc/intrin/fds.h"
|
||||||
#include "libc/intrin/kprintf.h"
|
#include "libc/intrin/kprintf.h"
|
||||||
|
|
||||||
static const char *__fdkind2str(int x) {
|
static const char *__fdkind2str(int x) {
|
||||||
|
@ -55,7 +55,7 @@ void __printfds(struct Fd *fds, size_t fdslen) {
|
||||||
continue;
|
continue;
|
||||||
kprintf("%3d %s", i, __fdkind2str(fds[i].kind));
|
kprintf("%3d %s", i, __fdkind2str(fds[i].kind));
|
||||||
if (fds[i].flags) {
|
if (fds[i].flags) {
|
||||||
kprintf(" flags=%s", (DescribeOpenFlags)(buf, fds[i].flags));
|
kprintf(" flags=%s", _DescribeOpenFlags(buf, fds[i].flags));
|
||||||
}
|
}
|
||||||
if (fds[i].mode)
|
if (fds[i].mode)
|
||||||
kprintf(" mode=%#o", fds[i].mode);
|
kprintf(" mode=%#o", fds[i].mode);
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
|
|
||||||
.init.start 305,_init_program_executable_name
|
.init.start 305,_init_program_executable_name
|
||||||
push %rdi
|
push %rdi
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#include "libc/calls/syscall-sysv.internal.h"
|
#include "libc/calls/syscall-sysv.internal.h"
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
#include "libc/intrin/strace.h"
|
#include "libc/intrin/strace.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/stdio/sysparam.h"
|
#include "libc/stdio/sysparam.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
#include "libc/intrin/nomultics.h"
|
#include "libc/intrin/nomultics.h"
|
||||||
#include "libc/intrin/strace.h"
|
#include "libc/intrin/strace.h"
|
||||||
#include "libc/intrin/weaken.h"
|
#include "libc/intrin/weaken.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/nt/console.h"
|
#include "libc/nt/console.h"
|
||||||
#include "libc/nt/createfile.h"
|
#include "libc/nt/createfile.h"
|
||||||
#include "libc/nt/enum/accessmask.h"
|
#include "libc/nt/enum/accessmask.h"
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#include "libc/calls/struct/iovec.h"
|
#include "libc/calls/struct/iovec.h"
|
||||||
#include "libc/calls/struct/iovec.internal.h"
|
#include "libc/calls/struct/iovec.internal.h"
|
||||||
#include "libc/intrin/weaken.h"
|
#include "libc/intrin/weaken.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
#include "libc/vga/vga.internal.h"
|
#include "libc/vga/vga.internal.h"
|
||||||
|
|
|
@ -19,9 +19,9 @@
|
||||||
#include "libc/calls/createfileflags.internal.h"
|
#include "libc/calls/createfileflags.internal.h"
|
||||||
#include "libc/calls/internal.h"
|
#include "libc/calls/internal.h"
|
||||||
#include "libc/calls/sig.internal.h"
|
#include "libc/calls/sig.internal.h"
|
||||||
#include "libc/intrin/fds.h"
|
|
||||||
#include "libc/calls/struct/sigset.h"
|
#include "libc/calls/struct/sigset.h"
|
||||||
#include "libc/calls/syscall_support-nt.internal.h"
|
#include "libc/calls/syscall_support-nt.internal.h"
|
||||||
|
#include "libc/intrin/fds.h"
|
||||||
#include "libc/intrin/weaken.h"
|
#include "libc/intrin/weaken.h"
|
||||||
#include "libc/nt/enum/filetype.h"
|
#include "libc/nt/enum/filetype.h"
|
||||||
#include "libc/nt/errors.h"
|
#include "libc/nt/errors.h"
|
||||||
|
@ -51,39 +51,41 @@ sys_readwrite_nt(int fd, void *data, size_t size, ssize_t offset,
|
||||||
uint32_t exchanged;
|
uint32_t exchanged;
|
||||||
struct Fd *f = g_fds.p + fd;
|
struct Fd *f = g_fds.p + fd;
|
||||||
|
|
||||||
// win32 i/o apis generally take 32-bit values thus we implicitly
|
|
||||||
// truncate outrageously large sizes. linux actually does it too!
|
|
||||||
size = MIN(size, 0x7ffff000);
|
|
||||||
|
|
||||||
// pread() and pwrite() perform an implicit lseek() operation, so
|
// pread() and pwrite() perform an implicit lseek() operation, so
|
||||||
// similar to the lseek() system call, they too raise ESPIPE when
|
// similar to the lseek() system call, they too raise ESPIPE when
|
||||||
// operating on a non-seekable file.
|
// operating on a non-seekable file.
|
||||||
bool pwriting = offset != -1;
|
bool pwriting = offset != -1;
|
||||||
bool seekable =
|
bool isdisk = f->kind == kFdFile && GetFileType(handle) == kNtFileTypeDisk;
|
||||||
(f->kind == kFdFile && GetFileType(handle) == kNtFileTypeDisk) ||
|
bool seekable = isdisk || f->kind == kFdDevNull || f->kind == kFdDevRandom;
|
||||||
f->kind == kFdDevNull || f->kind == kFdDevRandom;
|
if (pwriting && !seekable)
|
||||||
if (pwriting && !seekable) {
|
|
||||||
return espipe();
|
return espipe();
|
||||||
}
|
|
||||||
|
|
||||||
|
// determine if we need to lock a file descriptor across processes
|
||||||
|
bool locked = isdisk && !pwriting && f->cursor;
|
||||||
|
if (locked)
|
||||||
|
__cursor_lock(f->cursor);
|
||||||
|
|
||||||
|
RestartOperation:
|
||||||
// when a file is opened in overlapped mode win32 requires that we
|
// when a file is opened in overlapped mode win32 requires that we
|
||||||
// take over full responsibility for managing our own file pointer
|
// take over full responsibility for managing our own file pointer
|
||||||
// which is fine, because the one win32 has was never very good in
|
// which is fine, because the one win32 has was never very good in
|
||||||
// the sense that it behaves so differently from linux, that using
|
// the sense that it behaves so differently from linux, that using
|
||||||
// win32 i/o required more compatibilty toil than doing it by hand
|
// win32 i/o required more compatibilty toil than doing it by hand
|
||||||
if (!pwriting) {
|
if (!pwriting) {
|
||||||
if (seekable) {
|
if (seekable && f->cursor) {
|
||||||
offset = f->pointer;
|
offset = f->cursor->shared->pointer;
|
||||||
} else {
|
} else {
|
||||||
offset = 0;
|
offset = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RestartOperation:
|
|
||||||
bool eagained = false;
|
bool eagained = false;
|
||||||
// check for signals and cancelation
|
// check for signals and cancelation
|
||||||
if (_check_cancel() == -1)
|
if (_check_cancel() == -1) {
|
||||||
|
if (locked)
|
||||||
|
__cursor_unlock(f->cursor);
|
||||||
return -1; // ECANCELED
|
return -1; // ECANCELED
|
||||||
|
}
|
||||||
if (_weaken(__sig_get) && (sig = _weaken(__sig_get)(waitmask))) {
|
if (_weaken(__sig_get) && (sig = _weaken(__sig_get)(waitmask))) {
|
||||||
goto HandleInterrupt;
|
goto HandleInterrupt;
|
||||||
}
|
}
|
||||||
|
@ -114,16 +116,16 @@ RestartOperation:
|
||||||
}
|
}
|
||||||
ok = true;
|
ok = true;
|
||||||
}
|
}
|
||||||
if (ok) {
|
if (ok)
|
||||||
ok = GetOverlappedResult(handle, &overlap, &exchanged, true);
|
ok = GetOverlappedResult(handle, &overlap, &exchanged, true);
|
||||||
}
|
|
||||||
CloseHandle(overlap.hEvent);
|
CloseHandle(overlap.hEvent);
|
||||||
|
|
||||||
// if i/o succeeded then return its result
|
// if i/o succeeded then return its result
|
||||||
if (ok) {
|
if (ok) {
|
||||||
if (!pwriting && seekable) {
|
if (!pwriting && seekable && f->cursor)
|
||||||
f->pointer = offset + exchanged;
|
f->cursor->shared->pointer = offset + exchanged;
|
||||||
}
|
if (locked)
|
||||||
|
__cursor_unlock(f->cursor);
|
||||||
return exchanged;
|
return exchanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,23 +133,32 @@ RestartOperation:
|
||||||
if (GetLastError() == kNtErrorOperationAborted) {
|
if (GetLastError() == kNtErrorOperationAborted) {
|
||||||
// raise EAGAIN if it's due to O_NONBLOCK mmode
|
// raise EAGAIN if it's due to O_NONBLOCK mmode
|
||||||
if (eagained) {
|
if (eagained) {
|
||||||
|
if (locked)
|
||||||
|
__cursor_unlock(f->cursor);
|
||||||
return eagain();
|
return eagain();
|
||||||
}
|
}
|
||||||
// otherwise it must be due to a kill() via __sig_cancel()
|
// otherwise it must be due to a kill() via __sig_cancel()
|
||||||
if (_weaken(__sig_relay) && (sig = _weaken(__sig_get)(waitmask))) {
|
if (_weaken(__sig_relay) && (sig = _weaken(__sig_get)(waitmask))) {
|
||||||
HandleInterrupt:
|
HandleInterrupt:
|
||||||
|
if (locked)
|
||||||
|
__cursor_unlock(f->cursor);
|
||||||
int handler_was_called = _weaken(__sig_relay)(sig, SI_KERNEL, waitmask);
|
int handler_was_called = _weaken(__sig_relay)(sig, SI_KERNEL, waitmask);
|
||||||
if (_check_cancel() == -1)
|
if (_check_cancel() == -1)
|
||||||
return -1; // possible if we SIGTHR'd
|
return -1; // possible if we SIGTHR'd
|
||||||
|
if (locked)
|
||||||
|
__cursor_lock(f->cursor);
|
||||||
// read() is @restartable unless non-SA_RESTART hands were called
|
// read() is @restartable unless non-SA_RESTART hands were called
|
||||||
if (!(handler_was_called & SIG_HANDLED_NO_RESTART)) {
|
if (!(handler_was_called & SIG_HANDLED_NO_RESTART))
|
||||||
goto RestartOperation;
|
goto RestartOperation;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (locked)
|
||||||
|
__cursor_unlock(f->cursor);
|
||||||
return eintr();
|
return eintr();
|
||||||
}
|
}
|
||||||
|
|
||||||
// read() and write() have generally different error-handling paths
|
// read() and write() have generally different error-handling paths
|
||||||
|
if (locked)
|
||||||
|
__cursor_unlock(f->cursor);
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/internal.h"
|
#include "libc/calls/internal.h"
|
||||||
#include "libc/intrin/atomic.h"
|
#include "libc/intrin/atomic.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
|
|
||||||
// really want to avoid locking here so close() needn't block signals
|
// really want to avoid locking here so close() needn't block signals
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
.text.windows
|
.text.windows
|
||||||
|
|
||||||
// Restores thread to state before signal.
|
// Restores thread to state before signal.
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/struct/rusage.h"
|
#include "libc/calls/struct/rusage.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Accumulates resource statistics in `y` to `x`.
|
* Accumulates resource statistics in `y` to `x`.
|
||||||
|
|
|
@ -23,32 +23,82 @@
|
||||||
#include "libc/nexgen32e/x86feature.h"
|
#include "libc/nexgen32e/x86feature.h"
|
||||||
#include "libc/nt/struct/processornumber.h"
|
#include "libc/nt/struct/processornumber.h"
|
||||||
#include "libc/nt/synchronization.h"
|
#include "libc/nt/synchronization.h"
|
||||||
|
#include "libc/runtime/syslib.internal.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
int sys_getcpu(unsigned *opt_cpu, unsigned *opt_node, void *tcache);
|
int sys_getcpu(unsigned *opt_cpu, unsigned *opt_node, void *tcache);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns ID of CPU on which thread is currently scheduled.
|
* Returns ID of CPU on which thread is currently scheduled.
|
||||||
|
*
|
||||||
|
* This function is supported on the following platforms:
|
||||||
|
*
|
||||||
|
* - x86-64
|
||||||
|
*
|
||||||
|
* - Linux: rdtsc
|
||||||
|
* - FreeBSD: rdtsc
|
||||||
|
* - Windows: win32
|
||||||
|
* - OpenBSD: unsupported
|
||||||
|
* - NetBSD: unsupported
|
||||||
|
* - MacOS: unsupported
|
||||||
|
*
|
||||||
|
* - aarch64
|
||||||
|
*
|
||||||
|
* - Linux: syscall
|
||||||
|
* - FreeBSD: syscall
|
||||||
|
* - MacOS: supported
|
||||||
|
*
|
||||||
* @return cpu number on success, or -1 w/ errno
|
* @return cpu number on success, or -1 w/ errno
|
||||||
*/
|
*/
|
||||||
int sched_getcpu(void) {
|
int sched_getcpu(void) {
|
||||||
if (X86_HAVE(RDTSCP)) {
|
|
||||||
unsigned tsc_aux;
|
if (IsWindows()) {
|
||||||
rdtscp(&tsc_aux);
|
|
||||||
return TSC_AUX_CORE(tsc_aux);
|
|
||||||
} else if (IsAarch64()) {
|
|
||||||
long tpidr_el0;
|
|
||||||
asm("mrs\t%0,tpidr_el0" : "=r"(tpidr_el0));
|
|
||||||
return tpidr_el0 & 255;
|
|
||||||
} else if (IsWindows()) {
|
|
||||||
struct NtProcessorNumber pn;
|
struct NtProcessorNumber pn;
|
||||||
GetCurrentProcessorNumberEx(&pn);
|
GetCurrentProcessorNumberEx(&pn);
|
||||||
return 64 * pn.Group + pn.Number;
|
return 64 * pn.Group + pn.Number;
|
||||||
} else {
|
|
||||||
unsigned cpu = 0;
|
|
||||||
int rc = sys_getcpu(&cpu, 0, 0);
|
|
||||||
if (rc == -1)
|
|
||||||
return -1;
|
|
||||||
return cpu;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __x86_64__
|
||||||
|
if (X86_HAVE(RDTSCP) && (IsLinux() || IsFreebsd())) {
|
||||||
|
// Only the Linux, FreeBSD, and Windows kernels can be counted upon
|
||||||
|
// to populate the TSC_AUX register with the current thread number.
|
||||||
|
unsigned tsc_aux;
|
||||||
|
rdtscp(&tsc_aux);
|
||||||
|
return TSC_AUX_CORE(tsc_aux);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __aarch64__
|
||||||
|
if (IsXnu()) {
|
||||||
|
// pthread_cpu_number_np() is defined by MacOS 11.0+ (Big Sur) in
|
||||||
|
// the SDK pthread.h header file, even though there's no man page
|
||||||
|
if (__syslib && __syslib->__version >= 9) {
|
||||||
|
errno_t err;
|
||||||
|
size_t out = 0;
|
||||||
|
if ((err = __syslib->__pthread_cpu_number_np(&out))) {
|
||||||
|
errno = err;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
} else {
|
||||||
|
errno = ENOSYS; // upgrade your ape loader
|
||||||
|
return -1; // cc -o /usr/local/bin/ape ape/ape-m1.c
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __aarch64__
|
||||||
|
if (IsFreebsd()) {
|
||||||
|
register int x0 asm("x0");
|
||||||
|
register int x8 asm("x8") = 581; // sched_getcpu
|
||||||
|
asm volatile("svc\t0" : "=r"(x0) : "r"(x8) : "memory");
|
||||||
|
return x0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
unsigned cpu = 0;
|
||||||
|
int rc = sys_getcpu(&cpu, 0, 0);
|
||||||
|
if (rc == -1)
|
||||||
|
return -1;
|
||||||
|
return cpu;
|
||||||
}
|
}
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue