5 ms·
I think the author is confused. Protecting a code segment to be 'read only' does not change a machine from "Von Neumann" to "Modified Harvard" architecture. Tha
by ChuckMcM 11y ago
I think the author is confused. Protecting a code segment to be 'read only' does not change a machine from "Von Neumann" to "Modified Harvard" architecture. That distinction is reserved for computers that separate the 'store' (aka volatile memory) into two disjoint regions. And pure Harvard architecture machines (like the early PIC series from Microchip) suffer from an in ability to vary the partition between data and code, which is the real problem[1].
Now there is a pretty sound reason for making your code segment read only, and the author touches on it, which is that if you are running third party code, because it limits the attack surface for security exploits somewhat.
But then he goes off the rails with this claim, "What really struck me was that there was no flexibility here; no way to for a program to make changes to itself or build new subprograms, even if Microsoft approved it."
The next topic on the required reading list should be "Turing complete" :-) It is entirely possible to write a piece of code which is both a core interpreter, and the byte codes on which that interpreter is operating. And including in the byte codes a means to read, modify, and re-execute any previous byte codes. The sum of actions of course will be constrained by what can be expressed in a byte code but given that, you are free to do what ever you want.
And of course any interpreter which was interspersing its data and executable byte codes in the same chunk of memory, well that would be a Von Neumann architecture :-)
[1] Harvard machines ultimately fell out of favor because you could end up with left over code store and not enough data store for an application.
- vardump 11y agoI think it's all about performance. > Now there is a pretty sound reason for making your code segment read only Sure, but I've had enough situations where ability to generate code made inner loop 2-3x faster, by removing branches and constant folding. Difficult? Yes! Error prone? Yes! Fast? Hell yes! > It is entirely possible to write a piece of code which is both a core interpreter Yes, but it's going to be 10-100x slower.
- kayamon 11y agoSo every program needs to be wrapped in an additional VM?
- ChuckMcM 11y ago[Hi kayamon, I am presuming you're Richard, if I'm mistaken in that please let me know.] Collected together for one response ... > On a machine where programs are supplied as bytecode, > there are indeed two disjoint regions. > The bytecode sits in it's own region. You can't > touch it from the data region. Doesn't that depend on how you define the byte code? If I define byte codes as follows, 0x01 0xnn 0xmm load a byte from offset 0xnnmm in memory. 0x02 0xqq load qq into accumulator immediate 0x03 0xnn 0xmm store accumulator into 0xnnmm in memory 0x04 0xnn 0xmm set program counter to 0xnnmm 0x05 increment accumulator Then I put 02 00 05 03 00 01 04 00 00 Into memory, and "run" my byte code, This program self modifies the load immediate value continuously. When Java defined its byte code it went out of its way to avoid 'pointer arithmetic' to make the language safer but even in Java's heap model the memory to store data and executable content is the same memory, it is an artifact of the Java byte code definition that it doesn't allow for self modifying Java code, it has nothing to say about byte code in general. And the point where things get confusing for me is that architecture is reasoning about structure in general, where as implementation is reasoning about structure in specifics. So there is nothing architecturally significant about byte codes with respect to computer architecture, other than you can simulate a variety of architectural choices by how you define your byte codes. > So every program needs to be wrapped in an > additional VM? No. The point was that your blog post conflated computer architecture with an implementation choice made by a particular vendor. Many vendors have chosen to create implementations which make implementing self modifying code difficult. They have their reasons, and you elucidated on two of them, rights management and security. That they have done so, gives them some benefit, and it comes at some cost to you, the developer. When looked at from a cost / benefit point of view, I would be interested to read about how those design choices constrain your ability to deliver a compelling game experience, or a needed capability. To often these things are only discussed in terms of what they do for party A or party B and rarely do we get some thinking on what we cannot have because of the constraints imposed by their implementation choice.
- kayamon 11y agoYou're absolutely right that bytecodes in general are just like any other instruction set, so can be modified etc. I guess I'm using the term 'bytecode' to refer to systems such as Java, where they don't let you mess around with it much. It's almost always the case for any implementation of a bytecode system that they don't treat it as writeable data.
- kayamon 11y ago> That distinction is reserved for computers that separate the 'store' (aka volatile memory) into two disjoint regions On a machine where programs are supplied as bytecode, there are indeed two disjoint regions. The bytecode sits in it's own region. You can't touch it from the data region.
- microtherion 11y agoI believe you are misunderstanding the use of bytecode in the Apple Watch: What is deployed to the device is still native code, the bytecode is merely what's submitted to the app store.
- kayamon 11y agoBut if the program has no knowledge, visibility or control of the native code, it effectively does not exist.