ReactOS 0.4.15-dev-8434-g155a7c7
ndr_fullpointer.c File Reference
#include <stdarg.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 90 of file ndr_fullpointer.c.

91{
92 if (RefId >= pXlatTables->RefIdToPointer.NumberOfEntries)
93 {
94 pXlatTables->RefIdToPointer.NumberOfEntries = RefId * 2;
95 pXlatTables->RefIdToPointer.XlatTable =
97 pXlatTables->RefIdToPointer.XlatTable,
98 sizeof(void *) * pXlatTables->RefIdToPointer.NumberOfEntries);
99 pXlatTables->RefIdToPointer.StateTable =
101 pXlatTables->RefIdToPointer.StateTable,
102 sizeof(unsigned char) * pXlatTables->RefIdToPointer.NumberOfEntries);
103
104 if (!pXlatTables->RefIdToPointer.XlatTable || !pXlatTables->RefIdToPointer.StateTable)
105 pXlatTables->RefIdToPointer.NumberOfEntries = 0;
106 }
107}
#define GetProcessHeap()
Definition: compat.h:736
#define HeapReAlloc
Definition: compat.h:734
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
struct _FULL_PTR_XLAT_TABLES::@3221 RefIdToPointer

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

◆ NdrFullPointerFree()

int WINAPI NdrFullPointerFree ( PFULL_PTR_XLAT_TABLES  pXlatTables,
void Pointer 
)

Definition at line 214 of file ndr_fullpointer.c.

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

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

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

161{
162 TRACE("(%p, 0x%x, %d, %p)\n", pXlatTables, RefId, QueryType, ppPointer);
163
164 if (!RefId)
165 return 1;
166
167 expand_pointer_table_if_necessary(pXlatTables, RefId);
168
169 pXlatTables->NextRefId = max(RefId + 1, pXlatTables->NextRefId);
170
171 if (pXlatTables->RefIdToPointer.NumberOfEntries > RefId)
172 {
173 *ppPointer = pXlatTables->RefIdToPointer.XlatTable[RefId];
174 if (QueryType)
175 {
176 if (pXlatTables->RefIdToPointer.StateTable[RefId] & QueryType)
177 return 1;
178 pXlatTables->RefIdToPointer.StateTable[RefId] |= QueryType;
179 return 0;
180 }
181 else
182 return 0;
183 }
184 *ppPointer = NULL;
185 return 0;
186}
#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 64 of file ndr_fullpointer.c.

65{
66 ULONG i;
67
68 TRACE("(%p)\n", pXlatTables);
69
70 /* free the entries in the table */
71 for (i = 0; i < pXlatTables->PointerToRefId.NumberOfBuckets; i++)
72 {
73 PFULL_PTR_TO_REFID_ELEMENT XlatTableEntry;
74 for (XlatTableEntry = pXlatTables->PointerToRefId.XlatTable[i];
75 XlatTableEntry; )
76 {
77 PFULL_PTR_TO_REFID_ELEMENT Next = XlatTableEntry->Next;
78 HeapFree(GetProcessHeap(), 0, XlatTableEntry);
79 XlatTableEntry = Next;
80 }
81 }
82
83 HeapFree(GetProcessHeap(), 0, pXlatTables->RefIdToPointer.XlatTable);
84 HeapFree(GetProcessHeap(), 0, pXlatTables->RefIdToPointer.StateTable);
85 HeapFree(GetProcessHeap(), 0, pXlatTables->PointerToRefId.XlatTable);
86
87 HeapFree(GetProcessHeap(), 0, pXlatTables);
88}
#define HeapFree(x, y, z)
Definition: compat.h:735

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 32 of file ndr_fullpointer.c.

34{
35 ULONG NumberOfBuckets;
36 PFULL_PTR_XLAT_TABLES pXlatTables = HeapAlloc(GetProcessHeap(), 0, sizeof(*pXlatTables));
37
38 TRACE("(%d, %d)\n", NumberOfPointers, XlatSide);
39
40 if (!NumberOfPointers) NumberOfPointers = 512;
41 NumberOfBuckets = ((NumberOfPointers + 3) & ~3) - 1;
42
43 pXlatTables->RefIdToPointer.XlatTable =
45 sizeof(void *) * NumberOfPointers);
46 pXlatTables->RefIdToPointer.StateTable =
48 sizeof(unsigned char) * NumberOfPointers);
49 pXlatTables->RefIdToPointer.NumberOfEntries = NumberOfPointers;
50
51 TRACE("NumberOfBuckets = %d\n", NumberOfBuckets);
52 pXlatTables->PointerToRefId.XlatTable =
54 sizeof(PFULL_PTR_TO_REFID_ELEMENT) * NumberOfBuckets);
55 pXlatTables->PointerToRefId.NumberOfBuckets = NumberOfBuckets;
56 pXlatTables->PointerToRefId.HashMask = NumberOfBuckets - 1;
57
58 pXlatTables->NextRefId = 1;
59 pXlatTables->XlatSide = XlatSide;
60
61 return pXlatTables;
62}
XLAT_SIDE XlatSide
Definition: rpcndr.h:489

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

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( rpc  )