Branch Coverage

stack.h
Criterion Covered Total %
branch 112 234 47.8


line true false branch
99 0 3 if (dl->tv_nsec >= 1000000000L) { dl->tv_sec++; dl->tv_nsec -= 1000000000L; }
107 3 2 if (rem->tv_nsec < 0) { rem->tv_sec--; rem->tv_nsec += 1000000000L; }
127 63 0 if (STK_SLOT_STATE(c) == STK_SLOT_EMPTY) {
129 63 0 if (__atomic_compare_exchange_n(ctl_word, &c, nc,
144 18044 0 if (STK_SLOT_STATE(c) == STK_SLOT_FILLED) {
146 18044 0 if (__atomic_compare_exchange_n(ctl_word, &c, nc,
167 4 63 if (t >= cap) return 0;
168 63 0 if (__atomic_compare_exchange_n(&hdr->top, &t, t + 1,
174 0 63 if (cp < sz) memset(stk_slot(h, t) + cp, 0, sz - cp);
177 0 63 if (__atomic_load_n(&hdr->waiters_pop, __ATOMIC_RELAXED) > 0) {
187 0 1 if (stk_try_push(h, val, vlen)) return 1;
188 0 1 if (timeout == 0) return 0;
194 1 0 if (has_dl) stk_make_deadline(timeout, &dl);
201 1 0 if (t >= cap) {
203 1 0 if (has_dl) {
204 0 1 if (!stk_remaining(&dl, &rem)) {
214 0 1 if (stk_try_push(h, val, vlen)) return 1;
215 1 0 if (has_dl && !stk_remaining(&dl, &rem)) {
1 0 if (has_dl && !stk_remaining(&dl, &rem)) {
230 8 18039 if (t == 0) return 0;
231 18039 0 if (__atomic_compare_exchange_n(&hdr->top, &t, t - 1,
237 0 18039 if (__atomic_load_n(&hdr->waiters_push, __ATOMIC_RELAXED) > 0) {
247 0 2 if (stk_try_pop(h, out)) return 1;
248 0 2 if (timeout == 0) return 0;
253 2 0 if (has_dl) stk_make_deadline(timeout, &dl);
260 2 0 if (t == 0) {
262 2 0 if (has_dl) {
263 0 2 if (!stk_remaining(&dl, &rem)) {
273 1 1 if (stk_try_pop(h, out)) return 1;
274 1 0 if (has_dl && !stk_remaining(&dl, &rem)) {
1 0 if (has_dl && !stk_remaining(&dl, &rem)) {
289 3 0 for (int tries = 0; tries < 64; tries++) {
291 0 3 if (t == 0) return 0;
293 0 3 if (STK_SLOT_STATE(c1) != STK_SLOT_FILLED) {
300 3 0 if (c1 == c2 && t == t2) return 1;
3 0 if (c1 == c2 && t == t2) return 1;
344 0 17 if (!h) { munmap(base, msize); return NULL; }
350 3 14 h->path = path ? strdup(path) : NULL;
359 1 2 if (hdr->magic != STK_MAGIC) return 0;
360 0 2 if (hdr->version != STK_VERSION) return 0;
361 0 2 if (hdr->variant_id != expected_variant) return 0;
362 2 0 if (hdr->elem_size == 0 || hdr->capacity == 0) return 0;
0 2 if (hdr->elem_size == 0 || hdr->capacity == 0) return 0;
363 0 2 if (hdr->capacity > 0x7FFFFFFFu) return 0;
364 0 2 if (hdr->total_size != file_size) return 0;
365 0 2 if (hdr->data_off != sizeof(StkHeader)) return 0;
366 0 2 if (hdr->ctl_off != stk_ctl_offset(hdr->elem_size, hdr->capacity)) return 0;
367 0 2 if (hdr->total_size != stk_total_size(hdr->elem_size, hdr->capacity)) return 0;
374 16 0 if (errbuf) errbuf[0] = '\0';
375 0 16 if (capacity == 0) { STK_ERR("capacity must be > 0"); return NULL; }
0 0 if (capacity == 0) { STK_ERR("capacity must be > 0"); return NULL; }
376 0 16 if (elem_size == 0) { STK_ERR("elem_size must be > 0"); return NULL; }
0 0 if (elem_size == 0) { STK_ERR("elem_size must be > 0"); return NULL; }
377 0 16 if (capacity > (UINT64_MAX - sizeof(StkHeader) - 16) / (elem_size + sizeof(uint64_t))) {
378 0 0 STK_ERR("capacity * elem_size overflow"); return NULL;
387 12 4 if (anonymous) {
391 0 12 if (base == MAP_FAILED) { STK_ERR("mmap: %s", strerror(errno)); return NULL; }
0 0 if (base == MAP_FAILED) { STK_ERR("mmap: %s", strerror(errno)); return NULL; }
394 0 4 if (fd < 0) { STK_ERR("open(%s): %s", path, strerror(errno)); return NULL; }
0 0 if (fd < 0) { STK_ERR("open(%s): %s", path, strerror(errno)); return NULL; }
395 0 4 if (flock(fd, LOCK_EX) < 0) { STK_ERR("flock: %s", strerror(errno)); close(fd); return NULL; }
0 0 if (flock(fd, LOCK_EX) < 0) { STK_ERR("flock: %s", strerror(errno)); close(fd); return NULL; }
398 0 4 if (fstat(fd, &st) < 0) {
399 0 0 STK_ERR("fstat: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL;
402 2 2 if (!is_new && (uint64_t)st.st_size < sizeof(StkHeader)) {
0 2 if (!is_new && (uint64_t)st.st_size < sizeof(StkHeader)) {
403 0 0 STK_ERR("%s: file too small (%lld)", path, (long long)st.st_size);
407 2 2 if (is_new) {
408 0 2 if (ftruncate(fd, (off_t)total) < 0) {
409 0 0 STK_ERR("ftruncate: %s", strerror(errno));
413 2 2 map_size = is_new ? (size_t)total : (size_t)st.st_size;
415 0 4 if (base == MAP_FAILED) { STK_ERR("mmap: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; }
0 0 if (base == MAP_FAILED) { STK_ERR("mmap: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; }
417 2 2 if (!is_new) {
418 1 1 if (!stk_validate_header((StkHeader *)base, (uint64_t)st.st_size, variant_id)) {
419 1 0 STK_ERR("invalid or incompatible stack file");
428 2 12 if (fd >= 0) { flock(fd, LOCK_UN); close(fd); }
435 1 0 if (errbuf) errbuf[0] = '\0';
436 0 1 if (capacity == 0) { STK_ERR("capacity must be > 0"); return NULL; }
0 0 if (capacity == 0) { STK_ERR("capacity must be > 0"); return NULL; }
437 0 1 if (elem_size == 0) { STK_ERR("elem_size must be > 0"); return NULL; }
0 0 if (elem_size == 0) { STK_ERR("elem_size must be > 0"); return NULL; }
438 0 1 if (capacity > (UINT64_MAX - sizeof(StkHeader) - 16) / (elem_size + sizeof(uint64_t))) {
439 0 0 STK_ERR("capacity * elem_size overflow"); return NULL;
443 1 0 int fd = memfd_create(name ? name : "stack", MFD_CLOEXEC | MFD_ALLOW_SEALING);
444 0 1 if (fd < 0) { STK_ERR("memfd_create: %s", strerror(errno)); return NULL; }
0 0 if (fd < 0) { STK_ERR("memfd_create: %s", strerror(errno)); return NULL; }
445 0 1 if (ftruncate(fd, (off_t)total) < 0) { STK_ERR("ftruncate: %s", strerror(errno)); close(fd); return NULL; }
0 0 if (ftruncate(fd, (off_t)total) < 0) { STK_ERR("ftruncate: %s", strerror(errno)); close(fd); return NULL; }
448 0 1 if (base == MAP_FAILED) { STK_ERR("mmap: %s", strerror(errno)); close(fd); return NULL; }
0 0 if (base == MAP_FAILED) { STK_ERR("mmap: %s", strerror(errno)); close(fd); return NULL; }
454 1 0 if (errbuf) errbuf[0] = '\0';
456 0 1 if (fstat(fd, &st) < 0) { STK_ERR("fstat: %s", strerror(errno)); return NULL; }
0 0 if (fstat(fd, &st) < 0) { STK_ERR("fstat: %s", strerror(errno)); return NULL; }
457 0 1 if ((uint64_t)st.st_size < sizeof(StkHeader)) { STK_ERR("too small"); return NULL; }
0 0 if ((uint64_t)st.st_size < sizeof(StkHeader)) { STK_ERR("too small"); return NULL; }
460 0 1 if (base == MAP_FAILED) { STK_ERR("mmap: %s", strerror(errno)); return NULL; }
0 0 if (base == MAP_FAILED) { STK_ERR("mmap: %s", strerror(errno)); return NULL; }
461 0 1 if (!stk_validate_header((StkHeader *)base, (uint64_t)st.st_size, variant_id)) {
462 0 0 STK_ERR("invalid stack"); munmap(base, ms); return NULL;
465 0 1 if (myfd < 0) { STK_ERR("fcntl: %s", strerror(errno)); munmap(base, ms); return NULL; }
0 0 if (myfd < 0) { STK_ERR("fcntl: %s", strerror(errno)); munmap(base, ms); return NULL; }
470 0 17 if (!h) return;
471 2 15 if (h->notify_fd >= 0) close(h->notify_fd);
472 2 15 if (h->backing_fd >= 0) close(h->backing_fd);
473 17 0 if (h->hdr) munmap(h->hdr, h->mmap_size);
483 0 3 if (__atomic_load_n(&h->hdr->waiters_push, __ATOMIC_RELAXED) > 0) {
487 0 3 if (__atomic_load_n(&h->hdr->waiters_pop, __ATOMIC_RELAXED) > 0) {
498 1 1 if (t == 0) return 0;
499 5 1 for (uint32_t i = 0; i < t; i++) {
504 0 1 if (__atomic_load_n(&hdr->waiters_push, __ATOMIC_RELAXED) > 0) {
506 0 0 syscall(SYS_futex, &hdr->push_wake_seq, FUTEX_WAKE,
514 0 2 if (h->notify_fd >= 0) return h->notify_fd;
516 0 2 if (efd < 0) return -1;
521 0 3 if (h->notify_fd < 0) return 0;
526 0 2 if (h->notify_fd < 0) return -1;
528 0 2 if (read(h->notify_fd, &v, sizeof(v)) != sizeof(v)) return -1;