Line: Run elf in Windows

Source: Internet
Author: User

Recently, I have an idea that I want to develop something called line. We all know that there is a very awesome software on Linux called wine (wine is not emulater) that can run Windows on Linux.Program. Line (line is not emulater) is the opposite of wine, allowing Linux programs to run on Windows. Http://gussing.cnblogs.com/

The reason why wine is feasible is based on the fact that Windows programs are based on Windows APIs, NTDLL. DLL, kernel32.dll, user32.dll, and other APIs encapsulate all windows system calls. API-based applications do not know the details of the kernel. Wine does two things: 1. Develop a PE Loader to load Windows programs, and 2. Develop a complete set of Windows APIs for Windows programs. As far as I know, wine has reached the level where most Windows APIs have been implemented. The general architecture of wine is as follows: http://gussing.cnblogs.com/

Later, a project called "compatible with the kernel" was launched.CodeAll system calls in the kernel. We know that Linux calls and Windows calls cannot correspond one by one. For example, if ntcreateprocessex system calls are implemented on Linux, there may be more than one Linux system call. If Windows system calls are implemented directly in the Linux kernel, the number of calls will be reduced to 1, and the efficiency will be improved. In addition, some things that are difficult to handle by the user State will become easier with the help of the kernel state kernel export function. The general architecture with compatible kernel is as follows: http://gussing.cnblogs.com/

As shown in, the compatible kernel modifies the wine DLL and replaces the mechanism of "simulating windows DLL with Linux system call" with "Connecting int 2E on Linux to simulate Native Windows DLL ". Http://gussing.cnblogs.com/

Line is based on the fact that most Linux programs are based on glibc. Similar to Windows APIs, glibc encapsulates Linux system calls, if you can call the Linux system interface again, glibc should be able to run on Windows, and most * native * Linux programs can also run on Windows. Http://gussing.cnblogs.com/

Here we have to mention a program that is almost similar: cygwin. Cygwinsimulates the glibcfunction on Windows and calls it cygwin1.dll. it passes the portto the gcc.exeSource codeThe Linux program has been re-compiled again, but also to run the Linux program on windows, as shown in: http://gussing.cnblogs.com/

The general architecture is similar to that of wine. However, cygwin runs a pe-format Linux program, saving the trouble of doing elf loader. Why does wine not compile a Windows program in ELF format? It is very simple, because there is no source code. Http://gussing.cnblogs.com/

Finally, let's talk about the line architecture I expected: http://gussing.cnblogs.com/

As shown in, you must first have an elf loader to load the native Linux program into the process space. The native Linux program must deal with glibc, so you must also load glibc in. Glibc has two parts. One part can be completed in the user State, and the other part needs to enter the kernel through the system call. Therefore, there is a kernel state driver in line to support the int 80 system call. In Linux, there are more than 300 system calls. It is impossible for me to finish all the calls by myself, not to mention that the time is not enough. Some calls are basically difficult, so the system call routine is divided into two parts: some are implemented in the kernel, while some are not. Unimplemented parts will be played back to the user State using APC, and then taken from cygwin1 again.

In this way, line can execute * native * Linux programs like wine. In fact, at the beginning, I still thought about another path, that is, directly modifying cygwin to let it go to the int 80 path, so a series of annoying problems related to glibc (believe me, you can avoid it and use existing resources to the maximum extent. However, this path is less elf loader and runtime Lib, and more things can be learned, so I will drop it. Http://gussing.cnblogs.com/

I have been using the line project in my spare time, but I don't know how much it can be. Sometimes think about it, even I am very much looking forward to it. Haha.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.