[CRIU] [PATCH v2] parasite-syscall: make code_syscall local

Dmitry Safonov dsafonov at virtuozzo.com
Thu Mar 17 09:22:10 PDT 2016


On 03/17/2016 06:10 PM, Cyrill Gorcunov wrote:
> Please provide code_syscall_size in arguments as well, and add
>
> __parasite_execute_syscall
> 	...
> 	BUG_ON(sizeof(code_orig) != @code_syscall_size);
> 	...
>
> where @code_syscall_size comes from argument.
>
> 	Cyrill

Seems like, code_syscall_size was introduced because of
PTRACE_PEEKUSER restriction:
 >PTRACE_PEEKUSER
 >        Read  a  word  at offset addr in the tracee's USER area, which 
holds the registers and other information about the process (see 
<sys/user.h>).  The word is
 >        returned as the result of the ptrace() call.  Typically, the 
offset must be word-aligned, though this might vary by architecture.
(ptrace(2))

So, code_orig must be declared with code_syscall_size,
because it goes to ptrace_{swap,poke}_area, where
it goes to PTRACE_PEEKUSER.
Or am I missing something?

ITOW, what do you think about something like that?
(on top of this v2)

--->8---
diff --git a/criu/arch/aarch64/crtools.c b/criu/arch/aarch64/crtools.c
index f56b864..15345ec 100644
--- a/criu/arch/aarch64/crtools.c
+++ b/criu/arch/aarch64/crtools.c
@@ -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)));
  }

diff --git a/criu/arch/aarch64/include/asm/parasite-syscall.h 
b/criu/arch/aarch64/include/asm/parasite-syscall.h
index 60bd6e2..f992bca 100644
--- a/criu/arch/aarch64/include/asm/parasite-syscall.h
+++ b/criu/arch/aarch64/include/asm/parasite-syscall.h
@@ -6,8 +6,6 @@ struct parasite_ctl;
  #define ARCH_SI_TRAP TRAP_BRKPT


-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,
diff --git a/criu/arch/arm/crtools.c b/criu/arch/arm/crtools.c
index a82e9ef..8887262 100644
--- a/criu/arch/arm/crtools.c
+++ b/criu/arch/arm/crtools.c
@@ -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)));
  }

diff --git a/criu/arch/arm/include/asm/parasite-syscall.h 
b/criu/arch/arm/include/asm/parasite-syscall.h
index 0dd6efa..2d6b85f 100644
--- a/criu/arch/arm/include/asm/parasite-syscall.h
+++ b/criu/arch/arm/include/asm/parasite-syscall.h
@@ -5,9 +5,6 @@
  #define ARCH_SI_TRAP TRAP_BRKPT


-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,
diff --git a/criu/arch/ppc64/crtools.c b/criu/arch/ppc64/crtools.c
index 9ed377e..7d039a0 100644
--- a/criu/arch/ppc64/crtools.c
+++ b/criu/arch/ppc64/crtools.c
@@ -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);
diff --git a/criu/arch/ppc64/include/asm/parasite-syscall.h 
b/criu/arch/ppc64/include/asm/parasite-syscall.h
index 676749d..1ac6b3b 100644
--- a/criu/arch/ppc64/include/asm/parasite-syscall.h
+++ b/criu/arch/ppc64/include/asm/parasite-syscall.h
@@ -5,8 +5,6 @@ struct parasite_ctl;

  #define ARCH_SI_TRAP TRAP_BRKPT

-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,
diff --git a/criu/arch/x86/crtools.c b/criu/arch/x86/crtools.c
index 83d3c8e..7b59df6 100644
--- a/criu/arch/x86/crtools.c
+++ b/criu/arch/x86/crtools.c
@@ -31,11 +31,11 @@ const char code_syscall[] = {
         0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc      /* int 3, ... */
  };

-const int code_syscall_size = round_up(sizeof(code_syscall), sizeof(long));
+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)));
  }

diff --git a/criu/arch/x86/include/asm/parasite-syscall.h 
b/criu/arch/x86/include/asm/parasite-syscall.h
index 9cd698c..e2c7a5a 100644
--- a/criu/arch/x86/include/asm/parasite-syscall.h
+++ b/criu/arch/x86/include/asm/parasite-syscall.h
@@ -8,8 +8,6 @@ struct parasite_ctl;
  #define ARCH_SI_TRAP SI_KERNEL


-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,
diff --git a/criu/parasite-syscall.c b/criu/parasite-syscall.c
index 4bcccb1..0a1bdc6 100644
--- a/criu/parasite-syscall.c
+++ b/criu/parasite-syscall.c
@@ -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)



More information about the CRIU mailing list