General Purpose library for Freestanding C++ and POSIX systems
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

188 linhas
4.1 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. }
  86. typedef uint32_t file_descriptor_t;
  87. /**
  88. * @brief set to true to enable exceptions
  89. */
  90. constexpr bool has_exceptions = true;
  91. /**
  92. * @brief set to true to activate bounds checking
  93. */
  94. constexpr bool has_buffer_bounds = true;
  95. //
  96. //
  97. //
  98. /**
  99. * @brief A value used to determine the strength used by random number generators
  100. *
  101. * Value of 8 is considered not cryptographically secure
  102. * Value of 12 offers a good compromise of performance and robustness
  103. * Value of 20 offers maximum robustness
  104. */
  105. constexpr size_t arc4random_strength = 20;
  106. /**
  107. * @brief an exception that represents an assertion failure
  108. */
  109. struct assert_failure{
  110. assert_failure(const char* reason)
  111. : what_str{reason}
  112. {}
  113. const char* what_str;
  114. const char* what() {return what_str;}
  115. };
  116. /**
  117. * @brief UNUSED
  118. */
  119. constexpr size_t assert_buffer_size = 0;
  120. /**
  121. * @brief an assertion function
  122. */
  123. constexpr auto assertion = [](bool pred, const char* reason) -> void{
  124. if(!pred) {
  125. log_failure(reason);
  126. if constexpr (has_exceptions)
  127. throw assert_failure(reason);
  128. }
  129. };
  130. enum class cbor_tag {
  131. datetime = 0,
  132. unix_time = 1,
  133. ubignum = 2,
  134. nbignum = 3,
  135. decimal = 4,
  136. bigfloat = 5,
  137. cose_encrypt0 = 16,
  138. cose_mac0 = 17,
  139. cose_sign1 = 18,
  140. expected_base64url = 21,
  141. expected_base64 = 22,
  142. expected_base16 = 23,
  143. encoded_cbor = 24,
  144. url = 32,
  145. base64url = 33,
  146. base64 = 34,
  147. regexp = 35,
  148. mime = 36,
  149. cose_encrypt = 96,
  150. cose_mac = 97,
  151. cose_sign = 98,
  152. signature = 55799
  153. };
  154. }
  155. /**
  156. * @brief a list of error codes
  157. */
  158. enum class gp_errorcodes : int {
  159. /**
  160. * @brief this error code is activated upon reaching a skipstone limit that seems like infinity.
  161. */
  162. infinite_skipstone = 3000
  163. };