ReactOS  0.4.15-dev-1377-ga59cecd
print.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS win32 kernel mode subsystem
3  * LICENSE: GPL - See COPYING in the top level directory
4  * FILE: win32ss/gdi/ntgdi/print.c
5  * PURPOSE: Print functions
6  * PROGRAMMER:
7  */
8 
9 #include <win32k.h>
10 
11 #define NDEBUG
12 #include <debug.h>
13 
14 INT
17 {
19  return 0;
20 }
21 
22 INT
25 {
27  return 0;
28 }
29 
30 INT
33 {
35  return 0;
36 }
37 
38 INT
41  INT Escape,
42  INT InSize,
43  LPCSTR InData,
44  LPVOID OutData)
45 {
46  if (Escape == QUERYESCSUPPORT)
47  return FALSE;
48 
50  return SP_ERROR;
51 }
52 
53 INT
56  INT Escape,
57  INT InSize,
58  LPCSTR InData,
59  LPVOID OutData)
60 {
61  PDC dc;
62  INT ret;
63 
64  dc = DC_LockDc(hDC);
65  if (dc == NULL)
66  {
68  return SP_ERROR;
69  }
70 
71  /* TODO: FIXME: Don't pass umode buffer to an Int function */
72  ret = IntGdiEscape(dc, Escape, InSize, InData, OutData);
73 
74  DC_UnlockDc( dc );
75  return ret;
76 }
77 
78 INT
81  HDC hDC,
83  IN INT nDriver,
84  INT Escape,
85  INT InSize,
86  OPTIONAL LPSTR UnsafeInData,
87  INT OutSize,
88  OPTIONAL LPSTR UnsafeOutData)
89 {
90  LPVOID SafeInData = NULL;
91  LPVOID SafeOutData = NULL;
93  INT Result;
94  PPDEVOBJ ppdev;
95  PSURFACE psurf;
96 
97  if (hDC == NULL)
98  {
99  if (pDriver)
100  {
101  /* FIXME : Get the pdev from its name */
103  return -1;
104  }
105 
106  ppdev = EngpGetPDEV(NULL);
107  if (!ppdev)
108  {
110  return -1;
111  }
112 
113  /* We're using the primary surface of the pdev. Lock it */
115 
116  psurf = ppdev->pSurface;
117  if (!psurf)
118  {
120  PDEVOBJ_vRelease(ppdev);
121  return 0;
122  }
124  }
125  else
126  {
127  PDC pDC = DC_LockDc(hDC);
128  if ( pDC == NULL )
129  {
131  return -1;
132  }
133 
134  /* Get the PDEV from the DC */
135  ppdev = pDC->ppdev;
136  PDEVOBJ_vReference(ppdev);
137 
138  /* Check if we have a surface */
139  psurf = pDC->dclevel.pSurface;
140  if (!psurf)
141  {
142  DC_UnlockDc(pDC);
143  PDEVOBJ_vRelease(ppdev);
144  return 0;
145  }
147 
148  /* We're done with the DC */
149  DC_UnlockDc(pDC);
150  }
151 
152  /* See if we actually have a driver function to call */
153  if (ppdev->DriverFunctions.Escape == NULL)
154  {
155  Result = 0;
156  goto Exit;
157  }
158 
159  if ( InSize && UnsafeInData )
160  {
161  _SEH2_TRY
162  {
163  ProbeForRead(UnsafeInData,
164  InSize,
165  1);
166  }
168  {
170  }
171  _SEH2_END;
172 
173  if (!NT_SUCCESS(Status))
174  {
175  Result = -1;
176  goto Exit;
177  }
178 
179  SafeInData = ExAllocatePoolWithTag ( PagedPool, InSize, GDITAG_TEMP );
180  if ( !SafeInData )
181  {
183  Result = -1;
184  goto Exit;
185  }
186 
187  _SEH2_TRY
188  {
189  /* Pointers were already probed! */
190  RtlCopyMemory(SafeInData,
191  UnsafeInData,
192  InSize);
193  }
195  {
197  }
198  _SEH2_END;
199 
200  if ( !NT_SUCCESS(Status) )
201  {
203  Result = -1;
204  goto Exit;
205  }
206  }
207 
208  if ( OutSize && UnsafeOutData )
209  {
210  _SEH2_TRY
211  {
212  ProbeForWrite(UnsafeOutData,
213  OutSize,
214  1);
215  }
217  {
219  }
220  _SEH2_END;
221 
222  if (!NT_SUCCESS(Status))
223  {
225  Result = -1;
226  goto Exit;
227  }
228 
229  SafeOutData = ExAllocatePoolWithTag ( PagedPool, OutSize, GDITAG_TEMP );
230  if ( !SafeOutData )
231  {
233  Result = -1;
234  goto Exit;
235  }
236  }
237 
238  /* Finally call the driver */
239  Result = ppdev->DriverFunctions.Escape(
240  &psurf->SurfObj,
241  Escape,
242  InSize,
243  SafeInData,
244  OutSize,
245  SafeOutData );
246 
247 Exit:
248  if (hDC == NULL)
249  {
251  }
253  PDEVOBJ_vRelease(ppdev);
254 
255  if ( SafeInData )
256  {
257  ExFreePoolWithTag ( SafeInData ,GDITAG_TEMP );
258  }
259 
260  if ( SafeOutData )
261  {
262  if (Result > 0)
263  {
264  _SEH2_TRY
265  {
266  /* Pointers were already probed! */
267  RtlCopyMemory(UnsafeOutData, SafeOutData, OutSize);
268  }
270  {
272  }
273  _SEH2_END;
274 
275  if ( !NT_SUCCESS(Status) )
276  {
278  Result = -1;
279  }
280  }
281 
282  ExFreePoolWithTag ( SafeOutData, GDITAG_TEMP );
283  }
284 
285  return Result;
286 }
287 
288 INT
289 APIENTRY
291  IN HDC hdc,
292  IN DOCINFOW *pdi,
293  OUT BOOL *pbBanding,
294  IN INT iJob)
295 {
297  return 0;
298 }
299 
300 INT
301 APIENTRY
303 {
305  return 0;
306 }
307 /* EOF */
#define SP_ERROR
Definition: wingdi.h:317
VOID WINAPI EngReleaseSemaphore(IN HSEMAPHORE hsem)
Definition: eng.c:235
#define IN
Definition: typedefs.h:39
STRING Escape(const STRING &str)
Definition: fontsub.cpp:1030
#define GDITAG_TEMP
Definition: tags.h:166
FORCEINLINE PDC DC_LockDc(HDC hdc)
Definition: dc.h:219
#define SURFACE_ShareUnlockSurface(pBMObj)
Definition: surface.h:102
FORCEINLINE VOID PDEVOBJ_vReference(_In_ PPDEVOBJ ppdev)
Definition: pdevobj.h:167
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
LONG NTSTATUS
Definition: precomp.h:26
static HDC
Definition: imagelist.c:92
INT APIENTRY NtGdiStartPage(HDC hDC)
Definition: print.c:302
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define ERROR_BAD_DEVICE
Definition: winerror.h:703
INT FASTCALL IntGdiEscape(PDC dc, INT Escape, INT InSize, LPCSTR InData, LPVOID OutData)
Definition: print.c:40
INT APIENTRY NtGdiExtEscape(HDC hDC, IN OPTIONAL PWCHAR pDriver, IN INT nDriver, INT Escape, INT InSize, OPTIONAL LPSTR UnsafeInData, INT OutSize, OPTIONAL LPSTR UnsafeOutData)
Definition: print.c:80
uint16_t * PWCHAR
Definition: typedefs.h:56
char * LPSTR
Definition: xmlstorage.h:182
#define FASTCALL
Definition: nt_native.h:50
int32_t INT
Definition: typedefs.h:58
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
_SEH2_TRY
Definition: create.c:4226
DRIVER_FUNCTIONS DriverFunctions
Definition: pdevobj.h:138
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
SURFOBJ SurfObj
Definition: surface.h:8
FORCEINLINE VOID SURFACE_ShareLockByPointer(PSURFACE psurf)
Definition: surface.h:95
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
ENGAPI VOID APIENTRY EngAcquireSemaphore(_Inout_ HSEMAPHORE hsem)
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
HSEMAPHORE hsemDevLock
Definition: pdevobj.h:91
const char * LPCSTR
Definition: xmlstorage.h:183
Status
Definition: gdiplustypes.h:24
INT APIENTRY NtGdiEndPage(HDC hDC)
Definition: print.c:32
FxDriver * pDriver
Definition: polytest.cpp:40
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static void Exit(void)
Definition: sock.c:1331
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
int ret
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
HDC hdc
Definition: main.c:9
#define QUERYESCSUPPORT
Definition: wingdi.h:1000
INT APIENTRY NtGdiStartDoc(IN HDC hdc, IN DOCINFOW *pdi, OUT BOOL *pbBanding, IN INT iJob)
Definition: print.c:290
VOID FASTCALL SetLastNtError(NTSTATUS Status)
Definition: error.c:36
static HDC hDC
Definition: 3dtext.c:33
_SEH2_END
Definition: create.c:4400
FORCEINLINE VOID DC_UnlockDc(PDC pdc)
Definition: dc.h:237
INT APIENTRY NtGdiEscape(HDC hDC, INT Escape, INT InSize, LPCSTR InData, LPVOID OutData)
Definition: print.c:55
#define NULL
Definition: types.h:112
PSURFACE pSurface
Definition: pdevobj.h:125
#define OUT
Definition: typedefs.h:40
#define UNIMPLEMENTED
Definition: debug.h:115
static const WCHAR dc[]
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define STATUS_SUCCESS
Definition: shellext.h:65
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
VOID NTAPI PDEVOBJ_vRelease(_Inout_ PPDEVOBJ ppdev)
Definition: pdevobj.c:93
INT APIENTRY NtGdiEndDoc(HDC hDC)
Definition: print.c:24
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:27
#define APIENTRY
Definition: api.h:79
PFN_DrvEscape Escape
Definition: ntgdityp.h:593
INT APIENTRY NtGdiAbortDoc(HDC hDC)
Definition: print.c:16
PPDEVOBJ NTAPI EngpGetPDEV(_In_opt_ PUNICODE_STRING pustrDeviceName)
Definition: pdevobj.c:595
_In_ LPWSTR _In_ ULONG _In_ ULONG _In_ ULONG _Out_ DEVINFO * pdi
Definition: winddi.h:3553
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68