ReactOS 0.4.15-dev-7958-gcd0bb1a
marshalling.c File Reference
#include <windef.h>
#include <winbase.h>
#include <marshalling/marshalling.h>
Include dependency graph for marshalling.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 

Functions

MarshallDownStructure

Prepare a structure for marshalling/serialization by replacing absolute pointer addresses in its fields by relative offsets.

Parameters
pStructurePointer to the structure to operate on.
pInfoArray of MARSHALLING_INFO elements containing information about the fields of the structure as well as how to modify them. See the documentation on MARSHALLING_INFO for more information. You have to indicate the end of the array by setting the dwOffset field to MAXDWORD.
cbStructureSizeSize in bytes of the structure. This parameter is unused in my implementation.
bSomeBooleanUnknown boolean value, set to TRUE.
Returns
TRUE if the structure was successfully adjusted, FALSE otherwise.
BOOL WINAPI MarshallDownStructure (PVOID pStructure, const MARSHALLING_INFO *pInfo, DWORD cbStructureSize, BOOL bSomeBoolean)
 
MarshallDownStructuresArray

Prepare an array of structures for marshalling/serialization by replacing absolute pointer addresses in its fields by relative offsets.

Parameters
pStructuresArrayPointer to the array of structures to operate on.
cElementsNumber of array elements.
pInfoArray of MARSHALLING_INFO elements containing information about the fields of the structure as well as how to modify them. See the documentation on MARSHALLING_INFO for more information. You have to indicate the end of the array by setting the dwOffset field to MAXDWORD.
cbStructureSizeSize in bytes of each structure array element.
bSomeBooleanUnknown boolean value, set to TRUE.
Returns
TRUE if the array was successfully adjusted, FALSE otherwise.
BOOL WINAPI MarshallDownStructuresArray (PVOID pStructuresArray, DWORD cElements, const MARSHALLING_INFO *pInfo, DWORD cbStructureSize, BOOL bSomeBoolean)
 
MarshallUpStructure

Unmarshall/deserialize a structure previuosly marshalled by MarshallDownStructure by replacing relative offsets in its fields by absolute pointer addresses again.

Parameters
cbSizeSize in bytes of the memory allocated for both the structure and its data. The function will check if all relative offsets are within the bounds given by this size.
pStructurePointer to the structure to operate on.
pInfoArray of MARSHALLING_INFO elements containing information about the fields of the structure as well as how to modify them. See the documentation on MARSHALLING_INFO for more information. You have to indicate the end of the array by setting the dwOffset field to MAXDWORD.
cbStructureSizeSize in bytes of the structure. This parameter is unused in my implementation.
bSomeBooleanUnknown boolean value, set to TRUE.
Returns
TRUE if the structure was successfully adjusted, FALSE otherwise.
BOOL WINAPI MarshallUpStructure (DWORD cbSize, PVOID pStructure, const MARSHALLING_INFO *pInfo, DWORD cbStructureSize, BOOL bSomeBoolean)
 
MarshallUpStructuresArray

Unmarshall/deserialize an array of structures previuosly marshalled by MarshallDownStructuresArray by replacing relative offsets in its fields by absolute pointer addresses again.

Parameters
cbSizeSize in bytes of the memory allocated for the entire structure array and its data. The function will check if all relative offsets are within the bounds given by this size.
pStructuresArrayPointer to the array of structures to operate on.
cElementsNumber of array elements.
pInfoArray of MARSHALLING_INFO elements containing information about the fields of the structure as well as how to modify them. See the documentation on MARSHALLING_INFO for more information. You have to indicate the end of the array by setting the dwOffset field to MAXDWORD.
cbStructureSizeSize in bytes of each structure array element.
bSomeBooleanUnknown boolean value, set to TRUE.
Returns
TRUE if the array was successfully adjusted, FALSE otherwise.
BOOL WINAPI MarshallUpStructuresArray (DWORD cbSize, PVOID pStructuresArray, DWORD cElements, const MARSHALLING_INFO *pInfo, DWORD cbStructureSize, BOOL bSomeBoolean)
 

Macro Definition Documentation

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 8 of file marshalling.c.

Function Documentation

◆ MarshallDownStructure()

BOOL WINAPI MarshallDownStructure ( PVOID  pStructure,
const MARSHALLING_INFO pInfo,
DWORD  cbStructureSize,
BOOL  bSomeBoolean 
)

Definition at line 38 of file marshalling.c.

39{
40 // Sanity checks
41 if (!pStructure || !pInfo)
42 {
44 return FALSE;
45 }
46
47 // Loop until we reach an element with offset set to MAXDWORD.
48 while (pInfo->dwOffset != MAXDWORD)
49 {
50 PULONG_PTR pCurrentField = (PULONG_PTR)((PBYTE)pStructure + pInfo->dwOffset);
51
52 if (pInfo->bAdjustAddress && *pCurrentField)
53 {
54 // Make a relative offset out of the absolute pointer address.
55 *pCurrentField -= (ULONG_PTR)pStructure;
56 }
57
58 // Advance to the next field description.
59 pInfo++;
60 }
61
62 return TRUE;
63}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
#define ULONG_PTR
Definition: config.h:101
#define MAXDWORD
BYTE * PBYTE
Definition: pedump.c:66
uint32_t * PULONG_PTR
Definition: typedefs.h:65

Referenced by _RpcAddJob(), _RpcGetForm(), _RpcGetJob(), _RpcGetPrinter(), _RpcGetPrinterDriver(), _RpcGetPrinterDriver2(), MarshallDownStructuresArray(), and YGetPrinterDriver2().

◆ MarshallDownStructuresArray()

BOOL WINAPI MarshallDownStructuresArray ( PVOID  pStructuresArray,
DWORD  cElements,
const MARSHALLING_INFO pInfo,
DWORD  cbStructureSize,
BOOL  bSomeBoolean 
)

Definition at line 91 of file marshalling.c.

92{
93 PBYTE pCurrentElement = pStructuresArray;
94
95 // Call MarshallDownStructure on all array elements given by cElements of cbStructureSize.
96 while (cElements--)
97 {
98 if (!MarshallDownStructure(pCurrentElement, pInfo, cbStructureSize, bSomeBoolean))
99 return FALSE;
100
101 // Advance to the next array element.
102 pCurrentElement += cbStructureSize;
103 }
104
105 return TRUE;
106}
BOOL WINAPI MarshallDownStructure(PVOID pStructure, const MARSHALLING_INFO *pInfo, DWORD cbStructureSize, BOOL bSomeBoolean)
Definition: marshalling.c:38

Referenced by _RpcEnumForms(), _RpcEnumJobs(), _RpcEnumMonitors(), _RpcEnumPorts(), _RpcEnumPrinterDrivers(), _RpcEnumPrinters(), _RpcEnumPrintProcessorDatatypes(), _RpcEnumPrintProcessors(), and START_TEST().

◆ MarshallUpStructure()

BOOL WINAPI MarshallUpStructure ( DWORD  cbSize,
PVOID  pStructure,
const MARSHALLING_INFO pInfo,
DWORD  cbStructureSize,
BOOL  bSomeBoolean 
)

Definition at line 137 of file marshalling.c.

138{
139 // Sanity checks
140 if (!pStructure || !pInfo)
141 {
143 return FALSE;
144 }
145
146 // Loop until we reach an element with offset set to MAXDWORD.
147 while (pInfo->dwOffset != MAXDWORD)
148 {
149 PULONG_PTR pCurrentField = (PULONG_PTR)((PBYTE)pStructure + pInfo->dwOffset);
150
151 if (pInfo->bAdjustAddress && *pCurrentField)
152 {
153 // Verify that the offset in the current field is within the bounds given by cbSize.
154 if (cbSize <= *pCurrentField)
155 {
157 return FALSE;
158 }
159
160 // Make an absolute pointer address out of the relative offset.
161 *pCurrentField += (ULONG_PTR)pStructure;
162 }
163
164 // Advance to the next field description.
165 pInfo++;
166 }
167
168 return TRUE;
169}
#define ERROR_INVALID_DATA
Definition: winerror.h:116

Referenced by AddJobW(), GetFormW(), GetJobW(), GetPrinterDriverW(), GetPrinterW(), and MarshallUpStructuresArray().

◆ MarshallUpStructuresArray()

BOOL WINAPI MarshallUpStructuresArray ( DWORD  cbSize,
PVOID  pStructuresArray,
DWORD  cElements,
const MARSHALLING_INFO pInfo,
DWORD  cbStructureSize,
BOOL  bSomeBoolean 
)

Definition at line 202 of file marshalling.c.

203{
204 PBYTE pCurrentElement = pStructuresArray;
205
206 // Call MarshallUpStructure on all array elements given by cElements of cbStructureSize.
207 while (cElements--)
208 {
209 if (!MarshallUpStructure(cbSize, pCurrentElement, pInfo, cbStructureSize, bSomeBoolean))
210 return FALSE;
211
212 // Advance to the next array element.
213 pCurrentElement += cbStructureSize;
214 }
215
216 return TRUE;
217}
BOOL WINAPI MarshallUpStructure(DWORD cbSize, PVOID pStructure, const MARSHALLING_INFO *pInfo, DWORD cbStructureSize, BOOL bSomeBoolean)
Definition: marshalling.c:137

Referenced by EnumFormsW(), EnumJobsW(), EnumMonitorsW(), EnumPortsW(), EnumPrinterDriversW(), EnumPrintersW(), EnumPrintProcessorDatatypesW(), EnumPrintProcessorsW(), and START_TEST().