syscall table patch

linas at austin.ibm.com linas at austin.ibm.com
Sat Nov 8 05:48:17 EST 2003


On Fri, Nov 07, 2003 at 10:50:39AM -0600, Hollis Blanchard wrote:
> On Friday, Nov 7, 2003, at 10:36 US/Central, linas at austin.ibm.com wrote:
> >
> > -- table initialization is now done at runtime, rather than at
> >    compile time.
>
> Why?

two reasons:

First reason:
   Because I wanted to define a macro to initialize the 32-bit and 64-bit
   tables at the same time, and couldn't figure out how to do this at
   compile time.

   #define SCTE(slot,handler32,handler64) ...

   SCTE(execve,     sys32_execve,          sys_execve)

   To do a compile time table, one needs to assemble something like

   (void (*)()) sys_call_table[NR_syscalls] = { ..., sys_execve, ...  }

   and so one can't initialize 32 and 64 bit tables with one macro.

Second reason:
   If one does a simple C array such as the following:
   (void (*)()) sys_call_table[NR_syscalls] = { ..., sys_execve, ...  }

   Then its real easy to make off-by-one errors by accidentally
   misplacing an initializer.  This makes it no better (and some ways worse)
   than the current assembler implementation (which is just fine by me,
   except for the occasional off-by-one error that one stupidly commits.)

   The only way to avoid this in C starts getting complicated:

   struct {
      ...
      int execve_entry (char *, char **, char **);
      ... } syscall_table =
      {
      ...
      execve_entry:  sys32_execve,
      ...
      };

   and even that is prone to misalignment with the __NR_execve
   value stored in unistd.h

Which is why the safest thing seems to be a runtime
syscall_table[__NR_execve] = sys32_execve;


So yuck, too long a reply ...



--linas


** Sent via the linuxppc64-dev mail list. See http://lists.linuxppc.org/





More information about the Linuxppc64-dev mailing list