Project

General

Profile

Statistics
| Revision:

root / lab4 / .minix-src / include / minix / sef.h @ 13

History | View | Annotate | Download (15.3 KB)

1
/* Prototypes for System Event Framework (SEF) functions. */
2

    
3
#ifndef _SEF_H
4
#define _SEF_H
5

    
6
#include <minix/ipc.h>
7

    
8
/* SEF entry points for system processes. */
9
void sef_startup(void);
10
int sef_receive_status(endpoint_t src, message *m_ptr, int *status_ptr);
11
endpoint_t sef_self(void);
12
void sef_cancel(void);
13
void __dead sef_exit(int status);
14
int sef_getrndseed (void);
15
int sef_munmap(void *addrstart, vir_bytes len, int type);
16
#define sef_receive(src, m_ptr) sef_receive_status(src, m_ptr, NULL)
17

    
18
/* SEF global definitions. */
19
#define SEF_STATE_TRANSFER_GID          0
20

    
21
/* SEF Debug. */
22
#include <stdio.h>
23
#define sef_dprint                      printf
24
#define sef_debug_begin()               (void)(NULL)
25
#define sef_debug_end()                 (void)(NULL)
26

    
27
/*===========================================================================*
28
 *                                  SEF Init                                     *
29
 *===========================================================================*/
30
/* What to intercept. */
31
#define INTERCEPT_SEF_INIT_REQUESTS 1
32
#define SEF_INIT_REQUEST_TYPE RS_INIT
33
#define IS_SEF_INIT_REQUEST(mp, status) ((mp)->m_type == RS_INIT \
34
     && (mp)->m_source == RS_PROC_NR)
35

    
36
#define SEF_COPY_OLD_TO_NEW     0x001
37
#define SEF_COPY_NEW_TO_NEW     0x002
38
#define SEF_COPY_DEST_OFFSET    0x004
39
#define SEF_COPY_SRC_OFFSET     0X008
40

    
41
/* Type definitions. */
42
typedef struct {
43
    int flags;
44
    cp_grant_id_t rproctab_gid;
45
    endpoint_t endpoint;
46
    endpoint_t old_endpoint;
47
    int restarts;
48
    void* init_buff_start;
49
    void* init_buff_cleanup_start;
50
    size_t init_buff_len;
51
    int copy_flags;
52
    int prepare_state;
53
} sef_init_info_t;
54

    
55
/* Callback type definitions. */
56
typedef int(*sef_cb_init_t)(int type, sef_init_info_t *info);
57
typedef int(*sef_cb_init_response_t)(message *m_ptr);
58

    
59
/* Callback registration helpers. */
60
void sef_setcb_init_fresh(sef_cb_init_t cb);
61
void sef_setcb_init_lu(sef_cb_init_t cb);
62
void sef_setcb_init_restart(sef_cb_init_t cb);
63
void sef_setcb_init_response(sef_cb_init_response_t cb);
64

    
65
/* Predefined callback implementations. */
66
int sef_cb_init_null(int type, sef_init_info_t *info);
67
int sef_cb_init_response_null(message *m_ptr);
68

    
69
int sef_cb_init_fail(int type, sef_init_info_t *info);
70
int sef_cb_init_reset(int type, sef_init_info_t *info);
71
int sef_cb_init_crash(int type, sef_init_info_t *info);
72
int sef_cb_init_timeout(int type, sef_init_info_t *info);
73
int sef_cb_init_restart_generic(int type, sef_init_info_t *info);
74
int sef_cb_init_identity_state_transfer(int type, sef_init_info_t *info);
75
int sef_cb_init_lu_identity_as_restart(int type, sef_init_info_t *info);
76
int sef_cb_init_lu_generic(int type, sef_init_info_t *info);
77
int sef_cb_init_response_rs_reply(message *m_ptr);
78
int sef_cb_init_response_rs_asyn_once(message *m_ptr);
79

    
80
/* Macros for predefined callback implementations. */
81
#define SEF_CB_INIT_FRESH_NULL          sef_cb_init_null
82
#define SEF_CB_INIT_LU_NULL             sef_cb_init_null
83
#define SEF_CB_INIT_RESTART_NULL        sef_cb_init_null
84
#define SEF_CB_INIT_RESPONSE_NULL       sef_cb_init_response_null
85
#define SEF_CB_INIT_RESTART_STATEFUL    sef_cb_init_restart_generic
86

    
87
#define SEF_CB_INIT_FRESH_DEFAULT       sef_cb_init_null
88
#define SEF_CB_INIT_LU_DEFAULT          sef_cb_init_lu_generic
89
#define SEF_CB_INIT_RESTART_DEFAULT     sef_cb_init_reset
90
#define SEF_CB_INIT_RESPONSE_DEFAULT    sef_cb_init_response_rs_reply
91

    
92
/* Init types. */
93
#define SEF_INIT_FRESH                  0    /* init fresh */
94
#define SEF_INIT_LU                     1    /* init after live update */
95
#define SEF_INIT_RESTART                2    /* init after restart */
96

    
97
/* Init flags (live update flags can be used as init flags as well). */
98
#define SEF_INIT_CRASH                       0x1
99
#define SEF_INIT_FAIL                      0x2
100
#define SEF_INIT_TIMEOUT              0x4
101
#define SEF_INIT_DEFCB                0x8
102
#define SEF_INIT_SCRIPT_RESTART             0x10
103
#define SEF_INIT_ST                  0x20    /* force state transfer init */
104

    
105
/* Debug. */
106
#define SEF_INIT_DEBUG_DEFAULT                 0
107
#define SEF_INIT_ALLOW_DEBUG_INIT_FLAGS 1
108

    
109
#ifndef SEF_INIT_DEBUG
110
#define SEF_INIT_DEBUG                  SEF_INIT_DEBUG_DEFAULT
111
#endif
112

    
113
#define sef_init_dprint                 sef_dprint
114
#define sef_init_debug_begin            sef_debug_begin
115
#define sef_init_debug_end              sef_debug_end
116

    
117
/*===========================================================================*
118
 *                                  SEF Ping                                     *
119
 *===========================================================================*/
120
/* What to intercept. */
121
#define INTERCEPT_SEF_PING_REQUESTS 1
122
#define SEF_PING_REQUEST_TYPE NOTIFY_MESSAGE
123
#define IS_SEF_PING_REQUEST(mp, status) (is_ipc_notify(status) \
124
    && (mp)->m_source == RS_PROC_NR)
125

    
126
/* Callback type definitions. */
127
typedef void(*sef_cb_ping_reply_t)(endpoint_t source);
128

    
129
/* Callback registration helpers. */
130
void sef_setcb_ping_reply(sef_cb_ping_reply_t cb);
131

    
132
/* Predefined callback implementations. */
133
void sef_cb_ping_reply_null(endpoint_t source);
134

    
135
void sef_cb_ping_reply_pong(endpoint_t source);
136

    
137
/* Macros for predefined callback implementations. */
138
#define SEF_CB_PING_REPLY_NULL          sef_cb_ping_reply_null
139

    
140
#define SEF_CB_PING_REPLY_DEFAULT       sef_cb_ping_reply_pong
141

    
142
/* Debug. */
143
#define SEF_PING_DEBUG_DEFAULT 0
144

    
145
#ifndef SEF_PING_DEBUG
146
#define SEF_PING_DEBUG                  SEF_PING_DEBUG_DEFAULT
147
#endif
148

    
149
#define sef_ping_dprint                 sef_dprint
150
#define sef_ping_debug_begin            sef_debug_begin
151
#define sef_ping_debug_end              sef_debug_end
152

    
153
/*===========================================================================*
154
 *                                SEF Live update                                     *
155
 *===========================================================================*/
156
/* What to intercept. */
157
#define INTERCEPT_SEF_LU_REQUESTS 1
158
#define SEF_LU_REQUEST_TYPE RS_LU_PREPARE
159
#define IS_SEF_LU_REQUEST(mp, status) ((mp)->m_type == RS_LU_PREPARE \
160
    && (mp)->m_source == RS_PROC_NR)
161

    
162
/* Callback type definitions. */
163
typedef  int(*sef_cb_lu_prepare_t)(int);
164
typedef  int(*sef_cb_lu_state_isvalid_t)(int, int);
165
typedef void(*sef_cb_lu_state_changed_t)(int, int);
166
typedef void(*sef_cb_lu_state_dump_t)(int);
167
typedef  int(*sef_cb_lu_state_save_t)(int, int);
168
typedef  int(*sef_cb_lu_response_t)(message *m_ptr);
169

    
170
/* Callback registration helpers. */
171
void sef_setcb_lu_prepare(sef_cb_lu_prepare_t cb);
172
void sef_setcb_lu_state_isvalid(sef_cb_lu_state_isvalid_t cb);
173
void sef_setcb_lu_state_changed(sef_cb_lu_state_changed_t cb);
174
void sef_setcb_lu_state_dump(sef_cb_lu_state_dump_t cb);
175
void sef_setcb_lu_state_save(sef_cb_lu_state_save_t cb);
176
void sef_setcb_lu_response(sef_cb_lu_response_t cb);
177

    
178
/* Predefined callback implementations. */
179
int sef_cb_lu_prepare_null(int state);
180
int sef_cb_lu_state_isvalid_null(int state, int flags);
181
void sef_cb_lu_state_changed_null(int old_state, int state);
182
void sef_cb_lu_state_dump_null(int state);
183
int sef_cb_lu_state_save_null(int state, int flags);
184
int sef_cb_lu_response_null(message *m_ptr);
185

    
186
int sef_cb_lu_prepare_always_ready(int state);
187
int sef_cb_lu_prepare_never_ready(int state);
188
int sef_cb_lu_prepare_crash(int state);
189
int sef_cb_lu_prepare_eval(int state);
190
int sef_cb_lu_state_isvalid_standard(int state, int flags);
191
int sef_cb_lu_state_isvalid_workfree(int state, int flags);
192
int sef_cb_lu_state_isvalid_workfree_self(int state, int flags);
193
int sef_cb_lu_state_isvalid_generic(int state, int flags);
194
void sef_cb_lu_state_dump_eval(int state);
195
int sef_cb_lu_response_rs_reply(message *m_ptr);
196

    
197
/* Macros for predefined callback implementations. */
198
#define SEF_CB_LU_PREPARE_NULL          sef_cb_lu_prepare_null
199
#define SEF_CB_LU_STATE_ISVALID_NULL    sef_cb_lu_state_isvalid_null
200
#define SEF_CB_LU_STATE_CHANGED_NULL    sef_cb_lu_state_changed_null
201
#define SEF_CB_LU_STATE_DUMP_NULL       sef_cb_lu_state_dump_null
202
#define SEF_CB_LU_STATE_SAVE_NULL       sef_cb_lu_state_save_null
203
#define SEF_CB_LU_RESPONSE_NULL         sef_cb_lu_response_null
204

    
205
#define SEF_CB_LU_PREPARE_DEFAULT       sef_cb_lu_prepare_null
206
#define SEF_CB_LU_STATE_ISVALID_DEFAULT sef_cb_lu_state_isvalid_generic
207
#define SEF_CB_LU_STATE_CHANGED_DEFAULT sef_cb_lu_state_changed_null
208
#define SEF_CB_LU_STATE_DUMP_DEFAULT    sef_cb_lu_state_dump_eval
209
#define SEF_CB_LU_STATE_SAVE_DEFAULT    sef_cb_lu_state_save_null
210
#define SEF_CB_LU_RESPONSE_DEFAULT      sef_cb_lu_response_rs_reply
211

    
212
/* Standard live update states. */
213
#define SEF_LU_STATE_NULL               0    /* null state */
214
#define SEF_LU_STATE_WORK_FREE          1    /* no work in progress */
215
#define SEF_LU_STATE_REQUEST_FREE       2    /* no request in progress */
216
#define SEF_LU_STATE_PROTOCOL_FREE      3    /* no protocol in progress */
217
#define SEF_LU_STATE_EVAL               4    /* evaluate expression */
218

    
219
#define SEF_LU_STATE_UNREACHABLE        5    /* unreachable state */
220
#define SEF_LU_STATE_PREPARE_CRASH      6    /* crash at prepare time */
221

    
222
#define SEF_LU_STATE_STD_BASE           (SEF_LU_STATE_WORK_FREE)
223
#define SEF_LU_STATE_DEBUG_BASE         (SEF_LU_STATE_UNREACHABLE)
224
#define SEF_LU_STATE_CUSTOM_BASE        (SEF_LU_STATE_PREPARE_CRASH+1)
225

    
226
#define SEF_LU_STATE_IS_STANDARD(s)     ((s) >= SEF_LU_STATE_STD_BASE \
227
    && (s) < SEF_LU_STATE_CUSTOM_BASE \
228
    && (SEF_LU_ALWAYS_ALLOW_DEBUG_STATES || !SEF_LU_STATE_IS_DEBUG(s)))
229
#define SEF_LU_STATE_IS_DEBUG(s)     ((s) >= SEF_LU_STATE_DEBUG_BASE \
230
    && (s) < SEF_LU_STATE_CUSTOM_BASE)
231

    
232
#define SEF_LU_STATE_EVAL_MAX_LEN          512
233

    
234
/* Live update flags (can be used as init flags as well). */
235
#define SEF_LU_SELF                        0x0100    /* this is a self update */
236
#define SEF_LU_ASR                         0x0200    /* this is an ASR update */
237
#define SEF_LU_MULTI                       0x0400    /* this is a multi-component update */
238
#define SEF_LU_INCLUDES_VM                   0x0800    /* the update includes VM */
239
#define SEF_LU_INCLUDES_RS                   0x1000    /* the update includes RS */
240
#define SEF_LU_PREPARE_ONLY           0x2000    /* prepare only, no actual update taking place */
241
#define SEF_LU_NOMMAP                            0x4000    /* update doesn't inherit mmapped regions */
242
#define SEF_LU_DETACHED                    0x8000    /* update detaches the old instance */
243

    
244
#define SEF_LU_IS_IDENTITY_UPDATE(F) (((F) & (SEF_LU_SELF|SEF_LU_NOMMAP|SEF_LU_ASR|SEF_INIT_ST)) == SEF_LU_SELF)
245

    
246
/* Debug. */
247
#define SEF_LU_DEBUG_DEFAULT             0
248
#define SEF_LU_ALWAYS_ALLOW_DEBUG_STATES 1
249

    
250
#ifndef SEF_LU_DEBUG
251
#define SEF_LU_DEBUG            SEF_LU_DEBUG_DEFAULT
252
#endif
253

    
254
#define sef_lu_dprint           sef_dprint
255
#define sef_lu_debug_begin      sef_debug_begin
256
#define sef_lu_debug_end        sef_debug_end
257

    
258
/*===========================================================================*
259
 *                                  SEF Signal                                     *
260
 *===========================================================================*/
261
/* What to intercept. */
262
#define INTERCEPT_SEF_SIGNAL_REQUESTS 1
263
#define SEF_SIGNAL_REQUEST_TYPE SIGS_SIGNAL_RECEIVED
264
#define IS_SEF_SIGNAL_REQUEST(mp, status) \
265
    (((mp)->m_type == SIGS_SIGNAL_RECEIVED && (mp)->m_source < INIT_PROC_NR) \
266
    || (is_ipc_notify(status) && (mp)->m_source == SYSTEM))
267

    
268
/* Callback type definitions. */
269
typedef void(*sef_cb_signal_handler_t)(int signo);
270
typedef  int(*sef_cb_signal_manager_t)(endpoint_t target, int signo);
271

    
272
/* Callback registration helpers. */
273
void sef_setcb_signal_handler(sef_cb_signal_handler_t cb);
274
void sef_setcb_signal_manager(sef_cb_signal_manager_t cb);
275

    
276
/* Predefined callback implementations. */
277
void sef_cb_signal_handler_null(int signo);
278
int sef_cb_signal_manager_null(endpoint_t target, int signo);
279

    
280
void sef_cb_signal_handler_term(int signo);
281
void sef_cb_signal_handler_posix_default(int signo);
282

    
283
/* Macros for predefined callback implementations. */
284
#define SEF_CB_SIGNAL_HANDLER_NULL      sef_cb_signal_handler_null
285
#define SEF_CB_SIGNAL_MANAGER_NULL      sef_cb_signal_manager_null
286

    
287
#define SEF_CB_SIGNAL_HANDLER_DEFAULT   sef_cb_signal_handler_null
288
#define SEF_CB_SIGNAL_MANAGER_DEFAULT   sef_cb_signal_manager_null
289

    
290
/* Debug. */
291
#define SEF_SIGNAL_DEBUG_DEFAULT 0
292

    
293
#ifndef SEF_SIGNAL_DEBUG
294
#define SEF_SIGNAL_DEBUG                SEF_SIGNAL_DEBUG_DEFAULT
295
#endif
296

    
297
#define sef_signal_dprint               sef_dprint
298
#define sef_signal_debug_begin          sef_debug_begin
299
#define sef_signal_debug_end            sef_debug_end
300

    
301
/*===========================================================================*
302
 *                                  SEF GCOV                                     *
303
 *===========================================================================*/
304
/* What to intercept. */
305
#define INTERCEPT_SEF_GCOV_REQUESTS 1
306
#define SEF_GCOV_REQUEST_TYPE COMMON_REQ_GCOV_DATA
307
#define IS_SEF_GCOV_REQUEST(mp, status) \
308
    ((mp)->m_type == COMMON_REQ_GCOV_DATA && (mp)->m_source == VFS_PROC_NR)
309

    
310
/* Callback type definitions. */
311
typedef  int(*sef_cb_gcov_t)(message *msg);
312

    
313
/* Callback registration helpers. */
314
void sef_setcb_gcov(sef_cb_gcov_t cb);
315

    
316
/* Macros for predefined callback implementations. */
317
#define SEF_CB_GCOV_FLUSH_DEFAULT        do_gcov_flush_impl
318

    
319
/*===========================================================================*
320
 *                             SEF Fault Injection                             *
321
 *===========================================================================*/
322
/* What to intercept. */
323
#define INTERCEPT_SEF_FI_REQUESTS 1
324
#define SEF_FI_REQUEST_TYPE COMMON_REQ_FI_CTL
325
#define IS_SEF_FI_REQUEST(mp, status) \
326
    (m_ptr->m_type == COMMON_REQ_FI_CTL)
327

    
328
/* Fault injection tool support. */
329
#define SEF_FI_ALLOW_EDFI               1
330

    
331
/*===========================================================================*
332
 *                          SEF State Transfer                               *
333
 *===========================================================================*/
334
#define SEF_LU_STATE_EVAL_MAX_LEN          512
335

    
336
/* State transfer helpers. */
337
int sef_copy_state_region_ctl(sef_init_info_t *info,
338
    vir_bytes *src_address, vir_bytes *dst_address);
339
int sef_copy_state_region(sef_init_info_t *info,
340
    vir_bytes address, size_t size, vir_bytes dst_address, int may_have_holes);
341
int sef_st_state_transfer(sef_init_info_t *info);
342

    
343
/* Callback prototypes to be passed to the State Transfer framwork. */
344
int sef_old_state_table_lookup(sef_init_info_t *info, void *addr);
345
int sef_old_state_table_lookup_opaque(void *info_opaque, void *addr);
346
int sef_copy_state_region_opaque(void *info_opaque, uint32_t address,
347
    size_t size, uint32_t dst_address);
348

    
349
/* Debug. */
350
#define SEF_ST_DEBUG_DEFAULT                 0
351

    
352
#ifndef SEF_ST_DEBUG
353
#define SEF_ST_DEBUG                    SEF_ST_DEBUG_DEFAULT
354
#endif
355

    
356
/*===========================================================================*
357
 *                               SEF LLVM                                    *
358
 *===========================================================================*/
359
/* LLVM helpers. */
360
int sef_llvm_magic_enabled(void);
361
int sef_llvm_real_brk(char *newbrk);
362
int sef_llvm_state_cleanup(void);
363
void sef_llvm_dump_eval(char *expr);
364
int sef_llvm_eval_bool(char *expr, char *result);
365
void *sef_llvm_state_table_addr(void);
366
size_t sef_llvm_state_table_size(void);
367
void sef_llvm_stack_refs_save(char *stack_buff);
368
void sef_llvm_stack_refs_restore(char *stack_buff);
369
int sef_llvm_state_transfer(sef_init_info_t *info);
370
int sef_llvm_add_special_mem_region(void *addr, size_t len, const char* name);
371
int sef_llvm_del_special_mem_region_by_addr(void *addr);
372
void sef_llvm_ds_st_init(void);
373
void *sef_llvm_ac_mmap(void *buf, size_t len, int prot, int flags, int fd,
374
        off_t offset);
375
int sef_llvm_ac_munmap(void *buf, size_t len);
376

    
377
int sef_llvm_ltckpt_enabled(void);
378
int sef_llvm_get_ltckpt_offset(void);
379
int sef_llvm_ltckpt_restart(int type, sef_init_info_t *info);
380

    
381
#if !defined(USE_LIVEUPDATE)
382
#undef INTERCEPT_SEF_LU_REQUESTS
383
#undef SEF_LU_DEBUG
384
#endif
385

    
386
#endif /* _SEF_H */
387