112027Sjungma@eit.uni-kl.de/***************************************************************************** 212027Sjungma@eit.uni-kl.de 312027Sjungma@eit.uni-kl.de Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 412027Sjungma@eit.uni-kl.de more contributor license agreements. See the NOTICE file distributed 512027Sjungma@eit.uni-kl.de with this work for additional information regarding copyright ownership. 612027Sjungma@eit.uni-kl.de Accellera licenses this file to you under the Apache License, Version 2.0 712027Sjungma@eit.uni-kl.de (the "License"); you may not use this file except in compliance with the 812027Sjungma@eit.uni-kl.de License. You may obtain a copy of the License at 912027Sjungma@eit.uni-kl.de 1012027Sjungma@eit.uni-kl.de http://www.apache.org/licenses/LICENSE-2.0 1112027Sjungma@eit.uni-kl.de 1212027Sjungma@eit.uni-kl.de Unless required by applicable law or agreed to in writing, software 1312027Sjungma@eit.uni-kl.de distributed under the License is distributed on an "AS IS" BASIS, 1412027Sjungma@eit.uni-kl.de WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 1512027Sjungma@eit.uni-kl.de implied. See the License for the specific language governing 1612027Sjungma@eit.uni-kl.de permissions and limitations under the License. 1712027Sjungma@eit.uni-kl.de 1812027Sjungma@eit.uni-kl.de *****************************************************************************/ 1912027Sjungma@eit.uni-kl.de 2012027Sjungma@eit.uni-kl.de/***************************************************************************** 2112027Sjungma@eit.uni-kl.de 2212027Sjungma@eit.uni-kl.de sc_module_name.cpp -- An object used to help manage object names 2312027Sjungma@eit.uni-kl.de and hierarchy 2412027Sjungma@eit.uni-kl.de 2512027Sjungma@eit.uni-kl.de Original Author: Stan Y. Liao, Synopsys, Inc. 2612027Sjungma@eit.uni-kl.de 2712027Sjungma@eit.uni-kl.de CHANGE LOG AT THE END OF THE FILE 2812027Sjungma@eit.uni-kl.de *****************************************************************************/ 2912027Sjungma@eit.uni-kl.de 3012027Sjungma@eit.uni-kl.de#include <cstdlib> 3112027Sjungma@eit.uni-kl.de 3212027Sjungma@eit.uni-kl.de#include "sysc/kernel/sc_kernel_ids.h" 3312027Sjungma@eit.uni-kl.de#include "sysc/kernel/sc_module.h" 3412027Sjungma@eit.uni-kl.de#include "sysc/kernel/sc_module_name.h" 3512027Sjungma@eit.uni-kl.de#include "sysc/kernel/sc_object_manager.h" 3612027Sjungma@eit.uni-kl.de#include "sysc/kernel/sc_simcontext.h" 3712027Sjungma@eit.uni-kl.de#include "sysc/utils/sc_iostream.h" 3812027Sjungma@eit.uni-kl.de 3912027Sjungma@eit.uni-kl.denamespace sc_core { 4012027Sjungma@eit.uni-kl.de 4112027Sjungma@eit.uni-kl.desc_module_name::sc_module_name( const char* name_ ) 4212027Sjungma@eit.uni-kl.de: m_name( name_ ), 4312027Sjungma@eit.uni-kl.de m_module_p( 0 ), 4412027Sjungma@eit.uni-kl.de m_next( 0 ), 4512027Sjungma@eit.uni-kl.de m_simc( sc_get_curr_simcontext() ), 4612027Sjungma@eit.uni-kl.de m_pushed( true ) 4712027Sjungma@eit.uni-kl.de{ 4812027Sjungma@eit.uni-kl.de m_simc->get_object_manager()->push_module_name( this ); 4912027Sjungma@eit.uni-kl.de} 5012027Sjungma@eit.uni-kl.de 5112027Sjungma@eit.uni-kl.desc_module_name::sc_module_name( const sc_module_name& name_ ) 5212027Sjungma@eit.uni-kl.de: m_name( name_.m_name ), 5312027Sjungma@eit.uni-kl.de m_module_p( 0 ), 5412027Sjungma@eit.uni-kl.de m_next( 0 ), 5512027Sjungma@eit.uni-kl.de m_simc( name_.m_simc ), 5612027Sjungma@eit.uni-kl.de m_pushed( false ) 5712027Sjungma@eit.uni-kl.de{} 5812027Sjungma@eit.uni-kl.de 5912027Sjungma@eit.uni-kl.desc_module_name::~sc_module_name() 6012027Sjungma@eit.uni-kl.de{ 6112027Sjungma@eit.uni-kl.de if( m_pushed ) { 6212027Sjungma@eit.uni-kl.de sc_module_name* smn = m_simc->get_object_manager()->pop_module_name(); 6312027Sjungma@eit.uni-kl.de if( this != smn ) { 6412027Sjungma@eit.uni-kl.de SC_REPORT_ERROR( SC_ID_SC_MODULE_NAME_USE_, 0 ); 6512027Sjungma@eit.uni-kl.de } 6612027Sjungma@eit.uni-kl.de if ( m_module_p ) m_module_p->end_module(); 6712027Sjungma@eit.uni-kl.de } 6812027Sjungma@eit.uni-kl.de} 6912027Sjungma@eit.uni-kl.de 7012027Sjungma@eit.uni-kl.desc_module_name::operator const char*() const 7112027Sjungma@eit.uni-kl.de{ 7212027Sjungma@eit.uni-kl.de return m_name; 7312027Sjungma@eit.uni-kl.de} 7412027Sjungma@eit.uni-kl.de 7512027Sjungma@eit.uni-kl.de} // namespace sc_core 7612027Sjungma@eit.uni-kl.de 7712027Sjungma@eit.uni-kl.de// $Log: sc_module_name.cpp,v $ 7812027Sjungma@eit.uni-kl.de// Revision 1.5 2011/08/26 20:46:10 acg 7912027Sjungma@eit.uni-kl.de// Andy Goodrich: moved the modification log to the end of the file to 8012027Sjungma@eit.uni-kl.de// eliminate source line number skew when check-ins are done. 8112027Sjungma@eit.uni-kl.de// 8212027Sjungma@eit.uni-kl.de// Revision 1.4 2011/02/18 20:27:14 acg 8312027Sjungma@eit.uni-kl.de// Andy Goodrich: Updated Copyrights. 8412027Sjungma@eit.uni-kl.de// 8512027Sjungma@eit.uni-kl.de// Revision 1.3 2011/02/13 21:47:37 acg 8612027Sjungma@eit.uni-kl.de// Andy Goodrich: update copyright notice. 8712027Sjungma@eit.uni-kl.de// 8812027Sjungma@eit.uni-kl.de// Revision 1.2 2008/05/22 17:06:26 acg 8912027Sjungma@eit.uni-kl.de// Andy Goodrich: updated copyright notice to include 2008. 9012027Sjungma@eit.uni-kl.de// 9112027Sjungma@eit.uni-kl.de// Revision 1.1.1.1 2006/12/15 20:20:05 acg 9212027Sjungma@eit.uni-kl.de// SystemC 2.3 9312027Sjungma@eit.uni-kl.de// 9412027Sjungma@eit.uni-kl.de// Revision 1.4 2006/03/14 23:56:58 acg 9512027Sjungma@eit.uni-kl.de// Andy Goodrich: This fixes a bug when an exception is thrown in 9612027Sjungma@eit.uni-kl.de// sc_module::sc_module() for a dynamically allocated sc_module 9712027Sjungma@eit.uni-kl.de// object. We are calling sc_module::end_module() on a module that has 9812027Sjungma@eit.uni-kl.de// already been deleted. The scenario runs like this: 9912027Sjungma@eit.uni-kl.de// 10012027Sjungma@eit.uni-kl.de// a) the sc_module constructor is entered 10112027Sjungma@eit.uni-kl.de// b) the exception is thrown 10212027Sjungma@eit.uni-kl.de// c) the exception processor deletes the storage for the sc_module 10312027Sjungma@eit.uni-kl.de// d) the stack is unrolled causing the sc_module_name instance to be deleted 10412027Sjungma@eit.uni-kl.de// e) ~sc_module_name() calls end_module() with its pointer to the sc_module 10512027Sjungma@eit.uni-kl.de// f) because the sc_module has been deleted its storage is corrupted, 10612027Sjungma@eit.uni-kl.de// either by linking it to a free space chain, or by reuse of some sort 10712027Sjungma@eit.uni-kl.de// g) the m_simc field is garbage 10812027Sjungma@eit.uni-kl.de// h) the m_object_manager field is also garbage 10912027Sjungma@eit.uni-kl.de// i) an exception occurs 11012027Sjungma@eit.uni-kl.de// 11112027Sjungma@eit.uni-kl.de// This does not happen for automatic sc_module instances since the 11212027Sjungma@eit.uni-kl.de// storage for the module is not reclaimed its just part of the stack. 11312027Sjungma@eit.uni-kl.de// 11412027Sjungma@eit.uni-kl.de// I am fixing this by having the destructor for sc_module clear the 11512027Sjungma@eit.uni-kl.de// module pointer in its sc_module_name instance. That cuts things at 11612027Sjungma@eit.uni-kl.de// step (e) above, since the pointer will be null if the module has 11712027Sjungma@eit.uni-kl.de// already been deleted. To make sure the module stack is okay, I call 11812027Sjungma@eit.uni-kl.de// end-module() in ~sc_module in the case where there is an 11912027Sjungma@eit.uni-kl.de// sc_module_name pointer lying around. 12012027Sjungma@eit.uni-kl.de// 12112027Sjungma@eit.uni-kl.de// Revision 1.3 2006/01/13 18:44:30 acg 12212027Sjungma@eit.uni-kl.de// Added $Log to record CVS changes into the source. 12312027Sjungma@eit.uni-kl.de// 124