sys_sendto的函数实现
来源:互联网 发布:逛淘宝流量消耗异常 编辑:程序博客网 时间:2024/06/17 22:54
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.c
, line 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.h
for the details.
- sys_sendto的函数实现
- send、sendto与sys_sendto之间的关系
- 虚函数的实现
- memcpy函数的实现
- strcpy函数的实现
- strcmp函数的实现
- strtok函数的实现
- atoi函数的实现
- memmove函数的实现
- 函数OMX_MasterInit()的实现
- OmxComponentFactoryDynamicCreate()函数的实现
- INTC_ActivateInterrupt函数的实现
- strtok函数的实现
- strcpy函数的实现
- strcmp函数的实现
- strlen函数的实现
- strcmp函数的实现
- strcpy函数的实现
- 优化数据页面(4)——使用加粗字型突出标题行
- Android高手之路之获取正在运行的service,以及判断某个service是否正在运行
- 栈和堆的数组访问之异
- Spark源码分析(七)存储管理2
- Swift学习(逻辑篇)
- sys_sendto的函数实现
- 好记性不如烂笔头20-java对oracle的clob和blob字段的总结
- Oracle逻辑结构
- 揭秘PHP深受Web开发者喜爱的原因
- uva 10012 How Big Is It?(枚举)
- iOS性能优化系列
- hdu 1251 统计难题 字典树水题
- hibernate.hbm2ddl.auto配置详解
- Swift学习---日期计算小练习