sewardj | 92ef1ed | 2006-10-17 01:04:15 +0000 | [diff] [blame^] | 1 | |
| 2 | /* A program which prints its own syscall name-to-number bindings. |
| 3 | Used to generate the basis of include/vki/vki-scnums-aix5.h and |
| 4 | coregrind/m_vkiscnums.c. */ |
| 5 | |
| 6 | #include <stdio.h> |
| 7 | #include <sys/types.h> |
| 8 | #include <unistd.h> |
| 9 | #include <assert.h> |
| 10 | |
| 11 | #include <sys/procfs.h> |
| 12 | |
| 13 | #define NN 100000 |
| 14 | char buf[NN]; |
| 15 | int nbuf = 0; |
| 16 | |
| 17 | int main ( void ) |
| 18 | { |
| 19 | int i; |
| 20 | char name[50]; |
| 21 | sprintf(name, "/proc/%d/sysent", getpid()); |
| 22 | FILE* f = fopen(name, "r"); |
| 23 | assert(f); |
| 24 | nbuf = fread(buf, 1, NN, f); |
| 25 | assert(nbuf > 0 && nbuf <= NN); |
| 26 | |
| 27 | prsysent_t* header = (prsysent_t*)&buf[0]; |
| 28 | if (0) printf("Found %u syscalls\n\n", header->pr_nsyscalls); |
| 29 | |
| 30 | for (i = 0; i < header->pr_nsyscalls; i++) { |
| 31 | printf("%3u %s\n", header->pr_syscall[i].pr_number, |
| 32 | &buf[ header->pr_syscall[i].pr_nameoff ]); |
| 33 | } |
| 34 | |
| 35 | fclose(f); |
| 36 | return 0; |
| 37 | } |