Hacker News new | past | comments | ask | show | jobs | submit login

> so that it causes a segfault if you access it

No, this is UB. It can cause a segfault, but it can also allow bad things™ to happen.




Let's be clear on the difference between C and C++ undefined behaviour, and machine behaviour that GCs and runtimes can use for implementation.

It is not unusual to rely on triggering a hardware exception in runtimes and GCs, up to and including segfaults. For example, a check for safepoint might be implemented by attempting to read a particular address. When the GC needs to stop the world, it could change the protection bits on the page that contains that address. This technique minimizes the amount of code in the safepoint test and doesn't require any branching logic.

See e.g. https://stackoverflow.com/questions/46394575/safepoints-in-j...

Another technique: a runtime can support dynamic growth of the stack by keeping an unmapped or protected page at the limit, and extending it when hit. This is how stacks work on Windows, and it relies on help from codegen: compilers targeting Windows need to generate code that performs a loop touching every page in its stack frame allocation one at a time in allocation order, if the stack frame is larger than the page size.

See e.g. https://geidav.wordpress.com/tag/stack-probing/


In C that would be true. LLVM might be able to provide stronger guarantees, particularly on specific architectures.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: