Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Replace sprintf by snprintf.
[simgrid.git] / src / mc / mc_protocol.h
1 /* Copyright (c) 2015. 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 SIMGRID_MC_PROTOCOL_H
8 #define SIMGRID_MC_PROTOCOL_H
9
10 #include <stdint.h>
11
12 #include <xbt/base.h>
13
14 #include "mc/datatypes.h"
15
16 SG_BEGIN_DECL()
17
18 // ***** Environment variables for passing context to the model-checked process
19
20 /** Environment variable name set by `simgrid-mc` to enable MC support in the
21  *  children MC processes
22  */
23 #define MC_ENV_VARIABLE "SIMGRID_MC"
24
25 /** Environment variable name used to pass the communication socket */
26 #define MC_ENV_SOCKET_FD "SIMGRID_MC_SOCKET_FD"
27
28 // ***** Messages
29
30 typedef enum {
31   MC_MESSAGE_NONE,
32   MC_MESSAGE_CONTINUE,
33   MC_MESSAGE_IGNORE_HEAP,
34   MC_MESSAGE_UNIGNORE_HEAP,
35   MC_MESSAGE_IGNORE_MEMORY,
36   MC_MESSAGE_STACK_REGION,
37   MC_MESSAGE_REGISTER_SYMBOL,
38   MC_MESSAGE_DEADLOCK_CHECK,
39   MC_MESSAGE_DEADLOCK_CHECK_REPLY,
40   MC_MESSAGE_WAITING,
41   MC_MESSAGE_SIMCALL_HANDLE,
42   MC_MESSAGE_ASSERTION_FAILED,
43   // MCer request to finish the restoration:
44   MC_MESSAGE_RESTORE,
45 } e_mc_message_type;
46
47 #define MC_MESSAGE_LENGTH 512
48
49 /** Basic structure for a MC message
50  *
51  *  The current version of the client/server protocol sends C structures over `AF_LOCAL`
52  *  `SOCK_DGRAM` sockets. This means that the protocol is ABI/architecture specific:
53  *  we currently can't model-check a x86 process from a x86_64 process.
54  *
55  *  Moreover the protocol is not stable. The same version of the library should be used
56  *  for the client and the server.
57  *
58  *  This is the basic structure shared by all messages: all message start with a message
59  *  type.
60  */
61 struct s_mc_message {
62   e_mc_message_type type;
63 };
64 typedef struct s_mc_message  s_mc_message_t;
65 typedef struct s_mc_message* mc_message_t;
66
67 struct s_mc_int_message {
68   e_mc_message_type type;
69   uint64_t value;
70 };
71 typedef struct s_mc_int_message s_mc_int_message_t;
72 typedef struct s_mc_int_message* mc_int_message_t;
73
74 struct s_mc_ignore_heap_message {
75   e_mc_message_type type;
76   int block;
77   int fragment;
78   void *address;
79   size_t size;
80 };
81 typedef struct s_mc_ignore_heap_message  s_mc_ignore_heap_message_t;
82 typedef struct s_mc_ignore_heap_message* mc_ignore_heap_message_t;
83
84 struct s_mc_ignore_memory_message {
85   e_mc_message_type type;
86   uint64_t addr;
87   size_t size;
88 };
89 typedef struct s_mc_ignore_memory_message  s_mc_ignore_memory_message_t;
90 typedef struct s_mc_ignore_memory_message* mc_ignore_memory_message_t;
91
92 struct s_mc_stack_region_message {
93   e_mc_message_type type;
94   s_stack_region_t stack_region;
95 };
96 typedef struct s_mc_stack_region_message  s_mc_stack_region_message_t;
97 typedef struct s_mc_stack_region_message* mc_stack_region_message_t;
98
99 struct s_mc_simcall_handle_message {
100   e_mc_message_type type;
101   unsigned long pid;
102   int value;
103 };
104 typedef struct s_mc_simcall_handle_message  s_mc_simcall_handle_message_t;
105 typedef struct s_mc_simcall_handle_message* mc_simcall_handle_message;
106
107 struct s_mc_register_symbol_message {
108   e_mc_message_type type;
109   char name[128];
110   int (*callback)(void*);
111   void* data;
112 };
113 typedef struct s_mc_register_symbol_message  s_mc_register_symbol_message_t;
114 typedef struct s_mc_register_symbol_message* mc_register_symbol_message_t;
115
116 struct s_mc_restore_message {
117   e_mc_message_type type;
118   int index;
119 };
120 typedef struct s_mc_restore_message  s_mc_restore_message_t;
121 typedef struct s_mc_restore_message* mc_restore_message_t;
122
123 XBT_PRIVATE const char* MC_message_type_name(e_mc_message_type type);
124
125 SG_END_DECL()
126
127 #endif