rep_movsd
2005-03-29 21:41:36 UTC
Hi
I am writing a WDM capture driver, which simulates a webcam.
It has to render frames given it by a user mode app which is reading
from a file.
I assumed the best way to pass the frames would be through shared
memory, However, I just cant get it to work...
Heres the relevant code (much of it copied from the testcap sample)
#define SEC_COMMIT 0x08000000
NTSYSAPI NTSTATUS
ZwCreateSection(
OUT PHANDLE SectionHandle,
IN ACCESS_MASK DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes
OPTIONAL,
IN PLARGE_INTEGER MaximumSize
OPTIONAL,
IN ULONG SectionPageProtection,
IN ULONG AllocationAttributes,
IN HANDLE FileHandle OPTIONAL
);
WCHAR const SectionNameConst[] = L"\\BaseNamedObjects\\VCamBuffah";
UNICODE_STRING SectionName;
LARGE_INTEGER SecSize;
ULONG ViewSize = 262144;
struct _OBJECT_ATTRIBUTES oa;
BOOLEAN STREAMAPI HwInitialize (IN OUT PHW_STREAM_REQUEST_BLOCK pSrb)
{
STREAM_PHYSICAL_ADDRESS adr;
ULONG Size;
PUCHAR pDmaBuf;
int j;
PPORT_CONFIGURATION_INFORMATION ConfigInfo =
pSrb->CommandData.ConfigInfo;
PHW_DEVICE_EXTENSION pHwDevExt =
(PHW_DEVICE_EXTENSION)ConfigInfo->HwDeviceExtension;
SecSize.QuadPart = ViewSize;
SectionName.Buffer = (PWSTR)&SectionNameConst;
SectionName.Length = wcslen(SectionNameConst) * sizeof(WCHAR);
SectionName.MaximumLength = SectionName.Length + sizeof(WCHAR);
InitializeObjectAttributes(&oa, &SectionName, OBJ_CASE_INSENSITIVE
, NULL, NULL);
pHwDevExt->status = ZwCreateSection( &pHwDevExt->hMap,
SECTION_ALL_ACCESS, &oa, &SecSize, PAGE_READWRITE, SEC_COMMIT, 0);
//ViewSize = 0;
pHwDevExt->pBuf = 0;
if(pHwDevExt->hMap != 0)
{
pHwDevExt->status = ZwMapViewOfSection( pHwDevExt->hMap,
(HANDLE)-1 ,&pHwDevExt->pBuf, 0L, 262144, NULL, &ViewSize, 1, 0,
PAGE_READONLY );
}
AdapterSetInstance (pSrb);
pSrb->Status = STATUS_SUCCESS;
return TRUE;
}
It always reports that the 9th parameter is invalid.
At my wits end, I tried another experiment, I wrote an app to map
memory and stepped through the call for MapViewOfFile, when it
eventually calls ZwMapViewOfSection, the stack has 1, 0 and 2 as the
last 3 parameters to it.
This is weird, because in my app i specify PAGE_READWRITE which is 4,
but it goes to the kernel api as 2!!
Can anyone test this out and give me a solution?
Im so desperate, i am thinking I might have to use a regular file or
named pipe to share data.
I am writing a WDM capture driver, which simulates a webcam.
It has to render frames given it by a user mode app which is reading
from a file.
I assumed the best way to pass the frames would be through shared
memory, However, I just cant get it to work...
Heres the relevant code (much of it copied from the testcap sample)
#define SEC_COMMIT 0x08000000
NTSYSAPI NTSTATUS
ZwCreateSection(
OUT PHANDLE SectionHandle,
IN ACCESS_MASK DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes
OPTIONAL,
IN PLARGE_INTEGER MaximumSize
OPTIONAL,
IN ULONG SectionPageProtection,
IN ULONG AllocationAttributes,
IN HANDLE FileHandle OPTIONAL
);
WCHAR const SectionNameConst[] = L"\\BaseNamedObjects\\VCamBuffah";
UNICODE_STRING SectionName;
LARGE_INTEGER SecSize;
ULONG ViewSize = 262144;
struct _OBJECT_ATTRIBUTES oa;
BOOLEAN STREAMAPI HwInitialize (IN OUT PHW_STREAM_REQUEST_BLOCK pSrb)
{
STREAM_PHYSICAL_ADDRESS adr;
ULONG Size;
PUCHAR pDmaBuf;
int j;
PPORT_CONFIGURATION_INFORMATION ConfigInfo =
pSrb->CommandData.ConfigInfo;
PHW_DEVICE_EXTENSION pHwDevExt =
(PHW_DEVICE_EXTENSION)ConfigInfo->HwDeviceExtension;
SecSize.QuadPart = ViewSize;
SectionName.Buffer = (PWSTR)&SectionNameConst;
SectionName.Length = wcslen(SectionNameConst) * sizeof(WCHAR);
SectionName.MaximumLength = SectionName.Length + sizeof(WCHAR);
InitializeObjectAttributes(&oa, &SectionName, OBJ_CASE_INSENSITIVE
, NULL, NULL);
pHwDevExt->status = ZwCreateSection( &pHwDevExt->hMap,
SECTION_ALL_ACCESS, &oa, &SecSize, PAGE_READWRITE, SEC_COMMIT, 0);
//ViewSize = 0;
pHwDevExt->pBuf = 0;
if(pHwDevExt->hMap != 0)
{
pHwDevExt->status = ZwMapViewOfSection( pHwDevExt->hMap,
(HANDLE)-1 ,&pHwDevExt->pBuf, 0L, 262144, NULL, &ViewSize, 1, 0,
PAGE_READONLY );
}
AdapterSetInstance (pSrb);
pSrb->Status = STATUS_SUCCESS;
return TRUE;
}
It always reports that the 9th parameter is invalid.
At my wits end, I tried another experiment, I wrote an app to map
memory and stepped through the call for MapViewOfFile, when it
eventually calls ZwMapViewOfSection, the stack has 1, 0 and 2 as the
last 3 parameters to it.
This is weird, because in my app i specify PAGE_READWRITE which is 4,
but it goes to the kernel api as 2!!
Can anyone test this out and give me a solution?
Im so desperate, i am thinking I might have to use a regular file or
named pipe to share data.