TCP protocol implementation (RFC 9293)
0

Configure Feed

Select the types of activity you want to include in your feed.

3d: regenerate the standalone C cross-build rules and headers

Pick up the wire.3d change that builds and installs the standalone c/ verified
parser per target (wire pinned at f13082a3). Every packages c/dune.inc is
regenerated: the archive now builds in all contexts through the context
toolchain (%{ocaml-config:c_compiler}, the ocaml-config partial linker,
-print-prog-name binutils) instead of host-only, and installs unconditionally
-- no empty placeholder. Each c/EverParseEndianness.h gains a freestanding
__BYTE_ORDER__/__builtin_bswap* branch so it compiles for an OS-less target (a
unikernel defines neither __linux__ nor __APPLE__).

Verified: dune build -x unikraft ocaml-clcw/c/libclcw.a produces an aarch64
archive exporting only ClcwCheckClcw (the safe wrapper), with ClcwValidateClcw
localized.

+255 -219
+236 -205
c/EverParseEndianness.h
··· 1 - /*++ 2 - 3 - Copyright (c) Microsoft Corporation 4 - 5 - Module Name: 6 - 7 - EverParseEndianness.h 8 - 9 - Abstract: 10 - 11 - This is an EverParse-related file to read integer values from raw 12 - bytes. 13 - 14 - Authors: 15 - 16 - nswamy, protz, taramana 5-Feb-2020 17 - 18 - --*/ 19 - /* This is a hand-written header that selectively includes relevant bits from 20 - * krmllib.h -- it has to be updated manually to track upstream changes. */ 21 - 22 - #ifndef __EverParseEndianness_H 23 - #define __EverParseEndianness_H 24 - 25 - #if defined(__cplusplus) 26 - extern "C" { 27 - #endif 28 - 29 - /***************************************************************************** 30 - ********* Implementation of LowStar.Endianness (selected bits) ************** 31 - *****************************************************************************/ 32 - 33 - #if defined(_MSC_VER) 34 - # include <windows.h> 35 - #endif 36 - 37 - #include <string.h> 38 - #include <stdint.h> 39 - 40 - typedef const char * EVERPARSE_STRING; 41 - typedef EVERPARSE_STRING PRIMS_STRING; 42 - typedef void* EVERPARSE_COPY_BUFFER_T; 43 - 44 - #ifndef KRML_MAYBE_UNUSED_VAR 45 - # define KRML_MAYBE_UNUSED_VAR(x) (void)(x) 46 - #endif 47 - 48 - #ifndef KRML_HOST_IGNORE 49 - # define KRML_HOST_IGNORE(x) (void)(x) 50 - #endif 51 - 52 - #ifndef KRML_HOST_PRINTF 53 - # include <stdio.h> 54 - # define KRML_HOST_PRINTF printf 55 - #endif 56 - 57 - #ifndef KRML_HOST_EXIT 58 - # include <stdlib.h> 59 - # define KRML_HOST_EXIT exit 60 - #endif 61 - 62 - #define KRML_CHECK_SIZE(size_elt, sz) \ 63 - do { \ 64 - if (((size_t)(sz)) > ((size_t)(SIZE_MAX / (size_elt)))) { \ 65 - KRML_HOST_PRINTF( \ 66 - "Maximum allocatable size exceeded, aborting before overflow at " \ 67 - "%s:%d\n", \ 68 - __FILE__, __LINE__); \ 69 - KRML_HOST_EXIT(253); \ 70 - } \ 71 - } while (0) 72 - 73 - /* ... for Windows (MSVC)... not targeting XBOX 360! */ 74 - #if defined(_MSC_VER) 75 - 76 - # include <stdlib.h> 77 - 78 - # define htobe16(x) _byteswap_ushort(x) 79 - # define htole16(x) (x) 80 - # define be16toh(x) _byteswap_ushort(x) 81 - # define le16toh(x) (x) 82 - 83 - # define htobe32(x) _byteswap_ulong(x) 84 - # define htole32(x) (x) 85 - # define be32toh(x) _byteswap_ulong(x) 86 - # define le32toh(x) (x) 87 - 88 - # define htobe64(x) _byteswap_uint64(x) 89 - # define htole64(x) (x) 90 - # define be64toh(x) _byteswap_uint64(x) 91 - # define le64toh(x) (x) 92 - 93 - #else 94 - 95 - typedef uint8_t BOOLEAN; 96 - #define FALSE 0 97 - #define TRUE 1 98 - 99 - /* ... for Linux */ 100 - #if defined(__linux__) || defined(__CYGWIN__) || defined (__USE_SYSTEM_ENDIAN_H__) 101 - # include <endian.h> 102 - 103 - 104 - /* ... for OSX */ 105 - #elif defined(__APPLE__) 106 - # include <libkern/OSByteOrder.h> 107 - # define htole64(x) OSSwapHostToLittleInt64(x) 108 - # define le64toh(x) OSSwapLittleToHostInt64(x) 109 - # define htobe64(x) OSSwapHostToBigInt64(x) 110 - # define be64toh(x) OSSwapBigToHostInt64(x) 111 - 112 - # define htole16(x) OSSwapHostToLittleInt16(x) 113 - # define le16toh(x) OSSwapLittleToHostInt16(x) 114 - # define htobe16(x) OSSwapHostToBigInt16(x) 115 - # define be16toh(x) OSSwapBigToHostInt16(x) 116 - 117 - # define htole32(x) OSSwapHostToLittleInt32(x) 118 - # define le32toh(x) OSSwapLittleToHostInt32(x) 119 - # define htobe32(x) OSSwapHostToBigInt32(x) 120 - # define be32toh(x) OSSwapBigToHostInt32(x) 121 - 122 - /* ... for other BSDs */ 123 - #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) 124 - # include <sys/endian.h> 125 - #elif defined(__OpenBSD__) 126 - # include <endian.h> 127 - 128 - /* ... for Windows (GCC-like, e.g. mingw or clang) */ 129 - #elif (defined(_WIN32) || defined(_WIN64)) && \ 130 - (defined(__GNUC__) || defined(__clang__)) 131 - 132 - # define htobe16(x) __builtin_bswap16(x) 133 - # define htole16(x) (x) 134 - # define be16toh(x) __builtin_bswap16(x) 135 - # define le16toh(x) (x) 136 - 137 - # define htobe32(x) __builtin_bswap32(x) 138 - # define htole32(x) (x) 139 - # define be32toh(x) __builtin_bswap32(x) 140 - # define le32toh(x) (x) 141 - 142 - # define htobe64(x) __builtin_bswap64(x) 143 - # define htole64(x) (x) 144 - # define be64toh(x) __builtin_bswap64(x) 145 - # define le64toh(x) (x) 146 - 147 - #else 148 - 149 - #error "Unsupported platform" 150 - 151 - #endif 152 - 153 - #endif 154 - 155 - inline static uint16_t Load16(uint8_t *b) { 156 - uint16_t x; 157 - memcpy(&x, b, 2); 158 - return x; 159 - } 160 - 161 - inline static uint32_t Load32(uint8_t *b) { 162 - uint32_t x; 163 - memcpy(&x, b, 4); 164 - return x; 165 - } 166 - 167 - inline static uint64_t Load64(uint8_t *b) { 168 - uint64_t x; 169 - memcpy(&x, b, 8); 170 - return x; 171 - } 172 - 173 - inline static void Store16(uint8_t *b, uint16_t i) { 174 - memcpy(b, &i, 2); 175 - } 176 - 177 - inline static void Store32(uint8_t *b, uint32_t i) { 178 - memcpy(b, &i, 4); 179 - } 180 - 181 - inline static void Store64(uint8_t *b, uint64_t i) { 182 - memcpy(b, &i, 8); 183 - } 184 - 185 - #define Load16Le(b) (le16toh(Load16(b))) 186 - #define Store16Le(b, i) (Store16(b, htole16(i))) 187 - #define Load16Be(b) (be16toh(Load16(b))) 188 - #define Store16Be(b, i) (Store16(b, htobe16(i))) 189 - 190 - #define Load32Le(b) (le32toh(Load32(b))) 191 - #define Store32Le(b, i) (Store32(b, htole32(i))) 192 - #define Load32Be(b) (be32toh(Load32(b))) 193 - #define Store32Be(b, i) (Store32(b, htobe32(i))) 194 - 195 - #define Load64Le(b) (le64toh(Load64(b))) 196 - #define Store64Le(b, i) (Store64(b, htole64(i))) 197 - #define Load64Be(b) (be64toh(Load64(b))) 198 - #define Store64Be(b, i) (Store64(b, htobe64(i))) 199 - 200 - 201 - #if defined(__cplusplus) 202 - } 203 - #endif 204 - 205 - #endif 1 + /*++ 2 + 3 + Copyright (c) Microsoft Corporation 4 + 5 + Module Name: 6 + 7 + EverParseEndianness.h 8 + 9 + Abstract: 10 + 11 + This is an EverParse-related file to read integer values from raw 12 + bytes. 13 + 14 + Authors: 15 + 16 + nswamy, protz, taramana 5-Feb-2020 17 + 18 + --*/ 19 + /* This is a hand-written header that selectively includes relevant bits from 20 + * krmllib.h -- it has to be updated manually to track upstream changes. */ 21 + 22 + #ifndef __EverParseEndianness_H 23 + #define __EverParseEndianness_H 24 + 25 + #if defined(__cplusplus) 26 + extern "C" { 27 + #endif 28 + 29 + /***************************************************************************** 30 + ********* Implementation of LowStar.Endianness (selected bits) ************** 31 + *****************************************************************************/ 32 + 33 + #if defined(_MSC_VER) 34 + # include <windows.h> 35 + #endif 36 + 37 + #include <string.h> 38 + #include <stdint.h> 39 + 40 + typedef const char * EVERPARSE_STRING; 41 + typedef EVERPARSE_STRING PRIMS_STRING; 42 + typedef void* EVERPARSE_COPY_BUFFER_T; 43 + 44 + #ifndef KRML_MAYBE_UNUSED_VAR 45 + # define KRML_MAYBE_UNUSED_VAR(x) (void)(x) 46 + #endif 47 + 48 + #ifndef KRML_HOST_IGNORE 49 + # define KRML_HOST_IGNORE(x) (void)(x) 50 + #endif 51 + 52 + #ifndef KRML_HOST_PRINTF 53 + # include <stdio.h> 54 + # define KRML_HOST_PRINTF printf 55 + #endif 56 + 57 + #ifndef KRML_HOST_EXIT 58 + # include <stdlib.h> 59 + # define KRML_HOST_EXIT exit 60 + #endif 61 + 62 + #define KRML_CHECK_SIZE(size_elt, sz) \ 63 + do { \ 64 + if (((size_t)(sz)) > ((size_t)(SIZE_MAX / (size_elt)))) { \ 65 + KRML_HOST_PRINTF( \ 66 + "Maximum allocatable size exceeded, aborting before overflow at " \ 67 + "%s:%d\n", \ 68 + __FILE__, __LINE__); \ 69 + KRML_HOST_EXIT(253); \ 70 + } \ 71 + } while (0) 72 + 73 + /* ... for Windows (MSVC)... not targeting XBOX 360! */ 74 + #if defined(_MSC_VER) 75 + 76 + # include <stdlib.h> 77 + 78 + # define htobe16(x) _byteswap_ushort(x) 79 + # define htole16(x) (x) 80 + # define be16toh(x) _byteswap_ushort(x) 81 + # define le16toh(x) (x) 82 + 83 + # define htobe32(x) _byteswap_ulong(x) 84 + # define htole32(x) (x) 85 + # define be32toh(x) _byteswap_ulong(x) 86 + # define le32toh(x) (x) 87 + 88 + # define htobe64(x) _byteswap_uint64(x) 89 + # define htole64(x) (x) 90 + # define be64toh(x) _byteswap_uint64(x) 91 + # define le64toh(x) (x) 92 + 93 + #else 94 + 95 + typedef uint8_t BOOLEAN; 96 + #define FALSE 0 97 + #define TRUE 1 98 + 99 + /* ... for Linux */ 100 + #if defined(__linux__) || defined(__CYGWIN__) || defined (__USE_SYSTEM_ENDIAN_H__) 101 + # include <endian.h> 102 + 103 + 104 + /* ... for OSX */ 105 + #elif defined(__APPLE__) 106 + # include <libkern/OSByteOrder.h> 107 + # define htole64(x) OSSwapHostToLittleInt64(x) 108 + # define le64toh(x) OSSwapLittleToHostInt64(x) 109 + # define htobe64(x) OSSwapHostToBigInt64(x) 110 + # define be64toh(x) OSSwapBigToHostInt64(x) 111 + 112 + # define htole16(x) OSSwapHostToLittleInt16(x) 113 + # define le16toh(x) OSSwapLittleToHostInt16(x) 114 + # define htobe16(x) OSSwapHostToBigInt16(x) 115 + # define be16toh(x) OSSwapBigToHostInt16(x) 116 + 117 + # define htole32(x) OSSwapHostToLittleInt32(x) 118 + # define le32toh(x) OSSwapLittleToHostInt32(x) 119 + # define htobe32(x) OSSwapHostToBigInt32(x) 120 + # define be32toh(x) OSSwapBigToHostInt32(x) 121 + 122 + /* ... for other BSDs */ 123 + #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) 124 + # include <sys/endian.h> 125 + #elif defined(__OpenBSD__) 126 + # include <endian.h> 127 + 128 + /* ... for Windows (GCC-like, e.g. mingw or clang) */ 129 + #elif (defined(_WIN32) || defined(_WIN64)) && \ 130 + (defined(__GNUC__) || defined(__clang__)) 131 + 132 + # define htobe16(x) __builtin_bswap16(x) 133 + # define htole16(x) (x) 134 + # define be16toh(x) __builtin_bswap16(x) 135 + # define le16toh(x) (x) 136 + 137 + # define htobe32(x) __builtin_bswap32(x) 138 + # define htole32(x) (x) 139 + # define be32toh(x) __builtin_bswap32(x) 140 + # define le32toh(x) (x) 141 + 142 + # define htobe64(x) __builtin_bswap64(x) 143 + # define htole64(x) (x) 144 + # define be64toh(x) __builtin_bswap64(x) 145 + # define le64toh(x) (x) 146 + 147 + #elif (defined(__GNUC__) || defined(__clang__)) && defined(__BYTE_ORDER__) 148 + /* Freestanding target with no OS <endian.h> (e.g. a unikernel): take byte 149 + order from the compiler and byte-swap with its builtins. */ 150 + # if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 151 + # define htobe16(x) __builtin_bswap16(x) 152 + # define htole16(x) (x) 153 + # define be16toh(x) __builtin_bswap16(x) 154 + # define le16toh(x) (x) 155 + # define htobe32(x) __builtin_bswap32(x) 156 + # define htole32(x) (x) 157 + # define be32toh(x) __builtin_bswap32(x) 158 + # define le32toh(x) (x) 159 + # define htobe64(x) __builtin_bswap64(x) 160 + # define htole64(x) (x) 161 + # define be64toh(x) __builtin_bswap64(x) 162 + # define le64toh(x) (x) 163 + # else 164 + # define htobe16(x) (x) 165 + # define htole16(x) __builtin_bswap16(x) 166 + # define be16toh(x) (x) 167 + # define le16toh(x) __builtin_bswap16(x) 168 + # define htobe32(x) (x) 169 + # define htole32(x) __builtin_bswap32(x) 170 + # define be32toh(x) (x) 171 + # define le32toh(x) __builtin_bswap32(x) 172 + # define htobe64(x) (x) 173 + # define htole64(x) __builtin_bswap64(x) 174 + # define be64toh(x) (x) 175 + # define le64toh(x) __builtin_bswap64(x) 176 + # endif 177 + 178 + #else 179 + 180 + #error "Unsupported platform" 181 + 182 + #endif 183 + 184 + #endif 185 + 186 + inline static uint16_t Load16(uint8_t *b) { 187 + uint16_t x; 188 + memcpy(&x, b, 2); 189 + return x; 190 + } 191 + 192 + inline static uint32_t Load32(uint8_t *b) { 193 + uint32_t x; 194 + memcpy(&x, b, 4); 195 + return x; 196 + } 197 + 198 + inline static uint64_t Load64(uint8_t *b) { 199 + uint64_t x; 200 + memcpy(&x, b, 8); 201 + return x; 202 + } 203 + 204 + inline static void Store16(uint8_t *b, uint16_t i) { 205 + memcpy(b, &i, 2); 206 + } 207 + 208 + inline static void Store32(uint8_t *b, uint32_t i) { 209 + memcpy(b, &i, 4); 210 + } 211 + 212 + inline static void Store64(uint8_t *b, uint64_t i) { 213 + memcpy(b, &i, 8); 214 + } 215 + 216 + #define Load16Le(b) (le16toh(Load16(b))) 217 + #define Store16Le(b, i) (Store16(b, htole16(i))) 218 + #define Load16Be(b) (be16toh(Load16(b))) 219 + #define Store16Be(b, i) (Store16(b, htobe16(i))) 220 + 221 + #define Load32Le(b) (le32toh(Load32(b))) 222 + #define Store32Le(b, i) (Store32(b, htole32(i))) 223 + #define Load32Be(b) (be32toh(Load32(b))) 224 + #define Store32Be(b, i) (Store32(b, htobe32(i))) 225 + 226 + #define Load64Le(b) (le64toh(Load64(b))) 227 + #define Store64Le(b, i) (Store64(b, htole64(i))) 228 + #define Load64Be(b) (be64toh(Load64(b))) 229 + #define Store64Be(b, i) (Store64(b, htobe64(i))) 230 + 231 + 232 + #if defined(__cplusplus) 233 + } 234 + #endif 235 + 236 + #endif
+19 -14
c/dune.inc
··· 1 1 (rule 2 2 (alias 3d) 3 + (enabled_if 4 + (= %{context_name} default)) 3 5 (mode promote) 4 6 (targets Tcp.3d) 5 7 (action 6 8 (run %{exe:gen.exe} 3d))) 7 9 8 10 (rule 11 + (enabled_if 12 + (= %{context_name} default)) 9 13 (targets agree.c) 10 14 (action 11 15 (run %{exe:gen.exe} agree))) ··· 13 17 (rule 14 18 (alias 3d) 15 19 (enabled_if 16 - (= %{env:BUILD_EVERPARSE=} "1")) 20 + (and 21 + (= %{context_name} default) 22 + (= %{env:BUILD_EVERPARSE=} "1"))) 17 23 (mode promote) 18 24 (targets EverParse.h EverParseEndianness.h Tcp.c Tcp.h TcpWrapper.c TcpWrapper.h) 19 25 (deps Tcp.3d) ··· 22 28 23 29 (rule 24 30 (targets libtcp.a) 25 - (enabled_if (= %{ocaml-config:system} macosx)) 31 + (enabled_if 32 + (= %{ocaml-config:system} macosx)) 26 33 (deps EverParse.h EverParseEndianness.h Tcp.c Tcp.h TcpWrapper.c TcpWrapper.h) 27 34 (action 28 - (progn 29 - (run cc -std=c11 -D_DEFAULT_SOURCE -Wall -Werror -Wpedantic -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wcast-qual -DUINT8=uint8_t -DUINT16=uint16_t -DUINT16BE=uint16_t -DUINT32=uint32_t -DUINT32BE=uint32_t -DUINT64=uint64_t -DUINT64BE=uint64_t -c Tcp.c TcpWrapper.c) 30 - (run ld -r -o Tcp_lib.o Tcp.o TcpWrapper.o -exported_symbol _TcpCheckTcp) 31 - (run ar rcs libtcp.a Tcp_lib.o) 32 - ))) 35 + (run sh -c "set -e; CC=%{ocaml-config:c_compiler}; \"$CC\" -std=c11 -D_DEFAULT_SOURCE -Wall -Werror -Wpedantic -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wcast-qual -DUINT8=uint8_t -DUINT16=uint16_t -DUINT16BE=uint16_t -DUINT32=uint32_t -DUINT32BE=uint32_t -DUINT64=uint64_t -DUINT64BE=uint64_t -c Tcp.c TcpWrapper.c; %{ocaml-config:native_pack_linker} Tcp_lib.o Tcp.o TcpWrapper.o -exported_symbol _TcpCheckTcp; \"$(\"$CC\" -print-prog-name=ar)\" rcs libtcp.a Tcp_lib.o"))) 33 36 34 37 (rule 35 38 (targets libtcp.a) 36 - (enabled_if (<> %{ocaml-config:system} macosx)) 39 + (enabled_if 40 + (<> %{ocaml-config:system} macosx)) 37 41 (deps EverParse.h EverParseEndianness.h Tcp.c Tcp.h TcpWrapper.c TcpWrapper.h) 38 42 (action 39 - (progn 40 - (run cc -std=c11 -D_DEFAULT_SOURCE -Wall -Werror -Wpedantic -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wcast-qual -DUINT8=uint8_t -DUINT16=uint16_t -DUINT16BE=uint16_t -DUINT32=uint32_t -DUINT32BE=uint32_t -DUINT64=uint64_t -DUINT64BE=uint64_t -c Tcp.c TcpWrapper.c) 41 - (run ld -r -o Tcp_lib.o Tcp.o TcpWrapper.o) 42 - (run objcopy --keep-global-symbol TcpCheckTcp Tcp_lib.o) 43 - (run ar rcs libtcp.a Tcp_lib.o) 44 - ))) 43 + (run sh -c "set -e; CC=%{ocaml-config:c_compiler}; \"$CC\" -std=c11 -D_DEFAULT_SOURCE -Wall -Werror -Wpedantic -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wcast-qual -DUINT8=uint8_t -DUINT16=uint16_t -DUINT16BE=uint16_t -DUINT32=uint32_t -DUINT32BE=uint32_t -DUINT64=uint64_t -DUINT64BE=uint64_t -c Tcp.c TcpWrapper.c; %{ocaml-config:native_pack_linker} Tcp_lib.o Tcp.o TcpWrapper.o; \"$(\"$CC\" -print-prog-name=objcopy)\" --keep-global-symbol TcpCheckTcp Tcp_lib.o; \"$(\"$CC\" -print-prog-name=ar)\" rcs libtcp.a Tcp_lib.o"))) 45 44 46 45 (rule 46 + (enabled_if 47 + (= %{context_name} default)) 47 48 (targets corpus) 48 49 (action 49 50 (with-stdout-to corpus (run %{exe:gen.exe} corpus)))) 50 51 51 52 (rule 53 + (enabled_if 54 + (= %{context_name} default)) 52 55 (targets agree) 53 56 (deps agree.c libtcp.a EverParse.h EverParseEndianness.h Tcp.h TcpWrapper.h) 54 57 (action ··· 56 59 57 60 (rule 58 61 (alias runtest) 62 + (enabled_if 63 + (= %{context_name} default)) 59 64 (deps corpus agree) 60 65 (action 61 66 (run %{dep:agree} corpus)))