[+] Interim and incomplete Unix/Linux buildability

This commit is contained in:
Reece Wilson 2022-03-22 03:53:08 +00:00
parent a5c2600f1f
commit ba8602744b
14 changed files with 95 additions and 26 deletions

View File

@ -62,7 +62,7 @@ namespace Aurora::Async
private:
void DispatchFrame(ProcessInfo &info) override
{
if constexpr (AuIsBaseOfTemplate<Frame_t, decltype(frame)>::value)
if constexpr (AuIsBaseOfTemplate<AuFunction, Frame_t>::value)
{
if (!frame)
{
@ -76,7 +76,7 @@ namespace Aurora::Async
void Shutdown() override
{
if constexpr (AuIsBaseOfTemplate<Cleanup_t, decltype(cleanup)>::value)
if constexpr (AuIsBaseOfTemplate<AuFunction, Cleanup_t>::value)
{
if (!cleanup)
{

View File

@ -70,7 +70,7 @@ namespace Aurora::Memory
}
template<typename T_t, typename B_t>
ExSharedPtr(const ExSharedPtr<T_t, B_t> &in) : Base_t(in.BasePointerType())
ExSharedPtr(const ExSharedPtr<T_t, B_t> &in) : Base_t(in.BasePointerType(), static_cast<T_t *>(in.get()))
{
#if !defined(_AURORA_NULLEXPT_ENABLE_UB)
_cache();
@ -78,7 +78,7 @@ namespace Aurora::Memory
}
template<typename T_t, typename B_t>
ExSharedPtr(ExSharedPtr<T_t, B_t> &&in) : Base_t(in.BasePointerType())
ExSharedPtr(ExSharedPtr<T_t, B_t> &&in) : Base_t(in.BasePointerType(), static_cast<T_t *>(in.get()))
{
#if !defined(_AURORA_NULLEXPT_ENABLE_UB)
_cache();

View File

@ -233,8 +233,8 @@ namespace Aurora::Console::ConsoleStd
#elif defined(AURORA_IS_POSIX_DERIVED)
// no always means no under UNIX targets
// we *know* stdin/out will be available under these standards
if (gRuntimeConfig.console.disableAllConsoles)
// we *know* stdin/out will be available under these standards, dont fuck with what might be an IPC channel
if (!gRuntimeConfig.console.enableConsole)
{
return;
}

View File

@ -12,7 +12,7 @@
#include "PublicECCImpl.hpp"
#include "PrivateECCImpl.hpp"
#include "ECCx25519Public.hpp"
#include "ECCX25519Public.hpp"
#include "ECCX25519Private.hpp"
extern "C" int x509_decode_subject_public_key_info_2(const unsigned char *in, unsigned long inlen,
@ -252,4 +252,4 @@ namespace Aurora::Crypto::ECC
{
ReleasePublicECC(pub);
}
}
}

View File

@ -7,7 +7,7 @@
***/
#include <Source/RuntimeInternal.hpp>
#include "ECC.hpp"
#include "ECCx25519Public.hpp"
#include "ECCX25519Public.hpp"
namespace Aurora::Crypto::ECC
{

View File

@ -13,7 +13,7 @@
#include <cpuid.h>
#endif
#include "CPUInfo.hpp"
#include "CpuInfo.hpp"
namespace Aurora::HWInfo
{

View File

@ -128,6 +128,7 @@ namespace Aurora::IO::FS
path_ = path;
}
// TODO: spinlock
AuUInt64 PosixFileStream::GetOffset()
{
if (handle_ == -1)
@ -138,7 +139,8 @@ namespace Aurora::IO::FS
return PosixGetOffset(handle_);
}
// ...
bool PosixFileStream::SetOffset(AuUInt64 offset)
{
if (handle_ == -1)
@ -150,6 +152,7 @@ namespace Aurora::IO::FS
return PosixSetOffset(handle_, offset);
}
// ...
AuUInt64 PosixFileStream::GetLength()
{
if (handle_ == -1)
@ -161,6 +164,7 @@ namespace Aurora::IO::FS
return PosixGetLength(handle_);
}
// ...
bool PosixFileStream::Read(const Memory::MemoryViewStreamWrite &parameters)
{
if (handle_ == -1)
@ -201,6 +205,7 @@ namespace Aurora::IO::FS
return true;
}
// ...
bool PosixFileStream::Write(const Memory::MemoryViewStreamRead &parameters)
{
if (handle_ == -1)
@ -258,6 +263,11 @@ namespace Aurora::IO::FS
fsync(handle_);
}
void PosixFileStream::WriteEoS()
{
ftruncate(handle_, GetOffset());
}
static IFileStream *OpenNew(const AuString &path, bool read)
{
auto pathex = NormalizePathRet(path);
@ -292,9 +302,9 @@ namespace Aurora::IO::FS
return OpenNew(path, true);
}
AUKN_SYM void OpenReadRelease(IFileStream * that)
AUKN_SYM void OpenReadRelease(IFileStream *that)
{
SafeDelete<PosixFileStream *>(that);
AuSafeDelete<PosixFileStream *>(that);
}
AUKN_SYM IFileStream *OpenWriteNew(const AuString &path)
@ -304,7 +314,7 @@ namespace Aurora::IO::FS
AUKN_SYM void OpenWriteRelease(IFileStream * that)
{
SafeDelete<PosixFileStream *>(that);
AuSafeDelete<PosixFileStream *>(that);
}
}
#endif

View File

@ -25,6 +25,7 @@ namespace Aurora::IO::FS
bool Write(const Memory::MemoryViewStreamRead & parameters) override;
void Close() override;
void Flush() override;
void WriteEoS() override;
private:
@ -32,4 +33,4 @@ namespace Aurora::IO::FS
AuString path_;
};
}
#endif
#endif

View File

@ -0,0 +1,19 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: WaitSingle.Linux.hpp
Date: 2022-3-22
Author: Reece
***/
#pragma once
namespace Aurora::Loop
{
struct WaitSingleGeneric : public WaitSingleBase
{
virtual bool WaitForAtleastOne(const AuList<AuUInt> &handles, AuUInt &one) override;
virtual void OnPresleep() override;
virtual void OnFinishSleep() override;
virtual ELoopSource GetType() override;
};
}

View File

@ -10,10 +10,20 @@
#include "Cache.hpp"
#include <Source/HWInfo/HWInfo.hpp>
#define LINUX_SUPPORTS_CACHE_CTL 0
#if defined(AURORA_IS_LINUX_DERIVED)
#include <sys/mman.h>
#if LINUX_SUPPORTS_CACHE_CTL
#include <sys/cachectl.h>
#endif
#endif
#if defined(AURORA_IS_XNU_DERIVED)
void sys_icache_invalidate(void *start, size_t len);
#endif
namespace Aurora::Memory::Cache
{
AUKN_SYM void OptimizeAddressRangeOnCore(const AuList<AuPair<AuUInt, AuUInt>> &addressRanges)
@ -30,8 +40,8 @@ namespace Aurora::Memory::Cache
for (const auto &addressRange : addressRanges)
{
auto base = AuPageRound(addressRange.first, AuHwInfo::gPageSize);
auto length = AuPageRoundUp(addressRange.second + (addressRange.first - base), AuHwInfo::gPageSize);
auto base = AuPageRound(addressRange.first, AuUInt(AuHwInfo::gPageSize));
auto length = AuPageRoundUp(addressRange.second + (addressRange.first - base), AuUInt(AuHwInfo::gPageSize));
#if defined(AURORA_IS_MODERNNT_DERIVED)
arry[index++] = {
@ -46,7 +56,7 @@ namespace Aurora::Memory::Cache
// https://www.freebsd.org/cgi/man.cgi?query=madvise&apropos=0&sektion=2&manpath=FreeBSD+9.0-RELEASE&arch=default&format=html
// https://man7.org/linux/man-pages/man2/madvise.2.html
if (madvise(AuReinterpretCast<const void *>(base), length, MADV_WILLNEED) != 0)
if (madvise(AuReinterpretCast<void *>(base), length, MADV_WILLNEED) != 0)
{
SysPushErrorHAL("Couldn't advice memory range 0x{:x} {}", base, length);
}
@ -63,14 +73,39 @@ namespace Aurora::Memory::Cache
AUKN_SYM void ClearInstructionCache(const AuPair<AuUInt, AuUInt> &addressRange)
{
auto base = AuPageRound(addressRange.first, AuHwInfo::gPageSize);
auto length = AuPageRoundUp(addressRange.second + (addressRange.first - base), AuHwInfo::gPageSize);
auto base = AuPageRound(addressRange.first, AuUInt(AuHwInfo::gPageSize));
auto length = AuPageRoundUp(addressRange.second + (addressRange.first - base), AuUInt(AuHwInfo::gPageSize));
#if defined(AURORA_IS_MODERNNT_DERIVED)
FlushInstructionCache(GetCurrentProcess(), AuReinterpretCast<LPCVOID>(base), length);
#elif defined(AURORA_IS_XNU_DERIVED)
// https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/sys_icache_invalidate.3.html
sys_icache_invalidate(AuReinterpretCast<const void *>(base), length);
#elif defined(AURORA_IS_LINUX_DERIVED) && defined(LINUX_SUPPORTS_CACHE_CTL) && LINUX_SUPPORTS_CACHE_CTL
// https://man7.org/linux/man-pages/man2/cacheflush.2.html
cacheflush(AuReinterpretCast<const void *>(base), length, ICACHE);
#elif (defined(AURORA_ARCH_X86) || defined(AURORA_ARCH_X64)) && (defined(AURORA_COMPILER_CLANG) || AURORA_COMPILER_GCC)
const size_t cacheLine = 64; // TODO: pull from Aurora::HWInfo
asm volatile("sfence\n\t"
:
:
: "memory");
for (AuUInt i = 0; i < length; i += cacheLine)
{
asm volatile("clflush (%0)\n\t"
:
: "r"(AuReinterpretCast<const char *>(base) + i)
: "memory");
}
#elif defined(AURORA_COMPILER_GCC)
__builtin___clear_cache(AuReinterpretCast<const char *>(base), AuReinterpretCast<const char *>(base) + length);
#elif defined(AURORA_COMPILER_CLANG)
#elif defined(AURORA_COMPILER_CLANG) && defined(AURORA_ARCH_ARM)
// https://github.com/llvm/llvm-project/blob/d480f968ad8b56d3ee4a6b6df5532d485b0ad01e/clang/include/clang/Basic/BuiltinsARM.def#L25
// Does not exist anywhere else
__clear_cache(AuReinterpretCast<const char *>(base), AuReinterpretCast<const char *>(base) + length);
#endif
}

View File

@ -12,6 +12,10 @@
#include "mimalloc.h"
#include "o1heap.hpp"
#if defined(AURORA_IS_POSIX_DERIVED)
#include <sys/mman.h>
#endif
namespace Aurora::Memory
{
static AuUInt32 RoundPageUp(AuUInt32 value)

View File

@ -45,7 +45,7 @@ namespace Aurora::Threading::Primitives
AUKN_SYM void ConditionMutexRelease(IConditionMutex *mutex)
{
SafeDelete<UnixConditionMutex *>(mutex);
AuSafeDelete<UnixConditionMutex *>(mutex);
}
}

View File

@ -76,8 +76,8 @@ namespace Aurora::Threading::Primitives
AUKN_SYM void ConditionVariableRelease(IConditionVariable *mutex)
{
SafeDelete<ConditionVariableImpl *>(mutex);
AuSafeDelete<ConditionVariableImpl *>(mutex);
}
}
#endif
#endif

View File

@ -86,8 +86,8 @@ namespace Aurora::Threading::Primitives
AUKN_SYM void MutexRelease(IWaitable *waitable)
{
SafeDelete<Mutex *>(waitable);
AuSafeDelete<Mutex *>(waitable);
}
}
#endif
#endif