Le 19/03/2020 à 14:35, Andy Shevchenko a écrit :
On Thu, Mar 19, 2020 at 1:54 PM Michal Suchanek <msucha...@suse.de> wrote:

Merge the 32bit and 64bit version.

Halve the check constants on 32bit.

Use STACK_TOP since it is defined.

Passing is_64 is now redundant since is_32bit_task() is used to
determine which callchain variant should be used. Use STACK_TOP and
is_32bit_task() directly.

This removes a page from the valid 32bit area on 64bit:
  #define TASK_SIZE_USER32 (0x0000000100000000UL - (1 * PAGE_SIZE))
  #define STACK_TOP_USER32 TASK_SIZE_USER32

...

+static inline int valid_user_sp(unsigned long sp)
+{
+       bool is_64 = !is_32bit_task();
+
+       if (!sp || (sp & (is_64 ? 7 : 3)) || sp > STACK_TOP - (is_64 ? 32 : 16))
+               return 0;
+       return 1;
+}

Perhaps better to read

   if (!sp)
     return 0;

   if (is_32bit_task()) {
     if (sp & 0x03)
       return 0;
     if (sp > STACK_TOP - 16)
       return 0;
   } else {
     ...
   }

   return 1;

Other possibility:

I prefer this one.


   unsigned long align = is_32bit_task() ? 3 : 7;

I would call it mask instead of align

   unsigned long top = STACK_TOP - (is_32bit_task() ? 16 : 32);

   return !(!sp || (sp & align) || sp > top);


Christophe

Reply via email to