func findSyscallNum()

in cmd/seccomp-profiler/disasm/disasm.go [151:172]


func findSyscallNum(instructions []string, syscall *Syscall, matchers ...*regexp.Regexp) error {
	for i := len(instructions) - 1; i >= 0; i-- {
		line := instructions[i]

		for _, regex := range matchers {
			matches := regex.FindStringSubmatch(line)
			if len(matches) != 2 {
				continue
			}

			num, err := strconv.ParseInt(matches[1], 0, 64)
			if err != nil {
				return fmt.Errorf("failed to parse syscall number %v: %v", matches[1], err)
			}
			syscall.Num = int(num)
			syscall.Assembly = matches[0]
			return nil
		}
	}

	return fmt.Errorf("assembly instruction for loading the syscall number was not found")
}