Commit 0cc92371 authored by Maxime Perrotin's avatar Maxime Perrotin

Detect when users calls a RI during startup

msg queues and protected objects are not initialized yet so it is not
allowed to call a RI before system initialization is completed
parent 48c112cf
......@@ -47,6 +47,11 @@
@@END_IF@@
#include "dataview-uniq.h"
// reference to flag preventing calls to RIs during the startup transition
extern bool @_LOWER:Name_@_initialized;
// in case that happens, use system's abort function to crash the application
extern void abort (void);
@@-- For blackbox devices, don't generate the RI code here, because their parameters are different
@@-- (they are already encoded, not using native ASN.1 types)
@@IF@@ @_Language_@ /= "Blackbox_C"
......
......@@ -29,6 +29,16 @@ void @_LOWER:Parent_Function_@_RI_@_Name_@
void @_LOWER:Parent_Function_@_RI_@_Name_@(void)
@@END_IF@@
{
// Check that we are not in the startup transition
if (false == @_LOWER:Parent_Function_@_initialized) {
#ifdef __unix__
puts("A call to @_LOWER:Parent_Function_@_RI_@_Name_@ was made during system startup.");
puts("This is not allowed because the system is not yet fully initialized. Please fix your code/models");
#endif
// crash the application
abort();
}
#ifdef __unix__
// Log MSC data on Linux when environment variable is set
static int innerMsc = -1;
......@@ -63,7 +73,6 @@ void @_LOWER:Parent_Function_@_RI_@_Name_@(void)
puts ("[ERROR] ASN.1 Encoding failed in @_LOWER:Parent_Function_@_RI_@_Name_@, parameter @_Param_Names_@");
#endif
/* Crash the application due to message loss */
extern void abort (void);
abort();
}
@@END_IF@@
......
......@@ -48,13 +48,12 @@
extern void adainit(void);
@@END_IF@@
@@-- define a global initialization flag for the function, that is checked in invoke_ri
@@-- to prevent calls to RIs during the startup function
bool @_LOWER:Name_@_initialized = false;
void init_@_LOWER:Name_@(void)
{
static bool init = false;
if (!init) {
init = true;
if (!@_LOWER:Name_@_initialized) {
@@IF@@ @_Language_@ /= "Ada" and @_Language_@ /= "QGenAda" and @_Language_@ /= "QGenC" and @_Language_@ /= "SDL"
// Call user code startup function
@_LOWER:Name_@_startup();
......@@ -73,6 +72,7 @@ void init_@_LOWER:Name_@(void)
#ifdef __unix__
puts ("[TASTE] Initialization completed for function @_Name_@");
#endif
@_LOWER:Name_@_initialized = true;
}
}
@@-- For blackbox devices, don't generate the PI functions, they will be
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment