Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Populate native runtime sources #20

Merged
merged 1 commit into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
71 changes: 71 additions & 0 deletions src/coreclr/src/nativeaot/Bootstrap/CppCodeGen.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// CppCodeGen.h : Facilities for the C++ code generation backend

#ifndef __CPP_CODE_GEN_H
#define __CPP_CODE_GEN_H

#define _CRT_SECURE_NO_WARNINGS

#ifdef _MSC_VER
// Warnings disabled for generated cpp code
#pragma warning(disable:4200) // zero-sized array
#pragma warning(disable:4101) // unreferenced local variable
#pragma warning(disable:4102) // unreferenced label
#pragma warning(disable:4244) // possible loss of data
#pragma warning(disable:4717) // recursive on all control paths
#pragma warning(disable:4307) // integral constant overflow
#endif

#ifdef _MSC_VER
#define INT64VAL(x) (x##i64)
#else
#define INT64VAL(x) (x##LL)
#endif

#ifdef _MSC_VER
#define CORERT_UNREACHABLE __assume(0)
#else
#define CORERT_UNREACHABLE __builtin_unreachable()
#endif

#ifdef _MSC_VER
#define CORERT_THREAD __declspec(thread)
#else
#define CORERT_THREAD __thread
#endif

// Use the bit representation of uint64_t `v` as the bit representation of a double.
inline double __uint64_to_double(uint64_t v)
{
union
{
uint64_t u64;
double d;
} val;
val.u64 = v;
return val.d;
}

struct ReversePInvokeFrame
{
void* m_savedPInvokeTransitionFrame;
void* m_savedThread;
};

struct PInvokeTransitionFrame
{
void* m_RIP;
void* m_pThread; // unused by stack crawler, this is so GetThread is only called once per method
// can be an invalid pointer in universal transition cases (which never need to call GetThread)
uint32_t m_Flags; // PInvokeTransitionFrameFlags
};

// Should be synchronized with System.Private.CoreLib/src/System/Runtime/CompilerServices/StaticClassConstructionContext.cs
struct StaticClassConstructionContext
{
void* m_cctorMethodAddress;
uint32_t m_initialized;
};
#endif
11 changes: 11 additions & 0 deletions src/coreclr/src/nativeaot/Bootstrap/common.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// common.cpp : source file that includes just the standard includes
// testNative.pch will be the pre-compiled header
// common.obj will contain the pre-compiled type information

#include "common.h"

// TODO: reference any additional headers you need in common.H
// and not in this file
106 changes: 106 additions & 0 deletions src/coreclr/src/nativeaot/Bootstrap/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// common.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#ifndef __COMMON_H
#define __COMMON_H

#define _CRT_SECURE_NO_WARNINGS

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#include <assert.h>
#include <stdarg.h>
#include <stddef.h>
#include <math.h>

#include <new>

#ifndef _WIN32
#include <pthread.h>
#endif

using namespace std;

class MethodTable;
class Object;

#ifdef _MSC_VER
#define __NORETURN __declspec(noreturn)
#else
#define __NORETURN __attribute((noreturn))
#endif

int __initialize_runtime();
void __shutdown_runtime();

extern "C" Object * __allocate_object(MethodTable * pMT);
extern "C" Object * __allocate_array(size_t elements, MethodTable * pMT);
extern "C" Object * __castclass(MethodTable * pMT, void * obj);
extern "C" Object * __isinst(MethodTable * pMT, void * obj);
extern "C" __NORETURN void __throw_exception(void * pEx);
extern "C" void __debug_break();

Object * __load_string_literal(const char * string);

extern "C" void __range_check_fail();

inline void __range_check(void * a, size_t elem)
{
if (elem >= *((size_t*)a + 1))
__range_check_fail();
}

Object * __get_commandline_args(int argc, char * argv[]);

// POD version of EEType to use for static initialization
struct RawEEType
{
uint16_t m_componentSize;
uint16_t m_flags;
uint32_t m_baseSize;
MethodTable * m_pBaseType;
uint16_t m_usNumVtableSlots;
uint16_t m_usNumInterfaces;
uint32_t m_uHashCode;
};

struct ReversePInvokeFrame;

void __reverse_pinvoke(ReversePInvokeFrame* pRevFrame);
void __reverse_pinvoke_return(ReversePInvokeFrame* pRevFrame);

struct PInvokeTransitionFrame;

void __pinvoke(PInvokeTransitionFrame* pFrame);
void __pinvoke_return(PInvokeTransitionFrame* pFrame);

typedef size_t UIntNative;

inline bool IS_ALIGNED(UIntNative val, UIntNative alignment)
{
//ASSERT(0 == (alignment & (alignment - 1)));
return 0 == (val & (alignment - 1));
}

template <typename T>
inline bool IS_ALIGNED(T* val, UIntNative alignment)
{
//ASSERT(0 == (alignment & (alignment - 1)));
return IS_ALIGNED(reinterpret_cast<UIntNative>(val), alignment);
}

#define RAW_MIN_OBJECT_SIZE (3*sizeof(void*))

#define AlignBaseSize(s) ((s < RAW_MIN_OBJECT_SIZE) ? RAW_MIN_OBJECT_SIZE : ((s + (sizeof(void*)-1) & ~(sizeof(void*)-1))))

#define ARRAY_BASE (2*sizeof(void*))

#endif // __COMMON_H
Loading