bump modernc.org/sqlite to v1.35.0-concurrency-workaround (#3797)

This commit is contained in:
kim 2025-02-14 16:54:10 +00:00 committed by GitHub
commit ebbdeee0bb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
114 changed files with 891873 additions and 192475 deletions

8
go.mod
View file

@ -6,7 +6,7 @@ go 1.23
replace github.com/go-swagger/go-swagger => github.com/superseriousbusiness/go-swagger v0.31.0-gts-go1.23-fix replace github.com/go-swagger/go-swagger => github.com/superseriousbusiness/go-swagger v0.31.0-gts-go1.23-fix
// Replace modernc/sqlite with our version that fixes the concurrency INTERRUPT issue // Replace modernc/sqlite with our version that fixes the concurrency INTERRUPT issue
replace modernc.org/sqlite => gitlab.com/NyaaaWhatsUpDoc/sqlite v1.34.5-concurrency-workaround replace modernc.org/sqlite => gitlab.com/NyaaaWhatsUpDoc/sqlite v1.35.0-concurrency-workaround
require ( require (
codeberg.org/gruf/go-bytes v1.0.2 codeberg.org/gruf/go-bytes v1.0.2
@ -221,7 +221,7 @@ require (
google.golang.org/protobuf v1.36.3 // indirect google.golang.org/protobuf v1.36.3 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect
modernc.org/libc v1.55.3 // indirect modernc.org/libc v1.61.13 // indirect
modernc.org/mathutil v1.6.0 // indirect modernc.org/mathutil v1.7.1 // indirect
modernc.org/memory v1.8.0 // indirect modernc.org/memory v1.8.2 // indirect
) )

40
go.sum generated
View file

@ -617,8 +617,8 @@ github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/yuin/goldmark v1.7.8 h1:iERMLn0/QJeHFhxSt3p6PeN9mGnvIKSpG9YYorDMnic= github.com/yuin/goldmark v1.7.8 h1:iERMLn0/QJeHFhxSt3p6PeN9mGnvIKSpG9YYorDMnic=
github.com/yuin/goldmark v1.7.8/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E= github.com/yuin/goldmark v1.7.8/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
gitlab.com/NyaaaWhatsUpDoc/sqlite v1.34.5-concurrency-workaround h1:BLmmUkkZ2KiS8k2lePZRQo7Z5puFrfxuFq9BrJQmS9o= gitlab.com/NyaaaWhatsUpDoc/sqlite v1.35.0-concurrency-workaround h1:rSPHdoNXzXyWQUUeMEy8pdOFn8lH7XqdBRTS9G+jdTg=
gitlab.com/NyaaaWhatsUpDoc/sqlite v1.34.5-concurrency-workaround/go.mod h1:YLuNmX9NKs8wRNK2ko1LW1NGYcc9FkBO69JOt1AR9JE= gitlab.com/NyaaaWhatsUpDoc/sqlite v1.35.0-concurrency-workaround/go.mod h1:9cr2sicr7jIaWTBKQmAxQLfBv9LL0su4ZTEV+utt3ic=
go.mongodb.org/mongo-driver v1.14.0 h1:P98w8egYRjYe3XDjxhYJagTokP/H6HzlsnojRgZRd80= go.mongodb.org/mongo-driver v1.14.0 h1:P98w8egYRjYe3XDjxhYJagTokP/H6HzlsnojRgZRd80=
go.mongodb.org/mongo-driver v1.14.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c= go.mongodb.org/mongo-driver v1.14.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
@ -1010,26 +1010,26 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
modernc.org/cc/v4 v4.21.4 h1:3Be/Rdo1fpr8GrQ7IVw9OHtplU4gWbb+wNgeoBMmGLQ= modernc.org/cc/v4 v4.24.4 h1:TFkx1s6dCkQpd6dKurBNmpo+G8Zl4Sq/ztJ+2+DEsh0=
modernc.org/cc/v4 v4.21.4/go.mod h1:HM7VJTZbUCR3rV8EYBi9wxnJ0ZBRiGE5OeGXNA0IsLQ= modernc.org/cc/v4 v4.24.4/go.mod h1:uVtb5OGqUKpoLWhqwNQo/8LwvoiEBLvZXIQ/SmO6mL0=
modernc.org/ccgo/v4 v4.19.2 h1:lwQZgvboKD0jBwdaeVCTouxhxAyN6iawF3STraAal8Y= modernc.org/ccgo/v4 v4.23.16 h1:Z2N+kk38b7SfySC1ZkpGLN2vthNJP1+ZzGZIlH7uBxo=
modernc.org/ccgo/v4 v4.19.2/go.mod h1:ysS3mxiMV38XGRTTcgo0DQTeTmAO4oCmJl1nX9VFI3s= modernc.org/ccgo/v4 v4.23.16/go.mod h1:nNma8goMTY7aQZQNTyN9AIoJfxav4nvTnvKThAeMDdo=
modernc.org/fileutil v1.3.0 h1:gQ5SIzK3H9kdfai/5x41oQiKValumqNTDXMvKo62HvE= modernc.org/fileutil v1.3.0 h1:gQ5SIzK3H9kdfai/5x41oQiKValumqNTDXMvKo62HvE=
modernc.org/fileutil v1.3.0/go.mod h1:XatxS8fZi3pS8/hKG2GH/ArUogfxjpEKs3Ku3aK4JyQ= modernc.org/fileutil v1.3.0/go.mod h1:XatxS8fZi3pS8/hKG2GH/ArUogfxjpEKs3Ku3aK4JyQ=
modernc.org/gc/v2 v2.4.1 h1:9cNzOqPyMJBvrUipmynX0ZohMhcxPtMccYgGOJdOiBw= modernc.org/gc/v2 v2.6.3 h1:aJVhcqAte49LF+mGveZ5KPlsp4tdGdAOT4sipJXADjw=
modernc.org/gc/v2 v2.4.1/go.mod h1:wzN5dK1AzVGoH6XOzc3YZ+ey/jPgYHLuVckd62P0GYU= modernc.org/gc/v2 v2.6.3/go.mod h1:YgIahr1ypgfe7chRuJi2gD7DBQiKSLMPgBQe9oIiito=
modernc.org/libc v1.55.3 h1:AzcW1mhlPNrRtjS5sS+eW2ISCgSOLLNyFzRh/V3Qj/U= modernc.org/libc v1.61.13 h1:3LRd6ZO1ezsFiX1y+bHd1ipyEHIJKvuprv0sLTBwLW8=
modernc.org/libc v1.55.3/go.mod h1:qFXepLhz+JjFThQ4kzwzOjA/y/artDeg+pcYnY+Q83w= modernc.org/libc v1.61.13/go.mod h1:8F/uJWL/3nNil0Lgt1Dpz+GgkApWh04N3el3hxJcA6E=
modernc.org/mathutil v1.6.0 h1:fRe9+AmYlaej+64JsEEhoWuAYBkOtQiMEU7n/XgfYi4= modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
modernc.org/mathutil v1.6.0/go.mod h1:Ui5Q9q1TR2gFm0AQRqQUaBWFLAhQpCwNcuhBOSedWPo= modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
modernc.org/memory v1.8.0 h1:IqGTL6eFMaDZZhEWwcREgeMXYwmW83LYW8cROZYkg+E= modernc.org/memory v1.8.2 h1:cL9L4bcoAObu4NkxOlKWBWtNHIsnnACGF/TbqQ6sbcI=
modernc.org/memory v1.8.0/go.mod h1:XPZ936zp5OMKGWPqbD3JShgd/ZoQ7899TUuQqxY+peU= modernc.org/memory v1.8.2/go.mod h1:ZbjSvMO5NQ1A2i3bWeDiVMxIorXwdClKE/0SZ+BMotU=
modernc.org/opt v0.1.3 h1:3XOZf2yznlhC+ibLltsDGzABUGVx8J6pnFMS3E4dcq4= modernc.org/opt v0.1.4 h1:2kNGMRiUjrp4LcaPuLY2PzUfqM/w9N23quVwhKt5Qm8=
modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0= modernc.org/opt v0.1.4/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns=
modernc.org/sortutil v1.2.0 h1:jQiD3PfS2REGJNzNCMMaLSp/wdMNieTbKX920Cqdgqc= modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w=
modernc.org/sortutil v1.2.0/go.mod h1:TKU2s7kJMf1AE84OoiGppNHJwvB753OYfNl2WRb++Ss= modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE=
modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA= modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
modernc.org/strutil v1.2.0/go.mod h1:/mdcBmfOibveCTBxUl5B5l6W+TTH1FXPLHZE6bTosX0= modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y= modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM= modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
mvdan.cc/xurls/v2 v2.6.0 h1:3NTZpeTxYVWNSokW3MKeyVkz/j7uYXYiMtXRUfmjbgI= mvdan.cc/xurls/v2 v2.6.0 h1:3NTZpeTxYVWNSokW3MKeyVkz/j7uYXYiMtXRUfmjbgI=

1
vendor/modernc.org/libc/.gitignore generated vendored
View file

@ -2,3 +2,4 @@
*.zip *.zip
go.work go.work
go.sum go.sum
musl-*

31
vendor/modernc.org/libc/Makefile generated vendored
View file

@ -32,36 +32,30 @@ download:
@if [ ! -f $(TAR) ]; then wget $(URL) ; fi @if [ ! -f $(TAR) ]; then wget $(URL) ; fi
edit: edit:
@touch log
@if [ -f "Session.vim" ]; then novim -S & else novim -p Makefile go.mod builder.json & fi @if [ -f "Session.vim" ]; then novim -S & else novim -p Makefile go.mod builder.json & fi
editor: editor:
gofmt -l -s -w *.go 2>&1 | tee log-editor gofmt -l -s -w *.go
go test -c -o /dev/null 2>&1 | tee -a log-editor go test -c -o /dev/null
go install -v 2>&1 | tee -a log-editor go install -v
go build -o /dev/null generator*.go go build -o /dev/null generator*.go
generate: download generate: download
mkdir -p $(DIR) || true mkdir -p $(DIR) || true
rm -rf $(DIR)/* rm -rf $(DIR)/*
GO_GENERATE_DIR=$(DIR) go run generator*.go 2>&1 | tee log-generate GO_GENERATE_DIR=$(DIR) go run generator*.go
go build -v go build -v
# go install github.com/mdempsky/unconvert@latest go test -v -short -count=1 ./...
go build -v 2>&1 | tee -a log-generate git status
go test -v -short -count=1 ./... | tee -a log-generate
git status | tee -a log-generate
grep 'TRC\|TODO\|ERRORF\|FAIL' log-generate || true
dev: download dev: download
mkdir -p $(DIR) || true mkdir -p $(DIR) || true
rm -rf $(DIR)/* rm -rf $(DIR)/*
echo -n > /tmp/ccgo.log echo -n > /tmp/ccgo.log
GO_GENERATE_DIR=$(DIR) GO_GENERATE_DEV=1 go run -tags=ccgo.dmesg,ccgo.assert generator*.go 2>&1 | tee log-generate GO_GENERATE_DIR=$(DIR) GO_GENERATE_DEV=1 go run -tags=ccgo.dmesg,ccgo.assert generator*.go
go build -v | tee -a log-generate go build -v
go test -v -short -count=1 ./... | tee -a log-generate go test -v -short -count=1 ./...
git status | tee -a log-generate git status
grep 'TRC\|TODO\|ERRORF\|FAIL' log-generate || true
grep 'TRC\|TODO\|ERRORF\|FAIL' /tmp/ccgo.log || true
membrk-test: membrk-test:
echo -n > /tmp/ccgo.log echo -n > /tmp/ccgo.log
@ -71,10 +65,7 @@ membrk-test:
grep -a 'TRC\|TODO\|ERRORF\|FAIL' log-test || true 2>&1 | tee -a log-test grep -a 'TRC\|TODO\|ERRORF\|FAIL' log-test || true 2>&1 | tee -a log-test
test: test:
echo -n > /tmp/ccgo.log go test -v -timeout 24h -count=1
touch log-test
cp log-test log-test0
go test -v -timeout 24h -count=1 2>&1 | tee log-test
short-test: short-test:
echo -n > /tmp/ccgo.log echo -n > /tmp/ccgo.log

2
vendor/modernc.org/libc/aliases.go generated vendored
View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build linux && (amd64 || arm64 || loong64) //go:build linux && (amd64 || arm64 || loong64 || ppc64le || s390x || riscv64 || 386 || arm)
package libc // import "modernc.org/libc" package libc // import "modernc.org/libc"

77
vendor/modernc.org/libc/asm_386.s generated vendored Normal file
View file

@ -0,0 +1,77 @@
#include "textflag.h"
// static inline void a_or_64(volatile uint64_t *p, uint64_t v)
TEXT ·a_or_64(SB),NOSPLIT,$0
MOVL p+0(FP), BX
MOVL v+4(FP), AX
LOCK
ORL AX, 0(BX)
MOVL v+8(FP), AX
LOCK
ORL AX, 4(BX)
RET
// static inline void a_and_64(volatile uint64_t *p, uint64_t v)
TEXT ·a_and_64(SB),NOSPLIT,$0
MOVL p+0(FP), BX
MOVL v+4(FP), AX
LOCK
ANDL AX, 0(BX)
MOVL v+8(FP), AX
LOCK
ANDL AX, 4(BX)
RET
// static inline int a_cas(volatile int *p, int t, int s)
TEXT ·a_cas(SB),NOSPLIT,$0
MOVL p+0(FP), BX
MOVL t+4(FP), AX
MOVL s+8(FP), CX
LOCK
CMPXCHGL CX, 0(BX)
MOVL AX, ret+12(FP)
RET
// static inline void a_barrier()
TEXT ·a_barrier(SB),NOSPLIT,$0
MFENCE
RET
// #define a_crash a_crash
// static inline void a_crash()
// {
// __asm__ __volatile__( "hlt" : : : "memory" );
// }
TEXT ·a_crash(SB),NOSPLIT,$0
HLT
// static inline void *a_cas_p(volatile void *p, void *t, void *s)
TEXT ·a_cas_p(SB),NOSPLIT,$0
MOVL p+0(FP), BX
MOVL t+4(FP), AX
MOVL s+8(FP), CX
LOCK
CMPXCHGL CX, 0(BX)
MOVL AX, ret+12(FP)
RET
// static inline void a_or(volatile int *p, int v)
TEXT ·a_or(SB),NOSPLIT,$0
MOVL p+0(FP), BX
MOVL v+4(FP), AX
LOCK
ORL AX, 0(BX)
RET
// static inline int a_fetch_add(volatile int *p, int v)
TEXT ·a_fetch_add(SB),NOSPLIT,$0
MOVL p+0(FP), BX
MOVL v+4(FP), AX
LOCK
XADDL AX, 0(BX)
RET
// static inline void a_spin()
TEXT ·a_spin(SB),NOSPLIT,$0
PAUSE
RET

11
vendor/modernc.org/libc/atomic.go generated vendored
View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build linux && (amd64 || arm64 || loong64) //go:build linux && (amd64 || arm64 || loong64 || ppc64le || s390x || riscv64 || 386 || arm)
package libc // import "modernc.org/libc" package libc // import "modernc.org/libc"
@ -38,15 +38,6 @@ func a_store_16(addr uintptr, val uint16) {
*(*uint16)(unsafe.Pointer(addr)) = val *(*uint16)(unsafe.Pointer(addr)) = val
} }
// static inline int a_ctz_l(unsigned long x)
func _a_ctz_l(tls *TLS, x ulong) int32 {
if unsafe.Sizeof(x) == 8 {
return int32(mbits.TrailingZeros64(x))
}
return int32(mbits.TrailingZeros32(uint32(x)))
}
// static inline int a_ctz_64(uint64_t x) // static inline int a_ctz_64(uint64_t x)
func _a_ctz_64(tls *TLS, x uint64) int32 { func _a_ctz_64(tls *TLS, x uint64) int32 {
return int32(mbits.TrailingZeros64(x)) return int32(mbits.TrailingZeros64(x))

16
vendor/modernc.org/libc/atomic32.go generated vendored Normal file
View file

@ -0,0 +1,16 @@
// Copyright 2024 The Libc Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build linux && (386 || arm)
package libc // import "modernc.org/libc"
import (
mbits "math/bits"
)
// static inline int a_ctz_l(unsigned long x)
func _a_ctz_l(tls *TLS, x ulong) int32 {
return int32(mbits.TrailingZeros32(x))
}

16
vendor/modernc.org/libc/atomic64.go generated vendored Normal file
View file

@ -0,0 +1,16 @@
// Copyright 2024 The Libc Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build linux && (amd64 || arm64 || loong64 || ppc64le || s390x || riscv64)
package libc // import "modernc.org/libc"
import (
mbits "math/bits"
)
// static inline int a_ctz_l(unsigned long x)
func _a_ctz_l(tls *TLS, x ulong) int32 {
return int32(mbits.TrailingZeros64(x))
}

View file

@ -1,9 +1,9 @@
{ {
"autogen": "linux/(amd64|arm64|loong64)", "autogen": "linux/(amd64|arm64|loong64|ppc64le|s390x|riscv64|386|arm)",
"autotag": "darwin/(amd64|arm64)|freebsd/(amd64|arm64)|linux/(386|amd64|arm|arm64|loong64|ppc64le|riscv64|s390x)|windows/(amd64|arm64|386)",
"autoupdate": "linux/amd64", "autoupdate": "linux/amd64",
"autotag": "darwin/(amd64|arm64)|freebsd/(amd64|arm64)|linux/(386|amd64|arm|arm64|loong64|ppc64le|riscv64|s390x)|openbsd/(386|amd64|arm64)|windows/(amd64|arm64|386)",
"download": [ "download": [
{"re": "linux/(amd64|arm64|loong64)", "files": ["https://git.musl-libc.org/cgit/musl/snapshot/musl-7ada6dde6f9dc6a2836c3d92c2f762d35fd229e0.tar.gz"]} {"re": "linux/(amd64|arm64|loong64|ppc64le|s390x|riscv64|386|arm)", "files": ["https://git.musl-libc.org/cgit/musl/snapshot/musl-7ada6dde6f9dc6a2836c3d92c2f762d35fd229e0.tar.gz"]}
], ],
"test": "darwin/(amd64|arm64)|freebsd/(amd64|arm64)|linux/(386|amd64|arm|arm64|loong64|ppc64le|riscv64|s390x)|openbsd/(386|amd64|arm64)|windows/(amd64|arm64|386)" "test": "darwin/(amd64|arm64)|freebsd/(amd64|arm64)|linux/(386|amd64|arm|arm64|loong64|ppc64le|riscv64|s390x)|openbsd/(386|amd64|arm64)|windows/(amd64|arm64|386)"
} }

22
vendor/modernc.org/libc/builtin.go generated vendored
View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build linux && (amd64 || arm64 || loong64) //go:build linux && (amd64 || arm64 || loong64 || ppc64le || s390x || riscv64 || 386 || arm)
package libc // import "modernc.org/libc" package libc // import "modernc.org/libc"
@ -32,6 +32,10 @@ func X__builtin_round(tls *TLS, x float64) (r float64) {
return Xround(tls, x) return Xround(tls, x)
} }
func X__builtin_lround(tls *TLS, x float64) (r long) {
return Xlround(tls, x)
}
func X__builtin_roundf(tls *TLS, x float32) (r float32) { func X__builtin_roundf(tls *TLS, x float32) (r float32) {
return Xroundf(tls, x) return Xroundf(tls, x)
} }
@ -60,10 +64,6 @@ func X__builtin_clz(t *TLS, n uint32) int32 {
return int32(mbits.LeadingZeros32(n)) return int32(mbits.LeadingZeros32(n))
} }
func X__builtin_clzl(t *TLS, n ulong) int32 {
return int32(mbits.LeadingZeros64(n))
}
func X__builtin_clzll(t *TLS, n uint64) int32 { func X__builtin_clzll(t *TLS, n uint64) int32 {
return int32(mbits.LeadingZeros64(n)) return int32(mbits.LeadingZeros64(n))
} }
@ -164,11 +164,6 @@ func X__builtin_popcount(t *TLS, x uint32) int32 {
return int32(mbits.OnesCount32(x)) return int32(mbits.OnesCount32(x))
} }
// int __builtin_popcountl (unsigned long x)
func X__builtin_popcountl(t *TLS, x ulong) int32 {
return int32(mbits.OnesCount64(x))
}
// char * __builtin___strcpy_chk (char *dest, const char *src, size_t os); // char * __builtin___strcpy_chk (char *dest, const char *src, size_t os);
func X__builtin___strcpy_chk(t *TLS, dest, src uintptr, os Tsize_t) uintptr { func X__builtin___strcpy_chk(t *TLS, dest, src uintptr, os Tsize_t) uintptr {
return Xstrcpy(t, dest, src) return Xstrcpy(t, dest, src)
@ -295,7 +290,12 @@ func X__builtin___memset_chk(t *TLS, s uintptr, c int32, n, os Tsize_t) uintptr
// size_t __builtin_object_size (const void * ptr, int type) // size_t __builtin_object_size (const void * ptr, int type)
func X__builtin_object_size(t *TLS, p uintptr, typ int32) Tsize_t { func X__builtin_object_size(t *TLS, p uintptr, typ int32) Tsize_t {
return ^Tsize_t(0) //TODO frontend magic switch typ {
case 0, 1:
return ^Tsize_t(0)
default:
return 0
}
} }
// int __builtin___sprintf_chk (char *s, int flag, size_t os, const char *fmt, ...); // int __builtin___sprintf_chk (char *s, int flag, size_t os, const char *fmt, ...);

24
vendor/modernc.org/libc/builtin32.go generated vendored Normal file
View file

@ -0,0 +1,24 @@
// Copyright 2024 The Libc Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build linux && (386 || arm)
package libc // import "modernc.org/libc"
import (
mbits "math/bits"
)
func X__builtin_ctzl(tls *TLS, x ulong) int32 {
return int32(mbits.TrailingZeros32(x))
}
func X__builtin_clzl(t *TLS, n ulong) int32 {
return int32(mbits.LeadingZeros32(n))
}
// int __builtin_popcountl (unsigned long x)
func X__builtin_popcountl(t *TLS, x ulong) int32 {
return int32(mbits.OnesCount32(x))
}

24
vendor/modernc.org/libc/builtin64.go generated vendored Normal file
View file

@ -0,0 +1,24 @@
// Copyright 2024 The Libc Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build linux && (amd64 || arm64 || loong64 || ppc64le || s390x || riscv64)
package libc // import "modernc.org/libc"
import (
mbits "math/bits"
)
func X__builtin_ctzl(tls *TLS, x ulong) int32 {
return int32(mbits.TrailingZeros64(x))
}
func X__builtin_clzl(t *TLS, n ulong) int32 {
return int32(mbits.LeadingZeros64(n))
}
// int __builtin_popcountl (unsigned long x)
func X__builtin_popcountl(t *TLS, x ulong) int32 {
return int32(mbits.OnesCount64(x))
}

2
vendor/modernc.org/libc/ccgo.go generated vendored
View file

@ -1,6 +1,6 @@
// Code generated by 'go generate' - DO NOT EDIT. // Code generated by 'go generate' - DO NOT EDIT.
//go:build !(linux && (amd64 || arm64 || loong64)) //go:build !(linux && (amd64 || arm64 || loong64 || ppc64le || s390x || riscv64 || 386 || arm))
package libc // import "modernc.org/libc" package libc // import "modernc.org/libc"

157064
vendor/modernc.org/libc/ccgo_linux_386.go generated vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

156684
vendor/modernc.org/libc/ccgo_linux_arm.go generated vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

155163
vendor/modernc.org/libc/ccgo_linux_ppc64le.go generated vendored Normal file

File diff suppressed because one or more lines are too long

154062
vendor/modernc.org/libc/ccgo_linux_riscv64.go generated vendored Normal file

File diff suppressed because one or more lines are too long

154544
vendor/modernc.org/libc/ccgo_linux_s390x.go generated vendored Normal file

File diff suppressed because one or more lines are too long

5
vendor/modernc.org/libc/etc.go generated vendored
View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build !(linux && (amd64 || arm64 || loong64)) //go:build !(linux && (amd64 || arm64 || loong64 || ppc64le || s390x || riscv64 || 386 || arm))
package libc // import "modernc.org/libc" package libc // import "modernc.org/libc"
@ -19,7 +19,6 @@ import (
"strings" "strings"
"sync" "sync"
"sync/atomic" "sync/atomic"
"syscall"
"time" "time"
"unsafe" "unsafe"
@ -199,7 +198,7 @@ again:
case *os.PathError: case *os.PathError:
err = x.Err err = x.Err
goto again goto again
case syscall.Errno: case syscallErrno:
*(*int32)(unsafe.Pointer(t.errnop)) = int32(x) *(*int32)(unsafe.Pointer(t.errnop)) = int32(x)
case *os.SyscallError: case *os.SyscallError:
err = x.Err err = x.Err

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build linux && (amd64 || arm64 || loong64) //go:build linux && (amd64 || arm64 || loong64 || ppc64le || s390x || riscv64 || 386 || arm)
package libc // import "modernc.org/libc" package libc // import "modernc.org/libc"

View file

@ -6,7 +6,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build !(linux && (amd64 || arm64 || loong64)) //go:build !(linux && (amd64 || arm64 || loong64 || ppc64le || s390x || riscv64 || 386 || arm))
package libc // import "modernc.org/libc" package libc // import "modernc.org/libc"

9
vendor/modernc.org/libc/libc.go generated vendored
View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build !(linux && (amd64 || arm64 || loong64)) //go:build !linux || mips64le
//go.generate echo package libc > ccgo.go //go.generate echo package libc > ccgo.go
//go:generate go fmt ./... //go:generate go fmt ./...
@ -722,7 +722,12 @@ func X__builtin_object_size(t *TLS, p uintptr, typ int32) types.Size_t {
if __ccgo_strace { if __ccgo_strace {
trc("t=%v p=%v typ=%v, (%v:)", t, p, typ, origin(2)) trc("t=%v p=%v typ=%v, (%v:)", t, p, typ, origin(2))
} }
return ^types.Size_t(0) //TODO frontend magic switch typ {
case 0, 1:
return ^types.Size_t(0)
default:
return 0
}
} }
var atomicLoadStore16 sync.Mutex var atomicLoadStore16 sync.Mutex

3
vendor/modernc.org/libc/libc32.go generated vendored
View file

@ -2,8 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build 386 || arm //go:build !linux && (arm || 386)
// +build 386 arm
package libc // import "modernc.org/libc" package libc // import "modernc.org/libc"

8
vendor/modernc.org/libc/libc64.go generated vendored
View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build ((amd64 || arm64 || loong64) && !linux) || ppc64le || riscv64 || s390x || mips64le //go:build (!linux && !(386 || arm)) || mips64le
package libc // import "modernc.org/libc" package libc // import "modernc.org/libc"
@ -41,12 +41,12 @@ func Xstrchrnul(tls *TLS, s uintptr, c int32) (r uintptr) {
var k types.Size_t var k types.Size_t
var w uintptr var w uintptr
_, _ = k, w _, _ = k, w
c = int32(uint8(uint8(c))) c = int32(uint8(c))
if !(c != 0) { if !(c != 0) {
return s + uintptr(Xstrlen(tls, s)) return s + uintptr(Xstrlen(tls, s))
} }
for { for {
if !(uint64(uint64(s))%Uint64FromInt64(8) != 0) { if !(uint64(s)%Uint64FromInt64(8) != 0) {
break break
} }
if !(*(*int8)(unsafe.Pointer(s)) != 0) || int32(*(*uint8)(unsafe.Pointer(s))) == c { if !(*(*int8)(unsafe.Pointer(s)) != 0) || int32(*(*uint8)(unsafe.Pointer(s))) == c {
@ -56,7 +56,7 @@ func Xstrchrnul(tls *TLS, s uintptr, c int32) (r uintptr) {
_1: _1:
s++ s++
} }
k = uint64(-Int32FromInt32(1)) / Uint64FromInt32(limits.UCHAR_MAX) * uint64(uint64(c)) k = uint64(-Int32FromInt32(1)) / Uint64FromInt32(limits.UCHAR_MAX) * uint64(c)
w = s w = s
for { for {
if !(!((*(*uint64)(unsafe.Pointer(w))-uint64(-Int32FromInt32(1))/Uint64FromInt32(limits.UCHAR_MAX)) & ^*(*uint64)(unsafe.Pointer(w)) & (uint64(-Int32FromInt32(1))/Uint64FromInt32(limits.UCHAR_MAX)*uint64(Int32FromInt32(limits.UCHAR_MAX)/Int32FromInt32(2)+Int32FromInt32(1))) != 0) && !((*(*uint64)(unsafe.Pointer(w))^k-uint64(-Int32FromInt32(1))/Uint64FromInt32(limits.UCHAR_MAX)) & ^(*(*uint64)(unsafe.Pointer(w))^k) & (uint64(-Int32FromInt32(1))/Uint64FromInt32(limits.UCHAR_MAX)*uint64(Int32FromInt32(limits.UCHAR_MAX)/Int32FromInt32(2)+Int32FromInt32(1))) != 0)) { if !(!((*(*uint64)(unsafe.Pointer(w))-uint64(-Int32FromInt32(1))/Uint64FromInt32(limits.UCHAR_MAX)) & ^*(*uint64)(unsafe.Pointer(w)) & (uint64(-Int32FromInt32(1))/Uint64FromInt32(limits.UCHAR_MAX)*uint64(Int32FromInt32(limits.UCHAR_MAX)/Int32FromInt32(2)+Int32FromInt32(1))) != 0) && !((*(*uint64)(unsafe.Pointer(w))^k-uint64(-Int32FromInt32(1))/Uint64FromInt32(limits.UCHAR_MAX)) & ^(*(*uint64)(unsafe.Pointer(w))^k) & (uint64(-Int32FromInt32(1))/Uint64FromInt32(limits.UCHAR_MAX)*uint64(Int32FromInt32(limits.UCHAR_MAX)/Int32FromInt32(2)+Int32FromInt32(1))) != 0)) {

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build !linux
package libc // import "modernc.org/libc" package libc // import "modernc.org/libc"
import ( import (

34
vendor/modernc.org/libc/libc_all.go generated vendored Normal file
View file

@ -0,0 +1,34 @@
// Copyright 2024 The Libc Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package libc // import "modernc.org/libc"
import (
"sync/atomic"
"unsafe"
"golang.org/x/exp/constraints"
)
func X__sync_add_and_fetch[T constraints.Integer](t *TLS, p uintptr, v T) T {
switch unsafe.Sizeof(v) {
case 4:
return T(atomic.AddInt32((*int32)(unsafe.Pointer(p)), int32(v)))
case 8:
return T(atomic.AddInt64((*int64)(unsafe.Pointer(p)), int64(v)))
default:
panic(todo(""))
}
}
func X__sync_sub_and_fetch[T constraints.Integer](t *TLS, p uintptr, v T) T {
switch unsafe.Sizeof(v) {
case 4:
return T(atomic.AddInt32((*int32)(unsafe.Pointer(p)), -int32(v)))
case 8:
return T(atomic.AddInt64((*int64)(unsafe.Pointer(p)), -int64(v)))
default:
panic(todo(""))
}
}

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build !linux
package libc // import "modernc.org/libc" package libc // import "modernc.org/libc"
import ( import (

View file

@ -15,7 +15,6 @@ import (
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings" "strings"
"syscall"
gotime "time" gotime "time"
"unicode" "unicode"
"unsafe" "unsafe"
@ -51,8 +50,9 @@ const (
// ) // )
type ( type (
long = types.User_long_t syscallErrno = unix.Errno
ulong = types.User_ulong_t long = types.User_long_t
ulong = types.User_ulong_t
) )
type pthreadAttr struct { type pthreadAttr struct {
@ -1098,7 +1098,7 @@ func Xfileno(t *TLS, stream uintptr) int32 {
return -1 return -1
} }
func newFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscall.Errno) (r *fts.FTSENT) { func newFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscallErrno) (r *fts.FTSENT) {
var statp uintptr var statp uintptr
if stat != nil { if stat != nil {
statp = Xmalloc(t, types.Size_t(unsafe.Sizeof(unix.Stat_t{}))) statp = Xmalloc(t, types.Size_t(unsafe.Sizeof(unix.Stat_t{})))
@ -1122,7 +1122,7 @@ func newFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscall.Err
} }
} }
func newCFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscall.Errno) uintptr { func newCFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscallErrno) uintptr {
p := Xcalloc(t, 1, types.Size_t(unsafe.Sizeof(fts.FTSENT{}))) p := Xcalloc(t, 1, types.Size_t(unsafe.Sizeof(fts.FTSENT{})))
if p == 0 { if p == 0 {
panic("OOM") panic("OOM")
@ -1513,7 +1513,7 @@ func Xabort(t *TLS) {
(*signal.Sigaction)(unsafe.Pointer(p)).F__sigaction_u.F__sa_handler = signal.SIG_DFL (*signal.Sigaction)(unsafe.Pointer(p)).F__sigaction_u.F__sa_handler = signal.SIG_DFL
Xsigaction(t, signal.SIGABRT, p, 0) Xsigaction(t, signal.SIGABRT, p, 0)
Xfree(t, p) Xfree(t, p)
unix.Kill(unix.Getpid(), syscall.Signal(signal.SIGABRT)) unix.Kill(unix.Getpid(), unix.Signal(signal.SIGABRT))
panic(todo("unrechable")) panic(todo("unrechable"))
} }
@ -1765,7 +1765,7 @@ func Xgetservbyname(t *TLS, name, proto uintptr) uintptr {
// //TODO- return Xreaddir(t, dir) // //TODO- return Xreaddir(t, dir)
// //TODO- } // //TODO- }
// //
// func __syscall(r, _ uintptr, errno syscall.Errno) long { // func __syscall(r, _ uintptr, errno syscallErrno) long {
// if errno != 0 { // if errno != 0 {
// return long(-errno) // return long(-errno)
// } // }
@ -2055,7 +2055,7 @@ func Xpipe(t *TLS, pipefd uintptr) int32 {
trc("t=%v pipefd=%v, (%v:)", t, pipefd, origin(2)) trc("t=%v pipefd=%v, (%v:)", t, pipefd, origin(2))
} }
var a [2]int var a [2]int
if err := syscall.Pipe(a[:]); err != nil { if err := unix.Pipe(a[:]); err != nil {
if dmesgs { if dmesgs {
dmesg("%v: %v FAIL", origin(1), err) dmesg("%v: %v FAIL", origin(1), err)
} }
@ -2234,39 +2234,39 @@ func Xpause(t *TLS) int32 {
} }
c := make(chan os.Signal) c := make(chan os.Signal)
gosignal.Notify(c, gosignal.Notify(c,
syscall.SIGABRT, unix.SIGABRT,
syscall.SIGALRM, unix.SIGALRM,
syscall.SIGBUS, unix.SIGBUS,
syscall.SIGCHLD, unix.SIGCHLD,
syscall.SIGCONT, unix.SIGCONT,
syscall.SIGFPE, unix.SIGFPE,
syscall.SIGHUP, unix.SIGHUP,
syscall.SIGILL, unix.SIGILL,
// syscall.SIGINT, // unix.SIGINT,
syscall.SIGIO, unix.SIGIO,
syscall.SIGIOT, unix.SIGIOT,
syscall.SIGKILL, unix.SIGKILL,
syscall.SIGPIPE, unix.SIGPIPE,
syscall.SIGPROF, unix.SIGPROF,
syscall.SIGQUIT, unix.SIGQUIT,
syscall.SIGSEGV, unix.SIGSEGV,
syscall.SIGSTOP, unix.SIGSTOP,
syscall.SIGSYS, unix.SIGSYS,
syscall.SIGTERM, unix.SIGTERM,
syscall.SIGTRAP, unix.SIGTRAP,
syscall.SIGTSTP, unix.SIGTSTP,
syscall.SIGTTIN, unix.SIGTTIN,
syscall.SIGTTOU, unix.SIGTTOU,
syscall.SIGURG, unix.SIGURG,
syscall.SIGUSR1, unix.SIGUSR1,
syscall.SIGUSR2, unix.SIGUSR2,
syscall.SIGVTALRM, unix.SIGVTALRM,
syscall.SIGWINCH, unix.SIGWINCH,
syscall.SIGXCPU, unix.SIGXCPU,
syscall.SIGXFSZ, unix.SIGXFSZ,
) )
switch <-c { switch <-c {
case syscall.SIGINT: case unix.SIGINT:
panic(todo("")) panic(todo(""))
default: default:
t.setErrno(errno.EINTR) t.setErrno(errno.EINTR)
@ -2510,3 +2510,11 @@ func X__fpclassifyd(tls *TLS, x float64) (r int32) {
} }
var Xin6addr_any = in6_addr{} var Xin6addr_any = in6_addr{}
func X__builtin_lround(tls *TLS, x float64) (r long) {
return Xlround(tls, x)
}
func Xlround(tls *TLS, x float64) (r long) {
return long(Xround(tls, x))
}

View file

@ -6,6 +6,7 @@ package libc // import "modernc.org/libc"
import ( import (
"strings" "strings"
"time"
"unsafe" "unsafe"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
@ -241,12 +242,11 @@ func Xtime(t *TLS, tloc uintptr) types.Time_t {
if __ccgo_strace { if __ccgo_strace {
trc("t=%v tloc=%v, (%v:)", t, tloc, origin(2)) trc("t=%v tloc=%v, (%v:)", t, tloc, origin(2))
} }
panic(todo("")) n := time.Now().UTC().Unix()
// n := time.Now().UTC().Unix() if tloc != 0 {
// if tloc != 0 { *(*types.Time_t)(unsafe.Pointer(tloc)) = types.Time_t(n)
// *(*types.Time_t)(unsafe.Pointer(tloc)) = types.Time_t(n) }
// } return types.Time_t(n)
// return types.Time_t(n)
} }
// // int getrlimit(int resource, struct rlimit *rlim); // // int getrlimit(int resource, struct rlimit *rlim);

View file

@ -13,7 +13,6 @@ import (
"runtime" "runtime"
"runtime/debug" "runtime/debug"
"strings" "strings"
"syscall"
gotime "time" gotime "time"
"unicode" "unicode"
"unsafe" "unsafe"
@ -66,6 +65,8 @@ func X__runes_for_locale(t *TLS, l locale_t, p uintptr) uintptr {
panic(todo("")) panic(todo(""))
} }
type syscallErrno = unix.Errno
type file uintptr type file uintptr
func (f file) fd() int32 { return int32((*stdio.FILE)(unsafe.Pointer(f)).F_file) } func (f file) fd() int32 { return int32((*stdio.FILE)(unsafe.Pointer(f)).F_file) }
@ -411,7 +412,7 @@ func Xwrite(t *TLS, fd int32, buf uintptr, count types.Size_t) types.Ssize_t {
trc("t=%v fd=%v buf=%v count=%v, (%v:)", t, fd, buf, count, origin(2)) trc("t=%v fd=%v buf=%v count=%v, (%v:)", t, fd, buf, count, origin(2))
} }
const retry = 5 const retry = 5
var err syscall.Errno var err syscallErrno
for i := 0; i < retry; i++ { for i := 0; i < retry; i++ {
var n uintptr var n uintptr
switch n, _, err = unix.Syscall(unix.SYS_WRITE, uintptr(fd), buf, uintptr(count)); err { switch n, _, err = unix.Syscall(unix.SYS_WRITE, uintptr(fd), buf, uintptr(count)); err {
@ -881,7 +882,7 @@ func Xfileno(t *TLS, stream uintptr) int32 {
panic(todo("")) panic(todo(""))
} }
func newCFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscall.Errno) uintptr { func newCFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscallErrno) uintptr {
p := Xcalloc(t, 1, types.Size_t(unsafe.Sizeof(fts.FTSENT{}))) p := Xcalloc(t, 1, types.Size_t(unsafe.Sizeof(fts.FTSENT{})))
if p == 0 { if p == 0 {
panic("OOM") panic("OOM")
@ -1286,7 +1287,7 @@ func Xabort(t *TLS) {
(*signal.Sigaction)(unsafe.Pointer(p)).F__sigaction_u.F__sa_handler = signal.SIG_DFL (*signal.Sigaction)(unsafe.Pointer(p)).F__sigaction_u.F__sa_handler = signal.SIG_DFL
Xsigaction(t, signal.SIGABRT, p, 0) Xsigaction(t, signal.SIGABRT, p, 0)
Xfree(t, p) Xfree(t, p)
unix.Kill(unix.Getpid(), syscall.Signal(signal.SIGABRT)) unix.Kill(unix.Getpid(), unix.Signal(signal.SIGABRT))
panic(todo("unrechable")) panic(todo("unrechable"))
} }
@ -1516,7 +1517,7 @@ func Xreaddir64(t *TLS, dir uintptr) uintptr {
return Xreaddir(t, dir) return Xreaddir(t, dir)
} }
func __syscall(r, _ uintptr, errno syscall.Errno) long { func __syscall(r, _ uintptr, errno syscallErrno) long {
if errno != 0 { if errno != 0 {
return long(-errno) return long(-errno)
} }
@ -1591,7 +1592,16 @@ func Xwritev(t *TLS, fd int32, iov uintptr, iovcnt int32) types.Ssize_t {
if __ccgo_strace { if __ccgo_strace {
trc("t=%v fd=%v iov=%v iovcnt=%v, (%v:)", t, fd, iov, iovcnt, origin(2)) trc("t=%v fd=%v iov=%v iovcnt=%v, (%v:)", t, fd, iov, iovcnt, origin(2))
} }
panic(todo("")) r, _, err := unix.Syscall(unix.SYS_WRITEV, uintptr(fd), iov, uintptr(iovcnt))
if err != 0 {
if dmesgs {
dmesg("%v: %v FAIL", origin(1), err)
}
t.setErrno(err)
return -1
}
return types.Ssize_t(r)
} }
// int __isoc99_sscanf(const char *str, const char *format, ...); // int __isoc99_sscanf(const char *str, const char *format, ...);
@ -1725,7 +1735,7 @@ func Xpipe(t *TLS, pipefd uintptr) int32 {
trc("t=%v pipefd=%v, (%v:)", t, pipefd, origin(2)) trc("t=%v pipefd=%v, (%v:)", t, pipefd, origin(2))
} }
var a [2]int var a [2]int
if err := syscall.Pipe(a[:]); err != nil { if err := unix.Pipe(a[:]); err != nil {
if dmesgs { if dmesgs {
dmesg("%v: %v FAIL", origin(1), err) dmesg("%v: %v FAIL", origin(1), err)
} }
@ -1969,3 +1979,60 @@ func Xpwrite(t *TLS, fd int32, buf uintptr, count types.Size_t, offset types.Off
// } // }
return types.Ssize_t(n) return types.Ssize_t(n)
} }
func Xexplicit_bzero(tls *TLS, d uintptr, n types.Size_t) {
Xmemset(tls, d, 0, n)
}
// int issetugid(void);
func Xissetugid(t *TLS) int32 {
if __ccgo_strace {
trc("t=%v, (%v:)", t, origin(2))
}
panic(todo(""))
}
var progname uintptr
// const char *getprogname(void);
func Xgetprogname(t *TLS) uintptr {
if __ccgo_strace {
trc("t=%v, (%v:)", t, origin(2))
}
if progname != 0 {
return progname
}
var err error
progname, err = CString(filepath.Base(os.Args[0]))
if err != nil {
t.setErrno(err)
return 0
}
return progname
}
func Xstrncasecmp(tls *TLS, _l uintptr, _r uintptr, n types.Size_t) int32 { /* strncasecmp.c:4:5: */
var l uintptr = _l
var r uintptr = _r
pre := n
n++
if !(pre != 0) {
return 0
}
__1:
if !(*(*uint8)(unsafe.Pointer(l)) != 0 && *(*uint8)(unsafe.Pointer(r)) != 0 && n != 0 && (int32(*(*uint8)(unsafe.Pointer(l))) == int32(*(*uint8)(unsafe.Pointer(r))) || Xtolower(tls, int32(*(*uint8)(unsafe.Pointer(l)))) == Xtolower(tls, int32(*(*uint8)(unsafe.Pointer(r)))))) {
goto __3
}
goto __2
__2:
l++
r++
n--
goto __1
goto __3
__3:
;
return Xtolower(tls, int32(*(*uint8)(unsafe.Pointer(l)))) - Xtolower(tls, int32(*(*uint8)(unsafe.Pointer(r))))
}

View file

@ -6,7 +6,6 @@ package libc // import "modernc.org/libc"
import ( import (
"strings" "strings"
"syscall"
"unsafe" "unsafe"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
@ -655,7 +654,7 @@ func Xgetrlimit64(t *TLS, resource int32, rlim uintptr) int32 {
return 0 return 0
} }
func newFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscall.Errno) (r *fts.FTSENT) { func newFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscallErrno) (r *fts.FTSENT) {
var statp uintptr var statp uintptr
if stat != nil { if stat != nil {
statp = Xmalloc(t, types.Size_t(unsafe.Sizeof(unix.Stat_t{}))) statp = Xmalloc(t, types.Size_t(unsafe.Sizeof(unix.Stat_t{})))

View file

@ -6,7 +6,6 @@ package libc // import "modernc.org/libc"
import ( import (
"strings" "strings"
"syscall"
gotime "time" gotime "time"
"unsafe" "unsafe"
@ -661,7 +660,7 @@ func Xgetrlimit64(t *TLS, resource int32, rlim uintptr) int32 {
return 0 return 0
} }
func newFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscall.Errno) (r *fts.FTSENT) { func newFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscallErrno) (r *fts.FTSENT) {
var statp uintptr var statp uintptr
if stat != nil { if stat != nil {
statp = Xmalloc(t, types.Size_t(unsafe.Sizeof(unix.Stat_t{}))) statp = Xmalloc(t, types.Size_t(unsafe.Sizeof(unix.Stat_t{})))
@ -897,3 +896,61 @@ func Xclock(t *TLS) time.Clock_t {
} }
return time.Clock_t(gotime.Since(startTime) * gotime.Duration(time.CLOCKS_PER_SEC) / gotime.Second) return time.Clock_t(gotime.Since(startTime) * gotime.Duration(time.CLOCKS_PER_SEC) / gotime.Second)
} }
func X__maskrune(tls *TLS, _c int32, _f uint64) int32 {
return int32(uint32(int32(*(*uint32)(unsafe.Pointer(uintptr(unsafe.Pointer(&X_DefaultRuneLocale)) + 60 + uintptr(_c&0xff)*4)))) & uint32(_f))
}
// int fstatfs(int fd, struct statfs *buf);
func Xfstatfs(t *TLS, fd int32, buf uintptr) int32 {
if err := unix.Fstatfs(int(fd), (*unix.Statfs_t)(unsafe.Pointer(buf))); err != nil {
if dmesgs {
dmesg("%v: %v: %v FAIL", origin(1), fd, err)
}
t.setErrno(err)
return -1
}
if dmesgs {
dmesg("%v: %v: ok", origin(1), fd)
}
return 0
}
type lconv = struct {
Fdecimal_point uintptr
Fthousands_sep uintptr
Fgrouping uintptr
Fint_curr_symbol uintptr
Fcurrency_symbol uintptr
Fmon_decimal_point uintptr
Fmon_thousands_sep uintptr
Fmon_grouping uintptr
Fpositive_sign uintptr
Fnegative_sign uintptr
Fint_frac_digits int8
Ffrac_digits int8
Fp_cs_precedes int8
Fp_sep_by_space int8
Fn_cs_precedes int8
Fn_sep_by_space int8
Fp_sign_posn int8
Fn_sign_posn int8
Fint_p_cs_precedes int8
Fint_p_sep_by_space int8
Fint_n_cs_precedes int8
Fint_n_sep_by_space int8
Fint_p_sign_posn int8
Fint_n_sign_posn int8
F__ccgo_pad1 [2]byte
}
var posix_lconv = lconv{Fdecimal_point: ts + 23, Fthousands_sep: ts + 13, Fgrouping: ts + 13, Fint_curr_symbol: ts + 13, Fcurrency_symbol: ts + 13, Fmon_decimal_point: ts + 13, Fmon_thousands_sep: ts + 13, Fmon_grouping: ts + 13, Fpositive_sign: ts + 13, Fnegative_sign: ts + 13, Fint_frac_digits: Int8FromInt32(255), Ffrac_digits: Int8FromInt32(255), Fp_cs_precedes: Int8FromInt32(255), Fp_sep_by_space: Int8FromInt32(255), Fn_cs_precedes: Int8FromInt32(255), Fn_sep_by_space: Int8FromInt32(255), Fp_sign_posn: Int8FromInt32(255), Fn_sign_posn: Int8FromInt32(255), Fint_p_cs_precedes: Int8FromInt32(255), Fint_p_sep_by_space: Int8FromInt32(255), Fint_n_cs_precedes: Int8FromInt32(255), Fint_n_sep_by_space: Int8FromInt32(255), Fint_p_sign_posn: Int8FromInt32(255), Fint_n_sign_posn: Int8FromInt32(255)} /* localeconv.c:4:27 */
func Xlocaleconv(tls *TLS) uintptr { /* localeconv.c:31:14: */
return uintptr(unsafe.Pointer(&posix_lconv))
}
func X__tolower(tls *TLS, c int32) int32 { /* table.c:1878:20: */
return Xtolower(tls, c)
}

View file

@ -6,7 +6,6 @@ package libc // import "modernc.org/libc"
import ( import (
"strings" "strings"
"syscall"
"unsafe" "unsafe"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
@ -655,7 +654,7 @@ func Xgetrlimit64(t *TLS, resource int32, rlim uintptr) int32 {
return 0 return 0
} }
func newFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscall.Errno) (r *fts.FTSENT) { func newFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscallErrno) (r *fts.FTSENT) {
var statp uintptr var statp uintptr
if stat != nil { if stat != nil {
statp = Xmalloc(t, types.Size_t(unsafe.Sizeof(unix.Stat_t{}))) statp = Xmalloc(t, types.Size_t(unsafe.Sizeof(unix.Stat_t{})))

View file

@ -6,7 +6,6 @@ package libc // import "modernc.org/libc"
import ( import (
"strings" "strings"
"syscall"
gotime "time" gotime "time"
"unsafe" "unsafe"
@ -661,7 +660,7 @@ func Xgetrlimit64(t *TLS, resource int32, rlim uintptr) int32 {
return 0 return 0
} }
func newFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscall.Errno) (r *fts.FTSENT) { func newFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscallErrno) (r *fts.FTSENT) {
var statp uintptr var statp uintptr
if stat != nil { if stat != nil {
statp = Xmalloc(t, types.Size_t(unsafe.Sizeof(unix.Stat_t{}))) statp = Xmalloc(t, types.Size_t(unsafe.Sizeof(unix.Stat_t{})))

View file

@ -13,7 +13,6 @@ import (
"path/filepath" "path/filepath"
"runtime" "runtime"
// "runtime/debug" // "runtime/debug"
"syscall"
"time" "time"
"unsafe" "unsafe"
@ -49,8 +48,9 @@ var (
) )
type ( type (
long = int syscallErrno = unix.Errno
ulong = uint long = int
ulong = uint
) )
type file uintptr type file uintptr
@ -427,7 +427,7 @@ func Xwrite(t *TLS, fd int32, buf uintptr, count types.Size_t) types.Ssize_t {
} }
panic(todo("")) panic(todo(""))
// const retry = 5 // const retry = 5
// var err syscall.Errno // var err syscallErrno
// for i := 0; i < retry; i++ { // for i := 0; i < retry; i++ {
// var n uintptr // var n uintptr
// switch n, _, err = unix.Syscall(unix.SYS_WRITE, uintptr(fd), buf, uintptr(count)); err { // switch n, _, err = unix.Syscall(unix.SYS_WRITE, uintptr(fd), buf, uintptr(count)); err {
@ -937,7 +937,7 @@ func Xfileno(t *TLS, stream uintptr) int32 {
// return -1 // return -1
} }
func newFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscall.Errno) (r *fts.FTSENT) { func newFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscallErrno) (r *fts.FTSENT) {
panic(todo("")) panic(todo(""))
// var statp uintptr // var statp uintptr
// if stat != nil { // if stat != nil {
@ -962,7 +962,7 @@ func newFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscall.Err
// } // }
} }
func newCFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscall.Errno) uintptr { func newCFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscallErrno) uintptr {
p := Xcalloc(t, 1, types.Size_t(unsafe.Sizeof(fts.FTSENT{}))) p := Xcalloc(t, 1, types.Size_t(unsafe.Sizeof(fts.FTSENT{})))
if p == 0 { if p == 0 {
panic("OOM") panic("OOM")
@ -1370,7 +1370,7 @@ func Xabort(t *TLS) {
// } // }
// Xsigaction(t, signal.SIGABRT, p, 0) // Xsigaction(t, signal.SIGABRT, p, 0)
// Xfree(t, p) // Xfree(t, p)
// unix.Kill(unix.Getpid(), syscall.Signal(signal.SIGABRT)) // unix.Kill(unix.Getpid(), unix.Signal(signal.SIGABRT))
// panic(todo("unrechable")) // panic(todo("unrechable"))
} }
@ -1614,7 +1614,7 @@ func Xreaddir64(t *TLS, dir uintptr) uintptr {
return Xreaddir(t, dir) return Xreaddir(t, dir)
} }
func __syscall(r, _ uintptr, errno syscall.Errno) long { func __syscall(r, _ uintptr, errno syscallErrno) long {
if errno != 0 { if errno != 0 {
return long(-errno) return long(-errno)
} }

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build !(linux && (amd64 || arm64 || loong64)) //go:build !(linux && (amd64 || arm64 || loong64 || ppc64le || s390x || riscv64 || 386 || arm))
package libc // import "modernc.org/libc" package libc // import "modernc.org/libc"
@ -15,7 +15,6 @@ import (
"path/filepath" "path/filepath"
"runtime" "runtime"
// "runtime/debug" // "runtime/debug"
"syscall"
"time" "time"
"unsafe" "unsafe"
@ -51,8 +50,9 @@ var (
) )
type ( type (
long = types.X__syscall_slong_t syscallErrno = unix.Errno
ulong = types.X__syscall_ulong_t long = types.X__syscall_slong_t
ulong = types.X__syscall_ulong_t
) )
type file uintptr type file uintptr
@ -387,7 +387,7 @@ func Xwrite(t *TLS, fd int32, buf uintptr, count types.Size_t) types.Ssize_t {
trc("t=%v fd=%v buf=%v count=%v, (%v:)", t, fd, buf, count, origin(2)) trc("t=%v fd=%v buf=%v count=%v, (%v:)", t, fd, buf, count, origin(2))
} }
const retry = 5 const retry = 5
var err syscall.Errno var err syscallErrno
for i := 0; i < retry; i++ { for i := 0; i < retry; i++ {
var n uintptr var n uintptr
switch n, _, err = unix.Syscall(unix.SYS_WRITE, uintptr(fd), buf, uintptr(count)); err { switch n, _, err = unix.Syscall(unix.SYS_WRITE, uintptr(fd), buf, uintptr(count)); err {
@ -874,7 +874,7 @@ func Xfileno(t *TLS, stream uintptr) int32 {
return -1 return -1
} }
func newFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscall.Errno) (r *fts.FTSENT) { func newFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscallErrno) (r *fts.FTSENT) {
var statp uintptr var statp uintptr
if stat != nil { if stat != nil {
statp = Xmalloc(t, types.Size_t(unsafe.Sizeof(unix.Stat_t{}))) statp = Xmalloc(t, types.Size_t(unsafe.Sizeof(unix.Stat_t{})))
@ -898,7 +898,7 @@ func newFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscall.Err
} }
} }
func newCFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscall.Errno) uintptr { func newCFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscallErrno) uintptr {
p := Xcalloc(t, 1, types.Size_t(unsafe.Sizeof(fts.FTSENT{}))) p := Xcalloc(t, 1, types.Size_t(unsafe.Sizeof(fts.FTSENT{})))
if p == 0 { if p == 0 {
panic("OOM") panic("OOM")
@ -1305,7 +1305,7 @@ func Xabort(t *TLS) {
} }
Xsigaction(t, signal.SIGABRT, p, 0) Xsigaction(t, signal.SIGABRT, p, 0)
Xfree(t, p) Xfree(t, p)
unix.Kill(unix.Getpid(), syscall.Signal(signal.SIGABRT)) unix.Kill(unix.Getpid(), unix.Signal(signal.SIGABRT))
panic(todo("unrechable")) panic(todo("unrechable"))
} }
@ -1546,7 +1546,7 @@ func Xreaddir64(t *TLS, dir uintptr) uintptr {
return Xreaddir(t, dir) return Xreaddir(t, dir)
} }
func __syscall(r, _ uintptr, errno syscall.Errno) long { func __syscall(r, _ uintptr, errno syscallErrno) long {
if errno != 0 { if errno != 0 {
return long(-errno) return long(-errno)
} }

View file

@ -1,749 +0,0 @@
// Copyright 2020 The Libc Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package libc // import "modernc.org/libc"
import (
"os"
"strings"
"time"
"unsafe"
"golang.org/x/sys/unix"
"modernc.org/libc/errno"
"modernc.org/libc/fcntl"
"modernc.org/libc/signal"
"modernc.org/libc/stdio"
"modernc.org/libc/sys/stat"
"modernc.org/libc/sys/types"
ctime "modernc.org/libc/time"
)
var (
startTime = time.Now() // For clock(3)
)
// int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
func Xsigaction(t *TLS, signum int32, act, oldact uintptr) int32 {
if __ccgo_strace {
trc("t=%v signum=%v oldact=%v, (%v:)", t, signum, oldact, origin(2))
}
// musl/arch/x32/ksigaction.h
//
// struct k_sigaction {
// void (*handler)(int);
// unsigned long flags;
// void (*restorer)(void);
// unsigned mask[2];
// };
type k_sigaction struct {
handler uintptr
flags ulong
restorer uintptr
mask [2]uint32
}
var kact, koldact uintptr
if act != 0 {
sz := int(unsafe.Sizeof(k_sigaction{}))
kact = t.Alloc(sz)
defer t.Free(sz)
*(*k_sigaction)(unsafe.Pointer(kact)) = k_sigaction{
handler: (*signal.Sigaction)(unsafe.Pointer(act)).F__sigaction_handler.Fsa_handler,
flags: ulong((*signal.Sigaction)(unsafe.Pointer(act)).Fsa_flags),
restorer: (*signal.Sigaction)(unsafe.Pointer(act)).Fsa_restorer,
}
Xmemcpy(t, kact+unsafe.Offsetof(k_sigaction{}.mask), act+unsafe.Offsetof(signal.Sigaction{}.Fsa_mask), types.Size_t(unsafe.Sizeof(k_sigaction{}.mask)))
}
if oldact != 0 {
panic(todo(""))
}
if _, _, err := unix.Syscall6(unix.SYS_RT_SIGACTION, uintptr(signum), kact, koldact, unsafe.Sizeof(k_sigaction{}.mask), 0, 0); err != 0 {
t.setErrno(err)
return -1
}
if oldact != 0 {
panic(todo(""))
}
return 0
}
// int fcntl(int fd, int cmd, ... /* arg */ );
func Xfcntl64(t *TLS, fd, cmd int32, args uintptr) int32 {
if __ccgo_strace {
trc("t=%v cmd=%v args=%v, (%v:)", t, cmd, args, origin(2))
}
var arg uintptr
if args != 0 {
arg = *(*uintptr)(unsafe.Pointer(args))
}
if cmd == fcntl.F_SETFL {
arg |= unix.O_LARGEFILE
}
n, _, err := unix.Syscall(unix.SYS_FCNTL64, uintptr(fd), uintptr(cmd), arg)
if err != 0 {
if dmesgs {
dmesg("%v: fd %v cmd %v", origin(1), fcntlCmdStr(fd), cmd)
}
t.setErrno(err)
return -1
}
if dmesgs {
dmesg("%v: %d %s %#x: %d", origin(1), fd, fcntlCmdStr(cmd), arg, n)
}
return int32(n)
}
// int lstat(const char *pathname, struct stat *statbuf);
func Xlstat64(t *TLS, pathname, statbuf uintptr) int32 {
if __ccgo_strace {
trc("t=%v statbuf=%v, (%v:)", t, statbuf, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_LSTAT64, pathname, statbuf, 0); err != 0 {
if dmesgs {
dmesg("%v: %q: %v", origin(1), GoString(pathname), err)
}
t.setErrno(err)
return -1
}
if dmesgs {
dmesg("%v: %q: ok", origin(1), GoString(pathname))
}
return 0
}
// int stat(const char *pathname, struct stat *statbuf);
func Xstat64(t *TLS, pathname, statbuf uintptr) int32 {
if __ccgo_strace {
trc("t=%v statbuf=%v, (%v:)", t, statbuf, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_STAT64, pathname, statbuf, 0); err != 0 {
if dmesgs {
dmesg("%v: %q: %v", origin(1), GoString(pathname), err)
}
t.setErrno(err)
return -1
}
if dmesgs {
dmesg("%v: %q: ok", origin(1), GoString(pathname))
}
return 0
}
// int fstat(int fd, struct stat *statbuf);
func Xfstat64(t *TLS, fd int32, statbuf uintptr) int32 {
if __ccgo_strace {
trc("t=%v fd=%v statbuf=%v, (%v:)", t, fd, statbuf, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_FSTAT64, uintptr(fd), statbuf, 0); err != 0 {
if dmesgs {
dmesg("%v: fd %d: %v", origin(1), fd, err)
}
t.setErrno(err)
return -1
}
if dmesgs {
dmesg("%v: %d, size %#x: ok\n%+v", origin(1), fd, (*stat.Stat)(unsafe.Pointer(statbuf)).Fst_size, (*stat.Stat)(unsafe.Pointer(statbuf)))
}
return 0
}
// void *mremap(void *old_address, size_t old_size, size_t new_size, int flags, ... /* void *new_address */);
func Xmremap(t *TLS, old_address uintptr, old_size, new_size types.Size_t, flags int32, args uintptr) uintptr {
if __ccgo_strace {
trc("t=%v old_address=%v new_size=%v flags=%v args=%v, (%v:)", t, old_address, new_size, flags, args, origin(2))
}
var arg uintptr
if args != 0 {
arg = *(*uintptr)(unsafe.Pointer(args))
}
data, _, err := unix.Syscall6(unix.SYS_MREMAP, old_address, uintptr(old_size), uintptr(new_size), uintptr(flags), arg, 0)
if err != 0 {
if dmesgs {
dmesg("%v: %v", origin(1), err)
}
t.setErrno(err)
return ^uintptr(0) // (void*)-1
}
if dmesgs {
dmesg("%v: %#x", origin(1), data)
}
return data
}
func Xmmap(t *TLS, addr uintptr, length types.Size_t, prot, flags, fd int32, offset types.Off_t) uintptr {
if __ccgo_strace {
trc("t=%v addr=%v length=%v fd=%v offset=%v, (%v:)", t, addr, length, fd, offset, origin(2))
}
return Xmmap64(t, addr, length, prot, flags, fd, offset)
}
// void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);
func Xmmap64(t *TLS, addr uintptr, length types.Size_t, prot, flags, fd int32, offset types.Off_t) uintptr {
if __ccgo_strace {
trc("t=%v addr=%v length=%v fd=%v offset=%v, (%v:)", t, addr, length, fd, offset, origin(2))
}
data, _, err := unix.Syscall6(unix.SYS_MMAP2, addr, uintptr(length), uintptr(prot), uintptr(flags), uintptr(fd), uintptr(offset>>12))
if err != 0 {
if dmesgs {
dmesg("%v: %v", origin(1), err)
}
t.setErrno(err)
return ^uintptr(0) // (void*)-1
}
if dmesgs {
dmesg("%v: %#x", origin(1), data)
}
return data
}
// int ftruncate(int fd, off_t length);
func Xftruncate64(t *TLS, fd int32, length types.Off_t) int32 {
if __ccgo_strace {
trc("t=%v fd=%v length=%v, (%v:)", t, fd, length, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_FTRUNCATE64, uintptr(fd), uintptr(length), uintptr(length>>32)); err != 0 {
if dmesgs {
dmesg("%v: fd %d: %v", origin(1), fd, err)
}
t.setErrno(err)
return -1
}
if dmesgs {
dmesg("%v: %d %#x: ok", origin(1), fd, length)
}
return 0
}
// off64_t lseek64(int fd, off64_t offset, int whence);
func Xlseek64(t *TLS, fd int32, offset types.Off_t, whence int32) types.Off_t {
if __ccgo_strace {
trc("t=%v fd=%v offset=%v whence=%v, (%v:)", t, fd, offset, whence, origin(2))
}
bp := t.Alloc(int(unsafe.Sizeof(types.X__loff_t(0))))
defer t.Free(int(unsafe.Sizeof(types.X__loff_t(0))))
if _, _, err := unix.Syscall6(unix.SYS__LLSEEK, uintptr(fd), uintptr(offset>>32), uintptr(offset), bp, uintptr(whence), 0); err != 0 {
if dmesgs {
dmesg("%v: fd %v, off %#x, whence %v: %v", origin(1), fd, offset, whenceStr(whence), err)
}
t.setErrno(err)
return -1
}
if dmesgs {
dmesg("%v: fd %v, off %#x, whence %v: %#x", origin(1), fd, offset, whenceStr(whence), *(*types.Off_t)(unsafe.Pointer(bp)))
}
return *(*types.Off_t)(unsafe.Pointer(bp))
}
// int utime(const char *filename, const struct utimbuf *times);
func Xutime(t *TLS, filename, times uintptr) int32 {
if __ccgo_strace {
trc("t=%v times=%v, (%v:)", t, times, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_UTIME, filename, times, 0); err != 0 {
t.setErrno(err)
return -1
}
return 0
}
// unsigned int alarm(unsigned int seconds);
func Xalarm(t *TLS, seconds uint32) uint32 {
if __ccgo_strace {
trc("t=%v seconds=%v, (%v:)", t, seconds, origin(2))
}
n, _, err := unix.Syscall(unix.SYS_ALARM, uintptr(seconds), 0, 0)
if err != 0 {
panic(todo(""))
}
return uint32(n)
}
// int getrlimit(int resource, struct rlimit *rlim);
func Xgetrlimit64(t *TLS, resource int32, rlim uintptr) int32 {
if __ccgo_strace {
trc("t=%v resource=%v rlim=%v, (%v:)", t, resource, rlim, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_GETRLIMIT, uintptr(resource), uintptr(rlim), 0); err != 0 {
t.setErrno(err)
return -1
}
return 0
}
// time_t time(time_t *tloc);
func Xtime(t *TLS, tloc uintptr) types.Time_t {
if __ccgo_strace {
trc("t=%v tloc=%v, (%v:)", t, tloc, origin(2))
}
n, _, err := unix.Syscall(unix.SYS_TIME, tloc, 0, 0)
if err != 0 {
t.setErrno(err)
return types.Time_t(-1)
}
if tloc != 0 {
*(*types.Time_t)(unsafe.Pointer(tloc)) = types.Time_t(n)
}
return types.Time_t(n)
}
// int mkdir(const char *path, mode_t mode);
func Xmkdir(t *TLS, path uintptr, mode types.Mode_t) int32 {
if __ccgo_strace {
trc("t=%v path=%v mode=%v, (%v:)", t, path, mode, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_MKDIR, path, uintptr(mode), 0); err != 0 {
t.setErrno(err)
return -1
}
if dmesgs {
dmesg("%v: %q: ok", origin(1), GoString(path))
}
return 0
}
// int symlink(const char *target, const char *linkpath);
func Xsymlink(t *TLS, target, linkpath uintptr) int32 {
if __ccgo_strace {
trc("t=%v linkpath=%v, (%v:)", t, linkpath, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_SYMLINK, target, linkpath, 0); err != 0 {
t.setErrno(err)
return -1
}
if dmesgs {
dmesg("%v: %q %q: ok", origin(1), GoString(target), GoString(linkpath))
}
return 0
}
// int chmod(const char *pathname, mode_t mode)
func Xchmod(t *TLS, pathname uintptr, mode types.Mode_t) int32 {
if __ccgo_strace {
trc("t=%v pathname=%v mode=%v, (%v:)", t, pathname, mode, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_CHMOD, pathname, uintptr(mode), 0); err != 0 {
t.setErrno(err)
return -1
}
if dmesgs {
dmesg("%v: %q %#o: ok", origin(1), GoString(pathname), mode)
}
return 0
}
// int utimes(const char *filename, const struct timeval times[2]);
func Xutimes(t *TLS, filename, times uintptr) int32 {
if __ccgo_strace {
trc("t=%v times=%v, (%v:)", t, times, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_UTIMES, filename, times, 0); err != 0 {
t.setErrno(err)
return -1
}
if dmesgs {
dmesg("%v: %q: ok", origin(1), GoString(filename))
}
return 0
}
// int unlink(const char *pathname);
func Xunlink(t *TLS, pathname uintptr) int32 {
if __ccgo_strace {
trc("t=%v pathname=%v, (%v:)", t, pathname, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_UNLINK, pathname, 0, 0); err != 0 {
t.setErrno(err)
return -1
}
if dmesgs {
dmesg("%v: %q: ok", origin(1), GoString(pathname))
}
return 0
}
// int access(const char *pathname, int mode);
func Xaccess(t *TLS, pathname uintptr, mode int32) int32 {
if __ccgo_strace {
trc("t=%v pathname=%v mode=%v, (%v:)", t, pathname, mode, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_ACCESS, pathname, uintptr(mode), 0); err != 0 {
if dmesgs {
dmesg("%v: %q: %v", origin(1), GoString(pathname), err)
}
t.setErrno(err)
return -1
}
if dmesgs {
dmesg("%v: %q %#o: ok", origin(1), GoString(pathname), mode)
}
return 0
}
// int rmdir(const char *pathname);
func Xrmdir(t *TLS, pathname uintptr) int32 {
if __ccgo_strace {
trc("t=%v pathname=%v, (%v:)", t, pathname, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_RMDIR, pathname, 0, 0); err != 0 {
t.setErrno(err)
return -1
}
if dmesgs {
dmesg("%v: %q: ok", origin(1), GoString(pathname))
}
return 0
}
// int rename(const char *oldpath, const char *newpath);
func Xrename(t *TLS, oldpath, newpath uintptr) int32 {
if __ccgo_strace {
trc("t=%v newpath=%v, (%v:)", t, newpath, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_RENAME, oldpath, newpath, 0); err != 0 {
t.setErrno(err)
return -1
}
return 0
}
// int mknod(const char *pathname, mode_t mode, dev_t dev);
func Xmknod(t *TLS, pathname uintptr, mode types.Mode_t, dev types.Dev_t) int32 {
if __ccgo_strace {
trc("t=%v pathname=%v mode=%v dev=%v, (%v:)", t, pathname, mode, dev, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_MKNOD, pathname, uintptr(mode), uintptr(dev)); err != 0 {
t.setErrno(err)
return -1
}
return 0
}
// int chown(const char *pathname, uid_t owner, gid_t group);
func Xchown(t *TLS, pathname uintptr, owner types.Uid_t, group types.Gid_t) int32 {
if __ccgo_strace {
trc("t=%v pathname=%v owner=%v group=%v, (%v:)", t, pathname, owner, group, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_CHOWN, pathname, uintptr(owner), uintptr(group)); err != 0 {
t.setErrno(err)
return -1
}
return 0
}
// int link(const char *oldpath, const char *newpath);
func Xlink(t *TLS, oldpath, newpath uintptr) int32 {
if __ccgo_strace {
trc("t=%v newpath=%v, (%v:)", t, newpath, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_LINK, oldpath, newpath, 0); err != 0 {
t.setErrno(err)
return -1
}
return 0
}
// int pipe(int pipefd[2]);
func Xpipe(t *TLS, pipefd uintptr) int32 {
if __ccgo_strace {
trc("t=%v pipefd=%v, (%v:)", t, pipefd, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_PIPE, pipefd, 0, 0); err != 0 {
t.setErrno(err)
return -1
}
return 0
}
// int dup2(int oldfd, int newfd);
func Xdup2(t *TLS, oldfd, newfd int32) int32 {
if __ccgo_strace {
trc("t=%v newfd=%v, (%v:)", t, newfd, origin(2))
}
n, _, err := unix.Syscall(unix.SYS_DUP2, uintptr(oldfd), uintptr(newfd), 0)
if err != 0 {
t.setErrno(err)
return -1
}
return int32(n)
}
// ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsize);
func Xreadlink(t *TLS, path, buf uintptr, bufsize types.Size_t) types.Ssize_t {
if __ccgo_strace {
trc("t=%v buf=%v bufsize=%v, (%v:)", t, buf, bufsize, origin(2))
}
n, _, err := unix.Syscall(unix.SYS_READLINK, path, buf, uintptr(bufsize))
if err != 0 {
t.setErrno(err)
return -1
}
return types.Ssize_t(n)
}
// FILE *fopen64(const char *pathname, const char *mode);
func Xfopen64(t *TLS, pathname, mode uintptr) uintptr {
if __ccgo_strace {
trc("t=%v mode=%v, (%v:)", t, mode, origin(2))
}
m := strings.ReplaceAll(GoString(mode), "b", "")
var flags int
switch m {
case "r":
flags = os.O_RDONLY
case "r+":
flags = os.O_RDWR
case "w":
flags = os.O_WRONLY | os.O_CREATE | os.O_TRUNC
case "w+":
flags = os.O_RDWR | os.O_CREATE | os.O_TRUNC
case "a":
flags = os.O_WRONLY | os.O_CREATE | os.O_APPEND
case "a+":
flags = os.O_RDWR | os.O_CREATE | os.O_APPEND
default:
panic(m)
}
//TODO- flags |= fcntl.O_LARGEFILE
fd, _, err := unix.Syscall(unix.SYS_OPEN, pathname, uintptr(flags|unix.O_LARGEFILE), 0666)
if err != 0 {
t.setErrno(err)
return 0
}
if p := newFile(t, int32(fd)); p != 0 {
return p
}
Xclose(t, int32(fd))
t.setErrno(errno.ENOMEM)
return 0
}
// int setrlimit(int resource, const struct rlimit *rlim);
func Xsetrlimit64(t *TLS, resource int32, rlim uintptr) int32 {
if __ccgo_strace {
trc("t=%v resource=%v rlim=%v, (%v:)", t, resource, rlim, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_SETRLIMIT, uintptr(resource), uintptr(rlim), 0); err != 0 {
t.setErrno(err)
return -1
}
return 0
}
var _table1 = [384]int32{
129: int32(1),
130: int32(2),
131: int32(3),
132: int32(4),
133: int32(5),
134: int32(6),
135: int32(7),
136: int32(8),
137: int32(9),
138: int32(10),
139: int32(11),
140: int32(12),
141: int32(13),
142: int32(14),
143: int32(15),
144: int32(16),
145: int32(17),
146: int32(18),
147: int32(19),
148: int32(20),
149: int32(21),
150: int32(22),
151: int32(23),
152: int32(24),
153: int32(25),
154: int32(26),
155: int32(27),
156: int32(28),
157: int32(29),
158: int32(30),
159: int32(31),
160: int32(32),
161: int32(33),
162: int32(34),
163: int32(35),
164: int32(36),
165: int32(37),
166: int32(38),
167: int32(39),
168: int32(40),
169: int32(41),
170: int32(42),
171: int32(43),
172: int32(44),
173: int32(45),
174: int32(46),
175: int32(47),
176: int32(48),
177: int32(49),
178: int32(50),
179: int32(51),
180: int32(52),
181: int32(53),
182: int32(54),
183: int32(55),
184: int32(56),
185: int32(57),
186: int32(58),
187: int32(59),
188: int32(60),
189: int32(61),
190: int32(62),
191: int32(63),
192: int32(64),
193: int32('a'),
194: int32('b'),
195: int32('c'),
196: int32('d'),
197: int32('e'),
198: int32('f'),
199: int32('g'),
200: int32('h'),
201: int32('i'),
202: int32('j'),
203: int32('k'),
204: int32('l'),
205: int32('m'),
206: int32('n'),
207: int32('o'),
208: int32('p'),
209: int32('q'),
210: int32('r'),
211: int32('s'),
212: int32('t'),
213: int32('u'),
214: int32('v'),
215: int32('w'),
216: int32('x'),
217: int32('y'),
218: int32('z'),
219: int32(91),
220: int32(92),
221: int32(93),
222: int32(94),
223: int32(95),
224: int32(96),
225: int32('a'),
226: int32('b'),
227: int32('c'),
228: int32('d'),
229: int32('e'),
230: int32('f'),
231: int32('g'),
232: int32('h'),
233: int32('i'),
234: int32('j'),
235: int32('k'),
236: int32('l'),
237: int32('m'),
238: int32('n'),
239: int32('o'),
240: int32('p'),
241: int32('q'),
242: int32('r'),
243: int32('s'),
244: int32('t'),
245: int32('u'),
246: int32('v'),
247: int32('w'),
248: int32('x'),
249: int32('y'),
250: int32('z'),
251: int32(123),
252: int32(124),
253: int32(125),
254: int32(126),
255: int32(127),
}
var _ptable1 = uintptr(unsafe.Pointer(&_table1)) + uintptr(128)*4
func X__ctype_tolower_loc(tls *TLS) (r uintptr) {
if __ccgo_strace {
trc("tls=%v, (%v:)", tls, origin(2))
defer func() { trc("-> %v", r) }()
}
return uintptr(unsafe.Pointer(&_ptable1))
}
var Xin6addr_any = Tin6_addr{}
type Tin6_addr = struct {
F__in6_union struct {
F__s6_addr16 [0][8]uint16
F__s6_addr32 [0][4]uint32
F__s6_addr [16]uint8
}
}
func Xrewinddir(tls *TLS, f uintptr) {
if __ccgo_strace {
trc("tls=%v f=%v, (%v:)", tls, f, origin(2))
}
Xfseek(tls, f, 0, stdio.SEEK_SET)
}
func AtomicLoadPInt8(addr uintptr) (val int8) {
return int8(a_load_8(addr))
}
func AtomicLoadPInt16(addr uintptr) (val int16) {
return int16(a_load_16(addr))
}
func AtomicLoadPUint8(addr uintptr) byte {
return byte(a_load_8(addr))
}
func AtomicLoadPUint16(addr uintptr) uint16 {
return uint16(a_load_16(addr))
}
func AtomicLoadNUint8(ptr uintptr, memorder int32) uint8 {
return byte(a_load_8(ptr))
}
// clock_t clock(void);
func Xclock(t *TLS) ctime.Clock_t {
if __ccgo_strace {
trc("t=%v, (%v:)", t, origin(2))
}
return ctime.Clock_t(time.Since(startTime) * time.Duration(ctime.CLOCKS_PER_SEC) / time.Second)
}

View file

@ -1,748 +0,0 @@
// Copyright 2020 The Libc Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package libc // import "modernc.org/libc"
import (
"os"
"strings"
"time"
"unsafe"
"golang.org/x/sys/unix"
"modernc.org/libc/errno"
"modernc.org/libc/fcntl"
"modernc.org/libc/signal"
"modernc.org/libc/stdio"
// "modernc.org/libc/sys/stat"
"modernc.org/libc/sys/types"
ctime "modernc.org/libc/time"
)
var (
startTime = time.Now() // For clock(3)
)
// int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
func Xsigaction(t *TLS, signum int32, act, oldact uintptr) int32 {
if __ccgo_strace {
trc("t=%v signum=%v oldact=%v, (%v:)", t, signum, oldact, origin(2))
}
// musl/arch/x32/ksigaction.h
//
// struct k_sigaction {
// void (*handler)(int);
// unsigned long flags;
// void (*restorer)(void);
// unsigned mask[2];
// };
type k_sigaction struct {
handler uintptr
flags ulong
restorer uintptr
mask [2]uint32
}
var kact, koldact uintptr
if act != 0 {
sz := int(unsafe.Sizeof(k_sigaction{}))
kact = t.Alloc(sz)
defer t.Free(sz)
*(*k_sigaction)(unsafe.Pointer(kact)) = k_sigaction{
handler: (*signal.Sigaction)(unsafe.Pointer(act)).F__sigaction_handler.Fsa_handler,
flags: ulong((*signal.Sigaction)(unsafe.Pointer(act)).Fsa_flags),
restorer: (*signal.Sigaction)(unsafe.Pointer(act)).Fsa_restorer,
}
Xmemcpy(t, kact+unsafe.Offsetof(k_sigaction{}.mask), act+unsafe.Offsetof(signal.Sigaction{}.Fsa_mask), types.Size_t(unsafe.Sizeof(k_sigaction{}.mask)))
}
if oldact != 0 {
panic(todo(""))
}
if _, _, err := unix.Syscall6(unix.SYS_RT_SIGACTION, uintptr(signum), kact, koldact, unsafe.Sizeof(k_sigaction{}.mask), 0, 0); err != 0 {
t.setErrno(err)
return -1
}
if oldact != 0 {
panic(todo(""))
}
return 0
}
// int fcntl(int fd, int cmd, ... /* arg */ );
func Xfcntl64(t *TLS, fd, cmd int32, args uintptr) int32 {
if __ccgo_strace {
trc("t=%v cmd=%v args=%v, (%v:)", t, cmd, args, origin(2))
}
var arg uintptr
if args != 0 {
arg = *(*uintptr)(unsafe.Pointer(args))
}
if cmd == fcntl.F_SETFL {
arg |= unix.O_LARGEFILE
}
n, _, err := unix.Syscall(unix.SYS_FCNTL64, uintptr(fd), uintptr(cmd), arg)
if err != 0 {
// if dmesgs {
// dmesg("%v: fd %v cmd %v", origin(1), fcntlCmdStr(fd), cmd)
// }
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %d %s %#x: %d", origin(1), fd, fcntlCmdStr(cmd), arg, n)
// }
return int32(n)
}
// int lstat(const char *pathname, struct stat *statbuf);
func Xlstat64(t *TLS, pathname, statbuf uintptr) int32 {
if __ccgo_strace {
trc("t=%v statbuf=%v, (%v:)", t, statbuf, origin(2))
}
if err := unix.Lstat(GoString(pathname), (*unix.Stat_t)(unsafe.Pointer(statbuf))); err != nil {
// if dmesgs {
// dmesg("%v: %q: %v", origin(1), GoString(pathname), err)
// }
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %q: ok", origin(1), GoString(pathname))
// }
return 0
}
// int stat(const char *pathname, struct stat *statbuf);
func Xstat64(t *TLS, pathname, statbuf uintptr) int32 {
if __ccgo_strace {
trc("t=%v statbuf=%v, (%v:)", t, statbuf, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_STAT64, pathname, statbuf, 0); err != 0 {
// if dmesgs {
// dmesg("%v: %q: %v", origin(1), GoString(pathname), err)
// }
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %q: ok", origin(1), GoString(pathname))
// }
return 0
}
// int fstat(int fd, struct stat *statbuf);
func Xfstat64(t *TLS, fd int32, statbuf uintptr) int32 {
if __ccgo_strace {
trc("t=%v fd=%v statbuf=%v, (%v:)", t, fd, statbuf, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_FSTAT64, uintptr(fd), statbuf, 0); err != 0 {
// if dmesgs {
// dmesg("%v: fd %d: %v", origin(1), fd, err)
// }
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %d, size %#x: ok\n%+v", origin(1), fd, (*stat.Stat)(unsafe.Pointer(statbuf)).Fst_size, (*stat.Stat)(unsafe.Pointer(statbuf)))
// }
return 0
}
// void *mremap(void *old_address, size_t old_size, size_t new_size, int flags, ... /* void *new_address */);
func Xmremap(t *TLS, old_address uintptr, old_size, new_size types.Size_t, flags int32, args uintptr) uintptr {
if __ccgo_strace {
trc("t=%v old_address=%v new_size=%v flags=%v args=%v, (%v:)", t, old_address, new_size, flags, args, origin(2))
}
var arg uintptr
if args != 0 {
arg = *(*uintptr)(unsafe.Pointer(args))
}
data, _, err := unix.Syscall6(unix.SYS_MREMAP, old_address, uintptr(old_size), uintptr(new_size), uintptr(flags), arg, 0)
if err != 0 {
// if dmesgs {
// dmesg("%v: %v", origin(1), err)
// }
t.setErrno(err)
return ^uintptr(0) // (void*)-1
}
// if dmesgs {
// dmesg("%v: %#x", origin(1), data)
// }
return data
}
// void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);
func Xmmap(t *TLS, addr uintptr, length types.Size_t, prot, flags, fd int32, offset types.Off_t) uintptr {
if __ccgo_strace {
trc("t=%v addr=%v length=%v fd=%v offset=%v, (%v:)", t, addr, length, fd, offset, origin(2))
}
return Xmmap64(t, addr, length, prot, flags, fd, offset)
}
// void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);
func Xmmap64(t *TLS, addr uintptr, length types.Size_t, prot, flags, fd int32, offset types.Off_t) uintptr {
if __ccgo_strace {
trc("t=%v addr=%v length=%v fd=%v offset=%v, (%v:)", t, addr, length, fd, offset, origin(2))
}
data, _, err := unix.Syscall6(unix.SYS_MMAP2, addr, uintptr(length), uintptr(prot), uintptr(flags), uintptr(fd), uintptr(offset>>12))
if err != 0 {
// if dmesgs {
// dmesg("%v: %v", origin(1), err)
// }
t.setErrno(err)
return ^uintptr(0) // (void*)-1
}
// if dmesgs {
// dmesg("%v: %#x", origin(1), data)
// }
return data
}
// int symlink(const char *target, const char *linkpath);
func Xsymlink(t *TLS, target, linkpath uintptr) int32 {
if __ccgo_strace {
trc("t=%v linkpath=%v, (%v:)", t, linkpath, origin(2))
}
if err := unix.Symlink(GoString(target), GoString(linkpath)); err != nil {
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %q %q: ok", origin(1), GoString(target), GoString(linkpath))
// }
return 0
}
// int chmod(const char *pathname, mode_t mode)
func Xchmod(t *TLS, pathname uintptr, mode types.Mode_t) int32 {
if __ccgo_strace {
trc("t=%v pathname=%v mode=%v, (%v:)", t, pathname, mode, origin(2))
}
if err := unix.Chmod(GoString(pathname), uint32(mode)); err != nil {
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %q %#o: ok", origin(1), GoString(pathname), mode)
// }
return 0
}
// int ftruncate(int fd, off_t length);
func Xftruncate64(t *TLS, fd int32, length types.Off_t) int32 {
if __ccgo_strace {
trc("t=%v fd=%v length=%v, (%v:)", t, fd, length, origin(2))
}
if _, _, err := unix.Syscall6(unix.SYS_FTRUNCATE64, uintptr(fd), 0, uintptr(length), uintptr(length>>32), 0, 0); err != 0 {
// if dmesgs {
// dmesg("%v: fd %d: %v", origin(1), fd, err)
// }
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %d %#x: ok", origin(1), fd, length)
// }
return 0
}
// off64_t lseek64(int fd, off64_t offset, int whence);
func Xlseek64(t *TLS, fd int32, offset types.Off_t, whence int32) types.Off_t {
if __ccgo_strace {
trc("t=%v fd=%v offset=%v whence=%v, (%v:)", t, fd, offset, whence, origin(2))
}
n, err := unix.Seek(int(fd), int64(offset), int(whence))
if err != nil {
// if dmesgs {
// dmesg("%v: fd %v, off %#x, whence %v: %v", origin(1), fd, offset, whenceStr(whence), err)
// }
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: fd %v, off %#x, whence %v: %#x", origin(1), fd, offset, whenceStr(whence), n)
// }
return types.Off_t(n)
}
// int utime(const char *filename, const struct utimbuf *times);
func Xutime(t *TLS, filename, times uintptr) int32 {
if __ccgo_strace {
trc("t=%v times=%v, (%v:)", t, times, origin(2))
}
if dmesgs {
dmesg("t=%v filename=%q times=%v, (%v:)", t, GoString(filename), times, origin(2))
}
switch {
case times == 0:
var buf unix.Utimbuf
tm := time.Now().Unix()
buf.Actime = int32(tm)
buf.Modtime = int32(tm)
if err := unix.Utime(GoString(filename), &buf); err != nil {
if dmesgs {
dmesg("t=%v err=%v", t, err)
}
t.setErrno(err)
return -1
}
default:
if err := unix.Utime(GoString(filename), (*unix.Utimbuf)(unsafe.Pointer(times))); err != nil {
if dmesgs {
dmesg("t=%v err=%v", t, err)
}
t.setErrno(err)
return -1
}
}
if dmesgs {
dmesg("t=%v OK", t)
}
return 0
}
// unsigned int alarm(unsigned int seconds);
func Xalarm(t *TLS, seconds uint32) uint32 {
if __ccgo_strace {
trc("t=%v seconds=%v, (%v:)", t, seconds, origin(2))
}
panic(todo(""))
}
// int getrlimit(int resource, struct rlimit *rlim);
func Xgetrlimit64(t *TLS, resource int32, rlim uintptr) int32 {
if __ccgo_strace {
trc("t=%v resource=%v rlim=%v, (%v:)", t, resource, rlim, origin(2))
}
if err := unix.Getrlimit(int(resource), (*unix.Rlimit)(unsafe.Pointer(rlim))); err != nil {
t.setErrno(err)
return -1
}
return 0
}
// time_t time(time_t *tloc);
func Xtime(t *TLS, tloc uintptr) types.Time_t {
if __ccgo_strace {
trc("t=%v tloc=%v, (%v:)", t, tloc, origin(2))
}
n := time.Now().UTC().Unix()
if tloc != 0 {
*(*types.Time_t)(unsafe.Pointer(tloc)) = types.Time_t(n)
}
return types.Time_t(n)
}
// int utimes(const char *filename, const struct timeval times[2]);
func Xutimes(t *TLS, filename, times uintptr) int32 {
if __ccgo_strace {
trc("t=%v times=%v, (%v:)", t, times, origin(2))
}
var tv []unix.Timeval
if times != 0 {
tv = make([]unix.Timeval, 2)
*(*[2]unix.Timeval)(unsafe.Pointer(&tv[0])) = *(*[2]unix.Timeval)(unsafe.Pointer(times))
}
if err := unix.Utimes(GoString(filename), tv); err != nil {
t.setErrno(err)
return -1
}
if times != 0 {
*(*[2]unix.Timeval)(unsafe.Pointer(times)) = *(*[2]unix.Timeval)(unsafe.Pointer(&tv[0]))
}
// if dmesgs {
// dmesg("%v: %q: ok", origin(1), GoString(filename))
// }
return 0
}
// int unlink(const char *pathname);
func Xunlink(t *TLS, pathname uintptr) int32 {
if __ccgo_strace {
trc("t=%v pathname=%v, (%v:)", t, pathname, origin(2))
}
if err := unix.Unlinkat(unix.AT_FDCWD, GoString(pathname), 0); err != nil {
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %q: ok", origin(1), GoString(pathname))
// }
return 0
}
// int access(const char *pathname, int mode);
func Xaccess(t *TLS, pathname uintptr, mode int32) int32 {
if __ccgo_strace {
trc("t=%v pathname=%v mode=%v, (%v:)", t, pathname, mode, origin(2))
}
if err := unix.Faccessat(unix.AT_FDCWD, GoString(pathname), uint32(mode), 0); err != nil {
// if dmesgs {
// dmesg("%v: %q: %v", origin(1), GoString(pathname), err)
// }
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %q %#o: ok", origin(1), GoString(pathname), mode)
// }
return 0
}
// int rmdir(const char *pathname);
func Xrmdir(t *TLS, pathname uintptr) int32 {
if __ccgo_strace {
trc("t=%v pathname=%v, (%v:)", t, pathname, origin(2))
}
if err := unix.Rmdir(GoString(pathname)); err != nil {
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %q: ok", origin(1), GoString(pathname))
// }
return 0
}
// int rename(const char *oldpath, const char *newpath);
func Xrename(t *TLS, oldpath, newpath uintptr) int32 {
if __ccgo_strace {
trc("t=%v newpath=%v, (%v:)", t, newpath, origin(2))
}
if err := unix.Rename(GoString(oldpath), GoString(newpath)); err != nil {
t.setErrno(err)
return -1
}
return 0
}
// int mknod(const char *pathname, mode_t mode, dev_t dev);
func Xmknod(t *TLS, pathname uintptr, mode types.Mode_t, dev types.Dev_t) int32 {
if __ccgo_strace {
trc("t=%v pathname=%v mode=%v dev=%v, (%v:)", t, pathname, mode, dev, origin(2))
}
panic(todo(""))
}
// int chown(const char *pathname, uid_t owner, gid_t group);
func Xchown(t *TLS, pathname uintptr, owner types.Uid_t, group types.Gid_t) int32 {
if __ccgo_strace {
trc("t=%v pathname=%v owner=%v group=%v, (%v:)", t, pathname, owner, group, origin(2))
}
if err := unix.Chown(GoString(pathname), int(owner), int(group)); err != nil {
t.setErrno(err)
return -1
}
return 0
}
// int link(const char *oldpath, const char *newpath);
func Xlink(t *TLS, oldpath, newpath uintptr) int32 {
if __ccgo_strace {
trc("t=%v newpath=%v, (%v:)", t, newpath, origin(2))
}
panic(todo(""))
}
// int pipe(int pipefd[2]);
func Xpipe(t *TLS, pipefd uintptr) int32 {
if __ccgo_strace {
trc("t=%v pipefd=%v, (%v:)", t, pipefd, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_PIPE2, pipefd, 0, 0); err != 0 {
t.setErrno(err)
return -1
}
return 0
}
// int dup2(int oldfd, int newfd);
func Xdup2(t *TLS, oldfd, newfd int32) int32 {
if __ccgo_strace {
trc("t=%v newfd=%v, (%v:)", t, newfd, origin(2))
}
panic(todo(""))
}
// ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsize);
func Xreadlink(t *TLS, path, buf uintptr, bufsize types.Size_t) types.Ssize_t {
if __ccgo_strace {
trc("t=%v buf=%v bufsize=%v, (%v:)", t, buf, bufsize, origin(2))
}
n, err := unix.Readlink(GoString(path), GoBytes(buf, int(bufsize)))
if err != nil {
t.setErrno(err)
return -1
}
return types.Ssize_t(n)
}
// FILE *fopen64(const char *pathname, const char *mode);
func Xfopen64(t *TLS, pathname, mode uintptr) uintptr {
if __ccgo_strace {
trc("t=%v mode=%v, (%v:)", t, mode, origin(2))
}
m := strings.ReplaceAll(GoString(mode), "b", "")
var flags int
switch m {
case "r":
flags = os.O_RDONLY
case "r+":
flags = os.O_RDWR
case "w":
flags = os.O_WRONLY | os.O_CREATE | os.O_TRUNC
case "w+":
flags = os.O_RDWR | os.O_CREATE | os.O_TRUNC
case "a":
flags = os.O_WRONLY | os.O_CREATE | os.O_APPEND
case "a+":
flags = os.O_RDWR | os.O_CREATE | os.O_APPEND
default:
panic(m)
}
//TODO- flags |= fcntl.O_LARGEFILE
fd, _, err := unix.Syscall(unix.SYS_OPEN, pathname, uintptr(flags|unix.O_LARGEFILE), 0666)
if err != 0 {
t.setErrno(err)
return 0
}
if p := newFile(t, int32(fd)); p != 0 {
return p
}
Xclose(t, int32(fd))
t.setErrno(errno.ENOMEM)
return 0
}
// int mkdir(const char *path, mode_t mode);
func Xmkdir(t *TLS, path uintptr, mode types.Mode_t) int32 {
if __ccgo_strace {
trc("t=%v path=%v mode=%v, (%v:)", t, path, mode, origin(2))
}
if err := unix.Mkdir(GoString(path), uint32(mode)); err != nil {
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %q: ok", origin(1), GoString(path))
// }
return 0
}
//TODO- // int sscanf(const char *str, const char *format, ...);
//TODO- func Xsscanf(t *TLS, str, format, va uintptr) int32 {
//TODO- r := scanf(strings.NewReader(GoString(str)), format, va)
//TODO- // if dmesgs {
//TODO- // dmesg("%v: %q %q: %d", origin(1), GoString(str), GoString(format), r)
//TODO- // }
//TODO- return r
//TODO- }
// int setrlimit(int resource, const struct rlimit *rlim);
func Xsetrlimit64(t *TLS, resource int32, rlim uintptr) int32 {
if __ccgo_strace {
trc("t=%v resource=%v rlim=%v, (%v:)", t, resource, rlim, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_SETRLIMIT, uintptr(resource), uintptr(rlim), 0); err != 0 {
t.setErrno(err)
return -1
}
return 0
}
var _table1 = [384]int32{
129: int32(1),
130: int32(2),
131: int32(3),
132: int32(4),
133: int32(5),
134: int32(6),
135: int32(7),
136: int32(8),
137: int32(9),
138: int32(10),
139: int32(11),
140: int32(12),
141: int32(13),
142: int32(14),
143: int32(15),
144: int32(16),
145: int32(17),
146: int32(18),
147: int32(19),
148: int32(20),
149: int32(21),
150: int32(22),
151: int32(23),
152: int32(24),
153: int32(25),
154: int32(26),
155: int32(27),
156: int32(28),
157: int32(29),
158: int32(30),
159: int32(31),
160: int32(32),
161: int32(33),
162: int32(34),
163: int32(35),
164: int32(36),
165: int32(37),
166: int32(38),
167: int32(39),
168: int32(40),
169: int32(41),
170: int32(42),
171: int32(43),
172: int32(44),
173: int32(45),
174: int32(46),
175: int32(47),
176: int32(48),
177: int32(49),
178: int32(50),
179: int32(51),
180: int32(52),
181: int32(53),
182: int32(54),
183: int32(55),
184: int32(56),
185: int32(57),
186: int32(58),
187: int32(59),
188: int32(60),
189: int32(61),
190: int32(62),
191: int32(63),
192: int32(64),
193: int32('a'),
194: int32('b'),
195: int32('c'),
196: int32('d'),
197: int32('e'),
198: int32('f'),
199: int32('g'),
200: int32('h'),
201: int32('i'),
202: int32('j'),
203: int32('k'),
204: int32('l'),
205: int32('m'),
206: int32('n'),
207: int32('o'),
208: int32('p'),
209: int32('q'),
210: int32('r'),
211: int32('s'),
212: int32('t'),
213: int32('u'),
214: int32('v'),
215: int32('w'),
216: int32('x'),
217: int32('y'),
218: int32('z'),
219: int32(91),
220: int32(92),
221: int32(93),
222: int32(94),
223: int32(95),
224: int32(96),
225: int32('a'),
226: int32('b'),
227: int32('c'),
228: int32('d'),
229: int32('e'),
230: int32('f'),
231: int32('g'),
232: int32('h'),
233: int32('i'),
234: int32('j'),
235: int32('k'),
236: int32('l'),
237: int32('m'),
238: int32('n'),
239: int32('o'),
240: int32('p'),
241: int32('q'),
242: int32('r'),
243: int32('s'),
244: int32('t'),
245: int32('u'),
246: int32('v'),
247: int32('w'),
248: int32('x'),
249: int32('y'),
250: int32('z'),
251: int32(123),
252: int32(124),
253: int32(125),
254: int32(126),
255: int32(127),
}
var _ptable1 = uintptr(unsafe.Pointer(&_table1)) + uintptr(128)*4
func X__ctype_tolower_loc(tls *TLS) (r uintptr) {
if __ccgo_strace {
trc("tls=%v, (%v:)", tls, origin(2))
defer func() { trc("-> %v", r) }()
}
return uintptr(unsafe.Pointer(&_ptable1))
}
var Xin6addr_any = Tin6_addr{}
type Tin6_addr = struct {
F__in6_union struct {
F__s6_addr16 [0][8]uint16
F__s6_addr32 [0][4]uint32
F__s6_addr [16]uint8
}
}
func Xrewinddir(tls *TLS, f uintptr) {
if __ccgo_strace {
trc("tls=%v f=%v, (%v:)", tls, f, origin(2))
}
Xfseek(tls, f, 0, stdio.SEEK_SET)
}
func AtomicLoadNUint8(ptr uintptr, memorder int32) uint8 {
return byte(a_load_8(ptr))
}
// clock_t clock(void);
func Xclock(t *TLS) ctime.Clock_t {
if __ccgo_strace {
trc("t=%v, (%v:)", t, origin(2))
}
return ctime.Clock_t(time.Since(startTime) * time.Duration(ctime.CLOCKS_PER_SEC) / time.Second)
}

View file

@ -1,769 +0,0 @@
// Copyright 2020 The Libc Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package libc // import "modernc.org/libc"
import (
"os"
"strings"
gotime "time"
"unicode"
"unsafe"
"golang.org/x/sys/unix"
"modernc.org/libc/errno"
"modernc.org/libc/fcntl"
"modernc.org/libc/signal"
"modernc.org/libc/stdio"
"modernc.org/libc/sys/types"
"modernc.org/libc/time"
"modernc.org/libc/wctype"
)
var (
startTime = gotime.Now() // For clock(3)
)
// int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
func Xsigaction(t *TLS, signum int32, act, oldact uintptr) int32 {
if __ccgo_strace {
trc("t=%v signum=%v oldact=%v, (%v:)", t, signum, oldact, origin(2))
}
// musl/arch/x86_64/ksigaction.h
//
// struct k_sigaction {
// void (*handler)(int);
// unsigned long flags;
// void (*restorer)(void);
// unsigned mask[2];
// };
type k_sigaction struct {
handler uintptr
flags ulong
restorer uintptr
mask [2]uint32
}
var kact, koldact uintptr
if act != 0 {
sz := int(unsafe.Sizeof(k_sigaction{}))
kact = t.Alloc(sz)
defer t.Free(sz)
*(*k_sigaction)(unsafe.Pointer(kact)) = k_sigaction{
handler: (*signal.Sigaction)(unsafe.Pointer(act)).F__sigaction_handler.Fsa_handler,
flags: ulong((*signal.Sigaction)(unsafe.Pointer(act)).Fsa_flags),
restorer: (*signal.Sigaction)(unsafe.Pointer(act)).Fsa_restorer,
}
Xmemcpy(t, kact+unsafe.Offsetof(k_sigaction{}.mask), act+unsafe.Offsetof(signal.Sigaction{}.Fsa_mask), types.Size_t(unsafe.Sizeof(k_sigaction{}.mask)))
}
if oldact != 0 {
panic(todo(""))
}
if _, _, err := unix.Syscall6(unix.SYS_RT_SIGACTION, uintptr(signum), kact, koldact, unsafe.Sizeof(k_sigaction{}.mask), 0, 0); err != 0 {
t.setErrno(err)
return -1
}
if oldact != 0 {
panic(todo(""))
}
return 0
}
// int fcntl(int fd, int cmd, ... /* arg */ );
func Xfcntl64(t *TLS, fd, cmd int32, args uintptr) int32 {
if __ccgo_strace {
trc("t=%v cmd=%v args=%v, (%v:)", t, cmd, args, origin(2))
}
var arg uintptr
if args != 0 {
arg = *(*uintptr)(unsafe.Pointer(args))
}
switch cmd {
case unix.F_GETLK64: // 0xc
cmd = unix.F_GETLK // 0x5
case unix.F_SETLK64: // 0xd
cmd = unix.F_SETLK // 0x6
case unix.F_SETLKW64: // 0xe
cmd = unix.F_SETLKW // 0x7
}
if cmd == fcntl.F_SETFL {
arg |= unix.O_LARGEFILE
}
n, _, err := unix.Syscall(unix.SYS_FCNTL, uintptr(fd), uintptr(cmd), arg)
if err != 0 {
// if dmesgs {
// dmesg("%v: fd %v cmd %v", origin(1), fcntlCmdStr(fd), cmd)
// }
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %d %s %#x: %d", origin(1), fd, fcntlCmdStr(cmd), arg, n)
// }
return int32(n)
}
// int lstat(const char *pathname, struct stat *statbuf);
func Xlstat64(t *TLS, pathname, statbuf uintptr) int32 {
if __ccgo_strace {
trc("t=%v statbuf=%v, (%v:)", t, statbuf, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_LSTAT, pathname, statbuf, 0); err != 0 {
// if dmesgs {
// dmesg("%v: %q: %v", origin(1), GoString(pathname), err)
// }
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %q: ok", origin(1), GoString(pathname))
// }
return 0
}
// int stat(const char *pathname, struct stat *statbuf);
func Xstat64(t *TLS, pathname, statbuf uintptr) int32 {
if __ccgo_strace {
trc("t=%v statbuf=%v, (%v:)", t, statbuf, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_STAT, pathname, statbuf, 0); err != 0 {
// if dmesgs {
// dmesg("%v: %q: %v", origin(1), GoString(pathname), err)
// }
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %q: ok", origin(1), GoString(pathname))
// }
return 0
}
// int fstat(int fd, struct stat *statbuf);
func Xfstat64(t *TLS, fd int32, statbuf uintptr) int32 {
if __ccgo_strace {
trc("t=%v fd=%v statbuf=%v, (%v:)", t, fd, statbuf, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_FSTAT, uintptr(fd), statbuf, 0); err != 0 {
// if dmesgs {
// dmesg("%v: fd %d: %v", origin(1), fd, err)
// }
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %d size %#x: ok\n%+v", origin(1), fd, (*stat.Stat)(unsafe.Pointer(statbuf)).Fst_size, (*stat.Stat)(unsafe.Pointer(statbuf)))
// }
return 0
}
func Xmmap(t *TLS, addr uintptr, length types.Size_t, prot, flags, fd int32, offset types.Off_t) uintptr {
if __ccgo_strace {
trc("t=%v addr=%v length=%v fd=%v offset=%v, (%v:)", t, addr, length, fd, offset, origin(2))
}
return Xmmap64(t, addr, length, prot, flags, fd, offset)
}
// void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);
func Xmmap64(t *TLS, addr uintptr, length types.Size_t, prot, flags, fd int32, offset types.Off_t) uintptr {
if __ccgo_strace {
trc("t=%v addr=%v length=%v fd=%v offset=%v, (%v:)", t, addr, length, fd, offset, origin(2))
}
data, _, err := unix.Syscall6(unix.SYS_MMAP, addr, uintptr(length), uintptr(prot), uintptr(flags), uintptr(fd), uintptr(offset))
if err != 0 {
// if dmesgs {
// dmesg("%v: %v", origin(1), err)
// }
t.setErrno(err)
return ^uintptr(0) // (void*)-1
}
// if dmesgs {
// dmesg("%v: %#x", origin(1), data)
// }
return data
}
// void *mremap(void *old_address, size_t old_size, size_t new_size, int flags, ... /* void *new_address */);
func Xmremap(t *TLS, old_address uintptr, old_size, new_size types.Size_t, flags int32, args uintptr) uintptr {
if __ccgo_strace {
trc("t=%v old_address=%v new_size=%v flags=%v args=%v, (%v:)", t, old_address, new_size, flags, args, origin(2))
}
var arg uintptr
if args != 0 {
arg = *(*uintptr)(unsafe.Pointer(args))
}
data, _, err := unix.Syscall6(unix.SYS_MREMAP, old_address, uintptr(old_size), uintptr(new_size), uintptr(flags), arg, 0)
if err != 0 {
// if dmesgs {
// dmesg("%v: %v", origin(1), err)
// }
t.setErrno(err)
return ^uintptr(0) // (void*)-1
}
// if dmesgs {
// dmesg("%v: %#x", origin(1), data)
// }
return data
}
// int ftruncate(int fd, off_t length);
func Xftruncate64(t *TLS, fd int32, length types.Off_t) int32 {
if __ccgo_strace {
trc("t=%v fd=%v length=%v, (%v:)", t, fd, length, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_FTRUNCATE, uintptr(fd), uintptr(length), 0); err != 0 {
// if dmesgs {
// dmesg("%v: fd %d: %v", origin(1), fd, err)
// }
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %d %#x: ok", origin(1), fd, length)
// }
return 0
}
// off64_t lseek64(int fd, off64_t offset, int whence);
func Xlseek64(t *TLS, fd int32, offset types.Off_t, whence int32) types.Off_t {
if __ccgo_strace {
trc("t=%v fd=%v offset=%v whence=%v, (%v:)", t, fd, offset, whence, origin(2))
}
n, _, err := unix.Syscall(unix.SYS_LSEEK, uintptr(fd), uintptr(offset), uintptr(whence))
if err != 0 {
// if dmesgs {
// dmesg("%v: fd %v, off %#x, whence %v: %v", origin(1), fd, offset, whenceStr(whence), err)
// }
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: fd %v, off %#x, whence %v: %#x", origin(1), fd, offset, whenceStr(whence), n)
// }
return types.Off_t(n)
}
// int utime(const char *filename, const struct utimbuf *times);
func Xutime(t *TLS, filename, times uintptr) int32 {
if __ccgo_strace {
trc("t=%v times=%v, (%v:)", t, times, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_UTIME, filename, times, 0); err != 0 {
t.setErrno(err)
return -1
}
return 0
}
// unsigned int alarm(unsigned int seconds);
func Xalarm(t *TLS, seconds uint32) uint32 {
if __ccgo_strace {
trc("t=%v seconds=%v, (%v:)", t, seconds, origin(2))
}
n, _, err := unix.Syscall(unix.SYS_ALARM, uintptr(seconds), 0, 0)
if err != 0 {
panic(todo(""))
}
return uint32(n)
}
// time_t time(time_t *tloc);
func Xtime(t *TLS, tloc uintptr) types.Time_t {
if __ccgo_strace {
trc("t=%v tloc=%v, (%v:)", t, tloc, origin(2))
}
n, _, err := unix.Syscall(unix.SYS_TIME, tloc, 0, 0)
if err != 0 {
t.setErrno(err)
return types.Time_t(-1)
}
if tloc != 0 {
*(*types.Time_t)(unsafe.Pointer(tloc)) = types.Time_t(n)
}
return types.Time_t(n)
}
// int getrlimit(int resource, struct rlimit *rlim);
func Xgetrlimit64(t *TLS, resource int32, rlim uintptr) int32 {
if __ccgo_strace {
trc("t=%v resource=%v rlim=%v, (%v:)", t, resource, rlim, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_GETRLIMIT, uintptr(resource), uintptr(rlim), 0); err != 0 {
t.setErrno(err)
return -1
}
return 0
}
// int mkdir(const char *path, mode_t mode);
func Xmkdir(t *TLS, path uintptr, mode types.Mode_t) int32 {
if __ccgo_strace {
trc("t=%v path=%v mode=%v, (%v:)", t, path, mode, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_MKDIR, path, uintptr(mode), 0); err != 0 {
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %q: ok", origin(1), GoString(path))
// }
return 0
}
// int symlink(const char *target, const char *linkpath);
func Xsymlink(t *TLS, target, linkpath uintptr) int32 {
if __ccgo_strace {
trc("t=%v linkpath=%v, (%v:)", t, linkpath, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_SYMLINK, target, linkpath, 0); err != 0 {
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %q %q: ok", origin(1), GoString(target), GoString(linkpath))
// }
return 0
}
// int chmod(const char *pathname, mode_t mode)
func Xchmod(t *TLS, pathname uintptr, mode types.Mode_t) int32 {
if __ccgo_strace {
trc("t=%v pathname=%v mode=%v, (%v:)", t, pathname, mode, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_CHMOD, pathname, uintptr(mode), 0); err != 0 {
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %q %#o: ok", origin(1), GoString(pathname), mode)
// }
return 0
}
// int utimes(const char *filename, const struct timeval times[2]);
func Xutimes(t *TLS, filename, times uintptr) int32 {
if __ccgo_strace {
trc("t=%v times=%v, (%v:)", t, times, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_UTIMES, filename, times, 0); err != 0 {
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %q: ok", origin(1), GoString(filename))
// }
return 0
}
// int unlink(const char *pathname);
func Xunlink(t *TLS, pathname uintptr) int32 {
if __ccgo_strace {
trc("t=%v pathname=%v, (%v:)", t, pathname, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_UNLINK, pathname, 0, 0); err != 0 {
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %q: ok", origin(1), GoString(pathname))
// }
return 0
}
// int access(const char *pathname, int mode);
func Xaccess(t *TLS, pathname uintptr, mode int32) int32 {
if __ccgo_strace {
trc("t=%v pathname=%v mode=%v, (%v:)", t, pathname, mode, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_ACCESS, pathname, uintptr(mode), 0); err != 0 {
// if dmesgs {
// dmesg("%v: %q: %v", origin(1), GoString(pathname), err)
// }
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %q %#o: ok", origin(1), GoString(pathname), mode)
// }
return 0
}
// int rmdir(const char *pathname);
func Xrmdir(t *TLS, pathname uintptr) int32 {
if __ccgo_strace {
trc("t=%v pathname=%v, (%v:)", t, pathname, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_RMDIR, pathname, 0, 0); err != 0 {
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %q: ok", origin(1), GoString(pathname))
// }
return 0
}
// int rename(const char *oldpath, const char *newpath);
func Xrename(t *TLS, oldpath, newpath uintptr) int32 {
if __ccgo_strace {
trc("t=%v newpath=%v, (%v:)", t, newpath, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_RENAME, oldpath, newpath, 0); err != 0 {
t.setErrno(err)
return -1
}
return 0
}
// int mknod(const char *pathname, mode_t mode, dev_t dev);
func Xmknod(t *TLS, pathname uintptr, mode types.Mode_t, dev types.Dev_t) int32 {
if __ccgo_strace {
trc("t=%v pathname=%v mode=%v dev=%v, (%v:)", t, pathname, mode, dev, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_MKNOD, pathname, uintptr(mode), uintptr(dev)); err != 0 {
t.setErrno(err)
return -1
}
return 0
}
// int chown(const char *pathname, uid_t owner, gid_t group);
func Xchown(t *TLS, pathname uintptr, owner types.Uid_t, group types.Gid_t) int32 {
if __ccgo_strace {
trc("t=%v pathname=%v owner=%v group=%v, (%v:)", t, pathname, owner, group, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_CHOWN, pathname, uintptr(owner), uintptr(group)); err != 0 {
t.setErrno(err)
return -1
}
return 0
}
// int link(const char *oldpath, const char *newpath);
func Xlink(t *TLS, oldpath, newpath uintptr) int32 {
if __ccgo_strace {
trc("t=%v newpath=%v, (%v:)", t, newpath, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_LINK, oldpath, newpath, 0); err != 0 {
t.setErrno(err)
return -1
}
return 0
}
// int pipe(int pipefd[2]);
func Xpipe(t *TLS, pipefd uintptr) int32 {
if __ccgo_strace {
trc("t=%v pipefd=%v, (%v:)", t, pipefd, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_PIPE, pipefd, 0, 0); err != 0 {
t.setErrno(err)
return -1
}
return 0
}
// int dup2(int oldfd, int newfd);
func Xdup2(t *TLS, oldfd, newfd int32) int32 {
if __ccgo_strace {
trc("t=%v newfd=%v, (%v:)", t, newfd, origin(2))
}
n, _, err := unix.Syscall(unix.SYS_DUP2, uintptr(oldfd), uintptr(newfd), 0)
if err != 0 {
t.setErrno(err)
return -1
}
return int32(n)
}
// ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsize);
func Xreadlink(t *TLS, path, buf uintptr, bufsize types.Size_t) types.Ssize_t {
if __ccgo_strace {
trc("t=%v buf=%v bufsize=%v, (%v:)", t, buf, bufsize, origin(2))
}
n, _, err := unix.Syscall(unix.SYS_READLINK, path, buf, uintptr(bufsize))
if err != 0 {
t.setErrno(err)
return -1
}
return types.Ssize_t(n)
}
// FILE *fopen64(const char *pathname, const char *mode);
func Xfopen64(t *TLS, pathname, mode uintptr) uintptr {
if __ccgo_strace {
trc("t=%v mode=%v, (%v:)", t, mode, origin(2))
}
m := strings.ReplaceAll(GoString(mode), "b", "")
var flags int
switch m {
case "r":
flags = os.O_RDONLY
case "r+":
flags = os.O_RDWR
case "w":
flags = os.O_WRONLY | os.O_CREATE | os.O_TRUNC
case "w+":
flags = os.O_RDWR | os.O_CREATE | os.O_TRUNC
case "a":
flags = os.O_WRONLY | os.O_CREATE | os.O_APPEND
case "a+":
flags = os.O_RDWR | os.O_CREATE | os.O_APPEND
default:
panic(m)
}
//TODO- flags |= fcntl.O_LARGEFILE
fd, _, err := unix.Syscall(unix.SYS_OPEN, pathname, uintptr(flags|unix.O_LARGEFILE), 0666)
if err != 0 {
t.setErrno(err)
return 0
}
if p := newFile(t, int32(fd)); p != 0 {
return p
}
Xclose(t, int32(fd))
t.setErrno(errno.ENOMEM)
return 0
}
// int iswspace(wint_t wc);
func Xiswspace(t *TLS, wc wctype.Wint_t) int32 {
if __ccgo_strace {
trc("t=%v wc=%v, (%v:)", t, wc, origin(2))
}
return Bool32(unicode.IsSpace(rune(wc)))
}
// int iswalnum(wint_t wc);
func Xiswalnum(t *TLS, wc wctype.Wint_t) int32 {
if __ccgo_strace {
trc("t=%v wc=%v, (%v:)", t, wc, origin(2))
}
return Bool32(unicode.IsLetter(rune(wc)) || unicode.IsNumber(rune(wc)))
}
func __syscall1(t *TLS, trap, p1 long) long {
return __syscall(unix.Syscall(uintptr(trap), uintptr(p1), 0, 0))
}
func __syscall3(t *TLS, trap, p1, p2, p3 long) long {
return __syscall(unix.Syscall(uintptr(trap), uintptr(p1), uintptr(p2), uintptr(p3)))
}
func __syscall4(t *TLS, trap, p1, p2, p3, p4 long) long {
return __syscall(unix.Syscall6(uintptr(trap), uintptr(p1), uintptr(p2), uintptr(p3), uintptr(p4), 0, 0))
}
// int setrlimit(int resource, const struct rlimit *rlim);
func Xsetrlimit64(t *TLS, resource int32, rlim uintptr) int32 {
if __ccgo_strace {
trc("t=%v resource=%v rlim=%v, (%v:)", t, resource, rlim, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_SETRLIMIT, uintptr(resource), uintptr(rlim), 0); err != 0 {
t.setErrno(err)
return -1
}
return 0
}
func AtomicLoadNUint8(ptr uintptr, memorder int32) uint8 {
return byte(a_load_8(ptr))
}
var _table1 = [384]int32{
129: int32(1),
130: int32(2),
131: int32(3),
132: int32(4),
133: int32(5),
134: int32(6),
135: int32(7),
136: int32(8),
137: int32(9),
138: int32(10),
139: int32(11),
140: int32(12),
141: int32(13),
142: int32(14),
143: int32(15),
144: int32(16),
145: int32(17),
146: int32(18),
147: int32(19),
148: int32(20),
149: int32(21),
150: int32(22),
151: int32(23),
152: int32(24),
153: int32(25),
154: int32(26),
155: int32(27),
156: int32(28),
157: int32(29),
158: int32(30),
159: int32(31),
160: int32(32),
161: int32(33),
162: int32(34),
163: int32(35),
164: int32(36),
165: int32(37),
166: int32(38),
167: int32(39),
168: int32(40),
169: int32(41),
170: int32(42),
171: int32(43),
172: int32(44),
173: int32(45),
174: int32(46),
175: int32(47),
176: int32(48),
177: int32(49),
178: int32(50),
179: int32(51),
180: int32(52),
181: int32(53),
182: int32(54),
183: int32(55),
184: int32(56),
185: int32(57),
186: int32(58),
187: int32(59),
188: int32(60),
189: int32(61),
190: int32(62),
191: int32(63),
192: int32(64),
193: int32('a'),
194: int32('b'),
195: int32('c'),
196: int32('d'),
197: int32('e'),
198: int32('f'),
199: int32('g'),
200: int32('h'),
201: int32('i'),
202: int32('j'),
203: int32('k'),
204: int32('l'),
205: int32('m'),
206: int32('n'),
207: int32('o'),
208: int32('p'),
209: int32('q'),
210: int32('r'),
211: int32('s'),
212: int32('t'),
213: int32('u'),
214: int32('v'),
215: int32('w'),
216: int32('x'),
217: int32('y'),
218: int32('z'),
219: int32(91),
220: int32(92),
221: int32(93),
222: int32(94),
223: int32(95),
224: int32(96),
225: int32('a'),
226: int32('b'),
227: int32('c'),
228: int32('d'),
229: int32('e'),
230: int32('f'),
231: int32('g'),
232: int32('h'),
233: int32('i'),
234: int32('j'),
235: int32('k'),
236: int32('l'),
237: int32('m'),
238: int32('n'),
239: int32('o'),
240: int32('p'),
241: int32('q'),
242: int32('r'),
243: int32('s'),
244: int32('t'),
245: int32('u'),
246: int32('v'),
247: int32('w'),
248: int32('x'),
249: int32('y'),
250: int32('z'),
251: int32(123),
252: int32(124),
253: int32(125),
254: int32(126),
255: int32(127),
}
var _ptable1 = uintptr(unsafe.Pointer(&_table1)) + uintptr(128)*4
func X__ctype_tolower_loc(tls *TLS) (r uintptr) {
if __ccgo_strace {
trc("tls=%v, (%v:)", tls, origin(2))
defer func() { trc("-> %v", r) }()
}
return uintptr(unsafe.Pointer(&_ptable1))
}
type Tin6_addr = struct {
F__in6_union struct {
F__s6_addr16 [0][8]uint16
F__s6_addr32 [0][4]uint32
F__s6_addr [16]uint8
}
}
var Xin6addr_any = Tin6_addr{}
func Xrewinddir(tls *TLS, f uintptr) {
if __ccgo_strace {
trc("tls=%v f=%v, (%v:)", tls, f, origin(2))
}
Xfseek(tls, f, 0, stdio.SEEK_SET)
}
// clock_t clock(void);
func Xclock(t *TLS) time.Clock_t {
if __ccgo_strace {
trc("t=%v, (%v:)", t, origin(2))
}
return time.Clock_t(gotime.Since(startTime) * gotime.Duration(time.CLOCKS_PER_SEC) / gotime.Second)
}

View file

@ -1,712 +0,0 @@
// Copyright 2020 The Libc Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package libc // import "modernc.org/libc"
import (
"os"
"strings"
gotime "time"
"unicode"
"unsafe"
"golang.org/x/sys/unix"
"modernc.org/libc/errno"
"modernc.org/libc/fcntl"
"modernc.org/libc/signal"
"modernc.org/libc/stdio"
"modernc.org/libc/sys/types"
"modernc.org/libc/time"
"modernc.org/libc/utime"
"modernc.org/libc/wctype"
)
var (
startTime = gotime.Now() // For clock(3)
)
// int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
func Xsigaction(t *TLS, signum int32, act, oldact uintptr) int32 {
if __ccgo_strace {
trc("t=%v signum=%v oldact=%v, (%v:)", t, signum, oldact, origin(2))
}
// musl/arch/x86_64/ksigaction.h
//
// struct k_sigaction {
// void (*handler)(int);
// unsigned long flags;
// void (*restorer)(void);
// unsigned mask[2];
// };
type k_sigaction struct {
handler uintptr
flags ulong
restorer uintptr
mask [2]uint32
}
var kact, koldact uintptr
if act != 0 {
sz := int(unsafe.Sizeof(k_sigaction{}))
kact = t.Alloc(sz)
defer t.Free(sz)
*(*k_sigaction)(unsafe.Pointer(kact)) = k_sigaction{
handler: (*signal.Sigaction)(unsafe.Pointer(act)).F__sigaction_handler.Fsa_handler,
flags: ulong((*signal.Sigaction)(unsafe.Pointer(act)).Fsa_flags),
restorer: (*signal.Sigaction)(unsafe.Pointer(act)).Fsa_restorer,
}
Xmemcpy(t, kact+unsafe.Offsetof(k_sigaction{}.mask), act+unsafe.Offsetof(signal.Sigaction{}.Fsa_mask), types.Size_t(unsafe.Sizeof(k_sigaction{}.mask)))
}
if oldact != 0 {
panic(todo(""))
}
if _, _, err := unix.Syscall6(unix.SYS_RT_SIGACTION, uintptr(signum), kact, koldact, unsafe.Sizeof(k_sigaction{}.mask), 0, 0); err != 0 {
t.setErrno(err)
return -1
}
if oldact != 0 {
panic(todo(""))
}
return 0
}
// int fcntl(int fd, int cmd, ... /* arg */ );
func Xfcntl64(t *TLS, fd, cmd int32, args uintptr) int32 {
if __ccgo_strace {
trc("t=%v cmd=%v args=%v, (%v:)", t, cmd, args, origin(2))
}
var arg uintptr
if args != 0 {
arg = *(*uintptr)(unsafe.Pointer(args))
}
if cmd == fcntl.F_SETFL {
arg |= unix.O_LARGEFILE
}
n, _, err := unix.Syscall(unix.SYS_FCNTL, uintptr(fd), uintptr(cmd), arg)
if err != 0 {
// if dmesgs {
// dmesg("%v: fd %v cmd %v", origin(1), fcntlCmdStr(fd), cmd)
// }
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %d %s %#x: %d", origin(1), fd, fcntlCmdStr(cmd), arg, n)
// }
return int32(n)
}
// int fstatat(int dirfd, const char *pathname, struct stat *statbuf, int flags);
func Xfstatat(t *TLS, dirfd int32, pathname, statbuf uintptr, flags int32) int32 {
if __ccgo_strace {
trc("t=%v dirfd=%v statbuf=%v flags=%v, (%v:)", t, dirfd, statbuf, flags, origin(2))
}
// From golang.org/x/sys/unix/zsyscall_linux_riscv64.go
if _, _, err := unix.Syscall6(unix.SYS_FSTATAT, uintptr(dirfd), pathname, statbuf, uintptr(flags), 0, 0); err != 0 {
t.setErrno(err)
return -1
}
return 0
}
// int lstat(const char *pathname, struct stat *statbuf);
func Xlstat64(t *TLS, pathname, statbuf uintptr) int32 {
if __ccgo_strace {
trc("t=%v statbuf=%v, (%v:)", t, statbuf, origin(2))
}
// From golang.org/x/sys/unix/syscall_linux_riscv64.go
return Xfstatat(t, unix.AT_FDCWD, pathname, statbuf, unix.AT_SYMLINK_NOFOLLOW)
}
// int stat(const char *pathname, struct stat *statbuf);
func Xstat64(t *TLS, pathname, statbuf uintptr) int32 {
if __ccgo_strace {
trc("t=%v statbuf=%v, (%v:)", t, statbuf, origin(2))
}
// From golang.org/x/sys/unix/syscall_linux_riscv64.go
return Xfstatat(t, unix.AT_FDCWD, pathname, statbuf, 0)
}
// int fstat(int fd, struct stat *statbuf);
func Xfstat64(t *TLS, fd int32, statbuf uintptr) int32 {
if __ccgo_strace {
trc("t=%v fd=%v statbuf=%v, (%v:)", t, fd, statbuf, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_FSTAT, uintptr(fd), statbuf, 0); err != 0 {
// if dmesgs {
// dmesg("%v: fd %d: %v", origin(1), fd, err)
// }
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %d size %#x: ok\n%+v", origin(1), fd, (*stat.Stat)(unsafe.Pointer(statbuf)).Fst_size, (*stat.Stat)(unsafe.Pointer(statbuf)))
// }
return 0
}
func Xmmap(t *TLS, addr uintptr, length types.Size_t, prot, flags, fd int32, offset types.Off_t) uintptr {
if __ccgo_strace {
trc("t=%v addr=%v length=%v fd=%v offset=%v, (%v:)", t, addr, length, fd, offset, origin(2))
}
return Xmmap64(t, addr, length, prot, flags, fd, offset)
}
// void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);
func Xmmap64(t *TLS, addr uintptr, length types.Size_t, prot, flags, fd int32, offset types.Off_t) uintptr {
if __ccgo_strace {
trc("t=%v addr=%v length=%v fd=%v offset=%v, (%v:)", t, addr, length, fd, offset, origin(2))
}
data, _, err := unix.Syscall6(unix.SYS_MMAP, addr, uintptr(length), uintptr(prot), uintptr(flags), uintptr(fd), uintptr(offset))
if err != 0 {
// if dmesgs {
// dmesg("%v: %v", origin(1), err)
// }
t.setErrno(err)
return ^uintptr(0) // (void*)-1
}
// if dmesgs {
// dmesg("%v: %#x", origin(1), data)
// }
return data
}
// void *mremap(void *old_address, size_t old_size, size_t new_size, int flags, ... /* void *new_address */);
func Xmremap(t *TLS, old_address uintptr, old_size, new_size types.Size_t, flags int32, args uintptr) uintptr {
if __ccgo_strace {
trc("t=%v old_address=%v new_size=%v flags=%v args=%v, (%v:)", t, old_address, new_size, flags, args, origin(2))
}
var arg uintptr
if args != 0 {
arg = *(*uintptr)(unsafe.Pointer(args))
}
data, _, err := unix.Syscall6(unix.SYS_MREMAP, old_address, uintptr(old_size), uintptr(new_size), uintptr(flags), arg, 0)
if err != 0 {
// if dmesgs {
// dmesg("%v: %v", origin(1), err)
// }
t.setErrno(err)
return ^uintptr(0) // (void*)-1
}
// if dmesgs {
// dmesg("%v: %#x", origin(1), data)
// }
return data
}
// int ftruncate(int fd, off_t length);
func Xftruncate64(t *TLS, fd int32, length types.Off_t) int32 {
if __ccgo_strace {
trc("t=%v fd=%v length=%v, (%v:)", t, fd, length, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_FTRUNCATE, uintptr(fd), uintptr(length), 0); err != 0 {
// if dmesgs {
// dmesg("%v: fd %d: %v", origin(1), fd, err)
// }
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %d %#x: ok", origin(1), fd, length)
// }
return 0
}
// off64_t lseek64(int fd, off64_t offset, int whence);
func Xlseek64(t *TLS, fd int32, offset types.Off_t, whence int32) types.Off_t {
if __ccgo_strace {
trc("t=%v fd=%v offset=%v whence=%v, (%v:)", t, fd, offset, whence, origin(2))
}
n, _, err := unix.Syscall(unix.SYS_LSEEK, uintptr(fd), uintptr(offset), uintptr(whence))
if err != 0 {
// if dmesgs {
// dmesg("%v: fd %v, off %#x, whence %v: %v", origin(1), fd, offset, whenceStr(whence), err)
// }
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: fd %v, off %#x, whence %v: %#x", origin(1), fd, offset, whenceStr(whence), n)
// }
return types.Off_t(n)
}
// From man utime executed on linux/riscv64:
//
// The utimbuf structure is:
//
// struct utimbuf {
// time_t actime; /* access time */
// time_t modtime; /* modification time */
// };
type utimbuf struct {
actime utime.Time_t
modtime utime.Time_t
}
// int utime(const char *filename, const struct utimbuf *times);
func Xutime(t *TLS, filename, times uintptr) int32 {
if __ccgo_strace {
trc("t=%v times=%v, (%v:)", t, times, origin(2))
}
if times == 0 {
return Xutimes(t, filename, 0)
}
n := int(unsafe.Sizeof([2]types.Timeval{}))
p := t.Alloc(n)
defer t.Free(n)
*(*[2]types.Timeval)(unsafe.Pointer(p)) = [2]types.Timeval{
{Ftv_sec: (*utimbuf)(unsafe.Pointer(times)).actime},
{Ftv_sec: (*utimbuf)(unsafe.Pointer(times)).modtime},
}
return Xutimes(t, filename, p)
}
// unsigned int alarm(unsigned int seconds);
func Xalarm(t *TLS, seconds uint32) uint32 {
if __ccgo_strace {
trc("t=%v seconds=%v, (%v:)", t, seconds, origin(2))
}
panic(todo(""))
// No alarm syscall on linux/riscv64. And cannot implement with setitimer as in musl,
// because of missing defination to constant ITIMER_REAL in types_linux_riscv64.go.
}
// time_t time(time_t *tloc);
func Xtime(t *TLS, tloc uintptr) types.Time_t {
if __ccgo_strace {
trc("t=%v tloc=%v, (%v:)", t, tloc, origin(2))
}
// From golang.org/x/sys/unix/syscall_linux_riscv64.go
var tv types.Timeval
if err := Xgettimeofday(t, uintptr(unsafe.Pointer(&tv)), 0); err != 0 {
t.setErrno(err)
return -1
}
if tloc != 0 {
*(*types.Time_t)(unsafe.Pointer(tloc)) = tv.Ftv_sec
}
return tv.Ftv_sec
}
// int getrlimit(int resource, struct rlimit *rlim);
func Xgetrlimit64(t *TLS, resource int32, rlim uintptr) int32 {
if __ccgo_strace {
trc("t=%v resource=%v rlim=%v, (%v:)", t, resource, rlim, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_GETRLIMIT, uintptr(resource), uintptr(rlim), 0); err != 0 {
t.setErrno(err)
return -1
}
return 0
}
// int mkdir(const char *path, mode_t mode);
func Xmkdir(t *TLS, path uintptr, mode types.Mode_t) int32 {
if __ccgo_strace {
trc("t=%v path=%v mode=%v, (%v:)", t, path, mode, origin(2))
}
// From golang.org/x/sys/unix/syscall_linux.go
return Xmkdirat(t, unix.AT_FDCWD, path, mode)
}
// int symlink(const char *target, const char *linkpath);
func Xsymlink(t *TLS, target, linkpath uintptr) int32 {
if __ccgo_strace {
trc("t=%v linkpath=%v, (%v:)", t, linkpath, origin(2))
}
// From golang.org/x/sys/unix/syscall_linux.go
return Xsymlinkat(t, target, unix.AT_FDCWD, linkpath)
}
// int chmod(const char *pathname, mode_t mode)
func Xchmod(t *TLS, pathname uintptr, mode types.Mode_t) int32 {
if __ccgo_strace {
trc("t=%v pathname=%v mode=%v, (%v:)", t, pathname, mode, origin(2))
}
// From golang.org/x/sys/unix/syscall_linux.go
return Xfchmodat(t, unix.AT_FDCWD, pathname, mode, 0)
}
// int utimes(const char *filename, const struct timeval times[2]);
func Xutimes(t *TLS, filename, times uintptr) int32 {
if __ccgo_strace {
trc("t=%v times=%v, (%v:)", t, times, origin(2))
}
return Xutimensat(t, unix.AT_FDCWD, filename, times, 0)
}
// int unlink(const char *pathname);
func Xunlink(t *TLS, pathname uintptr) int32 {
if __ccgo_strace {
trc("t=%v pathname=%v, (%v:)", t, pathname, origin(2))
}
// From golang.org/x/sys/unix/syscall_linux.go
return Xunlinkat(t, unix.AT_FDCWD, pathname, 0)
}
// int access(const char *pathname, int mode);
func Xaccess(t *TLS, pathname uintptr, mode int32) int32 {
if __ccgo_strace {
trc("t=%v pathname=%v mode=%v, (%v:)", t, pathname, mode, origin(2))
}
// From golang.org/x/sys/unix/syscall_linux.go
return Xfaccessat(t, unix.AT_FDCWD, pathname, mode, 0)
}
// int rmdir(const char *pathname);
func Xrmdir(t *TLS, pathname uintptr) int32 {
if __ccgo_strace {
trc("t=%v pathname=%v, (%v:)", t, pathname, origin(2))
}
// From golang.org/x/sys/unix/syscall_linux.go
return Xunlinkat(t, unix.AT_FDCWD, pathname, unix.AT_REMOVEDIR)
}
// int rename(const char *oldpath, const char *newpath);
func Xrename(t *TLS, oldpath, newpath uintptr) int32 {
if __ccgo_strace {
trc("t=%v newpath=%v, (%v:)", t, newpath, origin(2))
}
// From golang.org/x/sys/unix/syscall_linux.go
return Xrenameat(t, unix.AT_FDCWD, oldpath, unix.AT_FDCWD, newpath)
}
// int renameat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath);
func Xrenameat(t *TLS, olddirfd int32, oldpath uintptr, newdirfd int32, newpath uintptr) int32 {
if __ccgo_strace {
trc("t=%v olddirfd=%v oldpath=%v newdirfd=%v newpath=%v, (%v:)", t, olddirfd, oldpath, newdirfd, newpath, origin(2))
}
// From golang.org/x/sys/unix/syscall_linux_riscv64.go
return Xrenameat2(t, olddirfd, oldpath, newdirfd, newpath, 0)
}
// int mknod(const char *pathname, mode_t mode, dev_t dev);
func Xmknod(t *TLS, pathname uintptr, mode types.Mode_t, dev types.Dev_t) int32 {
if __ccgo_strace {
trc("t=%v pathname=%v mode=%v dev=%v, (%v:)", t, pathname, mode, dev, origin(2))
}
// From golang.org/x/sys/unix/syscall_linux.go
return Xmknodat(t, unix.AT_FDCWD, pathname, mode, dev)
}
// int chown(const char *pathname, uid_t owner, gid_t group);
func Xchown(t *TLS, pathname uintptr, owner types.Uid_t, group types.Gid_t) int32 {
if __ccgo_strace {
trc("t=%v pathname=%v owner=%v group=%v, (%v:)", t, pathname, owner, group, origin(2))
}
// From golang.org/x/sys/unix/syscall_linux.go
return Xfchownat(t, unix.AT_FDCWD, pathname, owner, group, 0)
}
// int link(const char *oldpath, const char *newpath);
func Xlink(t *TLS, oldpath, newpath uintptr) int32 {
if __ccgo_strace {
trc("t=%v newpath=%v, (%v:)", t, newpath, origin(2))
}
// From golang.org/x/sys/unix/syscall_linux.go
return Xlinkat(t, unix.AT_FDCWD, oldpath, unix.AT_FDCWD, newpath, 0)
}
// int pipe(int pipefd[2]);
func Xpipe(t *TLS, pipefd uintptr) int32 {
if __ccgo_strace {
trc("t=%v pipefd=%v, (%v:)", t, pipefd, origin(2))
}
// From golang.org/x/sys/unix/syscall_linux.go
return Xpipe2(t, pipefd, 0)
}
// int dup2(int oldfd, int newfd);
func Xdup2(t *TLS, oldfd, newfd int32) int32 {
if __ccgo_strace {
trc("t=%v newfd=%v, (%v:)", t, newfd, origin(2))
}
// From golang.org/x/sys/unix/syscall_linux.go
return Xdup3(t, oldfd, newfd, 0)
}
// ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsize);
func Xreadlink(t *TLS, path, buf uintptr, bufsize types.Size_t) types.Ssize_t {
if __ccgo_strace {
trc("t=%v buf=%v bufsize=%v, (%v:)", t, buf, bufsize, origin(2))
}
// From golang.org/x/sys/unix/syscall_linux.go
return Xreadlinkat(t, unix.AT_FDCWD, path, buf, bufsize)
}
// FILE *fopen64(const char *pathname, const char *mode);
func Xfopen64(t *TLS, pathname, mode uintptr) uintptr {
if __ccgo_strace {
trc("t=%v mode=%v, (%v:)", t, mode, origin(2))
}
m := strings.ReplaceAll(GoString(mode), "b", "")
var flags int
switch m {
case "r":
flags = os.O_RDONLY
case "r+":
flags = os.O_RDWR
case "w":
flags = os.O_WRONLY | os.O_CREATE | os.O_TRUNC
case "w+":
flags = os.O_RDWR | os.O_CREATE | os.O_TRUNC
case "a":
flags = os.O_WRONLY | os.O_CREATE | os.O_APPEND
case "a+":
flags = os.O_RDWR | os.O_CREATE | os.O_APPEND
default:
panic(m)
}
//TODO- flags |= fcntl.O_LARGEFILE
// From golang.org/x/sys/unix/syscall_linux.go
fd := Xopenat(t, unix.AT_FDCWD, pathname, int32(flags|unix.O_LARGEFILE), 0666)
if fd == -1 {
return 0
}
if p := newFile(t, fd); p != 0 {
return p
}
Xclose(t, fd)
t.setErrno(errno.ENOMEM)
return 0
}
// int iswspace(wint_t wc);
func Xiswspace(t *TLS, wc wctype.Wint_t) int32 {
if __ccgo_strace {
trc("t=%v wc=%v, (%v:)", t, wc, origin(2))
}
return Bool32(unicode.IsSpace(rune(wc)))
}
// int iswalnum(wint_t wc);
func Xiswalnum(t *TLS, wc wctype.Wint_t) int32 {
if __ccgo_strace {
trc("t=%v wc=%v, (%v:)", t, wc, origin(2))
}
return Bool32(unicode.IsLetter(rune(wc)) || unicode.IsNumber(rune(wc)))
}
func __syscall1(t *TLS, trap, p1 long) long {
return __syscall(unix.Syscall(uintptr(trap), uintptr(p1), 0, 0))
}
func __syscall3(t *TLS, trap, p1, p2, p3 long) long {
return __syscall(unix.Syscall(uintptr(trap), uintptr(p1), uintptr(p2), uintptr(p3)))
}
func __syscall4(t *TLS, trap, p1, p2, p3, p4 long) long {
return __syscall(unix.Syscall6(uintptr(trap), uintptr(p1), uintptr(p2), uintptr(p3), uintptr(p4), 0, 0))
}
// int setrlimit(int resource, const struct rlimit *rlim);
func Xsetrlimit64(t *TLS, resource int32, rlim uintptr) int32 {
if __ccgo_strace {
trc("t=%v resource=%v rlim=%v, (%v:)", t, resource, rlim, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_SETRLIMIT, uintptr(resource), uintptr(rlim), 0); err != 0 {
t.setErrno(err)
return -1
}
return 0
}
func AtomicLoadNUint8(ptr uintptr, memorder int32) uint8 {
return byte(a_load_8(ptr))
}
var _table1 = [384]int32{
129: int32(1),
130: int32(2),
131: int32(3),
132: int32(4),
133: int32(5),
134: int32(6),
135: int32(7),
136: int32(8),
137: int32(9),
138: int32(10),
139: int32(11),
140: int32(12),
141: int32(13),
142: int32(14),
143: int32(15),
144: int32(16),
145: int32(17),
146: int32(18),
147: int32(19),
148: int32(20),
149: int32(21),
150: int32(22),
151: int32(23),
152: int32(24),
153: int32(25),
154: int32(26),
155: int32(27),
156: int32(28),
157: int32(29),
158: int32(30),
159: int32(31),
160: int32(32),
161: int32(33),
162: int32(34),
163: int32(35),
164: int32(36),
165: int32(37),
166: int32(38),
167: int32(39),
168: int32(40),
169: int32(41),
170: int32(42),
171: int32(43),
172: int32(44),
173: int32(45),
174: int32(46),
175: int32(47),
176: int32(48),
177: int32(49),
178: int32(50),
179: int32(51),
180: int32(52),
181: int32(53),
182: int32(54),
183: int32(55),
184: int32(56),
185: int32(57),
186: int32(58),
187: int32(59),
188: int32(60),
189: int32(61),
190: int32(62),
191: int32(63),
192: int32(64),
193: int32('a'),
194: int32('b'),
195: int32('c'),
196: int32('d'),
197: int32('e'),
198: int32('f'),
199: int32('g'),
200: int32('h'),
201: int32('i'),
202: int32('j'),
203: int32('k'),
204: int32('l'),
205: int32('m'),
206: int32('n'),
207: int32('o'),
208: int32('p'),
209: int32('q'),
210: int32('r'),
211: int32('s'),
212: int32('t'),
213: int32('u'),
214: int32('v'),
215: int32('w'),
216: int32('x'),
217: int32('y'),
218: int32('z'),
219: int32(91),
220: int32(92),
221: int32(93),
222: int32(94),
223: int32(95),
224: int32(96),
225: int32('a'),
226: int32('b'),
227: int32('c'),
228: int32('d'),
229: int32('e'),
230: int32('f'),
231: int32('g'),
232: int32('h'),
233: int32('i'),
234: int32('j'),
235: int32('k'),
236: int32('l'),
237: int32('m'),
238: int32('n'),
239: int32('o'),
240: int32('p'),
241: int32('q'),
242: int32('r'),
243: int32('s'),
244: int32('t'),
245: int32('u'),
246: int32('v'),
247: int32('w'),
248: int32('x'),
249: int32('y'),
250: int32('z'),
251: int32(123),
252: int32(124),
253: int32(125),
254: int32(126),
255: int32(127),
}
var _ptable1 = uintptr(unsafe.Pointer(&_table1)) + uintptr(128)*4
func X__ctype_tolower_loc(tls *TLS) (r uintptr) {
if __ccgo_strace {
trc("tls=%v, (%v:)", tls, origin(2))
defer func() { trc("-> %v", r) }()
}
return uintptr(unsafe.Pointer(&_ptable1))
}
type Tin6_addr = struct {
F__in6_union struct {
F__s6_addr16 [0][8]uint16
F__s6_addr32 [0][4]uint32
F__s6_addr [16]uint8
}
}
var Xin6addr_any = Tin6_addr{}
func Xrewinddir(tls *TLS, f uintptr) {
if __ccgo_strace {
trc("tls=%v f=%v, (%v:)", tls, f, origin(2))
}
Xfseek(tls, f, 0, stdio.SEEK_SET)
}
// clock_t clock(void);
func Xclock(t *TLS) time.Clock_t {
if __ccgo_strace {
trc("t=%v, (%v:)", t, origin(2))
}
return time.Clock_t(gotime.Since(startTime) * gotime.Duration(time.CLOCKS_PER_SEC) / gotime.Second)
}
const __NFDBITS = 64
func X__fdelt_chk(tls *TLS, d int64) (r int64) {
if __ccgo_strace {
trc("tls=%v d=%v, (%v:)", tls, d, origin(2))
defer func() { trc("-> %v", r) }()
}
return d / __NFDBITS
}

View file

@ -1,742 +0,0 @@
// Copyright 2021 The Libc Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package libc // import "modernc.org/libc"
import (
"os"
"strings"
gotime "time"
"unsafe"
"golang.org/x/sys/unix"
"modernc.org/libc/errno"
"modernc.org/libc/fcntl"
"modernc.org/libc/signal"
"modernc.org/libc/stdio"
"modernc.org/libc/sys/types"
"modernc.org/libc/time"
)
var (
startTime = gotime.Now() // For clock(3)
)
// int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
func Xsigaction(t *TLS, signum int32, act, oldact uintptr) int32 {
if __ccgo_strace {
trc("t=%v signum=%v oldact=%v, (%v:)", t, signum, oldact, origin(2))
}
// musl/src/internal/ksigaction.h
// struct k_sigaction {
// void (*handler)(int);
// unsigned long flags;
// void (*restorer)(void);
// unsigned mask[2];
// };
type k_sigaction struct {
handler uintptr
flags ulong
restorer uintptr
mask [2]uint32
}
var kact, koldact uintptr
if act != 0 {
sz := int(unsafe.Sizeof(k_sigaction{}))
kact = t.Alloc(sz)
defer t.Free(sz)
*(*k_sigaction)(unsafe.Pointer(kact)) = k_sigaction{
handler: (*signal.Sigaction)(unsafe.Pointer(act)).F__sigaction_handler.Fsa_handler,
flags: ulong((*signal.Sigaction)(unsafe.Pointer(act)).Fsa_flags),
restorer: (*signal.Sigaction)(unsafe.Pointer(act)).Fsa_restorer,
}
Xmemcpy(t, kact+unsafe.Offsetof(k_sigaction{}.mask), act+unsafe.Offsetof(signal.Sigaction{}.Fsa_mask), types.Size_t(unsafe.Sizeof(k_sigaction{}.mask)))
}
if oldact != 0 {
panic(todo(""))
}
if _, _, err := unix.Syscall6(unix.SYS_RT_SIGACTION, uintptr(signum), kact, koldact, unsafe.Sizeof(k_sigaction{}.mask), 0, 0); err != 0 {
t.setErrno(err)
return -1
}
if oldact != 0 {
panic(todo(""))
}
return 0
}
// int fcntl(int fd, int cmd, ... /* arg */ );
func Xfcntl64(t *TLS, fd, cmd int32, args uintptr) int32 {
if __ccgo_strace {
trc("t=%v cmd=%v args=%v, (%v:)", t, cmd, args, origin(2))
}
var arg uintptr
if args != 0 {
arg = *(*uintptr)(unsafe.Pointer(args))
}
if cmd == fcntl.F_SETFL {
arg |= unix.O_LARGEFILE
}
n, _, err := unix.Syscall(unix.SYS_FCNTL, uintptr(fd), uintptr(cmd), arg)
if err != 0 {
// if dmesgs {
// dmesg("%v: fd %v cmd %v", origin(1), fcntlCmdStr(fd), cmd)
// }
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %d %s %#x: %d", origin(1), fd, fcntlCmdStr(cmd), arg, n)
// }
return int32(n)
}
// int lstat(const char *pathname, struct stat *statbuf);
func Xlstat64(t *TLS, pathname, statbuf uintptr) int32 {
if __ccgo_strace {
trc("t=%v statbuf=%v, (%v:)", t, statbuf, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_LSTAT, pathname, statbuf, 0); err != 0 {
// if dmesgs {
// dmesg("%v: %q: %v", origin(1), GoString(pathname), err)
// }
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %q: ok", origin(1), GoString(pathname))
// }
return 0
}
// int stat(const char *pathname, struct stat *statbuf);
func Xstat64(t *TLS, pathname, statbuf uintptr) int32 {
if __ccgo_strace {
trc("t=%v statbuf=%v, (%v:)", t, statbuf, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_STAT, pathname, statbuf, 0); err != 0 {
// if dmesgs {
// dmesg("%v: %q: %v", origin(1), GoString(pathname), err)
// }
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %q: ok", origin(1), GoString(pathname))
// }
return 0
}
// int fstat(int fd, struct stat *statbuf);
func Xfstat64(t *TLS, fd int32, statbuf uintptr) int32 {
if __ccgo_strace {
trc("t=%v fd=%v statbuf=%v, (%v:)", t, fd, statbuf, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_FSTAT, uintptr(fd), statbuf, 0); err != 0 {
// if dmesgs {
// dmesg("%v: fd %d: %v", origin(1), fd, err)
// }
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %d size %#x: ok\n%+v", origin(1), fd, (*stat.Stat)(unsafe.Pointer(statbuf)).Fst_size, (*stat.Stat)(unsafe.Pointer(statbuf)))
// }
return 0
}
func Xmmap(t *TLS, addr uintptr, length types.Size_t, prot, flags, fd int32, offset types.Off_t) uintptr {
if __ccgo_strace {
trc("t=%v addr=%v length=%v fd=%v offset=%v, (%v:)", t, addr, length, fd, offset, origin(2))
}
return Xmmap64(t, addr, length, prot, flags, fd, offset)
}
// void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);
func Xmmap64(t *TLS, addr uintptr, length types.Size_t, prot, flags, fd int32, offset types.Off_t) uintptr {
if __ccgo_strace {
trc("t=%v addr=%v length=%v fd=%v offset=%v, (%v:)", t, addr, length, fd, offset, origin(2))
}
// https://github.com/golang/go/blob/7d822af4500831d131562f17dcf53374469d823e/src/syscall/syscall_linux_s390x.go#L77
args := [6]uintptr{addr, uintptr(length), uintptr(prot), uintptr(flags), uintptr(fd), uintptr(offset)}
data, _, err := unix.Syscall(unix.SYS_MMAP, uintptr(unsafe.Pointer(&args[0])), 0, 0)
if err != 0 {
// if dmesgs {
// dmesg("%v: addr %#x, length %#x, prot %#x, flags %#x, fd %v, offset %#x: %v", origin(1), addr, length, prot, flags, fd, offset, err)
// }
t.setErrno(err)
return ^uintptr(0) // (void*)-1
}
// if dmesgs {
// dmesg("%v: addr %#x, length %#x, prot %#x, flags %#x, fd %v, offset %#x: ok", origin(1), addr, length, prot, flags, fd, offset)
// }
return data
}
// void *mremap(void *old_address, size_t old_size, size_t new_size, int flags, ... /* void *new_address */);
func Xmremap(t *TLS, old_address uintptr, old_size, new_size types.Size_t, flags int32, args uintptr) uintptr {
if __ccgo_strace {
trc("t=%v old_address=%v new_size=%v flags=%v args=%v, (%v:)", t, old_address, new_size, flags, args, origin(2))
}
var arg uintptr
if args != 0 {
arg = *(*uintptr)(unsafe.Pointer(args))
}
data, _, err := unix.Syscall6(unix.SYS_MREMAP, old_address, uintptr(old_size), uintptr(new_size), uintptr(flags), arg, 0)
if err != 0 {
// if dmesgs {
// dmesg("%v: %v", origin(1), err)
// }
t.setErrno(err)
return ^uintptr(0) // (void*)-1
}
// if dmesgs {
// dmesg("%v: %#x", origin(1), data)
// }
return data
}
// int ftruncate(int fd, off_t length);
func Xftruncate64(t *TLS, fd int32, length types.Off_t) int32 {
if __ccgo_strace {
trc("t=%v fd=%v length=%v, (%v:)", t, fd, length, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_FTRUNCATE, uintptr(fd), uintptr(length), 0); err != 0 {
// if dmesgs {
// dmesg("%v: fd %d: %v", origin(1), fd, err)
// }
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %d %#x: ok", origin(1), fd, length)
// }
return 0
}
// off64_t lseek64(int fd, off64_t offset, int whence);
func Xlseek64(t *TLS, fd int32, offset types.Off_t, whence int32) types.Off_t {
if __ccgo_strace {
trc("t=%v fd=%v offset=%v whence=%v, (%v:)", t, fd, offset, whence, origin(2))
}
n, _, err := unix.Syscall(unix.SYS_LSEEK, uintptr(fd), uintptr(offset), uintptr(whence))
if err != 0 {
// if dmesgs {
// dmesg("%v: fd %v, off %#x, whence %v: %v", origin(1), fd, offset, whenceStr(whence), err)
// }
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: fd %v, off %#x, whence %v: %#x", origin(1), fd, offset, whenceStr(whence), n)
// }
return types.Off_t(n)
}
// int utime(const char *filename, const struct utimbuf *times);
func Xutime(t *TLS, filename, times uintptr) int32 {
if __ccgo_strace {
trc("t=%v times=%v, (%v:)", t, times, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_UTIME, filename, times, 0); err != 0 {
t.setErrno(err)
return -1
}
return 0
}
// unsigned int alarm(unsigned int seconds);
func Xalarm(t *TLS, seconds uint32) uint32 {
if __ccgo_strace {
trc("t=%v seconds=%v, (%v:)", t, seconds, origin(2))
}
n, _, err := unix.Syscall(unix.SYS_ALARM, uintptr(seconds), 0, 0)
if err != 0 {
panic(todo(""))
}
return uint32(n)
}
// time_t time(time_t *tloc);
func Xtime(t *TLS, tloc uintptr) types.Time_t {
if __ccgo_strace {
trc("t=%v tloc=%v, (%v:)", t, tloc, origin(2))
}
n, err := unix.Time((*unix.Time_t)(unsafe.Pointer(tloc)))
if err != nil {
t.setErrno(err)
return types.Time_t(-1)
}
return types.Time_t(n)
}
// int getrlimit(int resource, struct rlimit *rlim);
func Xgetrlimit64(t *TLS, resource int32, rlim uintptr) int32 {
if __ccgo_strace {
trc("t=%v resource=%v rlim=%v, (%v:)", t, resource, rlim, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_GETRLIMIT, uintptr(resource), uintptr(rlim), 0); err != 0 {
t.setErrno(err)
return -1
}
return 0
}
// int mkdir(const char *path, mode_t mode);
func Xmkdir(t *TLS, path uintptr, mode types.Mode_t) int32 {
if __ccgo_strace {
trc("t=%v path=%v mode=%v, (%v:)", t, path, mode, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_MKDIR, path, uintptr(mode), 0); err != 0 {
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %q: ok", origin(1), GoString(path))
// }
return 0
}
// int symlink(const char *target, const char *linkpath);
func Xsymlink(t *TLS, target, linkpath uintptr) int32 {
if __ccgo_strace {
trc("t=%v linkpath=%v, (%v:)", t, linkpath, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_SYMLINK, target, linkpath, 0); err != 0 {
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %q %q: ok", origin(1), GoString(target), GoString(linkpath))
// }
return 0
}
// int chmod(const char *pathname, mode_t mode)
func Xchmod(t *TLS, pathname uintptr, mode types.Mode_t) int32 {
if __ccgo_strace {
trc("t=%v pathname=%v mode=%v, (%v:)", t, pathname, mode, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_CHMOD, pathname, uintptr(mode), 0); err != 0 {
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %q %#o: ok", origin(1), GoString(pathname), mode)
// }
return 0
}
// int utimes(const char *filename, const struct timeval times[2]);
func Xutimes(t *TLS, filename, times uintptr) int32 {
if __ccgo_strace {
trc("t=%v times=%v, (%v:)", t, times, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_UTIMES, filename, times, 0); err != 0 {
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %q: ok", origin(1), GoString(filename))
// }
return 0
}
// int unlink(const char *pathname);
func Xunlink(t *TLS, pathname uintptr) int32 {
if __ccgo_strace {
trc("t=%v pathname=%v, (%v:)", t, pathname, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_UNLINK, pathname, 0, 0); err != 0 {
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %q: ok", origin(1), GoString(pathname))
// }
return 0
}
// int access(const char *pathname, int mode);
func Xaccess(t *TLS, pathname uintptr, mode int32) int32 {
if __ccgo_strace {
trc("t=%v pathname=%v mode=%v, (%v:)", t, pathname, mode, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_ACCESS, pathname, uintptr(mode), 0); err != 0 {
// if dmesgs {
// dmesg("%v: %q: %v", origin(1), GoString(pathname), err)
// }
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %q %#o: ok", origin(1), GoString(pathname), mode)
// }
return 0
}
// int rmdir(const char *pathname);
func Xrmdir(t *TLS, pathname uintptr) int32 {
if __ccgo_strace {
trc("t=%v pathname=%v, (%v:)", t, pathname, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_RMDIR, pathname, 0, 0); err != 0 {
t.setErrno(err)
return -1
}
// if dmesgs {
// dmesg("%v: %q: ok", origin(1), GoString(pathname))
// }
return 0
}
// int rename(const char *oldpath, const char *newpath);
func Xrename(t *TLS, oldpath, newpath uintptr) int32 {
if __ccgo_strace {
trc("t=%v newpath=%v, (%v:)", t, newpath, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_RENAME, oldpath, newpath, 0); err != 0 {
t.setErrno(err)
return -1
}
return 0
}
// int mknod(const char *pathname, mode_t mode, dev_t dev);
func Xmknod(t *TLS, pathname uintptr, mode types.Mode_t, dev types.Dev_t) int32 {
if __ccgo_strace {
trc("t=%v pathname=%v mode=%v dev=%v, (%v:)", t, pathname, mode, dev, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_MKNOD, pathname, uintptr(mode), uintptr(dev)); err != 0 {
t.setErrno(err)
return -1
}
return 0
}
// int chown(const char *pathname, uid_t owner, gid_t group);
func Xchown(t *TLS, pathname uintptr, owner types.Uid_t, group types.Gid_t) int32 {
if __ccgo_strace {
trc("t=%v pathname=%v owner=%v group=%v, (%v:)", t, pathname, owner, group, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_CHOWN, pathname, uintptr(owner), uintptr(group)); err != 0 {
t.setErrno(err)
return -1
}
return 0
}
// int link(const char *oldpath, const char *newpath);
func Xlink(t *TLS, oldpath, newpath uintptr) int32 {
if __ccgo_strace {
trc("t=%v newpath=%v, (%v:)", t, newpath, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_LINK, oldpath, newpath, 0); err != 0 {
t.setErrno(err)
return -1
}
return 0
}
// int pipe(int pipefd[2]);
func Xpipe(t *TLS, pipefd uintptr) int32 {
if __ccgo_strace {
trc("t=%v pipefd=%v, (%v:)", t, pipefd, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_PIPE, pipefd, 0, 0); err != 0 {
t.setErrno(err)
return -1
}
return 0
}
// int dup2(int oldfd, int newfd);
func Xdup2(t *TLS, oldfd, newfd int32) int32 {
if __ccgo_strace {
trc("t=%v newfd=%v, (%v:)", t, newfd, origin(2))
}
n, _, err := unix.Syscall(unix.SYS_DUP2, uintptr(oldfd), uintptr(newfd), 0)
if err != 0 {
t.setErrno(err)
return -1
}
return int32(n)
}
// ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsize);
func Xreadlink(t *TLS, path, buf uintptr, bufsize types.Size_t) types.Ssize_t {
if __ccgo_strace {
trc("t=%v buf=%v bufsize=%v, (%v:)", t, buf, bufsize, origin(2))
}
n, _, err := unix.Syscall(unix.SYS_READLINK, path, buf, uintptr(bufsize))
if err != 0 {
t.setErrno(err)
return -1
}
return types.Ssize_t(n)
}
// FILE *fopen64(const char *pathname, const char *mode);
func Xfopen64(t *TLS, pathname, mode uintptr) uintptr {
if __ccgo_strace {
trc("t=%v mode=%v, (%v:)", t, mode, origin(2))
}
m := strings.ReplaceAll(GoString(mode), "b", "")
var flags int
switch m {
case "r":
flags = os.O_RDONLY
case "r+":
flags = os.O_RDWR
case "w":
flags = os.O_WRONLY | os.O_CREATE | os.O_TRUNC
case "w+":
flags = os.O_RDWR | os.O_CREATE | os.O_TRUNC
case "a":
flags = os.O_WRONLY | os.O_CREATE | os.O_APPEND
case "a+":
flags = os.O_RDWR | os.O_CREATE | os.O_APPEND
default:
panic(m)
}
//TODO- flags |= fcntl.O_LARGEFILE
fd, _, err := unix.Syscall(unix.SYS_OPEN, pathname, uintptr(flags|unix.O_LARGEFILE), 0666)
if err != 0 {
t.setErrno(err)
return 0
}
if p := newFile(t, int32(fd)); p != 0 {
return p
}
Xclose(t, int32(fd))
t.setErrno(errno.ENOMEM)
return 0
}
// TODO-
func __syscall1(t *TLS, trap, p1 long) long {
return __syscall(unix.Syscall(uintptr(trap), uintptr(p1), 0, 0))
}
func __syscall3(t *TLS, trap, p1, p2, p3 long) long {
return __syscall(unix.Syscall(uintptr(trap), uintptr(p1), uintptr(p2), uintptr(p3)))
}
func __syscall4(t *TLS, trap, p1, p2, p3, p4 long) long {
return __syscall(unix.Syscall6(uintptr(trap), uintptr(p1), uintptr(p2), uintptr(p3), uintptr(p4), 0, 0))
}
// int setrlimit(int resource, const struct rlimit *rlim);
func Xsetrlimit64(t *TLS, resource int32, rlim uintptr) int32 {
if __ccgo_strace {
trc("t=%v resource=%v rlim=%v, (%v:)", t, resource, rlim, origin(2))
}
if _, _, err := unix.Syscall(unix.SYS_SETRLIMIT, uintptr(resource), uintptr(rlim), 0); err != 0 {
t.setErrno(err)
return -1
}
return 0
}
func AtomicLoadNUint8(ptr uintptr, memorder int32) uint8 {
return byte(a_load_8(ptr))
}
var _table1 = [384]int32{
129: int32(1),
130: int32(2),
131: int32(3),
132: int32(4),
133: int32(5),
134: int32(6),
135: int32(7),
136: int32(8),
137: int32(9),
138: int32(10),
139: int32(11),
140: int32(12),
141: int32(13),
142: int32(14),
143: int32(15),
144: int32(16),
145: int32(17),
146: int32(18),
147: int32(19),
148: int32(20),
149: int32(21),
150: int32(22),
151: int32(23),
152: int32(24),
153: int32(25),
154: int32(26),
155: int32(27),
156: int32(28),
157: int32(29),
158: int32(30),
159: int32(31),
160: int32(32),
161: int32(33),
162: int32(34),
163: int32(35),
164: int32(36),
165: int32(37),
166: int32(38),
167: int32(39),
168: int32(40),
169: int32(41),
170: int32(42),
171: int32(43),
172: int32(44),
173: int32(45),
174: int32(46),
175: int32(47),
176: int32(48),
177: int32(49),
178: int32(50),
179: int32(51),
180: int32(52),
181: int32(53),
182: int32(54),
183: int32(55),
184: int32(56),
185: int32(57),
186: int32(58),
187: int32(59),
188: int32(60),
189: int32(61),
190: int32(62),
191: int32(63),
192: int32(64),
193: int32('a'),
194: int32('b'),
195: int32('c'),
196: int32('d'),
197: int32('e'),
198: int32('f'),
199: int32('g'),
200: int32('h'),
201: int32('i'),
202: int32('j'),
203: int32('k'),
204: int32('l'),
205: int32('m'),
206: int32('n'),
207: int32('o'),
208: int32('p'),
209: int32('q'),
210: int32('r'),
211: int32('s'),
212: int32('t'),
213: int32('u'),
214: int32('v'),
215: int32('w'),
216: int32('x'),
217: int32('y'),
218: int32('z'),
219: int32(91),
220: int32(92),
221: int32(93),
222: int32(94),
223: int32(95),
224: int32(96),
225: int32('a'),
226: int32('b'),
227: int32('c'),
228: int32('d'),
229: int32('e'),
230: int32('f'),
231: int32('g'),
232: int32('h'),
233: int32('i'),
234: int32('j'),
235: int32('k'),
236: int32('l'),
237: int32('m'),
238: int32('n'),
239: int32('o'),
240: int32('p'),
241: int32('q'),
242: int32('r'),
243: int32('s'),
244: int32('t'),
245: int32('u'),
246: int32('v'),
247: int32('w'),
248: int32('x'),
249: int32('y'),
250: int32('z'),
251: int32(123),
252: int32(124),
253: int32(125),
254: int32(126),
255: int32(127),
}
var _ptable1 = uintptr(unsafe.Pointer(&_table1)) + uintptr(128)*4
func X__ctype_tolower_loc(tls *TLS) (r uintptr) {
if __ccgo_strace {
trc("tls=%v, (%v:)", tls, origin(2))
defer func() { trc("-> %v", r) }()
}
return uintptr(unsafe.Pointer(&_ptable1))
}
type Tin6_addr = struct {
F__in6_union struct {
F__s6_addr16 [0][8]uint16
F__s6_addr32 [0][4]uint32
F__s6_addr [16]uint8
}
}
var Xin6addr_any = Tin6_addr{}
func Xrewinddir(tls *TLS, f uintptr) {
if __ccgo_strace {
trc("tls=%v f=%v, (%v:)", tls, f, origin(2))
}
Xfseek(tls, f, 0, stdio.SEEK_SET)
}
// clock_t clock(void);
func Xclock(t *TLS) time.Clock_t {
if __ccgo_strace {
trc("t=%v, (%v:)", t, origin(2))
}
return time.Clock_t(gotime.Since(startTime) * gotime.Duration(time.CLOCKS_PER_SEC) / gotime.Second)
}

View file

@ -1,40 +0,0 @@
// Copyright 2023 The Libc Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !(linux && loong64)
package libc // import "modernc.org/libc"
import (
"fmt"
"unsafe"
)
// Byte loads are atomic on this CPU.
func a_load_8(addr uintptr) uint32 {
return uint32(*(*byte)(unsafe.Pointer(addr)))
}
// int16 loads are atomic on this CPU when properly aligned.
func a_load_16(addr uintptr) uint32 {
if addr&1 != 0 {
panic(fmt.Errorf("unaligned atomic 16 bit access at %#0x", addr))
}
return uint32(*(*uint16)(unsafe.Pointer(addr)))
}
// Byte sores are atomic on this CPU.
func a_store_8(addr uintptr, b byte) {
*(*byte)(unsafe.Pointer(addr)) = b
}
// int16 stores are atomic on this CPU when properly aligned.
func a_store_16(addr uintptr, n uint16) {
if addr&1 != 0 {
panic(fmt.Errorf("unaligned atomic 16 bit access at %#0x", addr))
}
*(*uint16)(unsafe.Pointer(addr)) = n
}

71
vendor/modernc.org/libc/libc_musl.go generated vendored
View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build linux && (amd64 || arm64 || loong64) //go:build linux && (amd64 || arm64 || loong64 || ppc64le || s390x || riscv64 || 386 || arm)
//go:generate go run generator.go //go:generate go run generator.go
@ -119,7 +119,7 @@ import (
"strings" "strings"
"sync" "sync"
"sync/atomic" "sync/atomic"
"syscall" "time"
"unsafe" "unsafe"
guuid "github.com/google/uuid" guuid "github.com/google/uuid"
@ -157,6 +157,7 @@ func init() {
Xprogram_invocation_name = mustCString(nm) Xprogram_invocation_name = mustCString(nm)
Xprogram_invocation_short_name = mustCString(filepath.Base(nm)) Xprogram_invocation_short_name = mustCString(filepath.Base(nm))
X__libc.Fpage_size = Tsize_t(os.Getpagesize())
} }
// RawMem64 represents the biggest uint64 array the runtime can handle. // RawMem64 represents the biggest uint64 array the runtime can handle.
@ -414,7 +415,7 @@ func (tls *TLS) Free(n int) {
select { select {
case sig := <-tls.pendingSignals: case sig := <-tls.pendingSignals:
signum := int32(sig.(syscall.Signal)) signum := int32(sig.(unix.Signal))
h, ok := tls.sigHandlers[signum] h, ok := tls.sigHandlers[signum]
if !ok { if !ok {
break break
@ -517,7 +518,7 @@ var abort Tsigaction
func Xabort(tls *TLS) { func Xabort(tls *TLS) {
X__libc_sigaction(tls, SIGABRT, uintptr(unsafe.Pointer(&abort)), 0) X__libc_sigaction(tls, SIGABRT, uintptr(unsafe.Pointer(&abort)), 0)
unix.Kill(unix.Getpid(), syscall.Signal(SIGABRT)) unix.Kill(unix.Getpid(), unix.Signal(SIGABRT))
panic(todo("unrechable")) panic(todo("unrechable"))
} }
@ -639,16 +640,56 @@ func ___synccall(tls *TLS, fn, ctx uintptr) {
(*(*func(*TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{fn})))(tls, ctx) (*(*func(*TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{fn})))(tls, ctx)
} }
// func ___randname(tls *TLS, template uintptr) (r1 uintptr) {
// bp := tls.Alloc(16)
// defer tls.Free(16)
// var i int32
// var r uint64
// var _ /* ts at bp+0 */ Ttimespec
// X__clock_gettime(tls, CLOCK_REALTIME, bp)
// goto _2
// _2:
// r = uint64((*(*Ttimespec)(unsafe.Pointer(bp))).Ftv_sec+(*(*Ttimespec)(unsafe.Pointer(bp))).Ftv_nsec) + uint64(tls.ID)*uint64(65537)
// i = 0
// for {
// if !(i < int32(6)) {
// break
// }
// *(*int8)(unsafe.Pointer(template + uintptr(i))) = int8(uint64('A') + r&uint64(15) + r&uint64(16)*uint64(2))
// goto _3
// _3:
// i++
// r >>= uint64(5)
// }
// return template
// }
// #include <time.h>
// #include <stdint.h>
// #include "pthread_impl.h"
//
// /* This assumes that a check for the
//
// template size has already been made */
//
// char *__randname(char *template)
//
// {
// int i;
// struct timespec ts;
// unsigned long r;
//
// __clock_gettime(CLOCK_REALTIME, &ts);
// r = ts.tv_sec + ts.tv_nsec + __pthread_self()->tid * 65537UL;
// for (i=0; i<6; i++, r>>=5)
// template[i] = 'A'+(r&15)+(r&16)*2;
//
// return template;
// }
func ___randname(tls *TLS, template uintptr) (r1 uintptr) { func ___randname(tls *TLS, template uintptr) (r1 uintptr) {
bp := tls.Alloc(16)
defer tls.Free(16)
var i int32 var i int32
var r uint64 ts := time.Now().UnixNano()
var _ /* ts at bp+0 */ Ttimespec r := uint64(ts) + uint64(tls.ID)*65537
X__clock_gettime(tls, CLOCK_REALTIME, bp)
goto _2
_2:
r = uint64((*(*Ttimespec)(unsafe.Pointer(bp))).Ftv_sec+(*(*Ttimespec)(unsafe.Pointer(bp))).Ftv_nsec) + uint64(tls.ID)*uint64(65537)
i = 0 i = 0
for { for {
if !(i < int32(6)) { if !(i < int32(6)) {
@ -682,15 +723,15 @@ func Xsignal(tls *TLS, signum int32, handler uintptr) (r uintptr) {
r, tls.sigHandlers[signum] = tls.sigHandlers[signum], handler r, tls.sigHandlers[signum] = tls.sigHandlers[signum], handler
switch handler { switch handler {
case SIG_DFL: case SIG_DFL:
gosignal.Reset(syscall.Signal(signum)) gosignal.Reset(unix.Signal(signum))
case SIG_IGN: case SIG_IGN:
gosignal.Ignore(syscall.Signal(signum)) gosignal.Ignore(unix.Signal(signum))
default: default:
if tls.pendingSignals == nil { if tls.pendingSignals == nil {
tls.pendingSignals = make(chan os.Signal, 3) tls.pendingSignals = make(chan os.Signal, 3)
tls.checkSignals = true tls.checkSignals = true
} }
gosignal.Notify(tls.pendingSignals, syscall.Signal(signum)) gosignal.Notify(tls.pendingSignals, unix.Signal(signum))
} }
return r return r
} }

52
vendor/modernc.org/libc/libc_musl_linux_386.go generated vendored Normal file
View file

@ -0,0 +1,52 @@
// Copyright 2023 The Libc Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package libc // import "modernc.org/libc"
import (
"math/bits"
"sync/atomic"
"unsafe"
)
type long = int32
type ulong = uint32
// RawMem represents the biggest byte array the runtime can handle
type RawMem [1<<31 - 1]byte
func a_crash()
func _a_crash(tls *TLS) {
a_crash()
}
func a_cas(p uintptr, t, s int32) int32
func _a_cas(tls *TLS, p uintptr, test, s int32) int32 {
return a_cas(p, test, s)
}
func _a_store(tls *TLS, p uintptr, v int32) {
atomic.StoreInt32((*int32)(unsafe.Pointer(p)), v)
}
func _a_clz_32(tls *TLS, x uint32) int32 {
return int32(bits.LeadingZeros32(x))
}
func _a_ctz_32(tls *TLS, x uint32) int32 {
return X__builtin_ctz(tls, x)
}
func a_or(p uintptr, v int32)
func _a_or(tls *TLS, p uintptr, v int32) {
a_or(p, v)
}
func _a_swap(tls *TLS, p uintptr, v int32) int32 {
return atomic.SwapInt32((*int32)(unsafe.Pointer(p)), v)
}

70
vendor/modernc.org/libc/libc_musl_linux_arm.go generated vendored Normal file
View file

@ -0,0 +1,70 @@
// Copyright 2023 The Libc Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package libc // import "modernc.org/libc"
import (
"math/bits"
"sync/atomic"
"unsafe"
)
type long = int32
type ulong = uint32
var (
___a_barrier_ptr ulong
)
// RawMem represents the biggest byte array the runtime can handle
type RawMem [1<<31 - 1]byte
// void *memcpy(void *dest, const void *src, size_t n);
func Xmemcpy(t *TLS, dest, src uintptr, n Tsize_t) (r uintptr) {
if __ccgo_strace {
trc("t=%v src=%v n=%v, (%v:)", t, src, n, origin(2))
defer func() { trc("-> %v", r) }()
}
return _memcpy(t, dest, src, n)
}
func _memcpy(t *TLS, dest, src uintptr, n Tsize_t) (r uintptr) {
if n != 0 {
copy((*RawMem)(unsafe.Pointer(dest))[:n:n], (*RawMem)(unsafe.Pointer(src))[:n:n])
}
return dest
}
func _fetestexcept(t *TLS, _ int32) int32 {
return 0
}
func _feclearexcept(t *TLS, _ int32) int32 {
return 0
}
func _a_crash(tls *TLS) {
panic("crash")
}
var atomicBarrier atomic.Int32
func _a_barrier(tls *TLS) {
atomicBarrier.Add(1)
}
// static inline int a_sc(volatile int *p, int v)
func _a_sc(*TLS, uintptr, int32) int32 {
panic(todo(""))
}
// static inline int a_ll(volatile int *p)
func _a_ll(tls *TLS, p uintptr) int32 {
return atomic.LoadInt32((*int32)(unsafe.Pointer(p)))
}
func _a_clz_32(tls *TLS, x uint32) int32 {
return int32(bits.LeadingZeros32(x))
}

12
vendor/modernc.org/libc/libc_musl_linux_ppc64le.go generated vendored Normal file
View file

@ -0,0 +1,12 @@
// Copyright 2023 The Libc Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package libc // import "modernc.org/libc"
type long = int64
type ulong = uint64
// RawMem represents the biggest byte array the runtime can handle
type RawMem [1<<50 - 1]byte

12
vendor/modernc.org/libc/libc_musl_linux_riscv64.go generated vendored Normal file
View file

@ -0,0 +1,12 @@
// Copyright 2023 The Libc Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package libc // import "modernc.org/libc"
type long = int64
type ulong = uint64
// RawMem represents the biggest byte array the runtime can handle
type RawMem [1<<50 - 1]byte

50
vendor/modernc.org/libc/libc_musl_linux_s390x.go generated vendored Normal file
View file

@ -0,0 +1,50 @@
// Copyright 2023 The Libc Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package libc // import "modernc.org/libc"
import (
"unsafe"
"golang.org/x/sys/unix"
)
type long = int64
type ulong = uint64
// RawMem represents the biggest byte array the runtime can handle
type RawMem [1<<50 - 1]byte
func Xfesetround(tls *TLS, r int32) (r1 int32) {
if __ccgo_strace {
trc("tls=%v r=%v, (%v:)", tls, r, origin(2))
defer func() { trc("-> %v", r1) }()
}
return X__fesetround(tls, r)
}
func Xmmap(tls *TLS, start uintptr, len1 Tsize_t, prot int32, flags int32, fd int32, off Toff_t) (r uintptr) {
if __ccgo_strace {
trc("tls=%v start=%v len1=%v prot=%v flags=%v fd=%v off=%v, (%v:)", tls, start, len1, prot, flags, fd, off, origin(2))
defer func() { trc("-> %v", r) }()
}
return ___mmap(tls, start, len1, prot, flags, fd, off)
}
func ___mmap(tls *TLS, start uintptr, len1 Tsize_t, prot int32, flags int32, fd int32, off Toff_t) (r uintptr) {
if __ccgo_strace {
trc("tls=%v start=%v len1=%v prot=%v flags=%v fd=%v off=%v, (%v:)", tls, start, len1, prot, flags, fd, off, origin(2))
defer func() { trc("-> %v", r) }()
}
// https://github.com/golang/go/blob/7d822af4500831d131562f17dcf53374469d823e/src/syscall/syscall_linux_s390x.go#L77
args := [6]uintptr{start, uintptr(len1), uintptr(prot), uintptr(flags), uintptr(fd), uintptr(off)}
data, _, err := unix.Syscall(unix.SYS_MMAP, uintptr(unsafe.Pointer(&args[0])), 0, 0)
if err != 0 {
tls.setErrno(int32(err))
return ^uintptr(0) // (void*)-1
}
return data
}

View file

@ -13,7 +13,6 @@ import (
"runtime" "runtime"
"runtime/debug" "runtime/debug"
"strings" "strings"
"syscall"
gotime "time" gotime "time"
"unsafe" "unsafe"
@ -41,6 +40,8 @@ var (
in6_addr_any in.In6_addr in6_addr_any in.In6_addr
) )
type syscallErrno = unix.Errno
// // Keep these outside of the var block otherwise go generate will miss them. // // Keep these outside of the var block otherwise go generate will miss them.
var X__stderrp = Xstdout var X__stderrp = Xstdout
var X__stdinp = Xstdin var X__stdinp = Xstdin
@ -445,7 +446,7 @@ func Xwrite(t *TLS, fd int32, buf uintptr, count types.Size_t) types.Ssize_t {
trc("t=%v fd=%v buf=%v count=%v, (%v:)", t, fd, buf, count, origin(2)) trc("t=%v fd=%v buf=%v count=%v, (%v:)", t, fd, buf, count, origin(2))
} }
const retry = 5 const retry = 5
var err syscall.Errno var err syscallErrno
for i := 0; i < retry; i++ { for i := 0; i < retry; i++ {
var n uintptr var n uintptr
switch n, _, err = unix.Syscall(unix.SYS_WRITE, uintptr(fd), buf, uintptr(count)); err { switch n, _, err = unix.Syscall(unix.SYS_WRITE, uintptr(fd), buf, uintptr(count)); err {
@ -916,7 +917,7 @@ func Xfileno(t *TLS, stream uintptr) int32 {
panic(todo("")) panic(todo(""))
} }
func newCFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscall.Errno) uintptr { func newCFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscallErrno) uintptr {
p := Xcalloc(t, 1, types.Size_t(unsafe.Sizeof(fts.FTSENT{}))) p := Xcalloc(t, 1, types.Size_t(unsafe.Sizeof(fts.FTSENT{})))
if p == 0 { if p == 0 {
panic("OOM") panic("OOM")
@ -1322,7 +1323,7 @@ func Xabort(t *TLS) {
// (*signal.Sigaction)(unsafe.Pointer(p)).F__sigaction_u.F__sa_handler = signal.SIG_DFL // (*signal.Sigaction)(unsafe.Pointer(p)).F__sigaction_u.F__sa_handler = signal.SIG_DFL
// Xsigaction(t, signal.SIGABRT, p, 0) // Xsigaction(t, signal.SIGABRT, p, 0)
// Xfree(t, p) // Xfree(t, p)
// unix.Kill(unix.Getpid(), syscall.Signal(signal.SIGABRT)) // unix.Kill(unix.Getpid(), unix.Signal(signal.SIGABRT))
// panic(todo("unrechable")) // panic(todo("unrechable"))
} }
@ -1552,7 +1553,7 @@ func Xreaddir64(t *TLS, dir uintptr) uintptr {
return Xreaddir(t, dir) return Xreaddir(t, dir)
} }
func __syscall(r, _ uintptr, errno syscall.Errno) long { func __syscall(r, _ uintptr, errno syscallErrno) long {
if errno != 0 { if errno != 0 {
return long(-errno) return long(-errno)
} }
@ -1787,7 +1788,7 @@ func Xpipe(t *TLS, pipefd uintptr) int32 {
trc("t=%v pipefd=%v, (%v:)", t, pipefd, origin(2)) trc("t=%v pipefd=%v, (%v:)", t, pipefd, origin(2))
} }
var a [2]int var a [2]int
if err := syscall.Pipe(a[:]); err != nil { if err := unix.Pipe(a[:]); err != nil {
if dmesgs { if dmesgs {
dmesg("%v: %v FAIL", origin(1), err) dmesg("%v: %v FAIL", origin(1), err)
} }
@ -1814,7 +1815,7 @@ func Xmmap(t *TLS, addr uintptr, length types.Size_t, prot, flags, fd int32, off
if __ccgo_strace { if __ccgo_strace {
trc("t=%v addr=%v length=%v fd=%v offset=%v, (%v:)", t, addr, length, fd, offset, origin(2)) trc("t=%v addr=%v length=%v fd=%v offset=%v, (%v:)", t, addr, length, fd, offset, origin(2))
} }
// Cannot avoid the syscall here, addr sometimes matter. // Cannot avoid the unix here, addr sometimes matter.
data, _, err := unix.Syscall6(unix.SYS_MMAP, addr, uintptr(length), uintptr(prot), uintptr(flags), uintptr(fd), uintptr(offset)) data, _, err := unix.Syscall6(unix.SYS_MMAP, addr, uintptr(length), uintptr(prot), uintptr(flags), uintptr(fd), uintptr(offset))
if err != 0 { if err != 0 {
if dmesgs { if dmesgs {

View file

@ -6,7 +6,6 @@ package libc // import "modernc.org/libc"
import ( import (
"strings" "strings"
"syscall"
"unsafe" "unsafe"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
@ -657,7 +656,7 @@ func Xgetrlimit64(t *TLS, resource int32, rlim uintptr) int32 {
return 0 return 0
} }
func newFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscall.Errno) (r *fts.FTSENT) { func newFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscallErrno) (r *fts.FTSENT) {
var statp uintptr var statp uintptr
if stat != nil { if stat != nil {
statp = Xmalloc(t, types.Size_t(unsafe.Sizeof(unix.Stat_t{}))) statp = Xmalloc(t, types.Size_t(unsafe.Sizeof(unix.Stat_t{})))

View file

@ -6,7 +6,6 @@ package libc // import "modernc.org/libc"
import ( import (
"strings" "strings"
"syscall"
"unsafe" "unsafe"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
@ -656,7 +655,7 @@ func Xgetrlimit64(t *TLS, resource int32, rlim uintptr) int32 {
return 0 return 0
} }
func newFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscall.Errno) (r *fts.FTSENT) { func newFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscallErrno) (r *fts.FTSENT) {
var statp uintptr var statp uintptr
if stat != nil { if stat != nil {
statp = Xmalloc(t, types.Size_t(unsafe.Sizeof(unix.Stat_t{}))) statp = Xmalloc(t, types.Size_t(unsafe.Sizeof(unix.Stat_t{})))

View file

@ -14,7 +14,6 @@ import (
"runtime" "runtime"
"runtime/debug" "runtime/debug"
"strings" "strings"
"syscall"
gotime "time" gotime "time"
"unsafe" "unsafe"
@ -44,6 +43,8 @@ var (
in6_addr_any in.In6_addr in6_addr_any in.In6_addr
) )
type syscallErrno = unix.Errno
// // Keep these outside of the var block otherwise go generate will miss them. // // Keep these outside of the var block otherwise go generate will miss them.
var X__stderrp = Xstdout var X__stderrp = Xstdout
var X__stdinp = Xstdin var X__stdinp = Xstdin
@ -971,7 +972,7 @@ func Xfileno(t *TLS, stream uintptr) int32 {
panic(todo("")) panic(todo(""))
} }
func newCFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscall.Errno) uintptr { func newCFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscallErrno) uintptr {
p := Xcalloc(t, 1, types.Size_t(unsafe.Sizeof(fts.FTSENT{}))) p := Xcalloc(t, 1, types.Size_t(unsafe.Sizeof(fts.FTSENT{})))
if p == 0 { if p == 0 {
panic("OOM") panic("OOM")
@ -1377,7 +1378,7 @@ func Xabort(t *TLS) {
// (*signal.Sigaction)(unsafe.Pointer(p)).F__sigaction_u.F__sa_handler = signal.SIG_DFL // (*signal.Sigaction)(unsafe.Pointer(p)).F__sigaction_u.F__sa_handler = signal.SIG_DFL
// Xsigaction(t, signal.SIGABRT, p, 0) // Xsigaction(t, signal.SIGABRT, p, 0)
// Xfree(t, p) // Xfree(t, p)
// unix.Kill(unix.Getpid(), syscall.Signal(signal.SIGABRT)) // unix.Kill(unix.Getpid(), unix.Signal(signal.SIGABRT))
// panic(todo("unrechable")) // panic(todo("unrechable"))
} }
@ -1610,7 +1611,7 @@ func Xreaddir64(t *TLS, dir uintptr) uintptr {
return Xreaddir(t, dir) return Xreaddir(t, dir)
} }
func __syscall(r, _ uintptr, errno syscall.Errno) long { func __syscall(r, _ uintptr, errno syscallErrno) long {
if errno != 0 { if errno != 0 {
return long(-errno) return long(-errno)
} }
@ -1845,7 +1846,7 @@ func Xpipe(t *TLS, pipefd uintptr) int32 {
trc("t=%v pipefd=%v, (%v:)", t, pipefd, origin(2)) trc("t=%v pipefd=%v, (%v:)", t, pipefd, origin(2))
} }
var a [2]int var a [2]int
if err := syscall.Pipe(a[:]); err != nil { if err := unix.Pipe(a[:]); err != nil {
if dmesgs { if dmesgs {
dmesg("%v: %v FAIL", origin(1), err) dmesg("%v: %v FAIL", origin(1), err)
} }
@ -2772,7 +2773,7 @@ func Xgetrlimit64(t *TLS, resource int32, rlim uintptr) int32 {
return 0 return 0
} }
func newFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscall.Errno) (r *fts.FTSENT) { func newFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscallErrno) (r *fts.FTSENT) {
var statp uintptr var statp uintptr
if stat != nil { if stat != nil {
statp = Xmalloc(t, types.Size_t(unsafe.Sizeof(unix.Stat_t{}))) statp = Xmalloc(t, types.Size_t(unsafe.Sizeof(unix.Stat_t{})))

View file

@ -1,38 +0,0 @@
// Copyright 2023 The Libc Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package libc // import "modernc.org/libc"
import (
"fmt"
"unsafe"
)
// Byte loads are atomic on this CPU.
func a_load_8(addr uintptr) uint32 {
return uint32(*(*byte)(unsafe.Pointer(addr)))
}
// int16 loads are atomic on this CPU when properly aligned.
func a_load_16(addr uintptr) uint32 {
if addr&1 != 0 {
panic(fmt.Errorf("unaligned atomic 16 bit access at %#0x", addr))
}
return uint32(*(*uint16)(unsafe.Pointer(addr)))
}
// Byte sores are atomic on this CPU.
func a_store_8(addr uintptr, b byte) {
*(*byte)(unsafe.Pointer(addr)) = b
}
// int16 stores are atomic on this CPU when properly aligned.
func a_store_16(addr uintptr, n uint16) {
if addr&1 != 0 {
panic(fmt.Errorf("unaligned atomic 16 bit access at %#0x", addr))
}
*(*uint16)(unsafe.Pointer(addr)) = n
}

View file

@ -1,38 +0,0 @@
// Copyright 2023 The Libc Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package libc // import "modernc.org/libc"
import (
"fmt"
"unsafe"
)
// Byte loads are atomic on this CPU.
func a_load_8(addr uintptr) uint32 {
return uint32(*(*byte)(unsafe.Pointer(addr)))
}
// int16 loads are atomic on this CPU when properly aligned.
func a_load_16(addr uintptr) uint32 {
if addr&1 != 0 {
panic(fmt.Errorf("unaligned atomic 16 bit access at %#0x", addr))
}
return uint32(*(*uint16)(unsafe.Pointer(addr)))
}
// Byte sores are atomic on this CPU.
func a_store_8(addr uintptr, b byte) {
*(*byte)(unsafe.Pointer(addr)) = b
}
// int16 stores are atomic on this CPU when properly aligned.
func a_store_16(addr uintptr, n uint16) {
if addr&1 != 0 {
panic(fmt.Errorf("unaligned atomic 16 bit access at %#0x", addr))
}
*(*uint16)(unsafe.Pointer(addr)) = n
}

View file

@ -1,38 +0,0 @@
// Copyright 2023 The Libc Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package libc // import "modernc.org/libc"
import (
"fmt"
"unsafe"
)
// Byte loads are atomic on this CPU.
func a_load_8(addr uintptr) uint32 {
return uint32(*(*byte)(unsafe.Pointer(addr)))
}
// int16 loads are atomic on this CPU when properly aligned.
func a_load_16(addr uintptr) uint32 {
if addr&1 != 0 {
panic(fmt.Errorf("unaligned atomic 16 bit access at %#0x", addr))
}
return uint32(*(*uint16)(unsafe.Pointer(addr)))
}
// Byte sores are atomic on this CPU.
func a_store_8(addr uintptr, b byte) {
*(*byte)(unsafe.Pointer(addr)) = b
}
// int16 stores are atomic on this CPU when properly aligned.
func a_store_16(addr uintptr, n uint16) {
if addr&1 != 0 {
panic(fmt.Errorf("unaligned atomic 16 bit access at %#0x", addr))
}
*(*uint16)(unsafe.Pointer(addr)) = n
}

23
vendor/modernc.org/libc/libc_unix.go generated vendored
View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build unix && !(linux && (amd64 || arm64 || loong64)) //go:build unix && !(linux && (amd64 || arm64 || loong64 || ppc64le || s390x || riscv64 || 386 || arm))
package libc // import "modernc.org/libc" package libc // import "modernc.org/libc"
@ -18,7 +18,6 @@ import (
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
"syscall"
"time" "time"
"unsafe" "unsafe"
@ -56,21 +55,21 @@ func Xsignal(t *TLS, signum int32, handler uintptr) uintptr { //TODO use sigacti
signals[signum] = handler signals[signum] = handler
switch handler { switch handler {
case signal.SIG_DFL: case signal.SIG_DFL:
panic(todo("%v %#x", syscall.Signal(signum), handler)) panic(todo("%v %#x", unix.Signal(signum), handler))
case signal.SIG_IGN: case signal.SIG_IGN:
switch r { switch r {
case signal.SIG_DFL: case signal.SIG_DFL:
gosignal.Ignore(syscall.Signal(signum)) //TODO gosignal.Ignore(unix.Signal(signum)) //TODO
case signal.SIG_IGN: case signal.SIG_IGN:
gosignal.Ignore(syscall.Signal(signum)) gosignal.Ignore(unix.Signal(signum))
default: default:
panic(todo("%v %#x", syscall.Signal(signum), handler)) panic(todo("%v %#x", unix.Signal(signum), handler))
} }
default: default:
switch r { switch r {
case signal.SIG_DFL: case signal.SIG_DFL:
c := make(chan os.Signal, 1) c := make(chan os.Signal, 1)
gosignal.Notify(c, syscall.Signal(signum)) gosignal.Notify(c, unix.Signal(signum))
go func() { //TODO mechanism to stop/cancel go func() { //TODO mechanism to stop/cancel
for { for {
<-c <-c
@ -82,9 +81,9 @@ func Xsignal(t *TLS, signum int32, handler uintptr) uintptr { //TODO use sigacti
} }
}() }()
case signal.SIG_IGN: case signal.SIG_IGN:
panic(todo("%v %#x", syscall.Signal(signum), handler)) panic(todo("%v %#x", unix.Signal(signum), handler))
default: default:
panic(todo("%v %#x", syscall.Signal(signum), handler)) panic(todo("%v %#x", unix.Signal(signum), handler))
} }
} }
return r return r
@ -140,7 +139,11 @@ func Xremove(t *TLS, pathname uintptr) int32 {
if __ccgo_strace { if __ccgo_strace {
trc("t=%v pathname=%v, (%v:)", t, pathname, origin(2)) trc("t=%v pathname=%v, (%v:)", t, pathname, origin(2))
} }
panic(todo("")) if err := os.Remove(GoString(pathname)); err != nil {
t.setErrno(err)
return -1
}
return 0
} }
// long pathconf(const char *path, int name); // long pathconf(const char *path, int name);

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build unix && !illumos && !(linux && (amd64 || arm64 || loong64)) && !openbsd //go:build unix && !illumos && !(linux && (amd64 || arm64 || loong64 || ppc64le || s390x || riscv64 || 386 || arm)) && !openbsd
package libc // import "modernc.org/libc" package libc // import "modernc.org/libc"

File diff suppressed because it is too large Load diff

View file

@ -5,9 +5,9 @@
package libc // import "modernc.org/libc" package libc // import "modernc.org/libc"
import ( import (
"golang.org/x/sys/windows"
"os" "os"
"strings" "strings"
"syscall"
gotime "time" gotime "time"
"unsafe" "unsafe"
@ -235,7 +235,7 @@ func Xlseek64(t *TLS, fd int32, offset types.Off_t, whence int32) types.Off_t {
return -1 return -1
} }
n, err := syscall.Seek(f.Handle, offset, int(whence)) n, err := windows.Seek(f.Handle, offset, int(whence))
if err != nil { if err != nil {
if dmesgs { if dmesgs {
dmesg("%v: fd %v, off %#x, whence %v: %v", origin(1), f._fd, offset, whenceStr(whence), n) dmesg("%v: fd %v, off %#x, whence %v: %v", origin(1), f._fd, offset, whenceStr(whence), n)
@ -366,7 +366,7 @@ func Xunlink(t *TLS, pathname uintptr) int32 {
if __ccgo_strace { if __ccgo_strace {
trc("t=%v pathname=%v, (%v:)", t, pathname, origin(2)) trc("t=%v pathname=%v, (%v:)", t, pathname, origin(2))
} }
err := syscall.DeleteFile((*uint16)(unsafe.Pointer(pathname))) err := windows.DeleteFile((*uint16)(unsafe.Pointer(pathname)))
if err != nil { if err != nil {
t.setErrno(err) t.setErrno(err)
return -1 return -1
@ -505,7 +505,7 @@ func Xfopen64(t *TLS, pathname, mode uintptr) uintptr {
panic(m) panic(m)
} }
//TODO- flags |= fcntl.O_LARGEFILE //TODO- flags |= fcntl.O_LARGEFILE
h, err := syscall.Open(GoString(pathname), int(flags), uint32(0666)) h, err := windows.Open(GoString(pathname), int(flags), uint32(0666))
if err != nil { if err != nil {
t.setErrno(err) t.setErrno(err)
return 0 return 0
@ -515,7 +515,7 @@ func Xfopen64(t *TLS, pathname, mode uintptr) uintptr {
if p != 0 { if p != 0 {
return p return p
} }
_ = syscall.Close(h) _ = windows.Close(h)
t.setErrno(errno.ENOMEM) t.setErrno(errno.ENOMEM)
return 0 return 0
} }
@ -615,8 +615,8 @@ func X_localtime32(_ *TLS, sourceTime uintptr) uintptr {
// struct tm *_gmtime32( const __time32_t *sourceTime ); // struct tm *_gmtime32( const __time32_t *sourceTime );
func X_gmtime32(t *TLS, sourceTime uintptr) uintptr { func X_gmtime32(t *TLS, sourceTime uintptr) uintptr {
r0, _, err := syscall.SyscallN(procGmtime32.Addr(), uintptr(sourceTime)) r0, _, err := procGmtime32.Call(uintptr(sourceTime))
if err != 0 { if err != windows.NOERROR {
t.setErrno(err) t.setErrno(err)
} }
return uintptr(r0) return uintptr(r0)
@ -681,8 +681,8 @@ func X_fstat(t *TLS, fd int32, buffer uintptr) int32 {
return -1 return -1
} }
var d syscall.ByHandleFileInformation var d windows.ByHandleFileInformation
err := syscall.GetFileInformationByHandle(f.Handle, &d) err := windows.GetFileInformationByHandle(f.Handle, &d)
if err != nil { if err != nil {
t.setErrno(EBADF) t.setErrno(EBADF)
return -1 return -1

View file

@ -5,11 +5,11 @@
package libc // import "modernc.org/libc" package libc // import "modernc.org/libc"
import ( import (
"golang.org/x/sys/windows"
"modernc.org/libc/errno" "modernc.org/libc/errno"
"modernc.org/libc/sys/types" "modernc.org/libc/sys/types"
"os" "os"
"strings" "strings"
"syscall"
"unsafe" "unsafe"
) )
@ -231,7 +231,7 @@ func Xlseek64(t *TLS, fd int32, offset types.Off_t, whence int32) types.Off_t {
return -1 return -1
} }
n, err := syscall.Seek(f.Handle, offset, int(whence)) n, err := windows.Seek(f.Handle, offset, int(whence))
if err != nil { if err != nil {
if dmesgs { if dmesgs {
dmesg("%v: fd %v, off %#x, whence %v: %v", origin(1), f._fd, offset, whenceStr(whence), n) dmesg("%v: fd %v, off %#x, whence %v: %v", origin(1), f._fd, offset, whenceStr(whence), n)
@ -363,7 +363,7 @@ func Xunlink(t *TLS, pathname uintptr) int32 {
trc("t=%v pathname=%v, (%v:)", t, pathname, origin(2)) trc("t=%v pathname=%v, (%v:)", t, pathname, origin(2))
} }
err := syscall.DeleteFile((*uint16)(unsafe.Pointer(pathname))) err := windows.DeleteFile((*uint16)(unsafe.Pointer(pathname)))
if err != nil { if err != nil {
t.setErrno(err) t.setErrno(err)
return -1 return -1
@ -501,7 +501,7 @@ func Xfopen64(t *TLS, pathname, mode uintptr) uintptr {
panic(m) panic(m)
} }
//TODO- flags |= fcntl.O_LARGEFILE //TODO- flags |= fcntl.O_LARGEFILE
h, err := syscall.Open(GoString(pathname), int(flags), uint32(0666)) h, err := windows.Open(GoString(pathname), int(flags), uint32(0666))
if err != nil { if err != nil {
t.setErrno(err) t.setErrno(err)
return 0 return 0
@ -511,7 +511,7 @@ func Xfopen64(t *TLS, pathname, mode uintptr) uintptr {
if p != 0 { if p != 0 {
return p return p
} }
_ = syscall.Close(h) _ = windows.Close(h)
t.setErrno(errno.ENOMEM) t.setErrno(errno.ENOMEM)
return 0 return 0
} }

View file

@ -5,11 +5,11 @@
package libc // import "modernc.org/libc" package libc // import "modernc.org/libc"
import ( import (
"golang.org/x/sys/windows"
"modernc.org/libc/errno" "modernc.org/libc/errno"
"modernc.org/libc/sys/types" "modernc.org/libc/sys/types"
"os" "os"
"strings" "strings"
"syscall"
"unsafe" "unsafe"
) )
@ -231,7 +231,7 @@ func Xlseek64(t *TLS, fd int32, offset types.Off_t, whence int32) types.Off_t {
return -1 return -1
} }
n, err := syscall.Seek(f.Handle, offset, int(whence)) n, err := windows.Seek(f.Handle, offset, int(whence))
if err != nil { if err != nil {
if dmesgs { if dmesgs {
dmesg("%v: fd %v, off %#x, whence %v: %v", origin(1), f._fd, offset, whenceStr(whence), n) dmesg("%v: fd %v, off %#x, whence %v: %v", origin(1), f._fd, offset, whenceStr(whence), n)
@ -363,7 +363,7 @@ func Xunlink(t *TLS, pathname uintptr) int32 {
trc("t=%v pathname=%v, (%v:)", t, pathname, origin(2)) trc("t=%v pathname=%v, (%v:)", t, pathname, origin(2))
} }
err := syscall.DeleteFile((*uint16)(unsafe.Pointer(pathname))) err := windows.DeleteFile((*uint16)(unsafe.Pointer(pathname)))
if err != nil { if err != nil {
t.setErrno(err) t.setErrno(err)
return -1 return -1
@ -501,7 +501,7 @@ func Xfopen64(t *TLS, pathname, mode uintptr) uintptr {
panic(m) panic(m)
} }
//TODO- flags |= fcntl.O_LARGEFILE //TODO- flags |= fcntl.O_LARGEFILE
h, err := syscall.Open(GoString(pathname), int(flags), uint32(0666)) h, err := windows.Open(GoString(pathname), int(flags), uint32(0666))
if err != nil { if err != nil {
t.setErrno(err) t.setErrno(err)
return 0 return 0
@ -511,7 +511,7 @@ func Xfopen64(t *TLS, pathname, mode uintptr) uintptr {
if p != 0 { if p != 0 {
return p return p
} }
_ = syscall.Close(h) _ = windows.Close(h)
t.setErrno(errno.ENOMEM) t.setErrno(errno.ENOMEM)
return 0 return 0
} }

2
vendor/modernc.org/libc/mem.go generated vendored
View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build !libc.membrk && !libc.memgrind && !(linux && (amd64 || arm64 || loong64)) //go:build !libc.membrk && !libc.memgrind && !(linux && (amd64 || arm64 || loong64 || ppc64le || s390x || riscv64 || 386 || arm))
package libc // import "modernc.org/libc" package libc // import "modernc.org/libc"

2
vendor/modernc.org/libc/mem_brk.go generated vendored
View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build libc.membrk && !libc.memgrind && !(linux && (amd64 || arm64 || loong64)) //go:build libc.membrk && !libc.memgrind && !(linux && (amd64 || arm64 || loong64 || ppc64le || s390x || riscv64 || 386 || arm))
// This is a debug-only version of the memory handling functions. When a // This is a debug-only version of the memory handling functions. When a
// program is built with -tags=libc.membrk a simple but safe version of malloc // program is built with -tags=libc.membrk a simple but safe version of malloc

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build libc.membrk && !libc.memgrind && linux && (amd64 || arm64 || loong64) //go:build libc.membrk && !libc.memgrind && linux && (amd64 || arm64 || loong64 || ppc64le || s390x || riscv64 || 386 || arm)
// This is a debug-only version of the memory handling functions. When a // This is a debug-only version of the memory handling functions. When a
// program is built with -tags=libc.membrk a simple but safe version of malloc // program is built with -tags=libc.membrk a simple but safe version of malloc

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build !libc.membrk && !libc.memgrind && linux && (amd64 || arm64 || loong64) //go:build !libc.membrk && !libc.memgrind && linux && (amd64 || arm64 || loong64 || ppc64le || s390x || riscv64 || 386 || arm)
package libc // import "modernc.org/libc" package libc // import "modernc.org/libc"

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build !libc.membrk && libc.memgrind && !(linux && (amd64 || arm64 || loong64)) //go:build !libc.membrk && libc.memgrind && !(linux && (amd64 || arm64 || loong64 || ppc64le || s390x || riscv64 || 386 || arm))
// This is a debug-only version of the memory handling functions. When a // This is a debug-only version of the memory handling functions. When a
// program is built with -tags=libc.memgrind the functions MemAuditStart and // program is built with -tags=libc.memgrind the functions MemAuditStart and

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build !libc.membrk && libc.memgrind && linux && (amd64 || arm64 || loong64) //go:build !libc.membrk && libc.memgrind && linux && (amd64 || arm64 || loong64 || ppc64le || s390x || riscv64 || 386 || arm)
// This is a debug-only version of the memory handling functions. When a // This is a debug-only version of the memory handling functions. When a
// program is built with -tags=libc.memgrind the functions MemAuditStart and // program is built with -tags=libc.memgrind the functions MemAuditStart and

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -912,19 +912,10 @@ type mode_t = uint32 /* alltypes.h:175:18 */
type syscall_arg_t = int32 /* syscall.h:22:14 */ type syscall_arg_t = int32 /* syscall.h:22:14 */
func a_cas(tls *TLS, p uintptr, t int32, s int32) int32 { /* atomic_arch.h:2:19: */
panic(`arch/i386/atomic_arch.h:4:2: assembler statements not supported`)
return t
}
func a_and(tls *TLS, p uintptr, v int32) { /* atomic_arch.h:29:20: */ func a_and(tls *TLS, p uintptr, v int32) { /* atomic_arch.h:29:20: */
panic(`arch/i386/atomic_arch.h:31:2: assembler statements not supported`) panic(`arch/i386/atomic_arch.h:31:2: assembler statements not supported`)
} }
func a_or(tls *TLS, p uintptr, v int32) { /* atomic_arch.h:37:20: */
panic(`arch/i386/atomic_arch.h:39:2: assembler statements not supported`)
}
func a_ctz_64(tls *TLS, x uint64_t) int32 { /* atomic_arch.h:87:19: */ func a_ctz_64(tls *TLS, x uint64_t) int32 { /* atomic_arch.h:87:19: */
var r int32 var r int32
panic(`arch/i386/atomic_arch.h:90:2: assembler statements not supported`) panic(`arch/i386/atomic_arch.h:90:2: assembler statements not supported`)
@ -942,22 +933,6 @@ func a_clz_32(tls *TLS, x uint32_t) int32 { /* atomic_arch.h:104:19: */
return int32(x) return int32(x)
} }
func a_or_64(tls *TLS, p uintptr, v uint64_t) { /* atomic.h:220:20: */
bp := tls.Alloc(8)
defer tls.Free(8)
*(*struct{ v uint64_t })(unsafe.Pointer(bp)) = func() (r struct{ v uint64_t }) {
*(*uint64_t)(unsafe.Pointer(uintptr(unsafe.Pointer(&r)) + 0)) = v
return r
}()
if *(*uint32_t)(unsafe.Pointer(bp)) != 0 {
a_or(tls, p, int32(*(*uint32_t)(unsafe.Pointer(bp))))
}
if *(*uint32_t)(unsafe.Pointer(bp + 1*4)) != 0 {
a_or(tls, p+uintptr(1)*4, int32(*(*uint32_t)(unsafe.Pointer(bp + 1*4))))
}
}
type a_cas_p_undefined_but_pointer_not_32bit = [1]int8 /* atomic.h:229:14 */ type a_cas_p_undefined_but_pointer_not_32bit = [1]int8 /* atomic.h:229:14 */
type __timer = struct { type __timer = struct {

2
vendor/modernc.org/libc/printf.go generated vendored
View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build !(linux && (amd64 || arm64 || loong64)) //go:build !(linux && (amd64 || arm64 || loong64 || ppc64le || s390x || riscv64 || 386 || arm))
package libc // import "modernc.org/libc" package libc // import "modernc.org/libc"

14
vendor/modernc.org/libc/pthread.go generated vendored
View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build !(linux && (amd64 || arm64 || loong64)) //go:build !(linux && (amd64 || arm64 || loong64 || ppc64le || s390x || riscv64 || 386 || arm))
package libc // import "modernc.org/libc" package libc // import "modernc.org/libc"
@ -421,6 +421,8 @@ func (m *mutex) lock(id int32) int32 {
// shall return zero; otherwise, an error number shall be returned to indicate // shall return zero; otherwise, an error number shall be returned to indicate
// the error. // the error.
switch m.typ { switch m.typ {
default:
fallthrough
case pthread.PTHREAD_MUTEX_NORMAL: case pthread.PTHREAD_MUTEX_NORMAL:
// If the mutex type is PTHREAD_MUTEX_NORMAL, deadlock detection shall not be // If the mutex type is PTHREAD_MUTEX_NORMAL, deadlock detection shall not be
// provided. Attempting to relock the mutex causes deadlock. If a thread // provided. Attempting to relock the mutex causes deadlock. If a thread
@ -450,8 +452,6 @@ func (m *mutex) lock(id int32) int32 {
// intentional empty section - wake up other waiters // intentional empty section - wake up other waiters
m.wait.Unlock() m.wait.Unlock()
} }
default:
panic(todo("", m.typ))
} }
} }
@ -461,6 +461,8 @@ func (m *mutex) tryLock(id int32) int32 {
} }
switch m.typ { switch m.typ {
default:
fallthrough
case pthread.PTHREAD_MUTEX_NORMAL: case pthread.PTHREAD_MUTEX_NORMAL:
return errno.EBUSY return errno.EBUSY
case pthread.PTHREAD_MUTEX_RECURSIVE: case pthread.PTHREAD_MUTEX_RECURSIVE:
@ -480,8 +482,6 @@ func (m *mutex) tryLock(id int32) int32 {
m.Unlock() m.Unlock()
return errno.EBUSY return errno.EBUSY
default:
panic(todo("", m.typ))
} }
} }
@ -494,6 +494,8 @@ func (m *mutex) unlock() int32 {
// shall return zero; otherwise, an error number shall be returned to indicate // shall return zero; otherwise, an error number shall be returned to indicate
// the error. // the error.
switch m.typ { switch m.typ {
default:
fallthrough
case pthread.PTHREAD_MUTEX_NORMAL: case pthread.PTHREAD_MUTEX_NORMAL:
// If the mutex type is PTHREAD_MUTEX_NORMAL, deadlock detection shall not be // If the mutex type is PTHREAD_MUTEX_NORMAL, deadlock detection shall not be
// provided. Attempting to relock the mutex causes deadlock. If a thread // provided. Attempting to relock the mutex causes deadlock. If a thread
@ -511,8 +513,6 @@ func (m *mutex) unlock() int32 {
} }
m.Unlock() m.Unlock()
return 0 return 0
default:
panic(todo("", m.typ))
} }
} }

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build !freebsd && !openbsd && !(linux && (amd64 || arm64 || loong64)) //go:build !freebsd && !openbsd && !(linux && (amd64 || arm64 || loong64 || ppc64le || s390x || riscv64 || 386 || arm))
package libc // import "modernc.org/libc" package libc // import "modernc.org/libc"

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build linux && (amd64 || arm64 || loong64) //go:build linux && (amd64 || arm64 || loong64 || ppc64le || s390x || riscv64 || 386 || arm)
package libc // import "modernc.org/libc" package libc // import "modernc.org/libc"
@ -22,14 +22,14 @@ type pthreadCleanupItem struct {
routine, arg uintptr routine, arg uintptr
} }
// C version is 40 bytes. // C version is 40 bytes (64b) and 24 bytes (32b).
type pthreadMutex struct { type pthreadMutex struct { // 64b 32b
sync.Mutex // 0 8 sync.Mutex // 0 8 0 8
count int32 // 8 4 count int32 // 8 4 8 4
mType uint32 // 12 4 mType uint32 // 12 4 12 4
outer sync.Mutex // 16 8 outer sync.Mutex // 16 8 16 8
owner int32 // 20 4 owner int32 // 24 4 24 4
// 24 // 28 28
} }
type pthreadConds struct { type pthreadConds struct {
@ -374,7 +374,7 @@ func Xpthread_cond_timedwait(tls *TLS, c, m, ts uintptr) (r int32) {
if ts != 0 { if ts != 0 {
deadlineSecs := (*Ttimespec)(unsafe.Pointer(ts)).Ftv_sec deadlineSecs := (*Ttimespec)(unsafe.Pointer(ts)).Ftv_sec
deadlineNsecs := (*Ttimespec)(unsafe.Pointer(ts)).Ftv_nsec deadlineNsecs := (*Ttimespec)(unsafe.Pointer(ts)).Ftv_nsec
deadline := time.Unix(deadlineSecs, deadlineNsecs) deadline := time.Unix(deadlineSecs, int64(deadlineNsecs))
d := deadline.Sub(time.Now()) d := deadline.Sub(time.Now())
if d <= 0 { if d <= 0 {
return ETIMEDOUT return ETIMEDOUT

2
vendor/modernc.org/libc/rtl.go generated vendored
View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build linux && (amd64 || arm64 || loong64) //go:build linux && (amd64 || arm64 || loong64 || ppc64le || s390x || riscv64 || 386 || arm)
package libc // import "modernc.org/libc" package libc // import "modernc.org/libc"

2
vendor/modernc.org/libc/scanf.go generated vendored
View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build !(linux && (amd64 || arm64 || loong64)) //go:build !(linux && (amd64 || arm64 || loong64 || ppc64le || s390x || riscv64 || 386 || arm))
package libc // import "modernc.org/libc" package libc // import "modernc.org/libc"

2
vendor/modernc.org/libc/sync.go generated vendored
View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build !(linux && (amd64 || arm64 || loong64)) //go:build !(linux && (amd64 || arm64 || loong64 || ppc64le || s390x || riscv64 || 386 || arm))
package libc // import "modernc.org/libc" package libc // import "modernc.org/libc"

View file

@ -2,17 +2,17 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build linux && (amd64 || arm64 || loong64) //go:build linux && (amd64 || arm64 || loong64 || ppc64le || s390x || riscv64 || 386 || arm)
package libc // import "modernc.org/libc" package libc // import "modernc.org/libc"
import ( import (
"golang.org/x/sys/unix"
"runtime" "runtime"
"syscall"
) )
func ___syscall_cp(tls *TLS, n, a, b, c, d, e, f long) long { func ___syscall_cp(tls *TLS, n, a, b, c, d, e, f long) long {
r1, _, err := (syscall.Syscall6(uintptr(n), uintptr(a), uintptr(b), uintptr(c), uintptr(d), uintptr(e), uintptr(f))) r1, _, err := (unix.Syscall6(uintptr(n), uintptr(a), uintptr(b), uintptr(c), uintptr(d), uintptr(e), uintptr(f)))
if err != 0 { if err != 0 {
return long(-err) return long(-err)
} }
@ -26,7 +26,7 @@ func X__syscall0(tls *TLS, n long) long {
runtime.Gosched() runtime.Gosched()
return 0 return 0
default: default:
r1, _, err := syscall.Syscall(uintptr(n), 0, 0, 0) r1, _, err := unix.Syscall(uintptr(n), 0, 0, 0)
if err != 0 { if err != 0 {
return long(-err) return long(-err)
} }
@ -36,7 +36,7 @@ func X__syscall0(tls *TLS, n long) long {
} }
func X__syscall1(tls *TLS, n, a1 long) long { func X__syscall1(tls *TLS, n, a1 long) long {
r1, _, err := syscall.Syscall(uintptr(n), uintptr(a1), 0, 0) r1, _, err := unix.Syscall(uintptr(n), uintptr(a1), 0, 0)
if err != 0 { if err != 0 {
return long(-err) return long(-err)
} }
@ -45,7 +45,7 @@ func X__syscall1(tls *TLS, n, a1 long) long {
} }
func X__syscall2(tls *TLS, n, a1, a2 long) long { func X__syscall2(tls *TLS, n, a1, a2 long) long {
r1, _, err := syscall.Syscall(uintptr(n), uintptr(a1), uintptr(a2), 0) r1, _, err := unix.Syscall(uintptr(n), uintptr(a1), uintptr(a2), 0)
if err != 0 { if err != 0 {
return long(-err) return long(-err)
} }
@ -54,7 +54,7 @@ func X__syscall2(tls *TLS, n, a1, a2 long) long {
} }
func X__syscall3(tls *TLS, n, a1, a2, a3 long) long { func X__syscall3(tls *TLS, n, a1, a2, a3 long) long {
r1, _, err := syscall.Syscall(uintptr(n), uintptr(a1), uintptr(a2), uintptr(a3)) r1, _, err := unix.Syscall(uintptr(n), uintptr(a1), uintptr(a2), uintptr(a3))
if err != 0 { if err != 0 {
return long(-err) return long(-err)
} }
@ -63,7 +63,7 @@ func X__syscall3(tls *TLS, n, a1, a2, a3 long) long {
} }
func X__syscall4(tls *TLS, n, a1, a2, a3, a4 long) long { func X__syscall4(tls *TLS, n, a1, a2, a3, a4 long) long {
r1, _, err := syscall.Syscall6(uintptr(n), uintptr(a1), uintptr(a2), uintptr(a3), uintptr(a4), 0, 0) r1, _, err := unix.Syscall6(uintptr(n), uintptr(a1), uintptr(a2), uintptr(a3), uintptr(a4), 0, 0)
if err != 0 { if err != 0 {
return long(-err) return long(-err)
} }
@ -72,7 +72,7 @@ func X__syscall4(tls *TLS, n, a1, a2, a3, a4 long) long {
} }
func X__syscall5(tls *TLS, n, a1, a2, a3, a4, a5 long) long { func X__syscall5(tls *TLS, n, a1, a2, a3, a4, a5 long) long {
r1, _, err := syscall.Syscall6(uintptr(n), uintptr(a1), uintptr(a2), uintptr(a3), uintptr(a4), uintptr(a5), 0) r1, _, err := unix.Syscall6(uintptr(n), uintptr(a1), uintptr(a2), uintptr(a3), uintptr(a4), uintptr(a5), 0)
if err != 0 { if err != 0 {
return long(-err) return long(-err)
} }
@ -81,7 +81,7 @@ func X__syscall5(tls *TLS, n, a1, a2, a3, a4, a5 long) long {
} }
func X__syscall6(tls *TLS, n, a1, a2, a3, a4, a5, a6 long) long { func X__syscall6(tls *TLS, n, a1, a2, a3, a4, a5, a6 long) long {
r1, _, err := syscall.Syscall6(uintptr(n), uintptr(a1), uintptr(a2), uintptr(a3), uintptr(a4), uintptr(a5), uintptr(a6)) r1, _, err := unix.Syscall6(uintptr(n), uintptr(a1), uintptr(a2), uintptr(a3), uintptr(a4), uintptr(a5), uintptr(a6))
if err != 0 { if err != 0 {
return long(-err) return long(-err)
} }

View file

@ -3,3 +3,4 @@ until unconvert -fastmath ./...
do do
unconvert -fastmath -apply ./... unconvert -fastmath -apply ./...
done done
git checkout -f pthread_musl.go

View file

@ -28,7 +28,7 @@ cpu: clean
go tool pprof -lines *.test cpu.out go tool pprof -lines *.test cpu.out
edit: edit:
@ 1>/dev/null 2>/dev/null gvim -p Makefile *.go & @ 1>/dev/null 2>/dev/null gvim -p Makefile go.mod builder.json *.go &
editor: editor:
gofmt -l -s -w *.go gofmt -l -s -w *.go

6
vendor/modernc.org/mathutil/builder.json generated vendored Normal file
View file

@ -0,0 +1,6 @@
{
"autogen": "<none>",
"autoupdate": ".",
"autotag": ".",
"test": "."
}

View file

@ -5,7 +5,7 @@
// Package mathutil provides utilities supplementing the standard 'math' and // Package mathutil provides utilities supplementing the standard 'math' and
// 'math/rand' packages. // 'math/rand' packages.
// //
// Release history and compatibility issues // # Release history and compatibility issues
// //
// 2020-12-20 v1.2.1 fixes MulOverflowInt64. // 2020-12-20 v1.2.1 fixes MulOverflowInt64.
// //
@ -14,50 +14,52 @@
// 2018-10-21 Added BinaryLog // 2018-10-21 Added BinaryLog
// //
// 2018-04-25: New functions for determining Max/Min of nullable values. Ex: // 2018-04-25: New functions for determining Max/Min of nullable values. Ex:
// func MaxPtr(a, b *int) *int { //
// func MinPtr(a, b *int) *int { // func MaxPtr(a, b *int) *int {
// func MaxBytePtr(a, b *byte) *byte { // func MinPtr(a, b *int) *int {
// func MinBytePtr(a, b *byte) *byte { // func MaxBytePtr(a, b *byte) *byte {
// ... // func MinBytePtr(a, b *byte) *byte {
// ...
// //
// 2017-10-14: New variadic functions for Max/Min. Ex: // 2017-10-14: New variadic functions for Max/Min. Ex:
// func MaxVal(val int, vals ...int) int { //
// func MinVal(val int, vals ...int) int { // func MaxVal(val int, vals ...int) int {
// func MaxByteVal(val byte, vals ...byte) byte { // func MinVal(val int, vals ...int) int {
// func MinByteVal(val byte, vals ...byte) byte { // func MaxByteVal(val byte, vals ...byte) byte {
// ... // func MinByteVal(val byte, vals ...byte) byte {
// ...
// //
// 2016-10-10: New functions QuadPolyDiscriminant and QuadPolyFactors. // 2016-10-10: New functions QuadPolyDiscriminant and QuadPolyFactors.
// //
// 2013-12-13: The following functions have been REMOVED // 2013-12-13: The following functions have been REMOVED
// //
// func Uint64ToBigInt(n uint64) *big.Int // func Uint64ToBigInt(n uint64) *big.Int
// func Uint64FromBigInt(n *big.Int) (uint64, bool) // func Uint64FromBigInt(n *big.Int) (uint64, bool)
// //
// 2013-05-13: The following functions are now DEPRECATED // 2013-05-13: The following functions are now DEPRECATED
// //
// func Uint64ToBigInt(n uint64) *big.Int // func Uint64ToBigInt(n uint64) *big.Int
// func Uint64FromBigInt(n *big.Int) (uint64, bool) // func Uint64FromBigInt(n *big.Int) (uint64, bool)
// //
// These functions will be REMOVED with Go release 1.1+1. // These functions will be REMOVED with Go release 1.1+1.
// //
// 2013-01-21: The following functions have been REMOVED // 2013-01-21: The following functions have been REMOVED
// //
// func MaxInt() int // func MaxInt() int
// func MinInt() int // func MinInt() int
// func MaxUint() uint // func MaxUint() uint
// func UintPtrBits() int // func UintPtrBits() int
// //
// They are now replaced by untyped constants // They are now replaced by untyped constants
// //
// MaxInt // MaxInt
// MinInt // MinInt
// MaxUint // MaxUint
// UintPtrBits // UintPtrBits
// //
// Additionally one more untyped constant was added // Additionally one more untyped constant was added
// //
// IntBits // IntBits
// //
// This change breaks any existing code depending on the above removed // This change breaks any existing code depending on the above removed
// functions. They should have not been published in the first place, that was // functions. They should have not been published in the first place, that was
@ -71,8 +73,8 @@
// 1.0.3+1 and REMOVED with Go release 1.0.3+2, b/c of // 1.0.3+1 and REMOVED with Go release 1.0.3+2, b/c of
// http://code.google.com/p/go/source/detail?r=954a79ee3ea8 // http://code.google.com/p/go/source/detail?r=954a79ee3ea8
// //
// func Uint64ToBigInt(n uint64) *big.Int // func Uint64ToBigInt(n uint64) *big.Int
// func Uint64FromBigInt(n *big.Int) (uint64, bool) // func Uint64FromBigInt(n *big.Int) (uint64, bool)
package mathutil // import "modernc.org/mathutil" package mathutil // import "modernc.org/mathutil"
import ( import (
@ -507,20 +509,20 @@ k == 1.
Wrt pseudocode shown at Wrt pseudocode shown at
http://en.wikipedia.org/wiki/Miller-Rabin_primality_test#Algorithm_and_running_time http://en.wikipedia.org/wiki/Miller-Rabin_primality_test#Algorithm_and_running_time
Input: n > 3, an odd integer to be tested for primality; Input: n > 3, an odd integer to be tested for primality;
Input: k, a parameter that determines the accuracy of the test Input: k, a parameter that determines the accuracy of the test
Output: composite if n is composite, otherwise probably prime Output: composite if n is composite, otherwise probably prime
write n 1 as 2^s·d with d odd by factoring powers of 2 from n 1 write n 1 as 2^s·d with d odd by factoring powers of 2 from n 1
LOOP: repeat k times: LOOP: repeat k times:
pick a random integer a in the range [2, n 2] pick a random integer a in the range [2, n 2]
x a^d mod n x a^d mod n
if x = 1 or x = n 1 then do next LOOP if x = 1 or x = n 1 then do next LOOP
for r = 1 .. s 1 for r = 1 .. s 1
x x^2 mod n x x^2 mod n
if x = 1 then return composite if x = 1 then return composite
if x = n 1 then do next LOOP if x = n 1 then do next LOOP
return composite return composite
return probably prime return probably prime
... this function behaves like passing 1 for 'k' and additionally a ... this function behaves like passing 1 for 'k' and additionally a
fixed/non-random 'a'. Otherwise it's the same algorithm. fixed/non-random 'a'. Otherwise it's the same algorithm.
@ -1385,7 +1387,7 @@ func ClampInt64(v, lo, hi int64) int64 {
// ToBase produces n in base b. For example // ToBase produces n in base b. For example
// //
// ToBase(2047, 22) -> [1, 5, 4] // ToBase(2047, 22) -> [1, 5, 4]
// //
// 1 * 22^0 1 // 1 * 22^0 1
// 5 * 22^1 110 // 5 * 22^1 110

7
vendor/modernc.org/mathutil/rat.go generated vendored
View file

@ -6,10 +6,9 @@ package mathutil // import "modernc.org/mathutil"
// QCmpUint32 compares a/b and c/d and returns: // QCmpUint32 compares a/b and c/d and returns:
// //
// -1 if a/b < c/d // -1 if a/b < c/d
// 0 if a/b == c/d // 0 if a/b == c/d
// +1 if a/b > c/d // +1 if a/b > c/d
//
func QCmpUint32(a, b, c, d uint32) int { func QCmpUint32(a, b, c, d uint32) int {
switch x, y := uint64(a)*uint64(d), uint64(b)*uint64(c); { switch x, y := uint64(a)*uint64(d), uint64(b)*uint64(c); {
case x < y: case x < y:

12
vendor/modernc.org/mathutil/rnd.go generated vendored
View file

@ -15,12 +15,12 @@ import (
// this code doesn't produce values at constant delta (mod cycle length). // this code doesn't produce values at constant delta (mod cycle length).
// The 32 bit limit is per this implementation, the algorithm used has no intrinsic limit on the cycle size. // The 32 bit limit is per this implementation, the algorithm used has no intrinsic limit on the cycle size.
// Properties include: // Properties include:
// - Adjustable limits on creation (hi, lo). // - Adjustable limits on creation (hi, lo).
// - Positionable/randomly accessible (Pos, Seek). // - Positionable/randomly accessible (Pos, Seek).
// - Repeatable (deterministic). // - Repeatable (deterministic).
// - Can run forward or backward (Next, Prev). // - Can run forward or backward (Next, Prev).
// - For a billion numbers cycle the Next/Prev PRN can be produced in cca 100-150ns. // - For a billion numbers cycle the Next/Prev PRN can be produced in cca 100-150ns.
// That's like 5-10 times slower compared to PRNs generated using the (non FC) rand package. // That's like 5-10 times slower compared to PRNs generated using the (non FC) rand package.
type FC32 struct { type FC32 struct {
cycle int64 // On average: 3 * delta / 2, (HQ: 2 * delta) cycle int64 // On average: 3 * delta / 2, (HQ: 2 * delta)
delta int64 // hi - lo delta int64 // hi - lo

1
vendor/modernc.org/memory/AUTHORS generated vendored
View file

@ -8,6 +8,7 @@
# #
# Please keep the list sorted. # Please keep the list sorted.
Chris Waldon <christopher(dot)waldon(dot)dev@gmail.com>
Gleb Sakhnov <gleb.sakhnov@gmail.com> Gleb Sakhnov <gleb.sakhnov@gmail.com>
Jan Mercl <0xjnml@gmail.com> Jan Mercl <0xjnml@gmail.com>
Scot C Bontrager <scot@indievisible.org> Scot C Bontrager <scot@indievisible.org>

View file

@ -7,6 +7,7 @@
# Please keep the list sorted. # Please keep the list sorted.
Anup Kodlekere <anup.kodlekere@ibm.com> Anup Kodlekere <anup.kodlekere@ibm.com>
Chris Waldon <christopher(dot)waldon(dot)dev@gmail.com>
Gleb Sakhnov <gleb.sakhnov@gmail.com> Gleb Sakhnov <gleb.sakhnov@gmail.com>
Jan Mercl <0xjnml@gmail.com> Jan Mercl <0xjnml@gmail.com>
Scot C Bontrager <scot@indievisible.org> Scot C Bontrager <scot@indievisible.org>

2
vendor/modernc.org/memory/Makefile generated vendored
View file

@ -30,7 +30,7 @@ cpu: clean
go tool pprof -lines *.test cpu.out go tool pprof -lines *.test cpu.out
edit: edit:
@ 1>/dev/null 2>/dev/null gvim -p Makefile *.go & @ 1>/dev/null 2>/dev/null gvim -p Makefile go.mod builder.json *.go &
editor: editor:
gofmt -l -s -w *.go gofmt -l -s -w *.go

View file

@ -1,6 +1,6 @@
{ {
"autogen": "none", "autogen": "<none>",
"autotag": "darwin/(amd64|arm64)|freebsd/(amd64|arm64)|linux/(386|amd64|arm|arm64|loong64|ppc64le|riscv64|s390x)|openbsd/amd64|windows/(amd64|arm64)", "autoupdate": ".",
"autoupdate": "darwin/(amd64|arm64)|freebsd/(amd64|arm64)|linux/(386|amd64|arm|arm64|loong64|ppc64le|riscv64|s390x)|openbsd/amd64|windows/(amd64|arm64)", "autotag": ".",
"test": "darwin/(amd64|arm64)|freebsd/(amd64|arm64)|linux/(386|amd64|arm|arm64|loong64|ppc64le|riscv64|s390x)|openbsd/amd64|windows/(amd64|arm64)" "test": "."
} }

View file

@ -6,7 +6,7 @@ package memory // import "modernc.org/memory"
import ( import (
"os" "os"
"syscall" syscall "golang.org/x/sys/windows"
) )
const ( const (
@ -22,7 +22,7 @@ const (
const pageSizeLog = 16 const pageSizeLog = 16
var ( var (
modkernel32 = syscall.NewLazyDLL("kernel32.dll") modkernel32 = syscall.NewLazySystemDLL("kernel32.dll")
osPageMask = osPageSize - 1 osPageMask = osPageSize - 1
osPageSize = os.Getpagesize() osPageSize = os.Getpagesize()
procVirtualAlloc = modkernel32.NewProc("VirtualAlloc") procVirtualAlloc = modkernel32.NewProc("VirtualAlloc")

9
vendor/modernc.org/sqlite/Makefile generated vendored
View file

@ -56,17 +56,16 @@ clean:
go clean go clean
edit: edit:
@touch log
@if [ -f "Session.vim" ]; then gvim -S & else gvim -p Makefile go.mod builder.json all_test.go vendor_libsqlite3.go & fi @if [ -f "Session.vim" ]; then gvim -S & else gvim -p Makefile go.mod builder.json all_test.go vendor_libsqlite3.go & fi
editor: editor:
gofmt -l -s -w . 2>&1 | tee log-editor gofmt -l -s -w .
go test -c -o /dev/null 2>&1 | tee -a log-editor go test -c -o /dev/null
go build -v -o /dev/null ./... 2>&1 | tee -a log-editor go build -v -o /dev/null ./...
go build -o /dev/null vendor_libsqlite3.go go build -o /dev/null vendor_libsqlite3.go
test: test:
go test -v -timeout 24h 2>&1 | tee log-test go test -v -timeout 24h
vendor: vendor:
cd vendor_libsqlite3 && go build -o ../vendor main.go cd vendor_libsqlite3 && go build -o ../vendor main.go

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build !(linux && (amd64 || arm64 || loong64)) //go:build !linux
package sqlite // import "modernc.org/sqlite" package sqlite // import "modernc.org/sqlite"

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build linux && (amd64 || arm64 || loong64) //go:build linux
package sqlite // import "modernc.org/sqlite" package sqlite // import "modernc.org/sqlite"

File diff suppressed because one or more lines are too long

Some files were not shown because too many files have changed in this diff Show more