| line |
true |
false |
branch |
|
102
|
0 |
0 |
if (pid == 0) return 1; |
|
103
|
0 |
0 |
return !(kill((pid_t)pid, 0) == -1 && errno == ESRCH); |
|
|
0 |
0 |
return !(kill((pid_t)pid, 0) == -1 && errno == ESRCH); |
|
110
|
110 |
0 |
if (__atomic_compare_exchange_n(&hdr->mutex, &expected, mypid, |
|
113
|
0 |
0 |
if (spin < 32) { |
|
123
|
0 |
0 |
if (cur != 0) { |
|
126
|
0 |
0 |
if (rc == -1 && errno == ETIMEDOUT && cur >= GRAPH_MUTEX_BIT) { |
|
|
0 |
0 |
if (rc == -1 && errno == ETIMEDOUT && cur >= GRAPH_MUTEX_BIT) { |
|
|
0 |
0 |
if (rc == -1 && errno == ETIMEDOUT && cur >= GRAPH_MUTEX_BIT) { |
|
128
|
0 |
0 |
if (!graph_pid_alive(pid) && |
|
129
|
0 |
0 |
__atomic_compare_exchange_n(&hdr->mutex, &cur, 0, |
|
143
|
0 |
110 |
if (__atomic_load_n(&hdr->mutex_waiters, __ATOMIC_RELAXED) > 0) |
|
157
|
90 |
0 |
for (uint32_t w = 0; w < bwords; w++) { |
|
159
|
0 |
90 |
if (word == ~(uint64_t)0) continue; |
|
162
|
0 |
90 |
if (idx >= max) return -1; |
|
179
|
0 |
80 |
if (idx < 0) return -1; |
|
187
|
11 |
0 |
if (src >= h->hdr->max_nodes || dst >= h->hdr->max_nodes) return 0; |
|
|
0 |
11 |
if (src >= h->hdr->max_nodes || dst >= h->hdr->max_nodes) return 0; |
|
188
|
10 |
1 |
if (!graph_bit_set(h->node_bitmap, src) || !graph_bit_set(h->node_bitmap, dst)) |
|
|
0 |
10 |
if (!graph_bit_set(h->node_bitmap, src) || !graph_bit_set(h->node_bitmap, dst)) |
|
191
|
0 |
10 |
if (eidx < 0) return 0; |
|
201
|
0 |
5 |
if (node >= h->hdr->max_nodes) return 0; |
|
202
|
0 |
5 |
if (!graph_bit_set(h->node_bitmap, node)) return 0; |
|
205
|
2 |
5 |
while (eidx != GRAPH_NONE) { |
|
220
|
1 |
3 |
if (node >= h->hdr->max_nodes) return 0; |
|
221
|
0 |
3 |
if (!graph_bit_set(h->node_bitmap, node)) return 0; |
|
223
|
20 |
3 |
for (uint32_t src = 0; src < max_n; src++) { |
|
224
|
3 |
17 |
if (src == node) continue; |
|
225
|
13 |
4 |
if (!graph_bit_set(h->node_bitmap, src)) continue; |
|
228
|
3 |
4 |
while (eidx != GRAPH_NONE) { |
|
230
|
2 |
1 |
if (h->edges[eidx].dst == node) { |
|
280
|
1 |
21 |
if (node >= h->hdr->max_nodes) return 0; |
|
286
|
0 |
8 |
if (node >= h->hdr->max_nodes) return 0; |
|
289
|
11 |
8 |
while (eidx != GRAPH_NONE) { |
|
335
|
206 |
11 |
for (uint32_t i = 0; i < max_nodes; i++) heads[i] = GRAPH_NONE; |
|
343
|
0 |
13 |
if (!h) { |
|
345
|
0 |
0 |
if (backing_fd >= 0) close(backing_fd); |
|
357
|
3 |
10 |
h->path = path ? strdup(path) : NULL; |
|
365
|
0 |
2 |
if (hdr->magic != GRAPH_MAGIC) return 0; |
|
366
|
0 |
2 |
if (hdr->version != GRAPH_VERSION) return 0; |
|
367
|
2 |
0 |
if (hdr->max_nodes == 0 || hdr->max_edges == 0) return 0; |
|
|
0 |
2 |
if (hdr->max_nodes == 0 || hdr->max_edges == 0) return 0; |
|
368
|
2 |
0 |
if (hdr->max_nodes > 0x7FFFFFFFu || hdr->max_edges > 0x7FFFFFFFu) return 0; |
|
|
0 |
2 |
if (hdr->max_nodes > 0x7FFFFFFFu || hdr->max_edges > 0x7FFFFFFFu) return 0; |
|
369
|
0 |
2 |
if (hdr->total_size != file_size) return 0; |
|
370
|
0 |
2 |
if (hdr->total_size != graph_total_size(hdr->max_nodes, hdr->max_edges)) return 0; |
|
378
|
0 |
2 |
if (hdr->node_data_off != exp_node_data) return 0; |
|
379
|
0 |
2 |
if (hdr->node_heads_off != exp_node_heads) return 0; |
|
380
|
0 |
2 |
if (hdr->node_bitmap_off != exp_node_bitmap) return 0; |
|
381
|
0 |
2 |
if (hdr->edge_data_off != exp_edge_data) return 0; |
|
382
|
0 |
2 |
if (hdr->edge_bitmap_off != exp_edge_bitmap) return 0; |
|
388
|
10 |
0 |
if (errbuf) errbuf[0] = '\0'; |
|
389
|
0 |
10 |
if (max_nodes == 0) { GRAPH_ERR("max_nodes must be > 0"); return NULL; } |
|
|
0 |
0 |
if (max_nodes == 0) { GRAPH_ERR("max_nodes must be > 0"); return NULL; } |
|
390
|
0 |
10 |
if (max_edges == 0) { GRAPH_ERR("max_edges must be > 0"); return NULL; } |
|
|
0 |
0 |
if (max_edges == 0) { GRAPH_ERR("max_edges must be > 0"); return NULL; } |
|
391
|
0 |
10 |
if (max_nodes > UINT32_MAX - 63) { GRAPH_ERR("max_nodes too large"); return NULL; } |
|
|
0 |
0 |
if (max_nodes > UINT32_MAX - 63) { GRAPH_ERR("max_nodes too large"); return NULL; } |
|
392
|
0 |
10 |
if (max_edges > UINT32_MAX - 63) { GRAPH_ERR("max_edges too large"); return NULL; } |
|
|
0 |
0 |
if (max_edges > UINT32_MAX - 63) { GRAPH_ERR("max_edges too large"); return NULL; } |
|
400
|
7 |
3 |
if (anonymous) { |
|
403
|
0 |
7 |
if (base == MAP_FAILED) { GRAPH_ERR("mmap: %s", strerror(errno)); return NULL; } |
|
|
0 |
0 |
if (base == MAP_FAILED) { GRAPH_ERR("mmap: %s", strerror(errno)); return NULL; } |
|
406
|
0 |
3 |
if (fd < 0) { GRAPH_ERR("open: %s", strerror(errno)); return NULL; } |
|
|
0 |
0 |
if (fd < 0) { GRAPH_ERR("open: %s", strerror(errno)); return NULL; } |
|
407
|
0 |
3 |
if (flock(fd, LOCK_EX) < 0) { GRAPH_ERR("flock: %s", strerror(errno)); close(fd); return NULL; } |
|
|
0 |
0 |
if (flock(fd, LOCK_EX) < 0) { GRAPH_ERR("flock: %s", strerror(errno)); close(fd); return NULL; } |
|
409
|
0 |
3 |
if (fstat(fd, &st) < 0) { GRAPH_ERR("fstat: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; } |
|
|
0 |
0 |
if (fstat(fd, &st) < 0) { GRAPH_ERR("fstat: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; } |
|
411
|
1 |
2 |
if (!is_new && (uint64_t)st.st_size < sizeof(GraphHeader)) { |
|
|
0 |
1 |
if (!is_new && (uint64_t)st.st_size < sizeof(GraphHeader)) { |
|
412
|
0 |
0 |
GRAPH_ERR("%s: file too small (%lld)", path, (long long)st.st_size); |
|
415
|
2 |
1 |
if (is_new && ftruncate(fd, (off_t)total) < 0) { |
|
|
0 |
2 |
if (is_new && ftruncate(fd, (off_t)total) < 0) { |
|
416
|
0 |
0 |
GRAPH_ERR("ftruncate: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; |
|
418
|
1 |
2 |
map_size = is_new ? (size_t)total : (size_t)st.st_size; |
|
420
|
0 |
3 |
if (base == MAP_FAILED) { GRAPH_ERR("mmap: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; } |
|
|
0 |
0 |
if (base == MAP_FAILED) { GRAPH_ERR("mmap: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; } |
|
421
|
1 |
2 |
if (!is_new) { |
|
422
|
0 |
1 |
if (!graph_validate_header((GraphHeader *)base, (uint64_t)st.st_size)) { |
|
423
|
0 |
0 |
GRAPH_ERR("invalid graph file"); munmap(base, map_size); flock(fd, LOCK_UN); close(fd); return NULL; |
|
430
|
2 |
7 |
if (fd >= 0) { flock(fd, LOCK_UN); close(fd); } |
|
436
|
2 |
0 |
if (errbuf) errbuf[0] = '\0'; |
|
437
|
0 |
2 |
if (max_nodes == 0) { GRAPH_ERR("max_nodes must be > 0"); return NULL; } |
|
|
0 |
0 |
if (max_nodes == 0) { GRAPH_ERR("max_nodes must be > 0"); return NULL; } |
|
438
|
0 |
2 |
if (max_edges == 0) { GRAPH_ERR("max_edges must be > 0"); return NULL; } |
|
|
0 |
0 |
if (max_edges == 0) { GRAPH_ERR("max_edges must be > 0"); return NULL; } |
|
439
|
2 |
0 |
if (max_nodes > UINT32_MAX - 63 || max_edges > UINT32_MAX - 63) { |
|
|
0 |
2 |
if (max_nodes > UINT32_MAX - 63 || max_edges > UINT32_MAX - 63) { |
|
440
|
0 |
0 |
GRAPH_ERR("max_nodes/max_edges too large"); return NULL; |
|
443
|
2 |
0 |
int fd = memfd_create(name ? name : "graph", MFD_CLOEXEC | MFD_ALLOW_SEALING); |
|
444
|
0 |
2 |
if (fd < 0) { GRAPH_ERR("memfd_create: %s", strerror(errno)); return NULL; } |
|
|
0 |
0 |
if (fd < 0) { GRAPH_ERR("memfd_create: %s", strerror(errno)); return NULL; } |
|
445
|
0 |
2 |
if (ftruncate(fd, (off_t)total) < 0) { |
|
446
|
0 |
0 |
GRAPH_ERR("ftruncate: %s", strerror(errno)); close(fd); return NULL; |
|
450
|
0 |
2 |
if (base == MAP_FAILED) { GRAPH_ERR("mmap: %s", strerror(errno)); close(fd); return NULL; } |
|
|
0 |
0 |
if (base == MAP_FAILED) { GRAPH_ERR("mmap: %s", strerror(errno)); close(fd); return NULL; } |
|
456
|
1 |
0 |
if (errbuf) errbuf[0] = '\0'; |
|
458
|
0 |
1 |
if (fstat(fd, &st) < 0) { GRAPH_ERR("fstat: %s", strerror(errno)); return NULL; } |
|
|
0 |
0 |
if (fstat(fd, &st) < 0) { GRAPH_ERR("fstat: %s", strerror(errno)); return NULL; } |
|
459
|
0 |
1 |
if ((uint64_t)st.st_size < sizeof(GraphHeader)) { GRAPH_ERR("too small"); return NULL; } |
|
|
0 |
0 |
if ((uint64_t)st.st_size < sizeof(GraphHeader)) { GRAPH_ERR("too small"); return NULL; } |
|
462
|
0 |
1 |
if (base == MAP_FAILED) { GRAPH_ERR("mmap: %s", strerror(errno)); return NULL; } |
|
|
0 |
0 |
if (base == MAP_FAILED) { GRAPH_ERR("mmap: %s", strerror(errno)); return NULL; } |
|
463
|
0 |
1 |
if (!graph_validate_header((GraphHeader *)base, (uint64_t)st.st_size)) { |
|
464
|
0 |
0 |
GRAPH_ERR("invalid graph"); munmap(base, ms); return NULL; |
|
467
|
0 |
1 |
if (myfd < 0) { GRAPH_ERR("fcntl: %s", strerror(errno)); munmap(base, ms); return NULL; } |
|
|
0 |
0 |
if (myfd < 0) { GRAPH_ERR("fcntl: %s", strerror(errno)); munmap(base, ms); return NULL; } |
|
472
|
0 |
13 |
if (!h) return; |
|
473
|
2 |
11 |
if (h->notify_fd >= 0) close(h->notify_fd); |
|
474
|
3 |
10 |
if (h->backing_fd >= 0) close(h->backing_fd); |
|
475
|
13 |
0 |
if (h->hdr) munmap(h->hdr, h->mmap_size); |
|
481
|
1 |
0 |
if (!h || !h->hdr) return 0; |
|
|
0 |
1 |
if (!h || !h->hdr) return 0; |
|
486
|
0 |
2 |
if (h->notify_fd >= 0) return h->notify_fd; |
|
488
|
0 |
2 |
if (efd < 0) return -1; |
|
494
|
0 |
3 |
if (h->notify_fd < 0) return 0; |
|
500
|
0 |
2 |
if (h->notify_fd < 0) return -1; |
|
502
|
0 |
2 |
if (read(h->notify_fd, &v, sizeof(v)) != sizeof(v)) return -1; |