sentry.c
void gen_oop(uint32_t *code, void *function)
{
	intptr_t *code_data = (intptr_t *) code;

	// The additional data needs to be stored somewhere in memory
	// where it can not be accessed by the user of the function.
	// This is why it is stored in the same place where the code will be.
	// As the code is not modifiable and not readable this data is also
	// protected.
	code_data[255] = (intptr_t) function;
	code_data[254] = (intptr_t) malloc(sizeof(struct data));

	uint32_t idx = 0;
	code[idx++] = auipcc(cs2, 1);
	code[idx++] = clc_128(cs3, cs2, ((-16) + (2 << 20)));
	// Move the arguments to the next register.
	// This will break if we have more then 6 arguments but that should be fine.
	code[idx++] = addi(a1, a0, 0);
	code[idx++] = addi(a2, a1, 0);
	code[idx++] = addi(a3, a2, 0);
	code[idx++] = addi(a4, a3, 0);
	code[idx++] = addi(a5, a4, 0);
	code[idx++] = addi(a6, a5, 0);
	code[idx++] = addi(a7, a6, 0);
	code[idx++] = clc_128(ca0, cs2, ((-32) + (2 << 20)));
	code[idx++] = cjalr(cnull, cs3);
}
// A function to generate the code that will put the
// this structure as first argument and move the rest of the
// arguments to the next registers.
A function to generate the code that will put the
this structure as first argument and move the rest of the
arguments to the next registers.
A function to generate the code that will put the this structure as first argument and move the rest of the arguments to the next registers .
void gen_oop(uint32_t *code, void *function)
{
	intptr_t *code_data = (intptr_t *) code;
	code_data[255] = (intptr_t) function;
	code_data[254] = (intptr_t) malloc(sizeof(struct data));
	uint32_t idx = 0;
	code[idx++] = auipcc(cs2, 1);
	code[idx++] = clc_128(cs3, cs2, ((-16) + (2 << 20)));
	code[idx++] = addi(a1, a0, 0);
	code[idx++] = addi(a2, a1, 0);
	code[idx++] = addi(a3, a2, 0);
	code[idx++] = addi(a4, a3, 0);
	code[idx++] = addi(a5, a4, 0);
	code[idx++] = addi(a6, a5, 0);
	code[idx++] = addi(a7, a6, 0);
	code[idx++] = clc_128(ca0, cs2, ((-32) + (2 << 20)));
	code[idx++] = cjalr(cnull, cs3);
}
void gen_oop ( uint32_t * code , void * function ) { intptr_t * code_data = ( intptr_t * ) code ; code_data [ 255 ] = ( intptr_t ) function ; code_data [ 254 ] = ( intptr_t ) malloc ( sizeof ( struct data ) ) ; uint32_t idx = 0 ; code [ idx ++ ] = auipcc ( cs2 , 1 ) ; code [ idx ++ ] = clc_128 ( cs3 , cs2 , ( ( -16 ) + ( 2 << 20 ) ) ) ; code [ idx ++ ] = addi ( a1 , a0 , 0 ) ; code [ idx ++ ] = addi ( a2 , a1 , 0 ) ; code [ idx ++ ] = addi ( a3 , a2 , 0 ) ; code [ idx ++ ] = addi ( a4 , a3 , 0 ) ; code [ idx ++ ] = addi ( a5 , a4 , 0 ) ; code [ idx ++ ] = addi ( a6 , a5 , 0 ) ; code [ idx ++ ] = addi ( a7 , a6 , 0 ) ; code [ idx ++ ] = clc_128 ( ca0 , cs2 , ( ( -32 ) + ( 2 << 20 ) ) ) ; code [ idx ++ ] = cjalr ( cnull , cs3 ) ; }
A function to generate the code that will put the
this structure as first argument and move the rest of the
arguments to the next registers.
A function to generate the code that will put the this structure as first argument and move the rest of the arguments to the next registers .
// The additional data needs to be stored somewhere in memory // where it can not be accessed by the user of the function. // This is why it is stored in the same place where the code will be. // As the code is not modifiable and not readable this data is also // protected. // Move the arguments to the next register. // This will break if we have more then 6 arguments but that should be fine.