How to use collectCallArgSizes method of compiler Package

Best Syzkaller code snippet using compiler.collectCallArgSizes

gen.go

Source:gen.go Github

copy

Full Screen

...37 res.Values = []uint64{0}38 }39 return res40}41func (comp *compiler) collectCallArgSizes() map[string][]uint64 {42 argPos := make(map[string]ast.Pos)43 callArgSizes := make(map[string][]uint64)44 for _, decl := range comp.desc.Nodes {45 n, ok := decl.(*ast.Call)46 if !ok {47 continue48 }49 // Figure out number of arguments and their sizes for each syscall.50 // For example, we may have:51 // ioctl(fd fd, cmd int32, arg intptr)52 // ioctl$FOO(fd fd, cmd const[FOO])53 // Here we will figure out that ioctl$FOO have 3 args, even that54 // only 2 are specified and that size of cmd is 4 even that55 // normally we would assume it's 8 (intptr).56 argSizes := callArgSizes[n.CallName]57 for i, arg := range n.Args {58 if len(argSizes) <= i {59 argSizes = append(argSizes, comp.ptrSize)60 }61 desc, _, _ := comp.getArgsBase(arg.Type, true)62 typ := comp.genField(arg, comp.ptrSize)63 // Ignore all types with base (const, flags). We don't have base in syscall args.64 // Also ignore resources and pointers because fd can be 32-bits and pointer 64-bits,65 // and then there is no way to fix this.66 // The only relevant types left is plain int types.67 if desc != typeInt {68 continue69 }70 if !comp.target.Int64SyscallArgs && typ.Size() > comp.ptrSize {71 comp.error(arg.Pos, "%v arg %v is larger than pointer size", n.Name.Name, arg.Name.Name)72 continue73 }74 argID := fmt.Sprintf("%v|%v", n.CallName, i)75 if _, ok := argPos[argID]; !ok {76 argSizes[i] = typ.Size()77 argPos[argID] = arg.Pos78 continue79 }80 if argSizes[i] != typ.Size() {81 comp.error(arg.Pos, "%v arg %v is redeclared with size %v, previously declared with size %v at %v",82 n.Name.Name, arg.Name.Name, typ.Size(), argSizes[i], argPos[argID])83 continue84 }85 }86 callArgSizes[n.CallName] = argSizes87 }88 return callArgSizes89}90func (comp *compiler) genSyscalls() []*prog.Syscall {91 callArgSizes := comp.collectCallArgSizes()92 var calls []*prog.Syscall93 for _, decl := range comp.desc.Nodes {94 if n, ok := decl.(*ast.Call); ok && n.NR != ^uint64(0) {95 calls = append(calls, comp.genSyscall(n, callArgSizes[n.CallName]))96 }97 }98 sort.Slice(calls, func(i, j int) bool {99 return calls[i].Name < calls[j].Name100 })101 return calls102}103func (comp *compiler) genSyscall(n *ast.Call, argSizes []uint64) *prog.Syscall {104 var ret prog.Type105 if n.Ret != nil {...

Full Screen

Full Screen

collectCallArgSizes

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fset := token.NewFileSet()4 func main(){5 f(1,2,3,4,5)6 }7 func f(a,b,c,d,e int){8 println(a,b,c,d,e)9 }`10 f, err := parser.ParseFile(fset, "2.go", src, parser.ParseComments)11 if err != nil {12 log.Fatal(err)13 }14 ast.Print(fset, f)15}

Full Screen

Full Screen

collectCallArgSizes

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Hello World")4}5import "fmt"6func main() {7 fmt.Println("Hello World")8}9import "fmt"10func main() {11 fmt.Println("Hello World")12}13import "fmt"14func main() {15 fmt.Println("Hello World")16}17import "fmt"18func main() {19 fmt.Println("Hello World")20}21import "fmt"22func main() {23 fmt.Println("Hello World")24}25import "fmt"26func main() {27 fmt.Println("Hello World")28}29import "fmt"30func main() {31 fmt.Println("Hello World")32}

Full Screen

Full Screen

collectCallArgSizes

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fset := token.NewFileSet()4 f, err := parser.ParseFile(fset, "2.go", nil, parser.ParseComments)5 if err != nil {6 panic(err)7 }8 c := types.Config{Importer: importer{}}9 info := &types.Info{10 Defs: make(map[*ast.Ident]types.Object),11 }12 _, err = c.Check("2.go", fset, []*ast.File{f}, info)13 if err != nil {14 panic(err)15 }16 for _, obj := range info.Defs {17 if obj, ok := obj.(*types.Func); ok {18 fmt.Println(obj.Name(), collectCallArgSizes(obj.Type()))19 }20 }21}22func collectCallArgSizes(typ types.Type) []int {23 sig, ok := typ.(*types.Signature)24 if !ok {25 }26 for i := 0; i < sig.Params().Len(); i++ {27 param := sig.Params().At(i)28 typ := param.Type()29 switch typ := typ.(type) {30 size = int(typ.Size())31 size = int(typ.Elem().Size())32 }33 sizes = append(sizes, size)34 }35}36type importer struct{}37func (importer) Import(path string) (*types.Package, error) {38 if strings.HasPrefix(path, "vendor/") {39 path = path[len("vendor/"):]40 }41 return types.DefaultImporter.Import(path)42}

Full Screen

Full Screen

collectCallArgSizes

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fset := token.NewFileSet()4 f, err := parser.ParseFile(fset, "1.go", nil, 0)5 if err != nil {6 panic(err)7 }8 info := types.Info{9 }10 conf := types.Config{11 }12 pkg, err := conf.Check("test", fset, []*ast.File{f}, &info)13 if err != nil {14 panic(err)15 }16 c := &compiler{17 }18 fn := c.pkg.Scope().Lookup("foo")19 fn2 := c.pkg.Scope().Lookup("bar")20 c.collectCallArgSizes(fn)21 c.collectCallArgSizes(fn2)22 fmt.Println(c.callArgSizes)23}24type compiler struct {25}26func (c *compiler) collectCallArgSizes(fn *types.Func) {27 ft := fn.Type().(*types.Signature)28 params := ft.Params()29 results := ft.Results()30 body := c.info.Defs[fn.Scope().Lookup(fn.Name())].(*types.Func).Decl.(*ast.FuncDecl).Body31 block := body.List[0].(*ast

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful