-
Notifications
You must be signed in to change notification settings - Fork 171
Expand file tree
/
Copy pathapi_proxy.h
More file actions
54 lines (45 loc) · 1.77 KB
/
api_proxy.h
File metadata and controls
54 lines (45 loc) · 1.77 KB
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
#ifndef API_PROXY_H_
#define API_PROXY_H_
#include "ver_control.h"
#include "linux_kernel_api.h"
#include <linux/ctype.h>
#include <asm/uaccess.h>
#include <linux/uaccess.h>
#include <linux/slab.h>
//声明
//////////////////////////////////////////////////////////////////////////
static inline int x_atoi(const char arr[]);
static inline bool x_isdigit(char c);
static inline struct task_struct* x_get_current(void);
static inline void * x_kmalloc(size_t size, gfp_t flags);
static inline unsigned long x_copy_from_user(void *to, const void __user *from, unsigned long n);
static inline unsigned long x_copy_to_user(void __user *to, const void *from, unsigned long n);
//实现
//////////////////////////////////////////////////////////////////////////
static inline bool x_isdigit(char c) { return (unsigned)(c - '0') < 10; }
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;
}
static 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;
}
static void * x_kmalloc(size_t size, gfp_t flags) {
return __kmalloc(size, flags);
}
static unsigned long x_copy_from_user(void *to, const void __user *from, unsigned long n) {
return __arch_copy_from_user(to, from, n);
}
static unsigned long x_copy_to_user(void __user *to, const void *from, unsigned long n) {
return __arch_copy_to_user(to, from, n);
}
#endif /* API_PROXY_H_ */