Skip to content

Commit b08bd73

Browse files
dotnet-botMichalStrehovsky
authored andcommitted
Populate native runtime sources (dotnet#20)
From dotnet/corert at commit bb212a9d2083046724f48e206f47b7dfb78d9979.
1 parent bf0076c commit b08bd73

File tree

320 files changed

+91474
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

320 files changed

+91474
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
// CppCodeGen.h : Facilities for the C++ code generation backend
5+
6+
#ifndef __CPP_CODE_GEN_H
7+
#define __CPP_CODE_GEN_H
8+
9+
#define _CRT_SECURE_NO_WARNINGS
10+
11+
#ifdef _MSC_VER
12+
// Warnings disabled for generated cpp code
13+
#pragma warning(disable:4200) // zero-sized array
14+
#pragma warning(disable:4101) // unreferenced local variable
15+
#pragma warning(disable:4102) // unreferenced label
16+
#pragma warning(disable:4244) // possible loss of data
17+
#pragma warning(disable:4717) // recursive on all control paths
18+
#pragma warning(disable:4307) // integral constant overflow
19+
#endif
20+
21+
#ifdef _MSC_VER
22+
#define INT64VAL(x) (x##i64)
23+
#else
24+
#define INT64VAL(x) (x##LL)
25+
#endif
26+
27+
#ifdef _MSC_VER
28+
#define CORERT_UNREACHABLE __assume(0)
29+
#else
30+
#define CORERT_UNREACHABLE __builtin_unreachable()
31+
#endif
32+
33+
#ifdef _MSC_VER
34+
#define CORERT_THREAD __declspec(thread)
35+
#else
36+
#define CORERT_THREAD __thread
37+
#endif
38+
39+
// Use the bit representation of uint64_t `v` as the bit representation of a double.
40+
inline double __uint64_to_double(uint64_t v)
41+
{
42+
union
43+
{
44+
uint64_t u64;
45+
double d;
46+
} val;
47+
val.u64 = v;
48+
return val.d;
49+
}
50+
51+
struct ReversePInvokeFrame
52+
{
53+
void* m_savedPInvokeTransitionFrame;
54+
void* m_savedThread;
55+
};
56+
57+
struct PInvokeTransitionFrame
58+
{
59+
void* m_RIP;
60+
void* m_pThread; // unused by stack crawler, this is so GetThread is only called once per method
61+
// can be an invalid pointer in universal transition cases (which never need to call GetThread)
62+
uint32_t m_Flags; // PInvokeTransitionFrameFlags
63+
};
64+
65+
// Should be synchronized with System.Private.CoreLib/src/System/Runtime/CompilerServices/StaticClassConstructionContext.cs
66+
struct StaticClassConstructionContext
67+
{
68+
void* m_cctorMethodAddress;
69+
uint32_t m_initialized;
70+
};
71+
#endif
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
// common.cpp : source file that includes just the standard includes
5+
// testNative.pch will be the pre-compiled header
6+
// common.obj will contain the pre-compiled type information
7+
8+
#include "common.h"
9+
10+
// TODO: reference any additional headers you need in common.H
11+
// and not in this file
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
// common.h : include file for standard system include files,
5+
// or project specific include files that are used frequently, but
6+
// are changed infrequently
7+
//
8+
9+
#ifndef __COMMON_H
10+
#define __COMMON_H
11+
12+
#define _CRT_SECURE_NO_WARNINGS
13+
14+
#include <stdint.h>
15+
#include <stdio.h>
16+
#include <stdlib.h>
17+
#include <string.h>
18+
#include <wchar.h>
19+
#include <assert.h>
20+
#include <stdarg.h>
21+
#include <stddef.h>
22+
#include <math.h>
23+
24+
#include <new>
25+
26+
#ifndef _WIN32
27+
#include <pthread.h>
28+
#endif
29+
30+
using namespace std;
31+
32+
class MethodTable;
33+
class Object;
34+
35+
#ifdef _MSC_VER
36+
#define __NORETURN __declspec(noreturn)
37+
#else
38+
#define __NORETURN __attribute((noreturn))
39+
#endif
40+
41+
int __initialize_runtime();
42+
void __shutdown_runtime();
43+
44+
extern "C" Object * __allocate_object(MethodTable * pMT);
45+
extern "C" Object * __allocate_array(size_t elements, MethodTable * pMT);
46+
extern "C" Object * __castclass(MethodTable * pMT, void * obj);
47+
extern "C" Object * __isinst(MethodTable * pMT, void * obj);
48+
extern "C" __NORETURN void __throw_exception(void * pEx);
49+
extern "C" void __debug_break();
50+
51+
Object * __load_string_literal(const char * string);
52+
53+
extern "C" void __range_check_fail();
54+
55+
inline void __range_check(void * a, size_t elem)
56+
{
57+
if (elem >= *((size_t*)a + 1))
58+
__range_check_fail();
59+
}
60+
61+
Object * __get_commandline_args(int argc, char * argv[]);
62+
63+
// POD version of EEType to use for static initialization
64+
struct RawEEType
65+
{
66+
uint16_t m_componentSize;
67+
uint16_t m_flags;
68+
uint32_t m_baseSize;
69+
MethodTable * m_pBaseType;
70+
uint16_t m_usNumVtableSlots;
71+
uint16_t m_usNumInterfaces;
72+
uint32_t m_uHashCode;
73+
};
74+
75+
struct ReversePInvokeFrame;
76+
77+
void __reverse_pinvoke(ReversePInvokeFrame* pRevFrame);
78+
void __reverse_pinvoke_return(ReversePInvokeFrame* pRevFrame);
79+
80+
struct PInvokeTransitionFrame;
81+
82+
void __pinvoke(PInvokeTransitionFrame* pFrame);
83+
void __pinvoke_return(PInvokeTransitionFrame* pFrame);
84+
85+
typedef size_t UIntNative;
86+
87+
inline bool IS_ALIGNED(UIntNative val, UIntNative alignment)
88+
{
89+
//ASSERT(0 == (alignment & (alignment - 1)));
90+
return 0 == (val & (alignment - 1));
91+
}
92+
93+
template <typename T>
94+
inline bool IS_ALIGNED(T* val, UIntNative alignment)
95+
{
96+
//ASSERT(0 == (alignment & (alignment - 1)));
97+
return IS_ALIGNED(reinterpret_cast<UIntNative>(val), alignment);
98+
}
99+
100+
#define RAW_MIN_OBJECT_SIZE (3*sizeof(void*))
101+
102+
#define AlignBaseSize(s) ((s < RAW_MIN_OBJECT_SIZE) ? RAW_MIN_OBJECT_SIZE : ((s + (sizeof(void*)-1) & ~(sizeof(void*)-1))))
103+
104+
#define ARRAY_BASE (2*sizeof(void*))
105+
106+
#endif // __COMMON_H

0 commit comments

Comments
 (0)