File: IISUnsafeMethods.cs

package info (click to toggle)
mono 6.8.0.105%2Bdfsg-3.3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,284,512 kB
  • sloc: cs: 11,172,132; xml: 2,850,069; ansic: 671,653; cpp: 122,091; perl: 59,366; javascript: 30,841; asm: 22,168; makefile: 20,093; sh: 15,020; python: 4,827; pascal: 925; sql: 859; sed: 16; php: 1
file content (711 lines) | stat: -rw-r--r-- 29,386 bytes parent folder | download | duplicates (7)
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
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
//------------------------------------------------------------------------------
// <copyright file="IISUnsafeMethods.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//------------------------------------------------------------------------------

namespace System.Web.Hosting {
    using System;
    using System.Configuration;
    using System.Text;
    using System.Runtime.InteropServices;
    using System.Diagnostics.CodeAnalysis;

    [
    System.Runtime.InteropServices.ComVisible(false),
    System.Security.SuppressUnmanagedCodeSecurityAttribute()
    ]
    // contains only method decls and data, so no instantiation
    internal unsafe static class UnsafeIISMethods {

        const string _IIS_NATIVE_DLL = ModName.MGDENG_FULL_NAME;
        static internal readonly IntPtr INVALID_HANDLE_VALUE = new IntPtr(-1);

        [DllImport(_IIS_NATIVE_DLL)]
        internal unsafe static extern int MgdGetRequestBasics(
            IntPtr           pRequestContext,
            out int          pContentType,
            out int          pContentTotalLength,
            out IntPtr       pPathTranslated,
            out int          pcchPathTranslated,
            out IntPtr       pCacheUrl,
            out int          pcchCacheUrl,
            out IntPtr       pHttpMethod,
            out IntPtr       pCookedUrl);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdGetHeaderChanges(
            IntPtr           pRequestContext,
            bool             fResponse,
            out IntPtr       knownHeaderSnapshot,
            out int          unknownHeaderSnapshotCount,
            out IntPtr       unknownHeaderSnapshotNames,
            out IntPtr       unknownHeaderSnapshotValues,
            out IntPtr       diffKnownIndicies,
            out int          diffUnknownCount,
            out IntPtr       diffUnknownIndicies);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdGetServerVarChanges(
            IntPtr           pRequestContext,
            out int          count,
            out IntPtr       names,
            out IntPtr       values,
            out int          diffCount,
            out IntPtr       diffIndicies);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern int MgdGetServerVariableW(
            IntPtr           pHandler,
            string           pszVarName,
            out IntPtr       ppBuffer,
            out int          pcchBufferSize);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern int MgdGetServerVariableA(
            IntPtr           pHandler,
            string           pszVarName,
            out IntPtr       ppBuffer,
            out int          pcchBufferSize);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern IntPtr MgdGetStopListeningEventHandle();

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern void MgdSetBadRequestStatus(
            IntPtr           pHandler);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern void MgdSetManagedHttpContext(
            IntPtr           pHandler,
            IntPtr           pManagedHttpContext);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern int MgdSetStatusW(
            IntPtr           pRequestContext,
            int              dwStatusCode,
            int              dwSubStatusCode,
            string           pszReason,
            string           pszErrorDescription /* optional, can be null */,
            bool             fTrySkipCustomErrors);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdSetKnownHeader(
            IntPtr           pRequestContext,
            bool             fRequest,
            bool             fReplace,
            ushort           uHeaderIndex,
            byte[]           value,
            ushort           valueSize);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdSetUnknownHeader(
            IntPtr           pRequestContext,
            bool             fRequest,
            bool             fReplace,
            byte []          header,
            byte []          value,
            ushort           valueSize);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdFlushCore(
            IntPtr    pRequestContext,
            bool      keepConnected,
            int       numBodyFragments,
            IntPtr[]  bodyFragments,
            int[]     bodyFragmentLengths,
            int[]     fragmentsNative);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdSetKernelCachePolicy(
            IntPtr    pHandler,
            int       secondsToLive);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern int MgdFlushKernelCache(
            string    cacheKey);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern void MgdDisableKernelCache(
            IntPtr    pHandler);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern void MgdDisableUserCache(
            IntPtr pHandler);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern int MgdRegisterEventSubscription(
            IntPtr           pAppContext,
            string           pszModuleName,
            [MarshalAs(UnmanagedType.U4)]
            RequestNotification requestNotifications,
            [MarshalAs(UnmanagedType.U4)]
            RequestNotification postRequestNotifications,
            string           pszModuleType,
            string           pszModulePrecondition,
            IntPtr           moduleSpecificData,
            bool             useHighPriority);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern void MgdIndicateCompletion(
            IntPtr           pHandler,
            [MarshalAs(UnmanagedType.U4)]
            ref RequestNotificationStatus notificationStatus );

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdInsertEntityBody(
            IntPtr           pHandler,
            byte[]           buffer,
            int              offset,
            int              count);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern int MgdPostCompletion(
            IntPtr           pHandler,
            [MarshalAs(UnmanagedType.U4)]
            RequestNotificationStatus notificationStatus );

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern int MgdReadEntityBody(
            IntPtr           pHandler,
            byte[]           pBuffer,
            int              dwOffset,
            int              dwBytesToRead,
            bool             fAsync,
            out int          pBytesRead,
            out IntPtr       ppAsyncReceiveBuffer );

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern int MgdGetCorrelationIdHeader(
            IntPtr          pHandler,
            out IntPtr      correlationId,
            out ushort      correlationIdLength,
            out bool        base64BinaryFormat);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern int MgdGetUserToken(
            IntPtr           pHandler,
            out IntPtr       pToken );

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern int MgdGetVirtualToken(
            IntPtr           pHandler,
            out IntPtr       pToken );

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern bool MgdIsClientConnected(
            IntPtr           pHandler);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern bool MgdIsHandlerExecutionDenied(
            IntPtr           pHandler);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        [SuppressMessage("Microsoft.Security", "CA2118:ReviewSuppressUnmanagedCodeSecurityUsage", Justification = "We carefully control this method's sole caller.")]
        internal static extern void MgdAbortConnection(
            IntPtr           pHandler);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern void MgdCloseConnection(
            IntPtr           pHandler);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern int MgdGetHandlerTypeString(
            IntPtr           pHandler,
            out IntPtr       ppszTypeString,
            out int          pcchTypeString);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern int MgdGetApplicationInfo(
            IntPtr           pHandler,
            out IntPtr       pVirtualPath,
            out int          cchVirtualPath,
            out IntPtr       pPhysPath,
            out int          cchPhysPath);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern int MgdGetUriPath(
            IntPtr           pHandler,
            out IntPtr       ppPath,
            out int          pcchPath,
            bool             fIncludePathInfo,
            bool             fUseParentContext);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdGetPreloadedContent(
            IntPtr           pHandler,
            byte[]           pBuffer,
            int              lOffset,
            int              cbLen,
            out int          pcbReceived);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdGetPreloadedSize(
            IntPtr           pHandler,
            out int          pcbAvailable);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern int MgdGetPrincipal(
            IntPtr           pHandler,
            int              dwRequestingAppDomainId,
            out IntPtr       pToken,
            out IntPtr       ppAuthType,
            ref int          pcchAuthType,
            out IntPtr       ppUserName,
            ref int          pcchUserName,
            out IntPtr       pManagedPrincipal);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern int MgdIsInRole(
            IntPtr           pHandler,
            string           pszRoleName,
            out bool         pfIsInRole);
            
        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern IntPtr MgdAllocateRequestMemory(
            IntPtr           pHandler,
            int              cbSize);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern int MgdAppDomainShutdown(
            IntPtr appContext );


        // Buffer pool methods
        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern IntPtr /* W3_MGD_BUFFER_POOL* */
            MgdGetBufferPool(int cbBufferSize);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern IntPtr /* PBYTE * */
            MgdGetBuffer(IntPtr pPool);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern IntPtr /* W3_MGD_BUFFER_POOL* */
            MgdReturnBuffer(IntPtr pBuffer);


        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern int /* DWORD */
           MgdGetLocalPort(IntPtr context);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern int /* DWORD */
           MgdGetRemotePort(IntPtr context);


        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdGetUserAgent(
            IntPtr           pRequestContext,
            out IntPtr       pBuffer,
            out int          cbBufferSize);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdGetCookieHeader(
            IntPtr           pRequestContext,
            out IntPtr       pBuffer,
            out int          cbBufferSize);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern int MgdRewriteUrl(
            IntPtr           pRequestContext,
            string           pszUrl,
            bool             fResetQueryString );

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdGetMaxConcurrentRequestsPerCPU();

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdGetMaxConcurrentThreadsPerCPU();

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdSetMaxConcurrentRequestsPerCPU(int value);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdSetMaxConcurrentThreadsPerCPU(int value);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdGetCurrentModuleName(
            IntPtr           pHandler,
            out IntPtr       pBuffer,
            out int          cbBufferSize);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdGetCurrentNotification(
            IntPtr           pRequestContext);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern void MgdDisableNotifications(
            IntPtr           pRequestContext,
            [MarshalAs(UnmanagedType.U4)]
            RequestNotification notifications,
            [MarshalAs(UnmanagedType.U4)]
            RequestNotification postNotifications);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern void MgdSuppressSendResponseNotifications(
            IntPtr pRequestContext);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdGetNextNotification(
            IntPtr           pRequestContext,
            [MarshalAs(UnmanagedType.U4)]
            RequestNotificationStatus dwStatus);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdClearResponse(
            IntPtr           pRequestContext,
            bool             fClearEntity,
            bool             fClearHeaders);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdCreateNativeConfigSystem(
            out IntPtr       ppConfigSystem);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdReleaseNativeConfigSystem(
            IntPtr           pConfigSystem);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdGetRequestTraceGuid(
            IntPtr           pRequestContext,
            out Guid         traceContextId);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdGetStatusChanges(
            IntPtr           pRequestContext,
            out ushort       statusCode,
            out ushort       subStatusCode,
            out IntPtr       pBuffer,
            out ushort       cbBufferSize);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdGetResponseChunks(
            IntPtr           pRequestContext,
            ref int          fragmentCount,
            IntPtr[]         bodyFragments,
            int[]            bodyFragmentLengths,
            int[]            fragmentChunkType);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdEtwGetTraceConfig(
            IntPtr           pRequestContext,
            out bool         providerEnabled,
            out int          flags,
            out int          level);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern int MgdEmitSimpleTrace(
            IntPtr           pRequestContext,
            int              type,
            string           eventData);

        [DllImport(_IIS_NATIVE_DLL, CharSet = CharSet.Unicode)]
        internal static extern int MgdEmitWebEventTrace(
            IntPtr           pRequestContext,
            int              webEventType,
            int              fieldCount,
            string[]         fieldNames,
            int[]            fieldTypes,
            string[]         fieldData);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern int MgdSetRequestPrincipal(
            IntPtr           pRequestContext,
            string           userName,
            string           authType,
            IntPtr           token);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern bool MgdCanDisposeManagedContext(
            IntPtr           pRequestContext,
            [MarshalAs(UnmanagedType.U4)]
            RequestNotificationStatus dwStatus);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern bool MgdIsLastNotification(
            IntPtr           pRequestContext,
            [MarshalAs(UnmanagedType.U4)]
            RequestNotificationStatus dwStatus);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern bool MgdIsWithinApp(
            IntPtr            pConfigSystem,
            string            siteName,
            string            appPath,
            string            virtualPath);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdGetSiteNameFromId(
            IntPtr            pConfigSystem,
            [MarshalAs(UnmanagedType.U4)]
            uint              siteId,
            out IntPtr        bstrSiteName,
            out int           cchSiteName);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern int MgdGetAppPathForPath(
            IntPtr            pConfigSystem,
            [MarshalAs(UnmanagedType.U4)]
            uint              siteId,
            string            virtualPath,
            out IntPtr        bstrPath,
            out int           cchPath);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdGetMemoryLimitKB(
            out long          limit);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdGetMimeMapCollection(
            IntPtr            pConfigSystem,
            IntPtr            appContext,
            out IntPtr        pMimeMapCollection,
            out int           count);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdGetModuleCollection(
            IntPtr            pConfigSystem,
            IntPtr            appContext,
            out IntPtr        pModuleCollection,
            out int           count);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdGetNextMimeMap(
            IntPtr            pMimeMapCollection,
            uint              dwIndex,
            out IntPtr        bstrFileExtension,
            out int           cchFileExtension,
            out IntPtr        bstrMimeType,
            out int           cchMimeType);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdGetNextModule(
            IntPtr            pModuleCollection,
            ref uint          dwIndex,
            out IntPtr        bstrModuleName,
            out int           cchModuleName,
            out IntPtr        bstrModuleType,
            out int           cchModuleType,
            out IntPtr        bstrModulePrecondition,
            out int           cchModulePrecondition);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern int MgdGetVrPathCreds(
            IntPtr            pConfigSystem,
            string            siteName,
            string            virtualPath,
            out IntPtr        bstrUserName,
            out int           cchUserName,
            out IntPtr        bstrPassword,
            out int           cchPassword);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern int MgdGetAppCollection(
            IntPtr            pConfigSystem,
            string            siteName,
            string            virtualPath,
            out IntPtr        bstrPath,
            out int           cchPath,
            out IntPtr        pAppCollection,
            out int           count);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdGetNextVPath(
            IntPtr            pAppCollection,
            uint              dwIndex,
            out IntPtr        bstrPath,
            out int           cchPath);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdInitNativeConfig();

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern void MgdTerminateNativeConfig();

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern int MgdMapPathDirect(
            IntPtr            pConfigSystem,
            string            siteName,
            string            virtualPath,
            out IntPtr        bstrPhysicalPath,
            out int           cchPath);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern int MgdMapHandler(
            IntPtr            pHandler,
            string            method,
            string            virtualPath,
            out IntPtr        ppszTypeString,
            out int           pcchTypeString,
            bool              convertNativeStaticFileModule,
            bool              ignoreWildcardMappings);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern int MgdReMapHandler(
            IntPtr            pHandler,
            string            pszVirtualPath,
            out IntPtr        ppszTypeString,
            out int           pcchTypeString,
            out bool          pfHandlerExists);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern int MgdSetRemapHandler(
            IntPtr            pHandler,
            string            pszName,
            string            ppszType);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdSetScriptMapForRemapHandler(
            IntPtr            pHandler);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdSetNativeConfiguration(
            IntPtr             nativeConfig);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        [return: MarshalAs(UnmanagedType.U4)]
        internal static extern uint MgdResolveSiteName(
            IntPtr           pConfigSystem,
            string           siteName);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern void MgdSetResponseFilter(
            IntPtr             context);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdGetFileChunkInfo(
            IntPtr             context,
            int                chunkOffset,
            out long           offset,
            out long           length);


        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdReadChunkHandle(
            IntPtr             context,
            IntPtr             FileHandle,
            long               startOffset,
            ref int            length,
            IntPtr             chunkEntity);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdExplicitFlush(
            IntPtr             context,
            bool               async,
            out bool           completedSynchronously);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern int MgdSetServerVariableW(
            IntPtr            context,
            string            variableName,
            string            variableValue);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern int MgdExecuteUrl(
            IntPtr            context,
            string            url,
            bool              resetQuerystring,
            bool              preserveForm,
            byte[]            entityBody,
            uint              entityBodySize,
            string            method,
            int               numHeaders,
            string[]          headersNames,
            string[]          headersValues,
            bool              preserveUser);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern int MgdGetClientCertificate(
            IntPtr            pHandler,
            out IntPtr        ppbClientCert,
            out int           pcbClientCert,
            out IntPtr        ppbClientCertIssuer,
            out int           pcbClientCertIssuer,
            out IntPtr        ppbClientCertPublicKey,
            out int           pcbClientCertPublicKey,
            out uint          pdwCertEncodingType,
            out long          ftNotBefore,
            out long          ftNotAfter);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern int MgdGetChannelBindingToken(
            IntPtr            pHandler,
            out IntPtr        ppbToken,
            out int           pcbTokenSize);

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern void MgdGetCurrentNotificationInfo(
            IntPtr            pHandler, 
            out int           currentModuleIndex,
            out bool          isPostNotification,
            out int           currentNotification);

        [DllImport(_IIS_NATIVE_DLL)]
        [SuppressMessage("Microsoft.Security", "CA2118:ReviewSuppressUnmanagedCodeSecurityUsage", Justification = "We carefully control this method's sole caller.")]
        internal static extern int MgdAcceptWebSocket(
            IntPtr pHandler);

        [DllImport(_IIS_NATIVE_DLL)]
        [SuppressMessage("Microsoft.Security", "CA2118:ReviewSuppressUnmanagedCodeSecurityUsage", Justification = "We carefully control this method's sole caller.")]
        internal static extern int MgdGetWebSocketContext(
            IntPtr pHandler,
            out IntPtr ppWebSocketContext);

        [DllImport(_IIS_NATIVE_DLL, CharSet=CharSet.Unicode)]
        internal static extern int MgdGetAnonymousUserToken(
            IntPtr            pHandler,
            out IntPtr        pToken );

        [DllImport(_IIS_NATIVE_DLL)]
        internal static extern void MgdGetIISVersionInformation(
            [Out] out uint pdwVersion,
            [Out] out bool pfIsIntegratedMode);

        [DllImport(_IIS_NATIVE_DLL)]
        [SuppressMessage("Microsoft.Security", "CA2118:ReviewSuppressUnmanagedCodeSecurityUsage", Justification = "We carefully control this method's callers.")]
        internal static extern int MgdConfigureAsyncDisconnectNotification(
            [In] IntPtr pHandler,
            [In] bool fEnable,
            [Out] out bool pfIsClientConnected);

        [DllImport(_IIS_NATIVE_DLL)]
        [SuppressMessage("Microsoft.Security", "CA2118:ReviewSuppressUnmanagedCodeSecurityUsage", Justification = "We carefully control this method's callers.")]
        internal static extern int MgdGetIsChildContext(
            [In] IntPtr pHandler,
            [Out] out bool pfIsChildContext);

        [DllImport(_IIS_NATIVE_DLL)]
        [SuppressMessage("Microsoft.Security", "CA2118:ReviewSuppressUnmanagedCodeSecurityUsage", Justification = "We carefully control this method's callers.")]
        internal static extern int MgdGetConfigProperty(
            [In, MarshalAs(UnmanagedType.BStr)] string appConfigMetabasePath,
            [In, MarshalAs(UnmanagedType.BStr)] string sectionName,
            [In, MarshalAs(UnmanagedType.BStr)] string propertyName,
            [Out, MarshalAs(UnmanagedType.Struct)] out object value); // marshaled as VARIANT

        [DllImport(_IIS_NATIVE_DLL)]
        [SuppressMessage("Microsoft.Security", "CA2118:ReviewSuppressUnmanagedCodeSecurityUsage", Justification = "We carefully control this method's callers.")]
        internal static extern int MgdPushPromise(
            [In] IntPtr context,
            [In, MarshalAs(UnmanagedType.LPWStr)] string path,
            [In, MarshalAs(UnmanagedType.LPWStr)] string queryString,
            [In, MarshalAs(UnmanagedType.LPStr)] string method,
            [In] int numHeaders,
            [In, MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.LPStr)] string[] headersNames,
            [In, MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr)] string[] headersValues);

        [DllImport(_IIS_NATIVE_DLL)]
        [SuppressMessage("Microsoft.Security", "CA2118:ReviewSuppressUnmanagedCodeSecurityUsage", Justification = "We carefully control this method's callers.")]
        internal static extern bool MgdIsAppPoolShuttingDown();

        [DllImport(_IIS_NATIVE_DLL)]
        [SuppressMessage("Microsoft.Security", "CA2118:ReviewSuppressUnmanagedCodeSecurityUsage", Justification = "We carefully control this method's callers.")]
        internal static extern int MgdGetTlsTokenBindingIdentifiers(
            [In] IntPtr pHandler,
            [In, Out] ref IntPtr tokenBindingHandle,
            [Out] out IntPtr providedToken,
            [Out] out uint providedTokenSize,
            [Out] out IntPtr referredToken,
            [Out] out uint referredTokenSize);
    }
}