|
@ -217,10 +217,18 @@ static uint64_t _align16(uint64_t ptrval) { if ( (ptrval & 15) != 0 ) ptrval += |
|
|
void *myaligned_alloc(uint64_t allocsize) |
|
|
void *myaligned_alloc(uint64_t allocsize) |
|
|
{ |
|
|
{ |
|
|
void *ptr,*realptr; uint64_t tmp; |
|
|
void *ptr,*realptr; uint64_t tmp; |
|
|
|
|
|
#if defined(_M_X64) |
|
|
|
|
|
realptr = mycalloc('A', 1, (uint64_t)(allocsize + 16 + sizeof(realptr))); |
|
|
|
|
|
#else |
|
|
realptr = mycalloc('A',1,(long)(allocsize + 16 + sizeof(realptr))); |
|
|
realptr = mycalloc('A',1,(long)(allocsize + 16 + sizeof(realptr))); |
|
|
|
|
|
#endif |
|
|
tmp = _align16((long)realptr + sizeof(ptr)); |
|
|
tmp = _align16((long)realptr + sizeof(ptr)); |
|
|
memcpy(&ptr,&tmp,sizeof(ptr)); |
|
|
memcpy(&ptr,&tmp,sizeof(ptr)); |
|
|
|
|
|
#if defined(_M_X64) |
|
|
|
|
|
memcpy((void *)((unsigned char *)ptr - sizeof(realptr)), &realptr, sizeof(realptr)); |
|
|
|
|
|
#else |
|
|
memcpy((void *)((long)ptr - sizeof(realptr)),&realptr,sizeof(realptr)); |
|
|
memcpy((void *)((long)ptr - sizeof(realptr)),&realptr,sizeof(realptr)); |
|
|
|
|
|
#endif |
|
|
//printf("aligned_alloc(%llu) realptr.%p -> ptr.%p, diff.%ld\n",(long long)allocsize,realptr,ptr,((long)ptr - (long)realptr));
|
|
|
//printf("aligned_alloc(%llu) realptr.%p -> ptr.%p, diff.%ld\n",(long long)allocsize,realptr,ptr,((long)ptr - (long)realptr));
|
|
|
return(ptr); |
|
|
return(ptr); |
|
|
} |
|
|
} |
|
|