-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvas.c
71 lines (52 loc) · 1.12 KB
/
vas.c
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
60
61
62
63
64
65
66
67
68
69
70
71
/* Trivial fallback implementation
* Check subdirectories for the real ones
*/
#include "vas.h"
#include "vas-internal.h"
#include <stdlib.h>
#include <string.h>
struct vas_t {
pid_t pid;
};
static const char *error;
#define NOT_SELF "memcpy backend only suppports self-operation.";
vas_t *vas_self(void) {
static struct vas_t vas;
if (!vas.pid)
vas.pid = pid_self();
return &vas;
}
vas_t *vas_open(pid_t pid, int flags) {
(void)flags;
if (pid == pid_self())
return vas_self();
error = NOT_SELF;
return NULL;
}
const char *vas_error(vas_t *vas)
{
if (vas)
return NULL;
return error;
}
void vas_clearerror(vas_t *vas)
{
if (vas)
return;
error = NULL;
}
void vas_close(vas_t *vas) {
(void)vas;
}
int vas_read(vas_t *vas, const vas_addr_t src, void* dst, size_t len) {
if (vas != vas_self())
return -1;
memcpy(dst, (const void*)src, len);
return len;
}
int vas_write(vas_t* vas, vas_addr_t dst, const void* src, size_t len) {
if (vas != vas_self())
return -1;
memcpy((void*)dst, src, len);
return len;
}