WSL概述

参考:What’s new in Windows Console in Windows 10 Fall Creators Update

Windows Subsystem for Linux Overview

WSL,Windows Subsystem for Linux 由Microsoft Windows内核团队创建

History of Windows Subsystems

  Windows NT自成立以来,便支持多environment subsystems(eg. POSIX, OS/2 and Win32 subsystems)。以Win32 subsystems为例,Win32 subsystems向应用程序提供编程接口(programmatic interface),使上层应用不必依赖于内核实现细节。

  早期的subsystems是以用户模式实现的,在上层应用与Windows NT内核之间“拉皮条”。将上层应用的API请求转换成对内核的系统调用。所有的应用程序都是PE/COFF可执行文件,或者作为库、服务。他们实现了subsystems像外“暴漏”API。当用户空间可执行文件启动时,loader会根据其header信息调用正确的subsystems来满足该可执行程序的环境、依赖等资源。后来POSIX这个subsystems被SUA(Subsystem for Unix-based Applications)替换,SUA由若干用户模式组件(user mode components)构成,包括:

    1. Process and signal management
    2. Terminal management
    3. System service requests and inter process communication

SUA的组要作用是鼓励应用程序在没有重大重写的情况下移植到Windows。其实现原理是:使用NT构造实现POSIX用户模式API。但是这有个弊端,由于这些组件(components)运行在用户模式下,原本针对Linux开发的应用程序,NT下很难为应用程序中那些系统调用实现优化或者加速,比如fork()。

随着时间的推移,最初的subsystems逐渐退役,但是Windows NT架构允许新的subsystems,因此可以在这个领域扩展或增强subsystems来满足需要,WSL就是这么诞生的。

Windows Subsystem for Linux

WSL是一堆组件的集合,他们协同工作,最终让你在Windows上运行原生Linux ELF64 二进制文件。WSL包括用户模式组件、内核模式组件,其职责:

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

It is the space between the user mode Linux binaries and the Windows kernel components where the magic happens. By placing unmodified Linux binaries in Pico processes we enable Linux system calls to be directed into the Windows kernel. The lxss.sys and lxcore.sys drivers translate the Linux system calls into NT APIs and emulate the Linux kernel.

 

猜你喜欢

转载自www.cnblogs.com/kelamoyujuzhen/p/10211953.html
wsl