Hacker News new | ask | show | jobs
by yjftsjthsd-h 23 days ago
So, basically an emulator layer that doesn't need a host OS? (I'm not really interested in running Darwin, but that's a cool concept)
2 comments

I guess one could call it a "bare-metal/type 1 emulator" much like VMs can run in a "bare-metal/type 1 hypervisor".
"An ahead-of-time and just-in-time compiler translates arm64e code to x86-64."

No, not the same, actually. It's more of a Rosetta, but other way round, if I understand this right.

Rosetta is an emulator (or, I suppose, a series of emulators), i.e. a piece of software that makes a computer pretend to be another kind of computer. This is also a bit of lower level software that makes a (x86_64) computer pretend to be a different kind of computer (aarch64), in this case, by AoT and JIT translation, though that's an implementation detail. What distinction are you trying to make?
This doesn't emulate a computer so that code in another architecture can run, it translates the other architecture'a code to native code. It's a small difference, but I guess it is a difference.
Is this not how qemu works? Is rosetta not considered an emulation layer? For all its name suggests otherwise, I would certainly refer to wine as an emulator, and it also uses these techniques.
Not to be That Guy, but WINE doesn't use those techniques, and thus isn't an emulator.

It lightly translates binary formats (Windows executables) into Linux-compatible executable code, and then runs that code against libraries that implement Windows APIs in terms of Linux underneath. It's not an emulator in the same way that your libc isn't emulating lockf(3) in terms of fcntl(2) underneath. In web-dev parlance, we'd call WINE a polyfill.

Rosetta and QEMU on the other hand are emulators--emulators, in this instance, being a term of art that implies interpreting bespoke meaning from machine code instructions written in another program. Some emulators translate instructions 1:1, some have optimized stencils, some (like Rosetta) have kernel support for emulating very quickly, and some (maybe like Rosetta; sources disagree) also have hardware support as well.

WINE emulates an ABI, rather than a CPU or such, but I'd happily argue that that's an emulator. (In fairness, though it's not generally described that way, I would call web polyfills API emulation)
It implements an ABI.

It "emulates a behaviour" and natural language is fluid, so sure, you could call WINE an emulator and I wouldn't be mad at you. But WINE is very different compared to what most emulators are. Usually the term is reserved for when you emulate in software what used to be hardware.

> It lightly translates binary formats (Windows executables) into Linux-compatible executable code,

Does this not involve transpilation? I guess I was grouping that in under dynamic recompilation and AOT techniques.

Regardless, I don't think that there's a benefit from defining emulation from an implementation rather than an empirical perspective. If it runs a chunk of code as if it were in a different environment, I'm kind of ok to call it an emulator. To the sibling's point, a polyfill would also fit as an emulation layer here.

Not necessarily. It could just rewrite the outer portion to be an ELF loader that then calls into a runtime that actually shims the syscalls for example. I don't think WINE does exactly this but it's not really transpiling either.
You don't even need that, really; just have wine load the PE binary into memory and hand it a bunch of DLLs that use Linux syscalls under the hood. It's less transpiler and more of a funky dynamic linker+loader plus libraries.
Wine as a polyfill makes so much more sense
I believe WINE doesn't actually translate any instructions; it's a Windows PE loader and a bunch of libraries that implement Windows APIs using Linux equivalents.
How does it handle stuff like syscalls without altering the executed code?
Windows apps don't use syscalls directly; they call into kernel32.dll, which is convenient for Wine. (Microsoft enforces this by scrambling the syscall numbers on OS updates [1].)

[1]: https://j00ru.vexillium.org/syscalls/nt/64/

It installs handlers. I don't have the exact name but there's support in the kernel to redirect syscalls to a Userland process
It's reverse Rosetta with a hardware emulator underneath.