r/AskComputerScience • u/Successful_Box_1007 • Nov 18 '25
Can somebody help me understand how a dev can trust building an app in a virtual machine that is only emulating hardware but not a true representative of it ? (I thought about it an even if the VM is the same as the native architecture they want to run on, how can they trust this VM)?
Can somebody help me understand how a dev can trust building an app in a virtual machine that is only emulating hardware but not a true representative of it ? (I thought about it an even if the VM is the same as the native architecture they want to run on, how can they trust this VM)?
0
Upvotes
View all comments
Show parent comment
2
u/Graumm Nov 21 '25
I think the word virtual is throwing you off. If the platform is the same as the host system it isn’t a simulation, as much as it is an isolation of resources. Consider that OS’s and applications both run based on a “relative” understanding of the underlying system.
The system gets CPU time and some understanding of how many threads are available to it, so that it can schedule how processes are allocated CPU time. This is a bit of a simplified view because there’s a lot of runtime heuristics that go into determining the best way to interleave different execution contexts, manage context switching, and juggle different processes. The OS can only manage the time that it has. An application can happily eat up all resources available to it, and the OS can decide scheduling priority of that application vs other processes on the system. The OS runs when it runs, and it only cares about managing fairness/priority of the execution time that it has. The OS can only manage the thread execution contexts that it knows about.
It’s the same with memory. Memory addresses are relative. The OS gets its own memory space that starts at 0, the same as an application that gets its own memory space that starts at 0. When the application assigns to a memory address this is a relative address from a base-address in the system below, but this detail is irrelevant to it. These are “virtual memory spaces” that get mapped down to hardware addresses from the application, to the OS/VM, to the hypervisor, to the physical hardware. They do not reference absolute global memory locations in the hardware. These virtual memory tables are a hardware primitive defined in an execution context that each layer above sanity checks and passes along, such that a CPU instruction operates on a memory address the exact same way at any level of the stack.
There is some more complexity here to randomize how addresses map to other addresses in terms of block allocations, so that you can’t use a compromised OS/app to access memory that you shouldn’t be able to access and extract data. There is complexity on the CPU side as well to mitigate side channel attacks, where you can use the timings/delays to assume details about other processes running on the same system. But in general every process at any level is only aware of the CPU time it has, and its own memory space.
Assembly runs in the context that it has. This is no different at any level. The CPU runs the exact same instructions. In the case of emulation layers they are re-expressing assembly and interfaces from other platforms/OS’s to use the platform/OS of the host system. There are virtual (or relative?) mappings all the way down but from the perspective of any one layer of the system they are the center of the universe. When virtual isolation is guaranteed at each layer, they are not being simulated (in the same way that an interpreted language is executed) because the hardware primitives respect the isolation of the individual execution contexts. An OS/VM can only operate on execution contexts that it manages. By the time the instructions get down to the hardware it has a memory address and an instruction, and it doesn’t need to do translations at each layer on the way down. The VM layers build around the hardware primitives so that they don’t have to, and the hardware primitives guarantee isolation between contexts.