How do Linux emulators work in Windows?

0

1

Obviously, they created a Linux environment for Linux applications to run in Windows. But,

  • What kind of techniques are used for this?
  • Are there any special mechanisms followed?

arulappan

Posted 2012-07-26T04:18:59.787

Reputation: 943

I'm assuming you're referring to applications like MSYS/MinGW/Cygwin? – Casey Kuball – 2012-07-26T04:24:15.633

Welcome to Super User. Please take a moment to read the FAQ. In particular, note that questions providing specifics and details are more likely to get good answers. You can edit your question to provide additional detail regarding what you would like to know.

– Michael Hampton – 2012-07-26T04:50:55.890

Which Linux emulators are you talking about in specific? What actual problem are you facing? – slhck – 2012-07-26T05:01:16.143

I'm not using any linux emulators. I'm just curious to know about how they achieve this? Because different executable file formats are used in linux and windows. There should be some basic or common technique used by all emulators, so which is that. If not, how they differ from each other? – arulappan – 2012-07-26T05:05:56.760

Are you facing a specific problem? This site is for Q&A regarding issues users are actually having, not discussions over or theories on how things work. – MaQleod – 2012-07-26T06:33:20.847

Answers

2

There are no such thing as Linux emulators

  • If you're talking about Cygwin then they literally reimplement all Unix system calls in terms of Windows API calls in a special userspace DLL file. Programs compiled for Cygwin environment therefore can't run independently in Windows

    Cygwin consists of two parts: a dynamic-link library (DLL) as an API compatibility layer in the form of a C standard library providing a substantial part of the POSIX API functionality, and an extensive collection of software tools and applications that provide a Unix-like look and feel.

    ...

    Cygwin consists of a library that implements the POSIX system call API in terms of Win32 system calls, a GNU development toolchain (including GCC and GDB) to allow software development, and running of a large number of application programs equivalent to those on Unix systems

    https://en.wikipedia.org/wiki/Cygwin

  • If you're talking about MSYS/MSYS2 or MinGW then they're not a simulator in any sense. Programs are compiled into native Windows binaries using Microsoft C library and they can run without any special environment

    Although both Cygwin and MinGW can be used to port Unix software to Windows, they have different approaches: Cygwin aims to provide a complete POSIX layer comprising a full implementation of all major Unix system calls and libraries. Compatibility is considered higher priority than performance. On the other hand, MinGW's priorities are simplicity and performance. As such, it does not provide certain POSIX APIs which cannot easily be implemented using the Windows API, such as fork(), mmap() and ioctl(). Applications written using a cross-platform library that has itself been ported to MinGW, such as SDL, wxWidgets, Qt, or GTK+, will usually compile as easily in MinGW as they would in Cygwin.

    https://en.wikipedia.org/wiki/MinGW#Comparison_with_Cygwin

  • In Windows 10 MS introduced which is really a Linux simulator and not an emulator, just like how Wine is not an emulator. They have a special kernel component to handle Linux system calls and convert them to Windows version in order to run native Linux ELF binaries without recompiling

    WSL is a collection of components that enables native Linux ELF64 binaries to run on Windows. It contains both user mode and kernel mode components. It is primarily comprised of:

    • User mode session manager service that handles the Linux instance life cycle
    • Pico provider drivers (lxss.sys, lxcore.sys) that emulate a Linux kernel by translating Linux syscalls
    • Pico processes that host the unmodified user mode Linux (e.g. /bin/bash)

    Block chart

    WSL executes unmodified Linux ELF64 binaries by virtualizing a Linux kernel interface on top of the Windows NT kernel. One of the kernel interfaces that it exposes are system calls (syscalls). A syscall is a service provided by the kernel that can be called from user mode. Both the Linux kernel and Windows NT kernel expose several hundred syscalls to user mode, but they have different semantics and are generally not directly compatible. For example, the Linux kernel includes things like fork, open, and kill while the Windows NT kernel has the comparable NtCreateProcess, NtOpenFile, and NtTerminateProcess.

    https://blogs.msdn.microsoft.com/wsl/2016/04/22/windows-subsystem-for-linux-overview/

In the past there were also Microsoft POSIX subsystem and Windows Services for UNIX but they're not meant to run Linux. For more information read POSIX and UNIX Support in Windows

phuclv

Posted 2012-07-26T04:18:59.787

Reputation: 14 930