Skip to content

Instantly share code, notes, and snippets.

@cwshu
Created April 2, 2017 08:38
Show Gist options
  • Save cwshu/823b95ed4c6aebdd0d535ec12a97912c to your computer and use it in GitHub Desktop.
Save cwshu/823b95ed4c6aebdd0d535ec12a97912c to your computer and use it in GitHub Desktop.
#include "syscalls.h"
SYSCALL_DEFINE2(add, int, a, int, b){
return a + b;
}
// partial s2.i, only paste functions related to system call add
asmlinkage long sys_add(int a, int b)
__attribute__((alias(__stringify(SyS_add))));
static inline long SYSC_add(int a, int b);
asmlinkage long SyS_add(
__typeof(__builtin_choose_expr((__same_type((int)0, 0LL) || __same_type((int)0, 0ULL)), 0LL, 0L)) a,
__typeof(__builtin_choose_expr((__same_type((int)0, 0LL) || __same_type((int)0, 0ULL)), 0LL, 0L)) b);
asmlinkage long SyS_add(
__typeof(__builtin_choose_expr((__same_type((int)0, 0LL) || __same_type((int)0, 0ULL)), 0LL, 0L)) a,
__typeof(__builtin_choose_expr((__same_type((int)0, 0LL) || __same_type((int)0, 0ULL)), 0LL, 0L)) b) {
long ret = SYSC_add((int) a, (int) b);
(void)BUILD_BUG_ON_ZERO(!(__same_type((int)0, 0LL) || __same_type((int)0, 0ULL)) && sizeof(int) > sizeof(long)),
(void)BUILD_BUG_ON_ZERO(!(__same_type((int)0, 0LL) || __same_type((int)0, 0ULL)) && sizeof(int) > sizeof(long));
asmlinkage_protect(2, ret, a, b);
return ret;
}
static inline long SYSC_add(int a, int b){
return a + b;
}
@cwshu
Copy link
Author

cwshu commented Apr 2, 2017

without define CONFIG_FTRACE_SYSCALLS

@cwshu
Copy link
Author

cwshu commented Apr 2, 2017

@cwshu
Copy link
Author

cwshu commented Apr 2, 2017

@cwshu
Copy link
Author

cwshu commented Apr 2, 2017

some ref of C Macro:
https://gcc.gnu.org/onlinedocs/cpp/index.html#SEC_Contents
3.4 Stringizing: #
3.5 Concatenation: ##
3.6 Varadic Macro: __VA_ARGS__
I think ch3.5's example is good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment