Welcome to mirror list, hosted at ThFree Co, Russian Federation.

McgIntrinsics.cs « Shared « src « System.Private.Interop « src - github.com/mono/corert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ca48d577b34fbd267bec60763a65c5fb76864cc8 (plain)
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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
// ----------------------------------------------------------------------------------
// Interop library code
//
// NOTE:
//   These source code are being published to InternalAPIs and consumed by RH builds
//   Use PublishInteropAPI.bat to keep the InternalAPI copies in sync
// ----------------------------------------------------------------------------------

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Text;
using System.Runtime;
using Internal.NativeFormat;

namespace System.Runtime.InteropServices
{
    //
    // This section contains the code that would have been generated by MCG in order to use the AddrOf and
    // StdCall intrinsics, had we used it to generate all of our interop code.  In general, the transformation
    // done by the IL2IL step is simple.  We search the assembly being transformed for a definition of the
    // McgIntrinsics attribute and, then, any class marked with [McgIntrinsics] will be searched for methods
    // named StdCall and AddrOf.  For methods named StdCall, an implementation is provided that loads up the
    // arguments and does an IL 'calli' instruction to the first argument to StdCall using the unmanaged
    // stdcall calling convention.  For methods named AddrOf, it is the callsites that are transformed.  For
    // this, the callsites are implicitly constructing a Func<T> delegate around a static method.  The IL2IL
    // transform will look at every callsite to an AddrOf and ensure that it matches the expected pattern.  If
    // it does, it will eliminate the delegate construction and the call to the methods defined below and
    // simply leave the 'ldftn' IL instruction that was used as part of that delegate construction sequence.
    //
    // Note:In .NET Native NutC and binder on seeing an LDFTN with NativeCallable target method generate method
    // callable from native , on CoreCLR we wrap NativeCallable in an UMThunk , which essentialy
    // is the same code path as reverse PInvoke.

    // Note: Because AddrOf depends on Func<T>, the arguments may not be pointer types (because generics can
    // not be instantiated over pointer types).
    //
    // Note: Because StdCall is most commonly used with COM calls, void-returning StdCalls weren't implemented
    // in MCG and we've also avoided them here (even though the IL2IL transform should support them).
    //
    [System.AttributeUsageAttribute(System.AttributeTargets.Class)]
    internal class McgIntrinsicsAttribute : System.Attribute
    {
    }

    [McgIntrinsics]
    internal static unsafe partial class CalliIntrinsics
    {
        internal static int StdCall__QueryInterface(
                   IntPtr pfn,
                   IntPtr pComThis,
                   IntPtr arg0,
                   IntPtr arg1)
        {
            // This method is implemented elsewhere in the toolchain
            return default(int);
        }

        internal static int StdCall__AddRef(System.IntPtr pfn, IntPtr pComThis)
        {
            // This method is implemented elsewhere in the toolchain
            return default(int);
        }

        internal static int StdCall__Release(System.IntPtr pfn, IntPtr pComThis)
        {
            // This method is implemented elsewhere in the toolchain
            return default(int);
        }

        internal static int StdCall__int(
            System.IntPtr pfn,
            IntPtr pComThis)
        {
            // This method is implemented elsewhere in the toolchain
            return default(int);
        }

        internal static int StdCall__int(
                    IntPtr pfn,
                    IntPtr pComThis,
                    uint arg0)
        {
            // This method is implemented elsewhere in the toolchain
            return default(int);
        }

        internal static int StdCall__int(
                    IntPtr pfn,
                    IntPtr pComThis,
                    void* arg0)
        {
            // This method is implemented elsewhere in the toolchain
            return default(int);
        }

        internal static int StdCall__int(
                   IntPtr pfn,
                   IntPtr pComThis,
                   void* arg0,
                   void* arg1)
        {

            // This method is implemented elsewhere in the toolchain
            return default(int);
        }

        internal static int StdCall__int(
           IntPtr pfn,
           IntPtr pComThis,
           void* arg0,
           int arg1,
           IntPtr arg2)
        {

            // This method is implemented elsewhere in the toolchain
            return default(int);
        }

        internal static int StdCall__int(
          IntPtr pfn,
          IntPtr pComThis,
          void* arg0,
          IntPtr arg1,
          uint arg2,
          IntPtr arg3,
          uint arg4,
          void* arg5)
        {

            // This method is implemented elsewhere in the toolchain
            return default(int);
        }

        public static int StdCall__int(
            IntPtr pfn,
            void* pthis,
            System.Runtime.InteropServices.HSTRING arg0,
            void* arg1)
        {
            // This method is implemented elsewhere in the toolchain
            return 0;
        }

        public static int StdCall__int(
            global::System.IntPtr pfn,
            void* pthis,
            void* arg0)
        {
            // This method is implemented elsewhere in the toolchain
            return 0;
        }

        public static int StdCall__int(
            global::System.IntPtr pfn,
            IntPtr pthis,
            HSTRING arg0,
            IntPtr arg1,
            void * arg2,
            void * arg3)
        {
            // This method is implemented elsewhere in the toolchain
            return 0;
        }

        public static int StdCall__int(
            global::System.IntPtr pfn,
            IntPtr pthis,
            int arg0,
            IntPtr arg1,
            IntPtr arg2,
            int arg3,
            int arg4,
            IntPtr arg5,
            void * arg6,
            void * arg7)
        {
            // This method is implemented elsewhere in the toolchain
            return default(int);
        }

        internal static int StdCall__int(
                    System.IntPtr pfn,
                    void* pComThis,
                    ulong arg0,
                    uint arg1,
                    void* arg2)
        {
            // This method is implemented elsewhere in the toolchain
            return 0;
        }
        internal static int StdCall__int(
                    System.IntPtr pfn,
                    void* pComThis,
                    IntPtr arg0,
                    void* arg1,
                    void* arg2,
                    int arg3,
                    IntPtr arg4)
        {
            // This method is implemented elsewhere in the toolchain
            return 0;
        }

        internal static int StdCall__int(
                    System.IntPtr pfn,
                    uint arg0)
        {
            // This method is implemented elsewhere in the toolchain
            return default(int);
        }
        internal static int StdCall__int(
                    System.IntPtr pfn,
                    void* arg0)
        {
            // This method is implemented elsewhere in the toolchain
            return default(int);
        }

        internal static int StdCall__int(
                    System.IntPtr pfn,
                    void* arg0,
                    uint arg1,
                    void* arg2)
        {
            // This method is implemented elsewhere in the toolchain
            return default(int);
        }
        internal static int StdCall__int(
                    System.IntPtr pfn,
                    void* arg0,
                    void* arg1,
                    void* arg2)
        {
            // This method is implemented elsewhere in the toolchain
            return default(int);
        }

        internal static int StdCall__int(
                    System.IntPtr pfn,
                    void* arg0,
                    uint arg1,
                    void* arg2,
                    void* arg3)
        {
            // This method is implemented elsewhere in the toolchain
            return default(int);
        }
        internal static int StdCall__int(
                    System.IntPtr pfn,
                    int hr,
                    void* errorMsg,
                    System.IntPtr pUnk)
        {
            // This method is implemented elsewhere in the toolchain
            return default(int);
        }

        internal static int StdCall__int(
                    System.IntPtr pfn,
                    System.IntPtr pComThis,
                    out System.IntPtr arg1,
                    out int arg2,
                    out System.IntPtr arg3,
                    out System.IntPtr arg4)
        {
            // This method is implemented elsewhere in the toolchain
            arg1 = default(IntPtr);
            arg3 = default(IntPtr);
            arg4 = default(IntPtr);
            arg2 = 0;
            return default(int);
        }
        internal static int StdCall__int(
            System.IntPtr pfn,
            System.IntPtr pComThis,
            out System.IntPtr arg)
        {
            // This method is implemented elsewhere in the toolchain
            arg = default(IntPtr);
            return default(int);
        }

        internal static int StdCall__int(
            System.IntPtr pfn,
            System.IntPtr pComThis,
            System.Guid arg1,
            out System.IntPtr arg2)
        {
            // This method is implemented elsewhere in the toolchain
            arg2 = default(IntPtr);
            return default(int);
        }

        internal static int StdCall__int(
            IntPtr pfn,
            void* pComThis,
            IntPtr piid,
            IntPtr pv,
            int dwDestContext,
            IntPtr pvDestContext,
            int mshlflags,
            IntPtr pclsid)
        {
            // This method is implemented elsewhere in the toolchain
            return default(int);
        }

        internal static int StdCall__int(
              IntPtr pfn,
              void* pComThis,
              IntPtr pStm,
              IntPtr piid,
              IntPtr pv,
              int dwDestContext,
              IntPtr pvDestContext,
              int mshlflags)
        {
            // This method is implemented elsewhere in the toolchain
            return default(int);
        }

        internal static int StdCall__int(
              IntPtr pfn,
              void* pComThis,
              IntPtr pStm,
              IntPtr piid,
              IntPtr ppvObj)
        {
            // This method is implemented elsewhere in the toolchain
            return default(int);
        }

        internal static int StdCall__int(
              IntPtr pfn,
              void* pComThis,
              IntPtr pStm)
        {
            // This method is implemented elsewhere in the toolchain
            return default(int);
        }

        internal static int StdCall__int(
              IntPtr pfn,
              void* pComThis,
              int dwReserved)
        {
            // This method is implemented elsewhere in the toolchain
            return default(int);
        }

        private const MethodImplOptions InternalCall = (MethodImplOptions)0x1000;

        // Cooperative GC versions of StdCall.
        // We need to call via an imported stub to do a stdcall without triggering GC
        // We can't use managed calli because the native target address could potentially satisfy a magic
        // bit check and causing the stub to believe it is a managed method which leads to crash.
#if !RHTESTCL && PROJECTN
        [MethodImplAttribute(InternalCall)]
#if X86
        [RuntimeImport("*", "@StdCallCOOP0@8")]
#else
        [RuntimeImport("*", "StdCallCOOP0")]
#endif // X86
        internal static extern int StdCallCOOP(System.IntPtr pfn, void* pComThis);

        [MethodImplAttribute(InternalCall)]
#if X86
        [RuntimeImport("*", "@StdCallCOOPV@12")]
#else
        [RuntimeImport("*", "StdCallCOOPV")]
#endif // X86

        internal static extern int StdCallCOOP(System.IntPtr pfn, void* pComThis, void* arg0);

        [MethodImplAttribute(InternalCall)]
#if X86
        [RuntimeImport("*", "@StdCallCOOPI@12")]
#else
        [RuntimeImport("*", "StdCallCOOPI")]
#endif // X86
        internal static extern int StdCallCOOP(System.IntPtr pfn, void* pComThis, int arg0);
#else
        internal static int StdCallCOOP(System.IntPtr pfn, void* pComThis)
        {
            return Call<int>(pfn, pComThis);
        }

        internal static int StdCallCOOP(System.IntPtr pfn, void* pComThis, void* arg0)
        {
            return Call<int>(pfn, pComThis, arg0);
        }

        internal static int StdCallCOOP(System.IntPtr pfn, void* pComThis, int arg0)
        {
            return Call<int>(pfn, pComThis, arg0);
        }
#endif

        // Used to invoke GetCcwVtable* methods which return pVtbl
        internal static IntPtr Call__GetCcwVtable(
                    System.IntPtr pfn)
        {
            return default(IntPtr);
        }
        internal static T Call<T>(
                   System.IntPtr pfn,
                   void* arg0)
        {
            return default(T);
        }
        internal static T Call<T>(
                    System.IntPtr pfn,
                    Object arg0)
        {
            return default(T);
        }
        internal static T Call<T>(
                    System.IntPtr pfn,
                    System.Object arg0,
                    System.Object arg1,
                    int arg2)
        {
            return default(T);
        }
        internal static T Call<T>(
                    System.IntPtr pfn,
                    System.Object arg0,
                    int arg1)
        {
            return default(T);
        }
        internal static T Call<T>(
                    System.IntPtr pfn,
                    void* arg0,
                    void* arg1)
        {
            return default(T);
        }
        internal static T Call<T>(
                    System.IntPtr pfn,
                    void* arg0,
                    int arg1)
        {
            return default(T);
        }
        internal static T Call<T>(
                    System.IntPtr pfn,
                    System.IntPtr arg0,
                    uint arg1,
                    System.IntPtr arg2)
        {
            return default(T);
        }
        internal static T Call<T>(
                    System.IntPtr pfn,
                    System.IntPtr arg0,
                    uint arg1,
                    void* arg2,
                    System.IntPtr arg3)
        {
            return default(T);
        }
        internal static T Call<T>(
                    System.IntPtr pfn,
                    __ComObject arg0,
                    System.IntPtr arg1)
        {
            return default(T);
        }
        internal static T Call<T>(
            System.IntPtr pfn,
            __ComObject arg0,
            System.IntPtr arg1,
            RuntimeTypeHandle arg2)
        {
            return default(T);
        }

#if ENABLE_MIN_WINRT
        // For SharedCCW_IVector/SharedCCW_IVectorView
        internal static T Call<T>(IntPtr pfn, object list, Toolbox.IList_Oper oper, int index, ref object item)
        {
            return default(T);
        }

        // For SharedCCW_ITerator
        internal static T Call<T>(IntPtr pfn, object iterator, Toolbox.IIterator_Oper oper, ref object data, int len)
        {
            return default(T);
        }

        internal static T Call<T>(IntPtr pfn, object iterator, Toolbox.IIterator_Oper oper, IntPtr pData, ref int len)
        {
            return default(T);
        }

#if ENABLE_WINRT
        // For SharedCcw_AsyncOperationCompletedHandler
        internal static T Call<T>(IntPtr pfn, object handler, object asyncInfo, global::Windows.Foundation.AsyncStatus status)
        {
            return default(T);
        }
#endif
        // For SharedCCW_IVector_Blittable/SharedCCW_IVectorView_Blittable
        internal static T Call<T>(IntPtr pfn, object list, Toolbox.IList_Oper oper, ref int index, System.IntPtr pData)
        {
            return default(T);
        }
#endif // ENABLE_MIN_WINRT
        // For ForwardDelegateCreationStub
        internal static Delegate Call__Delegate(System.IntPtr pfn, System.IntPtr pStub)
        {
            return default(Delegate);
        }
    }

    [McgIntrinsics]
    internal static partial class AddrOfIntrinsics
    {
        internal static IntPtr AddrOf<T>(T ftn)
        {
            // This method is implemented elsewhere in the toolchain
            return default(IntPtr);
        }

        internal static IntPtr StaticFieldAddr<T>(ref T field)
        {
            // This method is implemented elsewhere in the toolchain
            return default(IntPtr);
        }

        internal static IntPtr VirtualAddrOf<T>(object o, int methodIndex)
        {
            // This method is implemented elsewhere in the toolchain
            return System.IntPtr.Zero;
        }

        // Apart from AddRef , Release and QI there are lot other functions with same
        // signature but different semantics.So keeping AddrOfTarget1 , AddrOfTarget4 around even though
        // they have the same signature as AddrOfAddRef and AddrOfQueryInterface

        // Common delegate signature for many functions
        internal delegate int AddrOfTarget1(IntPtr p0);
        internal delegate int AddrOfTarget2(IntPtr p0, int p1);
        internal delegate int AddrOfTarget3(IntPtr p0, IntPtr p1);
        internal delegate int AddrOfTarget4(IntPtr p0, IntPtr p1, IntPtr p2);
        internal delegate int AddrOfTarget5(IntPtr p0, IntPtr p1, IntPtr p2, IntPtr p3);

        // specialized delegates
        internal delegate int AddrOfGetIID(IntPtr __IntPtr__pComThis, IntPtr __IntPtr__iidCount, IntPtr __IntPtr__iids);
        internal delegate int AddrOfCreateManagedReference(System.IntPtr pComThis, IntPtr __IntPtr__pJupiterObject, IntPtr __IntPtr__ppNewReference);
        internal delegate int AddrOfResolve(IntPtr __IntPtr__pComThis, IntPtr __IntPtr__piid, IntPtr __IntPtr__ppWeakReference);
        internal delegate int AddrOfIndexOf(IntPtr p0, IntPtr p1, IntPtr p2, IntPtr p3);
        internal delegate int AddrOfMarshalInterface(IntPtr p0, IntPtr p1, IntPtr p2, IntPtr p3, int p4, IntPtr p5, int p6);

        internal delegate int AddrOfGetMarshalUnMarshal(IntPtr pComThis,
                                                        IntPtr piid,
                                                        IntPtr pv,
                                                        int dwDestContext,
                                                        IntPtr pvDestContext,
                                                        int mshlflags,
                                                        IntPtr pclsid);

        internal delegate int AddrOfAttachingCtor(__ComObject comObject, IntPtr pBaseIUnknown, RuntimeTypeHandle classType);
        internal delegate int AddrOfGetSetInsertReplaceAll(IntPtr pComThis, uint index, IntPtr pItem);
        internal delegate int AddrOfRemoveAt(System.IntPtr pComThis, uint index);
        internal delegate int AddrOfGetMany1(IntPtr pComThis, uint startIndex, uint len, IntPtr pDest, IntPtr pCount);
        internal delegate int AddrOfGetMany2(IntPtr pComThis, uint len, IntPtr pDest, IntPtr pCount);
        internal delegate int AddrOfHookGCCallbacks(int nCondemnedGeneration);
        internal delegate int AddrOfAddRemoveMemoryPressure(System.IntPtr pComThis, ulong bytesAllocated);

        internal delegate bool AddrOfIsAlive(ComCallableObject comCallableObject);

        internal delegate int AddrOfGetTypeInfo(
            IntPtr pComThis,
            uint iTInfo,
            uint lcid,
            IntPtr ppTInfo);
        internal delegate int AddrOfGetIDsOfNames(
            IntPtr pComThis,
            IntPtr riid,
            IntPtr rgszNames,
            uint cNames,
            uint lcid,
            IntPtr rgDispId);
        internal delegate int AddrOfInvoke(
            IntPtr pComThis,
            int dispIdMember,
            IntPtr riid,
            uint lcid,
            ushort wFlags,
            IntPtr pDispParams,
            IntPtr pVarResult,
            IntPtr pExcepInfo,
            IntPtr puArgErr);

        // IStream
        internal delegate int AddrOfIStreamClone(IntPtr pComThis, IntPtr ppstm);
        internal delegate int AddrOfIStreamCopyTo(IntPtr pComThis, IntPtr pstm, long cb, IntPtr pcbRead, IntPtr pcbWritten);
        internal delegate int AddrOfIStreamLockRegion(IntPtr pComThis, long libOffset, long cb, int dwLockType);
        internal delegate int AddrOfIStreamRead(IntPtr pComThis, IntPtr pv, int cb, IntPtr pcbRead);
        internal delegate int AddrOfIStreamSeek(IntPtr pComThis, long dlibMove, int dwOrigin, IntPtr plibNewPosition);
        internal delegate int AddrOfIStreamSetSize(IntPtr pComThis, long libNewSize);
        internal delegate int AddrOfIStreamStat(IntPtr pComThis, IntPtr pstatstg, int grfStatFlag);
        internal delegate int AddrOfIStreamUnlockRegion(IntPtr pComThis, long libOffset, long cb, int dwLockType);
        internal delegate int AddrOfIStreamWrite(IntPtr pComThis, IntPtr pv, int cb, IntPtr pcbWritten);

#if !RHTESTCL && !CORECLR
        // ICommand
        internal delegate int AddrOfICommandremove_CanExecuteChanged(IntPtr pComThis, System.Runtime.InteropServices.WindowsRuntime.EventRegistrationToken unsafe_token);
#endif        
        // ILanguageExceptionStackBackTrace
        internal delegate int AddrOfILanguageExceptionStackBackTraceGetStackBackTrace(IntPtr pComThis, uint maxFramesToCapture, IntPtr stackBackTrace, IntPtr framesCaptured);
    }

#if ENABLE_MIN_WINRT
    [McgIntrinsics]
    internal class WinRTAddrOfIntrinsics
    {
        internal delegate int AddrOfGetCustomProperty(System.IntPtr pComThis, HSTRING unsafe_name, IntPtr __IntPtr__unsafe_customProperty);
        internal delegate int AddrOfGetIndexedProperty(System.IntPtr pComThis, HSTRING unsafe_name, TypeName unsafe_type, IntPtr __IntPtr__unsafe_customProperty);
        internal delegate int AddrOfTarget19(IntPtr p0, IntPtr p1, int p2);
    }
#endif // ENABLE_MIN_WINRT

    public delegate IntPtr AddrOfGetCCWVtable();
    public delegate int AddrOfRelease(IntPtr pComThis);
    public delegate int AddrOfAddRef(IntPtr pComThis);
    public delegate int AddrOfQueryInterface(IntPtr __IntPtr__pComThis, IntPtr __IntPtr__pIID, IntPtr __IntPtr__ppvObject);

    // Helper delegate to invoke mcg generated ForwardDelegateCreationStub(IntPtr functionPointer)
    public delegate Delegate ForwardDelegateCreationStub(IntPtr pFunc);
}