Merge remote-tracking branch 'upstream/master'

pull/9/head
987123879113 1 year ago
commit 6f2d25d8f4
  1. 90
      3rdparty/zydis/CMakeLists.txt
  2. 23
      3rdparty/zydis/LICENSE
  3. 178
      3rdparty/zydis/README.md
  4. 23
      3rdparty/zydis/dependencies/zycore/LICENSE
  5. 29
      3rdparty/zydis/dependencies/zycore/README.md
  6. 137
      3rdparty/zydis/dependencies/zycore/include/Zycore/API/Memory.h
  7. 70
      3rdparty/zydis/dependencies/zycore/include/Zycore/API/Process.h
  8. 132
      3rdparty/zydis/dependencies/zycore/include/Zycore/API/Synchronization.h
  9. 162
      3rdparty/zydis/dependencies/zycore/include/Zycore/API/Terminal.h
  10. 243
      3rdparty/zydis/dependencies/zycore/include/Zycore/API/Thread.h
  11. 142
      3rdparty/zydis/dependencies/zycore/include/Zycore/Allocator.h
  12. 173
      3rdparty/zydis/dependencies/zycore/include/Zycore/ArgParse.h
  13. 236
      3rdparty/zydis/dependencies/zycore/include/Zycore/Atomic.h
  14. 483
      3rdparty/zydis/dependencies/zycore/include/Zycore/Bitset.h
  15. 316
      3rdparty/zydis/dependencies/zycore/include/Zycore/Comparison.h
  16. 521
      3rdparty/zydis/dependencies/zycore/include/Zycore/Defines.h
  17. 285
      3rdparty/zydis/dependencies/zycore/include/Zycore/Format.h
  18. 117
      3rdparty/zydis/dependencies/zycore/include/Zycore/Internal/AtomicGNU.h
  19. 141
      3rdparty/zydis/dependencies/zycore/include/Zycore/Internal/AtomicMSVC.h
  20. 511
      3rdparty/zydis/dependencies/zycore/include/Zycore/LibC.h
  21. 573
      3rdparty/zydis/dependencies/zycore/include/Zycore/List.h
  22. 84
      3rdparty/zydis/dependencies/zycore/include/Zycore/Object.h
  23. 287
      3rdparty/zydis/dependencies/zycore/include/Zycore/Status.h
  24. 1011
      3rdparty/zydis/dependencies/zycore/include/Zycore/String.h
  25. 236
      3rdparty/zydis/dependencies/zycore/include/Zycore/Types.h
  26. 722
      3rdparty/zydis/dependencies/zycore/include/Zycore/Vector.h
  27. 110
      3rdparty/zydis/dependencies/zycore/include/Zycore/Zycore.h
  28. 132
      3rdparty/zydis/dependencies/zycore/src/API/Memory.c
  29. 76
      3rdparty/zydis/dependencies/zycore/src/API/Process.c
  30. 204
      3rdparty/zydis/dependencies/zycore/src/API/Synchronization.c
  31. 160
      3rdparty/zydis/dependencies/zycore/src/API/Terminal.c
  32. 244
      3rdparty/zydis/dependencies/zycore/src/API/Thread.c
  33. 134
      3rdparty/zydis/dependencies/zycore/src/Allocator.c
  34. 279
      3rdparty/zydis/dependencies/zycore/src/ArgParse.c
  35. 670
      3rdparty/zydis/dependencies/zycore/src/Bitset.c
  36. 507
      3rdparty/zydis/dependencies/zycore/src/Format.c
  37. 673
      3rdparty/zydis/dependencies/zycore/src/List.c
  38. 1098
      3rdparty/zydis/dependencies/zycore/src/String.c
  39. 846
      3rdparty/zydis/dependencies/zycore/src/Vector.c
  40. 38
      3rdparty/zydis/dependencies/zycore/src/Zycore.c
  41. 46
      3rdparty/zydis/include/ZycoreExportConfig.h
  42. 237
      3rdparty/zydis/include/Zydis/Decoder.h
  43. 1559
      3rdparty/zydis/include/Zydis/DecoderTypes.h
  44. 1190
      3rdparty/zydis/include/Zydis/Formatter.h
  45. 306
      3rdparty/zydis/include/Zydis/FormatterBuffer.h
  46. 104
      3rdparty/zydis/include/Zydis/Generated/EnumISAExt.h
  47. 196
      3rdparty/zydis/include/Zydis/Generated/EnumISASet.h
  48. 124
      3rdparty/zydis/include/Zydis/Generated/EnumInstructionCategory.h
  49. 1770
      3rdparty/zydis/include/Zydis/Generated/EnumMnemonic.h
  50. 302
      3rdparty/zydis/include/Zydis/Generated/EnumRegister.h
  51. 331
      3rdparty/zydis/include/Zydis/Internal/DecoderData.h
  52. 182
      3rdparty/zydis/include/Zydis/Internal/FormatterATT.h
  53. 318
      3rdparty/zydis/include/Zydis/Internal/FormatterBase.h
  54. 269
      3rdparty/zydis/include/Zydis/Internal/FormatterIntel.h
  55. 984
      3rdparty/zydis/include/Zydis/Internal/SharedData.h
  56. 464
      3rdparty/zydis/include/Zydis/Internal/String.h
  57. 88
      3rdparty/zydis/include/Zydis/MetaInfo.h
  58. 88
      3rdparty/zydis/include/Zydis/Mnemonic.h
  59. 293
      3rdparty/zydis/include/Zydis/Register.h
  60. 484
      3rdparty/zydis/include/Zydis/SharedTypes.h
  61. 90
      3rdparty/zydis/include/Zydis/ShortString.h
  62. 159
      3rdparty/zydis/include/Zydis/Status.h
  63. 275
      3rdparty/zydis/include/Zydis/Utils.h
  64. 169
      3rdparty/zydis/include/Zydis/Zydis.h
  65. 46
      3rdparty/zydis/include/ZydisExportConfig.h
  66. 5116
      3rdparty/zydis/src/Decoder.c
  67. 174
      3rdparty/zydis/src/DecoderData.c
  68. 702
      3rdparty/zydis/src/Formatter.c
  69. 424
      3rdparty/zydis/src/FormatterATT.c
  70. 782
      3rdparty/zydis/src/FormatterBase.c
  71. 191
      3rdparty/zydis/src/FormatterBuffer.c
  72. 453
      3rdparty/zydis/src/FormatterIntel.c
  73. 78
      3rdparty/zydis/src/Generated/AccessedFlags.inc
  74. 7585
      3rdparty/zydis/src/Generated/DecoderTables.inc
  75. 92
      3rdparty/zydis/src/Generated/EnumISAExt.inc
  76. 184
      3rdparty/zydis/src/Generated/EnumISASet.inc
  77. 112
      3rdparty/zydis/src/Generated/EnumInstructionCategory.inc
  78. 1758
      3rdparty/zydis/src/Generated/EnumMnemonic.inc
  79. 290
      3rdparty/zydis/src/Generated/EnumRegister.inc
  80. 816
      3rdparty/zydis/src/Generated/FormatterStrings.inc
  81. 7839
      3rdparty/zydis/src/Generated/InstructionDefinitions.inc
  82. 23
      3rdparty/zydis/src/Generated/InstructionEncodings.inc
  83. 7437
      3rdparty/zydis/src/Generated/OperandDefinitions.inc
  84. 68
      3rdparty/zydis/src/MetaInfo.c
  85. 52
      3rdparty/zydis/src/Mnemonic.c
  86. 303
      3rdparty/zydis/src/Register.c
  87. 188
      3rdparty/zydis/src/SharedData.c
  88. 362
      3rdparty/zydis/src/String.c
  89. 373
      3rdparty/zydis/src/Utils.c
  90. 73
      3rdparty/zydis/src/Zydis.c
  91. 130
      3rdparty/zydis/zydis.vcxproj
  92. 92
      3rdparty/zydis/zydis.vcxproj.filters
  93. 15
      PCSX2_qt.sln
  94. 25
      bin/resources/GameIndex.yaml
  95. 1
      cmake/SearchForStuff.cmake
  96. 35
      common/General.h
  97. 84
      common/Linux/LnxHostSys.cpp
  98. 4
      common/PageFaultSource.h
  99. 8
      common/RedtapeWindows.h
  100. 191
      common/Windows/WinHostSys.cpp
  101. Some files were not shown because too many files have changed in this diff Show More

@ -0,0 +1,90 @@
add_library(zydis
dependencies/zycore/src/Allocator.c
dependencies/zycore/src/API/Memory.c
dependencies/zycore/src/API/Process.c
dependencies/zycore/src/API/Synchronization.c
dependencies/zycore/src/API/Terminal.c
dependencies/zycore/src/API/Thread.c
dependencies/zycore/src/ArgParse.c
dependencies/zycore/src/Bitset.c
dependencies/zycore/src/Format.c
dependencies/zycore/src/List.c
dependencies/zycore/src/String.c
dependencies/zycore/src/Vector.c
dependencies/zycore/src/Zycore.c
src/Decoder.c
src/DecoderData.c
src/Formatter.c
src/FormatterATT.c
src/FormatterBase.c
src/FormatterBuffer.c
src/FormatterIntel.c
src/MetaInfo.c
src/Mnemonic.c
src/Register.c
src/SharedData.c
src/String.c
src/Utils.c
src/Zydis.c
dependencies/zycore/include/Zycore/Allocator.h
dependencies/zycore/include/Zycore/API/Memory.h
dependencies/zycore/include/Zycore/API/Process.h
dependencies/zycore/include/Zycore/API/Synchronization.h
dependencies/zycore/include/Zycore/API/Terminal.h
dependencies/zycore/include/Zycore/API/Thread.h
dependencies/zycore/include/Zycore/ArgParse.h
dependencies/zycore/include/Zycore/Atomic.h
dependencies/zycore/include/Zycore/Bitset.h
dependencies/zycore/include/Zycore/Comparison.h
dependencies/zycore/include/Zycore/Defines.h
dependencies/zycore/include/Zycore/Format.h
dependencies/zycore/include/Zycore/Internal/AtomicGNU.h
dependencies/zycore/include/Zycore/Internal/AtomicMSVC.h
dependencies/zycore/include/Zycore/LibC.h
dependencies/zycore/include/Zycore/List.h
dependencies/zycore/include/Zycore/Object.h
dependencies/zycore/include/Zycore/Status.h
dependencies/zycore/include/Zycore/String.h
dependencies/zycore/include/Zycore/Types.h
dependencies/zycore/include/Zycore/Vector.h
dependencies/zycore/include/Zycore/Zycore.h
include/Zydis/Decoder.h
include/Zydis/DecoderTypes.h
include/Zydis/Formatter.h
include/Zydis/FormatterBuffer.h
include/Zydis/Generated/EnumInstructionCategory.h
include/Zydis/Generated/EnumISAExt.h
include/Zydis/Generated/EnumISASet.h
include/Zydis/Generated/EnumMnemonic.h
include/Zydis/Generated/EnumRegister.h
include/Zydis/Internal/DecoderData.h
include/Zydis/Internal/FormatterATT.h
include/Zydis/Internal/FormatterBase.h
include/Zydis/Internal/FormatterIntel.h
include/Zydis/Internal/SharedData.h
include/Zydis/Internal/String.h
include/Zydis/MetaInfo.h
include/Zydis/Mnemonic.h
include/Zydis/Register.h
include/Zydis/SharedTypes.h
include/Zydis/ShortString.h
include/Zydis/Status.h
include/Zydis/Utils.h
include/Zydis/Zydis.h
)
target_compile_definitions(zydis PUBLIC
ZYCORE_STATIC_DEFINE
ZYDIS_STATIC_DEFINE
)
target_include_directories(zydis PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/dependencies/zycore/include
${CMAKE_CURRENT_SOURCE_DIR}/include
)
target_include_directories(zydis PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/dependencies/zycore/src
${CMAKE_CURRENT_SOURCE_DIR}/src
)

@ -0,0 +1,23 @@
The MIT License (MIT)
Copyright (c) 2014-2021 Florian Bernd
Copyright (c) 2014-2021 Joel Hรถner
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

@ -0,0 +1,178 @@
<p align="center">
<img alt="zydis logo" src="https://zydis.re/img/logo.svg" width="400px">
</p>
<p align="center">
<img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="License: MIT">
<a href="https://github.com/zyantific/zydis/actions"><img src="https://github.com/zyantific/zydis/workflows/GitHub%20Actions%20CI/badge.svg" alt="GitHub Actions"></a>
<a href="https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:zydis"><img src="https://oss-fuzz-build-logs.storage.googleapis.com/badges/zydis.svg" alt="Fuzzing Status"></a>
<a href="https://gitter.im/zyantific/zydis?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=body_badge"><img src="https://badges.gitter.im/zyantific/zyan-disassembler-engine.svg" alt="Gitter"></a>
<a href="https://discord.zyantific.com/"><img src="https://img.shields.io/discord/390136917779415060.svg?logo=discord&label=Discord" alt="Discord"></a>
</p>
<p align="center">Fast and lightweight x86/x86-64 disassembler library.</p>
## Features
- Supports all x86 and x86-64 (AMD64) instructions and [extensions](./include/Zydis/Generated/EnumISAExt.h)
- Optimized for high performance
- No dynamic memory allocation ("malloc")
- Thread-safe by design
- Very small file-size overhead compared to other common disassembler libraries
- [Complete doxygen documentation](https://zydis.re/doc/3/)
- Absolutely no third party dependencies โ€” not even libc
- Should compile on any platform with a working C99 compiler
- Tested on Windows, macOS, FreeBSD, Linux and UEFI, both user and kernel mode
## Quick Example
The following example program uses Zydis to disassemble a given memory buffer and prints the output to the console ([more examples here](./examples/)).
```C
#include <stdio.h>
#include <inttypes.h>
#include <Zydis/Zydis.h>
int main()
{
ZyanU8 data[] =
{
0x51, 0x8D, 0x45, 0xFF, 0x50, 0xFF, 0x75, 0x0C, 0xFF, 0x75,
0x08, 0xFF, 0x15, 0xA0, 0xA5, 0x48, 0x76, 0x85, 0xC0, 0x0F,
0x88, 0xFC, 0xDA, 0x02, 0x00
};
// Initialize decoder context
ZydisDecoder decoder;
ZydisDecoderInit(&decoder, ZYDIS_MACHINE_MODE_LONG_64, ZYDIS_ADDRESS_WIDTH_64);
// Initialize formatter. Only required when you actually plan to do instruction
// formatting ("disassembling"), like we do here
ZydisFormatter formatter;
ZydisFormatterInit(&formatter, ZYDIS_FORMATTER_STYLE_INTEL);
// Loop over the instructions in our buffer.
// The runtime-address (instruction pointer) is chosen arbitrary here in order to better
// visualize relative addressing
ZyanU64 runtime_address = 0x007FFFFFFF400000;
ZyanUSize offset = 0;
const ZyanUSize length = sizeof(data);
ZydisDecodedInstruction instruction;
while (ZYAN_SUCCESS(ZydisDecoderDecodeBuffer(&decoder, data + offset, length - offset,
&instruction)))
{
// Print current instruction pointer.
printf("%016" PRIX64 " ", runtime_address);
// Format & print the binary instruction structure to human readable format
char buffer[256];
ZydisFormatterFormatInstruction(&formatter, &instruction, buffer, sizeof(buffer),
runtime_address);
puts(buffer);
offset += instruction.length;
runtime_address += instruction.length;
}
}
```
## Sample Output
The above example program generates the following output:
```asm
007FFFFFFF400000 push rcx
007FFFFFFF400001 lea eax, [rbp-0x01]
007FFFFFFF400004 push rax
007FFFFFFF400005 push qword ptr [rbp+0x0C]
007FFFFFFF400008 push qword ptr [rbp+0x08]
007FFFFFFF40000B call [0x008000007588A5B1]
007FFFFFFF400011 test eax, eax
007FFFFFFF400013 js 0x007FFFFFFF42DB15
```
## Build
#### Unix
Zydis builds cleanly on most platforms without any external dependencies. You can use CMake to generate project files for your favorite C99 compiler.
```bash
git clone --recursive 'https://github.com/zyantific/zydis.git'
cd zydis
mkdir build && cd build
cmake ..
make
```
#### Windows
Either use the [Visual Studio 2017 project](./msvc/) or build Zydis using [CMake](https://cmake.org/download/) ([video guide](https://www.youtube.com/watch?v=fywLDK1OAtQ)).
#### Building Zydis - Using vcpkg
You can download and install Zydis using the [vcpkg](https://github.com/Microsoft/vcpkg) dependency manager:
```bash
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg integrate install
vcpkg install zydis
```
The Zydis port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.
## Using Zydis in a CMake project
An example on how to use Zydis in your own CMake based project [can be found in this repo](https://github.com/zyantific/zydis-submodule-example).
## `ZydisInfo` tool
![ZydisInfo](./assets/screenshots/ZydisInfo.png)
## Bindings
Official bindings exist for a selection of languages:
- [Pascal](https://github.com/zyantific/zydis-pascal)
- [Python 3](https://github.com/zyantific/zydis-py)
- [Rust](https://github.com/zyantific/zydis-rs)
Unofficial but actively maintained bindings:
- [Go](https://github.com/jpap/go-zydis)
- [LuaJIT](https://github.com/Wiladams/lj2zydis)
- [Haskell](https://github.com/nerded1337/zydiskell)
## Versions
#### Scheme
Versions follow the [semantic versioning scheme](https://semver.org/). All stability guarantees apply to the API only โ€” ABI stability between patches cannot be assumed unless explicitly mentioned in the release notes.
#### Branches & Tags
- `master` holds the bleeding edge code of the next, unreleased Zydis version. Elevated amounts of bugs and issues must be expected, API stability is not guaranteed outside of tagged commits.
- Stable and preview versions are annotated with git tags
- beta and other preview versions have `-beta`, `-rc`, etc. suffixes
- `maintenance/v2` contains the code of the latest legacy release of v2
- v2 is now deprecated, but will receive security fixes until 2021
## Credits
- Intel (for open-sourcing [XED](https://github.com/intelxed/xed), allowing for automatic comparison of our tables against theirs, improving both)
- [LLVM](https://llvm.org) (for providing pretty solid instruction data as well)
- Christian Ludloff (http://sandpile.org, insanely helpful)
- [LekoArts](https://www.lekoarts.de/) (for creating the project logo)
- Our [contributors on GitHub](https://github.com/zyantific/zydis/graphs/contributors)
## Troubleshooting
#### `-fPIC` for shared library builds
```
/usr/bin/ld: ./libfoo.a(foo.c.o): relocation R_X86_64_PC32 against symbol `bar' can not be used when making a shared object; recompile with -fPIC
```
Under some circumstances (e.g. when building Zydis as a static library using
CMake and then using Makefiles to manually link it into a shared library), CMake
might fail to detect that relocation information must be emitted. This can be forced
by passing `-DCMAKE_POSITION_INDEPENDENT_CODE=ON` to the CMake invocation.
## Consulting and Business Support
We offer consulting services and professional business support for Zydis. If you need a custom extension, require help in integrating Zydis into your product or simply want contractually guaranteed updates and turnaround times, we are happy to assist with that! Please contact us at business@zyantific.com.
## Donations
Since GitHub Sponsors currently doesn't support sponsoring teams directly, donations are collected and distributed using [flobernd](https://github.com/users/flobernd/sponsorship)s account.
## License
Zydis is licensed under the MIT license.

@ -0,0 +1,23 @@
The MIT License (MIT)
Copyright (c) 2018-2020 Florian Bernd
Copyright (c) 2018-2020 Joel Hรถner
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

@ -0,0 +1,29 @@
# Zyan Core Library for C
<a href="./LICENSE"><img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="License: MIT"></a>
<a href="https://github.com/zyantific/zycore-c/actions"><img src="https://github.com/zyantific/zycore-c/workflows/GitHub%20Actions%20CI/badge.svg" alt="GitHub Actions"></a>
<a href="https://discord.zyantific.com/"><img src="https://img.shields.io/discord/390136917779415060.svg?logo=discord&label=Discord" alt="Discord"></a>
Internal library providing platform independent types, macros and a fallback for environments without LibC.
## Features
- Platform independent types
- Integer types (`ZyanU8`, `ZyanI32`, `ZyanUSize`, ...)
- `ZyanBool` (+ `ZYAN_FALSE`, `ZYAN_TRUE`)
- `ZYAN_NULL`
- Macros
- Compiler/Platform/Architecture detection
- Asserts and static asserts
- Utils (`ARRAY_LENGTH`, `FALLTHROUGH`, `UNUSED`, ...)
- Common types
- `ZyanBitset`
- `ZyanString`/`ZyanStringView`
- Container types
- `ZyanVector`
- `ZyanList`
- LibC abstraction (WiP)
## License
Zycore is licensed under the MIT license.

@ -0,0 +1,137 @@
/***************************************************************************************************
Zyan Core Library (Zycore-C)
Original Author : Florian Bernd
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
***************************************************************************************************/
/**
* @file
* @brief
*/
#ifndef ZYCORE_API_MEMORY_H
#define ZYCORE_API_MEMORY_H
#include <Zycore/Defines.h>
#include <Zycore/Status.h>
#include <Zycore/Types.h>
#ifndef ZYAN_NO_LIBC
#if defined(ZYAN_WINDOWS)
# include <windows.h>
#elif defined(ZYAN_POSIX)
# include <sys/mman.h>
#else
# error "Unsupported platform detected"
#endif
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
/**
* Defines the `ZyanMemoryPageProtection` enum.
*/
typedef enum ZyanMemoryPageProtection_
{
#if defined(ZYAN_WINDOWS)
ZYAN_PAGE_READONLY = PAGE_READONLY,
ZYAN_PAGE_READWRITE = PAGE_READWRITE,
ZYAN_PAGE_EXECUTE = PAGE_EXECUTE,
ZYAN_PAGE_EXECUTE_READ = PAGE_EXECUTE_READ,
ZYAN_PAGE_EXECUTE_READWRITE = PAGE_EXECUTE_READWRITE
#elif defined(ZYAN_POSIX)
ZYAN_PAGE_READONLY = PROT_READ,
ZYAN_PAGE_READWRITE = PROT_READ | PROT_WRITE,
ZYAN_PAGE_EXECUTE = PROT_EXEC,
ZYAN_PAGE_EXECUTE_READ = PROT_EXEC | PROT_READ,
ZYAN_PAGE_EXECUTE_READWRITE = PROT_EXEC | PROT_READ | PROT_WRITE
#endif
} ZyanMemoryPageProtection;
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* General */
/* ---------------------------------------------------------------------------------------------- */
/**
* Returns the system page size.
*
* @return The system page size.
*/
ZYCORE_EXPORT ZyanU32 ZyanMemoryGetSystemPageSize();
/**
* Returns the system allocation granularity.
*
* The system allocation granularity specifies the minimum amount of bytes which can be allocated
* at a specific address by a single call of `ZyanMemoryVirtualAlloc`.
*
* This value is typically 64KiB on Windows systems and equal to the page size on most POSIX
* platforms.
*
* @return The system allocation granularity.
*/
ZYCORE_EXPORT ZyanU32 ZyanMemoryGetSystemAllocationGranularity();
/* ---------------------------------------------------------------------------------------------- */
/* Memory management */
/* ---------------------------------------------------------------------------------------------- */
/**
* Changes the memory protection value of one or more pages.
*
* @param address The start address aligned to a page boundary.
* @param size The size.
* @param protection The new page protection value.
*
* @return A zyan status code.
*/
ZYCORE_EXPORT ZyanStatus ZyanMemoryVirtualProtect(void* address, ZyanUSize size,
ZyanMemoryPageProtection protection);
/**
* Releases one or more memory pages starting at the given address.
*
* @param address The start address aligned to a page boundary.
* @param size The size.
*
* @return A zyan status code.
*/
ZYCORE_EXPORT ZyanStatus ZyanMemoryVirtualFree(void* address, ZyanUSize size);
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
#endif /* ZYAN_NO_LIBC */
#endif /* ZYCORE_API_MEMORY_H */

@ -0,0 +1,70 @@
/***************************************************************************************************
Zyan Core Library (Zycore-C)
Original Author : Florian Bernd
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
***************************************************************************************************/
/**
* @file
* @brief
*/
#ifndef ZYCORE_API_PROCESS_H
#define ZYCORE_API_PROCESS_H
#include <Zycore/Status.h>
#include <Zycore/Types.h>
#ifndef ZYAN_NO_LIBC
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* General */
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Flushes the process instruction cache.
*
* @param address The address.
* @param size The size.
*
* @return A zyan status code.
*/
ZYCORE_EXPORT ZyanStatus ZyanProcessFlushInstructionCache(void* address, ZyanUSize size);
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
#endif /* ZYAN_NO_LIBC */
#endif /* ZYCORE_API_PROCESS_H */

@ -0,0 +1,132 @@
/***************************************************************************************************
Zyan Core Library (Zycore-C)
Original Author : Florian Bernd
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
***************************************************************************************************/
/**
* @file
* @brief
*/
#ifndef ZYCORE_API_SYNCHRONIZATION_H
#define ZYCORE_API_SYNCHRONIZATION_H
#include <Zycore/Defines.h>
#include <Zycore/Status.h>
#ifndef ZYAN_NO_LIBC
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
#if defined(ZYAN_POSIX)
#include <pthread.h>
/* ---------------------------------------------------------------------------------------------- */
/* Critical Section */
/* ---------------------------------------------------------------------------------------------- */
typedef pthread_mutex_t ZyanCriticalSection;
/* ---------------------------------------------------------------------------------------------- */
#elif defined(ZYAN_WINDOWS)
#include <windows.h>
/* ---------------------------------------------------------------------------------------------- */
/* Critical Section */
/* ---------------------------------------------------------------------------------------------- */
typedef CRITICAL_SECTION ZyanCriticalSection;
/* ---------------------------------------------------------------------------------------------- */
#else
# error "Unsupported platform detected"
#endif
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Critical Section */
/* ---------------------------------------------------------------------------------------------- */
/**
* Initializes a critical section.
*
* @param critical_section A pointer to the `ZyanCriticalSection` struct.
*/
ZYCORE_EXPORT ZyanStatus ZyanCriticalSectionInitialize(ZyanCriticalSection* critical_section);
/**
* Enters a critical section.
*
* @param critical_section A pointer to the `ZyanCriticalSection` struct.
*/
ZYCORE_EXPORT ZyanStatus ZyanCriticalSectionEnter(ZyanCriticalSection* critical_section);
/**
* Tries to enter a critical section.
*
* @param critical_section A pointer to the `ZyanCriticalSection` struct.
*
* @return Returns `ZYAN_TRUE` if the critical section was successfully entered or `ZYAN_FALSE`,
* if not.
*/
ZYCORE_EXPORT ZyanBool ZyanCriticalSectionTryEnter(ZyanCriticalSection* critical_section);
/**
* Leaves a critical section.
*
* @param critical_section A pointer to the `ZyanCriticalSection` struct.
*/
ZYCORE_EXPORT ZyanStatus ZyanCriticalSectionLeave(ZyanCriticalSection* critical_section);
/**
* Deletes a critical section.
*
* @param critical_section A pointer to the `ZyanCriticalSection` struct.
*/
ZYCORE_EXPORT ZyanStatus ZyanCriticalSectionDelete(ZyanCriticalSection* critical_section);
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif /* ZYAN_NO_LIBC */
#endif /* ZYCORE_API_SYNCHRONIZATION_H */

@ -0,0 +1,162 @@
/***************************************************************************************************
Zyan Core Library (Zycore-C)
Original Author : Florian Bernd
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
***************************************************************************************************/
/**
* @file Provides cross-platform terminal helper functions.
* @brief
*/
#ifndef ZYCORE_API_TERMINAL_H
#define ZYCORE_API_TERMINAL_H
#include <Zycore/LibC.h>
#include <Zycore/Status.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef ZYAN_NO_LIBC
/* ============================================================================================== */
/* VT100 CSI SGR sequences */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* General */
/* ---------------------------------------------------------------------------------------------- */
#define ZYAN_VT100SGR_RESET "\033[0m"
/* ---------------------------------------------------------------------------------------------- */
/* Foreground colors */
/* ---------------------------------------------------------------------------------------------- */
#define ZYAN_VT100SGR_FG_DEFAULT "\033[39m"
#define ZYAN_VT100SGR_FG_BLACK "\033[30m"
#define ZYAN_VT100SGR_FG_RED "\033[31m"
#define ZYAN_VT100SGR_FG_GREEN "\033[32m"
#define ZYAN_VT100SGR_FG_YELLOW "\033[33m"
#define ZYAN_VT100SGR_FG_BLUE "\033[34m"
#define ZYAN_VT100SGR_FG_MAGENTA "\033[35m"
#define ZYAN_VT100SGR_FG_CYAN "\033[36m"
#define ZYAN_VT100SGR_FG_WHITE "\033[37m"
#define ZYAN_VT100SGR_FG_BRIGHT_BLACK "\033[90m"
#define ZYAN_VT100SGR_FG_BRIGHT_RED "\033[91m"
#define ZYAN_VT100SGR_FG_BRIGHT_GREEN "\033[92m"
#define ZYAN_VT100SGR_FG_BRIGHT_YELLOW "\033[93m"
#define ZYAN_VT100SGR_FG_BRIGHT_BLUE "\033[94m"
#define ZYAN_VT100SGR_FG_BRIGHT_MAGENTA "\033[95m"
#define ZYAN_VT100SGR_FG_BRIGHT_CYAN "\033[96m"
#define ZYAN_VT100SGR_FG_BRIGHT_WHITE "\033[97m"
/* ---------------------------------------------------------------------------------------------- */
/* Background color */
/* ---------------------------------------------------------------------------------------------- */
#define ZYAN_VT100SGR_BG_DEFAULT "\033[49m"
#define ZYAN_VT100SGR_BG_BLACK "\033[40m"
#define ZYAN_VT100SGR_BG_RED "\033[41m"
#define ZYAN_VT100SGR_BG_GREEN "\033[42m"
#define ZYAN_VT100SGR_BG_YELLOW "\033[43m"
#define ZYAN_VT100SGR_BG_BLUE "\033[44m"
#define ZYAN_VT100SGR_BG_MAGENTA "\033[45m"
#define ZYAN_VT100SGR_BG_CYAN "\033[46m"
#define ZYAN_VT100SGR_BG_WHITE "\033[47m"
#define ZYAN_VT100SGR_BG_BRIGHT_BLACK "\033[100m"
#define ZYAN_VT100SGR_BG_BRIGHT_RED "\033[101m"
#define ZYAN_VT100SGR_BG_BRIGHT_GREEN "\033[102m"
#define ZYAN_VT100SGR_BG_BRIGHT_YELLOW "\033[103m"
#define ZYAN_VT100SGR_BG_BRIGHT_BLUE "\033[104m"
#define ZYAN_VT100SGR_BG_BRIGHT_MAGENTA "\033[105m"
#define ZYAN_VT100SGR_BG_BRIGHT_CYAN "\033[106m"
#define ZYAN_VT100SGR_BG_BRIGHT_WHITE "\033[107m"
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
/**
* Declares the `ZyanStandardStream` enum.
*/
typedef enum ZyanStandardStream_
{
/**
* The default input stream.
*/
ZYAN_STDSTREAM_IN,
/**
* The default output stream.
*/
ZYAN_STDSTREAM_OUT,
/**
* The default error stream.
*/
ZYAN_STDSTREAM_ERR
} ZyanStandardStream;
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
/**
* Enables VT100 ansi escape codes for the given stream.
*
* @param stream Either `ZYAN_STDSTREAM_OUT` or `ZYAN_STDSTREAM_ERR`.
*
* @return A zyan status code.
*
* This functions returns `ZYAN_STATUS_SUCCESS` on all non-Windows systems without performing any
* operations, assuming that VT100 is supported by default.
*
* On Windows systems, VT100 functionality is only supported on Windows 10 build 1607 (anniversary
* update) and later.
*/
ZYCORE_EXPORT ZyanStatus ZyanTerminalEnableVT100(ZyanStandardStream stream);
/**
* Checks, if the given standard stream reads from or writes to a terminal.
*
* @param stream The standard stream to check.
*
* @return `ZYAN_STATUS_TRUE`, if the stream is bound to a terminal, `ZYAN_STATUS_FALSE` if not,
* or another zyan status code if an error occured.
*/
ZYCORE_EXPORT ZyanStatus ZyanTerminalIsTTY(ZyanStandardStream stream);
/* ============================================================================================== */
#endif // ZYAN_NO_LIBC
#ifdef __cplusplus
}
#endif
#endif /* ZYCORE_API_TERMINAL_H */

@ -0,0 +1,243 @@
/***************************************************************************************************
Zyan Core Library (Zycore-C)
Original Author : Florian Bernd
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
***************************************************************************************************/
/**
* @file
* @brief
*/
#ifndef ZYCORE_API_THREAD_H
#define ZYCORE_API_THREAD_H
#include <Zycore/Defines.h>
#include <Zycore/Status.h>
#ifndef ZYAN_NO_LIBC
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
#if defined(ZYAN_POSIX)
#include <pthread.h>
/* ---------------------------------------------------------------------------------------------- */
/* General */
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZyanThread` data-type.
*/
typedef pthread_t ZyanThread;
/**
* Defines the `ZyanThreadId` data-type.
*/
typedef ZyanU64 ZyanThreadId;
/* ---------------------------------------------------------------------------------------------- */
/* Thread Local Storage (TLS) */
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZyanThreadTlsIndex` data-type.
*/
typedef pthread_key_t ZyanThreadTlsIndex;
/**
* Defines the `ZyanThreadTlsCallback` function prototype.
*/
typedef void(*ZyanThreadTlsCallback)(void* data);
/**
* Declares a Thread Local Storage (TLS) callback function.
*
* @param name The callback function name.
* @param param_type The callback data parameter type.
* @param param_name The callback data parameter name.
*/
#define ZYAN_THREAD_DECLARE_TLS_CALLBACK(name, param_type, param_name) \
void name(param_type* param_name)
/* ---------------------------------------------------------------------------------------------- */
#elif defined(ZYAN_WINDOWS)
#include <windows.h>
/* ---------------------------------------------------------------------------------------------- */
/* General */
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZyanThread` data-type.
*/
typedef HANDLE ZyanThread;
/**
* Defines the `ZyanThreadId` data-type.
*/
typedef DWORD ZyanThreadId;
/* ---------------------------------------------------------------------------------------------- */
/* Thread Local Storage (TLS) */
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZyanThreadTlsIndex` data-type.
*/
typedef DWORD ZyanThreadTlsIndex;
/**
* Defines the `ZyanThreadTlsCallback` function prototype.
*/
typedef PFLS_CALLBACK_FUNCTION ZyanThreadTlsCallback;
/**
* Declares a Thread Local Storage (TLS) callback function.
*
* @param name The callback function name.
* @param param_type The callback data parameter type.
* @param param_name The callback data parameter name.
*/
#define ZYAN_THREAD_DECLARE_TLS_CALLBACK(name, param_type, param_name) \
VOID NTAPI name(param_type* param_name)
/* ---------------------------------------------------------------------------------------------- */
#else
# error "Unsupported platform detected"
#endif
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* General */
/* ---------------------------------------------------------------------------------------------- */
/**
* Returns the handle of the current thread.
*
* @param thread Receives the handle of the current thread.
*
* @return A zyan status code.
*/
ZYCORE_EXPORT ZyanStatus ZyanThreadGetCurrentThread(ZyanThread* thread);
/**
* Returns the unique id of the current thread.
*
* @param thread_id Receives the unique id of the current thread.
*
* @return A zyan status code.
*/
ZYCORE_EXPORT ZyanStatus ZyanThreadGetCurrentThreadId(ZyanThreadId* thread_id);
/* ---------------------------------------------------------------------------------------------- */
/* Thread Local Storage (TLS) */
/* ---------------------------------------------------------------------------------------------- */
/**
* Allocates a new Thread Local Storage (TLS) slot.
*
* @param index Receives the TLS slot index.
* @param destructor A pointer to a destructor callback which is invoked to finalize the data
* in the TLS slot or `ZYAN_NULL`, if not needed.
*
* The maximum available number of TLS slots is implementation specific and different on each
* platform:
* - Windows
* - A total amount of 128 slots per process are guaranteed
* - POSIX
* - A total amount of 128 slots per process are guaranteed
* - Some systems guarantee larger amounts like e.g. 1024 slots per process
*
* Note that the invocation rules for the destructor callback are implementation specific and
* different on each platform:
* - Windows
* - The callback is invoked when a thread exits
* - The callback is invoked when the process exits
* - The callback is invoked when the TLS slot is released
* - POSIX
* - The callback is invoked when a thread exits and the stored value is not null
* - The callback is NOT invoked when the process exits
* - The callback is NOT invoked when the TLS slot is released
*
* @return A zyan status code.
*/
ZYCORE_EXPORT ZyanStatus ZyanThreadTlsAlloc(ZyanThreadTlsIndex* index,
ZyanThreadTlsCallback destructor);
/**
* Releases a Thread Local Storage (TLS) slot.
*
* @param index The TLS slot index.
*
* @return A zyan status code.
*/
ZYCORE_EXPORT ZyanStatus ZyanThreadTlsFree(ZyanThreadTlsIndex index);
/**
* Returns the value inside the given Thread Local Storage (TLS) slot for the
* calling thread.
*
* @param index The TLS slot index.
* @param data Receives the value inside the given Thread Local Storage
* (TLS) slot for the calling thread.
*
* @return A zyan status code.
*/
ZYCORE_EXPORT ZyanStatus ZyanThreadTlsGetValue(ZyanThreadTlsIndex index, void** data);
/**
* Set the value of the given Thread Local Storage (TLS) slot for the calling thread.
*
* @param index The TLS slot index.
* @param data The value to store inside the given Thread Local Storage (TLS) slot for the
* calling thread
*
* @return A zyan status code.
*/
ZYCORE_EXPORT ZyanStatus ZyanThreadTlsSetValue(ZyanThreadTlsIndex index, void* data);
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif /* ZYAN_NO_LIBC */
#endif /* ZYCORE_API_THREAD_H */

@ -0,0 +1,142 @@
/***************************************************************************************************
Zyan Core Library (Zycore-C)
Original Author : Florian Bernd
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
***************************************************************************************************/
/**
* @file
* @brief
*/
#ifndef ZYCORE_ALLOCATOR_H
#define ZYCORE_ALLOCATOR_H
#include <Zycore/Status.h>
#include <Zycore/Types.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
struct ZyanAllocator_;
/**
* Defines the `ZyanAllocatorAllocate` function prototype.
*
* @param allocator A pointer to the `ZyanAllocator` instance.
* @param p Receives a pointer to the first memory block sufficient to hold an
* array of `n` elements with a size of `element_size`.
* @param element_size The size of a single element.
* @param n The number of elements to allocate storage for.
*
* @return A zyan status code.
*
* This prototype is used for the `allocate()` and `reallocate()` functions.
*
* The result of the `reallocate()` function is undefined, if `p` does not point to a memory block
* previously obtained by `(re-)allocate()`.
*/
typedef ZyanStatus (*ZyanAllocatorAllocate)(struct ZyanAllocator_* allocator, void** p,
ZyanUSize element_size, ZyanUSize n);
/**
* Defines the `ZyanAllocatorDeallocate` function prototype.
*
* @param allocator A pointer to the `ZyanAllocator` instance.
* @param p The pointer obtained from `(re-)allocate()`.
* @param element_size The size of a single element.
* @param n The number of elements earlier passed to `(re-)allocate()`.
*
* @return A zyan status code.
*/
typedef ZyanStatus (*ZyanAllocatorDeallocate)(struct ZyanAllocator_* allocator, void* p,
ZyanUSize element_size, ZyanUSize n);
/**
* Defines the `ZyanAllocator` struct.
*
* This is the base class for all custom allocator implementations.
*
* All fields in this struct should be considered as "private". Any changes may lead to unexpected
* behavior.
*/
typedef struct ZyanAllocator_
{
/**
* The allocate function.
*/
ZyanAllocatorAllocate allocate;
/**
* The reallocate function.
*/
ZyanAllocatorAllocate reallocate;
/**
* The deallocate function.
*/
ZyanAllocatorDeallocate deallocate;
} ZyanAllocator;
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
/**
* Initializes the given `ZyanAllocator` instance.
*
* @param allocator A pointer to the `ZyanAllocator` instance.
* @param allocate The allocate function.
* @param reallocate The reallocate function.
* @param deallocate The deallocate function.
*
* @return A zyan status code.
*/
ZYCORE_EXPORT ZyanStatus ZyanAllocatorInit(ZyanAllocator* allocator, ZyanAllocatorAllocate allocate,
ZyanAllocatorAllocate reallocate, ZyanAllocatorDeallocate deallocate);
#ifndef ZYAN_NO_LIBC
/**
* Returns the default `ZyanAllocator` instance.
*
* @return A pointer to the default `ZyanAllocator` instance.
*
* The default allocator uses the default memory manager to allocate memory on the heap.
*
* You should in no case modify the returned allocator instance to avoid unexpected behavior.
*/
ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanAllocator* ZyanAllocatorDefault(void);
#endif // ZYAN_NO_LIBC
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif /* ZYCORE_ALLOCATOR_H */

@ -0,0 +1,173 @@
/***************************************************************************************************
Zyan Core Library (Zycore-C)
Original Author : Joel Hoener
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
***************************************************************************************************/
/**
* @file
* Implements command-line argument parsing.
*/
#ifndef ZYCORE_ARGPARSE_H
#define ZYCORE_ARGPARSE_H
#include <Zycore/Types.h>
#include <Zycore/Status.h>
#include <Zycore/Vector.h>
#include <Zycore/String.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Structs and other types */
/* ============================================================================================== */