parasite: Use thread state hash for fast lookup over thread state areas

We lookup for threads state via hash map, which makes fini
sequence to provide @real for parasite code.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>

Conflicts:
	pie/parasite.c
parasite: Prepare structures for daemon mode

Parasite daemon mode might be considered as a series
of network messages sent from main crtools module to
parasite daemon which spins on a socket waiting for
command to handle.

Simple command handling session might look as

        crtools                     daemon
        |                           |                           |
        | ---> command message ---> |                           |
        |                           | ---> receive command ---> |
        |                           |           ....            |
        |                           |       handle command      |
        |                           |           ....            |
        |                           | <--- send ack       <---  |
        | <--- receive ack     <--- |                           |
        |                           |                           |
        v                           v                           v
      time

where, in case of multithread application [handle command] stage
includes waking up of children threads via futexes, wait until
handling complete and only then send ack back to ctrools module.

This patch brings in description of command message as

struct ctl_msg {
    unsigned int    id;     /* command recipient */
    unsigned int    cmd;    /* command itself */
    unsigned int    ack;    /* ack on command */
    int             err;    /* error code on reply */
};

For example, in case of dumpee being with pid 2 and acquiring
to handle PARASITE_CMD_DUMP_MISC, the command/ack series will look
as

    cmd-msg
    -------
    .id     = 2,
    .cmd    = PARASITE_CMD_DUMP_MISC,
    .ack    = 0,
    .err    = 0,

    ack-msg
    -------
    .id     = 2,
    .cmd    = PARASITE_CMD_DUMP_MISC,
    .ack    = PARASITE_CMD_DUMP_MISC,
    .err    = 0

in case if error happened in parasite, the @err field set accordingly.

For convenience ctl_msg_cmd()/ctl_msg_ack() macros are provided
for control message generations.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
parasite: Initialize @cmd/ack in init_thread

To not fail if one day PARASITE_CMD_IDLE become
non equal to zero.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
parasite: Switch parasite to daemon mode

Parasite daemon mode it quite tricky. One may consider
it as consisting of two parts

 - daemon mode for thread leader
 - daemon mode for regular threads

Thread leader daemon
--------------------

Once thread leader parasite code switched initialized,
it starts spinning on socket listening for commands
to handle.

If the command destination is the thread leader itself it
handles it and replies back the ack to the caller (iow
the main crtools code).

If the recepient is not thread leader but one of threads,
then thread leader wakes up the thread by futex and makes
it to handle the command waiting on futex for result. Once
result obtained, the ack is being sending back to caller.

Thread daemon
-------------

On initialization thread daemon starts waiting a command on futex.
The futex is triggered by thread leader daemon when command received.
Once command is received and handled, the result is reported back to
the thread leader daemon, which in turn send ack message.

Both thread-leader and regular threads require own stack to operate
on since they all are present in memory simultaneously. Thus we use
call_daemon_thread() helper which takes care of providing stack
to the callee.

TODO:

 - ARM requires own wrappers on damonize/trap low-level code,
   at moment x86-64 is only covered

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>

Conflicts:
	parasite-syscall.c
	pie/parasite.c
parasite: use a propper command for getting ack
parasite: restore thread registers

crtools dump should not be destructive.
xxx
dump: block signals with help of ptrace

Currently crtools blocks signals from a parasite code, but for executing
the parasite code a process has to handle all pending non-blocked signals.

It is not a problem until crtools decide to support stopped tasks.
signal
ptrace: don't call PTRACE_INTERRUPT many times

According to the commit message in the kernel git, a new trap flag
JOBCTL_TRAP_INTERRUPT is added, which is set on PTRACE_INTERRUPT and
cleared when any trap happens.

Currently we have a race window beetwen PTRACE_CONT and
PTRACE_INTERRUPT. If a process stops before PTRACE_INTERRUPT,
the flag JOBCTL_TRAP_INTERRUPT will be set once again.

https://bugzilla.openvz.org/show_bug.cgi?id=2569
socket-ext: provide access to socket for a test user
remove extra sync