Arnaldo Carvalho de Melo | d5d71e8 | 2016-05-06 12:45:25 -0300 | [diff] [blame] | 1 | #include <linux/futex.h> |
| 2 | |
Arnaldo Carvalho de Melo | e53e6bb | 2016-07-12 11:02:37 -0300 | [diff] [blame^] | 3 | #ifndef FUTEX_WAIT_BITSET |
| 4 | #define FUTEX_WAIT_BITSET 9 |
| 5 | #endif |
| 6 | #ifndef FUTEX_WAKE_BITSET |
| 7 | #define FUTEX_WAKE_BITSET 10 |
| 8 | #endif |
| 9 | #ifndef FUTEX_WAIT_REQUEUE_PI |
| 10 | #define FUTEX_WAIT_REQUEUE_PI 11 |
| 11 | #endif |
| 12 | #ifndef FUTEX_CMP_REQUEUE_PI |
| 13 | #define FUTEX_CMP_REQUEUE_PI 12 |
| 14 | #endif |
| 15 | #ifndef FUTEX_CLOCK_REALTIME |
| 16 | #define FUTEX_CLOCK_REALTIME 256 |
| 17 | #endif |
| 18 | |
Arnaldo Carvalho de Melo | d5d71e8 | 2016-05-06 12:45:25 -0300 | [diff] [blame] | 19 | static size_t syscall_arg__scnprintf_futex_op(char *bf, size_t size, struct syscall_arg *arg) |
| 20 | { |
| 21 | enum syscall_futex_args { |
| 22 | SCF_UADDR = (1 << 0), |
| 23 | SCF_OP = (1 << 1), |
| 24 | SCF_VAL = (1 << 2), |
| 25 | SCF_TIMEOUT = (1 << 3), |
| 26 | SCF_UADDR2 = (1 << 4), |
| 27 | SCF_VAL3 = (1 << 5), |
| 28 | }; |
| 29 | int op = arg->val; |
| 30 | int cmd = op & FUTEX_CMD_MASK; |
| 31 | size_t printed = 0; |
| 32 | |
| 33 | switch (cmd) { |
| 34 | #define P_FUTEX_OP(n) case FUTEX_##n: printed = scnprintf(bf, size, #n); |
| 35 | P_FUTEX_OP(WAIT); arg->mask |= SCF_VAL3|SCF_UADDR2; break; |
| 36 | P_FUTEX_OP(WAKE); arg->mask |= SCF_VAL3|SCF_UADDR2|SCF_TIMEOUT; break; |
| 37 | P_FUTEX_OP(FD); arg->mask |= SCF_VAL3|SCF_UADDR2|SCF_TIMEOUT; break; |
| 38 | P_FUTEX_OP(REQUEUE); arg->mask |= SCF_VAL3|SCF_TIMEOUT; break; |
| 39 | P_FUTEX_OP(CMP_REQUEUE); arg->mask |= SCF_TIMEOUT; break; |
| 40 | P_FUTEX_OP(CMP_REQUEUE_PI); arg->mask |= SCF_TIMEOUT; break; |
| 41 | P_FUTEX_OP(WAKE_OP); break; |
| 42 | P_FUTEX_OP(LOCK_PI); arg->mask |= SCF_VAL3|SCF_UADDR2|SCF_TIMEOUT; break; |
| 43 | P_FUTEX_OP(UNLOCK_PI); arg->mask |= SCF_VAL3|SCF_UADDR2|SCF_TIMEOUT; break; |
| 44 | P_FUTEX_OP(TRYLOCK_PI); arg->mask |= SCF_VAL3|SCF_UADDR2; break; |
| 45 | P_FUTEX_OP(WAIT_BITSET); arg->mask |= SCF_UADDR2; break; |
| 46 | P_FUTEX_OP(WAKE_BITSET); arg->mask |= SCF_UADDR2; break; |
| 47 | P_FUTEX_OP(WAIT_REQUEUE_PI); break; |
| 48 | default: printed = scnprintf(bf, size, "%#x", cmd); break; |
| 49 | } |
| 50 | |
| 51 | if (op & FUTEX_PRIVATE_FLAG) |
| 52 | printed += scnprintf(bf + printed, size - printed, "|PRIV"); |
| 53 | |
| 54 | if (op & FUTEX_CLOCK_REALTIME) |
| 55 | printed += scnprintf(bf + printed, size - printed, "|CLKRT"); |
| 56 | |
| 57 | return printed; |
| 58 | } |
| 59 | |
| 60 | #define SCA_FUTEX_OP syscall_arg__scnprintf_futex_op |