revert to oldcode
[snitchaser:mainline.git] / checkpoint / futex.c
1
2 #include "syscalls.h"
3
4 #define FUTEX_WAIT              0
5 #define FUTEX_WAKE              1
6 #define FUTEX_FD                2
7 #define FUTEX_REQUEUE           3
8 #define FUTEX_CMP_REQUEUE       4
9 #define FUTEX_WAKE_OP           5
10 #define FUTEX_LOCK_PI           6
11 #define FUTEX_UNLOCK_PI         7
12 #define FUTEX_TRYLOCK_PI        8
13 #define FUTEX_WAIT_BITSET       9
14 #define FUTEX_WAKE_BITSET       10
15
16 #define FUTEX_PRIVATE_FLAG      128
17 #define FUTEX_CMD_MASK          ~FUTEX_PRIVATE_FLAG
18
19
20 #ifndef SYSCALL_PRINTER
21
22 int SCOPE
23 post_futex(const struct syscall_regs * regs)
24 {
25         int32_t eax = regs->eax;
26         write_eax(regs);
27
28         if (eax < 0)
29                 return 0;
30
31         uint32_t uaddr = regs->ebx;
32         int op = regs->ecx;
33         uint32_t uaddr2 =regs->edi;
34
35         int cmd = op & FUTEX_CMD_MASK;
36
37         write_obj(cmd);
38
39         /* write uaddr */
40         write_mem(uaddr, sizeof(uint32_t));
41         switch (cmd) {
42                 case FUTEX_REQUEUE:
43                 case FUTEX_CMP_REQUEUE:
44                 case FUTEX_WAKE_OP:
45                         write_mem(uaddr2, sizeof(uint32_t));
46                 default:
47                         break;
48         }
49         return 0;
50 }
51
52 int SCOPE
53 replay_futex(const struct syscall_regs * regs)
54 {
55         int32_t eax = read_int32();
56         if (eax < 0)
57                 return eax;
58
59         uint32_t uaddr = regs->ebx;
60         int op = regs->ecx;
61         uint32_t uaddr2 =regs->edi;
62
63         int cmd;
64         read_obj(cmd);
65         ASSERT(cmd == (op & FUTEX_CMD_MASK), regs, 
66                         "futex cmd inconsistent: should be 0x%x, actually 0x%x\n",
67                         cmd, op & FUTEX_CMD_MASK);
68
69         /* read uaddr */
70         read_mem(uaddr, sizeof(uint32_t));
71         switch (cmd) {
72                 case FUTEX_REQUEUE:
73                 case FUTEX_CMP_REQUEUE:
74                 case FUTEX_WAKE_OP:
75                         read_mem(uaddr2, sizeof(uint32_t));
76                 default:
77                         break;
78         }
79
80         return eax;
81 }
82 #else
83
84 void
85 output_futex(int nr)
86 {
87         int eax = read_eax();
88         printf("futex:\t0x%x\n", eax);
89         if (eax < 0)
90                 return;
91         uint32_t cmd = read_uint32();
92         skip(sizeof(uint32_t));
93
94         switch (cmd) {
95                 case FUTEX_REQUEUE:
96                 case FUTEX_CMP_REQUEUE:
97                 case FUTEX_WAKE_OP:
98                         skip(sizeof(uint32_t));
99                 default:
100                         break;
101         }
102 }
103 #endif
104