Use correct linear pointer when accessing BIOS data area.
[wine.git] / dlls / rpcrt4 / ndr_midl.c
blob1797f9bf2272b67b840af86463fb942cd09c0dd8
1 /*
2 * MIDL proxy/stub stuff
4 * Copyright 2002 Ove Kåven, TransGaming Technologies
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * TODO:
21 * - figure out whether we *really* got this right
22 * - check for errors and throw exceptions
25 #include <stdarg.h>
26 #include <stdio.h>
27 #include <string.h>
28 #include <assert.h>
30 #include "windef.h"
31 #include "winbase.h"
32 #include "winerror.h"
33 #include "winreg.h"
35 #include "objbase.h"
37 #include "rpcproxy.h"
39 #include "wine/debug.h"
41 #include "cpsf.h"
42 #include "ndr_misc.h"
43 #include "rpcndr.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(ole);
47 /***********************************************************************
48 * NdrProxyInitialize [RPCRT4.@]
50 void WINAPI NdrProxyInitialize(void *This,
51 PRPC_MESSAGE pRpcMsg,
52 PMIDL_STUB_MESSAGE pStubMsg,
53 PMIDL_STUB_DESC pStubDescriptor,
54 unsigned int ProcNum)
56 HRESULT hr;
58 TRACE("(%p,%p,%p,%p,%d)\n", This, pRpcMsg, pStubMsg, pStubDescriptor, ProcNum);
59 NdrClientInitializeNew(pRpcMsg, pStubMsg, pStubDescriptor, ProcNum);
60 if (This) StdProxy_GetChannel(This, &pStubMsg->pRpcChannelBuffer);
61 if (pStubMsg->pRpcChannelBuffer) {
62 hr = IRpcChannelBuffer_GetDestCtx(pStubMsg->pRpcChannelBuffer,
63 &pStubMsg->dwDestContext,
64 &pStubMsg->pvDestContext);
66 TRACE("channel=%p\n", pStubMsg->pRpcChannelBuffer);
69 /***********************************************************************
70 * NdrProxyGetBuffer [RPCRT4.@]
72 void WINAPI NdrProxyGetBuffer(void *This,
73 PMIDL_STUB_MESSAGE pStubMsg)
75 HRESULT hr;
76 const IID *riid = NULL;
78 TRACE("(%p,%p)\n", This, pStubMsg);
79 pStubMsg->RpcMsg->BufferLength = pStubMsg->BufferLength;
80 pStubMsg->dwStubPhase = PROXY_GETBUFFER;
81 hr = StdProxy_GetIID(This, &riid);
82 hr = IRpcChannelBuffer_GetBuffer(pStubMsg->pRpcChannelBuffer,
83 (RPCOLEMESSAGE*)pStubMsg->RpcMsg,
84 riid);
85 pStubMsg->BufferStart = pStubMsg->RpcMsg->Buffer;
86 pStubMsg->BufferEnd = pStubMsg->BufferStart + pStubMsg->BufferLength;
87 pStubMsg->Buffer = pStubMsg->BufferStart;
88 pStubMsg->dwStubPhase = PROXY_MARSHAL;
91 /***********************************************************************
92 * NdrProxySendReceive [RPCRT4.@]
94 void WINAPI NdrProxySendReceive(void *This,
95 PMIDL_STUB_MESSAGE pStubMsg)
97 ULONG Status = 0;
98 HRESULT hr;
100 TRACE("(%p,%p)\n", This, pStubMsg);
101 pStubMsg->dwStubPhase = PROXY_SENDRECEIVE;
102 hr = IRpcChannelBuffer_SendReceive(pStubMsg->pRpcChannelBuffer,
103 (RPCOLEMESSAGE*)pStubMsg->RpcMsg,
104 &Status);
105 pStubMsg->dwStubPhase = PROXY_UNMARSHAL;
106 pStubMsg->BufferLength = pStubMsg->RpcMsg->BufferLength;
107 pStubMsg->BufferStart = pStubMsg->RpcMsg->Buffer;
108 pStubMsg->BufferEnd = pStubMsg->BufferStart + pStubMsg->BufferLength;
109 pStubMsg->Buffer = pStubMsg->BufferStart;
111 /* raise exception if call failed */
112 if (hr == RPC_S_CALL_FAILED) RpcRaiseException(*(DWORD*)pStubMsg->Buffer);
113 else if (FAILED(hr)) RpcRaiseException(hr);
116 /***********************************************************************
117 * NdrProxyFreeBuffer [RPCRT4.@]
119 void WINAPI NdrProxyFreeBuffer(void *This,
120 PMIDL_STUB_MESSAGE pStubMsg)
122 HRESULT hr;
124 TRACE("(%p,%p)\n", This, pStubMsg);
125 hr = IRpcChannelBuffer_FreeBuffer(pStubMsg->pRpcChannelBuffer,
126 (RPCOLEMESSAGE*)pStubMsg->RpcMsg);
129 /***********************************************************************
130 * NdrProxyErrorHandler [RPCRT4.@]
132 HRESULT WINAPI NdrProxyErrorHandler(DWORD dwExceptionCode)
134 FIXME("(0x%08lx): semi-stub\n", dwExceptionCode);
135 return MAKE_HRESULT(SEVERITY_ERROR, FACILITY_RPC, RPC_S_CALL_FAILED);
138 /***********************************************************************
139 * NdrStubInitialize [RPCRT4.@]
141 void WINAPI NdrStubInitialize(PRPC_MESSAGE pRpcMsg,
142 PMIDL_STUB_MESSAGE pStubMsg,
143 PMIDL_STUB_DESC pStubDescriptor,
144 LPRPCCHANNELBUFFER pRpcChannelBuffer)
146 TRACE("(%p,%p,%p,%p)\n", pRpcMsg, pStubMsg, pStubDescriptor, pRpcChannelBuffer);
147 NdrServerInitializeNew(pRpcMsg, pStubMsg, pStubDescriptor);
148 pStubMsg->pRpcChannelBuffer = pRpcChannelBuffer;
151 /***********************************************************************
152 * NdrStubGetBuffer [RPCRT4.@]
154 void WINAPI NdrStubGetBuffer(LPRPCSTUBBUFFER This,
155 LPRPCCHANNELBUFFER pRpcChannelBuffer,
156 PMIDL_STUB_MESSAGE pStubMsg)
158 TRACE("(%p,%p)\n", This, pStubMsg);
159 pStubMsg->pRpcChannelBuffer = pRpcChannelBuffer;
160 pStubMsg->RpcMsg->BufferLength = pStubMsg->BufferLength;
161 I_RpcGetBuffer(pStubMsg->RpcMsg); /* ? */
162 pStubMsg->BufferStart = pStubMsg->RpcMsg->Buffer;
163 pStubMsg->BufferEnd = pStubMsg->BufferStart + pStubMsg->BufferLength;
164 pStubMsg->Buffer = pStubMsg->BufferStart;
167 /************************************************************************
168 * NdrClientInitializeNew [RPCRT4.@]
170 void WINAPI NdrClientInitializeNew( PRPC_MESSAGE pRpcMessage, PMIDL_STUB_MESSAGE pStubMsg,
171 PMIDL_STUB_DESC pStubDesc, unsigned int ProcNum )
173 TRACE("(pRpcMessage == ^%p, pStubMsg == ^%p, pStubDesc == ^%p, ProcNum == %d)\n",
174 pRpcMessage, pStubMsg, pStubDesc, ProcNum);
176 assert( pRpcMessage && pStubMsg && pStubDesc );
178 memset(pRpcMessage, 0, sizeof(RPC_MESSAGE));
180 /* not everyone allocates stack space for w2kReserved */
181 memset(pStubMsg, 0, sizeof(*pStubMsg) - sizeof(pStubMsg->w2kReserved));
183 pStubMsg->ReuseBuffer = FALSE;
184 pStubMsg->IsClient = TRUE;
185 pStubMsg->StubDesc = pStubDesc;
186 pStubMsg->pfnAllocate = pStubDesc->pfnAllocate;
187 pStubMsg->pfnFree = pStubDesc->pfnFree;
188 pStubMsg->RpcMsg = pRpcMessage;
190 pRpcMessage->ProcNum = ProcNum;
191 pRpcMessage->RpcInterfaceInformation = pStubDesc->RpcInterfaceInformation;
194 /***********************************************************************
195 * NdrServerInitializeNew [RPCRT4.@]
197 unsigned char* WINAPI NdrServerInitializeNew( PRPC_MESSAGE pRpcMsg, PMIDL_STUB_MESSAGE pStubMsg,
198 PMIDL_STUB_DESC pStubDesc )
200 TRACE("(pRpcMsg == ^%p, pStubMsg == ^%p, pStubDesc == ^%p)\n", pRpcMsg, pStubMsg, pStubDesc);
202 assert( pRpcMsg && pStubMsg && pStubDesc );
204 /* not everyone allocates stack space for w2kReserved */
205 memset(pStubMsg, 0, sizeof(*pStubMsg) - sizeof(pStubMsg->w2kReserved));
207 pStubMsg->ReuseBuffer = TRUE;
208 pStubMsg->IsClient = FALSE;
209 pStubMsg->StubDesc = pStubDesc;
210 pStubMsg->pfnAllocate = pStubDesc->pfnAllocate;
211 pStubMsg->pfnFree = pStubDesc->pfnFree;
212 pStubMsg->RpcMsg = pRpcMsg;
213 pStubMsg->Buffer = pStubMsg->BufferStart = pRpcMsg->Buffer;
214 pStubMsg->BufferLength = pRpcMsg->BufferLength;
215 pStubMsg->BufferEnd = pStubMsg->Buffer + pStubMsg->BufferLength;
217 /* FIXME: determine the proper return value */
218 return NULL;
221 /***********************************************************************
222 * NdrGetBuffer [RPCRT4.@]
224 unsigned char *WINAPI NdrGetBuffer(MIDL_STUB_MESSAGE *stubmsg, unsigned long buflen, RPC_BINDING_HANDLE handle)
226 TRACE("(stubmsg == ^%p, buflen == %lu, handle == %p): wild guess.\n", stubmsg, buflen, handle);
228 assert( stubmsg && stubmsg->RpcMsg );
230 /* I guess this is our chance to put the binding handle into the RPC_MESSAGE */
231 stubmsg->RpcMsg->Handle = handle;
233 stubmsg->RpcMsg->BufferLength = buflen;
234 if (I_RpcGetBuffer(stubmsg->RpcMsg) != S_OK)
235 return NULL;
237 stubmsg->Buffer = stubmsg->BufferStart = stubmsg->RpcMsg->Buffer;
238 stubmsg->BufferLength = stubmsg->RpcMsg->BufferLength;
239 stubmsg->BufferEnd = stubmsg->Buffer + stubmsg->BufferLength;
240 return (stubmsg->Buffer = (unsigned char *)stubmsg->RpcMsg->Buffer);
242 /***********************************************************************
243 * NdrFreeBuffer [RPCRT4.@]
245 void WINAPI NdrFreeBuffer(MIDL_STUB_MESSAGE *pStubMsg)
247 TRACE("(pStubMsg == ^%p): wild guess.\n", pStubMsg);
248 I_RpcFreeBuffer(pStubMsg->RpcMsg);
249 pStubMsg->BufferLength = 0;
250 pStubMsg->Buffer = pStubMsg->BufferEnd = (unsigned char *)(pStubMsg->RpcMsg->Buffer = NULL);
253 /************************************************************************
254 * NdrSendReceive [RPCRT4.@]
256 unsigned char *WINAPI NdrSendReceive( MIDL_STUB_MESSAGE *stubmsg, unsigned char *buffer )
258 TRACE("(stubmsg == ^%p, buffer == ^%p)\n", stubmsg, buffer);
260 /* FIXME: how to handle errors? (raise exception?) */
261 if (!stubmsg) {
262 ERR("NULL stub message. No action taken.\n");
263 return NULL;
265 if (!stubmsg->RpcMsg) {
266 ERR("RPC Message not present in stub message. No action taken.\n");
267 return NULL;
269 if (stubmsg->RpcMsg->Buffer != buffer) {
270 ERR("Ambiguous buffer doesn't match rpc message buffer. No action taken.\n");
271 return NULL;
274 /* not sure where MS does this; for now I'll stick it here */
275 stubmsg->RpcMsg->DataRepresentation = NDR_LOCAL_DATA_REPRESENTATION;
277 if (I_RpcSendReceive(stubmsg->RpcMsg) != RPC_S_OK) {
278 WARN("I_RpcSendReceive did not return success.\n");
281 /* FIXME: is this the right return value? */
282 return NULL;