Skip to content

Commit 7bab8bb

Browse files
committed
wazero 1.7.1.
1 parent ce97e82 commit 7bab8bb

File tree

4 files changed

+14
-23
lines changed

4 files changed

+14
-23
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.21
55
require (
66
github.com/ncruces/julianday v1.0.0
77
github.com/psanford/httpreadat v0.1.0
8-
github.com/tetratelabs/wazero v1.7.1-0.20240410111357-a0fbb185447f
8+
github.com/tetratelabs/wazero v1.7.1
99
golang.org/x/crypto v0.22.0
1010
golang.org/x/sync v0.7.0
1111
golang.org/x/sys v0.19.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ github.com/ncruces/julianday v1.0.0 h1:fH0OKwa7NWvniGQtxdJRxAgkBMolni2BjDHaWTxqt
22
github.com/ncruces/julianday v1.0.0/go.mod h1:Dusn2KvZrrovOMJuOt0TNXL6tB7U2E8kvza5fFc9G7g=
33
github.com/psanford/httpreadat v0.1.0 h1:VleW1HS2zO7/4c7c7zNl33fO6oYACSagjJIyMIwZLUE=
44
github.com/psanford/httpreadat v0.1.0/go.mod h1:Zg7P+TlBm3bYbyHTKv/EdtSJZn3qwbPwpfZ/I9GKCRE=
5-
github.com/tetratelabs/wazero v1.7.1-0.20240410111357-a0fbb185447f h1:xJ6F/f7fM1OvnPFSn7Ggf9icswSXoYOYLZbu7aJVQbA=
6-
github.com/tetratelabs/wazero v1.7.1-0.20240410111357-a0fbb185447f/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y=
5+
github.com/tetratelabs/wazero v1.7.1 h1:QtSfd6KLc41DIMpDYlJdoMc6k7QTN246DM2+n2Y/Dx8=
6+
github.com/tetratelabs/wazero v1.7.1/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y=
77
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
88
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
99
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=

internal/util/alloc.go

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"golang.org/x/sys/unix"
1010
)
1111

12-
func mmappedAllocator(min, cap, max uint64) experimental.MemoryBuffer {
12+
func mmappedAllocator(cap, max uint64) experimental.LinearMemory {
1313
// Round up to the page size.
1414
rnd := uint64(unix.Getpagesize() - 1)
1515
max = (max + rnd) &^ rnd
@@ -32,28 +32,17 @@ func mmappedAllocator(min, cap, max uint64) experimental.MemoryBuffer {
3232
unix.Munmap(b)
3333
panic(err)
3434
}
35-
return &mmappedBuffer{
36-
buf: b[:cap],
37-
cur: min,
38-
}
35+
return &mmappedMemory{buf: b[:cap]}
3936
}
4037

4138
// The slice covers the entire mmapped memory:
4239
// - len(buf) is the already committed memory,
43-
// - cap(buf) is the reserved address space,
44-
// - cur is the already requested size.
45-
type mmappedBuffer struct {
40+
// - cap(buf) is the reserved address space.
41+
type mmappedMemory struct {
4642
buf []byte
47-
cur uint64
48-
}
49-
50-
func (m *mmappedBuffer) Buffer() []byte {
51-
// Limit capacity because bytes beyond len(m.buf)
52-
// have not yet been committed.
53-
return m.buf[:m.cur:len(m.buf)]
5443
}
5544

56-
func (m *mmappedBuffer) Grow(size uint64) []byte {
45+
func (m *mmappedMemory) Reallocate(size uint64) []byte {
5746
if com := uint64(len(m.buf)); com < size {
5847
// Round up to the page size.
5948
rnd := uint64(unix.Getpagesize() - 1)
@@ -68,11 +57,12 @@ func (m *mmappedBuffer) Grow(size uint64) []byte {
6857
// Update commited memory.
6958
m.buf = m.buf[:new]
7059
}
71-
m.cur = size
72-
return m.Buffer()
60+
// Limit returned capacity because bytes beyond
61+
// len(m.buf) have not yet been committed.
62+
return m.buf[:size:len(m.buf)]
7363
}
7464

75-
func (m *mmappedBuffer) Free() {
65+
func (m *mmappedMemory) Free() {
7666
err := unix.Munmap(m.buf[:cap(m.buf)])
7767
if err != nil {
7868
panic(err)

internal/util/mmap.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ type mmapState struct {
1919

2020
func (s *mmapState) init(ctx context.Context, enabled bool) context.Context {
2121
if s.enabled = enabled; enabled {
22-
return experimental.WithMemoryAllocator(ctx, mmappedAllocator)
22+
return experimental.WithMemoryAllocator(ctx,
23+
experimental.MemoryAllocatorFunc(mmappedAllocator))
2324
}
2425
return ctx
2526
}

0 commit comments

Comments
 (0)