Logo AND Algorithmique Numérique Distribuée

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