NO

Author Topic: setjmp x64 crash  (Read 356 times)

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1596
setjmp x64 crash
« on: December 10, 2016, 11:10:59 AM »
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

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 1581
Re: setjmp x64 crash
« Reply #1 on: December 10, 2016, 06:39:36 PM »
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:
Code: [Select]
#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.

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1596
Re: setjmp x64 crash
« Reply #2 on: December 10, 2016, 06:56:13 PM »
This C11 function can be used instead:
Code: [Select]
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