Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
this example needs to forcefully destroy the VMs
[simgrid.git] / src / mc / mc_address_space.h
1 /* Copyright (c) 2008-2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #ifndef MC_ADDRESS_SPACE_H
8 #define MC_ADDRESS_SPACE_H
9
10 #include <stdint.h>
11
12 #include "mc_forward.h"
13
14 // ***** Data types
15
16 typedef enum e_adress_space_read_flags {
17   MC_ADDRESS_SPACE_READ_FLAGS_NONE = 0,
18
19   /** Avoid a copy for when the data is available in the current process.
20    *
21    *  In this case, the return value of a MC_address_space_read might
22    *  be different from the provided buffer.
23    */
24   MC_ADDRESS_SPACE_READ_FLAGS_LAZY = 1
25 } e_adress_space_read_flags_t;
26
27 /** Process index used when no process is available
28  *
29  *  The expected behaviour is that if a process index is needed it will fail.
30  * */
31 #define MC_PROCESS_INDEX_MISSING -1
32
33 #define MC_PROCESS_INDEX_DISABLED -2
34
35 /** Process index when any process is suitable
36  *
37  * We could use a special negative value in the future.
38  */
39 #define MC_PROCESS_INDEX_ANY 0
40
41 // ***** Class definition
42
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;
45
46 /** Abstract base class for an address space
47  *
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`).
50  */
51 struct s_mc_address_space {
52   const s_mc_address_space_class_t* address_space_class;
53 };
54
55 /** Class object (vtable) for the virtual address spaces
56  */
57 struct s_mc_address_space_class {
58   const void* (*read)(
59     mc_address_space_t address_space, e_adress_space_read_flags_t flags,
60     void* target, const void* addr, size_t size,
61     int process_index);
62   mc_process_t (*get_process)(mc_address_space_t address_space);
63 };
64
65 // ***** Virtual/non-final methods
66
67 /** Read data from the given address space
68  *
69  *  Dynamic dispatch.
70  */
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,
75   int process_index)
76 {
77   return address_space->address_space_class->read(
78     address_space, flags, target, addr, size,
79     process_index);
80 }
81
82 static inline __attribute__((always_inline))
83 const void* MC_address_space_get_process(mc_address_space_t address_space)
84 {
85   return address_space->address_space_class->get_process(address_space);
86 }
87
88
89 #endif