Skip to content

Commit

Permalink
parasite-syscall: get rid of code_syscall{,size} globals
Browse files Browse the repository at this point in the history
I think, we may safely remove this exports, as:
- code_syscall is used only in one function, which now will have
  it as a parameter;
- code_syscall_size must be equall to BUILTIN_SYSCALL_SIZE under
  BUILD_BUG_ON, so BUILTIN_SYSCALL_SIZE may be used instead.
  (see ptrace(2) - align restriction to PTRACE_PEEKUSER).

This will reduce arch-depended code coupling a little.

(and I also interested in this because of I need __parasite_execute_syscall
to execute 32-bit syscall code on x86_64, which I prefer to leave without
some CONFIG_X86_64 as it's generic code)

Cc: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Reviewed-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
  • Loading branch information
0x7f454c46 authored and xemul committed Mar 21, 2016
1 parent ea244e1 commit f8a1a1d
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 28 deletions.
7 changes: 4 additions & 3 deletions criu/arch/aarch64/crtools.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ const char code_syscall[] = {
0x00, 0x00, 0x20, 0xd4 /* BRK #0 */
};

const int code_syscall_size = round_up(sizeof(code_syscall), sizeof(long));
static const int
code_syscall_aligned = round_up(sizeof(code_syscall), sizeof(long));

static inline void __always_unused __check_code_syscall(void)
{
BUILD_BUG_ON(sizeof(code_syscall) != BUILTIN_SYSCALL_SIZE);
BUILD_BUG_ON(code_syscall_aligned != BUILTIN_SYSCALL_SIZE);
BUILD_BUG_ON(!is_log2(sizeof(code_syscall)));
}

Expand Down Expand Up @@ -71,7 +72,7 @@ int syscall_seized(struct parasite_ctl *ctl, int nr, unsigned long *ret,
regs.regs[6] = 0;
regs.regs[7] = 0;

err = __parasite_execute_syscall(ctl, &regs);
err = __parasite_execute_syscall(ctl, &regs, code_syscall);

*ret = regs.regs[0];
return err;
Expand Down
3 changes: 0 additions & 3 deletions criu/arch/aarch64/include/asm/parasite-syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ struct parasite_ctl;
#define ARCH_SI_TRAP TRAP_BRKPT


extern const char code_syscall[];
extern const int code_syscall_size;

void parasite_setup_regs(unsigned long new_ip, void *stack, user_regs_struct_t *regs);

void *mmap_seized(struct parasite_ctl *ctl,
Expand Down
7 changes: 4 additions & 3 deletions criu/arch/arm/crtools.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ const char code_syscall[] = {
0xf0, 0x01, 0xf0, 0xe7 /* UDF #32 */
};

const int code_syscall_size = round_up(sizeof(code_syscall), sizeof(long));
static const int
code_syscall_aligned = round_up(sizeof(code_syscall), sizeof(long));

static inline __always_unused void __check_code_syscall(void)
{
BUILD_BUG_ON(sizeof(code_syscall) != BUILTIN_SYSCALL_SIZE);
BUILD_BUG_ON(code_syscall_aligned != BUILTIN_SYSCALL_SIZE);
BUILD_BUG_ON(!is_log2(sizeof(code_syscall)));
}

Expand Down Expand Up @@ -73,7 +74,7 @@ int syscall_seized(struct parasite_ctl *ctl, int nr, unsigned long *ret,
regs.ARM_r4 = arg5;
regs.ARM_r5 = arg6;

err = __parasite_execute_syscall(ctl, &regs);
err = __parasite_execute_syscall(ctl, &regs, code_syscall);

*ret = regs.ARM_r0;
return err;
Expand Down
4 changes: 0 additions & 4 deletions criu/arch/arm/include/asm/parasite-syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
#define ARCH_SI_TRAP TRAP_BRKPT


extern const char code_syscall[];
extern const int code_syscall_size;


void parasite_setup_regs(unsigned long new_ip, void *stack, user_regs_struct_t *regs);

void *mmap_seized(struct parasite_ctl *ctl,
Expand Down
4 changes: 1 addition & 3 deletions criu/arch/ppc64/crtools.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ const u32 code_syscall[] = {
0x0fe00000 /* twi 31,0,0 */
};

const int code_syscall_size = sizeof(code_syscall);

static inline void __check_code_syscall(void)
{
BUILD_BUG_ON(sizeof(code_syscall) != BUILTIN_SYSCALL_SIZE);
Expand Down Expand Up @@ -80,7 +78,7 @@ int syscall_seized(struct parasite_ctl *ctl, int nr, unsigned long *ret,
regs.gpr[7] = arg5;
regs.gpr[8] = arg6;

err = __parasite_execute_syscall(ctl, &regs);
err = __parasite_execute_syscall(ctl, &regs, code_syscall);

*ret = regs.gpr[3];
return err;
Expand Down
3 changes: 0 additions & 3 deletions criu/arch/ppc64/include/asm/parasite-syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ struct parasite_ctl;

#define ARCH_SI_TRAP TRAP_BRKPT

extern const char code_syscall[];
extern const int code_syscall_size;

void parasite_setup_regs(unsigned long new_ip, void *stack, user_regs_struct_t *regs);

void *mmap_seized(struct parasite_ctl *ctl,
Expand Down
7 changes: 4 additions & 3 deletions criu/arch/x86/crtools.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ const char code_syscall[] = {
0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc /* int 3, ... */
};

const int code_syscall_size = round_up(sizeof(code_syscall), sizeof(long));
static const int
code_syscall_aligned = round_up(sizeof(code_syscall), sizeof(long));

static inline __always_unused void __check_code_syscall(void)
{
BUILD_BUG_ON(sizeof(code_syscall) != BUILTIN_SYSCALL_SIZE);
BUILD_BUG_ON(code_syscall_aligned != BUILTIN_SYSCALL_SIZE);
BUILD_BUG_ON(!is_log2(sizeof(code_syscall)));
}

Expand Down Expand Up @@ -103,7 +104,7 @@ int syscall_seized(struct parasite_ctl *ctl, int nr, unsigned long *ret,
regs.r8 = arg5;
regs.r9 = arg6;

err = __parasite_execute_syscall(ctl, &regs);
err = __parasite_execute_syscall(ctl, &regs, code_syscall);

*ret = regs.ax;
return err;
Expand Down
3 changes: 0 additions & 3 deletions criu/arch/x86/include/asm/parasite-syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ struct parasite_ctl;
#define ARCH_SI_TRAP SI_KERNEL


extern const char code_syscall[];
extern const int code_syscall_size;

void parasite_setup_regs(unsigned long new_ip, void *stack, user_regs_struct_t *regs);

void *mmap_seized(struct parasite_ctl *ctl,
Expand Down
2 changes: 1 addition & 1 deletion criu/include/parasite-syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ extern int syscall_seized(struct parasite_ctl *ctl, int nr, unsigned long *ret,
unsigned long arg5, unsigned long arg6);

extern int __parasite_execute_syscall(struct parasite_ctl *ctl,
user_regs_struct_t *regs);
user_regs_struct_t *regs, const char *code_syscall);
extern bool arch_can_dump_task(pid_t pid);

/*
Expand Down
5 changes: 3 additions & 2 deletions criu/parasite-syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
static int can_run_syscall(unsigned long ip, unsigned long start,
unsigned long end, unsigned long pad)
{
return ip >= start && ip < (end - code_syscall_size - pad);
return ip >= start && ip < (end - BUILTIN_SYSCALL_SIZE - pad);
}

static int syscall_fits_vma_area(struct vma_area *vma_area, unsigned long pad)
Expand Down Expand Up @@ -210,7 +210,8 @@ static int parasite_trap(struct parasite_ctl *ctl, pid_t pid,
return ret;
}

int __parasite_execute_syscall(struct parasite_ctl *ctl, user_regs_struct_t *regs)
int __parasite_execute_syscall(struct parasite_ctl *ctl,
user_regs_struct_t *regs, const char *code_syscall)
{
pid_t pid = ctl->pid.real;
int err;
Expand Down

0 comments on commit f8a1a1d

Please sign in to comment.