Skip to content

Commit 18aafca

Browse files
committed
Debug
1 parent 04d3f1b commit 18aafca

File tree

6 files changed

+55
-4
lines changed

6 files changed

+55
-4
lines changed

.github/workflows/compile.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88

99
jobs:
1010
test:
11+
if: ${{ 0 == 1}}
1112
name: Check compilation on untested platforms (go ${{ matrix.go-version }})
1213
runs-on: ubuntu-latest
1314
timeout-minutes: 10
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
name: Test Darwin (go ${{ matrix.go }}, ${{ matrix.host }})
12+
runs-on: ${{ matrix.host }}
13+
timeout-minutes: 10
14+
strategy:
15+
matrix:
16+
go: ['1.26']
17+
host: ['macos-latest']
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Setup Go
24+
uses: actions/setup-go@v5
25+
with:
26+
go-version: ${{ matrix.go }}
27+
cache: true
28+
29+
- name: Run tests
30+
run: |
31+
go test -run 'TestFunc$'
32+
33+
#- name: Run tests (buildmode=exe)
34+
# run: |
35+
# go test -buildmode=exe ./...
36+
37+
#- name: Run tests (buildmode=pie)
38+
# run: |
39+
# go test -buildmode=pie ./...
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88

99
jobs:
1010
test:
11+
if: ${{ 0 == 1}}
1112
name: Test Windows/arm64 (go ${{ matrix.go }}, ${{ matrix.host }})
1213
runs-on: ${{ matrix.host }}
1314
timeout-minutes: 10

.github/workflows/test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88

99
jobs:
1010
test:
11+
if: ${{ 0 == 1}}
1112
name: Test (go ${{ matrix.go }}, ${{ matrix.host }})
1213
runs-on: ${{ matrix.host }}
1314
timeout-minutes: 10

clone.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"unsafe"
1212

1313
"github.com/pboyd/malloc"
14+
15+
"golang.org/x/sys/unix"
1416
)
1517

1618
// cloneFunc makes a copy of a function that persists after the original
@@ -76,6 +78,11 @@ func (a *allocator) init(startSize int) error {
7678
return
7779
}
7880

81+
_, err = be.Grow(nil, 4096)
82+
if err != nil {
83+
return
84+
}
85+
7986
a.Arena = malloc.NewArena(uint64(startSize), malloc.Backend(be))
8087
if a.Arena == nil {
8188
err = errors.New("unable to initialize arena")
@@ -135,7 +142,7 @@ func initMallocBackend() (malloc.ArenaBackend, error) {
135142
minAddress = absMinAddress
136143
}
137144
for addr := text - pageSize - size; addr >= minAddress; addr -= 0x100000 {
138-
be, err := malloc.VirtBackend(size, malloc.MmapAddr(addr), malloc.MmapProt(mprotectExec), malloc.MmapFlags(_MAP_FIXED_NOREPLACE))
145+
be, err := malloc.VirtBackend(size, malloc.MmapAddr(addr), malloc.MmapProt(mprotectExec), malloc.MmapFlags(unix.MAP_JIT|_MAP_FIXED_NOREPLACE))
139146
if err == nil {
140147
return be, nil
141148
}
@@ -148,7 +155,7 @@ func initMallocBackend() (malloc.ArenaBackend, error) {
148155
maxAddress = math.MaxUint
149156
}
150157
for addr := end; addr <= maxAddress; addr += 0x100000 {
151-
be, err := malloc.VirtBackend(size, malloc.MmapAddr(addr), malloc.MmapProt(mprotectExec), malloc.MmapFlags(_MAP_FIXED_NOREPLACE))
158+
be, err := malloc.VirtBackend(size, malloc.MmapAddr(addr), malloc.MmapProt(mprotectExec), malloc.MmapFlags(unix.MAP_JIT|_MAP_FIXED_NOREPLACE))
152159
if err == nil {
153160
return be, nil
154161
}

redefine.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ func Original[T any](fn T) T {
115115
}
116116

117117
if clonedType, ok := cloned.(*clonedFunc[T]); ok {
118-
return clonedType.Func
118+
if clonedType != nil {
119+
return clonedType.Func
120+
}
119121
}
120122

121123
return *((*T)(nil))
@@ -189,7 +191,7 @@ func unsafeFunc[T any](fn T, newFn any) error {
189191

190192
err = mprotect(code, mprotectRWX)
191193
if err != nil {
192-
return err
194+
return fmt.Errorf("mprotect: %v", err)
193195
}
194196
defer mprotect(code, mprotectRX)
195197

0 commit comments

Comments
 (0)