Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix the security hotspots of sonar
[simgrid.git] / src / mc / remote / mc_protocol.h
1 /* Copyright (c) 2015-2022. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef SIMGRID_MC_PROTOCOL_H
7 #define SIMGRID_MC_PROTOCOL_H
8
9 // ***** Environment variables for passing context to the model-checked process
10
11 /** Environment variable name used to pass the communication socket.
12  *
13  * It is set by `simgrid-mc` to enable MC support in the children processes
14  */
15 #define MC_ENV_SOCKET_FD "SIMGRID_MC_SOCKET_FD"
16
17 #ifdef __cplusplus
18
19 #include "src/kernel/actor/SimcallObserver.hpp"
20
21 #include "mc/datatypes.h"
22 #include "simgrid/forward.h" // aid_t
23 #include <array>
24 #include <cstdint>
25 #include <xbt/dynar.h>
26 #include <xbt/mmalloc.h>
27 #include <xbt/utility.hpp>
28
29 // ***** Messages
30 namespace simgrid {
31 namespace mc {
32
33 XBT_DECLARE_ENUM_CLASS(MessageType, NONE, INITIAL_ADDRESSES, CONTINUE, IGNORE_HEAP, UNIGNORE_HEAP, IGNORE_MEMORY,
34                        STACK_REGION, REGISTER_SYMBOL, DEADLOCK_CHECK, DEADLOCK_CHECK_REPLY, WAITING, SIMCALL_EXECUTE,
35                        SIMCALL_EXECUTE_ANSWER, SIMCALL_IS_VISIBLE, SIMCALL_IS_VISIBLE_ANSWER, SIMCALL_DOT_LABEL,
36                        SIMCALL_DOT_LABEL_ANSWER, ASSERTION_FAILED, ACTOR_ENABLED, ACTOR_ENABLED_REPLY, FINALIZE);
37
38 } // namespace mc
39 } // namespace simgrid
40
41 constexpr unsigned MC_MESSAGE_LENGTH = 512;
42
43 /** Basic structure for a MC message
44  *
45  *  The current version of the client/server protocol sends C structures over `AF_LOCAL`
46  *  `SOCK_SEQPACKET` sockets. This means that the protocol is ABI/architecture specific:
47  *  we currently can't model-check a x86 process from a x86_64 process.
48  *
49  *  Moreover the protocol is not stable. The same version of the library should be used
50  *  for the client and the server.
51  */
52
53 /* Basic structure: all message start with a message type */
54 struct s_mc_message_t {
55   simgrid::mc::MessageType type;
56 };
57
58 struct s_mc_message_int_t {
59   simgrid::mc::MessageType type;
60   uint64_t value;
61 };
62
63 /* Client->Server */
64 struct s_mc_message_initial_addresses_t {
65   simgrid::mc::MessageType type;
66   xbt_mheap_t mmalloc_default_mdp;
67   unsigned long* maxpid;
68   xbt_dynar_t actors;
69   xbt_dynar_t dead_actors;
70 };
71
72 struct s_mc_message_ignore_heap_t {
73   simgrid::mc::MessageType type;
74   int block;
75   int fragment;
76   void* address;
77   size_t size;
78 };
79
80 struct s_mc_message_ignore_memory_t {
81   simgrid::mc::MessageType type;
82   uint64_t addr;
83   size_t size;
84 };
85
86 struct s_mc_message_stack_region_t {
87   simgrid::mc::MessageType type;
88   s_stack_region_t stack_region;
89 };
90
91 struct s_mc_message_register_symbol_t {
92   simgrid::mc::MessageType type;
93   std::array<char, 128> name;
94   int (*callback)(void*);
95   void* data;
96 };
97
98 /* Server -> client */
99 struct s_mc_message_simcall_execute_t {
100   simgrid::mc::MessageType type;
101   aid_t aid_;
102   int times_considered_;
103 };
104 struct s_mc_message_simcall_execute_answer_t {
105   simgrid::mc::MessageType type;
106   simgrid::kernel::actor::SimcallObserver::Simcall simcall;
107   char buffer[SIMCALL_SERIALIZATION_BUFFER_SIZE];
108 };
109
110 struct s_mc_message_restore_t {
111   simgrid::mc::MessageType type;
112   int index;
113 };
114
115 struct s_mc_message_actor_enabled_t {
116   simgrid::mc::MessageType type;
117   aid_t aid; // actor ID
118 };
119
120 /* RPC */
121 struct s_mc_message_simcall_is_visible_t { // MessageType::SIMCALL_IS_VISIBLE
122   simgrid::mc::MessageType type;
123   aid_t aid;
124 };
125 struct s_mc_message_simcall_is_visible_answer_t { // MessageType::SIMCALL_IS_VISIBLE_ANSWER
126   simgrid::mc::MessageType type;
127   bool value;
128 };
129
130 struct s_mc_message_simcall_to_string_t { // MessageType::SIMCALL_DOT_LABEL
131   simgrid::mc::MessageType type;
132   aid_t aid;
133   int time_considered;
134 };
135 struct s_mc_message_simcall_to_string_answer_t { // MessageType::SIMCALL_DOT_LABEL_ANSWER
136   simgrid::mc::MessageType type;
137   char value[1024];
138 };
139
140 #endif // __cplusplus
141 #endif