📄 iorm.c
字号:
if (PSLGetCallerTrust() != OEM_CERTIFY_TRUST) {
SetLastError(ERROR_ACCESS_DENIED);
return FALSE;
}
EnterCriticalSection(&gcsIORM);
__try {
if ((pdom = FindDomain(dwResId)) == NULL) {
goto done; // no such resource
}
min = pdom->dwOffset;
if (dwId < min) {
goto done; // out of range
}
/// translate the resource to the domain's address space
dwId -= min;
size = pdom->table.dwSize;
if (dwId >= size || dwId + dwLen > size) {
goto done; // out of range
}
if (size <= gdwMaxDenseResources) {
DenseTable *ptab = &pdom->table.dt;
// make sure that none of the resources are in use or invalid
for(dwTrav = dwId, dwCount = 0; dwCount < dwLen; dwTrav++, dwCount++) {
if(!RBMIsSet(ptab->dwResMax, dwTrav, ptab->prvValid)
|| ptab->pUseCount[dwTrav] != 0) {
break;
}
}
// did we get to the end of the list?
if(dwCount != dwLen) {
dwError = ERROR_INVALID_PARAMETER;
} else {
for(dwTrav = dwId, dwCount = 0; dwCount < dwLen; dwTrav++, dwCount++) {
if(fShareable) {
RBMSet(pdom->table.dt.dwResMax, dwTrav, pdom->table.dt.prvShareable);
} else {
RBMClear(pdom->table.dt.dwResMax, dwTrav, pdom->table.dt.prvShareable);
}
}
dwError = ERROR_SUCCESS;
}
} else {
DEBUGMSG(ZONE_WARNING || ZONE_RESMGR,
(_T("IORM_ResourceMarkAsShareable: shared space size of %u exceeds maximum of %u\r\n"),
size, gdwMaxDenseResources));
dwError = ERROR_NOT_SUPPORTED;
goto done; // cannot set shared sparse resources
}
done:
; // need this to make the compiler happy
}
__except(EXCEPTION_EXECUTE_HANDLER) {
dwError = ERROR_GEN_FAILURE;
fOk = FALSE;
}
LeaveCriticalSection(&gcsIORM);
if(dwError != ERROR_SUCCESS) {
SetLastError(dwError);
fOk = FALSE;
} else {
fOk = TRUE;
}
DEBUGMSG(!fOk && (ZONE_WARNING || ZONE_RESMGR),
(_T("IORM: mark as %s returning %d, error code %d\r\n"),
fShareable ? _T("shareable") : _T("unshareable"), fOk, dwError));
return fOk;
}
// Referenced by device.c. This routine is now only used for
// resource release.
BOOL WINAPI IORM_ResourceAdjust (DWORD dwResId, DWORD dwId, DWORD dwLen, BOOL fClaim)
{
ResourceDomain *pdom;
DWORD size, min;
DWORD dwError = ERROR_SUCCESS;
BOOL fOk;
DEBUGCHK(!fClaim);
DEBUGMSG(ZONE_RESMGR, (_T("IORM: releasing 0x%x resources at 0x%x from list 0x%08x\r\n"),
dwLen, dwId, dwResId));
if (PSLGetCallerTrust() != OEM_CERTIFY_TRUST) {
SetLastError(ERROR_ACCESS_DENIED);
return FALSE;
}
EnterCriticalSection(&gcsIORM);
__try {
if ((pdom = FindDomain(dwResId)) == NULL) {
dwError = ERROR_FILE_NOT_FOUND;
goto done; // no such resource
}
min = pdom->dwOffset;
if (dwId < min) {
dwError = ERROR_INVALID_PARAMETER;
goto done; // out of range
}
// translate the resource to the domain's address space
dwId -= min;
size = pdom->table.dwSize;
if (dwId >= size || dwId + dwLen > size) {
dwError = ERROR_INVALID_PARAMETER;
goto done; // out of range
}
if (size <= gdwMaxDenseResources) {
dwError = SetDenseResources(&pdom->table.dt, dwId, dwLen, fClaim, 0);
} else {
dwError = SetSparseResources(&pdom->table.st, dwId, dwLen, fClaim, 0);
}
done:
; // need this to make the compiler happy
}
__except(EXCEPTION_EXECUTE_HANDLER) {
dwError = ERROR_GEN_FAILURE;
}
LeaveCriticalSection(&gcsIORM);
if(dwError != ERROR_SUCCESS) {
SetLastError(dwError);
fOk = FALSE;
} else {
fOk = TRUE;
}
DEBUGMSG(!fOk && (ZONE_WARNING || ZONE_RESMGR),
(_T("IORM: release returning %d, error code %d\r\n"), fOk, dwError));
#ifdef DEBUG
if(fOk && ZONE_RESMGR)
ResourceDump(pdom);
#endif
return fOk;
}
BOOL
IORM_ResourceRequestEx(DWORD dwResId, DWORD dwId, DWORD dwLen, DWORD dwFlags)
{
ResourceDomain *pdom;
DWORD size, min;
BOOL fOk;
DWORD dwError = ERROR_SUCCESS;
DEBUGMSG(ZONE_RESMGR, (_T("IORM: requesting 0x%x resources at 0x%x from list 0x%08x, flags 0x%08x\r\n"),
dwLen, dwId, dwResId, dwFlags));
if (PSLGetCallerTrust() != OEM_CERTIFY_TRUST) {
SetLastError(ERROR_ACCESS_DENIED);
return FALSE;
}
// validate flags
if((dwFlags & RREXF_REQUEST_EXCLUSIVE) != dwFlags) {
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
EnterCriticalSection(&gcsIORM);
__try {
if ((pdom = FindDomain(dwResId)) == NULL) {
dwError = ERROR_FILE_NOT_FOUND;
goto done; // no such resource
}
min = pdom->dwOffset;
if (dwId < min) {
dwError = ERROR_INVALID_PARAMETER;
goto done; // out of range
}
// translate the resource to the domain's address space
dwId -= min;
size = pdom->table.dwSize;
if (dwId >= size || dwId + dwLen > size) {
dwError = ERROR_INVALID_PARAMETER;
goto done; // out of range
}
if (size <= gdwMaxDenseResources) {
dwError = SetDenseResources(&pdom->table.dt, dwId, dwLen, TRUE, dwFlags);
} else {
dwError = SetSparseResources(&pdom->table.st, dwId, dwLen, TRUE, dwFlags);
}
done:
; // need this to make the compiler happy
}
__except(EXCEPTION_EXECUTE_HANDLER) {
dwError = ERROR_GEN_FAILURE;
}
LeaveCriticalSection(&gcsIORM);
if(dwError != ERROR_SUCCESS) {
SetLastError(dwError);
fOk = FALSE;
} else {
fOk = TRUE;
}
DEBUGMSG(!fOk && ZONE_RESMGR,
(_T("IORM: request returning %d, error code %d\r\n"), fOk, dwError));
#ifdef DEBUG
if (fOk && ZONE_RESMGR)
ResourceDump(pdom);
#endif
return fOk;
}
// Call this to tell the OS what resource types are available.
// Creates a resource domain with zero available resources.
// OEM can call ResourceRelease to make resources available.
BOOL IORM_ResourceCreateList (DWORD dwResId, DWORD dwMinimum, DWORD dwCount)
{
ResourceDomain *ndom;
DWORD dwSize;
BOOL fOk;
DWORD dwError = ERROR_SUCCESS;
DEBUGMSG(ZONE_RESMGR, (_T("IORM: creating list id 0x%08x - minimum is 0x%x, count is 0x%x\r\n"),
dwResId, dwMinimum, dwCount));
if (PSLGetCallerTrust() != OEM_CERTIFY_TRUST) {
SetLastError(ERROR_ACCESS_DENIED);
return FALSE;
}
EnterCriticalSection(&gcsIORM);
__try {
if (FindDomain(dwResId) != NULL) {
dwError = ERROR_ALREADY_EXISTS;
goto done; // domain already exists
}
if (dwCount < 1) {
dwError = ERROR_INVALID_PARAMETER;
goto done; // invalid parameters
}
// create an appropriate domain
dwSize = sizeof(*ndom);
if(dwCount <= gdwMaxDenseResources) {
dwSize += dwCount * sizeof(USHORT); // pUseCount array
dwSize += 3 * sizeof(DWORD) * ((dwCount + 31) / 32); // prvValid + prvShareable + prvExclusive
}
ndom = LocalAlloc(0, dwSize);
#ifdef DEBUG
memset(ndom, 0xAF, dwSize);
#endif // DEBUG
if (ndom == NULL) {
dwError = ERROR_NOT_ENOUGH_MEMORY;
goto done; // OOM!
}
ndom->dwResId = dwResId;
ndom->table.dwSize = dwCount;
ndom->dwOffset = dwMinimum;
if (dwCount <= gdwMaxDenseResources) {
DWORD dwVectorSize = (dwCount + 31) / 32; // number of DWORDs in vectors
PBYTE pbTmp = (PBYTE) ndom; // pointer to our new structure
// populate the domain structure's dense table member
pbTmp += sizeof(*ndom);
ndom->table.dt.prvValid = (PDWORD) pbTmp;
pbTmp += dwVectorSize * sizeof(DWORD);
ndom->table.dt.prvShareable = (PDWORD) pbTmp;
pbTmp += dwVectorSize * sizeof(DWORD);
ndom->table.dt.prvExclusive = (PDWORD) pbTmp;
pbTmp += dwVectorSize * sizeof(DWORD);
ndom->table.dt.pUseCount = (PUSHORT) pbTmp;
// Fill in vector and array values. Assume all resources
// are invalid and unshareable. We will initialize the use
// count when the resource is validated.
ndom->table.dt.dwResMax = dwCount - 1;
RBMInit((dwVectorSize * 32) - 1, ndom->table.dt.prvValid, FALSE);
RBMInit((dwVectorSize * 32) - 1, ndom->table.dt.prvShareable, FALSE);
RBMInit((dwVectorSize * 32) - 1, ndom->table.dt.prvExclusive, FALSE);
} else {
ndom->table.st.pFirst = NULL;
}
// link it to the domain list
ndom->pNext = g_DomainList;
g_DomainList = ndom;
done:
; // need this to make the compiler happy
}
__except(EXCEPTION_EXECUTE_HANDLER) {
dwError = ERROR_GEN_FAILURE;
}
LeaveCriticalSection(&gcsIORM);
if(dwError != ERROR_SUCCESS) {
SetLastError(dwError);
fOk = FALSE;
} else {
fOk = TRUE;
}
DEBUGMSG(!fOk && (ZONE_WARNING || ZONE_RESMGR), (_T("IORM: creation of list id 0x%08x returned %d, error code %d\r\n"),
dwResId, fOk, dwError));
return fOk;
}
BOOL
IORM_ResourceDestroyList(DWORD dwResId)
{
DWORD dwError = ERROR_SUCCESS;
BOOL fOk;
DEBUGMSG(ZONE_RESMGR, (_T("IORM: destroying list id 0x%08x\r\n"), dwResId));
if (PSLGetCallerTrust() != OEM_CERTIFY_TRUST) {
SetLastError(ERROR_ACCESS_DENIED);
return FALSE;
}
EnterCriticalSection(&gcsIORM);
__try {
ResourceDomain *pdom, *pdomPrevious;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -