rst: Add abstract rst_info on pstree_item

The plan is to put collected resources on this to avoid seeking the image.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
files: Rename fdinfo_list_entry's list to desc_list

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
files: Named constant for fdinfo_list_entry pool size

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
files: Put fdinfo entry on fdinfo_list_entry

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
files: Collect fdinfo-s on per-pstree_item list

Later we'll be able to restore them without re-reading the fdinfo file again.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
files: Simplify fd-s restore

Don't re-read fdinfo image 4 times on restore, just use those collected
on me pstree_entry instance.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
make: Sanitize pie.lds.S

Build one "section for all" only. This reflects
what we really do runtime with generated parasite
and restorer blobs.

Signle section is named as ".crblob".

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
make: Generate offsets from linked files only

Instead of generating offsets from early compiled
object files (one day the offsets obtained from
there might be changed during linkage stage) better
to get them from a final stage where all object
files involved are linked into complete binary blob.

That happened that at early stage we indeed were using
only single file per parasite and restorer but at present
there a couple of file involved (and will be more in
future) so we need a safe approach.

Also note the symbols being exported are prefixed as
"__export_". This is easier approach for now. Putting
such symbols into separate section requires a way
more efforts to handle.

The main reason of having two files (Elf object
and binary blob) is to get 1:1 mapping between
symbols definition and their position in binary
target.

The exported symbols name addresses are obtained
from object file and used as offsets in binary
target.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
make: Add own Makefile.pie for binary blobs we generate

Since the blob files are generated a different way
in compare with plain compiling we use for regular
*.c files -- add own Makefile.pie for this target.

This increases readability of general Makefile
and Makefile.pie itself.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
parasite: Move bootstrap code into parasite-head-x86-64.S

Inline assembly is very convenient if a couple of
instructions is used but when it grows better to
move it out of wrapper C code and write in plain
assembly, after all we need a very precise control
in bootstrap code.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
syscalls: Complete redesign v9

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@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
dump: Init mmap's file pos

It's unused, but makes show command show 0, not trash.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
sockets: Restore unconnected dgram sockets v7

In case if dgram socket peer is not connected back
we can try to resolve peer by name.

For security reason this happens only if '-x' option
is passed at checkpoint and restore time.

In particular this is needed for programs which do
use dgram socket to send messages to /dev/log.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
make: Fix typo in Makefile.syscall

Should be -fpie (actually it's not a problem
at moment since asm files have simple code
and work even without -fpie passed, but better
to fix it anyaway).

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
make: Simplify Makefile.pie

No need to duplicate variable for pie.lds.S.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
make: Split generation of %.bin and %.bin.o into two rules

This allows to have more detailed control over files
generated and might be extended in future.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
sockets: Use socket family for inet_ntop

Will need it for IPv6

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
sockets: Align output in collected unix/inet sockets debug printing

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
sockets: Show uncollected socket ino in hex

To be in same form as collected sockets.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
sockets: Use socket family in show_inetsk

Needed for IPv6.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>