13

I'm currently learning about operating systems the use of traps to facilitate system calls within the Linux kernel. I've located the table of the traps in traps.c and the implementation of many of the traps within entry.S.

However, I'm instructed to find an implementation of two system calls in the Linux kernel which utilize traps to implement a system call. Although I can find the definition of the traps themselves, I'm not sure what a "call" to one of these traps within the kernel would look like. Therefore, I'm struggling to find an example of this behavior.

Before anyone asks, yes, this is homework.

As a note, I'm using Github to browse the kernel source, since kernel.org is down: https://github.com/torvalds/linux/

3
  • 2
    The good sort of homework question :)
    – James
    Sep 13, 2011 at 20:01
  • 6
    Use lxr.linux.no to browse linux source. Will save you tons of time ;)
    – rumpel
    Sep 13, 2011 at 20:06
  • @rumpel: never heard of it.. looks quite plain. is there anything special here that isn't available with vim+ctags? Sep 13, 2011 at 21:50

3 Answers 3

7

For the x86 architecture the SYCALL_VECTOR (0x80) interrupt is used only for 32bit kernels. You can see the interrupt vector layout in arch/x86/include/asm/irq_vectors.h. The trap_init() function from traps.c is the one that sets the trap handler defined in entry_32.S:

set_system_trap_gate(SYSCALL_VECTOR, &system_call);

For the 64bit kernels, the new SYSENTER (Intel) or SYSCALL (AMD) intructions are used for performance reasons. The syscall_init() function from arch/x86/kernel/cpu/common.c sets up the "handler" defined in entry_64.S and bearing the same name (system_call).

For the user-space perspetive you might want to take a look at this page (a bit outdated for the function/file names).

0

I'm instructed to find an implementation of two system calls in the Linux kernel which utilize traps to implement a system call

Every system call utilizes a trap (interrupt 0x80 if I recall correctly) so the "kernel" bit will be turned on in PSW, and privileged operations will be available to the processor.

As you mentioned the system calls are specified in entry.S under sys_call_table: and they all start with the "sys" prefix.

you can find the system call function header in: include/linux/syscalls.h, you can find it here: http://lxr.linux.no/#linux+v3.0.4/include/linux/syscalls.h

Use lxr (as the comment above have already mentioned) in general in order to browse the source code.

Anyhow, the function are implemented using the SYSCALL_DEFINE1 or othe versions of the macro, see http://lxr.linux.no/#linux+v3.0.4/kernel/sys.c

3
  • 1
    There are also fastcalls that don't require an interrupt. I'm not to sure on how they are implemented so you'll have to google for it, i'm sorry.
    – RedX
    Sep 13, 2011 at 21:45
  • @RedX You're right in general but I'm pretty sure that the system calls in Entry.S below 'sys_call_table` are implemented with an interrupt (After briefly reading the code)
    – Guy L
    Sep 13, 2011 at 22:01
  • 2
    @RedX There are SYSENTER/SYSEXIT instructions in x86 which are probably what you are thinking of: articles.manugarg.com/systemcallinlinux2_6.html
    – SoapBox
    Sep 13, 2011 at 22:03
0

If you're looking for an actual system call, not an implementation of a system call, maybe you want to check some C libraries. Why would a kernel include a system call? (I'm not talking about a system call implementation, I'm talking about e.g. an actual chdir call for example. There is a chdir system call, which is a request for changing the directory and there is a chdir system call implementation which actually changes it and must be somewhere in the kernel). Ok, maybe some kernels do include some syscalls too but that's another story :)

Anyway, if I get your question right, you're not looking for an implementation but an actual call. GNU libc is too complicated for me, but you can try browsing the dietlibc sources. Some examples:

chdir.S

syscalls.h

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.