Execution Flow:
1. int main() in Frontends\VB\src\main.cpp (启动VirtualBox.exe和每个VM时都调用)
初始化VBox运行时(和)support library(RTR3Init()或RTR3InitAndSUPLib())
调用TrustedMain()
2. int RTR3Init() in src\VBox\Runtime\r3\init.cpp (实际工作由rtR3Init完成, 此时VM尚未启动)
全局变量g_cUsers(RTR3Init函数被调用次数)加1.[此全局变量只局限于VM之内, VB启动和VM启动时这个值初始都是0. 什么情况下这个值会变成大于1呢??]
获取环境变量"VBOX_DISABLE_HOST_DISK_CACHE"的值(windows为0, 无操作) [IN_GUEST, RT_NO_GIP not defined, VBOX, LOG_ENABLED defined.]
调用rtThreadInit()初始化线程数据库(in Runtime\common\misc\thread.cpp)[what's this?]
调用SUPR3Init()初始化支持库(如果fInitSUPLib为真)
记录程序启动时间
获取进程PID
调用rtR3InitProgramPath()验证可执行文件的目录和名字
初始化成功,返回.
3. int rtThreadInit() 初始化线程数据库
若在RING-3:
创建一个线程读写semaphore. (RTSemRWCreate())
调用rtThreadNativeInit() [调用PSDK:TlsAlloc(), The TlsAlloc function
allocates a thread local storage (TLS) index. Any thread of the process
can subsequently use this index to store and retrieve values that are
local to the thread, because each thread receives its own slot for the
index.]
调用rtThreadAdopt()通过(验证?)线程
调用rtSchedNativeCalcDefaultPriority检查线程的优先级是否正确
返回成功
若在RING-0:
创建一个spin-lock并调用rtThreadNativeInit()[空操作NT]
4. int rtThreadAdopt() in Runtime\common\misc\thread.cpp
调用rtThreadAlloc分配一个per-线程数据结构并初始化基本的域
调用rtThreadNativeAdopt(){in Runtime\r3\win\thread-win.cpp}
进而调用TlsSetValue(The TlsSetValue function stores a value in the calling
thread's thread local storage (TLS) slot for the specified TLS index.
Each thread of a process has its own slot for each TLS index.) 为线程的TLS
index赋值
调用rtThreadInsert()将per线程数据结构插入树(AVL树)中
1. int TrustedMain() in Frontends\VB\src\main.cpp
调用COMBase::InitializeCOM()初始化COM(windows only)
生成一个QIApplication对象
调用PlaySound以加载声音驱动和dll以防止cpu高利用率时的延迟(windows only)
调用VBoxGlobal::loadLanguage()加载语言
调用checkForAutoConvertedSettings()检查配置文件是否被改动并通知用户
调用startMachine启动VM
调用QApplication::exec()进入事件循环
1. bool VBoxGlobal::startMachine() in src\VBox\Frontends\VirtualBox\src\VBoxGlobal.cpp
调用VBoxConsoleWnd::openView()
1.
bool VBoxConsoleWnd::openView() in
src\VBox\Frontends\VirtualBox\src\VBoxConsoleWnd.cpp [Opens a new
console view to interact with a given VM. Does nothing if the console
view is already opened. Used by VBoxGlobal::startMachine(), should not
be called directly.]
1. void VBoxConsoleWnd::finalizeOpenView() in src\VBox\Frontends\VirtualBox\src\VBoxConsoleWnd.cpp
如果是首次启动VM, 启动FirstRunWzd; 否则
调用CConsole.PowerUp()启动VM
显示"VM starting/ restoring"进度条
全屏模式及无缝模式检查
1. STDMETHODIMP Console::PowerUp (IProgress **aProgress) in src\VBox\Main\ConsoleImpl.cpp
检查COM是否正确注册
检查虚拟机是否正在运行
检查磁盘是否可用
检查是否加载有ISO文件
检查软驱
网卡一致性检查
Console::loadDataFromSavedState()从已保存的状态文件中恢复VM(未保存则为空操作)
检查所有共享文件夹并组成一个单链表
检查Saved file是否正确(如果存在已保存的状态文件)
生成一个IProgress对象来跟踪对此VM的操作
生成一个VMPowerUpTask对象(并设置部分域)和IProgress对象同步执行
调用consoleInitReleaseLog()生成日志文件
调用RTThreadCreate生成一个函数为Console::powerUpThread()的线程,接管VMPowerUpTask对象的工作
释放VMPowerUpTask对象
调用setMachineState()设置VM的状态为Restore或者Restart.(进而调用OnStateChange(), 引发对回调函数VBoxConsoleCallback::OnStateChange的调用)
2. 开始执行Console::powerUpThread() (Thread function which starts the VM (also from saved state) and track progress)
调用CoInitializeEx初始化COM(windows only)
调用VMR3Create()生成VM(log至2624行)
调用SSMR3RegisterExternal()注册load/save state file handlers(saveStateFileExec和loadStateFileExec)
同步debugger设置
根据共享文件夹链表生成共享文件夹(console->createSharedFolder())
捕获USB设备(console->captureUSBDevice())
加载saved state(VMR3Load()-VMR3Resume())或者启动VM(VMR3PowerOn())
调用CoUninitialize()注销COM
返回成功
class VBoxGlobal : public QObject
public:
static VBoxGlobal& instance(): 返回全局VB数据
阅读(7668) | 评论(1) | 转发(0) |