Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 13: System Calls


A third ‘‘type‘‘ of system call acts as a multiplexer. Multiplexers use constants to delegate system calls to
functions that perform very different tasks. A prime example issocketcall(discussed in Chapter 12),
which groups together all network-related calls.

net/socket.c
asmlinkage long sys_socketcall(int call, unsigned long __user *args)
{
unsigned long a[6];
unsigned long a0,a1;
int err;
...
switch(call)
{
case SYS_SOCKET:
err = sys_socket(a0,a1,a[2]);
break;
case SYS_BIND:
err = sys_bind(a0,(struct sockaddr __user *)a1, a[2]);
break;
case SYS_CONNECT:
err = sys_connect(a0, (struct sockaddr __user *)a1, a[2]);
break;
case SYS_LISTEN:
err = sys_listen(a0,a1);
break;
...
case SYS_RECVMSG:
err = sys_recvmsg(a0, (struct msghdr __user *) a1, a[2]);
break;
default:
err = -EINVAL;
break;
}
return err;
}

Formally, only onevoidpointer is passed because the number of system call arguments varies according
to the multiplexing constant. The first task is therefore to determine the required number of arguments
and to fill the individual elements of thea[]array (this involves manipulating pointers and arrays and
is not discussed here). Thecallparameter is then referenced to decide which kernel function will be
responsible for further processing.

Regardless of their complexity, all handler functions have one thing in common. Each function dec-
laration includes the additional (asmlinkage) qualifier, which is not a standard element of C syntax.
asmlinkageis an assembler macro defined in<linkage.h>. What is its purpose? For most platforms, the
answer is very simple — it does nothing at all!

However, the macro is used in conjunction with the GCC enhancement (__attribute__) discussed
in Appendix C on IA-32 and IA-64 systems only in order to inform the compiler of the special calling
conventions for the function (examined in the next section).
Free download pdf