diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2018-12-07 12:48:59 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2018-12-07 12:56:38 +0100 |
| commit | eada53b810e964b4a71c20ab023020f281855fe9 (patch) | |
| tree | 2bbe4b59b3867ab531a3ea1e0dcc72e089892c50 /prog/target.go | |
| parent | 9e8a45fe27025af392abd366d8d31a9be4661ea9 (diff) | |
tools/syz-trace2syz/proggen: fix vma allocation
There are 2 bugs:
1. We always allocate 1 page, even if use more.
2. VMA addresses are not aligned, so most mmap-like functions fail with EINVAL.
The added test currently panics with "unaligned vma address".
Diffstat (limited to 'prog/target.go')
| -rw-r--r-- | prog/target.go | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/prog/target.go b/prog/target.go index f99c45c5b..56fbb860d 100644 --- a/prog/target.go +++ b/prog/target.go @@ -264,6 +264,12 @@ func (pg *ProgGen) Allocate(size uint64) uint64 { return pg.ma.alloc(nil, size) } +func (pg *ProgGen) AllocateVMA(npages uint64) uint64 { + psize := pg.target.PageSize + addr := pg.ma.alloc(nil, (npages+1)*psize) + return (addr + psize - 1) & ^(psize - 1) +} + func (pg *ProgGen) Finalize() (*Prog, error) { if err := pg.p.validate(); err != nil { return nil, err |
