* Entry point. */
| 42 | * Entry point. |
| 43 | */ |
| 44 | void 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 | { |
| 65 | error_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. |
nothing calls this directly
no test coverage detected