Discussion:
crash test virtual ram
(too old to reply)
fir
2017-08-20 21:39:12 UTC
Permalink
if you will run such code (on windows)

int main()
{
int sum = 0;

for(unsigned i=0x00400000; i<0x00401000; i++)
{
char* x = (char*) i;
sum+= *x;
}

printf("sum = %d", sum);

return 0;
}
then depending on readed ram area it will work or crash ("there is a trouble with that aplication, aplication will be closed")

i think you get crash when you will read a ram area where ram is just not pinned
(im not sure if on windows pages are just guarded from read, i understand write, execute, but read? is this the case?)

that was one question second is

how to catch and recover from this crash (i just want to write a tiny ram scanner who will try read all 32 bit ram area and will give me info back which areas i can read and which i cant)

(same possibly with write though im not sure if i will try read any byte vale then write say 0x55 to any byte then write back oryginal value it will calmly stand such crash test ;c will it?
R.Wieser
2017-08-21 06:13:41 UTC
Permalink
fir,
Post by fir
how to catch and recover from this crash
How about another approach, like not doing the action that will cause it to
crash ? Would that not be even better ? :-)

I don't know how they are called in C++, but Kernel32.dll has got commands
available to check if a certain memory area is readable or writable. Their
names are :

IsBadReadPtr

and

IsBadWritePtr

Hope you can use them.

Regards,
Rudy Wieser
Post by fir
if you will run such code (on windows)
int main()
int sum = 0;
for(unsigned i=0x00400000; i<0x00401000; i++)
{
char* x = (char*) i;
sum+= *x;
}
printf("sum = %d", sum);
return 0;
}
then depending on readed ram area it will work or crash ("there is a
trouble with that aplication, aplication will be closed")
Post by fir
i think you get crash when you will read a ram area where ram is just not pinned
(im not sure if on windows pages are just guarded from read, i understand
write, execute, but read? is this the case?)
Post by fir
that was one question second is
how to catch and recover from this crash (i just want to write a tiny ram
scanner who will try read all 32 bit ram area and will give me info back
which areas i can read and which i cant)
Post by fir
(same possibly with write though im not sure if i will try read any byte
vale then write say 0x55 to any byte then write back oryginal value it will
calmly stand such crash test ;c will it?
JJ
2017-08-21 14:59:36 UTC
Permalink
Post by R.Wieser
fir,
Post by fir
how to catch and recover from this crash
How about another approach, like not doing the action that will cause it to
crash ? Would that not be even better ? :-)
I don't know how they are called in C++, but Kernel32.dll has got commands
available to check if a certain memory area is readable or writable. Their
IsBadReadPtr
and
IsBadWritePtr
Hope you can use them.
Regards,
Rudy Wieser
FYI, those IsBadXXX() functions may still trigger an exception. Especially
if the application doesn't use C++ runtime library. e.g. non MSVC compiled
applications.
fir
2017-08-21 15:27:38 UTC
Permalink
Post by JJ
Post by R.Wieser
fir,
Post by fir
how to catch and recover from this crash
How about another approach, like not doing the action that will cause it to
crash ? Would that not be even better ? :-)
I don't know how they are called in C++, but Kernel32.dll has got commands
available to check if a certain memory area is readable or writable. Their
IsBadReadPtr
and
IsBadWritePtr
Hope you can use them.
Regards,
Rudy Wieser
FYI, those IsBadXXX() functions may still trigger an exception. Especially
if the application doesn't use C++ runtime library. e.g. non MSVC compiled
applications.
well ok tnx for info for thiose functions i dont knowed that ,

check btw my comment on this (for other group as i posted on other too)

"note however how bad this communicate is

CPU exactly know that it is

"MOV instruction for IP 0x0040_110c tried to read from adress 0x0000_0012 which is page guarded form read"

or

"MOV instruction for IP 0x0040_110c tried to write value of 0x00000002 to adress 0x0000_0012 which is page guarded for write"

or

"CALL instruction for IP 0x0040_110c tried to execute code at adress 0x0000_0012 which is page guarded for execute"

it gives a lot of info and those messages dont give this fine info "


is there a way to retrive just those info and continue execution back - to read another ram cell (and probably get it agian, then again skip it till
reaaching readable memory??

(note howewer how god example it is as
code who would have sense to continue
after page exception is i think rare to give ;c
Johann Klammer
2017-08-22 01:09:04 UTC
Permalink
Post by fir
Post by JJ
Post by R.Wieser
fir,
Post by fir
how to catch and recover from this crash
How about another approach, like not doing the action that will cause it to
crash ? Would that not be even better ? :-)
I don't know how they are called in C++, but Kernel32.dll has got commands
available to check if a certain memory area is readable or writable. Their
IsBadReadPtr
and
IsBadWritePtr
Hope you can use them.
Regards,
Rudy Wieser
FYI, those IsBadXXX() functions may still trigger an exception. Especially
if the application doesn't use C++ runtime library. e.g. non MSVC compiled
applications.
well ok tnx for info for thiose functions i dont knowed that ,
check btw my comment on this (for other group as i posted on other too)
"note however how bad this communicate is
CPU exactly know that it is
"MOV instruction for IP 0x0040_110c tried to read from adress 0x0000_0012 which is page guarded form read"
or
"MOV instruction for IP 0x0040_110c tried to write value of 0x00000002 to adress 0x0000_0012 which is page guarded for write"
or
"CALL instruction for IP 0x0040_110c tried to execute code at adress 0x0000_0012 which is page guarded for execute"
it gives a lot of info and those messages dont give this fine info "
that's what the os determines in the exception handler.
Post by fir
is there a way to retrive just those info and continue execution back - to read another ram cell (and probably get it agian, then again skip it till
reaaching readable memory??
(note howewer how god example it is as
code who would have sense to continue
after page exception is i think rare to give ;c
POSIX systems pass those things on as SIGNALs to userspace with
pretty much all that info attached. It requires installing a signal handler.
I do not know if windows is similar.
JJ
2017-08-22 13:10:18 UTC
Permalink
Post by fir
Post by JJ
Post by R.Wieser
fir,
Post by fir
how to catch and recover from this crash
How about another approach, like not doing the action that will cause it to
crash ? Would that not be even better ? :-)
I don't know how they are called in C++, but Kernel32.dll has got commands
available to check if a certain memory area is readable or writable. Their
IsBadReadPtr
and
IsBadWritePtr
Hope you can use them.
Regards,
Rudy Wieser
FYI, those IsBadXXX() functions may still trigger an exception. Especially
if the application doesn't use C++ runtime library. e.g. non MSVC compiled
applications.
well ok tnx for info for thiose functions i dont knowed that ,
check btw my comment on this (for other group as i posted on other too)
"note however how bad this communicate is
CPU exactly know that it is
"MOV instruction for IP 0x0040_110c tried to read from adress 0x0000_0012 which is page guarded form read"
or
"MOV instruction for IP 0x0040_110c tried to write value of 0x00000002 to adress 0x0000_0012 which is page guarded for write"
or
"CALL instruction for IP 0x0040_110c tried to execute code at adress 0x0000_0012 which is page guarded for execute"
it gives a lot of info and those messages dont give this fine info "
is there a way to retrive just those info and continue execution back - to read another ram cell (and probably get it agian, then again skip it till
reaaching readable memory??
(note howewer how god example it is as
code who would have sense to continue
after page exception is i think rare to give ;c
If applicable, you should scan the memory address space first using
VirtualQuery() or VirtualQueryEx() so that you'll know which address ranges
are accessible without triggering any exception.

Without first knowing the above information, you'll have to setup your own
exception handler each time you try to access a memory address in order to
know whether a memory address is accessible or not. Note that this method
will be much slower because when an exception is triggered, the exception
handler code will be executed.

Loading...