summaryrefslogtreecommitdiff
path: root/vendor/modernc.org/memory
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2024-04-17 17:10:51 +0100
committerLibravatar GitHub <noreply@github.com>2024-04-17 17:10:51 +0100
commitb3f2d441439af9d36096d11036220136588def43 (patch)
tree87e7f8808fed70fa6b3d303bd139f03de67b8621 /vendor/modernc.org/memory
parentupdate to set requesting account when deleting status (#2849) (diff)
downloadgotosocial-b3f2d441439af9d36096d11036220136588def43.tar.xz
bump to modernc.org/sqlite v1.29.7 (#2850)
Diffstat (limited to 'vendor/modernc.org/memory')
-rw-r--r--vendor/modernc.org/memory/AUTHORS3
-rw-r--r--vendor/modernc.org/memory/CONTRIBUTORS3
-rw-r--r--vendor/modernc.org/memory/builder.json6
-rw-r--r--vendor/modernc.org/memory/mmap_openbsd.go96
-rw-r--r--vendor/modernc.org/memory/mmap_unix.go5
5 files changed, 100 insertions, 13 deletions
diff --git a/vendor/modernc.org/memory/AUTHORS b/vendor/modernc.org/memory/AUTHORS
index 06687a287..599ec4063 100644
--- a/vendor/modernc.org/memory/AUTHORS
+++ b/vendor/modernc.org/memory/AUTHORS
@@ -8,6 +8,7 @@
#
# 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>
-Gleb Sakhnov <gleb.sakhnov@gmail.com>
diff --git a/vendor/modernc.org/memory/CONTRIBUTORS b/vendor/modernc.org/memory/CONTRIBUTORS
index 56ea0f100..e26a49e01 100644
--- a/vendor/modernc.org/memory/CONTRIBUTORS
+++ b/vendor/modernc.org/memory/CONTRIBUTORS
@@ -7,7 +7,8 @@
# 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>
-Gleb Sakhnov <gleb.sakhnov@gmail.com>
diff --git a/vendor/modernc.org/memory/builder.json b/vendor/modernc.org/memory/builder.json
new file mode 100644
index 000000000..c84be24ef
--- /dev/null
+++ b/vendor/modernc.org/memory/builder.json
@@ -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)"
+}
diff --git a/vendor/modernc.org/memory/mmap_openbsd.go b/vendor/modernc.org/memory/mmap_openbsd.go
index 0b5e4f1de..24cc0a424 100644
--- a/vendor/modernc.org/memory/mmap_openbsd.go
+++ b/vendor/modernc.org/memory/mmap_openbsd.go
@@ -1,19 +1,97 @@
-// Copyright 2017 The Memory Authors. All rights reserved.
+// 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 386 || amd64 || arm64
-// +build 386 amd64 arm64
+//go:build openbsd && (386 || amd64 || arm64)
package memory
import (
- _ "unsafe"
+ "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()
)
-// 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
+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()
-//go:linkname mmapSyscall syscall.mmap
-func mmapSyscall(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error)
+ return r, nsize, nil
+}
diff --git a/vendor/modernc.org/memory/mmap_unix.go b/vendor/modernc.org/memory/mmap_unix.go
index 93f9b820c..de57b8823 100644
--- a/vendor/modernc.org/memory/mmap_unix.go
+++ b/vendor/modernc.org/memory/mmap_unix.go
@@ -2,8 +2,8 @@
// 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 || openbsd || (solaris && !illumos) || netbsd
-// +build darwin dragonfly freebsd linux openbsd solaris,!illumos netbsd
+//go:build darwin || dragonfly || freebsd || linux || (solaris && !illumos) || netbsd
+// +build darwin dragonfly freebsd linux solaris,!illumos netbsd
// Modifications (c) 2017 The Memory Authors.
@@ -33,6 +33,7 @@ func unmap(addr uintptr, size int) error {
// 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,