retry on memory reading error

develop
Petr Mrázek 2009-10-29 00:45:23 +00:00
parent 42e5cdc361
commit 7e8fecccec
1 changed files with 8 additions and 1 deletions

@ -31,19 +31,26 @@ distribution.
#include <errno.h> #include <errno.h>
using namespace std; using namespace std;
// danger: uses recursion!
inline inline
void Mread (const uint32_t &offset, const uint32_t &size, uint8_t *target) void Mread (const uint32_t &offset, const uint32_t &size, uint8_t *target)
{ {
if(size == 0) return;
int result; int result;
result = pread(g_ProcessMemFile, target,size,offset); result = pread(g_ProcessMemFile, target,size,offset);
if(result != size) if(result != size)
{ {
cerr << "pread failed: can't read " << size << " bytes at addres " << offset << endl;
if(result == -1) if(result == -1)
{ {
cerr << "pread failed: can't read " << size << " bytes at addres " << offset << endl;
cerr << "errno: " << errno << endl; cerr << "errno: " << errno << endl;
errno = 0; errno = 0;
} }
else
{
Mread(offset + result, size - result, target + result);
}
} }
} }