|
5 | 5 | // |
6 | 6 | // Components that key per-build offsets on a uname fingerprint store rows of |
7 | 7 | // the form |
8 | | -// {0x<16-hex hash>, 0x<offset>}, // <release> <version> |
9 | | -// where the hash was produced by the offline table generator. This harness |
| 8 | +// {0x<16-hex hash>, <offset(s)>}, // <release> <version> |
| 9 | +// where <offset(s)> is one offset or a { ... } array, and the hash was produced |
| 10 | +// by the offline table generator. This harness |
10 | 11 | // recomputes kasld_fnv1a64() over each row's uname comment and asserts it |
11 | 12 | // equals the stored hash, so the runtime hash and the generator's cannot |
12 | 13 | // silently drift: a build whose row is present matches its own row exactly. It |
@@ -68,21 +69,24 @@ static int cmp_row(const void *a, const void *b) { |
68 | 69 | return (x > y) - (x < y); |
69 | 70 | } |
70 | 71 |
|
71 | | -/* Parse one table row "{0x<hash>, 0x<off>}, // <uname>". Returns 1 and fills |
72 | | - * *hash / *uname (into the caller's line buffer) on a match, else 0. */ |
| 72 | +/* Parse one hashed table row "{0x<hash>, <...>}, // <uname>", where <...> is a |
| 73 | + * single offset (qemu) or a { ... } offset array (bpf). Only the hash and the |
| 74 | + * uname comment are checked, so whatever sits between them is ignored. Returns |
| 75 | + * 1 and fills *hash / *uname (into the caller's line buffer) on a match, else |
| 76 | + * 0. */ |
73 | 77 | static int parse_row(char *line, uint64_t *hash, char **uname) { |
74 | 78 | char *p = line, *end; |
75 | 79 | while (*p == ' ' || *p == '\t') |
76 | 80 | p++; |
77 | 81 | if (*p != '{' || p[1] != '0' || p[2] != 'x') |
78 | 82 | return 0; |
79 | 83 | *hash = strtoull(p + 1, &end, 16); |
80 | | - if (strncmp(end, ", 0x", 4) != 0) |
| 84 | + if (*end != ',') /* a hashed row is "{0x<hash>, <offset(s)>}, // ..." */ |
81 | 85 | return 0; |
82 | | - strtoull(end + 2, &end, 16); /* offset: advance past, value unused here */ |
83 | | - if (strncmp(end, "}, // ", 6) != 0) |
| 86 | + char *c = strstr(end, "// "); /* the uname comment, past any offset(s) */ |
| 87 | + if (!c) |
84 | 88 | return 0; |
85 | | - char *u = end + 6; |
| 89 | + char *u = c + 3; |
86 | 90 | size_t n = strlen(u); |
87 | 91 | while (n > 0 && (u[n - 1] == '\n' || u[n - 1] == '\r')) |
88 | 92 | u[--n] = '\0'; |
|
0 commit comments