diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2024-10-24 14:33:36 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2024-10-25 07:56:49 +0000 |
| commit | 58bd906d601cde032f83f00e29676146a2f5104a (patch) | |
| tree | 9cebe7fbd9add2ac5119cbd5e9e71676603c50f6 | |
| parent | a316ebdbff3a501a1b041a488b2f22c8783df5f8 (diff) | |
tools/syz-declextract: make fixed header more readable
Combine all fixed header parts in a single raw string literal.
| -rw-r--r-- | sys/linux/auto.txt | 6 | ||||
| -rw-r--r-- | tools/syz-declextract/run.go | 33 |
2 files changed, 21 insertions, 18 deletions
diff --git a/sys/linux/auto.txt b/sys/linux/auto.txt index 6371a8e93..12ca55369 100644 --- a/sys/linux/auto.txt +++ b/sys/linux/auto.txt @@ -1,9 +1,8 @@ # Code generated by syz-declextract. DO NOT EDIT. -include <include/vdso/bits.h> -include <include/linux/types.h> include <drivers/net/ieee802154/mac802154_hwsim.h> include <drivers/net/wireless/virtual/mac80211_hwsim.h> include <include/linux/nl802154.h> +include <include/linux/types.h> include <include/net/nl802154.h> include <include/uapi/linux/batman_adv.h> include <include/uapi/linux/caif/if_caif.h> @@ -98,10 +97,12 @@ include <include/uapi/linux/wireguard.h> include <include/uapi/linux/wwan.h> include <include/uapi/linux/xfrm.h> include <include/uapi/rdma/rdma_netlink.h> +include <include/vdso/bits.h> include <net/netlabel/netlabel_calipso.h> include <net/netlabel/netlabel_cipso_v4.h> include <net/netlabel/netlabel_mgmt.h> include <net/netlabel/netlabel_unlabeled.h> +_ = __NR_mmap2 landlock_rule_type = LANDLOCK_RULE_PATH_BENEATH, LANDLOCK_RULE_NET_PORT resource genl_802_15_4_MAC_family_id_auto[int16] resource genl_HSR_family_id_auto[int16] @@ -1080,7 +1081,6 @@ waitid$auto(which int32, upid int32, infop ptr[inout, siginfo$auto_record], opti waitpid$auto(pid pid, stat_addr ptr[inout, int32], options int32) (automatic) write$auto(fd fd, buf ptr[in, string], count intptr) (automatic) writev$auto(fd intptr, vec ptr[in, iovec$auto_record], vlen intptr) (automatic) -_ = __NR_mmap2 XFRMA_COADDR$auto_record [ a4 int32 diff --git a/tools/syz-declextract/run.go b/tools/syz-declextract/run.go index a680ea12c..40d6497bb 100644 --- a/tools/syz-declextract/run.go +++ b/tools/syz-declextract/run.go @@ -157,6 +157,16 @@ func getMinimalOutput(out string, syscallNames map[string][]string) []string { } func makeOutput(nodes []ast.Node) []byte { + header := ` +# Code generated by syz-declextract. DO NOT EDIT. +include <include/vdso/bits.h> +include <include/linux/types.h> +_ = __NR_mmap2 +` + eh := ast.LoggingHandler + desc := ast.Parse([]byte(header), "", eh) + nodes = append(nodes, desc.Nodes...) + slices.SortFunc(nodes, func(a, b ast.Node) int { return strings.Compare(ast.SerializeNode(a), ast.SerializeNode(b)) }) @@ -179,7 +189,7 @@ func makeOutput(nodes []ast.Node) []byte { continue } structs = append(structs, node) - case *ast.Include, *ast.TypeDef, *ast.Resource, *ast.IntFlags, *ast.NewLine: + case *ast.Include, *ast.TypeDef, *ast.Resource, *ast.IntFlags, *ast.NewLine, *ast.Comment: continue default: _, typ, _ := node.Info() @@ -203,13 +213,6 @@ func makeOutput(nodes []ast.Node) []byte { return a.Name.Name == b.Name.Name }) - autoGeneratedNotice := "# Code generated by syz-declextract. DO NOT EDIT.\n" - commonKernelHeaders := "include <include/vdso/bits.h>\ninclude <include/linux/types.h>" - var netlinkNames []string - mmap2 := "_ = __NR_mmap2\n" - eh := ast.LoggingHandler - desc := ast.Parse([]byte(autoGeneratedNotice+commonKernelHeaders), "", eh) - desc.Nodes = append(desc.Nodes, nodes...) usedNetlink := make(map[string]bool) for _, node := range syscalls { if node.CallName == sendmsg && len(node.Args[1].Type.Args) == 2 && len(node.Args[1].Type.Args[1].Args) > 1 { @@ -222,11 +225,11 @@ func makeOutput(nodes []ast.Node) []byte { continue } } - desc.Nodes = append(desc.Nodes, node) + nodes = append(nodes, node) } - desc.Nodes = append(desc.Nodes, ast.Parse([]byte(mmap2), "", eh).Nodes...) + var netlinkNames []string for _, node := range structs { - desc.Nodes = append(desc.Nodes, node) + nodes = append(nodes, node) name := node.Name.Name if !usedNetlink[name] && !strings.HasSuffix(name, "$auto_record") { netlinkNames = append(netlinkNames, name) @@ -246,11 +249,11 @@ auto_union [ if netlinkUnionParsed == nil { tool.Failf("parsing error") } - desc.Nodes = append(desc.Nodes, netlinkUnionParsed.Nodes...) + nodes = append(nodes, netlinkUnionParsed.Nodes...) - // New lines are added in the parsing step. This is why we need to Format (serialize the description), Parse, then - // Format again. - return ast.Format(ast.Parse(ast.Format(desc), "", eh)) + // New lines are added in the parsing step. This is why we need to Format (serialize the description), + // Parse, then Format again. + return ast.Format(ast.Parse(ast.Format(&ast.Description{nodes}), "", eh)) } func worker(outputs chan output, files chan string, binary, compilationDatabase, format string) { |
