10 #include "xlat/semop_flags.h"
15 unsigned short *array;
16 struct seminfo *__buf;
24 semctl(id, 0, IPC_RMID, 0);
31 static const int bogus_semid = 0xfdb97531;
32 static void * const bogus_sops = (void *) -1L;
33 static const size_t bogus_nsops = (size_t) 0xdefaceddeadbeefULL;
35 TAIL_ALLOC_OBJECT_CONST_PTR(struct timespec, ts);
38 id = semget(IPC_PRIVATE, 1, 0600);
40 perror_msg_and_skip("semget");
43 union semun sem_union = { .val = 0 };
44 if (semctl(id, 0, SETVAL, sem_union) == -1)
45 perror_msg_and_skip("semctl");
47 TAIL_ALLOC_OBJECT_CONST_PTR(struct sembuf, sem_b);
48 TAIL_ALLOC_OBJECT_CONST_PTR(struct sembuf, sem_b2);
50 rc = semop(bogus_semid, NULL, bogus_nsops);
51 printf("semop(%d, NULL, %u) = %s\n",
52 bogus_semid, (unsigned) bogus_nsops, sprintrc(rc));
54 rc = semop(bogus_semid, bogus_sops, 1);
55 printf("semop(%d, %p, %u) = %s\n",
56 bogus_semid, bogus_sops, 1, sprintrc(rc));
60 sem_b->sem_flg = SEM_UNDO;
62 sem_b2->sem_num = 0xface;
63 sem_b2->sem_op = 0xf00d;
64 sem_b2->sem_flg = 0xbeef;
66 rc = semop(bogus_semid, sem_b2, 2);
67 printf("semop(%d, [{%hu, %hd, %s%s%#hx}, %p], %u) = %s\n",
68 bogus_semid, sem_b2->sem_num, sem_b2->sem_op,
69 sem_b2->sem_flg & SEM_UNDO ? "SEM_UNDO|" : "",
70 sem_b2->sem_flg & IPC_NOWAIT ? "IPC_NOWAIT|" : "",
71 sem_b2->sem_flg & ~(SEM_UNDO | IPC_NOWAIT),
72 sem_b2 + 1, 2, sprintrc(rc));
74 if (semop(id, sem_b, 1))
75 perror_msg_and_skip("semop, 1");
76 printf("semop(%d, [{0, 1, SEM_UNDO}], 1) = 0\n", id);
79 if (semop(id, sem_b, 1))
80 perror_msg_and_skip("semop, -1");
81 printf("semop(%d, [{0, -1, SEM_UNDO}], 1) = 0\n", id);
83 rc = semtimedop(bogus_semid, NULL, bogus_nsops, NULL);
84 printf("semtimedop(%d, NULL, %u, NULL) = %s\n",
85 bogus_semid, (unsigned) bogus_nsops, sprintrc(rc));
87 rc = semtimedop(id, sem_b + 1, 1, ts + 1);
88 printf("semtimedop(%d, %p, 1, %p) = %s\n",
89 id, sem_b + 1, ts + 1, sprintrc(rc));
92 ts->tv_nsec = 123456789;
93 rc = semtimedop(bogus_semid, sem_b2, 2, ts);
94 printf("semtimedop(%d, [{%hu, %hd, %s%s%#hx}, %p], %u"
95 ", {tv_sec=%lld, tv_nsec=%llu}) = %s\n",
96 bogus_semid, sem_b2->sem_num, sem_b2->sem_op,
97 sem_b2->sem_flg & SEM_UNDO ? "SEM_UNDO|" : "",
98 sem_b2->sem_flg & IPC_NOWAIT ? "IPC_NOWAIT|" : "",
99 sem_b2->sem_flg & ~(SEM_UNDO | IPC_NOWAIT),
101 (long long) ts->tv_sec, zero_extend_signed_to_ull(ts->tv_nsec),
105 if (semtimedop(id, sem_b, 1, NULL))
106 perror_msg_and_skip("semtimedop, 1");
107 printf("semtimedop(%d, [{0, 1, SEM_UNDO}], 1, NULL) = 0\n", id);
110 if (semtimedop(id, sem_b, 1, ts))
111 perror_msg_and_skip("semtimedop, -1");
112 printf("semtimedop(%d, [{0, -1, SEM_UNDO}], 1"
113 ", {tv_sec=%lld, tv_nsec=%llu}) = 0\n", id,
114 (long long) ts->tv_sec, zero_extend_signed_to_ull(ts->tv_nsec));
117 ts->tv_sec = 0xdeadbeefU;
118 ts->tv_nsec = 0xfacefeedU;
119 rc = semtimedop(id, sem_b, 1, ts);
120 printf("semtimedop(%d, [{0, 1, SEM_UNDO}], 1"
121 ", {tv_sec=%lld, tv_nsec=%llu}) = %s\n",
122 id, (long long) ts->tv_sec,
123 zero_extend_signed_to_ull(ts->tv_nsec), sprintrc(rc));
126 ts->tv_sec = (time_t) 0xcafef00ddeadbeefLL;
127 ts->tv_nsec = (long) 0xbadc0dedfacefeedLL;
128 rc = semtimedop(id, sem_b, 1, ts);
129 printf("semtimedop(%d, [{0, -1, SEM_UNDO}], 1"
130 ", {tv_sec=%lld, tv_nsec=%llu}) = %s\n",
131 id, (long long) ts->tv_sec,
132 zero_extend_signed_to_ull(ts->tv_nsec), sprintrc(rc));
134 puts("+++ exited with 0 +++");