switch to CGO-free builds
This commit is contained in:
14
vendor/modernc.org/memory/AUTHORS
generated
vendored
Normal file
14
vendor/modernc.org/memory/AUTHORS
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
# This file lists authors for copyright purposes. This file is distinct from
|
||||
# the CONTRIBUTORS files. See the latter for an explanation.
|
||||
#
|
||||
# Names should be added to this file as:
|
||||
# Name or Organization <email address>
|
||||
#
|
||||
# The email address is not required for organizations.
|
||||
#
|
||||
# Please keep the list sorted.
|
||||
|
||||
Gleb Sakhnov <gleb.sakhnov@gmail.com>
|
||||
Jan Mercl <0xjnml@gmail.com>
|
||||
Scot C Bontrager <scot@indievisible.org>
|
||||
Steffen Butzer <steffen(dot)butzer@outlook.com>
|
||||
14
vendor/modernc.org/memory/CONTRIBUTORS
generated
vendored
Normal file
14
vendor/modernc.org/memory/CONTRIBUTORS
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
# This file lists people who contributed code to this repository. The AUTHORS
|
||||
# file lists the copyright holders; this file lists people.
|
||||
#
|
||||
# Names should be added to this file like so:
|
||||
# Name <email address>
|
||||
#
|
||||
# Please keep the list sorted.
|
||||
|
||||
Anup Kodlekere <anup.kodlekere@ibm.com>
|
||||
Gleb Sakhnov <gleb.sakhnov@gmail.com>
|
||||
Jan Mercl <0xjnml@gmail.com>
|
||||
Scot C Bontrager <scot@indievisible.org>
|
||||
Steffen Butzer <steffen(dot)butzer@outlook.com>
|
||||
ZHU Zijia <piggynl@outlook.com>
|
||||
27
vendor/modernc.org/memory/LICENSE
generated
vendored
Normal file
27
vendor/modernc.org/memory/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
Copyright (c) 2017 The Memory Authors. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the names of the authors nor the names of the
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
27
vendor/modernc.org/memory/LICENSE-GO
generated
vendored
Normal file
27
vendor/modernc.org/memory/LICENSE-GO
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
Copyright (c) 2009 The Go Authors. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
25
vendor/modernc.org/memory/LICENSE-MMAP-GO
generated
vendored
Normal file
25
vendor/modernc.org/memory/LICENSE-MMAP-GO
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
Copyright (c) 2011, Evan Shaw <edsrzf@gmail.com>
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the copyright holder nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
83
vendor/modernc.org/memory/Makefile
generated
vendored
Normal file
83
vendor/modernc.org/memory/Makefile
generated
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
# Copyright 2017 The Memory Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style
|
||||
# license that can be found in the LICENSE file.
|
||||
|
||||
.PHONY: all clean cover cpu editor internalError later mem nuke todo edit build_all_targets
|
||||
|
||||
grep=--include=*.go --include=*.l --include=*.y --include=*.yy
|
||||
ngrep='TODOOK\|parser\.go\|scanner\.go\|.*_string\.go'
|
||||
|
||||
all: editor
|
||||
go vet 2>&1 | grep -v $(ngrep) || true
|
||||
golint 2>&1 | grep -v $(ngrep) || true
|
||||
make todo
|
||||
misspell *.go
|
||||
maligned || true
|
||||
unconvert -apply
|
||||
staticcheck | grep -v 'lexer\.go' || true
|
||||
grep -n 'FAIL\|PASS' log
|
||||
date
|
||||
|
||||
clean:
|
||||
go clean
|
||||
rm -f *~ *.test *.out
|
||||
|
||||
cover:
|
||||
t=$(shell tempfile) ; go test -coverprofile $$t && go tool cover -html $$t && unlink $$t
|
||||
|
||||
cpu: clean
|
||||
go test -run @ -bench . -cpuprofile cpu.out
|
||||
go tool pprof -lines *.test cpu.out
|
||||
|
||||
edit:
|
||||
@ 1>/dev/null 2>/dev/null gvim -p Makefile *.go &
|
||||
|
||||
editor:
|
||||
gofmt -l -s -w *.go
|
||||
|
||||
build_all_targets:
|
||||
GOOS=darwin GOARCH=amd64 go build
|
||||
GOOS=darwin GOARCH=arm64 go build
|
||||
GOOS=freebsd GOARCH=386 go build
|
||||
GOOS=freebsd GOARCH=amd64 go build
|
||||
GOOS=freebsd GOARCH=arm go build
|
||||
GOOS=freebsd GOARCH=arm64 go build
|
||||
GOOS=illumos GOARCH=amd64 go build
|
||||
GOOS=linux GOARCH=386 go build
|
||||
GOOS=linux GOARCH=amd64 go build
|
||||
GOOS=linux GOARCH=arm go build
|
||||
GOOS=linux GOARCH=arm64 go build
|
||||
GOOS=linux GOARCH=loong64 go build
|
||||
GOOS=linux GOARCH=mips go build
|
||||
GOOS=linux GOARCH=mips64le go build
|
||||
GOOS=linux GOARCH=mipsle go build
|
||||
GOOS=linux GOARCH=riscv64 go build
|
||||
GOOS=linux GOARCH=s390x go build
|
||||
GOOS=netbsd GOARCH=386 go build
|
||||
GOOS=netbsd GOARCH=amd64 go build
|
||||
GOOS=netbsd GOARCH=arm go build
|
||||
GOOS=openbsd GOARCH=386 go build
|
||||
GOOS=openbsd GOARCH=amd64 go build
|
||||
GOOS=openbsd GOARCH=arm64 go build
|
||||
GOOS=windows GOARCH=386 go build
|
||||
GOOS=windows GOARCH=amd64 go build
|
||||
|
||||
internalError:
|
||||
egrep -ho '"internal error.*"' *.go | sort | cat -n
|
||||
|
||||
later:
|
||||
@grep -n $(grep) LATER * || true
|
||||
@grep -n $(grep) MAYBE * || true
|
||||
|
||||
mem: clean
|
||||
go test -run @ -bench . -memprofile mem.out -memprofilerate 1 -timeout 24h
|
||||
go tool pprof -lines -web -alloc_space *.test mem.out
|
||||
|
||||
nuke: clean
|
||||
go clean -i
|
||||
|
||||
todo:
|
||||
@grep -nr $(grep) ^[[:space:]]*_[[:space:]]*=[[:space:]][[:alpha:]][[:alnum:]]* * | grep -v $(ngrep) || true
|
||||
@grep -nr $(grep) TODO * | grep -v $(ngrep) || true
|
||||
@grep -nr $(grep) BUG * | grep -v $(ngrep) || true
|
||||
@grep -nr $(grep) [^[:alpha:]]println * | grep -v $(ngrep) || true
|
||||
13
vendor/modernc.org/memory/README.md
generated
vendored
Normal file
13
vendor/modernc.org/memory/README.md
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
# memory
|
||||
|
||||
Package memory implements a memory allocator.
|
||||
|
||||
## Build status
|
||||
|
||||
available at https://modern-c.appspot.com/-/builder/?importpath=modernc.org%2fmemory
|
||||
|
||||
Installation
|
||||
|
||||
$ go get modernc.org/memory
|
||||
|
||||
Documentation: [godoc.org/modernc.org/memory](http://godoc.org/modernc.org/memory)
|
||||
6
vendor/modernc.org/memory/builder.json
generated
vendored
Normal file
6
vendor/modernc.org/memory/builder.json
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"autogen": "none",
|
||||
"autotag": "darwin/(amd64|arm64)|freebsd/(amd64|arm64)|linux/(386|amd64|arm|arm64|loong64|ppc64le|riscv64|s390x)|openbsd/amd64|windows/(amd64|arm64)",
|
||||
"autoupdate": "darwin/(amd64|arm64)|freebsd/(amd64|arm64)|linux/(386|amd64|arm|arm64|loong64|ppc64le|riscv64|s390x)|openbsd/amd64|windows/(amd64|arm64)",
|
||||
"test": "darwin/(amd64|arm64)|freebsd/(amd64|arm64)|linux/(386|amd64|arm|arm64|loong64|ppc64le|riscv64|s390x)|openbsd/amd64|windows/(amd64|arm64)"
|
||||
}
|
||||
10
vendor/modernc.org/memory/counters.go
generated
vendored
Normal file
10
vendor/modernc.org/memory/counters.go
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
// Copyright 2017 The Memory 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 memory.counters
|
||||
// +build memory.counters
|
||||
|
||||
package memory // import "modernc.org/memory"
|
||||
|
||||
const counters = true
|
||||
477
vendor/modernc.org/memory/memory.go
generated
vendored
Normal file
477
vendor/modernc.org/memory/memory.go
generated
vendored
Normal file
@@ -0,0 +1,477 @@
|
||||
// Copyright 2017 The Memory 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 memory implements a memory allocator.
|
||||
//
|
||||
// # Build status
|
||||
//
|
||||
// available at https://modern-c.appspot.com/-/builder/?importpath=modernc.org%2fmemory
|
||||
//
|
||||
// # Changelog
|
||||
//
|
||||
// 2017-10-03 Added alternative, unsafe.Pointer-based API.
|
||||
//
|
||||
// Package memory implements a memory allocator.
|
||||
//
|
||||
// # Changelog
|
||||
//
|
||||
// 2017-10-03 Added alternative, unsafe.Pointer-based API.
|
||||
//
|
||||
// # Benchmarks
|
||||
//
|
||||
// jnml@3900x:~/src/modernc.org/memory$ date ; go version ; go test -run @ -bench . -benchmem |& tee log
|
||||
// Mon Sep 25 16:02:02 CEST 2023
|
||||
// go version go1.21.1 linux/amd64
|
||||
// goos: linux
|
||||
// goarch: amd64
|
||||
// pkg: modernc.org/memory
|
||||
// cpu: AMD Ryzen 9 3900X 12-Core Processor
|
||||
// BenchmarkFree16-24 123506772 9.802 ns/op 0 B/op 0 allocs/op
|
||||
// BenchmarkFree32-24 73853230 15.08 ns/op 0 B/op 0 allocs/op
|
||||
// BenchmarkFree64-24 43070334 25.15 ns/op 0 B/op 0 allocs/op
|
||||
// BenchmarkCalloc16-24 59353304 18.92 ns/op 0 B/op 0 allocs/op
|
||||
// BenchmarkCalloc32-24 39415004 29.00 ns/op 0 B/op 0 allocs/op
|
||||
// BenchmarkCalloc64-24 35825725 32.02 ns/op 0 B/op 0 allocs/op
|
||||
// BenchmarkGoCalloc16-24 38274313 26.99 ns/op 16 B/op 1 allocs/op
|
||||
// BenchmarkGoCalloc32-24 44590477 33.06 ns/op 32 B/op 1 allocs/op
|
||||
// BenchmarkGoCalloc64-24 44233016 37.20 ns/op 64 B/op 1 allocs/op
|
||||
// BenchmarkMalloc16-24 145736911 7.720 ns/op 0 B/op 0 allocs/op
|
||||
// BenchmarkMalloc32-24 128898334 7.887 ns/op 0 B/op 0 allocs/op
|
||||
// BenchmarkMalloc64-24 149569483 7.994 ns/op 0 B/op 0 allocs/op
|
||||
// BenchmarkUintptrFree16-24 117043012 9.205 ns/op 0 B/op 0 allocs/op
|
||||
// BenchmarkUintptrFree32-24 77399617 14.20 ns/op 0 B/op 0 allocs/op
|
||||
// BenchmarkUintptrFree64-24 48770785 25.04 ns/op 0 B/op 0 allocs/op
|
||||
// BenchmarkUintptrCalloc16-24 79257636 15.44 ns/op 0 B/op 0 allocs/op
|
||||
// BenchmarkUintptrCalloc32-24 49644562 23.62 ns/op 0 B/op 0 allocs/op
|
||||
// BenchmarkUintptrCalloc64-24 39854710 28.22 ns/op 0 B/op 0 allocs/op
|
||||
// BenchmarkUintptrMalloc16-24 252987727 4.525 ns/op 0 B/op 0 allocs/op
|
||||
// BenchmarkUintptrMalloc32-24 241423840 4.433 ns/op 0 B/op 0 allocs/op
|
||||
// BenchmarkUintptrMalloc64-24 256450324 4.669 ns/op 0 B/op 0 allocs/op
|
||||
// PASS
|
||||
// ok modernc.org/memory 93.178s
|
||||
// jnml@3900x:~/src/modernc.org/memory$
|
||||
package memory // import "modernc.org/memory"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/bits"
|
||||
"os"
|
||||
"reflect"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
headerSize = unsafe.Sizeof(page{})
|
||||
mallocAllign = 2 * unsafe.Sizeof(uintptr(0))
|
||||
maxSlotSize = 1 << maxSlotSizeLog
|
||||
maxSlotSizeLog = pageSizeLog - 2
|
||||
pageAvail = pageSize - headerSize
|
||||
pageMask = pageSize - 1
|
||||
pageSize = 1 << pageSizeLog
|
||||
)
|
||||
|
||||
func init() {
|
||||
if unsafe.Sizeof(page{})%mallocAllign != 0 {
|
||||
panic("internal error")
|
||||
}
|
||||
}
|
||||
|
||||
// if n%m != 0 { n += m-n%m }. m must be a power of 2.
|
||||
func roundup(n, m int) int { return (n + m - 1) &^ (m - 1) }
|
||||
|
||||
type node struct {
|
||||
prev, next uintptr // *node
|
||||
}
|
||||
|
||||
type page struct {
|
||||
brk int
|
||||
log uint
|
||||
size int
|
||||
used int
|
||||
}
|
||||
|
||||
// Allocator allocates and frees memory. Its zero value is ready for use. The
|
||||
// exported counters are updated only when build tag memory.counters is
|
||||
// present.
|
||||
type Allocator struct {
|
||||
Allocs int // # of allocs.
|
||||
Bytes int // Asked from OS.
|
||||
cap [64]int
|
||||
lists [64]uintptr // *node
|
||||
Mmaps int // Asked from OS.
|
||||
pages [64]uintptr // *page
|
||||
regs map[uintptr]struct{} // map[*page]struct{}
|
||||
}
|
||||
|
||||
func (a *Allocator) mmap(size int) (uintptr /* *page */, error) {
|
||||
p, size, err := mmap(size)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if counters {
|
||||
a.Mmaps++
|
||||
a.Bytes += size
|
||||
}
|
||||
if a.regs == nil {
|
||||
a.regs = map[uintptr]struct{}{}
|
||||
}
|
||||
(*page)(unsafe.Pointer(p)).size = size
|
||||
a.regs[p] = struct{}{}
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (a *Allocator) newPage(size int) (uintptr /* *page */, error) {
|
||||
size += int(headerSize)
|
||||
p, err := a.mmap(size)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
(*page)(unsafe.Pointer(p)).log = 0
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (a *Allocator) newSharedPage(log uint) (uintptr /* *page */, error) {
|
||||
if a.cap[log] == 0 {
|
||||
a.cap[log] = int(pageAvail) / (1 << log)
|
||||
}
|
||||
size := int(headerSize) + a.cap[log]<<log
|
||||
p, err := a.mmap(size)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
a.pages[log] = p
|
||||
(*page)(unsafe.Pointer(p)).log = log
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (a *Allocator) unmap(p uintptr /* *page */) error {
|
||||
delete(a.regs, p)
|
||||
if counters {
|
||||
a.Mmaps--
|
||||
}
|
||||
return unmap(p, (*page)(unsafe.Pointer(p)).size)
|
||||
}
|
||||
|
||||
// UintptrCalloc is like Calloc except it returns an uintptr.
|
||||
func (a *Allocator) UintptrCalloc(size int) (r uintptr, err error) {
|
||||
if trace {
|
||||
defer func() {
|
||||
fmt.Fprintf(os.Stderr, "Calloc(%#x) %#x, %v\n", size, r, err)
|
||||
}()
|
||||
}
|
||||
if r, err = a.UintptrMalloc(size); r == 0 || err != nil {
|
||||
return 0, err
|
||||
}
|
||||
b := ((*rawmem)(unsafe.Pointer(r)))[:size:size]
|
||||
for i := range b {
|
||||
b[i] = 0
|
||||
}
|
||||
return r, nil
|
||||
}
|
||||
|
||||
// UintptrFree is like Free except its argument is an uintptr, which must have
|
||||
// been acquired from UintptrCalloc or UintptrMalloc or UintptrRealloc.
|
||||
func (a *Allocator) UintptrFree(p uintptr) (err error) {
|
||||
if trace {
|
||||
defer func() {
|
||||
fmt.Fprintf(os.Stderr, "Free(%#x) %v\n", p, err)
|
||||
}()
|
||||
}
|
||||
if p == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if counters {
|
||||
a.Allocs--
|
||||
}
|
||||
pg := p &^ uintptr(pageMask)
|
||||
log := (*page)(unsafe.Pointer(pg)).log
|
||||
if log == 0 {
|
||||
if counters {
|
||||
a.Bytes -= (*page)(unsafe.Pointer(pg)).size
|
||||
}
|
||||
return a.unmap(pg)
|
||||
}
|
||||
|
||||
(*node)(unsafe.Pointer(p)).prev = 0
|
||||
(*node)(unsafe.Pointer(p)).next = a.lists[log]
|
||||
if next := (*node)(unsafe.Pointer(p)).next; next != 0 {
|
||||
(*node)(unsafe.Pointer(next)).prev = p
|
||||
}
|
||||
a.lists[log] = p
|
||||
(*page)(unsafe.Pointer(pg)).used--
|
||||
if (*page)(unsafe.Pointer(pg)).used != 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
for i := 0; i < (*page)(unsafe.Pointer(pg)).brk; i++ {
|
||||
n := pg + headerSize + uintptr(i)<<log
|
||||
next := (*node)(unsafe.Pointer(n)).next
|
||||
prev := (*node)(unsafe.Pointer(n)).prev
|
||||
switch {
|
||||
case prev == 0:
|
||||
a.lists[log] = next
|
||||
if next != 0 {
|
||||
(*node)(unsafe.Pointer(next)).prev = 0
|
||||
}
|
||||
case next == 0:
|
||||
(*node)(unsafe.Pointer(prev)).next = 0
|
||||
default:
|
||||
(*node)(unsafe.Pointer(prev)).next = next
|
||||
(*node)(unsafe.Pointer(next)).prev = prev
|
||||
}
|
||||
}
|
||||
|
||||
if a.pages[log] == pg {
|
||||
a.pages[log] = 0
|
||||
}
|
||||
if counters {
|
||||
a.Bytes -= (*page)(unsafe.Pointer(pg)).size
|
||||
}
|
||||
return a.unmap(pg)
|
||||
}
|
||||
|
||||
// UintptrMalloc is like Malloc except it returns an uinptr.
|
||||
func (a *Allocator) UintptrMalloc(size int) (r uintptr, err error) {
|
||||
if trace {
|
||||
defer func() {
|
||||
fmt.Fprintf(os.Stderr, "Malloc(%#x) %#x, %v\n", size, r, err)
|
||||
}()
|
||||
}
|
||||
if size < 0 {
|
||||
panic("invalid malloc size")
|
||||
}
|
||||
|
||||
if size == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
if counters {
|
||||
a.Allocs++
|
||||
}
|
||||
log := uint(bits.Len(uint((size+int(mallocAllign)-1)&^int(mallocAllign-1) - 1)))
|
||||
if log > maxSlotSizeLog {
|
||||
p, err := a.newPage(size)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return p + headerSize, nil
|
||||
}
|
||||
|
||||
if a.lists[log] == 0 && a.pages[log] == 0 {
|
||||
if _, err := a.newSharedPage(log); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
if p := a.pages[log]; p != 0 {
|
||||
(*page)(unsafe.Pointer(p)).used++
|
||||
(*page)(unsafe.Pointer(p)).brk++
|
||||
if (*page)(unsafe.Pointer(p)).brk == a.cap[log] {
|
||||
a.pages[log] = 0
|
||||
}
|
||||
return p + headerSize + uintptr((*page)(unsafe.Pointer(p)).brk-1)<<log, nil
|
||||
}
|
||||
|
||||
n := a.lists[log]
|
||||
p := n &^ uintptr(pageMask)
|
||||
a.lists[log] = (*node)(unsafe.Pointer(n)).next
|
||||
if next := (*node)(unsafe.Pointer(n)).next; next != 0 {
|
||||
(*node)(unsafe.Pointer(next)).prev = 0
|
||||
}
|
||||
(*page)(unsafe.Pointer(p)).used++
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// UintptrRealloc is like Realloc except its first argument is an uintptr,
|
||||
// which must have been returned from UintptrCalloc, UintptrMalloc or
|
||||
// UintptrRealloc.
|
||||
func (a *Allocator) UintptrRealloc(p uintptr, size int) (r uintptr, err error) {
|
||||
if trace {
|
||||
defer func() {
|
||||
fmt.Fprintf(os.Stderr, "UnsafeRealloc(%#x, %#x) %#x, %v\n", p, size, r, err)
|
||||
}()
|
||||
}
|
||||
switch {
|
||||
case p == 0:
|
||||
return a.UintptrMalloc(size)
|
||||
case size == 0 && p != 0:
|
||||
return 0, a.UintptrFree(p)
|
||||
}
|
||||
|
||||
us := UintptrUsableSize(p)
|
||||
if us >= size {
|
||||
return p, nil
|
||||
}
|
||||
|
||||
if r, err = a.UintptrMalloc(size); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if us < size {
|
||||
size = us
|
||||
}
|
||||
copy((*rawmem)(unsafe.Pointer(r))[:size:size], (*rawmem)(unsafe.Pointer(p))[:size:size])
|
||||
return r, a.UintptrFree(p)
|
||||
}
|
||||
|
||||
// UintptrUsableSize is like UsableSize except its argument is an uintptr,
|
||||
// which must have been returned from UintptrCalloc, UintptrMalloc or
|
||||
// UintptrRealloc.
|
||||
func UintptrUsableSize(p uintptr) (r int) {
|
||||
if trace {
|
||||
defer func() {
|
||||
fmt.Fprintf(os.Stderr, "UsableSize(%#x) %#x\n", p, r)
|
||||
}()
|
||||
}
|
||||
if p == 0 {
|
||||
return 0
|
||||
}
|
||||
|
||||
return usableSize(p)
|
||||
}
|
||||
|
||||
func usableSize(p uintptr) (r int) {
|
||||
pg := p &^ uintptr(pageMask)
|
||||
if log := (*page)(unsafe.Pointer(pg)).log; log != 0 {
|
||||
return 1 << log
|
||||
}
|
||||
|
||||
return (*page)(unsafe.Pointer(pg)).size - int(headerSize)
|
||||
}
|
||||
|
||||
// Calloc is like Malloc except the allocated memory is zeroed.
|
||||
func (a *Allocator) Calloc(size int) (r []byte, err error) {
|
||||
p, err := a.UintptrCalloc(size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var b []byte
|
||||
sh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
|
||||
sh.Cap = usableSize(p)
|
||||
sh.Data = p
|
||||
sh.Len = size
|
||||
return b, nil
|
||||
}
|
||||
|
||||
// Close releases all OS resources used by a and sets it to its zero value.
|
||||
//
|
||||
// It's not necessary to Close the Allocator when exiting a process.
|
||||
func (a *Allocator) Close() (err error) {
|
||||
for p := range a.regs {
|
||||
if e := a.unmap(p); e != nil && err == nil {
|
||||
err = e
|
||||
}
|
||||
}
|
||||
*a = Allocator{}
|
||||
return err
|
||||
}
|
||||
|
||||
// Free deallocates memory (as in C.free). The argument of Free must have been
|
||||
// acquired from Calloc or Malloc or Realloc.
|
||||
func (a *Allocator) Free(b []byte) (err error) {
|
||||
if b = b[:cap(b)]; len(b) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return a.UintptrFree(uintptr(unsafe.Pointer(&b[0])))
|
||||
}
|
||||
|
||||
// Malloc allocates size bytes and returns a byte slice of the allocated
|
||||
// memory. The memory is not initialized. Malloc panics for size < 0 and
|
||||
// returns (nil, nil) for zero size.
|
||||
//
|
||||
// It's ok to reslice the returned slice but the result of appending to it
|
||||
// cannot be passed to Free or Realloc as it may refer to a different backing
|
||||
// array afterwards.
|
||||
func (a *Allocator) Malloc(size int) (r []byte, err error) {
|
||||
p, err := a.UintptrMalloc(size)
|
||||
if p == 0 || err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sh := (*reflect.SliceHeader)(unsafe.Pointer(&r))
|
||||
sh.Cap = usableSize(p)
|
||||
sh.Data = p
|
||||
sh.Len = size
|
||||
return r, nil
|
||||
}
|
||||
|
||||
// Realloc changes the size of the backing array of b to size bytes or returns
|
||||
// an error, if any. The contents will be unchanged in the range from the
|
||||
// start of the region up to the minimum of the old and new sizes. If the
|
||||
// new size is larger than the old size, the added memory will not be
|
||||
// initialized. If b's backing array is of zero size, then the call is
|
||||
// equivalent to Malloc(size), for all values of size; if size is equal to
|
||||
// zero, and b's backing array is not of zero size, then the call is equivalent
|
||||
// to Free(b). Unless b's backing array is of zero size, it must have been
|
||||
// returned by an earlier call to Malloc, Calloc or Realloc. If the area
|
||||
// pointed to was moved, a Free(b) is done.
|
||||
func (a *Allocator) Realloc(b []byte, size int) (r []byte, err error) {
|
||||
var p uintptr
|
||||
if b = b[:cap(b)]; len(b) != 0 {
|
||||
p = uintptr(unsafe.Pointer(&b[0]))
|
||||
}
|
||||
if p, err = a.UintptrRealloc(p, size); p == 0 || err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sh := (*reflect.SliceHeader)(unsafe.Pointer(&r))
|
||||
sh.Cap = usableSize(p)
|
||||
sh.Data = p
|
||||
sh.Len = size
|
||||
return r, nil
|
||||
}
|
||||
|
||||
// UsableSize reports the size of the memory block allocated at p, which must
|
||||
// point to the first byte of a slice returned from Calloc, Malloc or Realloc.
|
||||
// The allocated memory block size can be larger than the size originally
|
||||
// requested from Calloc, Malloc or Realloc.
|
||||
func UsableSize(p *byte) (r int) { return UintptrUsableSize(uintptr(unsafe.Pointer(p))) }
|
||||
|
||||
// UnsafeCalloc is like Calloc except it returns an unsafe.Pointer.
|
||||
func (a *Allocator) UnsafeCalloc(size int) (r unsafe.Pointer, err error) {
|
||||
p, err := a.UintptrCalloc(size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return unsafe.Pointer(p), nil
|
||||
}
|
||||
|
||||
// UnsafeFree is like Free except its argument is an unsafe.Pointer, which must
|
||||
// have been acquired from UnsafeCalloc or UnsafeMalloc or UnsafeRealloc.
|
||||
func (a *Allocator) UnsafeFree(p unsafe.Pointer) (err error) { return a.UintptrFree(uintptr(p)) }
|
||||
|
||||
// UnsafeMalloc is like Malloc except it returns an unsafe.Pointer.
|
||||
func (a *Allocator) UnsafeMalloc(size int) (r unsafe.Pointer, err error) {
|
||||
p, err := a.UintptrMalloc(size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return unsafe.Pointer(p), nil
|
||||
}
|
||||
|
||||
// UnsafeRealloc is like Realloc except its first argument is an
|
||||
// unsafe.Pointer, which must have been returned from UnsafeCalloc,
|
||||
// UnsafeMalloc or UnsafeRealloc.
|
||||
func (a *Allocator) UnsafeRealloc(p unsafe.Pointer, size int) (r unsafe.Pointer, err error) {
|
||||
q, err := a.UintptrRealloc(uintptr(p), size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return unsafe.Pointer(q), nil
|
||||
}
|
||||
|
||||
// UnsafeUsableSize is like UsableSize except its argument is an
|
||||
// unsafe.Pointer, which must have been returned from UnsafeCalloc,
|
||||
// UnsafeMalloc or UnsafeRealloc.
|
||||
func UnsafeUsableSize(p unsafe.Pointer) (r int) { return UintptrUsableSize(uintptr(p)) }
|
||||
10
vendor/modernc.org/memory/memory32.go
generated
vendored
Normal file
10
vendor/modernc.org/memory/memory32.go
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
// Copyright 2018 The Memory 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 386 || arm || armbe || mips || mipsle || ppc || s390 || s390x || sparc
|
||||
// +build 386 arm armbe mips mipsle ppc s390 s390x sparc
|
||||
|
||||
package memory // import "modernc.org/memory"
|
||||
|
||||
type rawmem [1<<31 - 2]byte
|
||||
10
vendor/modernc.org/memory/memory64.go
generated
vendored
Normal file
10
vendor/modernc.org/memory/memory64.go
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
// Copyright 2018 The Memory 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 amd64 || amd64p32 || arm64 || arm64be || mips64 || mips64le || mips64p32 || mips64p32le || ppc64 || ppc64le || sparc64 || riscv64 || loong64
|
||||
// +build amd64 amd64p32 arm64 arm64be mips64 mips64le mips64p32 mips64p32le ppc64 ppc64le sparc64 riscv64 loong64
|
||||
|
||||
package memory // import "modernc.org/memory"
|
||||
|
||||
type rawmem [1<<50 - 1]byte
|
||||
19
vendor/modernc.org/memory/mmap_darwin.go
generated
vendored
Normal file
19
vendor/modernc.org/memory/mmap_darwin.go
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
// Copyright 2017 The Memory 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 amd64 || arm64
|
||||
// +build amd64 arm64
|
||||
|
||||
package memory
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
)
|
||||
|
||||
// Function syscall.mmap for darwin and openbsd calls internal/abi.FuncPCABI0,
|
||||
// which is implemented as a compile intrinsic so the code cannot be reused.
|
||||
// Using go:linkname directive to link mmapSyscall to syscall.mmap
|
||||
|
||||
//go:linkname mmapSyscall syscall.mmap
|
||||
func mmapSyscall(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error)
|
||||
22
vendor/modernc.org/memory/mmap_freebsd_32.go
generated
vendored
Normal file
22
vendor/modernc.org/memory/mmap_freebsd_32.go
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
// Copyright 2009 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE-GO file.
|
||||
|
||||
//go:build (freebsd && 386) || (freebsd && arm)
|
||||
// +build freebsd,386 freebsd,arm
|
||||
|
||||
package memory
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// https://cs.opensource.google/go/go/+/refs/tags/go1.17.8:src/syscall/zsyscall_freebsd_386.go
|
||||
func mmapSyscall(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) {
|
||||
r0, _, e1 := syscall.Syscall9(syscall.SYS_MMAP, uintptr(addr), uintptr(length), uintptr(prot), uintptr(flag), uintptr(fd), uintptr(pos), uintptr(pos>>32), 0, 0)
|
||||
ret = uintptr(r0)
|
||||
if e1 != 0 {
|
||||
err = e1
|
||||
}
|
||||
return
|
||||
}
|
||||
22
vendor/modernc.org/memory/mmap_freebsd_64.go
generated
vendored
Normal file
22
vendor/modernc.org/memory/mmap_freebsd_64.go
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
// Copyright 2009 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE-GO file.
|
||||
|
||||
//go:build (freebsd && amd64) || (freebsd && arm64)
|
||||
// +build freebsd,amd64 freebsd,arm64
|
||||
|
||||
package memory
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// https://cs.opensource.google/go/go/+/refs/tags/go1.17.8:src/syscall/zsyscall_freebsd_amd64.go;l=1337-1346
|
||||
func mmapSyscall(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) {
|
||||
r0, _, e1 := syscall.Syscall6(syscall.SYS_MMAP, uintptr(addr), uintptr(length), uintptr(prot), uintptr(flag), uintptr(fd), uintptr(pos))
|
||||
ret = uintptr(r0)
|
||||
if e1 != 0 {
|
||||
err = e1
|
||||
}
|
||||
return
|
||||
}
|
||||
91
vendor/modernc.org/memory/mmap_illumos_amd64.go
generated
vendored
Normal file
91
vendor/modernc.org/memory/mmap_illumos_amd64.go
generated
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
// Copyright 2011 Evan Shaw. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE-MMAP-GO file.
|
||||
|
||||
// Modifications (c) 2022 The Memory Authors.
|
||||
|
||||
package memory // import "modernc.org/memory"
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
_ "unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
pageSizeLog = 20
|
||||
|
||||
// $ find /usr/include -name syscall.h
|
||||
// /usr/include/sys/syscall.h
|
||||
// $ grep -ni munmap /usr/include/sys/syscall.h
|
||||
// 293:#define SYS_munmap 117
|
||||
// $ grep -ni mmap /usr/include/sys/syscall.h
|
||||
// 291:#define SYS_mmap 115
|
||||
// 303:#define SYS_mmapobj 127
|
||||
// 442:#define SYS_mmap64 214
|
||||
// $
|
||||
// $ uname -a
|
||||
// SunOS omnios64 5.11 omnios-r151044-d3b715b9d1 i86pc i386 i86pc
|
||||
// $
|
||||
sys_MUNMAP = 117
|
||||
sys_MMAP = 214
|
||||
)
|
||||
|
||||
var (
|
||||
osPageMask = osPageSize - 1
|
||||
osPageSize = os.Getpagesize()
|
||||
)
|
||||
|
||||
//go:linkname mmapSyscall syscall.mmap
|
||||
func mmapSyscall(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error)
|
||||
|
||||
func unmap(addr uintptr, size int) error {
|
||||
_, _, errno := syscall.Syscall(sys_MUNMAP, addr, uintptr(size), 0)
|
||||
if errno != 0 {
|
||||
return errno
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// pageSize aligned.
|
||||
func mmap(size int) (uintptr, int, error) {
|
||||
size = roundup(size, osPageSize)
|
||||
// The actual mmap syscall varies by architecture. mmapSyscall provides same
|
||||
// functionality as the unexported funtion syscall.mmap and is declared in
|
||||
// mmap_*_*.go and mmap_fallback.go. To add support for a new architecture,
|
||||
// check function mmap in src/syscall/syscall_*_*.go or
|
||||
// src/syscall/zsyscall_*_*.go in Go's source code.
|
||||
p, err := mmapSyscall(0, uintptr(size+pageSize), syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_PRIVATE|syscall.MAP_ANON, -1, 0)
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
|
||||
n := size + pageSize
|
||||
if p&uintptr(osPageMask) != 0 {
|
||||
panic("internal error")
|
||||
}
|
||||
|
||||
mod := int(p) & pageMask
|
||||
if mod != 0 {
|
||||
m := pageSize - mod
|
||||
if err := unmap(p, m); err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
|
||||
n -= m
|
||||
p += uintptr(m)
|
||||
}
|
||||
|
||||
if p&uintptr(pageMask) != 0 {
|
||||
panic("internal error")
|
||||
}
|
||||
|
||||
if n-size != 0 {
|
||||
if err := unmap(p+uintptr(size), n-size); err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
}
|
||||
|
||||
return p, size, nil
|
||||
}
|
||||
35
vendor/modernc.org/memory/mmap_linux_32.go
generated
vendored
Normal file
35
vendor/modernc.org/memory/mmap_linux_32.go
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
// Copyright 2009 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE-GO file.
|
||||
|
||||
//go:build linux && (386 || arm || mips || mipsle)
|
||||
// +build linux
|
||||
// +build 386 arm mips mipsle
|
||||
|
||||
package memory
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// Function syscall.mmap and syscall.mmap2 are same for linux/386, linux/arm,
|
||||
// linux/mips and linux/mipsle
|
||||
|
||||
// https://cs.opensource.google/go/go/+/refs/tags/go1.17.8:src/syscall/syscall_linux_386.go;l=99-105
|
||||
func mmapSyscall(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error) {
|
||||
page := uintptr(offset / 4096)
|
||||
if offset != int64(page)*4096 {
|
||||
return 0, syscall.EINVAL
|
||||
}
|
||||
return mmap2Syscall(addr, length, prot, flags, fd, page)
|
||||
}
|
||||
|
||||
// https://cs.opensource.google/go/go/+/refs/tags/go1.17.8:src/syscall/zsyscall_linux_386.go;l=1361-1370
|
||||
func mmap2Syscall(addr uintptr, length uintptr, prot int, flags int, fd int, pageOffset uintptr) (xaddr uintptr, err error) {
|
||||
r0, _, e1 := syscall.Syscall6(syscall.SYS_MMAP2, uintptr(addr), uintptr(length), uintptr(prot), uintptr(flags), uintptr(fd), uintptr(pageOffset))
|
||||
xaddr = uintptr(r0)
|
||||
if e1 != 0 {
|
||||
err = e1
|
||||
}
|
||||
return
|
||||
}
|
||||
26
vendor/modernc.org/memory/mmap_linux_64.go
generated
vendored
Normal file
26
vendor/modernc.org/memory/mmap_linux_64.go
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright 2009 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE-GO file.
|
||||
|
||||
//go:build linux && (amd64 || arm64 || mips64 || mips64le || riscv64 || ppc64le || loong64)
|
||||
// +build linux
|
||||
// +build amd64 arm64 mips64 mips64le riscv64 ppc64le loong64
|
||||
|
||||
package memory
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// Function syscall.mmap is same for linux/amd64, linux/arm64, linux/mips64,
|
||||
// linux/mips64le and linux/riscv64.
|
||||
|
||||
// https://cs.opensource.google/go/go/+/refs/tags/go1.17.8:src/syscall/zsyscall_linux_amd64.go;l=1575-1584
|
||||
func mmapSyscall(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error) {
|
||||
r0, _, e1 := syscall.Syscall6(syscall.SYS_MMAP, uintptr(addr), uintptr(length), uintptr(prot), uintptr(flags), uintptr(fd), uintptr(offset))
|
||||
xaddr = uintptr(r0)
|
||||
if e1 != 0 {
|
||||
err = e1
|
||||
}
|
||||
return
|
||||
}
|
||||
23
vendor/modernc.org/memory/mmap_linux_s390x.go
generated
vendored
Normal file
23
vendor/modernc.org/memory/mmap_linux_s390x.go
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
// Copyright 2009 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE-GO file.
|
||||
|
||||
package memory
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// https://cs.opensource.google/go/go/+/refs/tags/go1.17.8:src/syscall/syscall_linux_s390x.go;l=105-115
|
||||
// Linux on s390x uses the old mmap interface, which requires arguments to be passed in a struct.
|
||||
// mmap2 also requires arguments to be passed in a struct; it is currently not exposed in <asm/unistd.h>.
|
||||
func mmapSyscall(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error) {
|
||||
mmap_args := [6]uintptr{addr, length, uintptr(prot), uintptr(flags), uintptr(fd), uintptr(offset)}
|
||||
r0, _, e1 := syscall.Syscall(syscall.SYS_MMAP, uintptr(unsafe.Pointer(&mmap_args[0])), 0, 0)
|
||||
xaddr = uintptr(r0)
|
||||
if e1 != 0 {
|
||||
err = e1
|
||||
}
|
||||
return
|
||||
}
|
||||
22
vendor/modernc.org/memory/mmap_netbsd_32.go
generated
vendored
Normal file
22
vendor/modernc.org/memory/mmap_netbsd_32.go
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
// Copyright 2009 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE-GO file.
|
||||
|
||||
//go:build (netbsd && 386) || (netbsd && arm)
|
||||
// +build netbsd,386 netbsd,arm
|
||||
|
||||
package memory
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// https://cs.opensource.google/go/go/+/refs/tags/go1.17.8:src/syscall/zsyscall_freebsd_386.go
|
||||
func mmapSyscall(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) {
|
||||
r0, _, e1 := syscall.Syscall9(syscall.SYS_MMAP, uintptr(addr), uintptr(length), uintptr(prot), uintptr(flag), uintptr(fd), 0, uintptr(pos), uintptr(pos>>32), 0)
|
||||
ret = uintptr(r0)
|
||||
if e1 != 0 {
|
||||
err = e1
|
||||
}
|
||||
return
|
||||
}
|
||||
22
vendor/modernc.org/memory/mmap_netbsd_64.go
generated
vendored
Normal file
22
vendor/modernc.org/memory/mmap_netbsd_64.go
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
// Copyright 2009 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE-GO file.
|
||||
|
||||
//go:build netbsd && amd64
|
||||
// +build netbsd,amd64
|
||||
|
||||
package memory
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// https://cs.opensource.google/go/go/+/refs/tags/go1.17.8:src/syscall/zsyscall_netbsd_amd64.go;l=1190
|
||||
func mmapSyscall(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) {
|
||||
r0, _, e1 := syscall.Syscall9(syscall.SYS_MMAP, uintptr(addr), uintptr(length), uintptr(prot), uintptr(flag), uintptr(fd), 0, uintptr(pos), 0, 0)
|
||||
ret = uintptr(r0)
|
||||
if e1 != 0 {
|
||||
err = e1
|
||||
}
|
||||
return
|
||||
}
|
||||
97
vendor/modernc.org/memory/mmap_openbsd.go
generated
vendored
Normal file
97
vendor/modernc.org/memory/mmap_openbsd.go
generated
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
// Copyright 2011 Evan Shaw. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE-MMAP-GO file.
|
||||
|
||||
// Modifications (c) 2024 The Memory Authors.
|
||||
// Copyright 2024 The Memory 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 openbsd && (386 || amd64 || arm64)
|
||||
|
||||
package memory
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// track what can be unmapped
|
||||
var allocmap map[uintptr][]byte
|
||||
var m sync.Mutex
|
||||
|
||||
const pageSizeLog = 20
|
||||
|
||||
var (
|
||||
osPageMask = osPageSize - 1
|
||||
osPageSize = os.Getpagesize()
|
||||
)
|
||||
|
||||
func init() {
|
||||
allocmap = make(map[uintptr][]byte)
|
||||
}
|
||||
|
||||
func unmap(addr uintptr, size int) error {
|
||||
if trace {
|
||||
fmt.Fprintf(os.Stderr, "unmap %#x\n", addr)
|
||||
}
|
||||
|
||||
a, ok := allocmap[addr]
|
||||
if !ok {
|
||||
if trace {
|
||||
fmt.Fprintf(os.Stderr, "unmap %#x: not found\n", addr)
|
||||
}
|
||||
// panic("unmap called on unknown mapping")
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := unix.Munmap(a); err != nil {
|
||||
if trace {
|
||||
fmt.Fprintf(os.Stderr, "unmap: %s\n", err.Error())
|
||||
}
|
||||
// panic(err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
m.Lock()
|
||||
delete(allocmap, addr)
|
||||
m.Unlock()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func mmap(size int) (uintptr, int, error) {
|
||||
roundsize := roundup(size, osPageSize) + pageSize
|
||||
|
||||
b, err := unix.Mmap(-1, 0, roundsize, unix.PROT_READ|unix.PROT_WRITE, unix.MAP_PRIVATE|unix.MAP_ANON)
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
|
||||
p := uintptr(unsafe.Pointer(&b[0]))
|
||||
|
||||
if trace {
|
||||
fmt.Fprintf(os.Stderr, "mmap actual @%#x size: %#x\n", p, roundsize)
|
||||
}
|
||||
|
||||
// waste all the space until the next page
|
||||
r := (p + uintptr(pageSize)) &^ uintptr(pageMask)
|
||||
nsize := (roundsize) - int((r - p))
|
||||
if nsize < size {
|
||||
panic("didn't allocate enough to meet initial request!")
|
||||
}
|
||||
|
||||
if trace {
|
||||
fmt.Fprintf(os.Stderr, "mmap page-rounded @%#x size: %#x\n", r, nsize)
|
||||
}
|
||||
|
||||
m.Lock()
|
||||
allocmap[r] = b
|
||||
m.Unlock()
|
||||
|
||||
return r, nsize, nil
|
||||
}
|
||||
74
vendor/modernc.org/memory/mmap_unix.go
generated
vendored
Normal file
74
vendor/modernc.org/memory/mmap_unix.go
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
// Copyright 2011 Evan Shaw. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE-MMAP-GO file.
|
||||
|
||||
//go:build darwin || dragonfly || freebsd || linux || (solaris && !illumos) || netbsd
|
||||
// +build darwin dragonfly freebsd linux solaris,!illumos netbsd
|
||||
|
||||
// Modifications (c) 2017 The Memory Authors.
|
||||
|
||||
package memory // import "modernc.org/memory"
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
const pageSizeLog = 20
|
||||
|
||||
var (
|
||||
osPageMask = osPageSize - 1
|
||||
osPageSize = os.Getpagesize()
|
||||
)
|
||||
|
||||
func unmap(addr uintptr, size int) error {
|
||||
_, _, errno := syscall.Syscall(syscall.SYS_MUNMAP, addr, uintptr(size), 0)
|
||||
if errno != 0 {
|
||||
return errno
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// pageSize aligned.
|
||||
func mmap(size int) (uintptr, int, error) {
|
||||
size = roundup(size, osPageSize)
|
||||
|
||||
// The actual mmap syscall varies by architecture. mmapSyscall provides same
|
||||
// functionality as the unexported funtion syscall.mmap and is declared in
|
||||
// mmap_*_*.go and mmap_fallback.go. To add support for a new architecture,
|
||||
// check function mmap in src/syscall/syscall_*_*.go or
|
||||
// src/syscall/zsyscall_*_*.go in Go's source code.
|
||||
p, err := mmapSyscall(0, uintptr(size+pageSize), syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_PRIVATE|syscall.MAP_ANON, -1, 0)
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
|
||||
n := size + pageSize
|
||||
if p&uintptr(osPageMask) != 0 {
|
||||
panic("internal error")
|
||||
}
|
||||
|
||||
mod := int(p) & pageMask
|
||||
if mod != 0 {
|
||||
m := pageSize - mod
|
||||
if err := unmap(p, m); err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
|
||||
n -= m
|
||||
p += uintptr(m)
|
||||
}
|
||||
|
||||
if p&uintptr(pageMask) != 0 {
|
||||
panic("internal error")
|
||||
}
|
||||
|
||||
if n-size != 0 {
|
||||
if err := unmap(p+uintptr(size), n-size); err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
}
|
||||
|
||||
return p, size, nil
|
||||
}
|
||||
49
vendor/modernc.org/memory/mmap_windows.go
generated
vendored
Normal file
49
vendor/modernc.org/memory/mmap_windows.go
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
// Copyright 2017 The Memory 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 memory // import "modernc.org/memory"
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
const (
|
||||
_MEM_COMMIT = 0x1000
|
||||
_MEM_RESERVE = 0x2000
|
||||
_MEM_DECOMMIT = 0x4000
|
||||
_MEM_RELEASE = 0x8000
|
||||
|
||||
_PAGE_READWRITE = 0x0004
|
||||
_PAGE_NOACCESS = 0x0001
|
||||
)
|
||||
|
||||
const pageSizeLog = 16
|
||||
|
||||
var (
|
||||
modkernel32 = syscall.NewLazyDLL("kernel32.dll")
|
||||
osPageMask = osPageSize - 1
|
||||
osPageSize = os.Getpagesize()
|
||||
procVirtualAlloc = modkernel32.NewProc("VirtualAlloc")
|
||||
procVirtualFree = modkernel32.NewProc("VirtualFree")
|
||||
)
|
||||
|
||||
// pageSize aligned.
|
||||
func mmap(size int) (uintptr, int, error) {
|
||||
size = roundup(size, pageSize)
|
||||
addr, _, err := procVirtualAlloc.Call(0, uintptr(size), _MEM_COMMIT|_MEM_RESERVE, _PAGE_READWRITE)
|
||||
if err.(syscall.Errno) != 0 || addr == 0 {
|
||||
return addr, size, err
|
||||
}
|
||||
return addr, size, nil
|
||||
}
|
||||
|
||||
func unmap(addr uintptr, size int) error {
|
||||
r, _, err := procVirtualFree.Call(addr, 0, _MEM_RELEASE)
|
||||
if r == 0 {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
10
vendor/modernc.org/memory/nocounters.go
generated
vendored
Normal file
10
vendor/modernc.org/memory/nocounters.go
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
// Copyright 2017 The Memory 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 !memory.counters
|
||||
// +build !memory.counters
|
||||
|
||||
package memory // import "modernc.org/memory"
|
||||
|
||||
const counters = false
|
||||
10
vendor/modernc.org/memory/trace_disabled.go
generated
vendored
Normal file
10
vendor/modernc.org/memory/trace_disabled.go
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
// Copyright 2017 The Memory 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 !memory.trace
|
||||
// +build !memory.trace
|
||||
|
||||
package memory // import "modernc.org/memory"
|
||||
|
||||
const trace = false
|
||||
10
vendor/modernc.org/memory/trace_enabled.go
generated
vendored
Normal file
10
vendor/modernc.org/memory/trace_enabled.go
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
// Copyright 2017 The Memory 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 memory.trace
|
||||
// +build memory.trace
|
||||
|
||||
package memory // import "modernc.org/memory"
|
||||
|
||||
const trace = true
|
||||
Reference in New Issue
Block a user