00001 /***************************************************************************** 00002 00003 The following code is derived, directly or indirectly, from the SystemC 00004 source code Copyright (c) 1996-2006 by all Contributors. 00005 All Rights reserved. 00006 00007 The contents of this file are subject to the restrictions and limitations 00008 set forth in the SystemC Open Source License Version 2.4 (the "License"); 00009 You may not use this file except in compliance with such restrictions and 00010 limitations. You may obtain instructions on how to receive a copy of the 00011 License at http://www.systemc.org/. Software distributed by Contributors 00012 under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF 00013 ANY KIND, either express or implied. See the License for the specific 00014 language governing rights and limitations under the License. 00015 00016 *****************************************************************************/ 00017 00018 /***************************************************************************** 00019 00020 sc_module_name.cpp -- An object used to help manage object names 00021 and hierarchy 00022 00023 Original Author: Stan Y. Liao, Synopsys, Inc. 00024 00025 *****************************************************************************/ 00026 00027 /***************************************************************************** 00028 00029 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 00030 changes you are making here. 00031 00032 Name, Affiliation, Date: 00033 Description of Modification: 00034 00035 *****************************************************************************/ 00036 00037 00038 // $Log: sc_module_name.cpp,v $ 00039 // Revision 1.1.1.1 2006/12/15 20:31:37 acg 00040 // SystemC 2.2 00041 // 00042 // Revision 1.4 2006/03/14 23:56:58 acg 00043 // Andy Goodrich: This fixes a bug when an exception is thrown in 00044 // sc_module::sc_module() for a dynamically allocated sc_module 00045 // object. We are calling sc_module::end_module() on a module that has 00046 // already been deleted. The scenario runs like this: 00047 // 00048 // a) the sc_module constructor is entered 00049 // b) the exception is thrown 00050 // c) the exception processor deletes the storage for the sc_module 00051 // d) the stack is unrolled causing the sc_module_name instance to be deleted 00052 // e) ~sc_module_name() calls end_module() with its pointer to the sc_module 00053 // f) because the sc_module has been deleted its storage is corrupted, 00054 // either by linking it to a free space chain, or by reuse of some sort 00055 // g) the m_simc field is garbage 00056 // h) the m_object_manager field is also garbage 00057 // i) an exception occurs 00058 // 00059 // This does not happen for automatic sc_module instances since the 00060 // storage for the module is not reclaimed its just part of the stack. 00061 // 00062 // I am fixing this by having the destructor for sc_module clear the 00063 // module pointer in its sc_module_name instance. That cuts things at 00064 // step (e) above, since the pointer will be null if the module has 00065 // already been deleted. To make sure the module stack is okay, I call 00066 // end-module() in ~sc_module in the case where there is an 00067 // sc_module_name pointer lying around. 00068 // 00069 // Revision 1.3 2006/01/13 18:44:30 acg 00070 // Added $Log to record CVS changes into the source. 00071 // 00072 00073 #include <cstdlib> 00074 00075 #include "sysc/kernel/sc_kernel_ids.h" 00076 #include "sysc/kernel/sc_module.h" 00077 #include "sysc/kernel/sc_module_name.h" 00078 #include "sysc/kernel/sc_object_manager.h" 00079 #include "sysc/kernel/sc_simcontext.h" 00080 #include "sysc/utils/sc_iostream.h" 00081 00082 namespace sc_core { 00083 00084 sc_module_name::sc_module_name( const char* name_ ) 00085 : m_name( name_ ), 00086 m_module_p( 0 ), 00087 m_next( 0 ), 00088 m_simc( sc_get_curr_simcontext() ), 00089 m_pushed( true ) 00090 { 00091 m_simc->get_object_manager()->push_module_name( this ); 00092 } 00093 00094 sc_module_name::sc_module_name( const sc_module_name& name_ ) 00095 : m_name( name_.m_name ), 00096 m_module_p( 0 ), 00097 m_next( 0 ), 00098 m_simc( name_.m_simc ), 00099 m_pushed( false ) 00100 {} 00101 00102 sc_module_name::~sc_module_name() 00103 { 00104 if( m_pushed ) { 00105 sc_module_name* smn = m_simc->get_object_manager()->pop_module_name(); 00106 if( this != smn ) { 00107 SC_REPORT_ERROR( SC_ID_SC_MODULE_NAME_USE_, 0 ); 00108 } 00109 if ( m_module_p ) m_module_p->end_module(); 00110 } 00111 } 00112 00113 sc_module_name::operator const char*() const 00114 { 00115 return m_name; 00116 } 00117 00118 } // namespace sc_core