Write Linux code for the simulator

xiaoxiao2021-03-06  45

The history of simulating other computers on a computer is very long, usually in order to use legacy applications, or to use more stable, responding to the faster OS system running the popular OS. As Linux is increasingly popular, when developers planning the binary procedures running on a non-Linux system, they need to review their choices. This article will study the functionality of the simulator and will learn the problem of hardware simulation and software simulation in detail.

Simulation of other computers have many years of history on a computer. A common reason for simulating old computers is nostalgic, but it is undeniable that many simulators can run a variety of computer games very well. Another reason for simulating other computers is to use applications that exist on a particular platform.

Typically, the application simulation is targeted for platforms that occupy a larger market share. For example, the Wine project attempts to provide a way to run a Windows binary.

However, in recent years, Linux has been proven to be a stable and fully equipped operating system; therefore, its market share has also increased. The growth of market share has aroused people's interest in simulating Linux. This paper commented on the status quo of Linux binary simulation on other systems, and focused on some of the issues that developers should keep in mind in order to make people more convenient to run their binaries in the simulated environment.

Basic simulator

The simulator's idea is very simple. Computers are fully predictable. If you want to know exactly if you give a specific code computing opportunity, you can get results by establishing a model of this computer. Of course, this will involve considerable overhead, however, if the computer to be simulated is much older than the computer being informing, then the analog environment will be faster than the original machine.

There are some simulated layers, such as NetBSD's Linux simulation layer, just providing analog of software part of an environment, acquiring system calls from the Linux library, and handles the return result, making it look like using the Linux kernel. Other simulation layers, such as VirtualPC, can simulate the entire computer, including a processor. The speed of the analog processor will be slower, but it can bring better compatibility.

Distributor in the release version format

Although this paper focuses on the method of running Linux binary programs on other platforms, the compiled binary issued version also has a place. With the increasing popularity of the Linux simulation environment, Linux binary formats become a feasible method of issuing simple programs (no source code). Linux binary can run on a variety of systems, can not be denied, sometimes you need to pay some costs as a Linux binary format as a general release version format.

Typically, analog is not enough to allow you to run a shared object built in a system in a program built for another system. If most of your product is released in the form of a shared library object, then these products may not be loaded on other platforms.

Some people think that using the Linux binary format to issue code to other platforms. Maybe this is crazy, but it is feasible. In recent years, my main web browser has been running in analog environments (more free of typing processors, document converters, and even credit card processing software).

Most of our software applications we are willing are commercial, and you can issue a single binary that can run on a lot of platforms will greatly benefit commercial software vendors. If there are a variety of Linux analog environments available, the Linux binary gauge is characterized by the first real software release selection.

Hey, transplanted source code is a great task that is very different from the issuance; in general, transplant tasks are simpler.

Full Hardware Simulator Full Hardware Simulator will simulate a complete machine; not just processors, but also include all parts of the machine. For example, the simulated computer may have its own keyboard controller and video card. Full hardware simulation is often used in programs that use older machines. The MAME Arcade Game The Simulator is a popular example that simulates the hardware of a variety of old-fashioned alien game consoles. For some aspects, the full hardware simulator is the easiest way to simulate. Many jobs need to build a full hardware simulator, but once you have such a simulator, all things can be solved. For example, VirtualPC version 3 for Macintosh begins to support Linux. Hardware simulations can solve problems that use other ways to solve. For example, I used to have a BIOS flash tool, which is only released by the format of an image file for DOS. Worse, the machine running it must install the actual floppy disk on the traditional ISA floppy controller (my Windows desktop has an LS-120 drive). Let's solve this problem by simulation! I run the program under the simulator and write the data into a USB floppy drive that has been inserted into the Mac. Hardware simulations also have their unfavorable aspects. In order for everything to work, it is necessary to pay great efforts. If a network is required, you also need to have a good network chip so that the operating system can run on this chip. In addition, the cost of the instructions that simulate itself may be very high. Typically, a system like this can run nearly perfectly, but the function associated with time limit may be unreliable. The full hardware simulator has been used for a long time, and the legacy system and code that can be processed can be affected by the simulation. Nonetheless, in order to run the X86Linux binary program on Macintosh or any other non-X-86 machine, in order to attempt to run the program, it may be fully dependent on a certain currently available X86 simulator. In a system like this, most of the tool programs will run very well (although it may be slower). The only major concern about worry is that in order to improve performance, the user may install smaller or older Linux distributions. Those who use 32 MB of memory to run analog machines cannot run the latest version of KDE. Some Hardware Simulator Some Hardware Simulars are an intermediate solution: they simulate a computer, but this computer can only be the same as the computer type they actually. Since the speed of execution is comparable to the host machine, similar such programs can reduce the cost of the simulation. Examples of such simulators include Serenity Virtual Station and VMware. These systems are most practical when you have applications for multiple operating systems and need to run them simultaneously. Similar to the full hardware simulation, such a system will run a complete Linux OS environment, as long as your program can be placed properly across Linux systems, then there is no problem. However, it is very useful to declare that Linux's portability to the older version will be very useful. People who use virtual machines may be willing to run an older, smaller Linux version on such systems. Software Simulator In analog world, the software simulator is the most basic. The software simulator is not running your application on a virtual machine - it does not pass virtual machines, but it runs in real time. To create an environment, in this environment, the code's code can run normally, however, the attempt to access the operating system will be sent through a simulation layer so that these programs can be used.

Wine is an excellent example (although it is used for Windows), although it is not a formal simulator. Some software simulators are explicitly called by the user, such as the LXRun program available for the SCO and Solaris systems. Some software simulators are built into the UNIX support to load the binary image support - if the program does not seem correctly, then it can take it with a possible analog table to see if they can run it. Software simulator usually brings the best user experience. No special settings are required, do not require a huge disk image. The program only needs to run (most cases). However, access system calls, shared libraries, and file system structures will trigger a lot of questions, so we will discuss them next. System call

System call is the easiest part of the simulation is also the most difficult part. System calls have explicitly defined interfaces, and it is often easy to detect and process calling mechanisms - this is a simple part. The difficulty is that it may be difficult or impossible to achieve system calls better. Traditionally, the most difficult to deal with the Linux simulation is the Clone () system call. This call provides a mandatory method for obtaining a simple thread, that is, create two shared many content processes, the shared content can include memory, file descriptors, signal processing - in other words, can include any content and all content. Unfortunately, if your operating system does not have a full-similar function, there is no way to implement this system call.

Worse, because the POSIX thread is not perfect or widely supported, Clone () has appeared and often used as an alternative to the POSIX thread, so many programs are exciting, complex And (I must say) I don't want to use it.

If you want people to run your binary, try to let them do not use system calls for a particular operating system; it is best to use standard POSIX system calls. This is a good habits for software development.

The kernel-based simulator can capture system calls to its system. User space simulator, such as lxrun, will wait for an application to try system calls. Since the Linux system call function is different from the system call function on Solaris or Scounix, a result is an error in the result. The lxrun program then corrects this error like a debugger and allows the system call to continue running - but, in fact, it has intercepted this system call, and performs corresponding system calls to the underlying operating system, and solves all problems. clever!

File system structure

The problem of the file system is usually more subtle. Access the file system is extremely simple. Not simple, how to find the file you want.

If your program is running in analog environments, the file system to access may be different from the file system used by your developer. For example, if your program uses a / proc file system (common to get kernel status and information), then the common features in the newer kernel may not exist in older systems.

The developers here have a huge advantage than developers on the proprietary system, as different Linux distributions are arranged in different ways, so most of the programmers are very clear how to avoid over-reliability design. But - sometimes - have to embed the file name into the program.

Many simulators solve the solution taken by this problem that establish an additional interpretation layer for file system calls. For example, in the NetBSD's Linux analog environment code, first check the files on the file according to the files in / emul / linux, and then check the files in the real root directory. This allows the system to provide a file that "override" system files when the Linux binary cannot use standard files.

In fact, the main purpose of this method is that the library and other support documents, but many system binary procedures are also provided. For example, if the Linux binary attempts to call uname to get the core version, it has got the version number of NetBSD, which will be very confused. Instead, it should get the expected Linux version number. Sharing library

As mentioned earlier, the shared library is a very good example of the binary that can be simulated to find but cannot be found by the system binary. Since the format and ABI details on different systems can be different, you cannot assume that all systems can share a given library. Name may conflict - for example, both NetBSD and SUSE7.3 have a file called libncurses.so.5. What is important is to use the correct one.

The shared library pointed out another precautions for developers. It is important to learn about the library version of different systems being used. Now, NetBSD's Linux analog environment is using the SUSE 7.3 shared library. There is still a code using a 9.1 shared program, but they get warnings, they cannot stably perform the internal nuclear level simulation.

The analog environmental package is usually not far from the market. Even if you think that most expected users should have a quite new Linux release, a large number of simulants are almost all in the era.

The shared library has also triggered another concern - not each system contains all shared libraries. Analog environmental packages typically do not install all the latest shared libraries. Moreover, it is more troublesome that their users are unlikely to easily install the missing packages.

In these cases, it is a good way to minimize the dependence on new features and non-core sharing. Simulator users may encounter these issues.

Do not mistake to use a static library to ensure solving these issues. Static libraries may introduce their own new dependencies, and it is not easy to check them. If you are static linking a system call to use an unmiglable system, then the rewrite algorithm avoids this system call will not be used. Dynamic links allow you to build programs to run on a larger range.

Calling other programs has a special situation than any other case, especially related to the installer. On many systems, the shell obtained by calling / bin / sh is not BASH. This means that scripts extended using BASH may not be run on other systems.

This is in a particularly intricate logic in the simulator. When performing a binary, the operating system may know enough, check the Linux path of the associated Linux binary, and it might install a copy of Bash. However, when you run a script, the kernel does not see it as a Linux binary; it finds that the script is attached to an interpreted program path, which will no longer run under analog mode when attempting to load an interpreter.

Portable shell script technology is hereained here. This is one of the most common problems that the user is facing when the user runs analog. The installer may not be able to run because it is not a portable shell script.

Similar to standard development, just more standard

In order to facilitate users who may want to run your program in analog environments, they need to keep ink the following items, and they should keep in keeping these matters when developing any software:

Comply with appropriate standards as much as possible.

Avoid "special features".

Do not challenge the limit (Push the envelope).

Moreover, as long as it is avoided, do not depends on some things just released a month to build your code. Because you will narrow your effective target market.

转载请注明原文地址:https://www.9cbs.com/read-60169.html

New Post(0)