From d34b9004a725446fadcf36e4e97aedf0fa460a1f Mon Sep 17 00:00:00 2001 From: Andrey Vagin Date: Tue, 28 Aug 2012 23:19:28 +0400 Subject: [PATCH] restore: use a currect stack for new processes (v3) Why do we need a new stack? We already have one and it can be used. We need to step a bit for executing a glibc clone() v2: Don't lose a page from a child's stack v3: Remove the defined constant STACK_SIZE Signed-off-by: Andrey Vagin Acked-by: Cyrill Gorcunov Signed-off-by: Pavel Emelyanov --- cr-restore.c | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/cr-restore.c b/cr-restore.c index 514787a74..586976b81 100644 --- a/cr-restore.c +++ b/cr-restore.c @@ -480,14 +480,10 @@ out: return ret; } -/* - * This stack size is important for the restorer - * itself only. At the final phase, we will switch - * to the original stack the program had at checkpoint - * time. - */ -#define STACK_SIZE (8 * 4096) +/* All arguments should be above stack, because it grows down */ struct cr_clone_arg { + char stack[PAGE_SIZE]; + char stack_ptr[0]; struct pstree_item *item; unsigned long clone_flags; int fd; @@ -497,18 +493,10 @@ static inline int fork_with_pid(struct pstree_item *item, unsigned long ns_clone { int ret = -1; struct cr_clone_arg ca; - void *stack; pid_t pid = item->pid.virt; pr_info("Forking task with %d pid (flags 0x%lx)\n", pid, ns_clone_flags); - stack = mmap(NULL, STACK_SIZE, PROT_WRITE | PROT_READ, - MAP_PRIVATE | MAP_GROWSDOWN | MAP_ANONYMOUS, -1, 0); - if (stack == MAP_FAILED) { - pr_perror("Failed to map stack for the child"); - goto err; - } - ca.item = item; ca.clone_flags = ns_clone_flags; @@ -544,7 +532,7 @@ static inline int fork_with_pid(struct pstree_item *item, unsigned long ns_clone if (netns_pre_create()) goto err_unlock; - ret = clone(restore_task_with_children, stack + STACK_SIZE, + ret = clone(restore_task_with_children, ca.stack_ptr, ca.clone_flags | SIGCHLD, &ca); if (ret < 0) @@ -574,8 +562,6 @@ err_unlock: close(ca.fd); } err: - if (stack != MAP_FAILED) - munmap(stack, STACK_SIZE); return ret; }