Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.7 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. SecUtil.cxx
  5. Abstract:
  6. Utility functions for manipulating cell sections
  7. Author:
  8. Kamen Moutafov (kamenm) Dec 99 - Feb 2000
  9. Revision History:
  10. --*/
  11. #include <precomp.hxx>
  12. RPC_STATUS OpenDbgSection(OUT HANDLE *pHandle, OUT PVOID *pSection,
  13. IN DWORD ProcessID, IN DWORD *pSectionNumbers OPTIONAL)
  14. {
  15. UNICODE_STRING SectionNameString;
  16. OBJECT_ATTRIBUTES ObjectAttributes;
  17. NTSTATUS NtStatus;
  18. RPC_CHAR SectionName[RpcSectionNameMaxSize];
  19. GenerateSectionName(SectionName, sizeof(SectionName)/sizeof(RPC_CHAR), ProcessID, pSectionNumbers);
  20. RtlInitUnicodeString(&SectionNameString, SectionName);
  21. InitializeObjectAttributes(&ObjectAttributes,
  22. &SectionNameString,
  23. OBJ_CASE_INSENSITIVE,
  24. 0,
  25. 0);
  26. NtStatus = NtOpenSection(pHandle, FILE_MAP_READ, &ObjectAttributes);
  27. if (!NT_SUCCESS(NtStatus))
  28. {
  29. if (NtStatus == STATUS_OBJECT_NAME_NOT_FOUND)
  30. return ERROR_FILE_NOT_FOUND;
  31. else if (NtStatus == STATUS_ACCESS_DENIED)
  32. return ERROR_ACCESS_DENIED;
  33. return RPC_S_OUT_OF_MEMORY;
  34. }
  35. *pSection = MapViewOfFileEx(*pHandle, FILE_MAP_READ, 0, 0, 0, NULL);
  36. if (*pSection == NULL)
  37. {
  38. CloseHandle(*pHandle);
  39. *pHandle = NULL;
  40. return RPC_S_OUT_OF_MEMORY;
  41. }
  42. return RPC_S_OK;
  43. }
  44. void CloseDbgSection(IN HANDLE SecHandle, PVOID SecPointer)
  45. {
  46. BOOL fResult;
  47. ASSERT(SecHandle != NULL);
  48. ASSERT(SecPointer != NULL);
  49. fResult = UnmapViewOfFile(SecPointer);
  50. ASSERT(fResult);
  51. fResult = CloseHandle(SecHandle);
  52. ASSERT(fResult);
  53. }