summaryrefslogtreecommitdiffstats
path: root/private/ole32/com/dcomrem/orpc_dbg.c
blob: ef410ce1c549778f6edfa55dad030eaf0ef6a9e0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
//--------------------------------------------------------------------------
// ORPC_DBG.C (tabs 4)
//
//  !!!!!!!!! !!!!!!!!! NOTE NOTE NOTE NOTE !!!!!!!!! !!!!!!!!!!
//
//          SEND MAIL TO SANJAYS  IF YOU MODIFY THIS FILE!
//            WE MUST KEEP OLE AND LANGUAGES IN SYNC!
//
//  !!!!!!!!! !!!!!!!!! NOTE NOTE NOTE NOTE !!!!!!!!! !!!!!!!!!!
//
// Created 08-Oct-1993 by Mike Morearty.  The master copy of this file
// is in the LANGAPI project owned by the Languages group.
//
// Helper functions for OLE RPC debugging.
//--------------------------------------------------------------------------

#include <windows.h>
#ifndef _CHICAGO_
#include <tchar.h>
#endif

#include "orpc_dbg.h"

static TCHAR tszAeDebugName[] = TEXT("AeDebug");
static TCHAR tszAutoName[] = TEXT("Auto");
static TCHAR tszOldAutoName[] = TEXT("OldAuto");
static TCHAR tszDebugObjectRpcEnabledName[] =
#ifdef _CHICAGO_
	"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\DebugObjectRPCEnabled";
#else
	TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\DebugObjectRPCEnabled");
#endif

// Emit the ORPC signature into the bytestream of the function
#define ORPC_EMIT_SIGNATURE()	'M', 'A', 'R', 'B',

// Emit a LONG into the bytestream
#define ORPC_EMIT_LONG(l)	\
	((l >>  0) & 0xFF),		\
	((l >>  8) & 0xFF),		\
	((l >> 16) & 0xFF),		\
	((l >> 24) & 0xFF),

// Emit a WORD into the bytestream
#define ORPC_EMIT_WORD(w)	\
	((w >> 0) & 0xFF),		\
	((w >> 8) & 0xFF),

// Emit a BYTE into the bytestream
#define ORPC_EMIT_BYTE(b)	\
	b,

// Emit a GUID into the bytestream
#define ORPC_EMIT_GUID(l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8)	\
	ORPC_EMIT_LONG(l)												\
	ORPC_EMIT_WORD(w1) ORPC_EMIT_WORD(w2)							\
	ORPC_EMIT_BYTE(b1) ORPC_EMIT_BYTE(b2)							\
	ORPC_EMIT_BYTE(b3) ORPC_EMIT_BYTE(b4)							\
	ORPC_EMIT_BYTE(b5) ORPC_EMIT_BYTE(b6)							\
	ORPC_EMIT_BYTE(b7) ORPC_EMIT_BYTE(b8)

BYTE rgbClientGetBufferSizeSignature[] =
{
	ORPC_EMIT_SIGNATURE()
	ORPC_EMIT_GUID(0x9ED14F80, 0x9673, 0x101A, 0xB0, 0x7B,
		0x00, 0xDD, 0x01, 0x11, 0x3F, 0x11)
	ORPC_EMIT_LONG(0)
};

BYTE rgbClientFillBufferSignature[] =
{
	ORPC_EMIT_SIGNATURE()
	ORPC_EMIT_GUID(0xDA45F3E0, 0x9673, 0x101A, 0xB0, 0x7B,
		0x00, 0xDD, 0x01, 0x11, 0x3F, 0x11)
	ORPC_EMIT_LONG(0)
};

BYTE rgbClientNotifySignature[] =
{
	ORPC_EMIT_SIGNATURE()
	ORPC_EMIT_GUID(0x4F60E540, 0x9674, 0x101A, 0xB0, 0x7B,
		0x00, 0xDD, 0x01, 0x11, 0x3F, 0x11)
	ORPC_EMIT_LONG(0)
};

BYTE rgbServerNotifySignature[] =
{
	ORPC_EMIT_SIGNATURE()
	ORPC_EMIT_GUID(0x1084FA00, 0x9674, 0x101A, 0xB0, 0x7B,
		0x00, 0xDD, 0x01, 0x11, 0x3F, 0x11)
	ORPC_EMIT_LONG(0)
};

BYTE rgbServerGetBufferSizeSignature[] =
{
	ORPC_EMIT_SIGNATURE()
	ORPC_EMIT_GUID(0x22080240, 0x9674, 0x101A, 0xB0, 0x7B,
		0x00, 0xDD, 0x01, 0x11, 0x3F, 0x11)
	ORPC_EMIT_LONG(0)
};

BYTE rgbServerFillBufferSignature[] =
{
	ORPC_EMIT_SIGNATURE()
	ORPC_EMIT_GUID(0x2FC09500, 0x9674, 0x101A, 0xB0, 0x7B,
		0x00, 0xDD, 0x01, 0x11, 0x3F, 0x11)
	ORPC_EMIT_LONG(0)
};

// Macro to deal with assigning refiid for both C and C++.
#if defined(__cplusplus)
#define ASSIGN_REFIID(orpc_all, iid)	((orpc_all).refiid = &iid)
#else
#define ASSIGN_REFIID(orpc_all, iid)	((orpc_all).refiid = iid)
#endif

#pragma code_seg(".orpc")

//--------------------------------------------------------------------------
// SzSubStr()
//
// Find str2 in str2
//--------------------------------------------------------------------------

static LPTSTR SzSubStr(LPTSTR str1, LPTSTR str2)
{
	CharLower(str1);

#ifdef _CHICAGO_
	return strstr(str1, str2);
#else
	return _tcsstr(str1, str2);
#endif
}

//--------------------------------------------------------------------------
// DebugORPCSetAuto()
//
// Sets the "Auto" value in the "AeDebug" key to "1", and saves info
// necessary to restore the previous value later.
//--------------------------------------------------------------------------

BOOL WINAPI DebugORPCSetAuto(VOID)
{
	HKEY	hkey;
	TCHAR	rgtchDebugger[256];	// 256 is the length NT itself uses for this
	TCHAR	rgtchAuto[256];
	TCHAR	rgtchOldAuto[2];	// don't need to get the whole thing

	// If the "DebugObjectRPCEnabled" key does not exist, then do not
	// cause any notifications
	if (RegOpenKey(HKEY_LOCAL_MACHINE, tszDebugObjectRpcEnabledName, &hkey))
		return FALSE;
	RegCloseKey(hkey);

	// If the AeDebug debugger string does not exist, or if it contains
	// "drwtsn32" anywhere in it, then don't cause any notifications,
	// because Dr. Watson is not capable of fielding OLE notifications.
	if (!GetProfileString(tszAeDebugName, TEXT("Debugger"), TEXT(""),
			rgtchDebugger, sizeof(rgtchDebugger)) ||
		SzSubStr(rgtchDebugger, TEXT("drwtsn32")) != NULL)
	{
		return FALSE;
	}

	// Must ensure that the "Auto" value in the AeDebug registry key
	// is set to "1", so that the embedded INT 3 below will cause the
	// debugger to be automatically spawned if it doesn't already
	// exist.

	// Get old "Auto" value
	GetProfileString(tszAeDebugName, tszAutoName, TEXT(""),
		rgtchAuto, sizeof(rgtchAuto));

	// If "OldAuto" already existed, then it's probably left over from
	// a previous invocation of the debugger, so don't overwrite it.
	// Otherwise, copy "Auto" value to "OldAuto"
	if (!GetProfileString(tszAeDebugName, tszOldAutoName, TEXT(""),
		rgtchOldAuto, sizeof(rgtchOldAuto)))
	{
		if (!WriteProfileString(tszAeDebugName, tszOldAutoName, rgtchAuto))
			return FALSE;
	}

	// Change "Auto" value to "1"
	if (!WriteProfileString(tszAeDebugName, tszAutoName, TEXT("1")))
		return FALSE;

	return TRUE;
}

//--------------------------------------------------------------------------
// DebugORPCRestoreAuto()
//
// Restores the previous value of the "Auto" value in the AeDebug key.
//--------------------------------------------------------------------------

VOID WINAPI DebugORPCRestoreAuto(VOID)
{
	TCHAR	rgtchAuto[256];

	// Restore old Auto value (or delete it if it didn't exist before).
	// Very minor bug here: if "Auto" was previously "", then we will
	// now delete it.  That's not a big deal though, as an empty "Auto"
	// and a nonexistent one have the same effect.
	GetProfileString(tszAeDebugName, tszOldAutoName, TEXT(""),
		rgtchAuto, sizeof(rgtchAuto));

	WriteProfileString(tszAeDebugName, tszAutoName,
		rgtchAuto[0] ? rgtchAuto : NULL);

	// Delete OldAuto value
	WriteProfileString(tszAeDebugName, tszOldAutoName, NULL);
}

 // This pragma is necessary in case the compiler chooses not to inline these
// functions (e.g. in a debug build, when optimizations are off).

#pragma code_seg(".orpc")

__inline DWORD WINAPI OrpcBreakpointFilter(
	LPEXCEPTION_POINTERS lpExcptPtr,
	BOOL *lpAeDebugAttached )									\
{
	BOOL fAeDebugAttached = FALSE;
	DWORD dwRet;
																
	if ( lpExcptPtr->ExceptionRecord->ExceptionCode == EXCEPTION_ORPC_DEBUG )	
	{
		if  ( UnhandledExceptionFilter(lpExcptPtr) == EXCEPTION_CONTINUE_SEARCH )
		{
			// It is important that we don't return EXCEPTION_CONTINUE_SEARCH.
			// This is because there might an handler up the stack which could
			// handle this exception. Just set the flag indicating that a
			// debugger is now attached.
			
			fAeDebugAttached = TRUE;
		}
		dwRet = EXCEPTION_EXECUTE_HANDLER;
	}
	else
	{
		// Not one of our exceptions.
		dwRet = EXCEPTION_CONTINUE_SEARCH;
	}

	if ( lpAeDebugAttached != NULL )
		(*lpAeDebugAttached) = fAeDebugAttached;
	
	return dwRet;	
}
							
ULONG WINAPI DebugORPCClientGetBufferSize(
	RPCOLEMESSAGE *		pMessage,
	REFIID				iid,
	void *				reserved,
	IUnknown *			pUnkProxyMgr,
	LPORPC_INIT_ARGS	lpInitArgs,
	BOOL				fHookEnabled)
{
	ULONG	cbBuffer = 0;
	ORPC_DBG_ALL	orpc_all = {0};
	ORPC_DBG_ALL *  lpOrpcAll = &orpc_all;

	if (!fHookEnabled)
		return 0; // We should be able to assert that this never happens.

	orpc_all.pSignature = rgbClientGetBufferSizeSignature;
	orpc_all.pMessage = pMessage;
	orpc_all.reserved = reserved;
	orpc_all.pUnkProxyMgr = pUnkProxyMgr;
	orpc_all.lpcbBuffer = &cbBuffer;
	ASSIGN_REFIID(orpc_all, iid);

	if ( lpInitArgs == NULL || lpInitArgs->lpIntfOrpcDebug == NULL )
	{
		// Do Orpc debug notification using an exception.
		__try
		{
			RaiseException(EXCEPTION_ORPC_DEBUG, 0, 1, (LPDWORD)&lpOrpcAll);
		}
		__except(OrpcBreakpointFilter(GetExceptionInformation(), NULL))
		{
			// this just goes down to the  to the return.
		}
	}
	else
	{
		IOrpcDebugNotify __RPC_FAR *lpIntf = lpInitArgs->lpIntfOrpcDebug;

		// call the appropriate method in the registered interface
		// ( this is typically used by in-proc debuggers)
#if defined(__cplusplus) && !defined(CINTERFACE)
		lpIntf->ClientGetBufferSize(lpOrpcAll);
#else
		lpIntf->lpVtbl->ClientGetBufferSize(lpIntf, lpOrpcAll);
#endif
		
	}

	return cbBuffer;
}

//--------------------------------------------------------------------------

void WINAPI DebugORPCClientFillBuffer(
	RPCOLEMESSAGE *		pMessage,
	REFIID				iid,
	void *				reserved,
	IUnknown *			pUnkProxyMgr,
	void *				pvBuffer,
	ULONG				cbBuffer,
	LPORPC_INIT_ARGS	lpInitArgs,
	BOOL				fHookEnabled)
{
	ORPC_DBG_ALL	orpc_all = {0};
	ORPC_DBG_ALL *  lpOrpcAll = &orpc_all;

	if (!fHookEnabled)
		return; // We should be able to assert that this never happens

	orpc_all.pSignature = rgbClientFillBufferSignature;

	orpc_all.pMessage = pMessage;
	orpc_all.reserved = reserved;
	orpc_all.pUnkProxyMgr = pUnkProxyMgr;
	ASSIGN_REFIID(orpc_all, iid);

	orpc_all.pvBuffer = pvBuffer;
	orpc_all.cbBuffer = cbBuffer;

	
	if ( lpInitArgs == NULL || lpInitArgs->lpIntfOrpcDebug == NULL )
	{
		// Do Orpc debug notification using an exception.
		__try
		{
			RaiseException(EXCEPTION_ORPC_DEBUG, 0, 1, (LPDWORD)&lpOrpcAll);
		}
		__except(OrpcBreakpointFilter(GetExceptionInformation(), NULL))
		{
			// this just returns.
		}
	}
	else
	{
		IOrpcDebugNotify __RPC_FAR *lpIntf = lpInitArgs->lpIntfOrpcDebug;

		// call the appropriate method in the registered interface
		// ( this is typically used by in-proc debuggers)
#if defined(__cplusplus) && !defined(CINTERFACE)
		lpIntf->ClientFillBuffer(lpOrpcAll);
#else
		lpIntf->lpVtbl->ClientFillBuffer(lpIntf, lpOrpcAll);
#endif	
	}
}

//--------------------------------------------------------------------------

// This special value is to ensure backward compatibility with VC 2.0.
// It is not exposed in the header files. The behavior if this is the value
// in the first four bytes of the debug packet, should be identical to
// ORPC_DEBUG_ALWAYS.

#define ORPC_COMPATIBILITY_CODE		(0x4252414DL)

void WINAPI DebugORPCClientNotify(
	RPCOLEMESSAGE *		pMessage,
	REFIID				iid,
	void *				reserved,
	IUnknown *			pUnkProxyMgr,
	HRESULT				hresult,
	void *				pvBuffer,
	ULONG				cbBuffer,
	LPORPC_INIT_ARGS	lpInitArgs,
	BOOL				fHookEnabled)
{
	ORPC_DBG_ALL orpc_all = {0};
	ORPC_DBG_ALL * lpOrpcAll = &orpc_all;
	BOOL fRethrow = FALSE;

	// First check to see if the debugger on the other side
	// wants us to notify this side if the hook is not enabled.
	if (!fHookEnabled)
	{
		if (cbBuffer >= 4)
		{
			LONG orpcCode = *(LONG *)pvBuffer;
			if ( orpcCode == ORPC_DEBUG_IF_HOOK_ENABLED)
				return;		// No notification in this case.
		}
	}

	orpc_all.pSignature = rgbClientNotifySignature;

	orpc_all.pMessage = pMessage;
	orpc_all.reserved = reserved;
	orpc_all.pUnkProxyMgr = pUnkProxyMgr;
	orpc_all.hresult = hresult;
	ASSIGN_REFIID(orpc_all, iid);

	orpc_all.pvBuffer = pvBuffer;
	orpc_all.cbBuffer = cbBuffer;

	if ( lpInitArgs == NULL || lpInitArgs->lpIntfOrpcDebug == NULL )
	{
		if (DebugORPCSetAuto())
		{
			// Do Orpc debug notification using an exception.
			__try
			{
				RaiseException(EXCEPTION_ORPC_DEBUG, 0, 1, (LPDWORD)&lpOrpcAll);
			}
			__except(OrpcBreakpointFilter(GetExceptionInformation(), &fRethrow))
			{
				// Fall through.
			}

			if (fRethrow)
			{
				// At this point we are sure that a debugger is attached
				// so we raise this exception outside of a __try block.
				RaiseException(EXCEPTION_ORPC_DEBUG, 0, 1, (LPDWORD)&lpOrpcAll);
			}

			DebugORPCRestoreAuto();
		}
	
	}
	else
	{
		IOrpcDebugNotify __RPC_FAR *lpIntf = lpInitArgs->lpIntfOrpcDebug;

		// call the appropriate method in the registered interface
		// ( this is typically used by in-proc debuggers)
#if defined(__cplusplus) && !defined(CINTERFACE)
		lpIntf->ClientNotify(lpOrpcAll);
#else
		lpIntf->lpVtbl->ClientNotify(lpIntf, lpOrpcAll);
#endif
	}

}

//--------------------------------------------------------------------------

void WINAPI DebugORPCServerNotify(
	RPCOLEMESSAGE *		pMessage,
	REFIID				iid,
	IRpcChannelBuffer *	pChannel,
	void *				pInterface,
	IUnknown *			pUnkObject,
	void *				pvBuffer,
	ULONG				cbBuffer,
	LPORPC_INIT_ARGS	lpInitArgs,
	BOOL				fHookEnabled)

{
	ORPC_DBG_ALL orpc_all = {0};
	ORPC_DBG_ALL * lpOrpcAll = &orpc_all;
	BOOL fRethrow = FALSE;

	// First check to see if the debugger on the other side
	// wants us to notify this side if the hook is not enabled.
	if (!fHookEnabled)
	{
		if (cbBuffer >= 4)
		{
			LONG orpcCode = *(LONG *)pvBuffer;
			if ( orpcCode == ORPC_DEBUG_IF_HOOK_ENABLED)
				return;		// No notification in this case.
		}
	}

	orpc_all.pSignature = rgbServerNotifySignature;

	orpc_all.pMessage = pMessage;
	orpc_all.pChannel = pChannel;
	orpc_all.pInterface = pInterface;
	orpc_all.pUnkObject = pUnkObject;
	ASSIGN_REFIID(orpc_all, iid);
	
	orpc_all.pvBuffer = pvBuffer;
	orpc_all.cbBuffer = cbBuffer;

	if ( lpInitArgs == NULL || lpInitArgs->lpIntfOrpcDebug == NULL )
	{
		if (DebugORPCSetAuto())
		{
			// Do Orpc debug notification using an exception.
			__try
			{
				RaiseException(EXCEPTION_ORPC_DEBUG, 0, 1, (LPDWORD)&lpOrpcAll);
			}
			__except(OrpcBreakpointFilter(GetExceptionInformation(), &fRethrow))
			{
				// Fall through
			}

			if (fRethrow)
			{
				// At this point we are sure that a debugger is attached
				// so we raise this exception outside of a __try block.
				RaiseException(EXCEPTION_ORPC_DEBUG, 0, 1, (LPDWORD)&lpOrpcAll);
			}

			DebugORPCRestoreAuto();
		}
	
	}
	else
	{
		IOrpcDebugNotify __RPC_FAR *lpIntf = lpInitArgs->lpIntfOrpcDebug;

		// call the appropriate method in the registered interface
		// ( this is typically used by in-proc debuggers)
#if defined(__cplusplus) && !defined(CINTERFACE)
		lpIntf->ServerNotify(lpOrpcAll);
#else
		lpIntf->lpVtbl->ServerNotify(lpIntf, lpOrpcAll);
#endif
	}

}

//--------------------------------------------------------------------------

ULONG WINAPI DebugORPCServerGetBufferSize(
	RPCOLEMESSAGE *		pMessage,
	REFIID				iid,
	IRpcChannelBuffer *	pChannel,
	void *				pInterface,
	IUnknown *			pUnkObject,
	LPORPC_INIT_ARGS	lpInitArgs,
	BOOL				fHookEnabled)

{
	ULONG	cbBuffer = 0;
	ORPC_DBG_ALL orpc_all = {0};
	ORPC_DBG_ALL * lpOrpcAll = &orpc_all;

	if (!fHookEnabled)
		return 0; // We should be able to assert that this never happens.

	orpc_all.pSignature = rgbServerGetBufferSizeSignature;

	orpc_all.pMessage = pMessage;
	orpc_all.pChannel = pChannel;
	orpc_all.pInterface = pInterface;
	orpc_all.pUnkObject = pUnkObject;
	orpc_all.lpcbBuffer = &cbBuffer;
	ASSIGN_REFIID(orpc_all, iid);

	if ( lpInitArgs == NULL || lpInitArgs->lpIntfOrpcDebug == NULL )
	{
		// Do Orpc debug notification using an exception.
		__try
		{
			RaiseException(EXCEPTION_ORPC_DEBUG, 0, 1, (LPDWORD)&lpOrpcAll);
		}
		__except(OrpcBreakpointFilter(GetExceptionInformation(), NULL))
		{
			// this just goes down to the return.
		}
	}
	else
	{
		IOrpcDebugNotify __RPC_FAR *lpIntf = lpInitArgs->lpIntfOrpcDebug;

		// call the appropriate method in the registered interface
		// ( this is typically used by in-proc debuggers)
#if defined(__cplusplus) && !defined(CINTERFACE)
		lpIntf->ServerGetBufferSize(lpOrpcAll);
#else
		lpIntf->lpVtbl->ServerGetBufferSize(lpIntf, lpOrpcAll);
#endif
	}

	return cbBuffer;
}

//--------------------------------------------------------------------------

void WINAPI DebugORPCServerFillBuffer(
	RPCOLEMESSAGE *		pMessage,
	REFIID				iid,
	IRpcChannelBuffer *	pChannel,
	void *				pInterface,
	IUnknown *			pUnkObject,
	void *				pvBuffer,
	ULONG				cbBuffer,
	LPORPC_INIT_ARGS	lpInitArgs,
	BOOL				fHookEnabled)
{
	ORPC_DBG_ALL orpc_all = {0};
	ORPC_DBG_ALL * lpOrpcAll = &orpc_all;

	if (!fHookEnabled)
		return;	// We should be able to assert that this never happens.

	orpc_all.pSignature = rgbServerFillBufferSignature;

	orpc_all.pMessage = pMessage;
	orpc_all.pChannel = pChannel;
	orpc_all.pInterface = pInterface;
	orpc_all.pUnkObject = pUnkObject;
	ASSIGN_REFIID(orpc_all, iid);

	orpc_all.pvBuffer = pvBuffer;
	orpc_all.cbBuffer = cbBuffer;

	if ( lpInitArgs == NULL || lpInitArgs->lpIntfOrpcDebug == NULL )
	{
		// Do Orpc debug notification using an exception.
		__try
		{
			RaiseException(EXCEPTION_ORPC_DEBUG, 0, 1, (LPDWORD)&lpOrpcAll);
		}
		__except(OrpcBreakpointFilter(GetExceptionInformation(), NULL))
		{
			// this just returns.
		}
	}
	else
	{
		IOrpcDebugNotify __RPC_FAR *lpIntf = lpInitArgs->lpIntfOrpcDebug;

		// call the appropriate method in the registered interface
		// ( this is typically used by in-proc debuggers)
#if defined(__cplusplus) && !defined(CINTERFACE)
		lpIntf->ServerFillBuffer(lpOrpcAll);
#else
		lpIntf->lpVtbl->ServerFillBuffer(lpIntf, lpOrpcAll);
#endif
	}
}

// WARNING: there is no way to "pop" to the previously active code_seg:
// this will revert to what the code seg was when compilation began.
#pragma code_seg()