Reece
cf70f0d45c
The intention is to quickly improve and add util apis, enhance functionality given current demands, go back to the build pipeline, finish that, publish runtime tests, and then use what we have to go back to to linux support with a more stable api. [+] AuMakeSharedArray [+] Technet ArgvQuote [+] Grug subsystem (UNIX signal thread async safe ipc + telemetry flusher + log flusher.) [+] auEndianness -> Endian swap utils [+] AuGet<N>(...) [*] AUE_DEFINE conversion for ECompresionType, EAnsiColor, EHashType, EStreamError, EHexDump [+] ConsoleMessage ByteBuffer serialization [+] CmdLine subsystem for parsing command line arguments and simple switch/flag checks [*] Split logger from console subsystem [+] StartupParameters -> A part of a clean up effort under Process [*] Refactor SysErrors header + get caller hack [+] Atomic APIs [+] popcnt [+] Ring Buffer sink [+] Added more standard errors Catch, Submission, LockError, NoAccess, ResourceMissing, ResourceLocked, MalformedData, InSandboxContext, ParseError [+] Added ErrorCategorySet, ErrorCategoryClear, GetStackTrace [+] IExitSubscriber, ETriggerLevel [*] Write bias the high performance RWLockImpl read-lock operation operation [+] ExitHandlerAdd/ExitHandlerRemove (exit subsystem) [*] Updated API style Digests [+] CpuId::CpuBitCount [+] GetUserProgramsFolder [+] GetPackagePath [*] Split IStreamReader with an inl file [*] BlobWriter/BlobReader/BlobArbitraryReader can now take shared pointers to bytebuffers. default constructor allocates a new scalable bytebuffer [+] ICharacterProvider [+] ICharacterProviderEx [+] IBufferedCharacterConsumer [+] ProviderFromSharedString [+] ProviderFromString [+] BufferConsumerFromProvider [*] Parse Subsystem uses character io bufferer [*] Rewritten NT's high perf semaphore to use userland SRW/ConVars [like mutex, based on generic semaphore] [+] ByteBuffer::ResetReadPointer [*] Bug fix bytebuffer base not reset on free and some scaling issues [+] ProcessMap -> Added kSectionNameStack, kSectionNameFile, kSectionNameHeap for Section [*] ProcessMap -> Refactor Segment to Section. I was stupid for keeping a type conflict hack API facing [+] Added 64 *byte* fast RNG seeds [+] File Advisorys/File Lock Awareness [+] Added extended IAuroraThread from OS identifier caches for debug purposes [*] Tweaked how memory is reported on Windows. Better consistency of what values mean across functions. [*] Broke AuroraUtils/Typedefs out into a separate library [*] Update build script [+] Put some more effort into adding detail to the readme before rewriting it, plus, added some media [*] Improved public API documentation [*] Bug fix `SetConsoleCtrlHandler` [+] Locale TimeDateToFileNameISO8601 [+] Console config stdOutShortTime [*] Begin using internal UTF8/16 decoders when platform support isnt available (instead of stl) [*] Bug fixes in decoders [*] Major bug fix, AuMax [+] RateLimiter [+] Binary file sink [+] Log directory sink [*] Data header usability (more operators) [+] AuRemoveRange [+] AuRemove [+] AuTryRemove [+] AuTryRemoveRange [+] auCastUtils [+] Finish NewLSWin32Source [+] AuTryFindByTupleN, AuTryRemoveByTupleN [+] Separated AuRead/Write types, now in auTypeUtils [+] Added GetPosition/SetPosition to FileWriter [*] Fix stupid AuMin in place of AuMax in SpawnThread.Unix.Cpp [*] Refactored Arbitrary readers to SeekingReaders (as in, they could be atomic and/or parallelized, and accept an arbitrary position as a work parameter -> not Seekable, as in, you can simply set the position) [*] Hack back in the sched deinit [+] File AIO loop source interop [+] Begin to prototype a LoopQueue object I had in mind for NT, untested btw [+] Stub code for networking [+] Compression BaseStream/IngestableStreamBase [*] Major: read/write locks now support write-entrant read routines. [*] Compression subsystem now uses the MemoryView concept [*] Rewrite the base stream compressions, made them less broken [*] Update hashing api [*] WriterTryGoForward and ReaderTryGoForward now revert to the previous relative index instead of panicing [+] Added new AuByteBuffer apis Trim, Pad, WriteFrom, WriteString, [TODO: ReadString] [+] Added ByteBufferPushReadState [+] Added ByteBufferPushWriteState [*] Move from USC-16 to full UTF-16. Win32 can handle full UTF-16. [*] ELogLevel is now an Aurora enum [+] Raised arbitrary limit in header to 255, the max filter buffer [+] Explicit GZip support [+] Explicit Zip support [+] Added [some] compressors et al
262 lines
6.2 KiB
C++
262 lines
6.2 KiB
C++
/***
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: Paths.cpp
|
|
Date: 2021-7-14
|
|
Author: Reece
|
|
***/
|
|
#include <Source/RuntimeInternal.hpp>
|
|
#include "Paths.hpp"
|
|
|
|
#if defined(AURORA_IS_POSIX_DERIVED)
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#define _USE_GET_CWD
|
|
#endif
|
|
|
|
namespace Aurora::Process
|
|
{
|
|
AUKN_SYM bool GetWorkingDirectory(AuString &path)
|
|
{
|
|
if (!AuTryResize(path, 0x4000))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
|
|
|
std::wstring eh;
|
|
eh.resize(path.size());
|
|
|
|
auto length = ::GetCurrentDirectoryW(eh.size(), eh.data());
|
|
if (length == 0)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
path = Locale::ConvertFromWChar(eh.data(), length);
|
|
|
|
return true;
|
|
|
|
#elif defined(AURORA_PLATFORM_ANDROID)
|
|
|
|
// TODO: consider pulling internal storage package directory
|
|
return false;
|
|
|
|
#elif defined(_USE_GET_CWD)
|
|
|
|
if (getcwd(path.data(), path.size()) == nullptr)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
path.resize(strlen(path.data()));
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
return false;
|
|
}
|
|
|
|
static bool GetModulePathSlow(AuString &path, char &splitter)
|
|
{
|
|
path.clear();
|
|
splitter = 0;
|
|
|
|
// TODO: BSD alternative sysctl CTL_KERN KERN_PROC KERN_PROC_PATHNAME -1
|
|
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
|
|
|
wchar_t chungus[0x4000];
|
|
auto len = GetModuleFileNameW(
|
|
NULL,
|
|
chungus,
|
|
AuArraySize(chungus)
|
|
);
|
|
|
|
if (!len)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
path = Aurora::Locale::ConvertFromWChar(chungus, len);
|
|
splitter = '\\';
|
|
|
|
if (AuEndsWith(path, ".dll"))
|
|
{
|
|
path.clear();
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
|
|
#elif defined(AURORA_IS_XNU_DERIVED)
|
|
// TODO: _NSGetExecutablePath() or CFBundleCopyExecutableURL?
|
|
// i think it would make sense to use NS over CoreFoundation
|
|
// i think we're also going to have to use CF's libevent abstraction - runloop source
|
|
// to pass through kqueue structures with the mach window message loop, like how
|
|
// user32 has MsgWaitMultipleObjects.
|
|
// t. windows and loonix dev
|
|
//
|
|
// TODO: if macos >= 10.12 || quarantine xattr
|
|
// /Applications/<app name>
|
|
CFURLRef bundleURL = CFBundleCopyExecutableURL(CFBundleGetMainBundle());
|
|
CFStringRef pathRef = CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle);
|
|
|
|
auto utf16length = CFStringGetLength(pathRef);
|
|
auto maxUtf8len = CFStringGetMaximumSizeForEncoding(utf16length, kCFStringEncodingUTF8);
|
|
|
|
path.resize(maxUtf8len);
|
|
|
|
if (!CFStringGetCString(pathRef, path.data(), maxUtf8len, kCFStringEncodingUTF8))
|
|
{
|
|
path.clear();
|
|
return false;
|
|
}
|
|
|
|
path.resize(std::strlen(path.c_str()));
|
|
splitter = '/';
|
|
|
|
#elif defined(AURORA_PLATFORM_ANDROID)
|
|
|
|
// SELinux gets in the way in some instances
|
|
// There is no reason we should be searching for the jre binary
|
|
// I'm also not convined pulling a cached apk path is the best thing to do here
|
|
// Why should we even bother pulling /system/bin/app_process?
|
|
|
|
return false;
|
|
|
|
#elif defined(AURORA_IS_POSIX_DERIVED)
|
|
|
|
static const AuList<AuString> procFsPaths = {
|
|
"/proc/self/exe",
|
|
"/proc/self/file",
|
|
"/proc/curproc/exe",
|
|
"/proc/curproc/file"
|
|
};
|
|
|
|
for (const auto &name : procFsPaths)
|
|
{
|
|
if (AuIOFS::ReadString(name, path))
|
|
{
|
|
splitter = '/';
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
|
|
#endif
|
|
}
|
|
|
|
static bool GetModulePath(AuString &module, AuString &partialPath, AuString &fullPath)
|
|
{
|
|
static AuString cachedModule, cachedPartialPath, cachedFullPath;
|
|
static bool init = false;
|
|
static AuThreadPrimitives::SpinLock spinlock;
|
|
char spitter;
|
|
|
|
AU_TRY_LOCK_GUARD_RET_DEF(spinlock);
|
|
|
|
if (AuExchange(init, true))
|
|
{
|
|
if (!cachedModule.size())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
goto returnCached;
|
|
}
|
|
|
|
if (!GetModulePathSlow(cachedFullPath, spitter))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
// this scope is required for c++20, bleh
|
|
{
|
|
auto indexA = cachedFullPath.find_last_of(spitter);
|
|
if (indexA == AuString::npos)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
cachedModule = cachedFullPath.substr(indexA + 1);
|
|
cachedPartialPath = cachedFullPath.substr(0, indexA);
|
|
}
|
|
|
|
returnCached:
|
|
module = cachedModule;
|
|
fullPath = cachedFullPath;
|
|
partialPath = cachedPartialPath;
|
|
return true;
|
|
}
|
|
|
|
AUKN_SYM bool GetProcName(AuString &executable)
|
|
{
|
|
AuString module, partial, full;
|
|
|
|
try
|
|
{
|
|
if (!GetModulePath(module, partial, full))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
executable = module;
|
|
}
|
|
catch (...)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
AUKN_SYM bool GetProcDirectory(AuString &path)
|
|
{
|
|
AuString module, partial, full;
|
|
|
|
try
|
|
{
|
|
if (!GetModulePath(module, partial, full))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
path = partial;
|
|
|
|
if (path.empty())
|
|
{
|
|
return GetWorkingDirectory(path);
|
|
}
|
|
}
|
|
catch (...)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
AUKN_SYM bool GetProcFullPath(AuString &path)
|
|
{
|
|
AuString module, partial, full;
|
|
|
|
try
|
|
{
|
|
if (!GetModulePath(module, partial, full))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
path = full;
|
|
}
|
|
catch (...)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
} |