ReactOS 0.4.16-dev-125-g798ea90
marshalling.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Printing Stack Marshalling Functions
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Marshalling functions
5 * COPYRIGHT: Copyright 2015-2018 Colin Finck (colin@reactos.org)
6 */
7
8#define WIN32_NO_STATUS
9#include <windef.h>
10#include <winbase.h>
11
13
38MarshallDownStructure(PVOID pStructure, const MARSHALLING_INFO* pInfo, DWORD cbStructureSize, BOOL bSomeBoolean)
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}
64
91MarshallDownStructuresArray(PVOID pStructuresArray, DWORD cElements, const MARSHALLING_INFO* pInfo, DWORD cbStructureSize, BOOL bSomeBoolean)
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}
107
137MarshallUpStructure(DWORD cbSize, PVOID pStructure, const MARSHALLING_INFO* pInfo, DWORD cbStructureSize, BOOL bSomeBoolean)
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}
170
202MarshallUpStructuresArray(DWORD cbSize, PVOID pStructuresArray, DWORD cElements, const MARSHALLING_INFO* pInfo, DWORD cbStructureSize, BOOL bSomeBoolean)
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}
#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
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL WINAPI MarshallDownStructure(PVOID pStructure, const MARSHALLING_INFO *pInfo, DWORD cbStructureSize, BOOL bSomeBoolean)
Definition: marshalling.c:38
BOOL WINAPI MarshallUpStructuresArray(DWORD cbSize, PVOID pStructuresArray, DWORD cElements, const MARSHALLING_INFO *pInfo, DWORD cbStructureSize, BOOL bSomeBoolean)
Definition: marshalling.c:202
BOOL WINAPI MarshallUpStructure(DWORD cbSize, PVOID pStructure, const MARSHALLING_INFO *pInfo, DWORD cbStructureSize, BOOL bSomeBoolean)
Definition: marshalling.c:137
BOOL WINAPI MarshallDownStructuresArray(PVOID pStructuresArray, DWORD cElements, const MARSHALLING_INFO *pInfo, DWORD cbStructureSize, BOOL bSomeBoolean)
Definition: marshalling.c:91
#define MAXDWORD
BYTE * PBYTE
Definition: pedump.c:66
uint32_t * PULONG_PTR
Definition: typedefs.h:65
#define WINAPI
Definition: msvc.h:6
#define ERROR_INVALID_DATA
Definition: winerror.h:116