summaryrefslogtreecommitdiff
path: root/src/bin/efl
diff options
context:
space:
mode:
authorDaniel Zaoui <daniel.zaoui@yahoo.com>2017-06-03 19:33:58 +0300
committerDaniel Zaoui <daniel.zaoui@yahoo.com>2017-06-05 08:55:38 +0300
commitea50cbd2b3c2adbf372ed2a9b7ec0ea96cabaaf5 (patch)
treebdcd03ad845a27bed0d902e4a1afab9748c9f236 /src/bin/efl
parent758bb0557c45353a8afffebb69d93f969e1ea4b6 (diff)
Support endianness
Diffstat (limited to 'src/bin/efl')
-rw-r--r--src/bin/efl/efl_debug.c17
-rw-r--r--src/bin/efl/efl_debugd.c58
2 files changed, 57 insertions, 18 deletions
diff --git a/src/bin/efl/efl_debug.c b/src/bin/efl/efl_debug.c
index 1ebe8c8564..18d0c62d76 100644
--- a/src/bin/efl/efl_debug.c
+++ b/src/bin/efl/efl_debug.c
@@ -23,6 +23,16 @@
23# include "config.h" 23# include "config.h"
24# endif 24# endif
25 25
26#if __BYTE_ORDER == __LITTLE_ENDIAN
27#define SWAP_64(x) x
28#define SWAP_32(x) x
29#define SWAP_16(x) x
30#else
31#define SWAP_64(x) eina_swap64(x)
32#define SWAP_32(x) eina_swap32(x)
33#define SWAP_16(x) eina_swap16(x)
34#endif
35
26#define EXTRACT(_buf, pval, sz) \ 36#define EXTRACT(_buf, pval, sz) \
27{ \ 37{ \
28 memcpy(pval, _buf, sz); \ 38 memcpy(pval, _buf, sz); \
@@ -65,7 +75,7 @@ _evlog_get_cb(Eina_Debug_Session *session EINA_UNUSED, int src EINA_UNUSED, void
65 unsigned int header[3]; 75 unsigned int header[3];
66 76
67 header[0] = 0xffee211; 77 header[0] = 0xffee211;
68 header[1] = blocksize; 78 header[1] = SWAP_32(blocksize);
69 header[2] = *overflow; 79 header[2] = *overflow;
70 if (fwrite(header, 1, 12, _evlog_file) < 12 || 80 if (fwrite(header, 1, 12, _evlog_file) < 12 ||
71 fwrite(p, 1, blocksize, _evlog_file) < blocksize) 81 fwrite(p, 1, blocksize, _evlog_file) < blocksize)
@@ -113,7 +123,7 @@ _cid_get_cb(Eina_Debug_Session *session EINA_UNUSED, int cid EINA_UNUSED, void *
113 123
114 if ((!strcmp(op_str, "pon")) && (3 <= (my_argc - 1))) 124 if ((!strcmp(op_str, "pon")) && (3 <= (my_argc - 1)))
115 { 125 {
116 int freq = atoi(my_argv[3]); 126 int freq = SWAP_32(atoi(my_argv[3]));
117 eina_debug_session_send(_session, _cid, _prof_on_opcode, &freq, sizeof(int)); 127 eina_debug_session_send(_session, _cid, _prof_on_opcode, &freq, sizeof(int));
118 } 128 }
119 else if (!strcmp(op_str, "poff")) 129 else if (!strcmp(op_str, "poff"))
@@ -155,6 +165,8 @@ _clients_info_added_cb(Eina_Debug_Session *session EINA_UNUSED, int src EINA_UNU
155 int cid, pid, len; 165 int cid, pid, len;
156 EXTRACT(buf, &cid, sizeof(int)); 166 EXTRACT(buf, &cid, sizeof(int));
157 EXTRACT(buf, &pid, sizeof(int)); 167 EXTRACT(buf, &pid, sizeof(int));
168 cid = SWAP_32(cid);
169 pid = SWAP_32(pid);
158 /* We dont need client notifications on evlog */ 170 /* We dont need client notifications on evlog */
159 if(!_evlog_fetch_timer) 171 if(!_evlog_fetch_timer)
160 printf("Added: CID: %d - PID: %d - Name: %s\n", cid, pid, buf); 172 printf("Added: CID: %d - PID: %d - Name: %s\n", cid, pid, buf);
@@ -173,6 +185,7 @@ _clients_info_deleted_cb(Eina_Debug_Session *session EINA_UNUSED, int src EINA_U
173 { 185 {
174 int cid; 186 int cid;
175 EXTRACT(buf, &cid, sizeof(int)); 187 EXTRACT(buf, &cid, sizeof(int));
188 cid = SWAP_32(cid);
176 size -= sizeof(int); 189 size -= sizeof(int);
177 190
178 /* If client deleted dont send anymore evlog requests */ 191 /* If client deleted dont send anymore evlog requests */
diff --git a/src/bin/efl/efl_debugd.c b/src/bin/efl/efl_debugd.c
index d36b307bf2..72f6062792 100644
--- a/src/bin/efl/efl_debugd.c
+++ b/src/bin/efl/efl_debugd.c
@@ -29,6 +29,16 @@
29#include <Eina.h> 29#include <Eina.h>
30#include <Ecore.h> 30#include <Ecore.h>
31 31
32#if __BYTE_ORDER == __LITTLE_ENDIAN
33#define SWAP_64(x) x
34#define SWAP_32(x) x
35#define SWAP_16(x) x
36#else
37#define SWAP_64(x) eina_swap64(x)
38#define SWAP_32(x) eina_swap32(x)
39#define SWAP_16(x) eina_swap16(x)
40#endif
41
32#define STORE(_buf, pval, sz) \ 42#define STORE(_buf, pval, sz) \
33{ \ 43{ \
34 memcpy(_buf, pval, sz); \ 44 memcpy(_buf, pval, sz); \
@@ -121,9 +131,9 @@ _send(Client *dest, int opcode, void *payload, int payload_size)
121 int size = sizeof(Eina_Debug_Packet_Header) + payload_size; 131 int size = sizeof(Eina_Debug_Packet_Header) + payload_size;
122 char *buf = alloca(size); 132 char *buf = alloca(size);
123 Eina_Debug_Packet_Header *hdr = (Eina_Debug_Packet_Header *)buf; 133 Eina_Debug_Packet_Header *hdr = (Eina_Debug_Packet_Header *)buf;
124 hdr->size = size; 134 hdr->size = SWAP_32(size);
125 hdr->cid = 0; 135 hdr->cid = 0;
126 hdr->opcode = opcode; 136 hdr->opcode = SWAP_32(opcode);
127 memcpy(buf + sizeof(Eina_Debug_Packet_Header), payload, payload_size); 137 memcpy(buf + sizeof(Eina_Debug_Packet_Header), payload, payload_size);
128 printf("Send packet (size = %d, opcode %s) to %s\n", size, 138 printf("Send packet (size = %d, opcode %s) to %s\n", size,
129 _opcodes[hdr->opcode]->opcode_string, 139 _opcodes[hdr->opcode]->opcode_string,
@@ -145,7 +155,8 @@ _client_del(Client *c)
145 155
146 EINA_LIST_FOREACH(_clients, itr, c2) 156 EINA_LIST_FOREACH(_clients, itr, c2)
147 { 157 {
148 if (c2->cl_stat_obs) _send(c2, _slave_deleted_opcode, &c->cid, sizeof(int)); 158 int cid = SWAP_32(c->cid);
159 if (c2->cl_stat_obs) _send(c2, _slave_deleted_opcode, &cid, sizeof(int));
149 } 160 }
150 free(c); 161 free(c);
151} 162}
@@ -162,7 +173,7 @@ _dispatch(Client *src, void *buffer, unsigned int size)
162 { 173 {
163 if (dest->is_master != src->is_master) 174 if (dest->is_master != src->is_master)
164 { 175 {
165 hdr->cid = src->cid; 176 hdr->cid = SWAP_32(src->cid);
166 if (send(dest->fd, buffer, size, 0) != size) perror("send"); 177 if (send(dest->fd, buffer, size, 0) != size) perror("send");
167 printf("Transfer of %d bytes from %s(%d) to %s(%d): operation %s\n", 178 printf("Transfer of %d bytes from %s(%d) to %s(%d): operation %s\n",
168 hdr->size, 179 hdr->size,
@@ -222,12 +233,16 @@ _hello_cb(Client *c, void *buffer, int size)
222{ 233{
223 Eina_List *itr; 234 Eina_List *itr;
224 char *buf = (char *)buffer, *tmp; 235 char *buf = (char *)buffer, *tmp;
236 int version, pid, cid;
225 237
226 EXTRACT(buf, &c->version, 4); 238 EXTRACT(buf, &version, 4);
227 EXTRACT(buf, &c->pid, 4); 239 EXTRACT(buf, &pid, 4);
240 c->version = SWAP_32(version);
241 c->pid = SWAP_32(pid);
228 size -= 8; 242 size -= 8;
229 243
230 c->cid = _free_cid++; 244 c->cid = _free_cid++;
245 cid = SWAP_32(c->cid);
231 if (size > 1) 246 if (size > 1)
232 { 247 {
233 c->app_name = eina_stringshare_add_length(buf, size); 248 c->app_name = eina_stringshare_add_length(buf, size);
@@ -242,8 +257,8 @@ _hello_cb(Client *c, void *buffer, int size)
242 size = 2 * sizeof(int) + (c->app_name ? strlen(c->app_name) : 0) + 1; /* cid + pid + name + \0 */ 257 size = 2 * sizeof(int) + (c->app_name ? strlen(c->app_name) : 0) + 1; /* cid + pid + name + \0 */
243 buf = alloca(size); 258 buf = alloca(size);
244 tmp = buf; 259 tmp = buf;
245 STORE(tmp, &c->cid, sizeof(int)); 260 STORE(tmp, &cid, sizeof(int));
246 STORE(tmp, &c->pid, sizeof(int)); 261 STORE(tmp, &pid, sizeof(int));
247 if (c->app_name) 262 if (c->app_name)
248 { 263 {
249 STORE(tmp, c->app_name, strlen(c->app_name) + 1); 264 STORE(tmp, c->app_name, strlen(c->app_name) + 1);
@@ -263,9 +278,9 @@ _hello_cb(Client *c, void *buffer, int size)
263static Eina_Bool 278static Eina_Bool
264_cid_get_cb(Client *src, void *buffer, int size EINA_UNUSED) 279_cid_get_cb(Client *src, void *buffer, int size EINA_UNUSED)
265{ 280{
266 int pid = *(int *)buffer; 281 int pid = SWAP_32(*(int *)buffer);
267 Client *c = _client_find_by_pid(pid); 282 Client *c = _client_find_by_pid(pid);
268 int cid = c ? c->cid : 0; 283 int cid = c ? SWAP_32(c->cid) : 0;
269 _send(src, _cid_from_pid_opcode, &cid, sizeof(int)); 284 _send(src, _cid_from_pid_opcode, &cid, sizeof(int));
270 return EINA_TRUE; 285 return EINA_TRUE;
271} 286}
@@ -292,12 +307,15 @@ _cl_stat_obs_register_cb(Client *src, void *buffer, int size)
292 EINA_LIST_FOREACH(_clients, itr, c) 307 EINA_LIST_FOREACH(_clients, itr, c)
293 { 308 {
294 char *tmp; 309 char *tmp;
310 int cid, pid;
295 if (c->is_master) continue; 311 if (c->is_master) continue;
296 size = 2 * sizeof(int) + (c->app_name ? strlen(c->app_name) : 0) + 1; 312 size = 2 * sizeof(int) + (c->app_name ? strlen(c->app_name) : 0) + 1;
297 buffer = alloca(size); 313 buffer = alloca(size);
298 tmp = buffer; 314 tmp = buffer;
299 STORE(tmp, &c->cid, sizeof(int)); 315 cid = SWAP_32(c->cid);
300 STORE(tmp, &c->pid, sizeof(int)); 316 pid = SWAP_32(c->pid);
317 STORE(tmp, &cid, sizeof(int));
318 STORE(tmp, &pid, sizeof(int));
301 if (c->app_name) 319 if (c->app_name)
302 { 320 {
303 STORE(tmp, c->app_name, strlen(c->app_name) + 1); 321 STORE(tmp, c->app_name, strlen(c->app_name) + 1);
@@ -327,7 +345,7 @@ _opcode_register_cb(Client *src, void *buffer, int size)
327 while (ops_size > 0) 345 while (ops_size > 0)
328 { 346 {
329 int len = strlen(ops_buf) + 1; 347 int len = strlen(ops_buf) + 1;
330 *opcodes++ = _opcode_register(ops_buf, EINA_DEBUG_OPCODE_INVALID, NULL); 348 *opcodes++ = SWAP_32(_opcode_register(ops_buf, EINA_DEBUG_OPCODE_INVALID, NULL));
331 ops_buf += len; 349 ops_buf += len;
332 ops_size -= len; 350 ops_size -= len;
333 } 351 }
@@ -350,7 +368,9 @@ _data_receive(Client *c, unsigned char *buffer)
350 if (rret == -1 || !size) goto error; 368 if (rret == -1 || !size) goto error;
351 if (rret == sizeof(int)) 369 if (rret == sizeof(int))
352 { 370 {
371 Eina_Debug_Packet_Header *hdr;
353 unsigned int cur_packet_size = 0; 372 unsigned int cur_packet_size = 0;
373 size = SWAP_32(size);
354 if (size > EINA_DEBUG_MAX_PACKET_SIZE) goto error; 374 if (size > EINA_DEBUG_MAX_PACKET_SIZE) goto error;
355 while (cur_packet_size < size) 375 while (cur_packet_size < size)
356 { 376 {
@@ -358,6 +378,10 @@ _data_receive(Client *c, unsigned char *buffer)
358 if (rret <= 0) goto error; 378 if (rret <= 0) goto error;
359 cur_packet_size += rret; 379 cur_packet_size += rret;
360 } 380 }
381 hdr = (Eina_Debug_Packet_Header *) buffer;
382 hdr->size = SWAP_32(hdr->size);
383 hdr->opcode = SWAP_32(hdr->opcode);
384 hdr->cid = SWAP_32(hdr->cid);
361 } 385 }
362 //printf("%d bytes received from client %s fd %d\n", size, c->app_name, c->fd); 386 //printf("%d bytes received from client %s fd %d\n", size, c->app_name, c->fd);
363 return size; 387 return size;
@@ -536,6 +560,7 @@ end:
536 free(socket_path); 560 free(socket_path);
537 return fd; 561 return fd;
538} 562}
563#endif
539 564
540static int 565static int
541_listening_tcp_socket_create() 566_listening_tcp_socket_create()
@@ -569,17 +594,19 @@ err:
569 if (fd >= 0) close(fd); 594 if (fd >= 0) close(fd);
570 return -1; 595 return -1;
571} 596}
572#endif
573 597
574static Eina_Bool 598static Eina_Bool
575_server_launch() 599_server_launch()
576{ 600{
577#ifndef _WIN32
578 struct epoll_event event = {0}; 601 struct epoll_event event = {0};
579 602
580 _epfd = epoll_create (MAX_EVENTS); 603 _epfd = epoll_create (MAX_EVENTS);
581 604
605#ifndef _WIN32
582 _listening_unix_fd = _listening_unix_socket_create(); 606 _listening_unix_fd = _listening_unix_socket_create();
607#else
608 _listening_unix_fd = -1;
609#endif
583 if (_listening_unix_fd <= 0) goto err; 610 if (_listening_unix_fd <= 0) goto err;
584 event.data.fd = _listening_unix_fd; 611 event.data.fd = _listening_unix_fd;
585 event.events = EPOLLIN; 612 event.events = EPOLLIN;
@@ -596,7 +623,6 @@ err:
596 _listening_unix_fd = -1; 623 _listening_unix_fd = -1;
597 if (_listening_tcp_fd >= 0) close(_listening_tcp_fd); 624 if (_listening_tcp_fd >= 0) close(_listening_tcp_fd);
598 _listening_tcp_fd = -1; 625 _listening_tcp_fd = -1;
599#endif
600 return EINA_FALSE; 626 return EINA_FALSE;
601} 627}
602 628