Re: RESTORE_ALL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jan 16, 2002 at 08:00:17AM +0000, Mark Zealey wrote:
> On Wed, Jan 16, 2002 at 05:44:56AM +0000, John Levon wrote:
> 
> > 
> > can someone explain the purpose of this code :
> > 
> > #define RESTORE_ALL     \
> > 	[snip]
> > 1:      popl %ds;       \
> > 2:      popl %es;       \
> >         addl $4,%esp;   \
> > 3:      iret;           \
> > .section .fixup,"ax";   \
> > 4:      movl $0,(%esp); \
> >         jmp 1b;         \
> > 5:      movl $0,(%esp); \
> >         jmp 2b;         \
> > 6:      pushl %ss;      \
> >         popl %ds;       \
> >         pushl %ss;      \
> >         popl %es;       \
> >         pushl $11;      \
> >         call do_exit;   \
> > .previous;              \
> > .section __ex_table,"a";\
> >         .align 4;       \
> >         .long 1b,4b;    \
> >         .long 2b,5b;    \
> >         .long 3b,6b;    \
> > 
> > Now, I understand the exception table stuff (fault at 1 ends up at 4 etc.) but I am
> > unable to fathom what it's actually for. Ideas ?
> 
> OK, I was gonna say 'I dunno' but, looking closer at it, it looks like it
> handles the cases where we were called from an invalid ds or es, or if we can't
> iret (bad cs/esp/ss/eip/whatever). In the first 2, it just writes 0 to them, in
> the last case, it kills the process.

Hmm, it's sort of described in "Understanding the linux kernel" (page
134), but nothing about the .fixup ane __ex_table sections. However,
from a long, long time ago in a galaxy far, far away, I remember that
at the start of a new development series (I think it was linux-2.1)
Linus modified the exception handlers in such a way that they could
handle exceptions from kernel mode.

In the old days you had to call verify_area() before you touched a
userland buffer with copy_from_user() et. al. That was slow because the
kernel actually checked the process memory space to see if the memory
was valid, and in 99% of the cases the memory *was* indeed safe to
access. That made it a prime candidate for speeding up, and the
__ex_table section magic exactly did that.

I think you can still find the magic explained in a linux-kernel
archive, though I think it we used news:comp.os.linux.development or
news:linux.dev.kernel at that time. I remember posting a message with
benchmark results at that time, so you could try to look for my name. I
think it was somewhere around linux-2.1.4, but it could also be around
linux-1.3.4.


Erik

-- 
J.A.K. (Erik) Mouw, Information and Communication Theory Group, Faculty
of Information Technology and Systems, Delft University of Technology,
PO BOX 5031, 2600 GA Delft, The Netherlands  Phone: +31-15-2783635
Fax: +31-15-2781843  Email: J.A.K.Mouw@its.tudelft.nl
WWW: http://www-ict.its.tudelft.nl/~erik/
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
IRC Channel:   irc.openprojects.net / #kernelnewbies
Web Page:      http://www.kernelnewbies.org/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux