Re: virtual memory range that can be used for wrong pointers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Oleg,

On Wed, Aug 01, 2018 at 12:58:01PM +0300, Oleg wrote:
>   Hello.
> 
> I have a code where i need more than one "wrong" pointer value(this one is
> NULL pointer). Something like a signal handler SIG_IGN that equal to 1.
> 
> So, my question is, what is the guarantied range of addresses (from 0 to X),
> which can be safely used for this purpose on any hardware architecture?
> 
> Thanks.
> 
> -- 
> Олег Неманов (Oleg Nemanov)
> --

Assuming your code is userspace code, right?

There is no generic rule that NULL is invalid pointer. One can mmap()
memory at NULL with MAP_FIXED and it will make NULL dereferencable.
Though, usually the whole page containing NULL is not mapped to
userspace.

You can check valid mappings with 'cat /proc/<pid>/maps'.
Dereferencing of any address out of that list will cause segfault.

If you need the range of addresses that cause segfaults if
dereferenced, the most portable way would be mapping sufficient
amount of memory with PROT_NONE.

Yury
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Assembler]     [Git]     [Kernel List]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [C Programming]     [Yosemite Campsites]     [Yosemite News]     [GCC Help]

  Powered by Linux