github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/tools/syz-trace2syz/proggen/fuzz.go (about)

     1  // Copyright 2018 syzkaller project authors. All rights reserved.
     2  // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
     3  
     4  //go:build !codeanalysis
     5  
     6  package proggen
     7  
     8  import (
     9  	"github.com/google/syzkaller/prog"
    10  	_ "github.com/google/syzkaller/sys/linux/gen" // pull in the target
    11  	"github.com/google/syzkaller/sys/targets"
    12  )
    13  
    14  var linuxTarget = func() *prog.Target {
    15  	target, err := prog.GetTarget(targets.Linux, targets.AMD64)
    16  	if err != nil {
    17  		panic(err)
    18  	}
    19  	target.ConstMap = make(map[string]uint64)
    20  	for _, c := range target.Consts {
    21  		target.ConstMap[c.Name] = c.Value
    22  	}
    23  	return target
    24  }()
    25  
    26  func Fuzz(data []byte) int {
    27  	progs, err := ParseData(data, linuxTarget)
    28  	if err != nil {
    29  		return 0
    30  	}
    31  	return len(progs)
    32  }