From: Dmitry V. Levin Date: Sat, 3 Dec 2016 22:39:19 +0000 (+0000) Subject: Change qual_vec/qual_fault into static fixed size arrays X-Git-Tag: v4.15~27 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=701792d70c30a2ab77adc9eb026a90d2c2b8da72;p=strace Change qual_vec/qual_fault into static fixed size arrays * defs.h (qual_vec, num_quals): Remove. (qual_flags): Move ... * syscall.c: ... here. (num_quals, num_faults, MIN_QUALS, reallocate_vec, reallocate_qual, reallocate_fault): Remove. (qual_vec, qual_fault): Change into static fixed size arrays. (qualify_one): Remove reallocate_qual and reallocate_fault calls. (qualify): Likewise. Replace num_quals and num_faults with MAX_NSYSCALLS. --- diff --git a/defs.h b/defs.h index 7998a16d..f98c8f95 100644 --- a/defs.h +++ b/defs.h @@ -841,8 +841,6 @@ extern const struct_sysent sysent0[]; extern const char *const errnoent0[]; extern const char *const signalent0[]; extern const struct_ioctlent ioctlent0[]; -extern qualbits_t *qual_vec[SUPPORTED_PERSONALITIES]; -#define qual_flags (qual_vec[current_personality]) #if SUPPORTED_PERSONALITIES > 1 extern const struct_sysent *sysent; @@ -860,7 +858,6 @@ extern unsigned nsyscalls; extern unsigned nerrnos; extern unsigned nsignals; extern unsigned nioctlents; -extern unsigned num_quals; #ifdef IN_MPERS_BOOTSTRAP /* Transform multi-line MPERS_PRINTER_DECL statements to one-liners. */ diff --git a/syscall.c b/syscall.c index 1f01adbb..1fd5dde5 100644 --- a/syscall.c +++ b/syscall.c @@ -224,9 +224,6 @@ unsigned nerrnos = nerrnos0; unsigned nsignals = nsignals0; unsigned nioctlents = nioctlents0; -unsigned num_quals; -qualbits_t *qual_vec[SUPPORTED_PERSONALITIES]; - static const unsigned nsyscall_vec[SUPPORTED_PERSONALITIES] = { nsyscalls0, #if SUPPORTED_PERSONALITIES > 1 @@ -257,15 +254,12 @@ enum { > nsyscalls2 ? MAX_NSYSCALLS1 : nsyscalls2 #endif ), - MAX_NSYSCALLS = MAX_NSYSCALLS2, - /* We are ready for arches with up to 255 signals, - * even though the largest known signo is on MIPS and it is 128. - * The number of existing syscalls on all arches is - * larger that 255 anyway, so it is just a pedantic matter. - */ - MIN_QUALS = MAX_NSYSCALLS > 255 ? MAX_NSYSCALLS : 255 + MAX_NSYSCALLS = MAX_NSYSCALLS2 }; +static qualbits_t qual_vec[SUPPORTED_PERSONALITIES][MAX_NSYSCALLS]; +#define qual_flags (qual_vec[current_personality]) + #if SUPPORTED_PERSONALITIES > 1 unsigned current_personality; @@ -389,42 +383,13 @@ static const struct qual_options { { 0, NULL, NULL, NULL }, }; -static void -reallocate_vec(void **vec, unsigned int old_nmemb, - size_t size, unsigned int new_nmemb) -{ - unsigned int p; - - for (p = 0; p < SUPPORTED_PERSONALITIES; ++p) { - vec[p] = xreallocarray(vec[p], new_nmemb, size); - memset(vec[p] + size * old_nmemb, 0, - (new_nmemb - old_nmemb) * size); - } -} - -static void -reallocate_qual(const unsigned int n) -{ - reallocate_vec((void **) qual_vec, num_quals, sizeof(qualbits_t), n); - num_quals = n; -} - struct fault_opts { uint16_t first; uint16_t step; uint16_t err; }; -static unsigned int num_faults; -static struct fault_opts *fault_vec[SUPPORTED_PERSONALITIES]; - -static inline void -reallocate_fault(const unsigned int n) -{ - reallocate_vec((void **) fault_vec, num_faults, - sizeof(struct fault_opts), n); - num_faults = n; -} +static struct fault_opts fault_vec[SUPPORTED_PERSONALITIES][MAX_NSYSCALLS]; static void qualify_one(const unsigned int n, unsigned int bitflag, const int not, @@ -432,11 +397,6 @@ qualify_one(const unsigned int n, unsigned int bitflag, const int not, { int p; - if (num_quals <= n) { - reallocate_qual(n + 1); - reallocate_fault(n + 1); - } - for (p = 0; p < SUPPORTED_PERSONALITIES; p++) { if (pers == p || pers < 0) { if (not) @@ -706,12 +666,7 @@ qualify(const char *s) char *copy; const char *p; int not; - unsigned int i; - - if (num_quals == 0) { - reallocate_qual(MIN_QUALS); - reallocate_fault(MIN_QUALS); - } + int i; opt = &qual_options[0]; for (i = 0; (p = qual_options[i].option_name); i++) { @@ -752,12 +707,12 @@ qualify(const char *s) return; } if (strcmp(s, "all") == 0) { - for (i = 0; i < num_quals; ++i) { + for (i = 0; i < MAX_NSYSCALLS; ++i) { qualify_one(i, opt->bitflag, not, -1, NULL); } return; } - for (i = 0; i < num_quals; ++i) { + for (i = 0; i < MAX_NSYSCALLS; ++i) { qualify_one(i, opt->bitflag, !not, -1, NULL); } copy = xstrdup(s); @@ -997,11 +952,10 @@ inject_syscall_fault_entering(struct tcb *tcp) { if (!tcp->fault_vec[current_personality]) { tcp->fault_vec[current_personality] = - xreallocarray(NULL, num_faults, - sizeof(struct fault_opts)); + xcalloc(MAX_NSYSCALLS, sizeof(struct fault_opts)); memcpy(tcp->fault_vec[current_personality], fault_vec[current_personality], - num_faults * sizeof(struct fault_opts)); + MAX_NSYSCALLS * sizeof(struct fault_opts)); } struct fault_opts *opts = tcb_fault_opts(tcp);