Re: asmlinkage

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

 



On Thu, Apr 01, 2004 at 19:36:29 -0600, Zhen Liu wrote:
> >On Thu, Apr 01, 2004 at 16:41:29 +0200, Eric wrote:
> >> Hi,
> >>
> >>
> >> "All system calls are marked with the asmlinkage tag, so they all look
> >> to the stack for arguments"
> >> From kernelnewbies.org on the FAQ at "What is asmlinkage ?".
> >>
> >> I find this a bit strange :)
> >> Let's take the exemple of the system call dup(0).
> >> The C funtion dup() will call the real dup system call (by tne Interrupt
> >> Software int 0x80). But the arguments of the real system call have to be
> >> passed on registers (0 on ebx for the example).
> >> Becoz when we call a system call, we're generally in user space. So the
> >> stack is different.
> >> So why  system calls are marked with the asmlinkage tag ? I don't
> >> understand.
> 
> >So they all look to the stack for arguments!
> 
> >> Or perhaps there's or i make a confusion between system call and C
> >> function wrapper of system calls.
> 
> >You are probably confusing the user-space and the kernel-space side of
> >the thing. On the user-side, the wrapper takes arguments from the stack
> >and loads them to the registers. And calls the trap. Now the kernel
> >parts comes to play. It does some setup and calls the sys_* function.
> >But the arguments are still in registers. So the asmlinkage tells the
> >compiler, that the function will have the args in registers and not on
> >the stack, as would be expected for C function.
> 
> Correct me if I am wrong.
> As my understanding, "asmlinkage" tells the compiler that the function
> should find the args on stack instead of register. The reason to do so is to
> disable some of confusion caused by compiler optimization, since the
> optimization may use the register to pass args instead of stack. You can
> find a piece of code in entry.S. Before calling the system call, the kernel
> saves all register onto stack using "SAVE_ALL", so that the system call
> functions can always find their args on the stack.

You are right. Just checked the definition. It says:
__attribute__((regparm(0))) So yes, the syscall gets arguments from the
stack, really.

Actualy, it is only defined that way on i386. On ia64 it says
__attribute__((syscall_linkage)) and for all other architectures, it is
just empty.

-------------------------------------------------------------------------------
						 Jan 'Bulb' Hudec <bulb@ucw.cz>

Attachment: signature.asc
Description: Digital signature


[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