From b80cc86486c89ec2b9bcdbf013870ae1149ad9e8 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sat, 8 Dec 2018 08:40:03 +0100 Subject: [PATCH] prog: rename ProgGen to Builder golint suggests that "prog.Prog" is a bad naming because everything in prog package is ProgSomething. Rename to Builder, "prog.Builder" sounds right. --- prog/target.go | 14 +++++++------- tools/syz-trace2syz/proggen/proggen.go | 12 ++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/prog/target.go b/prog/target.go index 56fbb860..360e2e60 100644 --- a/prog/target.go +++ b/prog/target.go @@ -237,14 +237,14 @@ func (g *Gen) MutateArg(arg0 Arg) (calls []*Call) { return calls } -type ProgGen struct { +type Builder struct { target *Target ma *memAlloc p *Prog } -func MakeProgGen(target *Target) *ProgGen { - return &ProgGen{ +func MakeProgGen(target *Target) *Builder { + return &Builder{ target: target, ma: newMemAlloc(target.NumPages * target.PageSize), p: &Prog{ @@ -253,24 +253,24 @@ func MakeProgGen(target *Target) *ProgGen { } } -func (pg *ProgGen) Append(c *Call) error { +func (pg *Builder) Append(c *Call) error { pg.target.assignSizesCall(c) pg.target.SanitizeCall(c) pg.p.Calls = append(pg.p.Calls, c) return nil } -func (pg *ProgGen) Allocate(size uint64) uint64 { +func (pg *Builder) Allocate(size uint64) uint64 { return pg.ma.alloc(nil, size) } -func (pg *ProgGen) AllocateVMA(npages uint64) uint64 { +func (pg *Builder) 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) { +func (pg *Builder) Finalize() (*Prog, error) { if err := pg.p.validate(); err != nil { return nil, err } diff --git a/tools/syz-trace2syz/proggen/proggen.go b/tools/syz-trace2syz/proggen/proggen.go index 54850892..cbe324e6 100644 --- a/tools/syz-trace2syz/proggen/proggen.go +++ b/tools/syz-trace2syz/proggen/proggen.go @@ -51,7 +51,7 @@ func parseTree(tree *parser.TraceTree, pid int64, target *prog.Target, progs *[] // Context stores metadata related to a syzkaller program type context struct { - pg *prog.ProgGen + builder *prog.Builder target *prog.Target callSelector *callSelector returnCache returnCache @@ -63,7 +63,7 @@ type context struct { func genProg(trace *parser.Trace, target *prog.Target) *prog.Prog { returnCache := newRCache() ctx := &context{ - pg: prog.MakeProgGen(target), + builder: prog.MakeProgGen(target), target: target, callSelector: newCallSelector(target, returnCache), returnCache: returnCache, @@ -85,11 +85,11 @@ func genProg(trace *parser.Trace, target *prog.Target) *prog.Prog { if call == nil { continue } - if err := ctx.pg.Append(call); err != nil { + if err := ctx.builder.Append(call); err != nil { log.Fatalf("%v", err) } } - p, err := ctx.pg.Finalize() + p, err := ctx.builder.Finalize() if err != nil { log.Fatalf("error validating program: %v", err) } @@ -182,7 +182,7 @@ func (ctx *context) genVma(syzType *prog.VmaType, _ parser.IrType) prog.Arg { if syzType.RangeBegin != 0 || syzType.RangeEnd != 0 { npages = syzType.RangeEnd } - return prog.MakeVmaPointerArg(syzType, ctx.pg.AllocateVMA(npages), npages) + return prog.MakeVmaPointerArg(syzType, ctx.builder.AllocateVMA(npages), npages) } func (ctx *context) genArray(syzType *prog.ArrayType, traceType parser.IrType) prog.Arg { @@ -388,7 +388,7 @@ func (ctx *context) parseProc(syzType *prog.ProcType, traceType parser.IrType) p } func (ctx *context) addr(syzType prog.Type, size uint64, data prog.Arg) prog.Arg { - return prog.MakePointerArg(syzType, ctx.pg.Allocate(size), data) + return prog.MakePointerArg(syzType, ctx.builder.Allocate(size), data) } func (ctx *context) reorderStructFields(syzType *prog.StructType, traceType *parser.GroupType) {