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
This commit is contained in:
Carsten Haitzler 2017-07-07 12:08:01 +09:00
parent 457d53ec29
commit eeb1eb1b74
1 changed files with 10 additions and 11 deletions

View File

@ -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;