direct-code-execution / ns-3-dce

Run real programs in the discrete time simulator ns3
http://www.nsnam.org/projects/direct-code-execution/
76 stars 46 forks source link

DCE application crashes when calling atexit handlers if it "never ends" #135

Open chenbq83 opened 2 years ago

chenbq83 commented 2 years ago

Description of the problem

I run my application on DCE, and it crashes when test ends. The application is something like a server, so it "never ended" when the whole test ends. It crashes when some global variable's destructor of this application is being called. and it crashes because some local variable on the stack has not yet released (because the process is still "run").

I guess this might be a problem of DCE. DCE calls the process's atexit handlers on TaskManager::DoDispose() while some objects on stack are never released. As a workaround, I skip the "dce___cxa_finalize " call.

What is your opinion? and how to fix this? Thanks

void TaskManager::DoDispose (void)
{
  if (m_disposing)
    {
      return;
    }
  m_disposing = 1;

  // Flush every FILEs in every processes.
  Ptr<DceManager> dceManager = this->GetObject<DceManager> ();

  if (0 != dceManager)
    {
      std::map<uint16_t, Process *> procs = dceManager->GetProcs ();
      std::map<uint16_t, Process *>::iterator it;

      for (it = procs.begin (); it != procs.end (); it++)
        {
          if (0 != it->second)
            {
              gDisposingThreadContext = it->second->threads.back ();

              // call atexit handler for linux kernel
              // dce___cxa_finalize (0);                                         <<<<<<< Skip the atexit handler 
              if (0 != gDisposingThreadContext)
                {
                  Process *p = it->second;
                  for (std::vector<FILE *>::const_iterator i = p->openStreams.begin ();
                       i != p->openStreams.end (); ++i)
                    {
                      fflush (*i);
                    }
                }
              gDisposingThreadContext = 0;
            }
        }
    }
  Object::DoDispose ();
}

output of ./waf configure

None

Steps to reproduce

None