diff options
Diffstat (limited to 'libraries/evas/src/lib/cserve/evas_cs_mem.c')
-rw-r--r-- | libraries/evas/src/lib/cserve/evas_cs_mem.c | 168 |
1 files changed, 0 insertions, 168 deletions
diff --git a/libraries/evas/src/lib/cserve/evas_cs_mem.c b/libraries/evas/src/lib/cserve/evas_cs_mem.c deleted file mode 100644 index 15edf93..0000000 --- a/libraries/evas/src/lib/cserve/evas_cs_mem.c +++ /dev/null | |||
@@ -1,168 +0,0 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | # include "config.h" | ||
3 | #endif | ||
4 | |||
5 | #include "evas_cs.h" | ||
6 | |||
7 | #ifdef EVAS_CSERVE | ||
8 | |||
9 | EAPI Mem * | ||
10 | evas_cserve_mem_new(int size, const char *name) | ||
11 | { | ||
12 | Mem *m; | ||
13 | static int id = 0; | ||
14 | char buf[PATH_MAX]; | ||
15 | |||
16 | m = calloc(1, sizeof(Mem)); | ||
17 | if (!m) return NULL; | ||
18 | if (name) | ||
19 | snprintf(buf, sizeof(buf), "/evas-shm-%x.%s", getuid(), name); | ||
20 | else | ||
21 | { | ||
22 | id++; | ||
23 | snprintf(buf, sizeof(buf), "/evas-shm-%x.%x.%x", getuid(), getpid(), id); | ||
24 | } | ||
25 | m->id = id; | ||
26 | m->offset = 0; | ||
27 | m->name = strdup(buf); | ||
28 | if (!m->name) | ||
29 | { | ||
30 | free(m); | ||
31 | return NULL; | ||
32 | } | ||
33 | m->size = size; | ||
34 | m->fd = shm_open(m->name, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); | ||
35 | if (m->fd < 0) | ||
36 | { | ||
37 | free(m->name); | ||
38 | free(m); | ||
39 | return NULL; | ||
40 | } | ||
41 | if (ftruncate(m->fd, m->size) < 0) | ||
42 | { | ||
43 | shm_unlink(m->name); | ||
44 | close(m->fd); | ||
45 | free(m->name); | ||
46 | free(m); | ||
47 | return NULL; | ||
48 | } | ||
49 | |||
50 | eina_mmap_safety_enabled_set(EINA_TRUE); | ||
51 | |||
52 | m->data = mmap(NULL, m->size, PROT_READ | PROT_WRITE, MAP_SHARED, m->fd, 0); | ||
53 | if (m->data == MAP_FAILED) | ||
54 | { | ||
55 | shm_unlink(m->name); | ||
56 | close(m->fd); | ||
57 | free(m->name); | ||
58 | free(m); | ||
59 | return NULL; | ||
60 | } | ||
61 | m->ref = 1; | ||
62 | m->write = 1; | ||
63 | return m; | ||
64 | } | ||
65 | |||
66 | EAPI void | ||
67 | evas_cserve_mem_free(Mem *m) | ||
68 | { | ||
69 | shm_unlink(m->name); | ||
70 | munmap(m->data, m->size); | ||
71 | close(m->fd); | ||
72 | free(m->name); | ||
73 | free(m); | ||
74 | } | ||
75 | |||
76 | EAPI Mem * | ||
77 | evas_cserve_mem_open(int pid, int id, const char *name, int size, int do_write) | ||
78 | { | ||
79 | Mem *m; | ||
80 | char buf[PATH_MAX]; | ||
81 | |||
82 | m = calloc(1, sizeof(Mem)); | ||
83 | if (!m) return NULL; | ||
84 | if (name) | ||
85 | snprintf(buf, sizeof(buf), "/evas-shm-%x.%s", getuid(), name); | ||
86 | else | ||
87 | snprintf(buf, sizeof(buf), "/evas-shm-%x.%x.%x", getuid(), pid, id); | ||
88 | m->name = strdup(buf); | ||
89 | if (!m->name) | ||
90 | { | ||
91 | free(m); | ||
92 | return NULL; | ||
93 | } | ||
94 | m->size = size; | ||
95 | if (do_write) | ||
96 | m->fd = shm_open(m->name, O_RDWR, S_IRUSR | S_IWUSR); | ||
97 | else | ||
98 | m->fd = shm_open(m->name, O_RDONLY, S_IRUSR); | ||
99 | if (m->fd < 0) | ||
100 | { | ||
101 | free(m->name); | ||
102 | free(m); | ||
103 | return NULL; | ||
104 | } | ||
105 | m->write = do_write; | ||
106 | |||
107 | eina_mmap_safety_enabled_set(EINA_TRUE); | ||
108 | |||
109 | if (do_write) | ||
110 | m->data = mmap(NULL, m->size, PROT_READ | PROT_WRITE, MAP_SHARED, m->fd, 0); | ||
111 | else | ||
112 | m->data = mmap(NULL, m->size, PROT_READ, MAP_SHARED, m->fd, 0); | ||
113 | if (m->data == MAP_FAILED) | ||
114 | { | ||
115 | close(m->fd); | ||
116 | free(m->name); | ||
117 | free(m); | ||
118 | return NULL; | ||
119 | } | ||
120 | m->ref = 1; | ||
121 | return m; | ||
122 | } | ||
123 | |||
124 | EAPI void | ||
125 | evas_cserve_mem_close(Mem *m) | ||
126 | { | ||
127 | munmap(m->data, m->size); | ||
128 | close(m->fd); | ||
129 | free(m->name); | ||
130 | free(m); | ||
131 | } | ||
132 | |||
133 | EAPI Eina_Bool | ||
134 | evas_cserve_mem_resize(Mem *m, int size) | ||
135 | { | ||
136 | if (m->size == size) return 1; | ||
137 | if (m->write) | ||
138 | { | ||
139 | if (ftruncate(m->fd, size) < 0) return 0; | ||
140 | munmap(m->data, m->size); | ||
141 | eina_mmap_safety_enabled_set(EINA_TRUE); | ||
142 | m->data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, m->fd, 0); | ||
143 | } | ||
144 | else | ||
145 | { | ||
146 | munmap(m->data, m->size); | ||
147 | eina_mmap_safety_enabled_set(EINA_TRUE); | ||
148 | m->data = mmap(NULL, size, PROT_READ, MAP_SHARED, m->fd, 0); | ||
149 | } | ||
150 | if (m->data == MAP_FAILED) | ||
151 | { | ||
152 | m->data = NULL; | ||
153 | return 0; | ||
154 | } | ||
155 | m->size = size; | ||
156 | return 1; | ||
157 | } | ||
158 | |||
159 | EAPI void | ||
160 | evas_cserve_mem_del(int pid, int id) | ||
161 | { | ||
162 | char buf[PATH_MAX]; | ||
163 | |||
164 | snprintf(buf, sizeof(buf), "/evas-shm-%x.%x.%x", getuid(), pid, id); | ||
165 | shm_unlink(buf); | ||
166 | } | ||
167 | |||
168 | #endif | ||