github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/tools/syz-trace2syz/proggen/return_cache.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 package proggen 5 6 import ( 7 "github.com/google/syzkaller/pkg/log" 8 "github.com/google/syzkaller/prog" 9 "github.com/google/syzkaller/tools/syz-trace2syz/parser" 10 ) 11 12 type returnCache map[string]prog.Arg 13 14 func newRCache() returnCache { 15 return make(map[string]prog.Arg) 16 } 17 18 func returnCacheKey(syzType prog.Type, traceType parser.IrType) string { 19 a, ok := syzType.(*prog.ResourceType) 20 if !ok { 21 log.Fatalf("caching non resource type") 22 } 23 return a.Desc.Kind[0] + "-" + traceType.String() 24 } 25 26 func (r returnCache) cache(syzType prog.Type, traceType parser.IrType, arg prog.Arg) { 27 log.Logf(2, "caching resource: %v", returnCacheKey(syzType, traceType)) 28 r[returnCacheKey(syzType, traceType)] = arg 29 } 30 31 func (r returnCache) get(syzType prog.Type, traceType parser.IrType) prog.Arg { 32 result := r[returnCacheKey(syzType, traceType)] 33 log.Logf(2, "fetching resource: %s, val: %s", returnCacheKey(syzType, traceType), result) 34 return result 35 }