Fix build on older kernels without BPF.
PATCH 1/1 Fix build on older kernels without BPF.
--- configure | 1 + syscalls/bpf.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 0 deletions(-)
configure +1 -0
@@ -239,6 +239,7 @@ check_header execinfo.h USE_BACKTRACE check_header netatalk/at.h USE_APPLETALK check_header netrom/netrom.h USE_NETROM check_header netrose/rose.h USE_ROSE +check_header linux/bpf.h USE_BPF rm -f "$TMP" "$TMP.log" "$TMP.c"
syscalls/bpf.c +14 -0
@@ -1,13 +1,16 @@/* * SYSCALL_DEFINE3(bpf, int, cmd, union bpf_attr __user *, uattr, unsigned int, size) */ +#ifdef USE_BPF #include <linux/bpf.h> +#endif #include <linux/filter.h> #include "arch.h" #include "net.h" #include "random.h" #include "sanitise.h" +#ifdef USE_BPF static unsigned long bpf_prog_types[] = {BPF_PROG_TYPE_UNSPEC , BPF_PROG_TYPE_SOCKET_FILTER,
@@ -15,9 +18,11 @@ static unsigned long bpf_prog_types[] = {BPF_PROG_TYPE_SCHED_CLS , BPF_PROG_TYPE_SCHED_ACT, }; +#endif static const char license[] ="GPLv2" ; +#ifdef USE_BPF static void bpf_prog_load (struct syscallrecord *rec) {unsigned long *insns =NULL , len =0 ;
@@ -49,18 +54,22 @@ static void bpf_prog_load(struct syscallrecord *rec) rec->a2 = (unsigned long ) attr; rec->a3 =sizeof (attr); } +#endif static void sanitise_bpf (struct syscallrecord *rec) {switch (rec->a1) { +#ifdef USE_BPF case BPF_PROG_LOAD :bpf_prog_load (rec);break ; +#endif default :break ; } } +#ifdef USE_BPF static void post_bpf (struct syscallrecord *rec) {union bpf_attr *attr;
@@ -84,10 +93,15 @@ static void post_bpf(struct syscallrecord *rec) break; } } +#else +static void post_bpf(__unused__ struct syscallrecord *rec) { } +#endif static unsigned long bpf_flags[] = { +#ifdef USE_BPF BPF_MAP_CREATE, BPF_MAP_LOOKUP_ELEM, BPF_MAP_UPDATE_ELEM, BPF_MAP_DELETE_ELEM, BPF_MAP_GET_NEXT_KEY, BPF_PROG_LOAD, +#endif }; struct syscallentry syscall_bpf = {
Signature · 1 line
1.7.1
Quoted 60 lines · Vinson Lee
syscalls/bpf.c +9
-0@@ -1,13 +1,16 @@/* * SYSCALL_DEFINE3(bpf, int, cmd, union bpf_attr __user *, uattr, unsigned int, size) */ +#ifdef USE_BPF #include <linux/bpf.h> +#endif #include <linux/filter.h> #include "arch.h" #include "net.h" #include "random.h" #include "sanitise.h" +#ifdef USE_BPF static unsigned long bpf_prog_types[] = {BPF_PROG_TYPE_UNSPEC , BPF_PROG_TYPE_SOCKET_FILTER,@@ -15,9 +18,11 @@ static unsigned long bpf_prog_types[] = {BPF_PROG_TYPE_SCHED_CLS , BPF_PROG_TYPE_SCHED_ACT, }; +#endif static const char license[] ="GPLv2" ; +#ifdef USE_BPF static void bpf_prog_load (struct syscallrecord *rec) {unsigned long *insns =NULL , len =0 ;@@ -49,18 +54,22 @@ static void bpf_prog_load(struct syscallrecord *rec) rec->a2 = (unsigned long ) attr; rec->a3 =sizeof (attr); } +#endif static void sanitise_bpf (struct syscallrecord *rec) {switch (rec->a1) { +#ifdef USE_BPF case BPF_PROG_LOAD :bpf_prog_load (rec);break ; +#endif default :break ; } } +#ifdef USE_BPF static void post_bpf (struct syscallrecord *rec) {union bpf_attr *attr;@@ -84,10 +93,15 @@ static void post_bpf(struct syscallrecord *rec)break ; } }
syscalls/bpf.c static void post_bpf(struct syscallrecord *rec) · line 105
Quoted 10 lines
syscalls/bpf.c +5
-0+#else +static void post_bpf(__unused__ struct syscallrecord *rec) { } +#endif static unsigned long bpf_flags[] = { +#ifdef USE_BPF BPF_MAP_CREATE ,BPF_MAP_LOOKUP_ELEM ,BPF_MAP_UPDATE_ELEM ,BPF_MAP_DELETE_ELEM , BPF_MAP_GET_NEXT_KEY, BPF_PROG_LOAD, +#endif };
This might be cleaner to wrap the whole of syscalls/bpf.c in one ifdef, and then add additional ones to include/syscalls-*.h to look like
#ifdef USE_BPF
{ .entry = &syscall_bpf },
#else
{ .entry = NULL },#endif
I can't remember if the tables code handles a NULL .entry in the middle though. Might need some tweaking.
Dave
PATCH v2 1/1 Fix build on older kernels without BPF.
--- configure | 1 + include/syscalls-aarch64.h | 2 ++ include/syscalls-arm.h | 2 ++ include/syscalls-i386.h | 2 ++ include/syscalls-ia64.h | 2 ++ include/syscalls-mips.h | 2 ++ include/syscalls-parisc.h | 2 ++ include/syscalls-s390.h | 2 ++ include/syscalls-s390x.h | 2 ++ include/syscalls-sparc.h | 2 ++ include/syscalls-x86_64.h | 2 ++ syscalls/bpf.c | 2 ++ 12 files changed, 23 insertions(+), 0 deletions(-)
configure +1 -0
@@ -239,6 +239,7 @@ check_header execinfo.h USE_BACKTRACE check_header netatalk/at.h USE_APPLETALK check_header netrom/netrom.h USE_NETROM check_header netrose/rose.h USE_ROSE +check_header linux/bfp.h USE_BPF rm -f "$TMP" "$TMP.log" "$TMP.c"
include/syscalls-aarch64.h +2 -0
@@ -290,6 +290,8 @@ struct syscalltable syscalls_aarch64[] = { /* 277 */ { .entry = &syscall_seccomp }, /* 278 */ { .entry = &syscall_getrandom }, /* 279 */ { .entry = &syscall_memfd_create }, +#ifdef USE_BPF /* 280 */ { .entry = &syscall_bpf }, +#endif /* 281 */ { .entry = &syscall_execveat }, };
include/syscalls-arm.h +2 -0
@@ -396,7 +396,9 @@ struct syscalltable syscalls_arm[] = { { .entry = &syscall_seccomp }, { .entry = &syscall_getrandom }, /* 385 */ { .entry = &syscall_memfd_create }, +#ifdef USE_BPF { .entry = &syscall_bpf }, +#endif { .entry = &syscall_execveat }, { .entry = &syscall_userfaultfd }, { .entry = &syscall_membarrier },
include/syscalls-i386.h +2 -0
@@ -364,7 +364,9 @@ struct syscalltable syscalls_i386[] = { { .entry = &syscall_seccomp }, { .entry = &syscall_getrandom }, { .entry = &syscall_memfd_create }, +#ifdef USE_BPF { .entry = &syscall_bpf }, +#endif { .entry = &syscall_execveat }, { .entry = &syscall_socket }, { .entry = &syscall_socketpair },
include/syscalls-ia64.h +2 -0
@@ -324,7 +324,9 @@ struct syscalltable syscalls_ia64[] = { { .entry = &syscall_renameat2 }, { .entry = &syscall_getrandom }, { .entry = &syscall_memfd_create }, +#ifdef USE_BPF { .entry = &syscall_bpf }, +#endif { .entry = &syscall_userfaultfd }, { .entry = &syscall_membarrier }, { .entry = &syscall_kcmp },
include/syscalls-mips.h +2 -0
@@ -371,5 +371,7 @@ struct syscalltable syscalls_mips[] = { { .entry = &syscall_seccomp }, { .entry = &syscall_getrandom }, { .entry = &syscall_memfd_create }, +#ifdef USE_BPF { .entry = &syscall_bpf }, /* 4355 */ +#endif };
include/syscalls-parisc.h +2 -0
@@ -348,6 +348,8 @@ struct syscalltable syscalls_parisc[] = { { .entry = &syscall_seccomp }, { .entry = &syscall_getrandom }, { .entry = &syscall_memfd_create }, +#ifdef USE_BPF { .entry = &syscall_bpf }, +#endif { .entry = &syscall_execveat }, };
include/syscalls-s390.h +2 -0
@@ -358,7 +358,9 @@ struct syscalltable syscalls_s390[] = { { .entry = &syscall_seccomp }, { .entry = &syscall_getrandom }, { .entry = &syscall_memfd_create }, +#ifdef USE_BPF { .entry = &syscall_bpf }, +#endif { .entry = &syscall_ni_syscall }, // TODO: syscall_s390_pci_mmio_write { .entry = &syscall_ni_syscall }, // TODO: syscall_s390_pci_mmio_read { .entry = &syscall_execveat },
include/syscalls-s390x.h +2 -0
@@ -358,7 +358,9 @@ struct syscalltable syscalls_s390x[] = { { .entry = &syscall_seccomp }, { .entry = &syscall_getrandom }, { .entry = &syscall_memfd_create }, +#ifdef USE_BPF { .entry = &syscall_bpf }, +#endif { .entry = &syscall_ni_syscall }, // TODO: syscall_s390_pci_mmio_write { .entry = &syscall_ni_syscall }, // TODO: syscall_s390_pci_mmio_read { .entry = &syscall_execveat },
include/syscalls-sparc.h +2 -0
@@ -356,6 +356,8 @@ struct syscalltable syscalls_sparc[] = { { .entry = &syscall_seccomp }, { .entry = &syscall_getrandom }, { .entry = &syscall_memfd_create }, +#ifdef USE_BPF { .entry = &syscall_bpf }, +#endif { .entry = &syscall_execveat }, };
include/syscalls-x86_64.h +2 -0
@@ -328,7 +328,9 @@ struct syscalltable syscalls_x86_64[] = { { .entry = &syscall_seccomp }, { .entry = &syscall_memfd_create }, { .entry = &syscall_kexec_file_load }, +#ifdef USE_BPF { .entry = &syscall_bpf }, +#endif { .entry = &syscall_execveat }, { .entry = &syscall_userfaultfd }, { .entry = &syscall_membarrier },
syscalls/bpf.c +2 -0
@@ -1,6 +1,7 @@/* * SYSCALL_DEFINE3(bpf, int, cmd, union bpf_attr __user *, uattr, unsigned int, size) */ +#ifdef USE_BPF #include <linux/bpf.h> #include <linux/filter.h> #include "arch.h"
@@ -102,3 +103,4 @@ struct syscallentry syscall_bpf = { .sanitise = sanitise_bpf, .post = post_bpf, }; +#endif
Signature · 1 line
1.7.1
Quoted 2 lines · Vinson Lee
Suggested-by Dave Jones <[email protected]>Signed-off-by Vinson Lee <[email protected]>
Close, but..
include/syscalls-aarch64.h struct syscalltable syscalls_aarch64[] = { · line 297
Quoted 13 lines
include/syscalls-aarch64.h +2
-0@@ -290,6 +290,8 @@ struct syscalltable syscalls_aarch64[] = { /* 277 */ { .entry = &syscall_seccomp }, /* 278 */ { .entry = &syscall_getrandom }, /* 279 */ { .entry = &syscall_memfd_create }, +#ifdef USE_BPF /* 280 */ { .entry = &syscall_bpf }, +#endif /* 281 */ { .entry = &syscall_execveat }, };
You need an
#else
NULL,
for each of these, otherwise the next syscall will be in the wrong slot.
Dave
Quoted 22 lines · Dave Jones
Quoted 2 lines · Vinson Lee
Suggested-by Dave Jones <[email protected]>Signed-off-by Vinson Lee <[email protected]>Close, but..
include/syscalls-aarch64.h struct syscalltable syscalls_aarch64[] = { · line 297
Quoted 13 lines
include/syscalls-aarch64.h +2
-0@@ -290,6 +290,8 @@ struct syscalltable syscalls_aarch64[] = { /* 277 */ { .entry = &syscall_seccomp }, /* 278 */ { .entry = &syscall_getrandom }, /* 279 */ { .entry = &syscall_memfd_create }, +#ifdef USE_BPF /* 280 */ { .entry = &syscall_bpf }, +#endif /* 281 */ { .entry = &syscall_execveat }, };You need an
Quoted 6 lines
#else
NULL,for each of these, otherwise the next syscall will be in the wrong slot.
Dave
I tried making that change but trinity would crash in copy_syscall_table with memcpy with a NULL from[n].entry.
Program received signal SIGSEGV, Segmentation fault. 0x000000000041300e in copy_syscall_table (from=0x63d840, nr=329) at /usr/include/bits/string3.h:52
52 return __builtin___memcpy_chk (__dest, __src, __len, __bos0 (__dest)); (gdb) bt
#0 0x000000000041300e in copy_syscall_table (from=0x63d840, nr=329) at /usr/include/bits/string3.h:52
#1 0x00000000004130f3 in select_syscall_tables () at tables.c:491 #2 0x0000000000413e95 in main (argc=1, argv=0x7fffffffe438) at trinity.c:115
tables.c
470 static struct syscalltable * copy_syscall_table(struct
syscalltable *from, unsigned int nr)
471 {
472 unsigned int n;
473 struct syscallentry *copy;
474
475 copy = alloc_shared(nr * sizeof(struct syscallentry));
476 if (copy == NULL)
477 exit(EXIT_FAILURE);
478
479 for (n = 0; n < nr; n++) {
480 memcpy(copy + n , from[n].entry, sizeof(struct
syscallentry));
481 copy[n].number = n; 482 copy[n].active_number = 0; 483 from[n].entry = ©[n];
484 }
485 return from;
486 }
Vinson
Quoted 27 lines · Vinson Lee
Quoted 1 line
for each of these, otherwise the next syscall will be in the wrong slot.
I tried making that change but trinity would crash in
copy_syscall_tablewith memcpy with a NULL from[n].entry.Program received signal SIGSEGV, Segmentation fault.
0x000000000041300eincopy_syscall_table(from=0x63d840, nr=329) at/usr/include/bits/string3.h:52
52 return__builtin___memcpy_chk(__dest,__src,__len,__bos0(__dest)); (gdb) bt
#00x000000000041300eincopy_syscall_table(from=0x63d840, nr=329) at/usr/include/bits/string3.h:52
#10x00000000004130f3inselect_syscall_tables() at tables.c:491 #20x0000000000413e95in main (argc=1, argv=0x7fffffffe438) at trinity.c:115
tables.c
470 static struct syscalltable * copy_syscall_table(struct
syscalltable *from, unsigned int nr)471 { 472 unsigned int n; 473 struct syscallentry *copy; 474 475 copy = alloc_shared(nr * sizeof(struct syscallentry)); 476 if (copy == NULL) 477 exit(EXIT_FAILURE); 478 479 for (n = 0; n < nr; n++) {
Quoted 8 lines
480 memcpy(copy + n , from[n].entry, sizeof(struct syscallentry)); 481 copy[n].number = n; 482 copy[n].active_number = 0; 483 from[n].entry = ©[n]; 484 } 485 return from; 486 }
stick a
if (from[n] == NULL) continue
before the memcpy. Does that dtrt ?
We might segv somewhere else after patching this up. It's been so long since I touched this stuff I don't fully recall how it works. I'll poke at it some tomorrow.
Dave
Quoted 23 lines · Dave Jones
Quoted 12 lines
tables.c
470 static struct syscalltable * copy_syscall_table(struct
syscalltable *from, unsigned int nr)471 { 472 unsigned int n; 473 struct syscallentry *copy; 474 475 copy = alloc_shared(nr * sizeof(struct syscallentry)); 476 if (copy == NULL) 477 exit(EXIT_FAILURE); 478 479 for (n = 0; n < nr; n++) {Quoted 8 lines
480 memcpy(copy + n , from[n].entry, sizeof(struct syscallentry)); 481 copy[n].number = n; 482 copy[n].active_number = 0; 483 from[n].entry = ©[n]; 484 } 485 return from; 486 }stick a
Quoted 8 lines
if (from[n] == NULL) continuebefore the memcpy. Does that dtrt ?
We might segv somewhere else after patching this up. It's been so long since I touched this stuff I don't fully recall how it works. I'll poke at it some tomorrow.
Just getting around to this. It's a bit more involved than I hoped. Spraying a bunch of null checks around like this seems to be the thing to do..
Let me know how this works out for you.
Dave
configure +1 -0
@@ -239,6 +239,7 @@ check_header execinfo.h USE_BACKTRACE check_header netatalk/at.h USE_APPLETALK check_header netrom/netrom.h USE_NETROM check_header netrose/rose.h USE_ROSE +check_header linux/bfp.h USE_BPFF rm -f "$TMP" "$TMP.log" "$TMP.c"
include/syscalls-aarch64.h +4 -0
@@ -290,6 +290,10 @@ struct syscalltable syscalls_aarch64[] = { /* 277 */ { .entry = &syscall_seccomp }, /* 278 */ { .entry = &syscall_getrandom }, /* 279 */ { .entry = &syscall_memfd_create }, +#ifdef USE_BPF /* 280 */ { .entry = &syscall_bpf }, +#else + { .entry = NULL }, +#endif /* 281 */ { .entry = &syscall_execveat }, };
include/syscalls-arm.h +4 -0
@@ -396,7 +396,11 @@ struct syscalltable syscalls_arm[] = { { .entry = &syscall_seccomp }, { .entry = &syscall_getrandom }, /* 385 */ { .entry = &syscall_memfd_create }, +#ifdef USE_BPF { .entry = &syscall_bpf }, +#else + { .entry = NULL }, +#endif { .entry = &syscall_execveat }, { .entry = &syscall_userfaultfd }, { .entry = &syscall_membarrier },
include/syscalls-i386.h +4 -0
@@ -364,7 +364,11 @@ struct syscalltable syscalls_i386[] = { { .entry = &syscall_seccomp }, { .entry = &syscall_getrandom }, { .entry = &syscall_memfd_create }, +#ifdef USE_BPF { .entry = &syscall_bpf }, +#else + { .entry = NULL }, +#endif { .entry = &syscall_execveat }, { .entry = &syscall_socket }, { .entry = &syscall_socketpair },
include/syscalls-ia64.h +4 -0
@@ -324,7 +324,11 @@ struct syscalltable syscalls_ia64[] = { { .entry = &syscall_renameat2 }, { .entry = &syscall_getrandom }, { .entry = &syscall_memfd_create }, +#ifdef USE_BPF { .entry = &syscall_bpf }, +#else + { .entry = NULL }, +#endif { .entry = &syscall_userfaultfd }, { .entry = &syscall_membarrier }, { .entry = &syscall_kcmp },
include/syscalls-mips.h +4 -0
@@ -371,5 +371,9 @@ struct syscalltable syscalls_mips[] = { { .entry = &syscall_seccomp }, { .entry = &syscall_getrandom }, { .entry = &syscall_memfd_create }, +#ifdef USE_BPF { .entry = &syscall_bpf }, /* 4355 */ +#else + { .entry = NULL }, +#endif };
include/syscalls-parisc.h +4 -0
@@ -348,6 +348,10 @@ struct syscalltable syscalls_parisc[] = { { .entry = &syscall_seccomp }, { .entry = &syscall_getrandom }, { .entry = &syscall_memfd_create }, +#ifdef USE_BPF { .entry = &syscall_bpf }, +#else + { .entry = NULL }, +#endif { .entry = &syscall_execveat }, };
include/syscalls-s390.h +4 -0
@@ -358,7 +358,11 @@ struct syscalltable syscalls_s390[] = { { .entry = &syscall_seccomp }, { .entry = &syscall_getrandom }, { .entry = &syscall_memfd_create }, +#ifdef USE_BPF { .entry = &syscall_bpf }, +#else + { .entry = NULL }, +#endif { .entry = &syscall_ni_syscall }, // TODO: syscall_s390_pci_mmio_write { .entry = &syscall_ni_syscall }, // TODO: syscall_s390_pci_mmio_read { .entry = &syscall_execveat },
include/syscalls-s390x.h +4 -0
@@ -358,7 +358,11 @@ struct syscalltable syscalls_s390x[] = { { .entry = &syscall_seccomp }, { .entry = &syscall_getrandom }, { .entry = &syscall_memfd_create }, +#ifdef USE_BPF { .entry = &syscall_bpf }, +#else + { .entry = NULL }, +#endif { .entry = &syscall_ni_syscall }, // TODO: syscall_s390_pci_mmio_write { .entry = &syscall_ni_syscall }, // TODO: syscall_s390_pci_mmio_read { .entry = &syscall_execveat },
include/syscalls-sparc.h +4 -0
@@ -356,6 +356,10 @@ struct syscalltable syscalls_sparc[] = { { .entry = &syscall_seccomp }, { .entry = &syscall_getrandom }, { .entry = &syscall_memfd_create }, +#ifdef USE_BPF { .entry = &syscall_bpf }, +#else + { .entry = NULL }, +#endif { .entry = &syscall_execveat }, };
include/syscalls-x86_64.h +4 -0
@@ -328,7 +328,11 @@ struct syscalltable syscalls_x86_64[] = { { .entry = &syscall_seccomp }, { .entry = &syscall_memfd_create }, { .entry = &syscall_kexec_file_load }, +#ifdef USE_BPF { .entry = &syscall_bpf }, +#else + { .entry = NULL }, +#endif { .entry = &syscall_execveat }, { .entry = &syscall_userfaultfd }, { .entry = &syscall_membarrier },
syscalls/bpf.c +2 -0
@@ -1,6 +1,7 @@/* * SYSCALL_DEFINE3(bpf, int, cmd, union bpf_attr __user *, uattr, unsigned int, size) */ +#ifdef USE_BPF #include <linux/bpf.h> #include <linux/filter.h> #include "arch.h"
@@ -102,3 +103,4 @@ struct syscallentry syscall_bpf = { .sanitise = sanitise_bpf, .post = post_bpf, }; +#endif
tables-biarch.c +43 -6
121 lines not on this page · raw message
tables-uniarch.c +19 -9
@@ -100,7 +100,11 @@ void mark_all_syscalls_active_uniarch(void)unsigned int i;for_each_syscall (i) { - syscalls[i].entry->flags |=ACTIVE ; +struct syscallentry *entry = syscalls[i].entry; +if (entry ==NULL ) +continue ; + + entry->flags |=ACTIVE ;activate_syscall (i); } }
@@ -110,9 +114,10 @@ void init_syscalls_uniarch(void)unsigned int i;for_each_syscall (i) { -struct syscallentry *entry; +struct syscallentry *entry = syscalls[i].entry; +if (entry ==NULL ) +continue ; - entry = syscalls[i].entry;if (entry->flags &ACTIVE )if (entry->init) entry->init ();
@@ -124,9 +129,11 @@ void deactivate_disabled_syscalls_uniarch(void)unsigned int i;for_each_syscall (i) { -struct syscallentry *entry; +struct syscallentry *entry = syscalls[i].entry; + +if (entry ==NULL ) +continue ; - entry = syscalls[i].entry;if (entry->flags &TO_BE_DEACTIVATED ) { entry->flags &= ~(ACTIVE |TO_BE_DEACTIVATED );deactivate_syscall_uniarch (i);
@@ -143,9 +150,11 @@ void dump_syscall_tables_uniarch(void)outputstd ("syscalls: %d\n" , max_nr_syscalls);for_each_syscall (i) { -struct syscallentry *entry; +struct syscallentry *entry = syscalls[i].entry; + +if (entry ==NULL ) +continue ; - entry = syscalls[i].entry;outputstd ("entrypoint %d %s : " , entry->number, entry->name);show_state (entry->flags &ACTIVE );if (entry->flags &AVOID_SYSCALL )
@@ -159,9 +168,10 @@ void display_enabled_syscalls_uniarch(void)unsigned int i;for_each_syscall (i) { -struct syscallentry *entry; +struct syscallentry *entry = syscalls[i].entry; - entry = syscalls[i].entry; +if (entry ==NULL ) +continue ;if (entry->flags &ACTIVE )output (0 ,"syscall %d:%s enabled.\n" , i, entry->name);
tables.c +22 -6
@@ -211,6 +211,8 @@ static void check_syscall(struct syscallentry *entry) {/* check that we have a name set. */ #define CHECK (NUMARGS ,ARGNUM ,ARGTYPE ,ARGNAME ) \ + if (entry == NULL) \ + return; \ if (entry->num_args > 0) { \ if (entry->num_args > NUMARGS) { \ if (entry->ARGNAME == NULL) { \
@@ -231,6 +233,8 @@ static void check_syscall(struct syscallentry *entry)/* note: not enabled by default, because we haven't annotated everything yet. */ #undef CHECK#define CHECK (NUMARGS ,ARGNUM ,ARGTYPE ,ARGNAME ) \ + if (entry == NULL) \ + return; \ if (entry->num_args > 0) { \ if (entry->num_args > NUMARGS) { \ if (entry->ARGTYPE == ARG_UNDEFINED) { \
@@ -379,6 +383,9 @@ static void show_unannotated_biarch(void)for_each_32bit_syscall (i) { entry = syscalls_32bit[i].entry; +if (entry ==NULL ) +continue ; + count =0 ;for (j =1 ; j <= entry->num_args; j++) {
@@ -415,6 +422,9 @@ static void show_unannotated_biarch(void)for_each_64bit_syscall (i) { entry = syscalls_64bit[i].entry; +if (entry ==NULL ) +continue ; + count =0 ;for (j =1 ; j <= entry->num_args; j++) {
@@ -469,18 +479,24 @@ void show_unannotated_args(void)*/ static struct syscalltable *copy_syscall_table (struct syscalltable *from,unsigned int nr) { -unsigned int n; +unsigned int n, m;struct syscallentry *copy; copy =alloc_shared (nr *sizeof (struct syscallentry ));if (copy ==NULL )exit (EXIT_FAILURE ); -for (n =0 ; n < nr; n++) { -memcpy (copy + n , from[n].entry,sizeof (struct syscallentry )); - copy[n].number = n; - copy[n].active_number =0 ; - from[n].entry = ©[n]; +for (n =0 , m =0 ; n < nr; n++) { +struct syscallentry *entry = from[n].entry; + +if (entry ==NULL ) +continue ; + +memcpy (copy + m , from[n].entry,sizeof (struct syscallentry )); + copy[m].number = n; + copy[m].active_number =0 ; + from[n].entry = ©[m]; + m++; }return from; }
Quoted 6 lines · Dave Jones
Quoted 3 lines
We might segv somewhere else after patching this up. It's been so long since I touched this stuff I don't fully recall how it works. I'll poke at it some tomorrow.
Just getting around to this. It's a bit more involved than I hoped. Spraying a bunch of null checks around like this seems to be the thing to do..
Now committed and pushed out, with an additional typo fix.
Dave