ReactOS 0.4.16-dev-1906-g43bc040
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 pXlatTables->RefIdToPointer.XlatTable =
90 realloc(pXlatTables->RefIdToPointer.XlatTable, sizeof(void *) * RefId * 2);
91 pXlatTables->RefIdToPointer.StateTable =
92 realloc(pXlatTables->RefIdToPointer.StateTable, RefId * 2);
93 if (!pXlatTables->RefIdToPointer.XlatTable || !pXlatTables->RefIdToPointer.StateTable)
94 {
95 pXlatTables->RefIdToPointer.NumberOfEntries = 0;
96 return;
97 }
98 memset(pXlatTables->RefIdToPointer.XlatTable + pXlatTables->RefIdToPointer.NumberOfEntries, 0,
99 (RefId * 2 - pXlatTables->RefIdToPointer.NumberOfEntries) * sizeof(void *));
100 memset(pXlatTables->RefIdToPointer.StateTable + pXlatTables->RefIdToPointer.NumberOfEntries, 0,
101 RefId * 2 - pXlatTables->RefIdToPointer.NumberOfEntries);
102 pXlatTables->RefIdToPointer.NumberOfEntries = RefId * 2;
103 }
104}
#define realloc
Definition: debug_ros.c:6
#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 211 of file ndr_fullpointer.c.

212{
213 ULONG Hash = 0;
214 unsigned int i;
215 PFULL_PTR_TO_REFID_ELEMENT XlatTableEntry;
216 ULONG RefId = 0;
217
218 TRACE("(%p, %p)\n", pXlatTables, Pointer);
219
220 if (!Pointer)
221 return 1;
222
223 /* simple hashing algorithm, don't know whether it matches native */
224 for (i = 0; i < sizeof(Pointer); i++)
225 Hash = (Hash * 3) ^ ((unsigned char *)&Pointer)[i];
226
227 XlatTableEntry = pXlatTables->PointerToRefId.XlatTable[Hash & pXlatTables->PointerToRefId.HashMask];
228 for (; XlatTableEntry; XlatTableEntry = XlatTableEntry->Next)
229 if (Pointer == XlatTableEntry->Pointer)
230 {
231 if (XlatTableEntry->State & 0x20)
232 return 0;
233 XlatTableEntry->State |= 0x20;
234 RefId = XlatTableEntry->RefId;
235 break;
236 }
237
238 if (!XlatTableEntry)
239 return 0;
240
241 if (pXlatTables->RefIdToPointer.NumberOfEntries > RefId)
242 {
243 pXlatTables->RefIdToPointer.StateTable[RefId] |= 0x20;
244 return 1;
245 }
246
247 return 0;
248}
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 185 of file ndr_fullpointer.c.

187{
188 ULONG Hash = 0;
189 unsigned int i;
190 PFULL_PTR_TO_REFID_ELEMENT XlatTableEntry;
191
192 TRACE("(%p, 0x%lx, %p)\n", pXlatTables, RefId, pPointer);
193
194 /* simple hashing algorithm, don't know whether it matches native */
195 for (i = 0; i < sizeof(pPointer); i++)
196 Hash = (Hash * 3) ^ ((unsigned char *)&pPointer)[i];
197
198 XlatTableEntry = malloc(sizeof(*XlatTableEntry));
199 XlatTableEntry->Next = pXlatTables->PointerToRefId.XlatTable[Hash & pXlatTables->PointerToRefId.HashMask];
200 XlatTableEntry->Pointer = pPointer;
201 XlatTableEntry->RefId = RefId;
202 XlatTableEntry->State = 0;
203 pXlatTables->PointerToRefId.XlatTable[Hash & pXlatTables->PointerToRefId.HashMask] = XlatTableEntry;
204
205 /* insert pointer into mapping table */
206 expand_pointer_table_if_necessary(pXlatTables, RefId);
207 if (pXlatTables->RefIdToPointer.NumberOfEntries > RefId)
208 pXlatTables->RefIdToPointer.XlatTable[XlatTableEntry->RefId] = pPointer;
209}
#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 106 of file ndr_fullpointer.c.

109{
110 ULONG Hash = 0;
111 unsigned int i;
112 PFULL_PTR_TO_REFID_ELEMENT XlatTableEntry;
113
114 TRACE("(%p, %p, %d, %p)\n", pXlatTables, pPointer, QueryType, pRefId);
115
116 if (!pPointer)
117 {
118 *pRefId = 0;
119 return 1;
120 }
121
122 /* simple hashing algorithm, don't know whether it matches native */
123 for (i = 0; i < sizeof(pPointer); i++)
124 Hash = (Hash * 3) ^ ((unsigned char *)&pPointer)[i];
125
126 XlatTableEntry = pXlatTables->PointerToRefId.XlatTable[Hash & pXlatTables->PointerToRefId.HashMask];
127 for (; XlatTableEntry; XlatTableEntry = XlatTableEntry->Next)
128 if (pPointer == XlatTableEntry->Pointer)
129 {
130 *pRefId = XlatTableEntry->RefId;
131 if (XlatTableEntry->State & QueryType)
132 return 1;
133 XlatTableEntry->State |= QueryType;
134 return 0;
135 }
136
137 XlatTableEntry = malloc(sizeof(*XlatTableEntry));
138 XlatTableEntry->Next = pXlatTables->PointerToRefId.XlatTable[Hash & pXlatTables->PointerToRefId.HashMask];
139 XlatTableEntry->Pointer = pPointer;
140 XlatTableEntry->RefId = *pRefId = pXlatTables->NextRefId++;
141 XlatTableEntry->State = QueryType;
142 pXlatTables->PointerToRefId.XlatTable[Hash & pXlatTables->PointerToRefId.HashMask] = XlatTableEntry;
143
144 /* insert pointer into mapping table */
145 expand_pointer_table_if_necessary(pXlatTables, XlatTableEntry->RefId);
146 if (pXlatTables->RefIdToPointer.NumberOfEntries > XlatTableEntry->RefId)
147 {
148 pXlatTables->RefIdToPointer.XlatTable[XlatTableEntry->RefId] = pPointer;
149 pXlatTables->RefIdToPointer.StateTable[XlatTableEntry->RefId] = QueryType;
150 }
151
152 return 0;
153}
_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 155 of file ndr_fullpointer.c.

158{
159 TRACE("(%p, 0x%lx, %d, %p)\n", pXlatTables, RefId, QueryType, ppPointer);
160
161 if (!RefId)
162 return 1;
163
164 expand_pointer_table_if_necessary(pXlatTables, RefId);
165
166 pXlatTables->NextRefId = max(RefId + 1, pXlatTables->NextRefId);
167
168 if (pXlatTables->RefIdToPointer.NumberOfEntries > RefId)
169 {
170 *ppPointer = pXlatTables->RefIdToPointer.XlatTable[RefId];
171 if (QueryType)
172 {
173 if (pXlatTables->RefIdToPointer.StateTable[RefId] & QueryType)
174 return 1;
175 pXlatTables->RefIdToPointer.StateTable[RefId] |= QueryType;
176 return 0;
177 }
178 else
179 return 0;
180 }
181 *ppPointer = NULL;
182 return 0;
183}
#define NULL
Definition: types.h:112
#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}
#define free
Definition: debug_ros.c:5
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  )