3
votes

In linux all socket related system calls are gated throw one system call named socketcall.Its handler is found in /net/socket.c. As one can expect there are a copy_from_user for the arguments and then a switch for all socket functions.

I expected to see in each case a call for a ordinary function , but it seems that there are callings to another system calls. For example the case for 'socket' :

case SYS_SOCKET:
    err = sys_socket(a0, a1, a[2]);
    break; 

sys_socket is also defined in /net/socket.c as :

SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)

My question is why its defined like this. I guess its for backward compatibility, or I have a mistake somewhere?

1

1 Answers

2
votes

man 2 socketcall says that

NOTES On a few architectures, for example ia64, there is no socketcall() system call; instead socket(2), accept(2), bind(2), and so on really are implemented as separate system calls

So, in the case of x86, the socketcall dispatcher is only for x86_32, while x86_64 uses separate system calls for each socket API.