Kernel layer:
1. Kernel Arch/x86/kernel/syscall_table_32.s
. Long Sys_mysyscall/* 285 * * Available
2. Arch/x86/include/asm/unistd_32.h
#define __nr_mysyscall 285
3. Add function code
asmlinkage int Sys_mysyscall (int n)
{
PRINTK ("This are My syscall\n");
return n;
}
User layer:
2.6.15 Times Unistd.h also has the following macros:
_syscall0 (Type,name)
2.6.32 has abolished these macros, changed it to the Syscall function, used man syscall to view the usage, and the extra need to modify sys/syscall.h, which is actually bits/syscall.h.
1. Add #define Sys_mysyscall __nr_mysyscall, you can use Syscall (Sys_mysyscall, ...) To invoke the.
2. Add #define __nr_mysyscall 285 in/usr/include/asm/unistd_32.h.
If you do not do the above two steps, you can only use Syscall (285, ...) To invoke.
#define _GNU_SOURCE/* or _bsd_source or _svid_source * *
#include <unistd.h>
#include <sys/syscall.h>/* for SYS_XXX Definitions * *
int syscall (int number, ...);
The actual system call in the kernel is defined using the Syscall_definex in Include/linux/syscalls.h:
#ifdef Config_ftrace_syscalls
#define SYSCALL_DEFINEX (x, sname, ...) \
static const char *types_# #sname [] = {\
__sc_str_tdecl# #x (__va_args__) \
}; \
static const char *args_# #sname [] = {\
__sc_str_adecl# #x (__va_args__) \
}; \
Syscall_metadata (sname, x); \
__syscall_definex (x, sname, __va_args__)
#else
#define SYSCALL_DEFINEX (x, sname, ...) \
__syscall_definex (x, sname, __va_args__)
#endif
#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 * *
Example:
Syscall_define2 (gettimeofday, struct timeval __user *, TV,
struct TimeZone __user *, TZ)
{
if (likely (TV!= NULL)) {
struct Timeval KTV;
Do_gettimeofday (&KTV);
if (Copy_to_user (TV, &ktv, sizeof (KTV))
Return-efault;
}
if (Unlikely (TZ!= NULL)) {
if (Copy_to_user (TZ, &sys_tz, sizeof (SYS_TZ))
Return-efault;
}
return 0;
}