diff options
Diffstat (limited to 'src/basefunc.go')
-rw-r--r-- | src/basefunc.go | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/src/basefunc.go b/src/basefunc.go index 5fff3e8..2f39507 100644 --- a/src/basefunc.go +++ b/src/basefunc.go | |||
@@ -4,32 +4,46 @@ import ( | |||
4 | "bufio" | 4 | "bufio" |
5 | "fmt" | 5 | "fmt" |
6 | "os" | 6 | "os" |
7 | "os/exec" | ||
7 | "path/filepath" | 8 | "path/filepath" |
8 | "regexp" | ||
9 | "strconv" | 9 | "strconv" |
10 | "strings" | 10 | "strings" |
11 | "time" | 11 | "time" |
12 | ) | 12 | ) |
13 | 13 | ||
14 | func figureOutSyscalls() error { | 14 | func figureOutSyscalls() error { |
15 | NRRegex := regexp.MustCompile(`#define __NR_(.*?) (\d+)$`) | 15 | cmd := exec.Command("ausyscall", "--dump") |
16 | file, err := os.Open("/usr/include/asm/unistd_64.h") | 16 | stdout, err := cmd.StdoutPipe() |
17 | if err != nil { | 17 | if err != nil { |
18 | return err | 18 | return err |
19 | } | 19 | } |
20 | defer file.Close() | ||
21 | 20 | ||
22 | scanner := bufio.NewScanner(file) | 21 | if err := cmd.Start(); err != nil { |
23 | for scanner.Scan() { | 22 | return err |
23 | } | ||
24 | |||
25 | scanner := bufio.NewScanner(stdout) | ||
26 | for i := 0; scanner.Scan(); i++ { | ||
27 | if i == 0 { | ||
28 | continue | ||
29 | } | ||
24 | line := scanner.Text() | 30 | line := scanner.Text() |
25 | if NRRegex.MatchString(line) { | 31 | parts := strings.Split(line, "\t") |
26 | match := NRRegex.FindStringSubmatch(line) | 32 | if len(parts) != 2 { |
27 | num, err := strconv.Atoi(match[2]) | 33 | return fmt.Errorf("invalid ausyscall format") |
28 | if err != nil { | ||
29 | return err | ||
30 | } | ||
31 | syscallTable[num] = match[1] | ||
32 | } | 34 | } |
35 | num, err := strconv.Atoi(parts[0]) | ||
36 | if err != nil { | ||
37 | return err | ||
38 | } | ||
39 | syscallTable[num] = parts[1] | ||
40 | } | ||
41 | |||
42 | if err := scanner.Err(); err != nil { | ||
43 | return err | ||
44 | } | ||
45 | if err := cmd.Wait(); err != nil { | ||
46 | return err | ||
33 | } | 47 | } |
34 | return nil | 48 | return nil |
35 | } | 49 | } |