⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vxd-e4.html

📁 汇编语言编写的虚拟驱动程序
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
   <meta name="Author" content="Iczelion">
   <meta name="GENERATOR" content="Mozilla/4.7 [en] (Win98; I) [Netscape]">
   <title>Virtual Device Driver Programming: Primer</title>
</head>
<body text="#FFFFFF" bgcolor="#000080" link="#FFFF00" vlink="#8080FF" alink="#FF00FF">

<center>
<h1>
<font face="Arial,Helvetica"><font color="#FFFF99">VxD Programming: Primer</font></font></h1></center>
<font face="Arial,Helvetica"><font size=-1>We know how to build a VxD which
does nothing. In this tutorial, we will make it more productive by adding
control message handlers.</font></font>
<h3>
<font face="Arial,Helvetica"><font color="#66FFFF"><font size=+0>VxD Initialization
and Termination</font></font></font></h3>
<font face="Arial,Helvetica"><font size=-1>There are two types of VxD:
static and dynamic. Each type has different load method. They also receive
different initialization and termination control messages.</font></font>
<h3>
<font face="Arial,Helvetica"><font color="#FFCC33"><font size=-1>Static
VxD:</font></font></font></h3>
<font face="Arial,Helvetica"><font size=-1>VMM loads a static VxD when:</font></font>
<ul>
<li>
<font face="Arial,Helvetica"><font size=-1>A real-mode resident programs
issue int 2Fh, 1605h to load it</font></font></li>

<li>
<font face="Arial,Helvetica"><font size=-1>The VxD is specified in the
registry under the key:</font></font></li>
</ul>

<ul>
<ul><b><font face="Arial,Helvetica"><font size=-1><font color="#FFFF99">HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\</font><font color="#66FF99">key</font><font color="#FFFF99">\StaticVxD=pathname</font></font></font></b></ul>
</ul>

<ul>
<li>
<font face="Arial,Helvetica"><font size=-1><font color="#FFFFFF">The VxD
is specified in system.ini under </font><b><font color="#FFFF99">[386enh]</font></b><font color="#FFFFFF">
section:</font></font></font></li>

<ul>&nbsp;
<br><b><font face="Arial,Helvetica"><font color="#FFFF99"><font size=-1>device=pathname</font></font></font></b></ul>
</ul>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>During
development period, I suggest you load the VxD from system.ini because
if something goes wrong with your VxD to the extent that Windows cannot
start, you can edit system.ini from DOS. You can't do that with the registry
loading method.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>When
the VMM loads your static VxD, your VxD will receive three system control
messages in the following order:</font></font></font>
<ul>
<li>
<font face="Arial,Helvetica"><font size=-1><b><font color="#FFFF99">Sys_Critical_Init</font></b><font color="#FFFFFF">&nbsp;
VMM sends this control message after switching into protected mode but
before enabling interrupts. Most VxDs don't need to handle this message
except when:</font></font></font></li>

<ul>
<li>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>Your VxD
hooks some interrupts that will be called later by other VxDs or protected
mode programs. Since the interrupts are disabled when you process this
control message, you can be sure that the interrupts you're hooking won't
be called during the time you're hooking them.</font></font></font></li>

<li>
<font face="Arial,Helvetica"><font size=-1><font color="#FFFFFF">Your VxD
provides some VxD services that will be called during initialization by
other VxDs. For example, some VxD that loads after your VxD may need to
call one of your VxD's services during </font><b><font color="#FFFF99">Device_Init</font></b><font color="#FFFFFF">
control message processing. Since </font><b><font color="#FFFF99">Sys_Critical_Init
</font></b><font color="#FFFFFF">message is sent before </font><b><font color="#FFFF99">Device_Init</font></b><font color="#FFFFFF">
message, you must initialize your services during </font><b><font color="#FFFF99">Sys_Critical_Init</font></b><font color="#FFFFFF">
message.</font></font></font></li>
</ul>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>If you
process this message, you should do your initialization as quickly as possible
to prevent hardware interrupt losses due to excessive latency. (Remember:
the interrupts are disabled)</font></font></font>
<li>
<font face="Arial,Helvetica"><font size=-1><b><font color="#FFFF99">Device_Init
</font></b><font color="#FFFFFF">VMM
sends this control message after the interrupts are enabled. Most VxDs
perform initialization in response to this message. Because the interrupts
are enabled, time-consuming operations can be done without the fear of
losing hardware interrupts. You should do your initialization here (if
needed).</font></font></font></li>

<li>
<font face="Arial,Helvetica"><font size=-1><b><font color="#FFFF99">Init_Complete</font></b><font color="#FFFFFF">
After all VxDs processed </font><b><font color="#FFFF99">Device_Init </font></b><font color="#FFFFFF">message
but before the VMM releases all initialization segments (ICODE and RCODE
segment classes), the VMM sends this control message. Few VxDs need to
process this message.</font></font></font></li>
</ul>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>Your VxD
<b>must</b> clear the carry flag if the initialization is successful else
you must set the carry flag in case of error before returning. You don't
have to process any of the three initialization messages if your VxD doesn't
need any initialization.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>When
it's time to terminate the static VxD, the VMM sends the following control
messages:</font></font></font>
<ul>
<li>
<font face="Arial,Helvetica"><font size=-1><b><font color="#FFFF99">System_Exit2</font></b><font color="#FFFFFF">&nbsp;
When your VxD receives this message, Windows 95 is about to shut down.
All other VMs except the system VM are already destroyed. However the CPU
is still in protected mode and it's still safe to execute real-mode code
in the system VM. Kernel32.dll was already unloaded by this time.</font></font></font></li>

<li>
<font face="Arial,Helvetica"><font size=-1><b><font color="#FFFF99">Sys_Critical_Exit2</font></b><font color="#FFFFFF">&nbsp;
Your VxD receives this message when all VxDs have processed System_Exit2
and the interrupts are disabled.</font></font></font></li>
</ul>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>Most VxDs
don't need to process those two messages, except when you want to prepare
the system to enter real mode. You should know that when Windows 95 shuts
down, it enters real mode. So if your VxD did something to the real-mode
image that will make it unstable, it should restore the change during this
time.</font></font></font>
<br><font face="Arial,Helvetica"><font size=-1><font color="#FFFFFF">You
may wonder why those two exit messages have "</font><b><font color="#FFFF99">2</font></b><font color="#FFFFFF">"
appended to them.Remember that when the VMM loads the static VxDs, it loads
the VxDs with the lower initialization order first so that the VxDs can
rely upon services of the VxDs that load before them. For example, if VxD2
relies on the services of VxD1, it must specify its initialization order
to be larger than that of VxD1. The load order would be:</font></font></font>
<blockquote><b><font face="Arial,Helvetica"><font color="#66FF99"><font size=-1>.....
VxD1 ===>&nbsp; VxD2 ===> VxD3 .....</font></font></font></b></blockquote>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>Now during
unloading, it stands to reason that the VxDs that initialize later should
uninitialize first so that they may still call VxD services of the VxDs
that were loaded before them. In the above example, the order should be:</font></font></font>
<blockquote><b><font face="Arial,Helvetica"><font color="#66FF99"><font size=-1>....
VxD3 ===> VxD2 ===> VxD1.....</font></font></font></b></blockquote>
<font face="Arial,Helvetica"><font size=-1><font color="#FFFFFF">In the
above example, if VxD2 called some VxD1's services during initialization,
it may need to rely on VxD1's services again during unloading. </font><b><font color="#FFFF99">System_Exit2</font></b><font color="#FFFFFF">
and </font><b><font color="#FFFF99">Sys_Critical_Exit2</font></b><font color="#FFFFFF">
are sent in </font><b><font color="#66FFFF">reverse initialization order</font></b><font color="#FFFFFF">.
It means that, when VxD2 receives those messages, VxD1 hasn't done uninitialization
yet and it can still call VxD1's services. </font><b><font color="#FFFF99">System_Exit</font></b><font color="#FFFFFF">
and </font><b><font color="#FFFF99">Sys_Critical_Exit</font></b><font color="#FFFFFF">
messages are not sent in reverse initialization order. It means that when
you process those two messages, you can't be sure that you can still call
VxD's services of the VxDs that were loaded before you. Those messages
should not be used for newer VxDs.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>There
are two more exit messages:</font></font></font>
<ul>
<li>
<font face="Arial,Helvetica"><font size=-1><b><font color="#FFFF99">Device_Reboot_Notify2</font></b><font color="#FFFFFF">&nbsp;
Notifies the VxD that the VMM is going to restart the system. The interupts
are still enabled during this time.</font></font></font></li>

<li>
<font face="Arial,Helvetica"><font size=-1><b><font color="#FFFF99">Crit_Reboot_Notify2</font></b><font color="#FFFFFF">&nbsp;
Notifies the VxD that the VMM is going to restart the system. The interrupts
are disabled.</font></font></font></li>
</ul>
<font face="Arial,Helvetica"><font size=-1><font color="#FFFFFF">By now,
you should be able to guess that there are </font><b><font color="#FFFF99">Device_Reboot_Notify</font></b><font color="#FFFFFF">
and </font><b><font color="#FFFF99">Crit_Reboot_Notify </font></b><font color="#FFFFFF">messages
but they are not sent in reverse initialization order as the "2" version.</font></font></font>
<h3>
<font face="Arial,Helvetica"><font color="#FFCC33"><font size=-1>Dynamic
VxD:</font></font></font></h3>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>Dynamic
VxDs can be dynamically loaded and unloaded during Windows 9x sessions.
This feature is not available under Windows 3.x. The primary goal of dynamic
VxDs is to support dynamic hardware reconfiguration such as Plug and Play
devices. However, you can load/unload them from your win32 applications
as well, making them ideal as your applications' ring-0 extension.</font></font></font>
<br><font face="Arial,Helvetica"><font size=-1><font color="#FFFFFF">The
example in the previous tutorial is a static VxD. You can convert the example
into a dynamic VxD by adding the keyword </font><b><font color="#FFFF99">DYNAMIC</font></b><font color="#FFFFFF">
to the</font><b><font color="#FFFF99"> VXD</font></b><font color="#FFFFFF">
statement in .DEF file.</font></font></font>
<blockquote><b><font face="Arial,Helvetica"><font color="#FFFF99"><font size=-1>VXD&nbsp;&nbsp;
FIRSTVXD&nbsp;&nbsp; DYNAMIC</font></font></font></b></blockquote>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>That's
all you have to do to convert a static VxD into a dynamic one.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>Dynamic
VxD can be loaded by:</font></font></font>
<ul>
<li>
<font face="Arial,Helvetica"><font size=-1><font color="#FFFFFF">Putting
it in </font><b><font color="#FFFF99">\SYSTEM\IOSUBSYS</font></b><font color="#FFFFFF">
folder in your Windows folder. The VxDs in this folder will be loaded by
</font><b><font color="#FFFF99">Input
Output Supervisor (IOS)</font></b><font color="#FFFFFF">. The VxDs in this
folder should support layer device drivers so it may not be a good idea
to load your dynamic VxD this way.</font></font></font></li>

<li>
<font face="Arial,Helvetica"><font size=-1><font color="#FFFFFF">Using
VxD Loader service.<b> </b></font><b><font color="#FFFF99">VxDLDR</font></b><font color="#FFFFFF">
is a static VxD that can load dynamic VxDs. You can call its services from
other VxDs or from 16-bit code.</font></font></font></li>

<li>
<font face="Arial,Helvetica"><font size=-1><font color="#FFFFFF">Using
</font><b><font color="#FFFF99">CreateFile</font></b><font color="#FFFFFF">
API from a Win32 application. You specify the dynamic VxD you want to load
to CreateFile in the format below:</font></font></font></li>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -