Commit a0956172 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov

restore: Simplify sigreturn code

Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@gmail.com>
parent 11eb2ca4
This diff is collapsed.
......@@ -12,64 +12,63 @@
# error Only x86-64 is supported
#endif
struct task_restore_core_args;
struct thread_restore_args;
extern long restore_task(long cmd, struct task_restore_core_args *args);
extern long restore_thread(long cmd, struct thread_restore_args *args);
typedef long (*task_restore_fcall_t) (long cmd, struct task_restore_core_args *args);
typedef long (*thread_restore_fcall_t) (long cmd, struct thread_restore_args *args);
#define RESTORE_CMD__NONE 0
#define RESTORE_CMD__GET_SELF_LEN 1
#define RESTORE_CMD__RESTORE_CORE 2
#define RESTORE_CMD__RESTORE_THREAD 3
/*
* These must! be power of two values.
* These *must* be power of two values.
*/
#define RESTORE_ARGS_SIZE (512)
#define RESTORE_STACK_REDZONE (128)
#define RESTORE_STACK_FRAME (16 << 10)
#define RESTORE_THREAD_STACK_SIZE (16 << 10)
#define RESTORE_THREAD_HEAP_SIZE (16 << 10)
#define RESTORE_STACK_SIGFRAME (16 << 10)
#define RESTORE_STACK_SIZE (32 << 10)
#define RESTORE_HEAP_SIZE (16 << 10)
#define RESTORE_CMD__NONE 0
#define RESTORE_CMD__GET_ARG_OFFSET 1
#define RESTORE_CMD__GET_SELF_LEN 2
#define RESTORE_CMD__PR_ARG_STRING 3
#define RESTORE_CMD__RESTORE_CORE 4
#define RESTORE_CMD__RESTORE_THREAD 5
#define RESTORE_ALIGN_STACK(start, size) \
(ALIGN((start) + (size) - sizeof(long), sizeof(long)))
#define ABI_RED_ZONE 128
struct restore_mem_zone {
u8 redzone[RESTORE_STACK_REDZONE];
u8 stack[RESTORE_STACK_SIZE];
u8 rt_sigframe[RESTORE_STACK_SIGFRAME];
u8 heap[RESTORE_HEAP_SIZE];
} __aligned(sizeof(long));
#define align_sigframe(sp) round_down(sp, 16) - 8
typedef u32 rlock_t;
#define RLOCK_T(v) rlock_t v __aligned(sizeof(u32)) = 0
#define first_on_heap(ptr, heap) ((typeof(ptr))heap)
#define next_on_heap(ptr, prev) ((typeof(ptr))((long)(prev) + sizeof(*(prev))))
/* Make sure it's pow2 in size */
struct thread_restore_args {
u32 pid;
u32 fd_core;
rlock_t *lock;
u8 stack[RESTORE_THREAD_STACK_SIZE];
union {
struct core_entry core_entry;
u8 heap[RESTORE_THREAD_HEAP_SIZE];
} __aligned(sizeof(long));
u8 rt_sigframe[RESTORE_STACK_FRAME];
};
struct restore_mem_zone mem_zone;
extern long restore_task(long cmd);
extern long restore_thread(long cmd, struct thread_restore_args *args);
typedef long (*task_restore_fcall_t) (long cmd);
typedef long (*thread_restore_fcall_t) (long cmd, struct thread_restore_args *args);
int pid;
int fd_core;
} __aligned(sizeof(long));
struct task_restore_core_args {
void *self_entry; /* restorer placed at */
void *rt_sigframe; /* sigframe placed at */
long self_size; /* size for restorer granted */
char core_path[64];
char self_vmas_path[64];
u32 pid;
rlock_t *lock;
/* threads restoration specifics */
struct restore_mem_zone mem_zone;
int pid; /* task pid */
int fd_core; /* opened core file */
int fd_self_vmas; /* opened file with running VMAs to unmap */
bool restore_threads; /* if to restore threads */
/* threads restoration */
int nr_threads; /* number of threads */
thread_restore_fcall_t clone_restore_fn; /* helper address for clone() call */
long nr_threads; /* number of threads */
struct thread_restore_args *thread_args; /* array of thread arguments */
};
} __aligned(sizeof(long));
struct pt_regs {
unsigned long r15;
......@@ -207,6 +206,8 @@ static void always_inline write_hex_n(unsigned long num)
unsigned char c;
int i;
c = 'x';
sys_write(1, &c, 1);
for (i = sizeof(long)/sizeof(char) - 1; i >= 0; i--) {
c = (s[i] & 0xf0) >> 4;
add_ord(c);
......@@ -221,29 +222,4 @@ static void always_inline write_hex_n(unsigned long num)
sys_write(1, &c, 1);
}
static always_inline void r_lock(rlock_t *v)
{
while (*v) {
asm volatile("lfence");
asm volatile("pause");
}
(*v)++;
asm volatile("sfence");
}
static always_inline void r_unlock(rlock_t *v)
{
(*v)--;
asm volatile("sfence");
}
static always_inline void r_wait_unlock(rlock_t *v)
{
while (*v) {
asm volatile("lfence");
asm volatile("pause");
}
}
#endif /* CR_RESTORER_H__ */
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment