MCPcopy Create free account
hub / github.com/GJDuck/e9patch / entry

Function entry

examples/limit.c:44–84  ·  view source on GitHub ↗

* Entry point. */

Source from the content-addressed store, hash-verified

42 * Entry point.
43 */
44void entry(const void *addr)
45{
46 if (mutex_lock(&mutex) < 0)
47 {
48 if (errno == EOWNERDEAD)
49 {
50 fputs("thread died with lock\n", stderr);
51 abort();
52 }
53 return;
54 }
55
56 // This uses tfind()/tsearch() to track instruction counts.
57 // For more information, see the tsearch manpage (man tsearch).
58 ENTRY key = {addr, 0}, *entry = NULL;
59 void *node = tfind(&key, &TREE, compare);
60 if (node == NULL)
61 {
62 entry = (ENTRY *)malloc(sizeof(ENTRY));
63 if (entry == NULL)
64 {
65error_no_mem:
66 fputs("failed to allocate memory\n", stderr);
67 abort();
68 }
69 entry->addr = addr;
70 entry->count = 0;
71 node = tsearch(entry, &TREE, compare);
72 if (node == NULL)
73 goto error_no_mem;
74 }
75 entry = *(ENTRY **)node;
76 entry->count++;
77 if (entry->count > limit)
78 {
79 fprintf(stderr, "limit=%zu reached @ addr=%p\n", limit, addr);
80 abort();
81 }
82
83 mutex_unlock(&mutex);
84}
85
86/*
87 * Init.

Callers

nothing calls this directly

Calls 8

mutex_lockFunction · 0.85
fputsFunction · 0.85
abortFunction · 0.85
tfindFunction · 0.85
mallocFunction · 0.85
tsearchFunction · 0.85
mutex_unlockFunction · 0.85
fprintfFunction · 0.70

Tested by

no test coverage detected