ReactOS 0.4.16-dev-1946-g52006dd
ndr_fullpointer.c File Reference
#include <stdarg.h>
#include <stdlib.h>
#include "windef.h"
#include "winbase.h"
#include "rpc.h"
#include "rpcndr.h"
#include "wine/debug.h"
Include dependency graph for ndr_fullpointer.c:

Go to the source code of this file.

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (rpc)
 
PFULL_PTR_XLAT_TABLES WINAPI NdrFullPointerXlatInit (ULONG NumberOfPointers, XLAT_SIDE XlatSide)
 
void WINAPI NdrFullPointerXlatFree (PFULL_PTR_XLAT_TABLES pXlatTables)
 
static void expand_pointer_table_if_necessary (PFULL_PTR_XLAT_TABLES pXlatTables, ULONG RefId)
 
int WINAPI NdrFullPointerQueryPointer (PFULL_PTR_XLAT_TABLES pXlatTables, void *pPointer, unsigned char QueryType, ULONG *pRefId)
 
int WINAPI NdrFullPointerQueryRefId (PFULL_PTR_XLAT_TABLES pXlatTables, ULONG RefId, unsigned char QueryType, void **ppPointer)
 
void WINAPI NdrFullPointerInsertRefId (PFULL_PTR_XLAT_TABLES pXlatTables, ULONG RefId, void *pPointer)
 
int WINAPI NdrFullPointerFree (PFULL_PTR_XLAT_TABLES pXlatTables, void *Pointer)
 

Function Documentation

◆ expand_pointer_table_if_necessary()

static void expand_pointer_table_if_necessary ( PFULL_PTR_XLAT_TABLES  pXlatTables,
ULONG  RefId 
)
static

Definition at line 85 of file ndr_fullpointer.c.

86{
87 if (RefId >= pXlatTables->RefIdToPointer.NumberOfEntries)
88 {
89#ifdef __REACTOS__
90 void* ptrNew;
91 ptrNew = realloc(pXlatTables->RefIdToPointer.XlatTable, sizeof(void *) * RefId * 2);
92 if (!ptrNew)
93 {
94 ERR("Couldn't reallocate RefIdToPointer.XlatTable from %lu to %lu entries\n",
95 pXlatTables->RefIdToPointer.NumberOfEntries, RefId * 2);
96 free(pXlatTables->RefIdToPointer.XlatTable);
97 }
98 pXlatTables->RefIdToPointer.XlatTable = ptrNew;
99 if (ptrNew)
100 {
101 ptrNew = realloc(pXlatTables->RefIdToPointer.StateTable, RefId * 2);
102 if (!ptrNew)
103 {
104 ERR("Couldn't reallocate RefIdToPointer.StateTable from %lu to %lu entries\n",
105 pXlatTables->RefIdToPointer.NumberOfEntries, RefId * 2);
106 free(pXlatTables->RefIdToPointer.StateTable);
107 }
108 pXlatTables->RefIdToPointer.StateTable = ptrNew;
109 }
110#else
111 pXlatTables->RefIdToPointer.XlatTable =
112 realloc(pXlatTables->RefIdToPointer.XlatTable, sizeof(void *) * RefId * 2);
113 pXlatTables->RefIdToPointer.StateTable =
114 realloc(pXlatTables->RefIdToPointer.StateTable, RefId * 2);
115#endif
116 if (!pXlatTables->RefIdToPointer.XlatTable || !pXlatTables->RefIdToPointer.StateTable)
117 {
118#ifdef __REACTOS__
119 free(pXlatTables->RefIdToPointer.XlatTable);
120 free(pXlatTables->RefIdToPointer.StateTable);
121 pXlatTables->RefIdToPointer.XlatTable = NULL;
122 pXlatTables->RefIdToPointer.StateTable = NULL;
123#endif
124 pXlatTables->RefIdToPointer.NumberOfEntries = 0;
125 return;
126 }
127 memset(pXlatTables->RefIdToPointer.XlatTable + pXlatTables->RefIdToPointer.NumberOfEntries, 0,
128 (RefId * 2 - pXlatTables->RefIdToPointer.NumberOfEntries) * sizeof(void *));
129 memset(pXlatTables->RefIdToPointer.StateTable + pXlatTables->RefIdToPointer.NumberOfEntries, 0,
130 RefId * 2 - pXlatTables->RefIdToPointer.NumberOfEntries);
131 pXlatTables->RefIdToPointer.NumberOfEntries = RefId * 2;
132 }
133}
#define ERR(fmt,...)
Definition: precomp.h:57
#define realloc
Definition: debug_ros.c:6
#define free
Definition: debug_ros.c:5
#define NULL
Definition: types.h:112
#define memset(x, y, z)
Definition: compat.h:39
struct _FULL_PTR_XLAT_TABLES::@3417 RefIdToPointer

Referenced by NdrFullPointerInsertRefId(), NdrFullPointerQueryPointer(), and NdrFullPointerQueryRefId().

◆ NdrFullPointerFree()

int WINAPI NdrFullPointerFree ( PFULL_PTR_XLAT_TABLES  pXlatTables,
void Pointer 
)

Definition at line 240 of file ndr_fullpointer.c.

241{
242 ULONG Hash = 0;
243 unsigned int i;
244 PFULL_PTR_TO_REFID_ELEMENT XlatTableEntry;
245 ULONG RefId = 0;
246
247 TRACE("(%p, %p)\n", pXlatTables, Pointer);
248
249 if (!Pointer)
250 return 1;
251
252 /* simple hashing algorithm, don't know whether it matches native */
253 for (i = 0; i < sizeof(Pointer); i++)
254 Hash = (Hash * 3) ^ ((unsigned char *)&Pointer)[i];
255
256 XlatTableEntry = pXlatTables->PointerToRefId.XlatTable[Hash & pXlatTables->PointerToRefId.HashMask];
257 for (; XlatTableEntry; XlatTableEntry = XlatTableEntry->Next)
258 if (Pointer == XlatTableEntry->Pointer)
259 {
260 if (XlatTableEntry->State & 0x20)
261 return 0;
262 XlatTableEntry->State |= 0x20;
263 RefId = XlatTableEntry->RefId;
264 break;
265 }
266
267 if (!XlatTableEntry)
268 return 0;
269
270 if (pXlatTables->RefIdToPointer.NumberOfEntries > RefId)
271 {
272 pXlatTables->RefIdToPointer.StateTable[RefId] |= 0x20;
273 return 1;
274 }
275
276 return 0;
277}
static int Hash(const char *)
Definition: reader.c:2237
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define TRACE(s)
Definition: solgame.cpp:4
struct _FULL_PTR_TO_REFID_ELEMENT * Next
Definition: rpcndr.h:504
unsigned char State
Definition: rpcndr.h:507
struct _FULL_PTR_XLAT_TABLES::@3418 PointerToRefId
uint32_t ULONG
Definition: typedefs.h:59

Referenced by PointerFree(), and test_fullpointer_xlat().

◆ NdrFullPointerInsertRefId()

void WINAPI NdrFullPointerInsertRefId ( PFULL_PTR_XLAT_TABLES  pXlatTables,
ULONG  RefId,
void pPointer 
)

Definition at line 214 of file ndr_fullpointer.c.

216{
217 ULONG Hash = 0;
218 unsigned int i;
219 PFULL_PTR_TO_REFID_ELEMENT XlatTableEntry;
220
221 TRACE("(%p, 0x%lx, %p)\n", pXlatTables, RefId, pPointer);
222
223 /* simple hashing algorithm, don't know whether it matches native */
224 for (i = 0; i < sizeof(pPointer); i++)
225 Hash = (Hash * 3) ^ ((unsigned char *)&pPointer)[i];
226
227 XlatTableEntry = malloc(sizeof(*XlatTableEntry));
228 XlatTableEntry->Next = pXlatTables->PointerToRefId.XlatTable[Hash & pXlatTables->PointerToRefId.HashMask];
229 XlatTableEntry->Pointer = pPointer;
230 XlatTableEntry->RefId = RefId;
231 XlatTableEntry->State = 0;
232 pXlatTables->PointerToRefId.XlatTable[Hash & pXlatTables->PointerToRefId.HashMask] = XlatTableEntry;
233
234 /* insert pointer into mapping table */
235 expand_pointer_table_if_necessary(pXlatTables, RefId);
236 if (pXlatTables->RefIdToPointer.NumberOfEntries > RefId)
237 pXlatTables->RefIdToPointer.XlatTable[XlatTableEntry->RefId] = pPointer;
238}
#define malloc
Definition: debug_ros.c:4
static void expand_pointer_table_if_necessary(PFULL_PTR_XLAT_TABLES pXlatTables, ULONG RefId)

Referenced by PointerUnmarshall(), and test_fullpointer_xlat().

◆ NdrFullPointerQueryPointer()

int WINAPI NdrFullPointerQueryPointer ( PFULL_PTR_XLAT_TABLES  pXlatTables,
void pPointer,
unsigned char  QueryType,
ULONG pRefId 
)

Definition at line 135 of file ndr_fullpointer.c.

138{
139 ULONG Hash = 0;
140 unsigned int i;
141 PFULL_PTR_TO_REFID_ELEMENT XlatTableEntry;
142
143 TRACE("(%p, %p, %d, %p)\n", pXlatTables, pPointer, QueryType, pRefId);
144
145 if (!pPointer)
146 {
147 *pRefId = 0;
148 return 1;
149 }
150
151 /* simple hashing algorithm, don't know whether it matches native */
152 for (i = 0; i < sizeof(pPointer); i++)
153 Hash = (Hash * 3) ^ ((unsigned char *)&pPointer)[i];
154
155 XlatTableEntry = pXlatTables->PointerToRefId.XlatTable[Hash & pXlatTables->PointerToRefId.HashMask];
156 for (; XlatTableEntry; XlatTableEntry = XlatTableEntry->Next)
157 if (pPointer == XlatTableEntry->Pointer)
158 {
159 *pRefId = XlatTableEntry->RefId;
160 if (XlatTableEntry->State & QueryType)
161 return 1;
162 XlatTableEntry->State |= QueryType;
163 return 0;
164 }
165
166 XlatTableEntry = malloc(sizeof(*XlatTableEntry));
167 XlatTableEntry->Next = pXlatTables->PointerToRefId.XlatTable[Hash & pXlatTables->PointerToRefId.HashMask];
168 XlatTableEntry->Pointer = pPointer;
169 XlatTableEntry->RefId = *pRefId = pXlatTables->NextRefId++;
170 XlatTableEntry->State = QueryType;
171 pXlatTables->PointerToRefId.XlatTable[Hash & pXlatTables->PointerToRefId.HashMask] = XlatTableEntry;
172
173 /* insert pointer into mapping table */
174 expand_pointer_table_if_necessary(pXlatTables, XlatTableEntry->RefId);
175 if (pXlatTables->RefIdToPointer.NumberOfEntries > XlatTableEntry->RefId)
176 {
177 pXlatTables->RefIdToPointer.XlatTable[XlatTableEntry->RefId] = pPointer;
178 pXlatTables->RefIdToPointer.StateTable[XlatTableEntry->RefId] = QueryType;
179 }
180
181 return 0;
182}
_Must_inspect_result_ _In_ KTMOBJECT_TYPE QueryType
Definition: nttmapi.h:404

Referenced by PointerBufferSize(), PointerMarshall(), and test_fullpointer_xlat().

◆ NdrFullPointerQueryRefId()

int WINAPI NdrFullPointerQueryRefId ( PFULL_PTR_XLAT_TABLES  pXlatTables,
ULONG  RefId,
unsigned char  QueryType,
void **  ppPointer 
)

Definition at line 184 of file ndr_fullpointer.c.

187{
188 TRACE("(%p, 0x%lx, %d, %p)\n", pXlatTables, RefId, QueryType, ppPointer);
189
190 if (!RefId)
191 return 1;
192
193 expand_pointer_table_if_necessary(pXlatTables, RefId);
194
195 pXlatTables->NextRefId = max(RefId + 1, pXlatTables->NextRefId);
196
197 if (pXlatTables->RefIdToPointer.NumberOfEntries > RefId)
198 {
199 *ppPointer = pXlatTables->RefIdToPointer.XlatTable[RefId];
200 if (QueryType)
201 {
202 if (pXlatTables->RefIdToPointer.StateTable[RefId] & QueryType)
203 return 1;
204 pXlatTables->RefIdToPointer.StateTable[RefId] |= QueryType;
205 return 0;
206 }
207 else
208 return 0;
209 }
210 *ppPointer = NULL;
211 return 0;
212}
#define max(a, b)
Definition: svc.c:63

Referenced by PointerMemorySize(), PointerUnmarshall(), and test_fullpointer_xlat().

◆ NdrFullPointerXlatFree()

void WINAPI NdrFullPointerXlatFree ( PFULL_PTR_XLAT_TABLES  pXlatTables)

Definition at line 59 of file ndr_fullpointer.c.

60{
61 ULONG i;
62
63 TRACE("(%p)\n", pXlatTables);
64
65 /* free the entries in the table */
66 for (i = 0; i < pXlatTables->PointerToRefId.NumberOfBuckets; i++)
67 {
68 PFULL_PTR_TO_REFID_ELEMENT XlatTableEntry;
69 for (XlatTableEntry = pXlatTables->PointerToRefId.XlatTable[i];
70 XlatTableEntry; )
71 {
72 PFULL_PTR_TO_REFID_ELEMENT Next = XlatTableEntry->Next;
73 free(XlatTableEntry);
74 XlatTableEntry = Next;
75 }
76 }
77
78 free(pXlatTables->RefIdToPointer.XlatTable);
79 free(pXlatTables->RefIdToPointer.StateTable);
80 free(pXlatTables->PointerToRefId.XlatTable);
81
82 free(pXlatTables);
83}
STDMETHOD() Next(THIS_ ULONG celt, IAssociationElement *pElement, ULONG *pceltFetched) PURE

Referenced by ndr_client_call_finally(), NdrMesProcEncodeDecode(), NdrpCompleteAsyncClientCall(), NdrpCompleteAsyncServerCall(), NdrStubCall2(), and test_fullpointer_xlat().

◆ NdrFullPointerXlatInit()

PFULL_PTR_XLAT_TABLES WINAPI NdrFullPointerXlatInit ( ULONG  NumberOfPointers,
XLAT_SIDE  XlatSide 
)

Definition at line 33 of file ndr_fullpointer.c.

35{
36 ULONG NumberOfBuckets;
37 FULL_PTR_XLAT_TABLES *pXlatTables = malloc(sizeof(*pXlatTables));
38
39 TRACE("(%ld, %d)\n", NumberOfPointers, XlatSide);
40
41 if (!NumberOfPointers) NumberOfPointers = 512;
42 NumberOfBuckets = ((NumberOfPointers + 3) & ~3) - 1;
43
44 pXlatTables->RefIdToPointer.XlatTable = calloc(NumberOfPointers, sizeof(void *));
45 pXlatTables->RefIdToPointer.StateTable = calloc(NumberOfPointers, sizeof(unsigned char));
46 pXlatTables->RefIdToPointer.NumberOfEntries = NumberOfPointers;
47
48 TRACE("NumberOfBuckets = %ld\n", NumberOfBuckets);
49 pXlatTables->PointerToRefId.XlatTable = calloc(NumberOfBuckets, sizeof(FULL_PTR_TO_REFID_ELEMENT *));
50 pXlatTables->PointerToRefId.NumberOfBuckets = NumberOfBuckets;
51 pXlatTables->PointerToRefId.HashMask = NumberOfBuckets - 1;
52
53 pXlatTables->NextRefId = 1;
54 pXlatTables->XlatSide = XlatSide;
55
56 return pXlatTables;
57}
#define calloc
Definition: rosglue.h:14
XLAT_SIDE XlatSide
Definition: rpcndr.h:525

Referenced by do_ndr_async_client_call(), ndr_client_call(), NdrAsyncServerCall(), NdrMesProcEncodeDecode(), NdrStubCall2(), and test_fullpointer_xlat().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( rpc  )