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
12 #include "mc_forward.h"
16 typedef enum e_adress_space_read_flags {
17 MC_ADDRESS_SPACE_READ_FLAGS_NONE = 0,
19 /** Avoid a copy for when the data is available in the current process.
21 * In this case, the return value of a MC_address_space_read might
22 * be different from the provided buffer.
24 MC_ADDRESS_SPACE_READ_FLAGS_LAZY = 1
25 } e_adress_space_read_flags_t;
27 /** Process index used when no process is available
29 * The expected behaviour is that if a process index is needed it will fail.
31 #define MC_PROCESS_INDEX_MISSING -1
33 #define MC_PROCESS_INDEX_DISABLED -2
35 /** Process index when any process is suitable
37 * We could use a special negative value in the future.
39 #define MC_PROCESS_INDEX_ANY 0
41 // ***** Class definition
43 typedef struct s_mc_address_space s_mc_address_space_t, *mc_address_space_t;
44 typedef struct s_mc_address_space_class s_mc_address_space_class_t, *mc_address_space_class_t;
46 /** Abstract base class for an address space
48 * This is the base class for all virtual address spaces (process, snapshot).
49 * It uses dynamic dispatch based on a vtable (`address_space_class`).
51 struct s_mc_address_space {
52 const s_mc_address_space_class_t* address_space_class;
55 /** Class object (vtable) for the virtual address spaces
57 struct s_mc_address_space_class {
59 mc_address_space_t address_space, e_adress_space_read_flags_t flags,
60 void* target, const void* addr, size_t size,
62 mc_process_t (*get_process)(mc_address_space_t address_space);
65 // ***** Virtual/non-final methods
67 /** Read data from the given address space
71 static inline __attribute__((always_inline))
72 const void* MC_address_space_read(
73 mc_address_space_t address_space, e_adress_space_read_flags_t flags,
74 void* target, const void* addr, size_t size,
77 return address_space->address_space_class->read(
78 address_space, flags, target, addr, size,
82 static inline __attribute__((always_inline))
83 const void* MC_address_space_get_process(mc_address_space_t address_space)
85 return address_space->address_space_class->get_process(address_space);