%{_libdir}/libbcc.so.*
%{_prefix}/lib/python2.7/site-packages/bcc*
%{_datadir}/bcc/*
+%{_includedir}/bcc/hostcompat/*
%files dbus
%{_datadir}/bcc/tools/dbus-*
install(FILES ${bcc_table_headers} DESTINATION include/bcc)
install(FILES ${bcc_api_headers} DESTINATION include/bcc)
install(DIRECTORY compat/linux/ DESTINATION include/bcc/compat/linux FILES_MATCHING PATTERN "*.h")
+install(DIRECTORY hostcompat/ DESTINATION include/bcc/hostcompat FILES_MATCHING PATTERN "*.h")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libbcc.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
endif(ENABLE_CLANG_JIT)
install(FILES ${bcc_common_headers} DESTINATION include/bcc)
#define __BPF_HELPERS_H
#include <uapi/linux/bpf.h>
+#ifndef __arm__
#include <uapi/linux/if_packet.h>
+#endif
#include <linux/version.h>
#ifndef CONFIG_BPF_SYSCALL
--- /dev/null
+R"*****(#ifndef HOST32_H
+#define HOST32_H
+
+typedef uint32_t uint_t;
+typedef int32_t int_t;
+typedef uint32_t ptr_t;
+typedef uint32_t ulong_t;
+typedef int32_t long_t;
+
+#endif // HOST32_H)*****"
--- /dev/null
+R"*****(#ifndef HOST64_H
+#define HOST64_H
+
+typedef uint64_t uint_t;
+typedef int64_t int_t;
+typedef uint64_t ptr_t;
+typedef uint64_t ulong_t;
+typedef int64_t long_t;
+
+#endif // HOST64_H)*****"
"/virtual/lib/clang/include/stdarg.h",
#include "clang/include/stdarg.h"
},
+ {
+ "/virtual/include/bcc/host32.h",
+ #include "export/host32.h"
+ },
+ {
+ "/virtual/include/bcc/host64.h",
+ #include "export/host64.h"
+ },
};
}
// noinline and optnone (if not always inlining).
// Note that first argument is ignored in clang compilation invocation.
vector<const char *> flags_cstr({"-O0", "-O2", "-emit-llvm", "-I", dstack.cwd(),
+ "-I/usr/include/bcc",
+ "-I/usr/local/include/bcc",
"-Wno-deprecated-declarations",
"-Wno-gnu-variable-sized-type-not-at-end",
"-Wno-pragma-once-outside-header",
kflags.push_back("/virtual/include/bcc/bpf.h");
kflags.push_back("-include");
kflags.push_back("/virtual/include/bcc/helpers.h");
+#ifdef __arm__
+ kflags.push_back("-include");
+ kflags.push_back("/virtual/include/bcc/host32.h");
+#else
+ kflags.push_back("-include");
+ kflags.push_back("/virtual/include/bcc/host64.h");
+#endif
kflags.push_back("-isystem");
kflags.push_back("/virtual/include");
for (auto it = kflags.begin(); it != kflags.end(); ++it)
#elif defined(__aarch64__)
driver::Driver drv("", "aarch64-unknown-linux-gnu", diags);
#elif defined(__arm__)
- driver::Driver drv("", "armv7l-tizen-linux-gnueabi", diags);
+ driver::Driver drv("", "bpf-pc-linux", diags);
+ flags_cstr.push_back("-D__arm__");
#else
driver::Driver drv("", "x86_64-unknown-linux-gnu", diags);
#endif
--- /dev/null
+#ifndef COMPAT_SCHED_H
+#define COMPAT_SCHED_H
+
+#ifdef __arm__
+#define TASK_COMM_LEN 40
+#else
+#include <linux/sched.h>
+#endif
+
+#endif // COMPAT_SCHED_H
--- /dev/null
+#ifndef COMPAT_PTRACE_H
+#define COMPAT_PTRACE_H
+
+#ifdef __arm__
+struct pt_regs
+{
+ uint32_t uregs[18];
+};
+#else
+#include <uapi/linux/ptrace.h>
+#endif
+
+#endif // COMPAT_PTRACE_H
-#include <uapi/linux/ptrace.h>
-#include <linux/sched.h>
+#include <hostcompat/uapi/linux/ptrace.h>
+#include <hostcompat/linux/sched.h>
struct DBusString {
- void *str;
- int len;
- unsigned int allocated;
- unsigned int constant : 1;
- unsigned int locked : 1;
- unsigned int invalid : 1;
- unsigned int align_offset : 3;
+ ptr_t str;
+ int_t len;
+ uint_t allocated;
+ uint_t constant : 1;
+ uint_t locked : 1;
+ uint_t invalid : 1;
+ uint_t align_offset : 3;
};
struct DBusHeaderFields {
- int value_pos;
+ int_t value_pos;
};
struct DBusHeader {
};
struct DBusMessage {
- int refcount;
+ int_t refcount;
struct DBusHeader header;
struct DBusString body;
- unsigned int locked : 1;
+ uint_t locked : 1;
- void * list;
- long size_counter_delta;
- int timeout_ms;
+ ptr_t list; // void *
+ long_t size_counter_delta;
+ int_t timeout_ms;
u32 changed_stamp : 21;
- void *slot_list;
+ ptr_t slot_list; // void *
- int generation;
+ int_t generation;
- int *unix_fds;
+ ptr_t unix_fds; // int *
- unsigned n_unix_fds;
- unsigned n_unix_fds_allocated;
+ uint_t n_unix_fds;
+ uint_t n_unix_fds_allocated;
- long unix_fd_counter_delta;
+ long_t unix_fd_counter_delta;
- struct DBusString *signature;
- struct DBusString *unique_sender;
- size_t gvariant_body_last_offset;
- size_t gvariant_body_last_pos;
+ ptr_t signature; // struct DBusString *signature;
+ ptr_t unique_sender; // struct DBusString *unique_sender;
+ ulong_t gvariant_body_last_offset;
+ ulong_t gvariant_body_last_pos;
};
struct data_t {
if (ptr_gsize == 0) {
return 0;
}
- unsigned long *gsize = 0;
- bpf_probe_read(&gsize, sizeof(gsize), ptr_gsize);
+ unsigned long *gsize = *ptr_gsize;
unsigned long size = 0;
bpf_probe_read(&size, sizeof(size), gsize);
if(size > 0 && size < 1000000) {
int dbus_message_size(struct pt_regs *ctx, void *conn, struct DBusMessage *message) {
unsigned long size = 0;
- int header_len = 0;
- int body_len = 0;
+ int header_len = message->header.data.len;
+ int body_len = message->body.len;
- bpf_probe_read(&header_len, sizeof(header_len), (char*)message + offsetof(struct DBusMessage, header.data.len));
if (header_len > 0) {
size += header_len;
}
- bpf_probe_read(&body_len, sizeof(body_len), (char*)message + offsetof(struct DBusMessage, body.len));
if (body_len > 0) {
size += body_len;
}
interval = 5
loop = 0
# load BPF program
-bpf_text="""#include <uapi/linux/ptrace.h>
-#include <linux/sched.h>
+bpf_text="""
+#include <hostcompat/linux/sched.h>
+#include <hostcompat/uapi/linux/ptrace.h>
typedef struct pdata_T {
u32 pid;
u64 time = 0;
pdata_t pdata;
pdata_t new_pdata = {0, ' ', 0, 0, 0, 0, 0};
- u64 ts, *tsp, delta;
+ u64 ts, *tsp, delta;
u32 pid;
ts = bpf_ktime_get_ns() / 1000;
u64 time = 0;
pdata_t pdata;
pdata_t new_pdata = {0, ' ', 0, 0, 0, 0, 0};
- u64 ts, *tsp, delta;
+ u64 ts, *tsp, delta;
u32 pid;
ts = bpf_ktime_get_ns() / 1000;
u64 time = 0;
pdata_t pdata;
pdata_t new_pdata = {0, ' ', 0, 0, 0, 0, 0};
- u64 ts, *tsp, delta;
+ u64 ts, *tsp, delta;
u32 pid;
ts = bpf_ktime_get_ns() / 1000;
u64 time = 0;
pdata_t pdata;
pdata_t new_pdata = {0, ' ', 0, 0, 0, 0, 0};
- u64 ts, *tsp, delta;
+ u64 ts, *tsp, delta;
u32 pid;
ts = bpf_ktime_get_ns() / 1000;
-#include <uapi/linux/ptrace.h>
-#include <linux/sched.h>
+#include <hostcompat/linux/sched.h>
+#include <hostcompat/uapi/linux/ptrace.h>
typedef enum {
G_DBUS_MESSAGE_TYPE_INVALID,
} GDBusSendMessageFlags;
struct GTypeInstance {
- void *g_class;
+ ptr_t g_class; // void *
};
struct GObject {
struct GTypeInstance g_type_instance;
- volatile unsigned int ref_count;
- void *qdata;
+ volatile uint_t ref_count;
+ ptr_t qdata; // void *
};
struct GDBusMessage {
GDBusMessageType type;
GDBusMessageFlags flags;
bool locked;
- GDBusMessageByteOrder byte_order;
+ uint_t byte_order; // GDBusMessageByteOrder byte_order;
unsigned char major_protocol_version;
unsigned int serial;
- void *headers;
- void *body;
+ ptr_t headers; // void *headers;
+ ptr_t body; // void *body;
};
struct DBusString {
- void *str;
- int len;
- unsigned int allocated;
+ ptr_t str;
+ int_t len;
+ uint_t allocated;
unsigned int constant : 1;
unsigned int locked : 1;
unsigned int invalid : 1;
};
struct DBusLink {
- struct DBusLink *prev;
- struct DBusLink *next;
- void *data;
+ ptr_t prev; // struct DBusLink *prev;
+ ptr_t next; // struct DBusLink *next;
+ ptr_t data; // void *data;
};
struct DBusHeaderFields {
- int value_pos;
+ int_t value_pos;
};
struct DBusHeader {
};
struct DBusDataSlot {
- void *data;
- void *dummy1;
+ ptr_t data; // void *data;
+ ptr_t dummy1; // void *dummy1;
};
struct DBusDataSlotList {
- struct DBusDataSlot *slots;
- int n_slots;
+ ptr_t slots; // struct DBusDataSlot *slots;
+ int_t n_slots;
};
struct DBusList {
- struct DBusList *prev;
- struct DbusList *next;
- void *data;
+ ptr_t prev; // struct DBusList *prev;
+ ptr_t next; // struct DbusList *next;
+ ptr_t data; // void *data;
};
struct DBusMessage {
- int refcount;
+ int_t refcount;
struct DBusHeader header;
struct DBusString body;
- unsigned int locked : 1;
- unsigned int in_cache : 1;
+ uint_t locked : 1;
+ uint_t in_cache : 1;
- void *counters;
- long size_counter_delta;
- int timeout_ms;
+ ptr_t counters; // void *counters;
+ long_t size_counter_delta;
+ int_t timeout_ms;
u32 changed_stamp : 21;
- struct DBusDataSlotList *slot_list;
+ ptr_t slot_list; // struct DBusDataSlotList *slot_list;
- int generation;
+ int_t generation;
- int *unix_fds;
+ ptr_t unix_fds; // int *unix_fds;
- unsigned n_unix_fds;
- unsigned n_unix_fds_allocated;
+ uint_t n_unix_fds;
+ uint_t n_unix_fds_allocated;
- long unix_fd_counter_delta;
+ long_t unix_fd_counter_delta;
- struct DBusString *signature;
- struct DBusString *unique_sender;
- size_t gvariant_body_last_offset;
- size_t gvariant_body_last_pos;
+ ptr_t signature; // struct DBusString *signature;
+ ptr_t unique_sender; // struct DBusString *unique_sender;
+ long_t gvariant_body_last_offset;
+ long_t gvariant_body_last_pos;
};
struct DBusConnection {
- int refcount;
+ int_t refcount;
- void *mutex;
+ ptr_t mutex; // void *mutex;
- void *dispatch_mutex;
- void *dispatch_cond;
- void *io_path_mutex;
- void *io_path_cond;
+ ptr_t dispatch_mutex; // void *dispatch_mutex;
+ ptr_t dispatch_cond; // void *dispatch_cond;
+ ptr_t io_path_mutex; // void *io_path_mutex;
+ ptr_t io_path_cond; // void *io_path_cond;
- struct DBusList *outgoing_messages;
- struct DBusList *incoming_messages;
- struct DBusList *expired_messages;
+ ptr_t outgoing_messages; // struct DBusList *outgoing_messages;
+ ptr_t incoming_messages; // struct DBusList *incoming_messages;
+ ptr_t expired_messages; // struct DBusList *expired_messages;
- struct DBusMessage *message_borrowed;
+ ptr_t message_borrowed; // struct DBusMessage *message_borrowed;
- int n_outgoing;
- int n_incoming;
+ int_t n_outgoing;
+ int_t n_incoming;
};
struct data_t {
int get_msg_addr(struct pt_regs *ctx, struct DBusConnection *conn, struct DBusMessage *msg){
struct data_t data = {};
get_process_data(&data);
- struct header_data *header = 0;
- bpf_probe_read(&header, sizeof(header), (char*)msg + offsetof(struct DBusMessage, header.data.str));
- u32 serial = 0;
- bpf_probe_read(&serial, sizeof(serial), (char*)header + offsetof(struct header_data, serial));
+ struct header_data *header = msg->header.data.str;
+ u32 serial = header->serial;
msg_sent_addr.update(&serial,&data);
return 0;
}
struct DBusMessage *msg = 0;
struct header_data *header = 0;
int serial = 0;
- struct DBusList *link = 0;
-
- bpf_probe_read(&link, sizeof(link), (char *)conn + offsetof(struct DBusConnection, incoming_messages));
+ struct DBusList *link = conn->incoming_messages;
if (link == 0) {
return 0;
}
get_process_data(&receiver_data);
- bpf_probe_read(&msg, sizeof(msg), (char *)link + offsetof(struct DBusList, data));
- bpf_probe_read(&header, sizeof(header), (char*)msg + offsetof(struct DBusMessage, header.data.str));
- bpf_probe_read(&serial, sizeof(serial), (char*)header + offsetof(struct header_data, serial));
+ msg = link->data;
+ header = msg->header.data.str;
+ serial = header->serial;
get_delay(serial, receiver_data);
return 0;
}
-#include <uapi/linux/ptrace.h>
-#include <linux/sched.h>
+#include <hostcompat/linux/sched.h>
+#include <hostcompat/uapi/linux/ptrace.h>
#define COUNTS COUNTS_T
u64 bytes;
};
-BPF_HASH(size_sent, struct data_t, struct bytes_t)
+BPF_HASH(size_sent, struct data_t, struct bytes_t);
BPF_HISTOGRAM(sizes);
-#include <uapi/linux/ptrace.h>
-#include <linux/sched.h>
+#include <hostcompat/linux/sched.h>
+#include <hostcompat/uapi/linux/ptrace.h>
#define DBUS_TYPE_OFFSET 1
} GDBusMessageByteOrder;
struct GTypeInstance {
- void *g_class;
+ ptr_t g_class; // void *g_class;
};
struct GObject {
struct GTypeInstance g_type_instance;
- volatile unsigned int ref_count;
- void *qdata;
+ volatile uint_t ref_count;
+ ptr_t qdata; // void *qdata;
};
struct GHashTable {
- int size;
- int mod;
- unsigned int mask;
- int nnodes;
- int noccupied;
-
- void *keys;
- void *hashes;
- void *values;
+ int_t size;
+ int_t mod;
+ uint_t mask;
+ int_t nnodes;
+ int_t noccupied;
+
+ ptr_t keys; // void *keys;
+ ptr_t hashes; // void *hashes;
+ ptr_t values; // void *values;
};
struct GVariant {
- void *type_info;
- unsigned long size;
+ ptr_t type_info; // void *type_info;
+ ulong_t size;
union {
struct {
- void *bytes;
- const char *gconstpointer;
+ ptr_t bytes; // void *bytes;
+ ptr_t gconstpointer; // const char *gconstpointer;
} serialised;
struct {
- struct GVariant **children;
- unsigned long n_children;
+ ptr_t children; // struct GVariant **children;
+ ulong_t n_children;
} tree;
} content;
- int state;
- int ref_count;
+ int_t state;
+ int_t ref_count;
};
struct GDBusMessage {
struct GObject parent_instance;
- GDBusMessageType type;
- GDBusMessageFlags flags;
+ uint_t type; // GDBusMessageType type;
+ uint_t flags; // GDBusMessageFlags flags;
bool locked;
- GDBusMessageByteOrder byte_order;
+ uint_t byte_order; // GDBusMessageByteOrder byte_order;
unsigned char major_protocol_version;
- unsigned int serial;
- struct GHashTable *headers;
- struct GVariant *body;
+ uint_t serial;
+ ptr_t headers; // struct GHashTable *headers;
+ ptr_t body; // struct GVariant *body;
};
struct DBusString {
- void *str;
- int len;
- unsigned int allocated;
+ ptr_t str; // void *str;
+ int_t len;
+ uint_t allocated;
unsigned int constant : 1;
unsigned int locked : 1;
unsigned int invalid : 1;
};
struct DBusHeaderFields {
- int value_pos;
+ int_t value_pos;
};
struct DBusHeader {
};
struct DBusMessage {
- int refcount;
+ int_t refcount;
struct DBusHeader header;
struct DBusString body;
- unsigned int locked : 1;
+ uint_t locked : 1;
- void * list;
- long size_counter_delta;
- int timeout_ms;
+ ptr_t list; // void * list;
+ long_t size_counter_delta;
+ int_t timeout_ms;
u32 changed_stamp : 21;
- void *slot_list;
+ ptr_t slot_list; // void *slot_list;
- int generation;
+ int_t generation;
- int *unix_fds;
+ ptr_t unix_fds; // int *unix_fds;
- unsigned n_unix_fds;
- unsigned n_unix_fds_allocated;
+ uint_t n_unix_fds;
+ uint_t n_unix_fds_allocated;
- long unix_fd_counter_delta;
+ long_t unix_fd_counter_delta;
- struct DBusString *signature;
- struct DBusString *unique_sender;
- size_t gvariant_body_last_offset;
- size_t gvariant_body_last_pos;
+ ptr_t signature; // struct DBusString *signature;
+ ptr_t unique_sender; // struct DBusString *unique_sender;
+ uint_t gvariant_body_last_offset;
+ uint_t gvariant_body_last_pos;
};
struct data_t {
}
int message_type(struct pt_regs *ctx, void *conn, struct DBusMessage *message) {
- char *addr = 0;
- bpf_probe_read(&addr, sizeof(addr), (char*)message + offsetof(struct DBusMessage, header.data.str));
- char type;
- bpf_probe_read(&type, sizeof(type), addr + 1);
- msg_type.increment(type);
+ const char *c = message->header.data.str;
+ c++;
+ msg_type.increment(*c);
return 0;
}
interval = 5
loop = 0
# load BPF program
-bpf_text="""#include <uapi/linux/ptrace.h>
-#include <linux/sched.h>
+bpf_text="""
+#include <hostcompat/linux/sched.h>
+#include <hostcompat/uapi/linux/ptrace.h>
struct p_name{
- char buf[80];
+ char buf[TASK_COMM_LEN];
u32 pid;
};
-#include <uapi/linux/ptrace.h>
-#include <linux/sched.h>
+#include <hostcompat/uapi/linux/ptrace.h>
+#include <hostcompat/linux/sched.h>
typedef struct pdata_T {
u32 pid;
stats.update(&pid, &pdata);
return 0;
}
-