defs.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. * defs.h: initial definitions for PuTTY.
  3. *
  4. * The rule about this header file is that it can't depend on any
  5. * other header file in this code base. This is where we define
  6. * things, as much as we can, that other headers will want to refer
  7. * to, such as opaque structure types and their associated typedefs,
  8. * or macros that are used by other headers.
  9. */
  10. #ifndef PUTTY_DEFS_H
  11. #define PUTTY_DEFS_H
  12. #include <stddef.h>
  13. #include <stdint.h>
  14. #include <stdbool.h>
  15. #if defined _MSC_VER && _MSC_VER < 1800
  16. /* Work around lack of inttypes.h and strtoumax in older MSVC */
  17. #define PRIx32 "x"
  18. #define PRIu64 "I64u"
  19. #define PRIdMAX "I64d"
  20. #define PRIXMAX "I64X"
  21. #define SCNu64 "I64u"
  22. #define SIZEx "Ix"
  23. #define SIZEu "Iu"
  24. uintmax_t strtoumax(const char *nptr, char **endptr, int base);
  25. #else
  26. #include <inttypes.h>
  27. /* Because we still support older MSVC libraries which don't recognise the
  28. * standard C "z" modifier for size_t-sized integers, we must use an
  29. * inttypes.h-style macro for those */
  30. #define SIZEx "zx"
  31. #define SIZEu "zu"
  32. #endif
  33. #if defined __GNUC__ || defined __clang__
  34. /*
  35. * On MinGW, the correct compiler format checking for vsnprintf() etc
  36. * can depend on compile-time flags; these control whether you get
  37. * ISO C or Microsoft's non-standard format strings.
  38. * We sometimes use __attribute__ ((format)) for our own printf-like
  39. * functions, which are ultimately interpreted by the toolchain-chosen
  40. * printf, so we need to take that into account to get correct warnings.
  41. */
  42. #ifdef __MINGW_PRINTF_FORMAT
  43. #define PRINTF_LIKE(fmt_index, ellipsis_index) \
  44. __attribute__ ((format (__MINGW_PRINTF_FORMAT, fmt_index, ellipsis_index)))
  45. #else
  46. #define PRINTF_LIKE(fmt_index, ellipsis_index) \
  47. __attribute__ ((format (printf, fmt_index, ellipsis_index)))
  48. #endif
  49. #else /* __GNUC__ */
  50. #define PRINTF_LIKE(fmt_index, ellipsis_index)
  51. #endif /* __GNUC__ */
  52. typedef struct conf_tag Conf;
  53. typedef struct terminal_tag Terminal;
  54. typedef struct term_utf8_decode term_utf8_decode;
  55. typedef struct Filename Filename;
  56. typedef struct FontSpec FontSpec;
  57. typedef struct bufchain_tag bufchain;
  58. typedef struct strbuf strbuf;
  59. typedef struct RSAKey RSAKey;
  60. typedef struct BinarySink BinarySink;
  61. typedef struct BinarySource BinarySource;
  62. typedef struct stdio_sink stdio_sink;
  63. typedef struct bufchain_sink bufchain_sink;
  64. typedef struct handle_sink handle_sink;
  65. typedef struct IdempotentCallback IdempotentCallback;
  66. typedef struct SockAddr SockAddr;
  67. typedef struct Socket Socket;
  68. typedef struct Plug Plug;
  69. typedef struct SocketPeerInfo SocketPeerInfo;
  70. typedef struct Backend Backend;
  71. typedef struct BackendVtable BackendVtable;
  72. typedef struct Ldisc_tag Ldisc;
  73. typedef struct LogContext LogContext;
  74. typedef struct LogPolicy LogPolicy;
  75. typedef struct LogPolicyVtable LogPolicyVtable;
  76. typedef struct Seat Seat;
  77. typedef struct SeatVtable SeatVtable;
  78. typedef struct TermWin TermWin;
  79. typedef struct TermWinVtable TermWinVtable;
  80. typedef struct Ssh Ssh;
  81. typedef struct mp_int mp_int;
  82. typedef struct MontyContext MontyContext;
  83. typedef struct WeierstrassCurve WeierstrassCurve;
  84. typedef struct WeierstrassPoint WeierstrassPoint;
  85. typedef struct MontgomeryCurve MontgomeryCurve;
  86. typedef struct MontgomeryPoint MontgomeryPoint;
  87. typedef struct EdwardsCurve EdwardsCurve;
  88. typedef struct EdwardsPoint EdwardsPoint;
  89. typedef struct SshServerConfig SshServerConfig;
  90. typedef struct SftpServer SftpServer;
  91. typedef struct SftpServerVtable SftpServerVtable;
  92. typedef struct Channel Channel;
  93. typedef struct SshChannel SshChannel;
  94. typedef struct mainchan mainchan;
  95. typedef struct ssh_sharing_state ssh_sharing_state;
  96. typedef struct ssh_sharing_connstate ssh_sharing_connstate;
  97. typedef struct share_channel share_channel;
  98. typedef struct PortFwdManager PortFwdManager;
  99. typedef struct PortFwdRecord PortFwdRecord;
  100. typedef struct ConnectionLayer ConnectionLayer;
  101. typedef struct prng prng;
  102. typedef struct ssh_hashalg ssh_hashalg;
  103. typedef struct ssh_hash ssh_hash;
  104. typedef struct ssh_kex ssh_kex;
  105. typedef struct ssh_kexes ssh_kexes;
  106. typedef struct ssh_keyalg ssh_keyalg;
  107. typedef struct ssh_key ssh_key;
  108. typedef struct ssh_compressor ssh_compressor;
  109. typedef struct ssh_decompressor ssh_decompressor;
  110. typedef struct ssh_compression_alg ssh_compression_alg;
  111. typedef struct ssh2_userkey ssh2_userkey;
  112. typedef struct ssh2_macalg ssh2_macalg;
  113. typedef struct ssh2_mac ssh2_mac;
  114. typedef struct ssh_cipheralg ssh_cipheralg;
  115. typedef struct ssh_cipher ssh_cipher;
  116. typedef struct ssh2_ciphers ssh2_ciphers;
  117. typedef struct dh_ctx dh_ctx;
  118. typedef struct ecdh_key ecdh_key;
  119. typedef struct dlgparam dlgparam;
  120. typedef struct settings_w settings_w;
  121. typedef struct settings_r settings_r;
  122. typedef struct settings_e settings_e;
  123. typedef struct SessionSpecial SessionSpecial;
  124. typedef struct StripCtrlChars StripCtrlChars;
  125. /*
  126. * A small structure wrapping up a (pointer, length) pair so that it
  127. * can be conveniently passed to or from a function.
  128. */
  129. typedef struct ptrlen {
  130. const void *ptr;
  131. size_t len;
  132. } ptrlen;
  133. typedef struct logblank_t logblank_t;
  134. typedef struct BinaryPacketProtocol BinaryPacketProtocol;
  135. typedef struct PacketProtocolLayer PacketProtocolLayer;
  136. /* Do a compile-time type-check of 'to_check' (without evaluating it),
  137. * as a side effect of returning the value 'to_return'. Note that
  138. * although this macro double-*expands* to_return, it always
  139. * *evaluates* exactly one copy of it, so it's side-effect safe. */
  140. #define TYPECHECK(to_check, to_return) \
  141. (sizeof(to_check) ? (to_return) : (to_return))
  142. /* Return a pointer to the object of structure type 'type' whose field
  143. * with name 'field' is pointed at by 'object'. */
  144. #define container_of(object, type, field) \
  145. TYPECHECK(object == &((type *)0)->field, \
  146. ((type *)(((char *)(object)) - offsetof(type, field))))
  147. #if defined __GNUC__ || defined __clang__
  148. #define NORETURN __attribute__((__noreturn__))
  149. #else
  150. #define NORETURN
  151. #endif
  152. /* ----------------------------------------------------------------------
  153. * Platform-specific definitions.
  154. *
  155. * Most of these live in the per-platform header files, of which
  156. * puttyps.h selects the appropriate one. But some of the sources
  157. * (particularly standalone test applications) would prefer not to
  158. * have to include a per-platform header at all, because that makes it
  159. * more portable to platforms not supported by the code base as a
  160. * whole (for example, compiling purely computational parts of the
  161. * code for specialist platforms for test and analysis purposes). So
  162. * any definition that has to affect even _those_ modules will have to
  163. * go here, with the key constraint being that this code has to come
  164. * to _some_ decision even if the compilation platform is not a
  165. * recognised one at all.
  166. */
  167. /* Purely computational code uses smemclr(), so we have to make the
  168. * decision here about whether that's provided by utils.c or by a
  169. * platform implementation. We define PLATFORM_HAS_SMEMCLR to suppress
  170. * utils.c's definition. */
  171. #ifdef _WINDOWS
  172. /* Windows provides the API function 'SecureZeroMemory', which we use
  173. * unless the user has told us not to by defining NO_SECUREZEROMEMORY. */
  174. #ifndef NO_SECUREZEROMEMORY
  175. #define PLATFORM_HAS_SMEMCLR
  176. #endif
  177. #endif
  178. #endif /* PUTTY_DEFS_H */