superwangliwen
驱动小牛
驱动小牛
  • 注册日期2002-07-30
  • 最后登录2005-01-10
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1930回复:10

WriteFile和ReadFile会不会造成蓝屏死机?

楼主#
更多 发布于:2002-10-28 18:12
如题!
Just remember my name : wing
superwangliwen
驱动小牛
驱动小牛
  • 注册日期2002-07-30
  • 最后登录2005-01-10
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2002-10-31 10:59
偶换了2.7,没问题了!呵呵~~
Just remember my name : wing
rayyang2000
管理员
管理员
  • 注册日期2001-03-23
  • 最后登录2012-09-13
  • 粉丝3
  • 关注0
  • 积分1036分
  • 威望925点
  • 贡献值3点
  • 好评度823点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2002-10-29 16:15
哈哈!那个就是BULK的bug!
天天coding-debugging中----超稀饭memory dump file ======================================================== [b]Windows Device Driver Development and Consulting Service[/b] [color=blue][url]http://www.ybwork.com[/url][/color] ========================================================
bunnyh
驱动牛犊
驱动牛犊
  • 注册日期2002-04-25
  • 最后登录2005-09-03
  • 粉丝1
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地板#
发布于:2002-10-29 14:09
WIN2K 下我也有同样的问题!!!
DS2.6 生成的代码, 每有任何修改, 只要读写就蓝屏 :(
我换成WinDriver4.33 直接访问USB设备, 出现同样问题.
又尝试装了一个USB到串口转换器的驱动, 同样有问题.

最后, 换了一台机器,重装WIN2K (Service Pack 2). WinDriver4.33 OK,USB到串口转换器的驱动 OK. DS2.6 还没有试
superwangliwen
驱动小牛
驱动小牛
  • 注册日期2002-07-30
  • 最后登录2005-01-10
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2002-10-29 13:47
是:
Just remember my name : wing
rayyang2000
管理员
管理员
  • 注册日期2001-03-23
  • 最后登录2012-09-13
  • 粉丝3
  • 关注0
  • 积分1036分
  • 威望925点
  • 贡献值3点
  • 好评度823点
  • 原创分0分
  • 专家分0分
5楼#
发布于:2002-10-29 11:31
DS2.5和2.6有bug,你按照peitai的帖子修改了吗?
天天coding-debugging中----超稀饭memory dump file ======================================================== [b]Windows Device Driver Development and Consulting Service[/b] [color=blue][url]http://www.ybwork.com[/url][/color] ========================================================
superwangliwen
驱动小牛
驱动小牛
  • 注册日期2002-07-30
  • 最后登录2005-01-10
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
6楼#
发布于:2002-10-29 10:23
帮忙帮忙啊,偶出高分啊!绝对高分啊!
Just remember my name : wing
superwangliwen
驱动小牛
驱动小牛
  • 注册日期2002-07-30
  • 最后登录2005-01-10
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
7楼#
发布于:2002-10-29 08:28
上面是读写的源程序 我该改哪些啊 ??
Just remember my name : wing
superwangliwen
驱动小牛
驱动小牛
  • 注册日期2002-07-30
  • 最后登录2005-01-10
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
8楼#
发布于:2002-10-29 08:25
////////////////////////////////////////////////////////////////////////
//  FinallyDevice::Read
//
// Routine Description:
// Handler for IRP_MJ_READ
//
// Parameters:
// I Current IRP
//
// Return Value:
// NTSTATUS Result code
//
// Comments:
// This routine handles read requests.
//
// The KPnpDevice class handles restricting IRP flow
// if the device is stopping or being removed.
//

NTSTATUS FinallyDevice::Read(KIrp I)
{
t << \"Entering FinallyDevice::Read, \" << I << EOL;
// TODO: Check the incoming request.  Replace \"FALSE\" in the following
// line with a check that returns TRUE if the request is not valid.

    if (FALSE) // If (Request is invalid)
{
// Invalid parameter in the Read request
I.Information() = 0;
return I.PnpComplete(this, STATUS_INVALID_PARAMETER);
}

// Always ok to read 0 elements.
if (I.ReadSize() == 0)
{
I.Information() = 0;
return I.PnpComplete(this, STATUS_SUCCESS);
}

// Declare a memory object
KMemory Mem(I.Mdl());

    ULONG dwTotalSize = I.ReadSize(CURRENT);
ULONG dwMaxSize = requestpipe.MaximumTransferSize();

// If the total requested read size is greater than the Maximum Transfer
// Size for the Pipe, request to read only the Maximum Transfer Size since
// the bus driver will fail an URB with a TransferBufferLength of greater
// than the Maximum Transfer Size.
if (dwTotalSize > dwMaxSize)
{
ASSERT(dwMaxSize);
dwTotalSize = dwMaxSize;
}

// Allocate a new context structure for Irp completion
USB_COMPLETION_INFO* pCompInfo = new (NonPagedPool) USB_COMPLETION_INFO;
if (pCompInfo == NULL)
{
I.Information() = 0;
return I.PnpComplete(this, STATUS_INSUFFICIENT_RESOURCES);
}

// TODO: Select the correct pipe to read from

// Create an URB to do actual Bulk read from the pipe
PURB pUrb = requestpipe.BuildBulkTransfer(
    Mem,       // Where is data coming from?
dwTotalSize,   // How much data to read?
TRUE,         // direction (TRUE = IN)
NULL, // Link to next URB
TRUE // Allow a short transfer
);        

if (pUrb == NULL)
{
delete pCompInfo;
I.Information() = 0;
return I.PnpComplete(this, STATUS_INSUFFICIENT_RESOURCES);
}

// Initialize context structure
pCompInfo->m_pClass = this;
pCompInfo->m_pUrb = pUrb;

    // Submit the URB to our USB device
NTSTATUS status;
status = requestpipe.SubmitUrb(I, pUrb, LinkTo(ReadComplete), pCompInfo, 0);
return status;
}

////////////////////////////////////////////////////////////////////////
//  FinallyDevice::ReadComplete
//
// Routine Description:
// Completion Handler for IRP_MJ_READ
//
// Parameters:
// I - IRP just completed by USB
// pContext - Context structure containing pointer to Urb
//
// Parameters:
// NTSTATUS - STATUS_SUCCESS
//
// Comments:
// This routine is called when USBD completes the read request
//

NTSTATUS FinallyDevice::ReadComplete(KIrp I, USB_COMPLETION_INFO* pContext)
{
// Normal completion routine code to propagate pending flag

if (I->PendingReturned)
{
I.MarkPending();
}

NTSTATUS status = I.Status();
PURB pUrb = pContext->m_pUrb;
ULONG nBytesRead = 0;

if ( NT_SUCCESS(status) )
{
nBytesRead = pUrb->UrbBulkOrInterruptTransfer.TransferBufferLength;
if (nBytesRead > 0)
t << \"Read() got \" << nBytesRead<< \" bytes from USB\\n\";
    }

// Deallocate Urb and context structure
delete pUrb;
delete pContext;

// set returned count
I.Information() = nBytesRead;

// Plug and Play accounting
DecrementOutstandingRequestCount();

// allow IRP completion processing
return STATUS_SUCCESS;
}

////////////////////////////////////////////////////////////////////////
//  FinallyDevice::Write
//
// Routine Description:
// Handler for IRP_MJ_WRITE
//
// Parameters:
// I - Current IRP
//
// Return Value:
// NTSTATUS - Result code
//
// Comments:
// This routine handles write requests.
//
// The KPnpDevice class handles restricting IRP flow
// if the device is stopping or being removed.
//

NTSTATUS FinallyDevice::Write(KIrp I)
{
t << \"Entering FinallyDevice::Write, \" << I << EOL;
// TODO: Check the incoming request.  Replace \"FALSE\" in the following
// line with a check that returns TRUE if the request is not valid.
    if (FALSE)
{
// Invalid parameter in the Write request
I.Information() = 0;
return I.PnpComplete(this, STATUS_INVALID_PARAMETER);
}

// Always ok to write 0 elements.
if (I.WriteSize() == 0)
{
I.Information() = 0;
return I.PnpComplete(this, STATUS_SUCCESS);
}
ULONG dwTotalSize = I.WriteSize(CURRENT);
ULONG dwMaxSize = requestpipe.MaximumTransferSize();

// If the total requested read size is greater than the Maximum Transfer
// Size for the Pipe, request to read only the Maximum Transfer Size since
// the bus driver will fail an URB with a TransferBufferLength of greater
// than the Maximum Transfer Size.
if (dwTotalSize > dwMaxSize)
{
ASSERT(dwMaxSize);
dwTotalSize = dwMaxSize;
}

// Declare a memory object
KMemory Mem(I.Mdl());

// Allocate a new context structure for Irp completion
USB_COMPLETION_INFO* pCompInfo = new (NonPagedPool) USB_COMPLETION_INFO;
if (pCompInfo == NULL)
{
I.Information() = 0;
return I.PnpComplete(this, STATUS_INSUFFICIENT_RESOURCES);
}

// TODO: Select the correct pipe to write to

// Create an URB to do actual Bulk write to the pipe
PURB pUrb = requestpipe.BuildBulkTransfer(
Mem,          // Where is data coming from?
dwTotalSize,  // How much data to read?
FALSE,        // direction (FALSE = OUT)
NULL  // Link to next URB
);        

if (pUrb == NULL)
{
delete pCompInfo;
I.Information() = 0;
return I.PnpComplete(this, STATUS_INSUFFICIENT_RESOURCES);
}

// Initialize context structure
pCompInfo->m_pClass = this;
pCompInfo->m_pUrb = pUrb;

    // Submit the URB to our USB device
NTSTATUS status;
status = requestpipe.SubmitUrb(I, pUrb, LinkTo(WriteComplete), pCompInfo, 0);
return status;
}

////////////////////////////////////////////////////////////////////////
//  FinallyDevice::WriteComplete
//
// Routine Description:
// Completion Handler for IRP_MJ_WRITE
//
// Parameters:
// I - IRP just completed by USB
// pContext - Context structure containing pointer to Urb
//
// Return Value:
// NTSTATUS STATUS_SUCCESS
//
// Comments:
// This routine is called when USBD completes the write request
//

NTSTATUS FinallyDevice::WriteComplete(KIrp I, USB_COMPLETION_INFO* pContext)
{
// Normal completion routine code to propagate pending flag

if (I->PendingReturned)
{
I.MarkPending();
}

NTSTATUS status = I.Status();
PURB pUrb = pContext->m_pUrb;
ULONG nBytesWritten = 0;

if ( NT_SUCCESS(status) )
{
nBytesWritten = pUrb->UrbBulkOrInterruptTransfer.TransferBufferLength;
if (nBytesWritten > 0)
t << \"Wrote \" << nBytesWritten << \" bytes to USB\\n\";
    }

// Deallocate Urb and context structure
delete pUrb;
delete pContext;

// set returned count
I.Information() = nBytesWritten;

// Plug and Play accounting
DecrementOutstandingRequestCount();

// allow IRP completion processing
return STATUS_SUCCESS;
}

Just remember my name : wing
superwangliwen
驱动小牛
驱动小牛
  • 注册日期2002-07-30
  • 最后登录2005-01-10
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
9楼#
发布于:2002-10-29 08:22
我的驱动是用DS2.6做的,做了一些修改。但也没有改Read和Write部分 我该怎么改啊?大哥教我~~
Just remember my name : wing
LIUTANG
驱动大牛
驱动大牛
  • 注册日期2001-03-30
  • 最后登录2020-12-27
  • 粉丝0
  • 关注0
  • 积分8分
  • 威望58点
  • 贡献值0点
  • 好评度12点
  • 原创分0分
  • 专家分0分
  • 社区居民
10楼#
发布于:2002-10-28 21:24
ReadFile和WriteFile本身不会造成蓝屏,造成蓝屏的原因是你的驱动程序的Read或Write例程(就是IRP_MJ_READ和IRP_MJ_WRITE对应的部分)有问题,你仔细检查一下这两个函数里有没有非法的地方。
游客

返回顶部