criu/compel/test/stack/parasite.c
Younes Manton 17ec539132 compel: Add test to check parasite stack setup
Some ABIs allow functions to store data in caller frame, which
means that we have to allocate an initial stack frame before
executing code on the parasite stack.

This test saves the contents of writable memory that follows the stack
after the victim has been infected but before we start using the
parasite stack. It later checks that the saved data matches the
current contents of the two memory areas. This is done while the
victim is halted so we expect a match unless executing parasite code
caused memory corruption. The test doesn't detect cases where we
corrupted memory by writing the same value.

Signed-off-by: Younes Manton <ymanton@ca.ibm.com>
2023-04-15 21:17:21 -07:00

38 lines
568 B
C

#include <errno.h>
#include <compel/plugins/std.h>
#include <infect-rpc.h>
/*
* Stubs for std compel plugin.
*/
int parasite_trap_cmd(int cmd, void *args)
{
return 0;
}
void parasite_cleanup(void)
{
}
#define PARASITE_CMD_INC PARASITE_USER_CMDS
#define PARASITE_CMD_DEC PARASITE_USER_CMDS + 1
int parasite_daemon_cmd(int cmd, void *args)
{
int v;
switch (cmd) {
case PARASITE_CMD_INC:
v = (*(int *)args) + 1;
break;
case PARASITE_CMD_DEC:
v = (*(int *)args) - 1;
break;
default:
v = -1;
break;
}
sys_write(1, &v, sizeof(int));
return 0;
}