10-13-2008 07:37 AM
Hello NI developers!
In my DLL there is a following code block:
for (i = 0; i < 10; i++)
{
if (fIsRead)
((UINT32 *)(pDma->pBuf))[i] = i;
else
((UINT32 *)(pDma->pBuf))[i] = 0xdeadbeaf; /* to be overwritten by WRITE dma */
}
Which causes reboot of PC.
By thinking that I haven't allocated memory for this array - I even substituted this loop by this string:
((UINT32 *)(pDma->pBuf))[0] = 0;
The same result - PC reboots.
Could you explain possible reasons why this might happen ?
Best Regards,
ACiDuser
10-13-2008 07:47 AM
Hi there
please post the complete C-Code, especially the variable declarations.
10-13-2008 09:43 AM
The code block, where PC reboots is highlighted by comment " /****** THIS STRING, where PC REBOOTS ******/ "
Code is attached below.
Thanks in advance.
10-13-2008 09:55 AM
Sorry, i can't find the definition of PDIAG_DMA.
How to you allocate the memory for PDIAG_DMA pDma in MenuDMAOpen ?
10-14-2008 12:55 AM
PDIAG_DMA is defined in test.h
//============= test.h ===============
typedef struct {
VIRTEX5_DMA_HANDLE hDma;
PVOID pBuf;
} DIAG_DMA, *PDIAG_DMA;
//=================================
pDma defined in virtex5_lib.h
//=========== virtex5_lib.h ====================
typedef struct {
WD_DMA *pDma;
WDC_DEVICE_HANDLE hDev;
} VIRTEX5_DMA_STRUCT, *VIRTEX5_DMA_HANDLE;
//========================================
as I understand memory allocates in one of the source files (wdc_dma.c)
//====================== wdc_dma.c =============================
static DWORD DMABufLock(PWDC_DEVICE pDev, PVOID *ppBuf,
DWORD dwOptions, DWORD dwDMABufSize, WD_DMA **ppDma)
{
DWORD dwStatus;
WD_DMA *pDma;
DWORD dwPagesNeeded = 0, dwAllocSize;
BOOL fSG;
if (!WdcIsValidPtr(ppDma, "NULL address of DMA struct pointer") ||
!WdcIsValidPtr(ppBuf, "NULL address of DMA buffer pointer"))
{
return WD_INVALID_PARAMETER;
}
fSG = !(dwOptions & DMA_KERNEL_BUFFER_ALLOC);
dwAllocSize = sizeof(WD_DMA);
if (fSG)
{
/*
* Since the first and last page do not necessarily start (or end) on a
* PAGE_SIZE boundary, add 1 page to support the worst case scenario
*/
dwPagesNeeded = ((dwDMABufSize + GetPageSize() - 1)/GetPageSize()) + 1;
if (WD_DMA_PAGES < dwPagesNeeded)
{
dwAllocSize += ((DWORD)sizeof(WD_DMA_PAGE) * (dwPagesNeeded -
WD_DMA_PAGES));
dwOptions |= DMA_LARGE_BUFFER;
}
}
pDma = (WD_DMA*)malloc(dwAllocSize);
if (!pDma)
{
WdcSetLastErrStr("Failed allocating memory for a DMA struct\n");
return WD_INSUFFICIENT_RESOURCES;
}
memset(pDma, 0, dwAllocSize);
pDma->dwBytes = dwDMABufSize;
pDma->dwOptions = dwOptions;
pDma->hCard = pDev ? WDC_GET_CARD_HANDLE(pDev) : 0;
if (fSG)
{
pDma->pUserAddr = *ppBuf;
if (dwOptions & DMA_LARGE_BUFFER)
pDma->dwPages = dwPagesNeeded;
}
dwStatus = WD_DMALock(WDC_GetWDHandle(), pDma);
if (WD_STATUS_SUCCESS != dwStatus)
{
free(pDma);
WdcSetLastErrStr("Error 0x%lx - %s\n", dwStatus, Stat2Str(dwStatus));
return dwStatus;
}
/* If a contiguous kernel buffer was locked, update buffer */
if (!fSG)
*ppBuf = pDma->pUserAddr;
*ppDma = pDma;
return WD_STATUS_SUCCESS;
}
//============================================================