What is the meaning of "code" in segmentation error

I see these 2 segmentation errors in android. One said SEGV_MAPERR, the other said SEGV_ACCERR.

Could you tell me what is the difference between the two?

signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 41963214 signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 4006e000 

Thanks.

+7
android linux
source share
2 answers

Per siginfo.h :

SEGV_MAPERR means that you tried to access an address that does not map to anything.

SEGV_ACCERR means that you tried to access an address that you do not have access to.

Thus, in both cases, you gained access to an address that you should not have, which is probably the only culprit in your actual code. In the first case, there is no memory in this address range. In the latter case, there is memory in this address range, but you do not own it.

If you need to access a random address that you get depends on how the OS will have your process at the moment.

+12
source share

If you access memory like *((int*)0)=1 , you will get SEGV_MAPERR .

If you protected the memory with mprotect(2) , for example, mprotect(buffer, pagesize, PROT_READ) , then you changed the memory as *(buffer)=1 , you will get SEGV_ACCERR .

Please man mprotect for details.

0
source share

All Articles