@@ -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 }
0 commit comments