-
Notifications
You must be signed in to change notification settings - Fork 304
/
api_proxy.h
61 lines (53 loc) · 2.07 KB
/
api_proxy.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef API_PROXY_H_
#define API_PROXY_H_
#include "ver_control.h"
#include "linux_kernel_api/linux_kernel_api_4_19_81.h"
#include "linux_kernel_api/linux_kernel_api_5_4_61.h"
#include "linux_kernel_api/linux_kernel_api_5_10_43.h"
#include "linux_kernel_api/linux_kernel_api_5_15_41.h"
#include "linux_kernel_api/linux_kernel_api_6_1_75.h"
#include <linux/ctype.h>
#include <asm/uaccess.h>
#include <linux/uaccess.h>
//声明
//////////////////////////////////////////////////////////////////////////
MY_STATIC inline int x_atoi(const char arr[]);
MY_STATIC inline unsigned long x_copy_from_user(void *to, const void __user *from, unsigned long n);
MY_STATIC inline unsigned long x_copy_to_user(void __user *to, const void *from, unsigned long n);
MY_STATIC struct task_struct* x_get_current(void);
//实现
//////////////////////////////////////////////////////////////////////////
MY_STATIC inline int x_atoi(const char arr[]) {
int index = 0;
int flag = 1;
int num = 0;
if (arr == NULL) { return -1; }
while (isspace(arr[index])) { index++; }
if (arr[index] == '-') { flag = -1; }
if (arr[index] == '-' || arr[index] == '+') { index++; }
while (arr[index] >= '0' && arr[index] <= '9') { num = num * 10 + arr[index] - '0'; index++; }
return flag * num;
}
MY_STATIC inline unsigned long x_copy_from_user(void *to, const void __user *from, unsigned long n) {
#ifdef CONFIG_DIRECT_API_USER_COPY
unsigned long __arch_copy_from_user(void* to, const void __user * from, unsigned long n);
return __arch_copy_from_user(to, from, n);
#else
return copy_from_user(to, from, n);
#endif
}
MY_STATIC inline unsigned long x_copy_to_user(void __user *to, const void *from, unsigned long n) {
#ifdef CONFIG_DIRECT_API_USER_COPY
unsigned long __arch_copy_to_user(void __user * to, const void* from, unsigned long n);
return __arch_copy_to_user(to, from, n);
#else
return copy_to_user(to, from, n);
#endif
}
MY_STATIC __always_inline struct task_struct *x_get_current(void)
{
unsigned long sp_el0;
asm ("mrs %0, sp_el0" : "=r" (sp_el0));
return (struct task_struct *)sp_el0;
}
#endif /* API_PROXY_H_ */