News for hackers. Stuff that matters.
Re:A static_cast is not always just a pointer adjustment by titzer on Saturday April 02, 2016 @05:18AM (#11410856)
> This is just plain ugly.

Yeah. Unfortunately the only really efficient protection mechanisms that modern processors have is virtual memory. C++ programs generally unmap the first few pages for exactly the same reason; to catch nullptr derefs.

> Why should the normal operation of a program written in a high-level language trigger page faults?

NullPointerExceptions are not considered normal operation. They are safety violations that have a controlled, well-defined semantics. BTW page faults happen all the time; the OS transparently handles them and maps in new pages as necessary. The problem you are referring occurs when a page fault happens and the OS knows there is no mapping for those addresses.

> How do you guarantee that the OS won't give you back the same pages you unmapped

Because the mapping is for an address space range (e.g. 0-N), and the OS does not overlap new request with existing mappings unless specified in the request.

Re:A static_cast is not always just a pointer adjustment by catnaroek on Saturday April 02, 2016 @01:38PM (#11412390)
> NullPointerExceptions are not considered normal operation. They are safety violations that have a controlled, well-defined semantics.

I'm not really buying this. My definition of “normal operation” is very simple: Everything but FFI calls. Normal operation in a safe language is supposed to be safe.

Re:A static_cast is not always just a pointer adjustment by catnaroek on Saturday April 02, 2016 @05:25AM (#11410869)
> and the OS does not overlap new request with existing mappings unless specified in the request.

Ah, so by “unmap”, you actually something like POSIX's `mprotect()`, rather than `munmap()`?

Re:A static_cast is not always just a pointer adjustment by titzer on Saturday April 02, 2016 @07:30AM (#11411151)
Sorry, yes. You can do this just through segment declarations in both ELF and MachO binary formats, to prevent anything getting accidentally mapped there before startup.