From 67234372ef1e27c87a6be2e0141d70ae797231a1 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sat, 18 Apr 2020 12:36:52 +0200 Subject: 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. --- sys/windows/init.go | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'sys/windows') 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), } } -- cgit mrf-deployment