Skip to content

Commit 92d0de5

Browse files
committed
mach_vm: add MachMakeMemoryEntry
Signed-off-by: Koichi Shiraishi <[email protected]>
1 parent 2519561 commit 92d0de5

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

Diff for: mach_vm.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33

44
package mach
55

6-
import "github.com/go-darwin/sys"
6+
import (
7+
"unsafe"
8+
9+
"github.com/go-darwin/sys"
10+
)
711

812
//go:cgo_import_dynamic mach_vm_allocate mach_vm_allocate "/usr/lib/libSystem.B.dylib"
913

@@ -32,3 +36,17 @@ func MachVMDeallocate(target VMMap, address MachVMAddress, size MachVMSize) erro
3236

3337
return nil
3438
}
39+
40+
//go:cgo_import_dynamic mach_make_memory_entry _mach_make_memory_entry "/usr/lib/libSystem.B.dylib"
41+
42+
var mach_make_memory_entry_trampoline_addr uintptr
43+
44+
// MachMakeMemoryEntry allow pagers to create named entries that point to un-mapped abstract memory object.
45+
func MachMakeMemoryEntry(targetTask VMMap, size *MemoryObjectSize, offset MemoryObjectOffset, permission VMProt, objectHandle *MemEntryNamePort, parentHandle MemEntryNamePort) error {
46+
_, _, errno := sys.Ccall9(mach_make_memory_entry_trampoline_addr, uintptr(targetTask), uintptr(unsafe.Pointer(&size)), uintptr(offset), uintptr(permission), uintptr(unsafe.Pointer(&objectHandle)), uintptr(parentHandle), 0, 0, 0)
47+
if errno != 0 {
48+
return sys.KernReturn(errno)
49+
}
50+
51+
return nil
52+
}

Diff for: mach_vm.s

+6
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,9 @@ DATA ·mach_vm_deallocate_trampoline_addr(SB)/8, $mach_vm_deallocate_trampoline<
1717

1818
TEXT mach_vm_deallocate_trampoline<>(SB), NOSPLIT, $0-0
1919
JMP mach_vm_deallocate(SB)
20+
21+
GLOBL ·mach_make_memory_entry_trampoline_addr(SB), RODATA, $8
22+
DATA ·mach_make_memory_entry_trampoline_addr(SB)/8, $mach_make_memory_entry_trampoline<>(SB)
23+
24+
TEXT mach_make_memory_entry_trampoline<>(SB), NOSPLIT, $0-0
25+
JMP mach_make_memory_entry(SB)

Diff for: types_darwin_amd64.go

+3
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,9 @@ type (
435435
MachVoucherAttrKey = C.mach_voucher_attr_key_t
436436
MachVoucherAttrRawRecipe = C.mach_voucher_attr_raw_recipe_t
437437
MachVoucherAttrRawRecipeArray = C.mach_voucher_attr_raw_recipe_array_t
438+
MemEntryNamePort = C.mem_entry_name_port_t
439+
MemoryObjectOffset = C.memory_object_offset_t
440+
MemoryObjectSize = C.memory_object_size_t
438441
Natural = C.natural_t
439442
SleepType = C.sleep_type_t
440443
ThreadPort = C.thread_port_t

Diff for: ztypes_darwin_amd64.go

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)