skysea_csn
驱动牛犊
驱动牛犊
  • 注册日期2002-08-16
  • 最后登录2007-04-05
  • 粉丝0
  • 关注0
  • 积分30分
  • 威望3点
  • 贡献值0点
  • 好评度3点
  • 原创分0分
  • 专家分0分
阅读:1527回复:6

请问为什么会死机?

楼主#
更多 发布于:2002-11-24 21:57
2000下的filter driver:

我在IRP_MJ_CREAT 中用 ZwCreate创建一个临时文件
ZwCreateFile( &hfile, GENERIC_READ | GENERIC_WRITE | FILE_APPEND_DATA | DELETE | SYNCHRONIZE, &oa, &iostatus, NULL, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ, FILE_OVERWRITE_IF,FILE_WRITE_THROUGH | FILE_SYNCHRONOUS_IO_NONALERT | FILE_CREATE_FOR_APCFILTER ,NULL, 0 );

系统就当机了?为什么?
请多指教!
Coolice
驱动小牛
驱动小牛
  • 注册日期2002-11-13
  • 最后登录2003-08-22
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2002-11-25 13:36
CreateOptions改成
FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE
试试
Tom_lyd
驱动大牛
驱动大牛
  • 注册日期2001-09-02
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分10分
  • 威望1点
  • 贡献值0点
  • 好评度1点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2002-11-30 13:28
2000下的filter driver:

我在IRP_MJ_CREAT 中用 ZwCreate创建一个临时文件
ZwCreateFile( &hfile, GENERIC_READ | GENERIC_WRITE | FILE_APPEND_DATA | DELETE | SYNCHRONIZE, &oa, &iostatus, NULL, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ, FILE_OVERWRITE_IF,FILE_WRITE_THROUGH | FILE_SYNCHRONOUS_IO_NONALERT | FILE_CREATE_FOR_APCFILTER ,NULL, 0 );

系统就当机了?为什么?

从OSR上弄来的,仔细看看.
While processing an IRP_MJ_CREATE a filter may need to open the file with different attributes/rights, etc. This is often done by using a second call to ZwCreatefile. This then will generate a call back into the FSD filter. Thus, a common filter issue is being able to detect this reentrancy.

There are several ways of dealing with reentrancy during an IRP_MJ_CREATE operation, and the appropriate solution for your particular driver will depend upon the circumstances. In addition, there are a number of techniques that might work for a single file system filter driver, but that fail when used in a multi-filter environment.

For Windows XP and newer versions of Windows, the best mechanism for opening a file within the filter is to use IoCreateFileSpecifyDeviceObjectHint. A filter driver can call this function and specify a given device object. The IRP_MJ_CREATE that is built will be passed to the specified device object. This technique avoids reentrancy issues and is the best mechanism available for a filter to open a file.

For versions of Windows prior to Windows XP, this mechanism is not available. The best mechanism in this environment is to implement your own functional equivalent of IoCreateFileSpecifyDeviceObjectHint. This can be done by creating a second device object for each device you are filtering.

For example, suppose you decide to filter some given file system device object, FSDVolumeDeviceObject. You then create a device object MyFilterDeviceObject and attach it using IoAttachDeviceToDeviceStack (of course, in Windows XP you would use IoAttachDeviceToDeviceStackSafe instead). In addition, you create a second device object MyFilterShadowDeviceObject. This device object must be assigned a name (\"\\Device\\MyFilterDevice27\", for example). The name can be anything, but it must obviously be unique. In your device extension for your two device objects, you need to track this name, and you need to maintain pointers to the respective device objects (that is, the device extension for MyFilterShadowDeviceObject should point to MyFilterDeviceObject and the device object extension for MyFilterDeviceObject should point to MyFilterShadowDeviceObject). Don\'t forget to set the StackSize field of the device object correctly!)

Now, an IRP_MJ_CREATE request arrives in your filter, specifying MyFilterDeviceObject. To open the file without experiencing reentrancy problems, you call IoCreateFile (or ZwCreateFile). Since you must pass the name of the file being opened, you construct that by using both the name you gave MyFilterShadowDeviceObject and the name that is in the FileObject of the I/O stack Location (IoGetCurrentIrpStackLocation(Irp)->FileObject).

Since you are passing a name in that points to your second device object, the I/O Manager will build the IRP_MJ_CREATE and pass the resulting I/O request packet to your driver, but specifying MyFilterShadowDeviceObject.

In your IRP_MJ_CREATE dispatch handler you must detect that this is a \"shadow\" device object, rather than a typical filter device object. In this case, you should send the IRP_MJ_CREATE operation down to the device being filtered by MyFilterDeviceObject. Indeed, since you should not need to do any further processing, you can use IoSkipCurrentIrpStackLocation (rather than IoCopyCurrentIrpStackLocationToNext).

The original filter (where the IoCreateFile call was made) will receive back a file handle that can then be used for subsequent operations (using the Zw API routines).

Typically, filter drivers that attempt to use IoCreateFile or ZwCreateFile with the same file/device name as the original request experience reentrancy into their driver. A number of techniques for dealing with this have been tried in the past, but they exhibit various problems when combined with other filters. These include:

? Appending a \"special string\" to the end of the file name. This will not work when two filters using this technique are loaded onto the same system (since each one appends its \"special string\" onto the previous filter\'s \"special string\").
? Track thread identifiers to detect reentrancy. This technique fails when combined with a filter that utilizes a separate service for opening the file; filters sometimes must switch to a different thread context in order to eliminate stack overflow conditions.
? Building create IRPs within a filter. This technique does work properly, but is completely unsupported and quite difficult to implement correctly. Because of this, it is a fragile solution that should not be used given the availability of alternative mechanisms.
? Re-using the file object from the current IRP_MJ_CREATE. In this sequence, the filter allows the create operation to complete and then uses the file object subsequently. When done, the filter then sends a cleanup and close operation to the underlying file system. It then sends the original IRP_MJ_CREATE operation to the underlying FSD. There are several potential issues with this approach. First, in this technique the filter does not have a file handle for the file object and thus cannot use the Zw API calls. Second, the file object must be restored to its original state - otherwise, there are fields within it that are not set up properly. Third, because the file object has not yet been \"properly referenced\" the filter may find that the OS deletes the object because its reference count drops to zero during its use. Used carefully, this technique has been successful in the past.

Regardless of the technique used, the filter driver must be cognizant of the issues involving oplocks (and the FILE_COMPLETE_IF_OPLOCKED option). If an oplock break occurs during an IRP_MJ_CREATE, whether from an original application, or from a filter driver attempting to open the file, the filter must be able to handle it gracefully.

Finally, the filter must be aware of the fact that even though it is calling from kernel mode, the underlying FSD will continue to enforce sharing access against the file
Tom_lyd
Coolice
驱动小牛
驱动小牛
  • 注册日期2002-11-13
  • 最后登录2003-08-22
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地板#
发布于:2002-12-02 12:34
Create重入应该只会引起某个逻辑盘死锁,但不会引起整个系统死锁,更不会当机,所以问题可能还会在其它方面
paladinii
驱动中牛
驱动中牛
  • 注册日期2003-10-28
  • 最后登录2012-03-09
  • 粉丝0
  • 关注0
  • 积分282分
  • 威望74点
  • 贡献值0点
  • 好评度23点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2005-02-03 19:16
同意Coolice的说法,我也遇到过类似的问题。
Ideas for life!
tooflat
论坛版主
论坛版主
  • 注册日期2002-07-08
  • 最后登录2014-03-11
  • 粉丝2
  • 关注0
  • 积分1007分
  • 威望551点
  • 贡献值3点
  • 好评度476点
  • 原创分0分
  • 专家分0分
5楼#
发布于:2005-02-03 21:49
ZwCreateFile只能运行在passive_level,而DispatchCreate有可能运行在apc_level
paladinii
驱动中牛
驱动中牛
  • 注册日期2003-10-28
  • 最后登录2012-03-09
  • 粉丝0
  • 关注0
  • 积分282分
  • 威望74点
  • 贡献值0点
  • 好评度23点
  • 原创分0分
  • 专家分0分
6楼#
发布于:2005-02-04 18:43

ZwCreateFile只能运行在passive_level,而DispatchCreate有可能运行在apc_level

 

tooflat: 有没有好的解决办法?
Ideas for life!
游客

返回顶部