资源描述:
《virtualbox-原理构架分析》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、1,PATM.cppPATM.h2,PATMa.asm3,em.cpp4,em.h5,vm.cpp6,vm.h7.vm虚机创建:VMMR3DECL(int)VMR3Create(uint32_tcCpus,PCVMM2USERMETHODSpVmm2UserMethods,PFNVMATERRORpfnVMAtError,void*pvUserVM,PFNCFGMCONSTRUCTORpfnCFGMConstructor,void*pvUserCFGM,PVM*ppVM){……staticintv
2、mR3CreateUVM(uint32_tcCpus,PCVMM2USERMETHODSpVmm2UserMethods,PUVM*ppUVM){uint32_ti;}…….DECLCALLBACK(int)vmR3EmulationThread(RTTHREADThreadSelf,void*pvArgs){PUVMCPUpUVCpu=(PUVMCPU)pvArgs;returnvmR3EmulationThreadWithId(ThreadSelf,pUVCpu,pUVCpu->idCpu);
3、}……VMMR3DECL(int)EMR3ExecuteVM(PVMpVM,PVMCPUpVCpu){…………….rc2=PATMAreInterruptsEnabled(pVM)?VINF_EM_RESCHEDULE_RAW:VINF_EM_RESCHEDULE_REM;……………………VMMR3DECL(int)PATMR3InstallPatch(PVMpVM,RTRCPTRpInstrGC,uint64_tflags){JumpbacktoguestifIF=1,elsefault;BEG
4、INPROCPATMJumpToGuest_IF1PATMJumpToGuest_IF1_Start:movdword[ss:PATM_INTERRUPTFLAG],0pushftestdword[ss:PATM_VMFLAGS],X86_EFL_IFjnzPATMJumpToGuest_IF1_Safenop;IF=0->unsafe,sofaultpopfmovdword[ss:PATM_INTERRUPTFLAG],1PATM_INT3PATMJumpToGuest_IF1_Safe:;IF
5、=1->wecansafelyjumpbacktotheoriginalinstructionpopfmovdword[ss:PATM_INTERRUPTFLAG],1DB0xE9PATMJumpToGuest_IF1_Jump:DDPATM_JUMPDELTAPATMJumpToGuest_IF1_End:ENDPROCPATMJumpToGuest_IF1;PatchrecordforcallinstructionsPATM_JUMPDELTA在补丁代码生成时会被提换为虚拟机中被打补丁的下一条
6、指令以PATM开头的标签都会在补丁代码生成时被替换成相应的地址或变量的值全局定义类:VBoxGlobal.h1,虚拟化分类:一,基于软件虚拟化:1,解释执行;2,扫描与修补技术3,BT技术qemu,vmware二,硬件辅助虚拟化,三,类/泛/半虚拟化(xen)Ring0—ring3技术;Vm.cppGmm--GlobalMemoryManager,ring-3requestwrappers.Em.cpp:EM-ExecutionMonitor/Manager.staticintemR3RemExe
7、cute(PVMpVM,PVMCPUpVCpu,bool*pfFFDone){Executesrecompiledcode.Thisfunctioncontainstherecompilerversionoftheinner*executionloop(theouterloopbeinginEMR3ExecuteVM()).*ExecuteVM.*ThisfunctionisthemainloopoftheVM.Theemulationthread*callsthisfunctionwhenthe
8、VMhasbeensuccessfullyconstructed*andwe'rereadyforexecutingtheVM.**ReturningfromthisfunctionmeansthattheVMisturnedoffor*suspended(statealreadysaved)anddeconstructioninnextinline.VMMR3DECL(int)EMR3ExecuteVM(PVMpVM,PVMCPUpVCpu){…………………………VMEmt.cp