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.

96 lines
2.5 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. ForceSeparateVDM.cpp
  5. Abstract:
  6. Force child processes to use a separate VDM.
  7. This can be useful if the parent process wants to wait on a handle returned
  8. by CreateProcess. This only works because of a hack in the VDM that returns
  9. and actual thread handle that will go away along with the process if a VDM
  10. doesn't already exist.
  11. Notes:
  12. This is a general purpose shim.
  13. History:
  14. 06/14/2001 linstev Created
  15. --*/
  16. #include "precomp.h"
  17. IMPLEMENT_SHIM_BEGIN(ForceSeparateVDM)
  18. #include "ShimHookMacro.h"
  19. APIHOOK_ENUM_BEGIN
  20. APIHOOK_ENUM_ENTRY(CreateProcessA)
  21. APIHOOK_ENUM_ENTRY(CreateProcessW)
  22. APIHOOK_ENUM_END
  23. BOOL
  24. APIHOOK(CreateProcessA)(
  25. LPCSTR lpApplicationName,
  26. LPSTR lpCommandLine,
  27. LPSECURITY_ATTRIBUTES lpProcessAttributes,
  28. LPSECURITY_ATTRIBUTES lpThreadAttributes,
  29. BOOL bInheritHandles,
  30. DWORD dwCreationFlags,
  31. LPVOID lpEnvironment,
  32. LPSTR lpCurrentDirectory,
  33. LPSTARTUPINFOA lpStartupInfo,
  34. LPPROCESS_INFORMATION lpProcessInformation
  35. )
  36. {
  37. if (!(dwCreationFlags & CREATE_SEPARATE_WOW_VDM)) {
  38. LOGN(eDbgLevelWarning, "Added CREATE_SEPARATE_WOW_VDM to CreateProcessA");
  39. }
  40. return ORIGINAL_API(CreateProcessA)(lpApplicationName, lpCommandLine,
  41. lpProcessAttributes, lpThreadAttributes, bInheritHandles,
  42. dwCreationFlags | CREATE_SEPARATE_WOW_VDM,
  43. lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation);
  44. }
  45. BOOL
  46. APIHOOK(CreateProcessW)(
  47. LPCWSTR lpApplicationName,
  48. LPWSTR lpCommandLine,
  49. LPSECURITY_ATTRIBUTES lpProcessAttributes,
  50. LPSECURITY_ATTRIBUTES lpThreadAttributes,
  51. BOOL bInheritHandles,
  52. DWORD dwCreationFlags,
  53. LPVOID lpEnvironment,
  54. LPWSTR lpCurrentDirectory,
  55. LPSTARTUPINFOW lpStartupInfo,
  56. LPPROCESS_INFORMATION lpProcessInformation
  57. )
  58. {
  59. if (!(dwCreationFlags & CREATE_SEPARATE_WOW_VDM)) {
  60. LOGN(eDbgLevelWarning, "Added CREATE_SEPARATE_WOW_VDM to CreateProcessW");
  61. }
  62. return ORIGINAL_API(CreateProcessW)(lpApplicationName, lpCommandLine,
  63. lpProcessAttributes, lpThreadAttributes, bInheritHandles,
  64. dwCreationFlags | CREATE_SEPARATE_WOW_VDM,
  65. lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation);
  66. }
  67. /*++
  68. Register hooked functions
  69. --*/
  70. HOOK_BEGIN
  71. APIHOOK_ENTRY(KERNEL32.DLL, CreateProcessA)
  72. APIHOOK_ENTRY(KERNEL32.DLL, CreateProcessW)
  73. HOOK_END
  74. IMPLEMENT_SHIM_END