revert to oldcode
[snitchaser:mainline.git] / checkpoint / clone.c
1
2 #include "syscalls.h"
3
4 #define CLONE_PARENT_SETTID     0x00100000      /*  set the TID in the parent */
5
6 #ifndef SYSCALL_PRINTER
7 #ifdef IN_INJECTOR
8 #include "checkpoint/newprocess.h"
9 #endif
10 int SCOPE
11 post_clone(const struct syscall_regs * regs)
12 {
13 #ifdef IN_INJECTOR
14         int32_t retval = regs->eax;
15         if (retval < 0) {
16                 /* failed */
17                 write_eax(regs);
18                 return 0;
19         }
20
21         /* check whether we support this clone */
22
23         unsigned long clone_flags;
24         unsigned long newsp;
25         uintptr_t parent_tidptr, child_tidptr;
26
27         clone_flags = regs->ebx;
28         newsp = regs->ecx;
29         parent_tidptr = regs->edx;
30         child_tidptr = regs->edi;
31         if (!newsp)
32                 newsp = regs->esp;
33
34         if (retval == 0) {
35                 /* child */
36                 do_child_fork(clone_flags, newsp, regs,
37                                 parent_tidptr, child_tidptr);
38         } else {
39                 write_eax(regs);
40                 /* write the flags */
41                 write_obj(clone_flags);
42                 if (clone_flags & CLONE_PARENT_SETTID) {
43                         ASSERT(parent_tidptr != 0, regs, "!@!@#$%^@#$\n");
44                         write_mem(parent_tidptr, sizeof(long));
45                 }
46
47                 do_parent_fork(clone_flags, newsp, regs,
48                                 parent_tidptr, child_tidptr);
49         }
50 #else
51         INJ_ERROR("call clone in load phase\n");
52         exit(-1);
53 #endif
54         return 0;
55 }
56
57 int SCOPE
58 replay_clone(const struct syscall_regs * regs)
59 {
60         int32_t eax = read_eax();
61         if (eax > 0) {
62                 uint32_t clone_flags;
63                 read_obj(clone_flags);
64                 ASSERT(clone_flags == regs->ebx, regs, "clone flags inconsistent\n");
65                 if (clone_flags & CLONE_PARENT_SETTID) {
66                         uintptr_t parent_tidptr = regs->edx;
67                         read_mem(parent_tidptr, sizeof(long));
68                 }
69         }
70         return eax;
71 }
72 #else
73
74 void
75 output_clone(int nr)
76 {
77         int32_t eax = read_eax();
78         printf("clone:\t%d\n", eax);
79         if (eax > 0) {
80                 uint32_t clone_flags;
81                 read_obj(clone_flags);
82                 if (clone_flags & CLONE_PARENT_SETTID) {
83                         skip(sizeof(long));
84                 }
85         }
86 }
87 #endif
88