微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > Arm Linux系统调用流程详细解析

Arm Linux系统调用流程详细解析

时间:11-09 来源:互联网 点击:

3.__SYSCALL_DEFINEx

#ifdef CONFIG_HAVE_SYSCALL_WRAPPERS#define SYSCALL_DEFINE(name) static inline long SYSC_##name#define __SYSCALL_DEFINEx(x, name, ...)                    \asmlinkage long sys##name(__SC_DECL##x(__VA_ARGS__));        \static inline long SYSC##name(__SC_DECL##x(__VA_ARGS__));    \asmlinkage long SyS##name(__SC_LONG##x(__VA_ARGS__))        \{                                \__SC_TEST##x(__VA_ARGS__);                \return (long) SYSC##name(__SC_CAST##x(__VA_ARGS__));    \}                                \SYSCALL_ALIAS(sys##name, SyS##name);                \static inline long SYSC##name(__SC_DECL##x(__VA_ARGS__))#else /* CONFIG_HAVE_SYSCALL_WRAPPERS */#define SYSCALL_DEFINE(name) asmlinkage long sys_##name#define __SYSCALL_DEFINEx(x, name, ...)                    \asmlinkage long sys##name(__SC_DECL##x(__VA_ARGS__))#endif /* CONFIG_HAVE_SYSCALL_WRAPPERS */

4.__SC_开头的宏

#define __SC_DECL1(t1, a1)    t1 a1#define __SC_DECL2(t2, a2, ...) t2 a2, __SC_DECL1(__VA_ARGS__)#define __SC_DECL3(t3, a3, ...) t3 a3, __SC_DECL2(__VA_ARGS__)#define __SC_DECL4(t4, a4, ...) t4 a4, __SC_DECL3(__VA_ARGS__)#define __SC_DECL5(t5, a5, ...) t5 a5, __SC_DECL4(__VA_ARGS__)#define __SC_DECL6(t6, a6, ...) t6 a6, __SC_DECL5(__VA_ARGS__)#define __SC_LONG1(t1, a1)     long a1#define __SC_LONG2(t2, a2, ...) long a2, __SC_LONG1(__VA_ARGS__)#define __SC_LONG3(t3, a3, ...) long a3, __SC_LONG2(__VA_ARGS__)#define __SC_LONG4(t4, a4, ...) long a4, __SC_LONG3(__VA_ARGS__)#define __SC_LONG5(t5, a5, ...) long a5, __SC_LONG4(__VA_ARGS__)#define __SC_LONG6(t6, a6, ...) long a6, __SC_LONG5(__VA_ARGS__)#define __SC_CAST1(t1, a1)    (t1) a1#define __SC_CAST2(t2, a2, ...) (t2) a2, __SC_CAST1(__VA_ARGS__)#define __SC_CAST3(t3, a3, ...) (t3) a3, __SC_CAST2(__VA_ARGS__)#define __SC_CAST4(t4, a4, ...) (t4) a4, __SC_CAST3(__VA_ARGS__)#define __SC_CAST5(t5, a5, ...) (t5) a5, __SC_CAST4(__VA_ARGS__)#define __SC_CAST6(t6, a6, ...) (t6) a6, __SC_CAST5(__VA_ARGS__)...

5.针对SYSCALL_DEFINE1(close, unsigned int, fd)来分析一下

SYSCALL_DEFINE1(close, unsigned int, fd)根据#define SYSCALL_DEFINE1(name, ...) SYSCALL_DEFINEx(1, _##name, __VA_ARGS__)

化简SYSCALL_DEFINEx(1, _close, __VA_ARGS__),根据SYSCALL_DEFINEx的定义

化简__SYSCALL_DEFINEx(1, _close, __VA_ARGS__) 根据__SYSCALL_DEFINEx的定义

#define __SYSCALL_DEFINEx(1, _close, ...)                \asmlinkage long sys_close(__SC_DECL1(__VA_ARGS__));        \static inline long SYSC_close(__SC_DECL1(__VA_ARGS__));    \asmlinkage long SyS_close(__SC_LONG1(__VA_ARGS__))        \{                            \__SC_TEST1(__VA_ARGS__);                \return (long) SYSC_close(__SC_CAST1(__VA_ARGS__));    \}                            \SYSCALL_ALIAS(sys_close, SyS_close);                \static inline long SYSC_close(__SC_DECL1(__VA_ARGS__))

这里__VA_ARGS__是可变参数宏,可以认为等于unsigned int, fd

根据__SC_宏化简

#define __SYSCALL_DEFINEx(1, _close, ...)                \asmlinkage long sys_close(unsigned int fd);            \static inline long SYSC_close(unsigned int fd);        \asmlinkage long SyS_close(long fd))                \{                            \BUILD_BUG_ON(sizeof(unsigned int) > sizeof(long))    \return (long) SYSC_close((unsigned int)fd);        \}                            \SYSCALL_ALIAS(sys_close, SyS_close);                \static inline long SYSC_close(unsigned int fd)

声明了sys_close函数

定义了SyS_close函数,函数体调用SYSC_close函数,并返回其返回值

SYSCALL_ALIAS宏

#define SYSCALL_ALIAS(alias, name)                    \asm ("\t.globl " #alias "\n\t.set " #alias ", " #name)

插入汇编代码 让执行sys_close等同于执行SYS_close

#define SYSCALL_ALIAS(alias, name)                    \asm ("\t.globl " #alias "\n\t.set " #alias ", " #name)

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top