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.

255 lines
6.2 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: meta.cxx
  3. *
  4. * This contains the code to create metafiles in the kernel
  5. *
  6. * Created: 26-Mar-1997
  7. * Author: Andre Vachon [andreva]
  8. *
  9. * Copyright (c) 1992-1999 Microsoft Corporation
  10. \**************************************************************************/
  11. #include "precomp.hxx"
  12. #if DBG
  13. LONG cSrvMetaFile = 0;
  14. LONG cMaxSrvMetaFile = 0;
  15. #endif
  16. class META : public OBJECT
  17. {
  18. public:
  19. DWORD iType; // MFPICT_IDENTIFIER or MFEN_IDENTIFIER
  20. DWORD mm; // used by MFPICT_IDENTIFIER only
  21. DWORD xExt; // used by MFPICT_IDENTIFIER only
  22. DWORD yExt; // used by MFPICT_IDENTIFIER only
  23. ULONG cbData; // Number of bytes in abData[]
  24. BYTE abData[1]; // Metafile bits
  25. };
  26. typedef META *PMETA;
  27. /******************************Public*Routine******************************\
  28. * NtGdiCreateServerMetaFile()
  29. *
  30. * History:
  31. * 26-Mar-1997 -by- Andre Vachon [andreva]
  32. * Wrote it.
  33. \**************************************************************************/
  34. HANDLE
  35. APIENTRY
  36. NtGdiCreateServerMetaFile(
  37. DWORD iType,
  38. ULONG cjData,
  39. LPBYTE pjData,
  40. DWORD mm,
  41. DWORD xExt,
  42. DWORD yExt
  43. )
  44. {
  45. PMETA pMeta;
  46. HANDLE hRet = NULL;
  47. if ((iType != MFEN_IDENTIFIER) && (iType != MFPICT_IDENTIFIER))
  48. {
  49. ASSERTGDI(FALSE, "GreCreateServerMetaFile: unknown type\n");
  50. return NULL;
  51. }
  52. if (pjData == NULL)
  53. {
  54. WARNING("GreCreateServerMetaFile: No metafile bits\n");
  55. return NULL;
  56. }
  57. if (cjData > (MAXULONG - sizeof(META)))
  58. {
  59. WARNING("GreCreateServerMetaFile: overflow\n");
  60. return NULL;
  61. }
  62. pMeta = (PMETA) HmgAlloc(cjData + sizeof(META),
  63. META_TYPE,
  64. HMGR_ALLOC_LOCK | HMGR_MAKE_PUBLIC);
  65. if (pMeta)
  66. {
  67. hRet = pMeta->hGet();
  68. pMeta->iType = iType;
  69. pMeta->mm = mm;
  70. pMeta->xExt = xExt;
  71. pMeta->yExt = yExt;
  72. pMeta->cbData = cjData;
  73. if (cjData)
  74. {
  75. __try
  76. {
  77. //
  78. // Probe and Read the structure
  79. //
  80. ProbeForRead(pjData, cjData, sizeof(DWORD));
  81. RtlCopyMemory((PVOID) pMeta->abData,
  82. (PVOID) pjData,
  83. cjData);
  84. #if DBG
  85. InterlockedIncrement(&cSrvMetaFile);
  86. if (cMaxSrvMetaFile < cSrvMetaFile)
  87. {
  88. cMaxSrvMetaFile = cSrvMetaFile;
  89. }
  90. if (cSrvMetaFile >= 100)
  91. {
  92. DbgPrint("GreCreateServerMetaFile: Number of server metafiles is %ld\n", cSrvMetaFile);
  93. }
  94. #endif
  95. }
  96. __except(EXCEPTION_EXECUTE_HANDLER)
  97. {
  98. WARNINGX(14);
  99. hRet = 0;
  100. }
  101. }
  102. if (hRet == 0)
  103. {
  104. HmgFree((HOBJ) pMeta->hGet());
  105. }
  106. else
  107. {
  108. DEC_EXCLUSIVE_REF_CNT(pMeta);
  109. }
  110. }
  111. if (hRet == 0)
  112. {
  113. WARNING("NtGdiCreateServerMetaFile: unable to create metafile\n");
  114. }
  115. return (hRet);
  116. }
  117. /******************************Public*Routine******************************\
  118. * NtGdiGetServerMetaFileBits()
  119. *
  120. * History:
  121. * 26-Mar-1997 -by- Andre Vachon [andreva]
  122. * Wrote it.
  123. \**************************************************************************/
  124. ULONG
  125. APIENTRY
  126. NtGdiGetServerMetaFileBits(
  127. HANDLE hmo,
  128. ULONG cjData,
  129. LPBYTE pjData,
  130. PDWORD piType,
  131. PDWORD pmm,
  132. PDWORD pxExt,
  133. PDWORD pyExt
  134. )
  135. {
  136. ULONG ulRet = 0;
  137. PMETA pMeta = (PMETA) HmgLock((HOBJ)hmo, META_TYPE);
  138. if (pMeta)
  139. {
  140. if (pMeta->iType == MFPICT_IDENTIFIER ||
  141. pMeta->iType == MFEN_IDENTIFIER)
  142. {
  143. //
  144. // How much data is (or should be) returned.
  145. //
  146. ulRet = pMeta->cbData;
  147. if (cjData)
  148. {
  149. if (cjData != pMeta->cbData)
  150. {
  151. ASSERTGDI(FALSE, "GreGetServerMetaFileBits: sizes do no match");
  152. ulRet = 0;
  153. }
  154. else
  155. {
  156. __try
  157. {
  158. ProbeAndWriteUlong(pxExt,pMeta->xExt);
  159. ProbeAndWriteUlong(pyExt,pMeta->yExt);
  160. ProbeAndWriteUlong(piType,pMeta->iType);
  161. ProbeAndWriteUlong(pmm,pMeta->mm);
  162. ProbeForWrite(pjData, cjData, sizeof(DWORD));
  163. RtlCopyMemory(pjData,
  164. (PVOID) pMeta->abData,
  165. pMeta->cbData);
  166. }
  167. __except(EXCEPTION_EXECUTE_HANDLER)
  168. {
  169. WARNINGX(20);
  170. ulRet = 0;
  171. }
  172. }
  173. }
  174. }
  175. DEC_EXCLUSIVE_REF_CNT(pMeta);
  176. }
  177. return (ulRet);
  178. }
  179. /******************************Public*Routine******************************\
  180. * GreDeleteServerMetaFile()
  181. *
  182. * History:
  183. * 26-Mar-1997 -by- Andre Vachon [andreva]
  184. * Wrote it.
  185. \**************************************************************************/
  186. BOOL
  187. GreDeleteServerMetaFile(
  188. HANDLE hmo
  189. )
  190. {
  191. PMETA pMeta = (PMETA) HmgLock((HOBJ)hmo, META_TYPE);
  192. if (pMeta)
  193. {
  194. if (pMeta->iType == MFPICT_IDENTIFIER ||
  195. pMeta->iType == MFEN_IDENTIFIER)
  196. {
  197. HmgFree((HOBJ) pMeta->hGet());
  198. #if DBG
  199. InterlockedDecrement(&cSrvMetaFile);
  200. if (cSrvMetaFile < 0)
  201. {
  202. ASSERTGDI(FALSE, "GreDeleteServerMetaFile: cSrvMetaFile < 0");
  203. }
  204. #endif
  205. return TRUE;
  206. }
  207. else
  208. {
  209. DEC_EXCLUSIVE_REF_CNT(pMeta);
  210. }
  211. }
  212. WARNING("GreDeleteServerMetaFile: bad metafile handle");
  213. return FALSE;
  214. }