types.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*!
  2. \ingroup Memory
  3. \brief This is not actually a function, but rather a preprocessor macro,
  4. which allows the user to substitute in their own malloc, realloc, and free
  5. functions in place of the standard C memory functions.
  6. To use external memory functions, define XMALLOC_USER. This will cause the
  7. memory functions to be replaced by external functions of the form:
  8. extern void *XMALLOC(size_t n, void* heap, int type);
  9. extern void *XREALLOC(void *p, size_t n, void* heap, int type);
  10. extern void XFREE(void *p, void* heap, int type);
  11. To use the basic C memory functions in place of wolfSSL_Malloc,
  12. wolfSSL_Realloc, wolfSSL_Free, define NO_WOLFSSL_MEMORY. This
  13. will replace the memory functions with:
  14. #define XMALLOC(s, h, t) ((void)h, (void)t, malloc((s)))
  15. #define XFREE(p, h, t) {void* xp = (p); if((xp)) free((xp));}
  16. #define XREALLOC(p, n, h, t) realloc((p), (n))
  17. If none of these options are selected, the system will default to use
  18. the wolfSSL memory functions. A user can set custom memory functions
  19. through callback hooks, (see wolfSSL_Malloc,
  20. wolfSSL_Realloc, wolfSSL_Free). This option will replace the
  21. memory functions with:
  22. #define XMALLOC(s, h, t) ((void)h, (void)t, wolfSSL_Malloc((s)))
  23. #define XFREE(p, h, t) {void* xp = (p); if((xp)) wolfSSL_Free((xp));}
  24. #define XREALLOC(p, n, h, t) wolfSSL_Realloc((p), (n))
  25. \return pointer Return a pointer to allocated memory on success
  26. \return NULL on failure
  27. \param s size of memory to allocate
  28. \param h (used by custom XMALLOC function) pointer to the heap to use
  29. \param t memory allocation types for user hints. See enum in types.h
  30. _Example_
  31. \code
  32. int* 10 ints = XMALLOC(10 * sizeof(int), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  33. if ( ints == NULL) {
  34. // error allocating space
  35. return MEMORY_E;
  36. }
  37. \endcode
  38. \sa wolfSSL_Malloc
  39. \sa wolfSSL_Realloc
  40. \sa wolfSSL_Free
  41. \sa wolfSSL_SetAllocators
  42. */
  43. WOLFSSL_API void* XMALLOC(size_t n, void* heap, int type);
  44. /*!
  45. \ingroup Memory
  46. \brief This is not actually a function, but rather a preprocessor macro,
  47. which allows the user to substitute in their own malloc, realloc, and
  48. free functions in place of the standard C memory functions.
  49. To use external memory functions, define XMALLOC_USER. This will cause the
  50. memory functions to be replaced by external functions of the form:
  51. extern void *XMALLOC(size_t n, void* heap, int type);
  52. extern void *XREALLOC(void *p, size_t n, void* heap, int type);
  53. extern void XFREE(void *p, void* heap, int type);
  54. To use the basic C memory functions in place of wolfSSL_Malloc,
  55. wolfSSL_Realloc, wolfSSL_Free, define NO_WOLFSSL_MEMORY. This will
  56. replace the memory functions with:
  57. #define XMALLOC(s, h, t) ((void)h, (void)t, malloc((s)))
  58. #define XFREE(p, h, t) {void* xp = (p); if((xp)) free((xp));}
  59. #define XREALLOC(p, n, h, t) realloc((p), (n))
  60. If none of these options are selected, the system will default to
  61. use the wolfSSL memory functions. A user can set custom memory
  62. functions through callback hooks, (see wolfSSL_Malloc,
  63. wolfSSL_Realloc, wolfSSL_Free). This option will replace
  64. the memory functions with:
  65. #define XMALLOC(s, h, t) ((void)h, (void)t, wolfSSL_Malloc((s)))
  66. #define XFREE(p, h, t) {void* xp = (p); if((xp)) wolfSSL_Free((xp));}
  67. #define XREALLOC(p, n, h, t) wolfSSL_Realloc((p), (n))
  68. \return Return a pointer to allocated memory on success
  69. \return NULL on failure
  70. \param p pointer to the address to reallocate
  71. \param n size of memory to allocate
  72. \param h (used by custom XREALLOC function) pointer to the heap to use
  73. \param t memory allocation types for user hints. See enum in types.h
  74. _Example_
  75. \code
  76. none
  77. \endcode
  78. \sa wolfSSL_Malloc
  79. \sa wolfSSL_Realloc
  80. \sa wolfSSL_Free
  81. \sa wolfSSL_SetAllocators
  82. */
  83. WOLFSSL_API void* XREALLOC(void *p, size_t n, void* heap, int type);
  84. /*!
  85. \ingroup Memory
  86. \brief This is not actually a function, but rather a preprocessor macro,
  87. which allows the user to substitute in their own malloc, realloc, and
  88. free functions in place of the standard C memory functions.
  89. To use external memory functions, define XMALLOC_USER. This will cause
  90. the memory functions to be replaced by external functions of the form:
  91. extern void *XMALLOC(size_t n, void* heap, int type);
  92. extern void *XREALLOC(void *p, size_t n, void* heap, int type);
  93. extern void XFREE(void *p, void* heap, int type);
  94. To use the basic C memory functions in place of wolfSSL_Malloc,
  95. wolfSSL_Realloc, wolfSSL_Free, define NO_WOLFSSL_MEMORY. This
  96. will replace the memory functions with:
  97. #define XMALLOC(s, h, t) ((void)h, (void)t, malloc((s)))
  98. #define XFREE(p, h, t) {void* xp = (p); if((xp)) free((xp));}
  99. #define XREALLOC(p, n, h, t) realloc((p), (n))
  100. If none of these options are selected, the system will default to use
  101. the wolfSSL memory functions. A user can set custom memory functions
  102. through callback hooks, (see wolfSSL_Malloc, wolfSSL_Realloc,
  103. wolfSSL_Free). This option will replace the memory functions with:
  104. #define XMALLOC(s, h, t) ((void)h, (void)t, wolfSSL_Malloc((s)))
  105. #define XFREE(p, h, t) {void* xp = (p); if((xp)) wolfSSL_Free((xp));}
  106. #define XREALLOC(p, n, h, t) wolfSSL_Realloc((p), (n))
  107. \return none No returns.
  108. \param p pointer to the address to free
  109. \param h (used by custom XFREE function) pointer to the heap to use
  110. \param t memory allocation types for user hints. See enum in types.h
  111. _Example_
  112. \code
  113. int* 10 ints = XMALLOC(10 * sizeof(int), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  114. if ( ints == NULL) {
  115. // error allocating space
  116. return MEMORY_E;
  117. }
  118. \endcode
  119. \sa wolfSSL_Malloc
  120. \sa wolfSSL_Realloc
  121. \sa wolfSSL_Free
  122. \sa wolfSSL_SetAllocators
  123. */
  124. WOLFSSL_API void XFREE(void *p, void* heap, int type);
  125. /*!
  126. \ingroup Math
  127. \brief This function checks the compile time class settings. It is
  128. important when a user is using a wolfCrypt library independently, as
  129. the settings must match between libraries for math to work correctly.
  130. This check is defined as CheckCtcSettings(), which simply compares
  131. CheckRunTimeSettings and CTC_SETTINGS, returning 0 if there is a
  132. mismatch, or 1 if they match.
  133. \return settings Returns the runtime CTC_SETTINGS (Compile Time Settings)
  134. \param none No Parameters.
  135. _Example_
  136. \code
  137. if (CheckCtcSettings() != 1) {
  138. return err_sys("Build vs. runtime math mismatch\n");
  139. }
  140. // This is converted by the preprocessor to:
  141. // if ( (CheckCtcSettings() == CTC_SETTINGS) != 1) {
  142. // and will compare whether the compile time class settings
  143. // match the current settings
  144. \endcode
  145. \sa CheckRunTimeFastMath
  146. */
  147. WOLFSSL_API word32 CheckRunTimeSettings(void);