diff options
author | Carsten Haitzler (Rasterman) <raster@rasterman.com> | 2017-07-07 12:08:01 +0900 |
---|---|---|
committer | Carsten Haitzler (Rasterman) <raster@rasterman.com> | 2017-07-07 12:08:01 +0900 |
commit | eeb1eb1b7422e1d5510dd3f643b1c77c3fbb87e0 (patch) | |
tree | 1117539d74991e2b6bd94c1ba5dafae0bc2bfd9b | |
parent | 457d53ec29171a759697ec30012fe2668ad6c292 (diff) | |
download | efl-eeb1eb1b7422e1d5510dd3f643b1c77c3fbb87e0.tar.gz |
eina - fix eina_file_virtualize to copy data to an aligned addr
so we copy data to an UNALINED memory address (just after whatever
string we packed on the end of the eina file struct header). this is
bad. especially for non-intel architectures. this forces a 16 byte
alignment which should cover us.
@fix
-rw-r--r-- | src/lib/eina/eina_file_common.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/lib/eina/eina_file_common.c b/src/lib/eina/eina_file_common.c index 8d7472bdd3..1008a5f224 100644 --- a/src/lib/eina/eina_file_common.c +++ b/src/lib/eina/eina_file_common.c @@ -403,7 +403,7 @@ eina_file_virtualize(const char *virtual_name, const void *data, unsigned long l Eina_Nano_Time tp; long int ti; const char *tmpname = "/dev/mem/virtual\\/%16x"; - int slen; + size_t slen, head_padded; EINA_SAFETY_ON_NULL_RETURN_VAL(data, NULL); @@ -412,19 +412,19 @@ eina_file_virtualize(const char *virtual_name, const void *data, unsigned long l ti = _eina_time_convert(&tp); slen = virtual_name ? strlen(virtual_name) + 1 : strlen(tmpname) + 17; + // align copied data at end of file struct to 16 bytes... + head_padded = 16 * ((sizeof(Eina_File) + slen + 15) / 16); - file = malloc(sizeof (Eina_File) + - slen + - (copy ? length : 0)); + file = malloc(head_padded + (copy ? length : 0)); if (!file) return NULL; memset(file, 0, sizeof(Eina_File)); EINA_MAGIC_SET(file, EINA_FILE_MAGIC); - file->filename = (char*) (file + 1); + file->filename = (char *)(file + 1); if (virtual_name) - strcpy((char*) file->filename, virtual_name); + strcpy((char *)file->filename, virtual_name); else - sprintf((char*) file->filename, tmpname, ti); + sprintf((char *)file->filename, tmpname, ti); eina_lock_new(&file->lock); file->mtime = ti / 1000; @@ -448,13 +448,12 @@ eina_file_virtualize(const char *virtual_name, const void *data, unsigned long l if (copy) { - file->global_map = (void*)(file->filename + - strlen(file->filename) + 1); - memcpy((char*) file->global_map, data, length); + file->global_map = ((char *)file) + head_padded; + memcpy((char *)file->global_map, data, length); } else { - file->global_map = (void*) data; + file->global_map = (void *)data; } return file; |