c - Heap corruption with function pointer on Solaris 64-bits -



c - Heap corruption with function pointer on Solaris 64-bits -

i have next c code on solaris 5.10 64-bits compiled cc 5.10 flags -m64 -kpic -x04

header.h

typedef struct functions { double (* pfcomputegeneric) (mystruct *, mystruct *, double, double *, int); } functions; ... double mycompute(mystruct *, mystruct *, double, double *, int);

source.c

double mycompute(mystruct * px1, mystruct *px2, double d1, double *pd1, int i1) { // stuff px1 } ... mystruct *pxstruct = alloc(...); functions *pxfunctions = alloc(...); pxfunctions->pfcomputegeneric = mycompute; ... double dresult += pxfunctions->pfcomputegeneric(pxstruct, pxstruct, 0.0, null, 0);

the code in source.c runs fine (nothing weird) until come in enter mycompute through function pointer pfcompute, px1 gets corrupted. don't know why.

replacing phone call through pfcompute direct phone call mycompute solves issue.

removing -x04 alternative solves issue.

i had @ reply of this question i'm sure i'm not messing pointer sizes.

i think indeed issue of -x04. when @ assemby call, see:

... 0x0000000000987eb2: mycaller+0x081a: movq 0xfffffffffffffe28(%rbp),%rcx 0x0000000000987eb9: mycaller+0x0821: movq $0x0000000000000006,%rax 0x0000000000987ec0: mycaller+0x0828: movq 0xfffffffffffffe08(%rbp),%rdi 0x0000000000987ec7: mycaller+0x082f: phone call *0x0000000000000018(%rdi) 0x0000000000987eca: mycaller+0x0832: addq $0x0000000000000010,%rsp

so compiler uses %rdi (!) real adress of mycompute pxfunctions. , in 64-bits, %rdi used store first argument of function, hence alteration.

c function-pointers solaris

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -