开发Linux兼容内核的策略与路线Word文档下载推荐.docx
- 文档编号:5823160
- 上传时间:2023-05-05
- 格式:DOCX
- 页数:15
- 大小:31.15KB
开发Linux兼容内核的策略与路线Word文档下载推荐.docx
《开发Linux兼容内核的策略与路线Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《开发Linux兼容内核的策略与路线Word文档下载推荐.docx(15页珍藏版)》请在冰点文库上搜索。
Saidtohavebeenreached,becausewealreadyhaveintheuserspaceWine,butithasbeenresolvedNdisWrapperWindowsdevicedrivertoloadLinuxkernelproblem.另一个极端呢,则是说兼容内核的难度太大,根本就不可能成功,所以只是一个“梦”。
Theotherextremeitiscompatiblewiththekernelisthattoodifficult,simplycannotsucceed,soonlya"
dream."
显然,在谈论开发路线图之前首先应该回答这两种意见。
Obviously,talkingabouttheroadmapshouldbeansweredbeforethefirstofthesetwoviews.幸好它们正好互相构成回答。
Fortunately,theyarejustanotherformanswer.
首先,正如笔者在另几篇文章中所说,Wine只是在逻辑上、功能上基本解决了用Linux内核来模拟/仿真Windows内核的问题,但是性能上是无法令人满意的,而且说基本上解决其实也很勉强。
First,asIhavesaidinotherarticles,Wineisonlylogical,functionbasicallysolvedwiththeLinuxkerneltosimulate/SimulationWindowskernelproblem,butperformanceisnotsatisfactory,andthatbasicallysolutionisactuallyveryreluctant.至于NdisWrapper,它所解决的是一些网络设备(网卡)的驱动,而不是普遍意义上的设备驱动。
AsNdisWrapper,itsolvedsomenetworkdevice(NIC)driver,notthegeneralsenseofthedevicedriver.更何况NdisWrapper设备驱动的上层只能是Linux的Socket,而不能与诸多文件操作的系统调用挂上钩。
Moreover,theupperNdisWrapperdevicedrivercanonlybeLinux,Socket,andnotwithalotoffilemanipulationsystemcallsprocessislinked.实际上,退一步说,即使NdisWrapper和Wine真的已经分别解决了Windows设备驱动和应用软件在Linux内核上的跨平台运行,也还需要有人把这二者整合起来。
Infact,tosaytheleast,evenifNdisWrapperandWinereallyhassolvedtheWindowsdevicedrivers,respectively,andapplicationsoftwareintheLinuxkerneltoruncross-platform,theystillneedsomeonetointegratethesetwo.有许多公司只是把一些开源软件收集(而不是整合)拢来,做成发行版,不是就号称成了“高科技公司”吗?
Therearemanycompaniesjusttocollectsomeopensourcesoftware(notintegrated)LongLai,makedistributions,nottobecomeknownas"
high-techcompanies"
do?
所以,要使Windows的应用软件和设备驱动能在Linux上高效地运行,从而真正为广大用户所接受,兼容内核的开发应该说是很有必要,而且也不是那么轻而易举。
So,tomakeWindowsapplicationsanddevicedriverscanrunefficientlyonLinux,andtrulyacceptedbythemajorityofusers,thedevelopmentshouldbecompatiblewiththekernelisnecessary,butnotsoeasy.
至于说难度太大,那么Wine和NdisWrapper的存在和发展恰恰为兼容内核技术上的可行性提供了参考。
Astoodifficult,thentheWineandNdisWrapperpreciselytheexistenceanddevelopmentofthetechnicalfeasibilityofacompatiblekerneltoprovideareference.诚然,Wine在某些方面很不理想,但那正是因为要避开内核而导致的后果,许多在用户空间很难解决的问题一到了内核里面就可以豁然开朗。
Indeed,Wineisverygoodinsomerespects,butitispreciselybecausethekerneltoavoidtheresultingconsequences,manyoftheproblemsdifficulttosolvetheuserspacetokernelinsideonecansuddenlyseethelight.或者可以反过来说,Wine在用户空间都可以基本解决的问题,到了内核里面就更好解决了。
Oritcanconversely,Wineintheuserspacecanbebasicallysolvedtheproblem,tothekernelwhichwouldbebettersolved.当然,涉及内核的设计和编程比之用户空间在难度(复杂度)上要高得多,但是“难”是个相对的概念,谁能说清到底难到什么程度就根本不能做了呢?
Ofcourse,thekernelofthedesignandprogramminginvolvedintheuserspacethaninthedifficulty(complexity)ismuchhigheron,but"
difficult"
isarelativeconcept,whoshalltelltowhatdegreeofdifficultyintheendsimplycannotdoit?
再说这也毕竟不是登月、不是哥德巴赫猜想。
Thisisnottosay,afterall,themoon,nottheGoldbachconjecture.另一方面,Wine所提供的许多高层DLL为兼容内核的实际使用提供了条件,或者可以说是解决了后顾之忧。
Ontheotherhand,WineprovidedbytheDLLiscompatiblewithmanyhigh-levelkernelprovidestheconditionsforpracticaluse,orcanbesaidtosolvetheworries.如果说Wine毕竟不涉及内核,因此还不足为凭,那么NdisWrapper可确实为我们在内核中构建设备驱动框架和支撑界面提供了参考,实质上也是一个可行性证明。
Afterall,ifWinedoesnotinvolvethekernel,itisalsoBuzuweiping,thenNdisWrappercandoforusinbuildingthekerneldevicedriverinterfaceprovidesaframeworkandsupportingreference,inessence,isafeasibilityproof.
认为难度太大的人还有一个顾虑,就是Windows的代码是不公开的,藏在黑盒子中,光凭几本书能得到多少信息、如何就能开发出跟Windows兼容的内核?
Toodifficultforthepeoplethatthereisaconcern,thatis,Windowsthecodeisnotpublic,hiddenintheblackbox,evenwiththefewbookstogetmuchinformation,howcandevelopcompatiblewiththeWindowskernel?
这种顾虑当然也有一些道理,但是ReactOS又在这方面给我们提供了参考。
Thisconcernofcourse,thereissometruth,butinthiscontextReactOShasprovideduswithinformation.ReactOS以零为起点从头开发,Wine只在内核外面做文章,尚且都能在一定程度上达到设计目标,而我们站在它们的肩膀上,又有Linux内核作为原材料,至少条件比他们好多了。
ReactOStozeroasastartingpointfromscratch,Wineonlymakeanissueoutofthekernel,yetitcanbetosomeextenttomeetthedesigngoals,andwestandontheirshoulders,anotherLinuxkernelasarawmaterial,atleastmuchbetterconditionsthantheyare.
当然,把Wine、NdisWrapper和ReactOS作为参考意味着我们需要吃透、或者至少基本上理解它们的代码。
Ofcourse,theWine,NdisWrapperandReactOSasareferencemeansthatweneedtounderstandwell,oratleastbasicallyunderstandtheircode.为此笔者将陆续写一些分析文章在本网站上推出,起个抛转引玉的作用。
TodothisIwillgraduallywriteanalyticalarticlesonthissitelaunch,sincetheroleofaparabolicquotedYu.
总之,兼容内核的开发既不是唾手可得,也不是难于上青天,既不能一蹴而就,也不至于遥遥无期。
Inshort,neithercompatiblewiththedevelopmentofthekernelisaneasy,norisitimpossibleforthecounty,wecannotbedoneovernight,youwillnotbeputoffindefinitely.说起来还是那句老话:
战略上藐视困难,战术上重视困难。
Thatitisanoldsayinggoes:
strategicdefianceofdifficultiesandtacticallydifficult.
后发跟进、逐步逼近Follow-upafterthehair,graduallyapproaching
我们开发兼容内核不能采取一步到位、而应采取逐步逼近的策略。
Wehavedevelopedcompatiblewiththekernelcannottakeonestep,butshouldadoptagradualapproachofthestrategy.以系统调用界面为例,我们完全可以先搁置那些用于GUI、即win32k.sys的扩充系统调用,即便是对于248个常规系统调用也可以分期分批地实现。
Thesystemcallinterface,forexample,wecansetasidethoseusedforthefirstGUI,thewin32k.sysexpansionofsystemcalls,evencallsfortheconventionalsystem248canalsobeachievedinstages.实际上,我们甚至并无必要追求一个完整的实现。
Infact,weevendonotneedtopursueacompleteimplementation.工程上有一个所谓20/80原理,说是20%的工作量往往可以实现80%的功能,而剩下的20%功能却往往需要80%的工作量才能实现。
Worksonaso-called20/80principle,thatis20%oftheworkloadcanoftenachieve80%ofthefunction,whiletheremaining20%ofthefeaturesareoftenrequiredtoachieve80%oftheworkload.如果我们的兼容内核可以支持80%的Windows应用,剩下的20%慢慢从长计议也无不可。
Ifwecansupportthecompatibilityofkernel80%ofWindowsapplications,andtheremaining20%havenolong-termperspectiveisnotslow.再说,Windows本身也在发展,今天还是“完整”的实现,明天就可能是不完整的了。
Besides,Windowsisalsodevelopingitsowntoday,or"
complete"
therealizationoftomorrowmaynotbecompleteby.所以,我们可以采取在一定距离后面跟进的策略。
Therefore,wecantakeinacertaindistancebehindthefollow-upstrategy.只要Windows还存在、还在发展,这样的跟进就永远不会完。
AslongasthereisWindows,isstilldeveloping,sothatfollow-upwillneverend.这种后发跟进、逐步逼近的策略决定了我们的开发必定是一个螺旋式的渐进开发过程。
Thefollow-upafterthehair,graduallyapproachingthestrategicdecisionsofourdevelopmentmustbeaprogressivespiraldevelopmentprocess.就是说:
从不同成分之间的关系看,是螺旋式的发展;
从同一成分内部看,则是渐进的发展。
Thatis:
therelationshipbetweendifferentcomponentsfromview,isaspiraldevelopment;
fromthesamecomponentsinside,isthegradualdevelopment.
那么,这个螺旋式渐进开发过程的起点是什么呢?
Well,thisprogressivespiraldevelopmentprocessisthestartingpointforwhat?
起点就是Linux+Wine。
StartingpointistheLinux+Wine.随着开发的进行,Linux的内核逐渐变成兼容内核,我们姑且以Linux+表示;
而Wine则逐渐演变成一个按Windows系统调用界面定制并且优化了的Wine,我们姑且称之为Wine'
。
Withthedevelopment,Linuxkernelbecomingcompatiblekernel,wehavetentativelysaidtoLinux+;
andWineisgraduallyevolvingintoaWindowssystemcallinterfacebycustomizedandoptimizedforWine,let'
scallthemWine'
.所以整个开发过程就是:
Sothewholedevelopmentprocessis:
(Linux+Wine)=>
…=>
(Linux++Wine'
)(Linux+Wine)=>
...=>
(Linux++Wine'
)
起点Linux+Wine显然是可以运行的,开发过程中的每一步都实现一组有限的目标,每一步的结果都应该是一个可以运行的、更逼近Windows的、可以发行的版本。
Linux+Wineisobviouslystartingtorun,thedevelopmentprocessateverysteptoachievealimitedsetofobjectives,theresultsofeachstepshouldbearun,andclosertoWindows,youcanversion.
对Linux内核的修改原则上以动态安装模块的形式实现,尽可能不改变Linux内核原有的代码,必要时当然也可以打一下补丁。
ChangestotheLinuxkernelinprincipletoinstallthemodule,implementedasdynamicaspossiblewithoutchangingtheoriginalLinuxkernelcode,ifnecessary,ofcourse,canbeatthepatch.
兼容内核开发的主体是一个框架、两个界面。
Compatiblewiththemainkernelisaframework,thetwointerfaces.如果按它们在内核中的位置从上到下排序,那就是:
系统调用界面,设备驱动框架,以及设备驱动支撑界面。
Ifyoupresstheminorderfromtoptobottomthepositionofthekernel,thatis:
Thesystemcallinterface,thedevicedriverframework,anddevicedriversupportinterface.下面分别加以讨论。
Bediscussedseparatelybelow.
系统调用界面的开发Systemcallinterfacedevelopment
系统调用界面的实现有个“门槛”,那就是内核的进入/退出机制,即系统调用时的空间切换机制,不跨过这道门槛就谈不上系统调用界面。
Implementationofthesystemcallinterfacehasa"
threshold"
thatisthekernelentry/exitmechanism,thatspacewhenthesystemcallswitchingmechanism,donotcrossthisthresholdwouldbenosystemcallinterface.不过这个机制的实现并不复杂,因为我们要实现的本质上是Linux内核上的系统调用,从而这实际上就是Linux系统调用的空间切换机制,所不同的只是:
However,therealizationofthismechanismisnotcomplicated,becausewewanttoachieveistheessenceofsystemcallsonLinuxkernel,sothisisactuallyaLinuxsystemcallsthespaceswitchingmechanism,theonlydifference:
●●
Linux
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 开发 Linux 兼容 内核 策略 路线