4 ms·
I was just thinking about this in the shower. The death of the Harvard architecture combined with the slow adoption of w^x seems to vindicate the problem, but I
by GauntletWizard 5y ago
I was just thinking about this in the shower. The death of the Harvard architecture combined with the slow adoption of w^x seems to vindicate the problem, but I think there's a deeper truth to it: Turing complete machines can emulate any other Turing complete machine. Harvard architecture is immune to stack-smashing, but it's not immune to privilege escalations - Fundamentally, there's a usability tradeoff of "Loading new executable code from the data segment" that makes true Harvard architectures inoperable. We've settled on a happy if imperfect medium.
- gumby 5y agoVan neumann is more general and provides more flexibility (what if you need more data space and don't need all that code space?). There are still new harvard architecture microcontrollers being designed. It provides some security in the field as well as simplifying the chip layout.
- ludamad 5y agoIt'd be pretty annoying for a JIT compiler to have to manage too. Java can do a garbage collection with barely any memory left - cool! But, it'd be a shame if similar tricky stuff was written just to e.g. decompile code just to make way for more code space. Pages with only one of 'write' or 'execute' privileges work well enough
- samus 5y agoThese use cases could be served by asking the operating system or the hardware to copy data to the code memory. Weakens absolute protection, but it would be an escape hatch to enable JIT compilers.
- GauntletWizard 5y agoThat's half the definitional difference between Harvard and Von Neumann architectures, though - That never the twain shall meet. There's a second insight on the tip of my tongue, here: Harvard architectures can emulate Von Neumann ones, and vice versa. And problems, specific problems, can be solved by either. But it seems to me that there's something interesting about emulation too - That Harvard architectures can open themselves up to precisely the same vectors of attacks if you enable "Copy this data block to code memory".
- ______-_-______ 5y agoIf you couldn't transfer data memory to code memory at all, how would it be possible to write an ordinary compiler? If it's possible to run a compiler on the system, just have your JIT do whatever the compiler does.
- gumby 5y agoWell you write a bytecode compiler and run an interpreter for it out of code space. It could be a JIT compiler, just not one that generated native code. This approach was pretty common in the 80s Lisp days IIRC.
- samus 5y agoJava already compiles to bytecode, which executes on the JVM. But this is too slow for most practical applications. JIT compilation to native code is crucial for execution of Java programs with competitive speed. It would be possible to compile everything to machine code ahead of time (pretty much what GraalVM does), but that would compile everything even if it would never end up being executed*. Without JIT compiler, it would not be possible to recompile code to take advantage of tracing information gathered at runtime. Also, newly loaded Java code would not be able to be optimized at all. There are workarounds for all of these. For example, the JIT compiler could generate a new executable with the optimized code and migrate execution state to a new process. But it seems very clunky. *: Not really an issue with microservices and stripped-down binaries. A huge deal for IDEs and environments with plugin architecture though.
- bronson 5y agoWrite it to the filesystem (ELF format presumably) and execute the file. Some Harvard architecture implementations provide ways of shoving data into executable space and back (like special copy instructions) but it's not general purpose. Generally you compile on Von Neumann and flash to Harvard.
- compressedgas 5y agoBut not if instead of copying, they support a "Run this data as a program in virtual machine with access to these segments of memory" operation. The behavior would be functionally identical to emulating the architecture and interpreting the data, except that it wouldn't be slow and could be done recursively with no cumulative overhead.
- gumby 5y agoIn a standard harvard architecture that isn't possible.
- Espressosaurus 5y agoHarvard architecture is pretty common in MCU and ASIC space, and especially in tiny little low-powered processors that might have a tiny bit of flash that instructions are read out of and an even smaller amount of SRAM for data. The ARM9 architecture is effectively Harvard for example.
- kibwen 5y agoWASM is a Harvard architecture, so it's not as dead as one might think. :)
- gumby 5y agoI believe this is for the same reason some microcontrollers do it, to whit there is no page table and much less page access bits. These days the browser is a greater thread vector than ordinary application code.
- pcwalton 5y agoWasm is a Harvard architecture mostly because it wants to support implementations based on static recompilation. Obviously, self-modifying code is a problem for static recompilation, and the easiest way to prevent self-modifying code is just to not expose code in the address space at all. There's also the historical fact that wasm is a successor to asm.js, and asm.js is a Harvard architecture by virtue of the fact that JS Typed Arrays don't allow you to execute code stored in them.
- malkia 5y agoWouldn't GPU somewhat be Harvard architecture - e.g. code + data is split (then again, it's not general purpose CPU so this is way off, but it's coming closer every year)...