aboutsummaryrefslogtreecommitdiffstats
path: root/sys/windows
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-04-18 12:36:52 +0200
committerDmitry Vyukov <dvyukov@google.com>2020-04-18 14:35:45 +0200
commit67234372ef1e27c87a6be2e0141d70ae797231a1 (patch)
treee6304ac41f5af586d81d84e31f9c8547754a32d9 /sys/windows
parentea36da8271c508fe4c8bcc80af20ec81c812b95a (diff)
prog: refactor target.MakeMmap
Make MakeMmap return more than 1 call. This is a preparation for future changes. Also remove addr/size as they are effectively always the same and can be inferred from the target (will also conflict with the future changes). Also rename to MakeDataMmap to better represent the new purpose: it's just some arbitrary mmap, but rather mapping of the data segment.
Diffstat (limited to 'sys/windows')
-rw-r--r--sys/windows/init.go25
1 files changed, 15 insertions, 10 deletions
diff --git a/sys/windows/init.go b/sys/windows/init.go
index 5c1a1e9a9..6a245cdba 100644
--- a/sys/windows/init.go
+++ b/sys/windows/init.go
@@ -9,16 +9,18 @@ import (
func InitTarget(target *prog.Target) {
arch := &arch{
+ target: target,
virtualAllocSyscall: target.SyscallMap["VirtualAlloc"],
MEM_COMMIT: target.GetConst("MEM_COMMIT"),
MEM_RESERVE: target.GetConst("MEM_RESERVE"),
PAGE_EXECUTE_READWRITE: target.GetConst("PAGE_EXECUTE_READWRITE"),
}
- target.MakeMmap = arch.makeMmap
+ target.MakeDataMmap = arch.makeMmap
}
type arch struct {
+ target *prog.Target
virtualAllocSyscall *prog.Syscall
MEM_COMMIT uint64
@@ -26,16 +28,19 @@ type arch struct {
PAGE_EXECUTE_READWRITE uint64
}
-func (arch *arch) makeMmap(addr, size uint64) *prog.Call {
+func (arch *arch) makeMmap() []*prog.Call {
meta := arch.virtualAllocSyscall
- return &prog.Call{
- Meta: meta,
- Args: []prog.Arg{
- prog.MakeVmaPointerArg(meta.Args[0], addr, size),
- prog.MakeConstArg(meta.Args[1], size),
- prog.MakeConstArg(meta.Args[2], arch.MEM_COMMIT|arch.MEM_RESERVE),
- prog.MakeConstArg(meta.Args[3], arch.PAGE_EXECUTE_READWRITE),
+ size := arch.target.NumPages * arch.target.PageSize
+ return []*prog.Call{
+ &prog.Call{
+ Meta: meta,
+ Args: []prog.Arg{
+ prog.MakeVmaPointerArg(meta.Args[0], 0, size),
+ prog.MakeConstArg(meta.Args[1], size),
+ prog.MakeConstArg(meta.Args[2], arch.MEM_COMMIT|arch.MEM_RESERVE),
+ prog.MakeConstArg(meta.Args[3], arch.PAGE_EXECUTE_READWRITE),
+ },
+ Ret: prog.MakeReturnArg(meta.Ret),
},
- Ret: prog.MakeReturnArg(meta.Ret),
}
}