Initial commit.

This commit is contained in:
2019-07-01 14:33:21 +02:00
parent 92a04d779e
commit baa2e0279d
1624 changed files with 3204958 additions and 0 deletions
@@ -0,0 +1,27 @@
#pragma once
#if IL2CPP_TARGET_WINDOWS
#include "os/Win32/WindowsHeaders.h"
#include "c-api/Atomic-c-api.h"
namespace il2cpp
{
namespace os
{
inline void Atomic::FullMemoryBarrier()
{
#if defined(_AMD64_)
::__faststorefence();
#elif defined(_M_IX86)
::MemoryBarrier();
#elif defined(_M_ARM)
__dmb(_ARM_BARRIER_SY);
#else
#error Not implemented;
#endif
}
}
}
#endif
@@ -0,0 +1,33 @@
#pragma once
#if NET_4_0
#if IL2CPP_THREADS_WIN32
#include "utils/NonCopyable.h"
#include "WindowsHeaders.h"
class FastMutexImpl;
namespace il2cpp
{
namespace os
{
class ConditionVariableImpl : public il2cpp::utils::NonCopyable
{
public:
ConditionVariableImpl();
~ConditionVariableImpl();
int Wait(FastMutexImpl* lock);
int TimedWait(FastMutexImpl* lock, uint32_t timeout_ms);
void Broadcast();
void Signal();
private:
CONDITION_VARIABLE m_ConditionVariable;
};
}
}
#endif
#endif
@@ -0,0 +1,9 @@
#pragma once
namespace il2cpp
{
namespace os
{
void InitializeDllMain();
}
}
@@ -0,0 +1,32 @@
#pragma once
#if IL2CPP_THREADS_WIN32
#include "os/ErrorCodes.h"
#include "os/WaitStatus.h"
#include "utils/NonCopyable.h"
#include "WindowsHeaders.h"
namespace il2cpp
{
namespace os
{
class EventImpl : public il2cpp::utils::NonCopyable
{
public:
EventImpl(bool manualReset = false, bool signaled = false);
~EventImpl();
ErrorCode Set();
ErrorCode Reset();
WaitStatus Wait(bool interruptible);
WaitStatus Wait(uint32_t ms, bool interruptible);
private:
HANDLE m_Event;
};
}
}
#endif
@@ -0,0 +1,63 @@
#pragma once
#if IL2CPP_THREADS_WIN32
#include "os/ErrorCodes.h"
#include "os/WaitStatus.h"
#include "utils/NonCopyable.h"
#include "WindowsHeaders.h"
namespace il2cpp
{
namespace os
{
class MutexImpl : public il2cpp::utils::NonCopyable
{
public:
MutexImpl();
~MutexImpl();
void Lock(bool interruptible);
bool TryLock(uint32_t milliseconds, bool interruptible);
void Unlock();
private:
HANDLE m_MutexHandle;
};
class FastMutexImpl
{
public:
FastMutexImpl()
{
InitializeCriticalSection(&m_CritialSection);
}
~FastMutexImpl()
{
DeleteCriticalSection(&m_CritialSection);
}
void Lock()
{
EnterCriticalSection(&m_CritialSection);
}
void Unlock()
{
LeaveCriticalSection(&m_CritialSection);
}
CRITICAL_SECTION* GetOSHandle()
{
return &m_CritialSection;
}
private:
CRITICAL_SECTION m_CritialSection;
};
}
}
#endif
@@ -0,0 +1,51 @@
#pragma once
#if IL2CPP_THREADS_WIN32
#include "WindowsHeaders.h"
namespace il2cpp
{
namespace os
{
class ReaderWriterLockImpl
{
public:
ReaderWriterLockImpl()
{
InitializeSRWLock(&m_Lock);
}
void LockExclusive()
{
AcquireSRWLockExclusive(&m_Lock);
}
void LockShared()
{
AcquireSRWLockShared(&m_Lock);
}
void ReleaseExclusive()
{
ReleaseSRWLockExclusive(&m_Lock);
}
void ReleaseShared()
{
ReleaseSRWLockShared(&m_Lock);
}
PSRWLOCK GetOSHandle()
{
return &m_Lock;
}
private:
SRWLOCK m_Lock;
};
}
}
#endif
@@ -0,0 +1,29 @@
#pragma once
#if IL2CPP_THREADS_WIN32
#include "os/ErrorCodes.h"
#include "os/WaitStatus.h"
#include "utils/NonCopyable.h"
#include "WindowsHeaders.h"
namespace il2cpp
{
namespace os
{
class SemaphoreImpl : public il2cpp::utils::NonCopyable
{
public:
SemaphoreImpl(int32_t initialValue, int32_t maximumValue);
~SemaphoreImpl();
bool Post(int32_t releaseCount, int32_t* previousCount = NULL);
WaitStatus Wait(bool interruptible);
WaitStatus Wait(uint32_t ms, bool interruptible);
private:
HANDLE m_Handle;
};
}
}
#endif
@@ -0,0 +1,129 @@
#pragma once
#if IL2CPP_TARGET_WINDOWS
#include <string>
#include <vector>
#include <stdint.h>
#include "os/Socket.h"
#include "os/ErrorCodes.h"
#include "os/WaitStatus.h"
#include "utils/NonCopyable.h"
struct sockaddr;
namespace il2cpp
{
namespace os
{
class SocketImpl : public il2cpp::utils::NonCopyable
{
public:
/// Handle for socket. Must be large enough to hold a pointer.
typedef uint64_t SocketDescriptor;
SocketImpl(ThreadStatusCallback thread_status_callback);
~SocketImpl();
inline SocketDescriptor GetDescriptor()
{
return _fd;
}
ErrorCode GetLastError() const;
WaitStatus Create(SocketDescriptor fd, int32_t family, int32_t type, int32_t protocol);
WaitStatus Create(AddressFamily family, SocketType type, ProtocolType protocol);
WaitStatus Close();
bool IsClosed() { return (_fd == -1); }
WaitStatus SetBlocking(bool blocking);
WaitStatus Listen(int32_t blacklog);
WaitStatus Bind(const char *path);
WaitStatus Bind(const char *address, uint16_t port);
WaitStatus Bind(uint32_t address, uint16_t port);
WaitStatus Bind(uint8_t address[ipv6AddressSize], uint32_t scope, uint16_t port);
WaitStatus Connect(const char *path);
WaitStatus Connect(uint32_t address, uint16_t port);
WaitStatus Connect(uint8_t address[ipv6AddressSize], uint32_t scope, uint16_t port);
WaitStatus Disconnect(bool reuse);
WaitStatus Shutdown(int32_t how);
WaitStatus GetLocalEndPointInfo(EndPointInfo &info);
WaitStatus GetRemoteEndPointInfo(EndPointInfo &info);
WaitStatus Receive(const uint8_t *data, int32_t count, os::SocketFlags flags, int32_t *len);
WaitStatus ReceiveFromInternal(const uint8_t *data, size_t count, int32_t flags, int32_t *len, struct sockaddr *from, int32_t *fromlen);
WaitStatus Send(const uint8_t *data, int32_t count, os::SocketFlags flags, int32_t *len);
WaitStatus SendArray(WSABuf *wsabufs, int32_t count, int32_t *sent, SocketFlags c_flags);
WaitStatus ReceiveArray(WSABuf *wsabufs, int32_t count, int32_t *len, SocketFlags c_flags);
WaitStatus SendTo(uint32_t address, uint16_t port, const uint8_t *data, int32_t count, os::SocketFlags flags, int32_t *len);
WaitStatus SendTo(const char *path, const uint8_t *data, int32_t count, os::SocketFlags flags, int32_t *len);
WaitStatus SendTo(uint8_t address[ipv6AddressSize], uint32_t scope, uint16_t port, const uint8_t *data, int32_t count, os::SocketFlags flags, int32_t *len);
WaitStatus RecvFrom(uint32_t address, uint16_t port, const uint8_t *data, int32_t count, os::SocketFlags flags, int32_t *len, os::EndPointInfo &ep);
WaitStatus RecvFrom(const char *path, const uint8_t *data, int32_t count, os::SocketFlags flags, int32_t *len, os::EndPointInfo &ep);
WaitStatus RecvFrom(uint8_t address[ipv6AddressSize], uint32_t scope, uint16_t port, const uint8_t *data, int32_t count, os::SocketFlags flags, int32_t *len, os::EndPointInfo &ep);
WaitStatus Available(int32_t *amount);
WaitStatus Accept(os::Socket **socket);
WaitStatus Ioctl(int32_t command, const uint8_t *in_data, int32_t in_len, uint8_t *out_data, int32_t out_len, int32_t *written);
WaitStatus GetSocketOption(SocketOptionLevel level, SocketOptionName name, uint8_t *buffer, int32_t *length);
WaitStatus GetSocketOptionFull(SocketOptionLevel level, SocketOptionName name, int32_t *first, int32_t *second);
WaitStatus SetSocketOption(SocketOptionLevel level, SocketOptionName name, int32_t value);
WaitStatus SetSocketOptionLinger(SocketOptionLevel level, SocketOptionName name, bool enabled, int32_t seconds);
WaitStatus SetSocketOptionArray(SocketOptionLevel level, SocketOptionName name, const uint8_t *buffer, int32_t length);
WaitStatus SetSocketOptionMembership(SocketOptionLevel level, SocketOptionName name, uint32_t group_address, uint32_t local_address);
#if IL2CPP_SUPPORT_IPV6
WaitStatus SetSocketOptionMembership(SocketOptionLevel level, SocketOptionName name, IPv6Address ipv6, uint64_t interfaceOffset);
#endif
WaitStatus SendFile(const char *filename, TransmitFileBuffers *buffers, TransmitFileOptions options);
static WaitStatus Poll(std::vector<PollRequest> &requests, int32_t count, int32_t timeout, int32_t *result, int32_t *error);
static WaitStatus Poll(std::vector<PollRequest> &requests, int32_t timeout, int32_t *result, int32_t *error);
static WaitStatus Poll(PollRequest& request, int32_t timeout, int32_t *result, int32_t *error);
static WaitStatus GetHostName(std::string &name);
static WaitStatus GetHostByName(const std::string &host, std::string &name, std::vector<std::string> &aliases, std::vector<std::string> &addresses);
static WaitStatus GetHostByName(const std::string &host, std::string &name, int32_t &family, std::vector<std::string> &aliases, std::vector<void*> &addr_list, int32_t &addr_size);
static WaitStatus GetHostByAddr(const std::string &address, std::string &name, std::vector<std::string> &aliases, std::vector<std::string> &addr_list);
static void Startup();
static void Cleanup();
private:
bool _is_valid;
SocketDescriptor _fd;
int32_t _domain;
int32_t _type;
int32_t _protocol;
ErrorCode _saved_error;
int32_t _still_readable;
ThreadStatusCallback _thread_status_callback;
void StoreLastError();
void StoreLastError(int32_t error_no);
WaitStatus ConnectInternal(struct sockaddr *sa, int32_t sa_size);
WaitStatus SetSocketOptionInternal(int32_t level, int32_t name, const void *value, int32_t len);
};
}
}
#endif
@@ -0,0 +1,76 @@
#pragma once
#if !IL2CPP_THREADS_STD && IL2CPP_THREADS_WIN32
#include "os/ErrorCodes.h"
#include "os/Thread.h"
#include "os/WaitStatus.h"
#include "utils/NonCopyable.h"
#include "WindowsHeaders.h"
#define IL2CPP_DEFAULT_STACK_SIZE ( 1 * 1024 * 1024) // default .NET stacksize is 1mb
namespace il2cpp
{
namespace os
{
class ThreadImpl : public il2cpp::utils::NonCopyable
{
public:
ThreadImpl();
~ThreadImpl();
uint64_t Id();
ErrorCode Run(Thread::StartFunc func, void* arg);
void SetName(const std::string& name);
void SetPriority(ThreadPriority priority);
ThreadPriority GetPriority();
void SetStackSize(size_t newsize)
{
// only makes sense if it's called BEFORE the thread has been created
IL2CPP_ASSERT(m_ThreadHandle == NULL);
// if newsize is zero we use the per-platform default value for size of stack
if (newsize == 0)
{
newsize = IL2CPP_DEFAULT_STACK_SIZE;
}
m_StackSize = newsize;
}
static int GetMaxStackSize();
void QueueUserAPC(Thread::APCFunc func, void* context);
ApartmentState GetApartment();
ApartmentState GetExplicitApartment();
ApartmentState SetApartment(ApartmentState state);
void SetExplicitApartment(ApartmentState state);
static void Sleep(uint32_t ms, bool interruptible);
static uint64_t CurrentThreadId();
static ThreadImpl* CreateForCurrentThread();
#if NET_4_0
static bool YieldInternal();
#endif
#if IL2CPP_HAS_NATIVE_THREAD_CLEANUP
static void SetNativeThreadCleanup(Thread::ThreadCleanupFunc cleanupFunction);
static void RegisterCurrentThreadForCleanup(void* arg);
static void UnregisterCurrentThreadForCleanup();
static void OnCurrentThreadExiting();
#endif
private:
HANDLE m_ThreadHandle;
volatile DWORD m_ThreadId;
SIZE_T m_StackSize;
ApartmentState m_ApartmentState;
ThreadPriority m_Priority;
};
}
}
#endif
@@ -0,0 +1,27 @@
#pragma once
#if IL2CPP_THREADS_WIN32
#include "os/ErrorCodes.h"
#include "utils/NonCopyable.h"
#include "WindowsHelpers.h"
namespace il2cpp
{
namespace os
{
class ThreadLocalValueImpl : public il2cpp::utils::NonCopyable
{
public:
ThreadLocalValueImpl();
~ThreadLocalValueImpl();
ErrorCode SetValue(void* value);
ErrorCode GetValue(void** value);
private:
DWORD m_Index;
};
}
}
#endif
@@ -0,0 +1,7 @@
#pragma once
#if IL2CPP_TARGET_WINDOWS
#include "../c-api/Win32/WindowsHeaders.h"
#endif
@@ -0,0 +1,32 @@
#pragma once
#if IL2CPP_TARGET_WINDOWS
#include "WindowsHeaders.h"
#include "os/WaitStatus.h"
#if IL2CPP_TARGET_WINRT
#include "os/WinRT/Win32ApiWinRTEmulation.h"
#endif
#if IL2CPP_TARGET_XBOXONE
#include "os/XboxOne/Win32ApiXboxEmulation.h"
#endif
#if IL2CPP_TARGET_WINRT || IL2CPP_TARGET_XBOXONE
#include "os/WinRT/Win32ApiSharedEmulation.h"
#endif
namespace il2cpp
{
namespace os
{
namespace win
{
// Wait for a release of the given handle in way that can be interrupted by APCs.
WaitStatus WaitForSingleObjectAndAccountForAPCs(HANDLE handle, uint32_t ms, bool interruptible);
}
}
}
#endif // IL2CPP_TARGET_WINDOWS