From 270520b4a2eac8725c8575c3180964289722e191 Mon Sep 17 00:00:00 2001 From: John Ogness Date: Tue, 19 Dec 2017 10:59:40 +0100 Subject: schulung_tools: add various demos and tools Different tools have been used by various trainers as demos. Put all these into master so they are available to all trainers. ipc_pipe: ipc demo using pipes ipc_shm: ipc demo using shared memory libduma: source and instructions for compiling libduma matrix: demo of good and bad cache access mtrace: patch and infos for using mtrace with ASLR rtex: demo of handling page faults Signed-off-by: John Ogness --- schulung_tools/ipc_shm/recv.c | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 schulung_tools/ipc_shm/recv.c (limited to 'schulung_tools/ipc_shm/recv.c') diff --git a/schulung_tools/ipc_shm/recv.c b/schulung_tools/ipc_shm/recv.c new file mode 100644 index 0000000..8a08338 --- /dev/null +++ b/schulung_tools/ipc_shm/recv.c @@ -0,0 +1,49 @@ +#include +#include +#include +#include +#include +#include "shm.h" + +int main(void) +{ + struct share_data *data; + int rv; + + if (create_share() != 0) + return 1; + + data = get_share(); + if (!data) + return 1; + + init_share(data); + + if (pthread_mutex_lock(&data->m) != 0) + return 1; + + printf("recv (%d): waiting for signal\n", getpid()); + + do { + rv = pthread_cond_wait(&data->c, &data->m); + if (rv != 0) { + if (rv == EOWNERDEAD) { + printf("recv(%d): recover mutex\n", getpid()); + data->msg[0] = 0; + pthread_mutex_consistent(&data->m); + } else { + /* maybe rv == ENOTRECOVERABLE */ + return 1; + } + } + } while (rv != 0); + + /* set "received" uprobe here */ + + printf("recv (%d): received signal: %s\n", getpid(), data->msg); + pthread_mutex_unlock(&data->m); + + remove_share(); + + return 0; +} -- cgit v1.2.3