/* Loop over all child structs in the children list and free them */ static void free_children(struct tracy_ll *children) { struct tracy_child *tc; struct tracy_ll_item *cur = children->head; /* Walk over all items in the list */ while(cur) { tc = cur->data; /* Detach or kill */ if (tc->attached) { fprintf(stderr, _b("Detaching from child %d")"\n", tc->pid); PTRACE_CHECK_NORETURN(PTRACE_DETACH, tc->pid, NULL, NULL); /* TODO: What can we do in case of failure? */ } else { fprintf(stderr, _b("Killing child %d")"\n", tc->pid); tracy_kill_child(tc); } /* Free data and fetch next item */ cur = cur->next; } return; }
int hook_gettimeofday(struct tracy_event *e) { struct timeval tv = {1700, 0}; int err; if (e->child->pre_syscall) { e->child->custom = (void*)e->args.a0; } else { if (e->child->custom) { err = tracy_write_mem(e->child, (tracy_child_addr_t)e->child->custom, (tracy_parent_addr_t)&tv, sizeof(struct timeval)); if (err < 0) { fprintf(stderr, "tracy_write_mem returned %d\n", err); tracy_kill_child(e->child); } } } return TRACY_HOOK_CONTINUE; }
int hook_clock_gettime(struct tracy_event *e) { struct timespec tp = {2000, 0}; int err; if (e->child->pre_syscall) { if (e->args.a0 == CLOCK_REALTIME || e->args.a0 == CLOCK_REALTIME_COARSE) { e->child->custom = (void*)e->args.a1; } else { e->child->custom = NULL; } } else { if (e->child->custom) { err = tracy_write_mem(e->child, (tracy_child_addr_t)e->child->custom, (tracy_parent_addr_t)&tp, sizeof(struct timespec)); if (err < 0) { fprintf(stderr, "tracy_write_mem returned %d\n", err); tracy_kill_child(e->child); } } } return TRACY_HOOK_CONTINUE; }