[PATCH v3 5/6] Optimize default filtering

Victor Krapivensky krapivenskiy.va at phystech.edu
Mon Jul 3 15:43:37 UTC 2017


On Mon, Jul 03, 2017 at 03:03:15PM +0300, Eugene Syromiatnikov wrote:
> On Thu, Jun 29, 2017 at 02:46:14PM +0700, Nikolay Marchuk wrote:
> > * filter_action.c (default_flags, clear_default_flags): Add default flags.
> > (add_action): Use action type as argument. Clear default flags.
> > (filter_syscall): Add default_flags to qual_flg.
> > * strace.c (init): Remove default filters.
> There's also another change, change in the add_action function
> signature, and the presence of this change here (and its non-incorporation
> into the initial "Introduce new filtering architecture" patch) is not justified.
> 
> > ---
> >  filter_action.c | 30 ++++++++++++++++++++++++------
> >  strace.c        |  3 ---
> >  2 files changed, 24 insertions(+), 9 deletions(-)
> > 
> > diff --git a/filter_action.c b/filter_action.c
> > index fd3fa92..0c235da 100644
> > --- a/filter_action.c
> > +++ b/filter_action.c
> > @@ -88,6 +88,7 @@ struct filter_action {
> >  	void* _priv_data;
> >  };
> >  
> > +static int default_flags = DEFAULT_QUAL_FLAGS;
> >  static struct filter_action *filter_actions;
> >  static unsigned int nfilter_actions;
> >  
> > @@ -103,10 +104,28 @@ compare_action_priority(const void *a, const void *b)
> >  void
> >  sort_filter_actions(void)
> >  {
> > +	if (nfilter_actions == 0)
> > +		return;
> I'm pretty sure qsort exits rather early when an empty array is provided,
> does this additional check actually bring any speed benefit for the one-time
> action?

Actually, passing a non-dereferencable pointer as a first argument to
qsort is UB, even if the second argument is 0:

http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf

Subclause 7.1.4 Use of library functions, point 1:

> Each of the following statements applies unless explicitly stated
> otherwise in the detailed descriptions that follow: If an argument
> to a function has an invalid value (such as a value outside the
> domain of the function, or a pointer outside the address space of
> the program, or a null pointer, or a pointer to non-modifiable
> storage when the corresponding parameter is not const-qualified) or
> a type (after promotion) not expected by a function with variable
> number of arguments, the behavior is undefined. If a function
> argument is described as being an array, the pointer actually passed
> to the function shall have a value such that all address
> computations and accesses to objects (that would be valid if the
> pointer did point to the first element of such an array) are in fact
> valid.

Subclause 7.20.5 Searching and sorting utilites, point 1:

> These utilities make use of a comparison function to search or sort
> arrays of unspecified type. Where an argument declared as size_t
> nmemb specifies the length of the array for a function, nmemb can
> have the value zero on a call to that function; the comparison
> function is not called, a search finds no matching element, and
> sorting performs no rearrangement. Pointer arguments on such a call
> shall still have valid values, as described in 7.1.4.




More information about the Strace-devel mailing list