[CRIU] [PATCH 19/20] x86/restorer/tls: simplify restoring of TLS

Dmitry Safonov dsafonov at virtuozzo.com
Fri Dec 2 11:53:43 PST 2016


We can live here without 32-bit CS - this syscall doesn't depend on
descriptor type.
No functional changes expected, cleanup.

Signed-off-by: Dmitry Safonov <dsafonov at virtuozzo.com>
---
 criu/arch/x86/restorer.c | 51 ++++++++++--------------------------------------
 1 file changed, 10 insertions(+), 41 deletions(-)

diff --git a/criu/arch/x86/restorer.c b/criu/arch/x86/restorer.c
index 050241cca8a2..06854a7af09f 100644
--- a/criu/arch/x86/restorer.c
+++ b/criu/arch/x86/restorer.c
@@ -33,60 +33,29 @@ int restore_nonsigframe_gpregs(UserX86RegsEntry *r)
 }
 
 #ifdef CONFIG_COMPAT
-asm (	"	.pushsection .text				\n"
-	"	.global restore_set_thread_area			\n"
-	"	.code32						\n"
-	"restore_set_thread_area:				\n"
-	"	movl $"__stringify(__NR32_set_thread_area)",%eax\n"
-	"	int $0x80					\n"
-	"	ret						\n"
-	"	.popsection					\n"
-	"	.code64");
-extern char restore_set_thread_area;
-
-static void *stack32;
-
-static int prepare_stack32(void)
-{
-
-	if (stack32)
-		return 0;
-
-	stack32 = alloc_compat_syscall_stack();
-	if (!stack32) {
-		pr_err("Failed to allocate stack for 32-bit TLS restore\n");
-		return -1;
-	}
-
-	return 0;
-}
-
 void restore_tls(tls_t *ptls)
 {
-	int i;
+	unsigned i;
 
 	for (i = 0; i < GDT_ENTRY_TLS_NUM; i++) {
 		user_desc_t *desc = &ptls->desc[i];
-		int ret;
+		long int ret;
 
 		if (desc->seg_not_present)
 			continue;
 
-		if (prepare_stack32() < 0)
-			return;
-
-		builtin_memcpy(stack32, desc, sizeof(user_desc_t));
+		asm volatile (
+		"       mov %1,%%rax                    \n"
+		"       mov %2,%%rdi                    \n"
+		"	int $0x80			\n"
+		"	mov %%rax,%0			\n"
+		: "=g"(ret) : "r"((u64)__NR32_set_thread_area), "r"(desc)
+		: "rax", "rdi", "memory");
 
-		/* user_desc parameter for set_thread_area syscall */
-		asm volatile ("\t movl %%ebx,%%ebx\n" : :"b"(stack32));
-		call32_from_64(stack32 + PAGE_SIZE, &restore_set_thread_area);
-		asm volatile ("\t movl %%eax,%0\n" : "=r"(ret));
 		if (ret)
-			pr_err("Failed to restore TLS descriptor %d in GDT ret %d\n",
+			pr_err("Failed to restore TLS descriptor %u in GDT : %ld\n",
 					desc->entry_number, ret);
 	}
 
-	if (stack32)
-		free_compat_syscall_stack(stack32);
 }
 #endif
-- 
2.10.2



More information about the CRIU mailing list