Skip to content

Communication

tmatis edited this page Mar 26, 2023 · 1 revision

Communication between host and library

This page describes the communication between the host and the library.

Overview

The host and the library communicate through a shared memory created by the host defined like this in shared/shared.h

typedef enum e_runtype
{
    RUNTYPE_UNDEFINED,
    RUNTYPE_FETCH,
    RUNTYPE_TEST
} t_runtype;

#define MAX_BACKTRACE_DEPTH 100

typedef enum e_event
{
    NONE,
    ALLOC,
    REMOVE_ALLOC,
    FUNCTION_CALL,
    CRASH,
    EXIT
} t_event;

typedef unsigned long ptr_address;

typedef struct allocation_data_s
{
    size_t size;
    void *ptr;
} t_allocation_data;

typedef struct s_shared_info
{
    t_runtype runtype;
    ptr_address backtrace[MAX_BACKTRACE_DEPTH];
    char function_name[256];
    bool_t should_test;
    t_allocation_data allocation;
    t_event event;
    sem_t lock_guest;
    sem_t lock_host;
    char treat_abort_as_crash;
} t_shared_info;

The host and the library will write to this shared memory to communicate.

Host

The host is responsible for creating the shared memory. host/srcs/shared_memory.c contains the code to create the shared memory.

host/srcs/event_utils.c contains the code to read events from the shared memory.

Library

library/srcs/shared_memory.c contains the code to open the shared memory.

library/srcs/events/event_sender.c contains the code to write events to the shared memory.

Racing

To avoid racing between the host and the library, the host and the library will lock the shared memory while handling an event.

Clone this wiki locally