Ticket #282: SafeDosDevIOCtl.c

File SafeDosDevIOCtl.c, 1.6 KB (added by KO Myung-Hun, 11 years ago)

Implementation of SafeDosDevIOCtl()

Line 
1APIRET SafeDosDevIOCtl( HFILE hdevice, ULONG category, ULONG function,
2 PVOID pParams, ULONG cbParamLenMax, PULONG pcbParamLen,
3 PVOID pData, ULONG cbDataLenMax, PULONG pcbDataLen )
4{
5 PVOID pParamsLow = NULL;
6 PVOID pDataLow = NULL;
7 PULONG pcbParamLenLow = NULL;
8 PULONG pcbDataLenLow = NULL;
9 ULONG cbParamLenLow;
10 ULONG cbDataLenLow;
11
12 APIRET rc = 0;
13
14 if( pParams )
15 rc = DosAllocMem( &pParamsLow, cbParamLenMax, fALLOC );
16
17 if( rc )
18 goto exit_free;
19
20 if( pData )
21 rc = DosAllocMem( &pDataLow, cbDataLenMax, fALLOC );
22
23 if( rc )
24 goto exit_free;
25
26 if( pParams )
27 memcpy( pParamsLow, pParams, cbParamLenMax );
28
29 if( pData )
30 memcpy( pDataLow, pData, cbDataLenMax );
31
32 if( pcbParamLen )
33 {
34 pcbParamLenLow = &cbParamLenLow;
35 *pcbParamLenLow = *pcbParamLen;
36 }
37
38 if( pcbDataLen )
39 {
40 pcbDataLenLow = &cbParamLenLow;
41 *pcbDataLenLow = *pcbDataLen;
42 }
43
44 rc = DosDevIOCtl( hdevice, category, function, pParamsLow,
45 cbParamLenMax, pcbParamLenLow, pDataLow, cbDataLenMax,
46 pcbDataLenLow );
47
48 if( !rc )
49 {
50 if( pParams )
51 memcpy( pParams, pParamsLow, cbParamLenMax );
52
53 if( pData )
54 memcpy( pData, pDataLow, cbDataLenMax );
55
56 if( pcbParamLen )
57 *pcbParamLen = *pcbParamLenLow;
58
59 if( pcbDataLen )
60 *pcbDataLen = *pcbDataLenLow;
61 }
62
63exit_free:
64 DosFreeMem( pParamsLow);
65 DosFreeMem( pDataLow);
66
67 return rc;
68}