1
0

defs.h 7.6 KB

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