1 /* Copyright (c) 2008-2014. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #ifndef MC_ADDRESS_SPACE_H
8 #define MC_ADDRESS_SPACE_H
14 #include "mc_forward.h"
20 /** Options for the read() operation
22 * - MC_ADDRESS_SPACE_READ_FLAGS_LAZY, avoid a copy when the data is
23 * available in the current process. In this case, the return value
24 * of MC_address_space_read might be different from the provided one.
26 typedef int adress_space_read_flags_t;
27 #define MC_ADDRESS_SPACE_READ_FLAGS_NONE 0
28 #define MC_ADDRESS_SPACE_READ_FLAGS_LAZY 1
30 /** Process index used when no process is available
32 * The expected behaviour is that if a process index is needed it will fail.
34 #define MC_PROCESS_INDEX_MISSING -1
36 #define MC_PROCESS_INDEX_DISABLED -2
38 /** Process index when any process is suitable
40 * We could use a special negative value in the future.
42 #define MC_PROCESS_INDEX_ANY 0
44 // ***** Class definition
46 typedef struct s_mc_address_space s_mc_address_space_t, *mc_address_space_t;
47 typedef struct s_mc_address_space_class s_mc_address_space_class_t, *mc_address_space_class_t;
49 /** Abstract base class for an address space
51 * This is the base class for all virtual address spaces (process, snapshot).
52 * It uses dynamic dispatch based on a vtable (`address_space_class`).
54 struct s_mc_address_space {
55 const s_mc_address_space_class_t* address_space_class;
58 /** Class object (vtable) for the virtual address spaces
60 struct s_mc_address_space_class {
62 mc_address_space_t address_space, adress_space_read_flags_t flags,
63 void* target, const void* addr, size_t size,
65 mc_process_t (*get_process)(mc_address_space_t address_space);
68 typedef const void* (*mc_address_space_class_read_callback_t)(
69 mc_address_space_t address_space, adress_space_read_flags_t flags,
70 void* target, const void* addr, size_t size,
72 typedef mc_process_t (*mc_address_space_class_get_process_callback_t)(mc_address_space_t address_space);
74 // ***** Virtual/non-final methods
76 /** Read data from the given address space
80 static inline __attribute__((always_inline))
81 const void* MC_address_space_read(
82 mc_address_space_t address_space, adress_space_read_flags_t flags,
83 void* target, const void* addr, size_t size,
86 return address_space->address_space_class->read(
87 address_space, flags, target, addr, size,
91 static inline __attribute__((always_inline))
92 const void* MC_address_space_get_process(mc_address_space_t address_space)
94 if (address_space->address_space_class->get_process)
95 return address_space->address_space_class->get_process(address_space);