News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

setjmp x64 crash

Started by TimoVJL, December 10, 2016, 11:10:59 AM

Previous topic - Next topic

TimoVJL

setjmp x64 crash if jmpenv isn't aligned.
problem came with malloc a struct.
should it just fail in that situation?
is it a bug?
May the source be with you

frankie

Hello Timo,
Hard to say.
in setjmp.h for an X64 target is is explicitly indicated that the buffer must be aligned on 16bits boundary:

#elif __POCC_TARGET__ == 3

/* macros */
#define setjmp(env)  _setjmp((env),0)

/* type definitions */
typedef struct __declspec(align(16)) {
    unsigned long long data[2];
} jmp_buf[16];

...


Maybe the problem is malloc family, that should supply memory on a boundary suitable, even if in the help Pelle specify that:
Quote
The allocated space is guaranteed to be suitable aligned for all basic data types.
The workaround is to allocate almost 15 bytes more than required and supply to setjmp an adjusted pointer that is on a 16bits boundary.
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

TimoVJL

This C11 function can be used instead:
void * aligned_alloc(size_t alignment, size_t size);
That problem was with TinyC libtcc.c code.
TinyC source works with gcc, msvc, ...
May the source be with you