[CRIU] [PATCH 16/16] syscalls: Complete redesign

Cyrill Gorcunov gorcunov at openvz.org
Fri Mar 30 18:46:34 EDT 2012


At early days we've been using only a few syscalls
which together with debug compiler options always
produce relative addresses for memory variables used
in parasite and restorer blobs. Thus it came in unnoticed
that there is something worng with syscalls declarations
we use.

Basically all our syscalls are just a wrappers over inline
assembly code in form of

static long syscall2(int nr, long arg0, long arg1)
{
	long ret;
	asm volatile(
		"movl %1, %%eax		\t\n"
		"movq %2, %%rdi		\t\n"
		"movq %3, %%rsi		\t\n"
		"syscall		\t\n"
		"movq %%rax, %0		\t\n"
		: "=r"(ret)
		: "g" ((int)nr), "g" (arg0), "g" (arg1)
		: "rax", "rdi", "rsi", "memory");
	return ret;
}

so every argument treated to be plain long (even if the call
sematics implies it's a memory address passed but not some
integer direct value) and transferred via general purpose
register.

As being mentioned it caused no problems when debug options
specified at compile time, the compiler do not tries to optimize
addressing but generates code which always compute them.

The situation is changed if one is building crtools with
optimization enabled -- the compiler finds that arguments
are rather plain long numbers and might pass direct addresses
of variables, instead of generating relative addresses
(because function declarations have no pointers and 'g' in cope
 with 'mov' is used, which is of course wrong).

To fix all this -- now syscalls declarations are generated from
syscall.def file and function arguments are passed in conform
with x86-64 ABI.

This shrinks amount of source code needed to declare syscalls
and opens a way to use optimization.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 Makefile                |    9 +-
 Makefile.inc            |    1 +
 Makefile.pie            |   18 +-
 Makefile.syscall        |   37 ++++
 cr-restore.c            |    2 +-
 include/syscall-codes.h |   62 -------
 include/syscall-types.h |   51 ++++++
 include/syscall.def     |   57 ++++++
 include/syscall.h       |  435 -----------------------------------------------
 parasite.c              |   14 +-
 restorer.c              |   20 +-
 syscall-common.S        |   16 ++
 syscalls.pl             |   51 ++++++
 13 files changed, 245 insertions(+), 528 deletions(-)
 create mode 100644 Makefile.syscall
 delete mode 100644 include/syscall-codes.h
 create mode 100644 include/syscall-types.h
 create mode 100644 include/syscall.def
 delete mode 100644 include/syscall.h
 create mode 100644 syscall-common.S
 create mode 100644 syscalls.pl

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0016-syscalls-Complete-redesign.patch
Type: text/x-patch
Size: 29877 bytes
Desc: not available
Url : http://openvz.org/pipermail/criu/attachments/20120331/bc5edd48/0016-syscalls-Complete-redesign-0001.bin


More information about the CRIU mailing list