[CRIU] [PATCH 8/9] restorer: introduced the struct krlimit

Alexander Kartashov alekskartashov at parallels.com
Wed Jan 16 03:28:30 EST 2013


The layout of the struct rlimit depends on the value
of the macro FILE_OFFSET_BITS. If FILE_OFFSET_BITS is 64
the userspace and kernel definitions becomes incoherent
on a 32-bit platform.

The struct krlimit representing the kernel version of
the struct rlimit is introduced to address the issue:
the function restore_rlims() is fixed to convert between
the userspace and kernel representations of the struct.

Signed-off-by: Alexander Kartashov <alekskartashov at parallels.com>
---
 arch/x86/syscall-x86-64.def |    2 +-
 include/syscall-types.h     |    5 +++++
 pie/restorer.c              |    9 +++++++--
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/arch/x86/syscall-x86-64.def b/arch/x86/syscall-x86-64.def
index 6786986..fc6ed26 100644
--- a/arch/x86/syscall-x86-64.def
+++ b/arch/x86/syscall-x86-64.def
@@ -61,7 +61,7 @@ __NR_setpriority	141		sys_setpriority		(int which, int who, int nice)
 __NR_sched_setscheduler	144		sys_sched_setscheduler	(int pid, int policy, struct sched_param *p)
 __NR_prctl		157		sys_prctl		(int option, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5)
 __NR_arch_prctl		158		sys_arch_prctl		(int option, unsigned long addr)
-__NR_setrlimit		160		sys_setrlimit		(int resource, struct rlimit *rlim)
+__NR_setrlimit		160		sys_setrlimit		(int resource, struct krlimit *rlim)
 __NR_mount		165		sys_mount		(char *dev_nmae, char *dir_name, char *type, unsigned long flags, void *data)
 __NR_umount2		166		sys_umount2		(char *name, int flags)
 __NR_gettid		186		sys_gettid		(void)
diff --git a/include/syscall-types.h b/include/syscall-types.h
index 7ef56bd..40390d5 100644
--- a/include/syscall-types.h
+++ b/include/syscall-types.h
@@ -59,4 +59,9 @@ struct robust_list_head;
 
 struct rlimit;
 
+struct krlimit {
+	unsigned long rlim_cur;
+	unsigned long rlim_max;
+};
+
 #endif /* __CR_SYSCALL_TYPES_H__ */
diff --git a/pie/restorer.c b/pie/restorer.c
index 9f6fdb6..0e0dc78 100644
--- a/pie/restorer.c
+++ b/pie/restorer.c
@@ -147,8 +147,13 @@ static void restore_rlims(struct task_restore_core_args *ta)
 {
 	int r;
 
-	for (r = 0; r < ta->nr_rlim; r++)
-		sys_setrlimit(r, &ta->rlims[r]);
+	for (r = 0; r < ta->nr_rlim; r++) {
+		struct krlimit krlim;
+
+		krlim.rlim_cur = ta->rlims[r].rlim_cur;
+		krlim.rlim_max = ta->rlims[r].rlim_max;
+		sys_setrlimit(r, &krlim);
+	}
 }
 
 static int restore_thread_common(struct rt_sigframe *sigframe,
-- 
1.7.10.4



More information about the CRIU mailing list