General Purpose library for Freestanding C++ and POSIX systems
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

199 righe
4.5 KiB

  1. #pragma once
  2. #include <new>
  3. #include <type_traits>
  4. #include <cstddef>
  5. #include <cstdint>
  6. #include <cstdlib>
  7. #ifdef GP_TESTS
  8. class static_mapper;
  9. #else
  10. namespace gp {
  11. class c_allocator;
  12. }
  13. #endif
  14. extern void log_failure(const char* failure);
  15. extern void log_segment(const char* name, const char* text, int16_t prio = 0);
  16. /**
  17. * @brief This namespace contains the configuration.
  18. *
  19. * This namespace is expected to be fully defined in an include accessible from the root
  20. * of your header list:
  21. * \code{.cpp}
  22. * #include "gp_config.hpp"
  23. * \endcode
  24. *
  25. * The code line above should always be the one including that config and that namespace.
  26. */
  27. namespace gp_config{
  28. namespace rendering {
  29. /**
  30. * @brief The default type used for rendering processes
  31. */
  32. using default_type = float;
  33. /**
  34. * @brief The small enough value used in signed distance function resolution
  35. */
  36. constexpr default_type epsilon = 0.01;
  37. /**
  38. * @brief The default color type
  39. */
  40. #define GP_CONFIG__RENDERING__COLOR_T vec4
  41. }
  42. /**
  43. * @brief This namespace contains artificial limitations put on the runtime
  44. */
  45. namespace limits {
  46. /**
  47. * @brief the total number of processes the system is allowed to have
  48. */
  49. constexpr size_t max_processes = 4096;
  50. /**
  51. * @brief the maximum size a channel can address
  52. */
  53. constexpr size_t channel_max_size = 1 << 20;
  54. /**
  55. * @brief the default size a channel will take
  56. */
  57. constexpr size_t channel_default_size = 1 << 16;
  58. /**
  59. * @brief the number of open files each process is allowed to have
  60. */
  61. constexpr size_t max_fd_per_process = 128;
  62. /**
  63. * @brief the stack size for the new stacks generated by the concurrency system
  64. */
  65. constexpr size_t process_stack = 1024;
  66. /**
  67. * @brief expected stack alignment
  68. */
  69. constexpr size_t process_stack_align_to = 16;
  70. /**
  71. * @brief presents the direction of stack growth
  72. */
  73. constexpr size_t stack_grow_upwards = false;
  74. #if __cpp_lib_hardware_interference_size >= 201603
  75. constexpr size_t hardware_constructive_interference_size = std::hardware_constructive_interference_size;
  76. constexpr size_t hardware_destructive_interference_size = std::hardware_destructive_interference_size;
  77. #else
  78. constexpr size_t hardware_constructive_interference_size = 128;
  79. constexpr size_t hardware_destructive_interference_size = 128;
  80. #endif
  81. constexpr size_t loggers_segment_size = 128;
  82. }
  83. namespace memory_module{
  84. constexpr bool is_ok = true;
  85. constexpr bool prefer_constant_memory = true;
  86. }
  87. typedef uint32_t file_descriptor_t;
  88. /**
  89. * @brief set to true to enable exceptions
  90. */
  91. constexpr bool has_exceptions = true;
  92. /**
  93. * @brief set to true to activate bounds checking
  94. */
  95. constexpr bool has_buffer_bounds = true;
  96. /**
  97. * @brief A value used to determine the strength used by random number generators
  98. *
  99. * Value of 8 is considered not cryptographically secure
  100. * Value of 12 offers a good compromise of performance and robustness
  101. * Value of 20 offers maximum robustness
  102. */
  103. constexpr size_t arc4random_strength = 20;
  104. /**
  105. * @brief an exception that represents an assertion failure
  106. */
  107. struct assert_failure : std::exception {
  108. assert_failure(const char* reason)
  109. : what_str{reason}
  110. {}
  111. const char* what_str;
  112. const char* what() {return what_str;}
  113. };
  114. /**
  115. * @brief UNUSED
  116. */
  117. constexpr size_t assert_buffer_size = 0;
  118. constexpr auto fail = [] [[noreturn]] (auto reason) noexcept(not has_exceptions) {
  119. if constexpr (has_exceptions) {
  120. throw assert_failure(reason);
  121. } else {
  122. volatile uint8_t n = 0;
  123. {
  124. failure_point:
  125. n = n + 1;
  126. goto failure_point;
  127. }
  128. }
  129. };
  130. /**
  131. * @brief an assertion function
  132. */
  133. constexpr auto assertion = [](bool pred, const char* reason)
  134. noexcept(std::is_nothrow_invocable_v<decltype(fail), decltype(reason)>) -> void {
  135. if(!pred) {
  136. log_failure(reason);
  137. fail(reason);
  138. }
  139. };
  140. enum class cbor_tag {
  141. datetime = 0,
  142. unix_time = 1,
  143. ubignum = 2,
  144. nbignum = 3,
  145. decimal = 4,
  146. bigfloat = 5,
  147. cose_encrypt0 = 16,
  148. cose_mac0 = 17,
  149. cose_sign1 = 18,
  150. expected_base64url = 21,
  151. expected_base64 = 22,
  152. expected_base16 = 23,
  153. encoded_cbor = 24,
  154. url = 32,
  155. base64url = 33,
  156. base64 = 34,
  157. regexp = 35,
  158. mime = 36,
  159. cose_encrypt = 96,
  160. cose_mac = 97,
  161. cose_sign = 98,
  162. signature = 55799
  163. };
  164. }
  165. /**
  166. * @brief a list of error codes
  167. */
  168. enum class gp_errorcodes : int {
  169. /**
  170. * @brief this error code is activated upon reaching a skipstone limit that seems like infinity.
  171. */
  172. infinite_skipstone = 3000
  173. };