sys_sendto的函数实现

Question

I am trying to explore the implementation of the "sendto" socket function. I tried to find an implementation in Linux.

In Linux, sendto function corresponds to "sys_sendto" system call.When I tried to follow it, I only found one definition for it which is the following:

asmlinkage long sys_sendto (void) attribute((weak,alias("sys_ni_syscall"))

That's to say sys_sendto is nothing than an alias to sys_ni_syscall, which does nothing more than returning a value. That does not make sense, as far as I am concerned. Where to find sys_snedto implementation? Is it implemented by some Assembly code?


Answers:



It’s in net/socket.cline 1747 of v3.10-rc7.

/*
 *  Send a datagram to a given address. We move the address into kernel
 *  space and check the user space data area is readable before invoking
 *  the protocol.
 */

SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
        unsigned int, flags, struct sockaddr __user *, addr,
        int, addr_len)
{
    struct socket *sock;
    struct sockaddr_storage address;
...

The SYSCALL_DEFINE6 macro is the macro for defining syscalls that take six arguments. It’s defined in include/linux/syscalls.h. It’s pretty complicated, so let’s start by looking at what happens in the no-argument version:

#define SYSCALL_DEFINE0(sname)                                  \
        SYSCALL_METADATA(_##sname, 0);                          \
        asmlinkage long sys_##sname(void)

A system call like getuid(), defined in kernel/sys.c, is coded like this:

SYSCALL_DEFINE0(getuid)
{
    /* Only we change this so SMP safe */
    return from_kuid_munged(current_user_ns(), current_uid());
}

The macro expands out to

SYSCALL_METADATA(_##sname, 0);
asmlinkage long sys_getuid(void)
{
    /* Only we change this so SMP safe */
    return from_kuid_munged(current_user_ns(), current_uid());
}

Which is a straightforward definition of the function sys_getuid.

The metadata is optionally compiled into the kernel for tracing. See the source in syscalls.hfor the details.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值