Fix linux crashes.

develop
Petr Mrázek 2010-04-19 00:32:50 +02:00
parent 39eacd2069
commit 96b42f8ac1
7 changed files with 39 additions and 17 deletions

@ -46,7 +46,7 @@ using namespace DFHack;
class SHMProcess::Private class SHMProcess::Private
{ {
public: public:
Private() Private(Process * self_)
{ {
memdescriptor = NULL; memdescriptor = NULL;
process_ID = 0; process_ID = 0;
@ -62,10 +62,12 @@ class SHMProcess::Private
suspend_lock = -1; suspend_lock = -1;
attachmentIdx = 0; attachmentIdx = 0;
locked = false; locked = false;
self = self_;
}; };
~Private(){}; ~Private(){};
memory_info * memdescriptor; memory_info * memdescriptor;
DFWindow * window; DFWindow * window;
Process * self;
pid_t process_ID; pid_t process_ID;
char *shm_addr; char *shm_addr;
int shm_ID; int shm_ID;
@ -262,9 +264,10 @@ bool SHMProcess::Private::GetLocks()
} }
SHMProcess::SHMProcess(uint32_t PID, vector< memory_info* >& known_versions) SHMProcess::SHMProcess(uint32_t PID, vector< memory_info* >& known_versions)
: d(new Private()) : d(new Private(this))
{ {
d->process_ID = PID; d->process_ID = PID;
d->memdescriptor = 0;
if(!attach()) if(!attach())
{ {
// couldn't attach to process // couldn't attach to process
@ -335,9 +338,9 @@ bool SHMProcess::Private::validate(vector <memory_info *> & known_versions)
try{ try{
if(hash == (*it)->getString("md5")) // are the md5 hashes the same? if(hash == (*it)->getString("md5")) // are the md5 hashes the same?
{ {
memory_info * m = *it; memory_info *m = new memory_info(**it);
memdescriptor = m; memdescriptor = m;
m->setParentProcess((Process*)this); m->setParentProcess(dynamic_cast<Process *>( self ));
identified = true; identified = true;
// cerr << "identified " << m->getVersion() << endl; // cerr << "identified " << m->getVersion() << endl;
return true; return true;
@ -357,7 +360,8 @@ SHMProcess::~SHMProcess()
{ {
detach(); detach();
} }
// destroy data model. this is assigned by processmanager if(d->memdescriptor)
delete d->memdescriptor;
if(d->window) if(d->window)
{ {
delete d->window; delete d->window;

@ -34,7 +34,7 @@ using namespace DFHack;
class WineProcess::Private class WineProcess::Private
{ {
public: public:
Private() Private(Process * self_)
{ {
my_descriptor = NULL; my_descriptor = NULL;
my_handle = NULL; my_handle = NULL;
@ -43,10 +43,12 @@ class WineProcess::Private
attached = false; attached = false;
suspended = false; suspended = false;
memFileHandle = 0; memFileHandle = 0;
self = self_;
}; };
~Private(){}; ~Private(){};
DFWindow* my_window; DFWindow* my_window;
memory_info * my_descriptor; memory_info * my_descriptor;
Process * self;
ProcessHandle my_handle; ProcessHandle my_handle;
uint32_t my_pid; uint32_t my_pid;
string memFile; string memFile;
@ -58,7 +60,7 @@ class WineProcess::Private
}; };
WineProcess::WineProcess(uint32_t pid, vector <memory_info *> & known_versions) WineProcess::WineProcess(uint32_t pid, vector <memory_info *> & known_versions)
: d(new Private()) : d(new Private(this))
{ {
char dir_name [256]; char dir_name [256];
char exe_link_name [256]; char exe_link_name [256];
@ -69,6 +71,7 @@ WineProcess::WineProcess(uint32_t pid, vector <memory_info *> & known_versions)
int target_result; int target_result;
d->identified = false; d->identified = false;
d->my_descriptor = 0;
sprintf(dir_name,"/proc/%d/", pid); sprintf(dir_name,"/proc/%d/", pid);
sprintf(exe_link_name,"/proc/%d/exe", pid); sprintf(exe_link_name,"/proc/%d/exe", pid);
@ -147,9 +150,11 @@ bool WineProcess::Private::validate(char* exe_file, uint32_t pid, char* mem_file
// are the md5 hashes the same? // are the md5 hashes the same?
if(memory_info::OS_WINDOWS == (*it)->getOS() && hash == thishash) if(memory_info::OS_WINDOWS == (*it)->getOS() && hash == thishash)
{ {
memory_info * m = *it;
// keep track of created memory_info object so we can destroy it later
memory_info *m = new memory_info(**it);
my_descriptor = m; my_descriptor = m;
m->setParentProcess((Process*)this); m->setParentProcess(dynamic_cast<Process *>( self ));
my_handle = my_pid = pid; my_handle = my_pid = pid;
// tell WineProcess about the /proc/PID/mem file // tell WineProcess about the /proc/PID/mem file
memFile = mem_file; memFile = mem_file;
@ -166,6 +171,9 @@ WineProcess::~WineProcess()
{ {
detach(); detach();
} }
// destroy our copy of the memory descriptor
if(d->my_descriptor)
delete d->my_descriptor;
if(d->my_window) if(d->my_window)
delete d->my_window; delete d->my_window;
delete d; delete d;

@ -33,7 +33,7 @@ using namespace DFHack;
class NormalProcess::Private class NormalProcess::Private
{ {
public: public:
Private() Private(Process * self_)
{ {
my_descriptor = NULL; my_descriptor = NULL;
my_handle = NULL; my_handle = NULL;
@ -42,6 +42,7 @@ class NormalProcess::Private
attached = false; attached = false;
suspended = false; suspended = false;
memFileHandle = 0; memFileHandle = 0;
self = self_;
}; };
~Private(){}; ~Private(){};
DFWindow* my_window; DFWindow* my_window;
@ -53,11 +54,12 @@ class NormalProcess::Private
bool attached; bool attached;
bool suspended; bool suspended;
bool identified; bool identified;
Process * self;
bool validate(char * exe_file, uint32_t pid, char * mem_file, vector <memory_info *> & known_versions); bool validate(char * exe_file, uint32_t pid, char * mem_file, vector <memory_info *> & known_versions);
}; };
NormalProcess::NormalProcess(uint32_t pid, vector< memory_info* >& known_versions) NormalProcess::NormalProcess(uint32_t pid, vector< memory_info* >& known_versions)
: d(new Private()) : d(new Private(this))
{ {
char dir_name [256]; char dir_name [256];
char exe_link_name [256]; char exe_link_name [256];
@ -68,6 +70,7 @@ NormalProcess::NormalProcess(uint32_t pid, vector< memory_info* >& known_version
int target_result; int target_result;
d->identified = false; d->identified = false;
d->my_descriptor = 0;
sprintf(dir_name,"/proc/%d/", pid); sprintf(dir_name,"/proc/%d/", pid);
sprintf(exe_link_name,"/proc/%d/exe", pid); sprintf(exe_link_name,"/proc/%d/exe", pid);
@ -125,8 +128,9 @@ bool NormalProcess::Private::validate(char * exe_file,uint32_t pid, char * memFi
memory_info * m = *it; memory_info * m = *it;
if (memory_info::OS_LINUX == m->getOS()) if (memory_info::OS_LINUX == m->getOS())
{ {
my_descriptor = m; memory_info *m2 = new memory_info(*m);
m->setParentProcess((Process*)this); my_descriptor = m2;
m2->setParentProcess(dynamic_cast<Process *>( self ));
my_handle = my_pid = pid; my_handle = my_pid = pid;
} }
else else
@ -154,6 +158,9 @@ NormalProcess::~NormalProcess()
{ {
detach(); detach();
} }
// destroy our copy of the memory descriptor
if(d->my_descriptor)
delete d->my_descriptor;
// destroy data model. this is assigned by processmanager // destroy data model. this is assigned by processmanager
if(d->my_window) if(d->my_window)
delete d->my_window; delete d->my_window;

@ -110,7 +110,7 @@ bool Buildings::Read (const uint32_t index, t_building & building)
// transform // transform
int32_t type = -1; int32_t type = -1;
d->d->offset_descriptor->resolveObjectToClassID (temp, type); d->owner->getDescriptor()->resolveObjectToClassID (temp, type);
building.origin = temp; building.origin = temp;
building.vtable = bld_40d.vtable; building.vtable = bld_40d.vtable;
building.x1 = bld_40d.x1; building.x1 = bld_40d.x1;

@ -142,7 +142,6 @@ bool Maps::Start()
d->block = new uint32_t[mx*my*mz]; d->block = new uint32_t[mx*my*mz];
uint32_t *temp_x = new uint32_t[mx]; uint32_t *temp_x = new uint32_t[mx];
uint32_t *temp_y = new uint32_t[my]; uint32_t *temp_y = new uint32_t[my];
uint32_t *temp_z = new uint32_t[mz];
p->read (x_array_loc, mx * sizeof (uint32_t), (uint8_t *) temp_x); p->read (x_array_loc, mx * sizeof (uint32_t), (uint8_t *) temp_x);
for (uint32_t x = 0; x < mx; x++) for (uint32_t x = 0; x < mx; x++)
@ -158,7 +157,6 @@ bool Maps::Start()
} }
delete [] temp_x; delete [] temp_x;
delete [] temp_y; delete [] temp_y;
delete [] temp_z;
return true; return true;
} }

@ -44,10 +44,14 @@ class Materials::Private
Materials::Materials(APIPrivate * d_) Materials::Materials(APIPrivate * d_)
{ {
d = new Private;
d->d = d_; d->d = d_;
d->owner = d_->p; d->owner = d_->p;
} }
Materials::~Materials(){} Materials::~Materials()
{
delete d;
}
/* /*
{ {
LABEL_53: LABEL_53:

@ -1060,6 +1060,7 @@ size=212
<Offset name="map_data_temperature1_offset">0x159c</Offset> <Offset name="map_data_temperature1_offset">0x159c</Offset>
<Offset name="map_data_temperature2_offset">0x179c</Offset> <Offset name="map_data_temperature2_offset">0x179c</Offset>
<Offset name="map_data_biome_stuffs">0x1D9C</Offset> <Offset name="map_data_biome_stuffs">0x1D9C</Offset>
<Offset name="map_data_pathfinding_offset">0x0D9c</Offset>
<!-- <!--
map_data_map_x_offset 0x0058 map_data_map_x_offset 0x0058
map_data_map_y_offset 0x005A map_data_map_y_offset 0x005A