-
Notifications
You must be signed in to change notification settings - Fork 4
/
dtrace_dyld.cpp
69 lines (58 loc) · 1.79 KB
/
dtrace_dyld.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* dtrace_dyld.cpp
* dtrace
*
* Created by James McIlree on 3/30/09.
* Copyright 2009 Apple Inc.. All rights reserved.
*
*/
#include <unistd.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <mach/mach.h>
#include <mach-o/dyld_images.h>
#include "CSCppTimeoutLock.hpp"
#include "CSCppDyldSharedMemoryPage.hpp"
static
void prepareDTraceRPC() __attribute__((constructor));
static
void prepareDTraceRPC()
{
unsetenv("DYLD_INSERT_LIBRARIES"); /* children must not have this present in their env */
task_dyld_info_data_t task_dyld_info;
mach_msg_type_number_t count = TASK_DYLD_INFO_COUNT;
if (kern_return_t err = task_info(mach_task_self(), TASK_DYLD_INFO, (task_info_t)&task_dyld_info, &count)) {
mach_error("Call to task_info failed ", err);
exit(1);
}
// This should NEVER happen. We're running in process, so we have to be initialized...
if (task_dyld_info.all_image_info_addr == 0) {
fprintf(stderr, "Impossible failure, task_dyld_info returned NULL all_image_info_addr. Please report this bug!\n");
exit(1);
}
struct dyld_all_image_infos* aii = (struct dyld_all_image_infos*)task_dyld_info.all_image_info_addr;
if (CSCppDyldSharedMemoryPage* connection = (CSCppDyldSharedMemoryPage*)aii->coreSymbolicationShmPage) {
bool should_send_notice = false;
//
// First we encode data for the ping
//
{
CSCppTimeoutLock lock(connection->lock_addr(), connection->timeout());
if (lock.is_locked()) {
connection->increment_data_generation();
uint64_t* data = (uint64_t*)connection->data();
data[0] = 666;
should_send_notice = true;
}
}
//
// Now we ping everyone
//
if (should_send_notice) {
uint32_t sent, recv;
connection->send_notice(CORESYMBOLICATION_DYLD_PING_MSGH_ID, sent, recv);
}
}
}