CCSDS Space Data Link Security (355.0-B-2)
0
fork

Configure Feed

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

regenerate EverParse C files with wire 0.9.0

Wire_3d now generates ExternalTypedefs.h, ExternalAPI.h, Wrapper,
and Fields files for schemas using WireCtx. Bitfield padding is
fixed so .3d structs match the OCaml codec wire_size. Test.c passes
NULL for the WIRECTX parameter and links per-schema Field stubs.

Affected: ax25, cfdp, fsr, ltp, mbr, pid1, pus, rpmsg, sdls,
spacefibre, squashfs, tcpcl, udpcl, spacewire, and others via @gen.

+1224 -16
+7 -8
c/EP_Header.3d
··· 1 1 extern typedef struct _WireCtx WireCtx 2 2 3 - extern unit WireSetU8(mutable WireCtx *ctx, UINT32 idx, UINT8 v) 3 + extern unit EP_HeaderSetU8(mutable WireCtx *ctx, UINT32 idx, UINT8 v) 4 4 5 - extern unit WireSetU16BE(mutable WireCtx *ctx, UINT32 idx, UINT16BE v) 5 + extern unit EP_HeaderSetU16BE(mutable WireCtx *ctx, UINT32 idx, UINT16BE v) 6 6 7 7 entrypoint 8 8 typedef struct _EP_Header(mutable WireCtx *ctx) 9 9 { 10 - UINT8 Type : 1 {:act WireSetU8(ctx, (UINT32) 0, Type); }; 11 - UINT8 UF : 1 {:act WireSetU8(ctx, (UINT32) 1, UF); }; 12 - UINT8 _anon_0 : 2; 13 - UINT8 PID : 4 {:act WireSetU8(ctx, (UINT32) 3, PID); }; 14 - UINT8 SG : 2 {:act WireSetU8(ctx, (UINT32) 2, SG); }; 15 - UINT16BE PDU_LEN {:on-success WireSetU16BE(ctx, (UINT32) 4, PDU_LEN); return true; }; 10 + UINT8 PID : 4 {:act EP_HeaderSetU8(ctx, (UINT32) 3, PID); }; 11 + UINT8 SG : 2 {:act EP_HeaderSetU8(ctx, (UINT32) 2, SG); }; 12 + UINT8 UF : 1 {:act EP_HeaderSetU8(ctx, (UINT32) 1, UF); }; 13 + UINT8 Type : 1 {:act EP_HeaderSetU8(ctx, (UINT32) 0, Type); }; 14 + UINT16BE PDU_LEN {:on-success EP_HeaderSetU16BE(ctx, (UINT32) 4, PDU_LEN); return true; }; 16 15 } EP_Header; 17 16 18 17
+116
c/EP_Header.c
··· 1 + 2 + 3 + #include "EP_Header.h" 4 + 5 + #include "EP_Header_ExternalAPI.h" 6 + 7 + uint64_t 8 + EpHeaderValidateEpHeader( 9 + WIRECTX *Ctx, 10 + uint8_t *Ctxt, 11 + void 12 + (*ErrorHandlerFn)( 13 + EVERPARSE_STRING x0, 14 + EVERPARSE_STRING x1, 15 + EVERPARSE_STRING x2, 16 + uint64_t x3, 17 + uint8_t *x4, 18 + uint8_t *x5, 19 + uint64_t x6 20 + ), 21 + uint8_t *Input, 22 + uint64_t InputLength, 23 + uint64_t StartPosition 24 + ) 25 + { 26 + /* Validating field __bitfield_0 */ 27 + /* Checking that we have enough space for a UINT8, i.e., 1 byte */ 28 + BOOLEAN hasBytes0 = 1ULL <= (InputLength - StartPosition); 29 + uint64_t positionAfterBitfield0; 30 + if (hasBytes0) 31 + { 32 + positionAfterBitfield0 = StartPosition + 1ULL; 33 + } 34 + else 35 + { 36 + positionAfterBitfield0 = 37 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 38 + StartPosition); 39 + } 40 + uint64_t positionAfterEpHeader; 41 + if (EverParseIsError(positionAfterBitfield0)) 42 + { 43 + positionAfterEpHeader = positionAfterBitfield0; 44 + } 45 + else 46 + { 47 + uint8_t bitfield0 = Input[(uint32_t)StartPosition]; 48 + EpHeaderSetU8(Ctx, (uint32_t)3U, EverParseGetBitfield8(bitfield0, 0U, 4U)); 49 + EpHeaderSetU8(Ctx, (uint32_t)2U, EverParseGetBitfield8(bitfield0, 4U, 6U)); 50 + EpHeaderSetU8(Ctx, (uint32_t)1U, EverParseGetBitfield8(bitfield0, 6U, 7U)); 51 + EpHeaderSetU8(Ctx, (uint32_t)0U, EverParseGetBitfield8(bitfield0, 7U, 8U)); 52 + BOOLEAN actionResult = TRUE; 53 + KRML_MAYBE_UNUSED_VAR(actionResult); 54 + positionAfterEpHeader = positionAfterBitfield0; 55 + } 56 + uint64_t positionAfterBitfield00; 57 + if (EverParseIsSuccess(positionAfterEpHeader)) 58 + { 59 + positionAfterBitfield00 = positionAfterEpHeader; 60 + } 61 + else 62 + { 63 + ErrorHandlerFn("_EP_Header", 64 + "__bitfield_0", 65 + EverParseErrorReasonOfResult(positionAfterEpHeader), 66 + EverParseGetValidatorErrorKind(positionAfterEpHeader), 67 + Ctxt, 68 + Input, 69 + StartPosition); 70 + positionAfterBitfield00 = positionAfterEpHeader; 71 + } 72 + if (EverParseIsError(positionAfterBitfield00)) 73 + { 74 + return positionAfterBitfield00; 75 + } 76 + /* Validating field PDU_LEN */ 77 + /* Checking that we have enough space for a UINT16BE, i.e., 2 bytes */ 78 + BOOLEAN hasBytes = 2ULL <= (InputLength - positionAfterBitfield00); 79 + uint64_t positionAfterPduLen; 80 + if (hasBytes) 81 + { 82 + positionAfterPduLen = positionAfterBitfield00 + 2ULL; 83 + } 84 + else 85 + { 86 + positionAfterPduLen = 87 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 88 + positionAfterBitfield00); 89 + } 90 + uint64_t positionAfterEpHeader0; 91 + if (EverParseIsError(positionAfterPduLen)) 92 + { 93 + positionAfterEpHeader0 = positionAfterPduLen; 94 + } 95 + else 96 + { 97 + uint16_t pduLen = Load16Be(Input + (uint32_t)positionAfterBitfield00); 98 + EpHeaderSetU16be(Ctx, (uint32_t)4U, pduLen); 99 + BOOLEAN actionResult = TRUE; 100 + KRML_MAYBE_UNUSED_VAR(actionResult); 101 + positionAfterEpHeader0 = positionAfterPduLen; 102 + } 103 + if (EverParseIsSuccess(positionAfterEpHeader0)) 104 + { 105 + return positionAfterEpHeader0; 106 + } 107 + ErrorHandlerFn("_EP_Header", 108 + "PDU_LEN", 109 + EverParseErrorReasonOfResult(positionAfterEpHeader0), 110 + EverParseGetValidatorErrorKind(positionAfterEpHeader0), 111 + Ctxt, 112 + Input, 113 + positionAfterBitfield00); 114 + return positionAfterEpHeader0; 115 + } 116 +
+37
c/EP_Header.h
··· 1 + 2 + 3 + #ifndef EP_Header_H 4 + #define EP_Header_H 5 + 6 + #if defined(__cplusplus) 7 + extern "C" { 8 + #endif 9 + 10 + #include "EverParse.h" 11 + #include "EP_Header_ExternalTypedefs.h" 12 + 13 + uint64_t 14 + EpHeaderValidateEpHeader( 15 + WIRECTX *Ctx, 16 + uint8_t *Ctxt, 17 + void 18 + (*ErrorHandlerFn)( 19 + EVERPARSE_STRING x0, 20 + EVERPARSE_STRING x1, 21 + EVERPARSE_STRING x2, 22 + uint64_t x3, 23 + uint8_t *x4, 24 + uint8_t *x5, 25 + uint64_t x6 26 + ), 27 + uint8_t *Input, 28 + uint64_t InputLength, 29 + uint64_t StartPosition 30 + ); 31 + 32 + #if defined(__cplusplus) 33 + } 34 + #endif 35 + 36 + #define EP_Header_H_DEFINED 37 + #endif /* EP_Header_H */
+41
c/EP_HeaderWrapper.c
··· 1 + #include "EP_HeaderWrapper.h" 2 + #include "EverParse.h" 3 + #include "EP_Header.h" 4 + void EP_HeaderEverParseError(const char *StructName, const char *FieldName, const char *Reason); 5 + 6 + static 7 + void DefaultErrorHandler( 8 + const char *typename_s, 9 + const char *fieldname, 10 + const char *reason, 11 + uint64_t error_code, 12 + uint8_t *context, 13 + EVERPARSE_INPUT_BUFFER input, 14 + uint64_t start_pos) 15 + { 16 + EVERPARSE_ERROR_FRAME *frame = (EVERPARSE_ERROR_FRAME*)context; 17 + EverParseDefaultErrorHandler( 18 + typename_s, 19 + fieldname, 20 + reason, 21 + error_code, 22 + frame, 23 + input, 24 + start_pos 25 + ); 26 + } 27 + 28 + BOOLEAN EpHeaderCheckEpHeader(WIRECTX* ctx, uint8_t *base, uint32_t len) { 29 + EVERPARSE_ERROR_FRAME frame; 30 + frame.filled = FALSE; 31 + uint64_t result = EpHeaderValidateEpHeader(ctx, (uint8_t*)&frame, &DefaultErrorHandler, base, len, 0); 32 + if (EverParseIsError(result)) 33 + { 34 + if (frame.filled) 35 + { 36 + EP_HeaderEverParseError(frame.typename_s, frame.fieldname, frame.reason); 37 + } 38 + return FALSE; 39 + } 40 + return TRUE; 41 + }
+26
c/EP_HeaderWrapper.h
··· 1 + #include "EverParseEndianness.h" 2 + #define EVERPARSE_SUCCESS 0ul 3 + #define EVERPARSE_ERROR_GENERIC 1uL 4 + #define EVERPARSE_ERROR_NOT_ENOUGH_DATA 2uL 5 + #define EVERPARSE_ERROR_IMPOSSIBLE 3uL 6 + #define EVERPARSE_ERROR_LIST_SIZE_NOT_MULTIPLE 4uL 7 + #define EVERPARSE_ERROR_ACTION_FAILED 5uL 8 + #define EVERPARSE_ERROR_CONSTRAINT_FAILED 6uL 9 + #define EVERPARSE_ERROR_UNEXPECTED_PADDING 7uL 10 + // Probe wrapper error codes 11 + #define EVERPARSE_PROBE_FAILURE_INCORRECT_SIZE 256uL 12 + #define EVERPARSE_PROBE_FAILURE_INIT 257uL 13 + #define EVERPARSE_PROBE_FAILURE_PROBE 258uL 14 + #define EVERPARSE_PROBE_FAILURE_VALIDATION 259uL 15 + 16 + 17 + #include "EP_Header_ExternalTypedefs.h" 18 + 19 + 20 + #ifdef __cplusplus 21 + extern "C" { 22 + #endif 23 + BOOLEAN EpHeaderCheckEpHeader(WIRECTX* ctx, uint8_t *base, uint32_t len); 24 + #ifdef __cplusplus 25 + } 26 + #endif
+22
c/EP_Header_ExternalAPI.h
··· 1 + 2 + 3 + #ifndef EP_Header_ExternalAPI_H 4 + #define EP_Header_ExternalAPI_H 5 + 6 + #if defined(__cplusplus) 7 + extern "C" { 8 + #endif 9 + 10 + #include "EverParse.h" 11 + #include "EP_Header_ExternalTypedefs.h" 12 + 13 + extern void EpHeaderSetU8(WIRECTX *ctx, uint32_t idx, uint8_t v); 14 + 15 + extern void EpHeaderSetU16be(WIRECTX *ctx, uint32_t idx, uint16_t v); 16 + 17 + #if defined(__cplusplus) 18 + } 19 + #endif 20 + 21 + #define EP_Header_ExternalAPI_H_DEFINED 22 + #endif /* EP_Header_ExternalAPI_H */
+4
c/EP_Header_ExternalTypedefs.h
··· 1 + #ifndef WIRECTX_DEFINED 2 + #define WIRECTX_DEFINED 3 + typedef struct EP_HeaderFields WIRECTX; 4 + #endif
+24
c/EP_Header_Fields.c
··· 1 + #include <stdint.h> 2 + #include "EP_Header_Fields.h" 3 + #include "EP_Header_ExternalTypedefs.h" 4 + #include "EP_Header_ExternalAPI.h" 5 + 6 + void EpHeaderSetU8(WIRECTX *ctx, uint32_t idx, uint8_t v) { 7 + EP_HeaderFields *f = (EP_HeaderFields *) ctx; 8 + switch (idx) { 9 + case 0: f->Type = (uint32_t) v; break; 10 + case 1: f->UF = (uint32_t) v; break; 11 + case 2: f->SG = (uint8_t) v; break; 12 + case 3: f->PID = (uint8_t) v; break; 13 + default: (void) f; (void) v; break; 14 + } 15 + } 16 + 17 + void EpHeaderSetU16be(WIRECTX *ctx, uint32_t idx, uint16_t v) { 18 + EP_HeaderFields *f = (EP_HeaderFields *) ctx; 19 + switch (idx) { 20 + case 4: f->PDU_LEN = (uint16_t) v; break; 21 + default: (void) f; (void) v; break; 22 + } 23 + } 24 +
+22
c/EP_Header_Fields.h
··· 1 + #ifndef EP_HEADER_FIELDS_H 2 + #define EP_HEADER_FIELDS_H 3 + #include <stdint.h> 4 + 5 + /* Field indices -- use with the schema's WireSet* callbacks in a 6 + custom [WIRECTX] if you only want to capture a subset. */ 7 + #define EP_HEADER_IDX_TYPE 0 8 + #define EP_HEADER_IDX_UF 1 9 + #define EP_HEADER_IDX_SG 2 10 + #define EP_HEADER_IDX_PID 3 11 + #define EP_HEADER_IDX_PDU_LEN 4 12 + 13 + /* Default plug: one typed member per named field. Pass a pointer to 14 + [EP_HeaderFields] as [WIRECTX *] when you want every field populated. */ 15 + typedef struct EP_HeaderFields { 16 + uint32_t Type; 17 + uint32_t UF; 18 + uint8_t SG; 19 + uint8_t PID; 20 + uint16_t PDU_LEN; 21 + } EP_HeaderFields; 22 + #endif
+243
c/EverParse.h
··· 1 + /*++ 2 + 3 + Copyright (c) Microsoft Corporation 4 + 5 + Module Name: 6 + 7 + EverParse.h 8 + 9 + Abstract: 10 + 11 + This is an EverParse-generated file that contains common auxiliary 12 + functions for EverParse-generated verified data validators. 13 + 14 + This file was generated by EverParse v2026.02.25 15 + 16 + Authors: 17 + 18 + nswamy, protz, taramana 5-Feb-2020 19 + 20 + --*/ 21 + 22 + 23 + #ifndef EverParse_H 24 + #define EverParse_H 25 + 26 + #if defined(__cplusplus) 27 + extern "C" { 28 + #endif 29 + 30 + #include "EverParseEndianness.h" 31 + 32 + static inline uint8_t EverParseGetBitfield8(uint8_t Value, uint32_t BitsFrom, uint32_t BitsTo) 33 + { 34 + uint8_t op1 = (uint32_t)Value << (8U - BitsTo); 35 + return (uint32_t)op1 >> (8U - BitsTo + BitsFrom); 36 + } 37 + 38 + static inline uint16_t 39 + EverParseGetBitfield16(uint16_t Value, uint32_t BitsFrom, uint32_t BitsTo) 40 + { 41 + uint16_t bf = (uint32_t)Value << (16U - BitsTo); 42 + return (uint32_t)bf >> (16U - BitsTo + BitsFrom); 43 + } 44 + 45 + static inline uint32_t 46 + EverParseGetBitfield32(uint32_t Value, uint32_t BitsFrom, uint32_t BitsTo) 47 + { 48 + return Value << (32U - BitsTo) >> (32U - BitsTo + BitsFrom); 49 + } 50 + 51 + static inline uint64_t 52 + EverParseGetBitfield64(uint64_t Value, uint32_t BitsFrom, uint32_t BitsTo) 53 + { 54 + return Value << (64U - BitsTo) >> (64U - BitsTo + BitsFrom); 55 + } 56 + 57 + static inline uint8_t 58 + EverParseGetBitfield8MsbFirst(uint8_t Value, uint32_t BitsFrom, uint32_t BitsTo) 59 + { 60 + return EverParseGetBitfield8(Value, 8U - BitsTo, 8U - BitsFrom); 61 + } 62 + 63 + static inline uint16_t 64 + EverParseGetBitfield16MsbFirst(uint16_t Value, uint32_t BitsFrom, uint32_t BitsTo) 65 + { 66 + return EverParseGetBitfield16(Value, 16U - BitsTo, 16U - BitsFrom); 67 + } 68 + 69 + static inline uint32_t 70 + EverParseGetBitfield32MsbFirst(uint32_t Value, uint32_t BitsFrom, uint32_t BitsTo) 71 + { 72 + return EverParseGetBitfield32(Value, 32U - BitsTo, 32U - BitsFrom); 73 + } 74 + 75 + static inline uint64_t 76 + EverParseGetBitfield64MsbFirst(uint64_t Value, uint32_t BitsFrom, uint32_t BitsTo) 77 + { 78 + return EverParseGetBitfield64(Value, 64U - BitsTo, 64U - BitsFrom); 79 + } 80 + 81 + #define EVERPARSE_VALIDATOR_MAX_LENGTH (1152921504606846975ULL) 82 + 83 + static inline BOOLEAN EverParseIsError(uint64_t PositionOrError) 84 + { 85 + return PositionOrError > EVERPARSE_VALIDATOR_MAX_LENGTH; 86 + } 87 + 88 + static inline BOOLEAN EverParseIsSuccess(uint64_t PositionOrError) 89 + { 90 + return PositionOrError <= EVERPARSE_VALIDATOR_MAX_LENGTH; 91 + } 92 + 93 + static inline uint64_t EverParseSetValidatorErrorPos(uint64_t Error, uint64_t Position) 94 + { 95 + return (Error & 17293822569102704640ULL) | Position << 0U; 96 + } 97 + 98 + static inline uint64_t EverParseGetValidatorErrorPos(uint64_t X) 99 + { 100 + return (X & 1152921504606846975ULL) >> 0U; 101 + } 102 + 103 + static inline uint64_t EverParseSetValidatorErrorKind(uint64_t Error, uint64_t Code) 104 + { 105 + return (Error & 1152921504606846975ULL) | Code << 60U; 106 + } 107 + 108 + static inline uint64_t EverParseGetValidatorErrorKind(uint64_t Error) 109 + { 110 + return (Error & 17293822569102704640ULL) >> 60U; 111 + } 112 + 113 + #define EVERPARSE_VALIDATOR_ERROR_GENERIC (1152921504606846976ULL) 114 + 115 + #define EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA (2305843009213693952ULL) 116 + 117 + #define EVERPARSE_VALIDATOR_ERROR_IMPOSSIBLE (3458764513820540928ULL) 118 + 119 + #define EVERPARSE_VALIDATOR_ERROR_LIST_SIZE_NOT_MULTIPLE (4611686018427387904ULL) 120 + 121 + #define EVERPARSE_VALIDATOR_ERROR_ACTION_FAILED (5764607523034234880ULL) 122 + 123 + #define EVERPARSE_VALIDATOR_ERROR_CONSTRAINT_FAILED (6917529027641081856ULL) 124 + 125 + #define EVERPARSE_VALIDATOR_ERROR_UNEXPECTED_PADDING (8070450532247928832ULL) 126 + 127 + #define EVERPARSE_VALIDATOR_ERROR_PROBE_FAILED (9223372036854775808ULL) 128 + 129 + static inline PRIMS_STRING EverParseErrorReasonOfResult(uint64_t Code) 130 + { 131 + switch (EverParseGetValidatorErrorKind(Code)) 132 + { 133 + case 1ULL: 134 + { 135 + return "generic error"; 136 + } 137 + case 2ULL: 138 + { 139 + return "not enough data"; 140 + } 141 + case 3ULL: 142 + { 143 + return "impossible"; 144 + } 145 + case 4ULL: 146 + { 147 + return "list size not multiple of element size"; 148 + } 149 + case 5ULL: 150 + { 151 + return "action failed"; 152 + } 153 + case 6ULL: 154 + { 155 + return "constraint failed"; 156 + } 157 + case 7ULL: 158 + { 159 + return "unexpected padding"; 160 + } 161 + case 8ULL: 162 + { 163 + return "probe failed"; 164 + } 165 + default: 166 + { 167 + return "unspecified"; 168 + } 169 + } 170 + } 171 + 172 + static inline uint64_t EverParseCheckConstraintOk(BOOLEAN Ok, uint64_t Position) 173 + { 174 + if (Ok) 175 + { 176 + return Position; 177 + } 178 + return EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_CONSTRAINT_FAILED, Position); 179 + } 180 + 181 + static inline BOOLEAN EverParseIsRangeOkay(uint32_t Size, uint32_t Offset, uint32_t AccessSize) 182 + { 183 + return Size >= AccessSize && (Size - AccessSize) >= Offset; 184 + } 185 + 186 + typedef struct EVERPARSE_ERROR_FRAME_s 187 + { 188 + BOOLEAN filled; 189 + uint64_t start_pos; 190 + PRIMS_STRING typename_s; 191 + PRIMS_STRING fieldname; 192 + PRIMS_STRING reason; 193 + uint64_t error_code; 194 + } 195 + EVERPARSE_ERROR_FRAME; 196 + 197 + typedef uint8_t *EVERPARSE_INPUT_BUFFER; 198 + 199 + typedef void *EVERPARSE__LIVE; 200 + 201 + static inline void 202 + EverParseDefaultErrorHandler( 203 + PRIMS_STRING TypenameS, 204 + PRIMS_STRING Fieldname, 205 + PRIMS_STRING Reason, 206 + uint64_t ErrorCode, 207 + EVERPARSE_ERROR_FRAME *Context, 208 + uint8_t *Input, 209 + uint64_t StartPos 210 + ) 211 + { 212 + KRML_MAYBE_UNUSED_VAR(Input); 213 + if (!(*Context).filled) 214 + { 215 + *Context = 216 + ( 217 + (EVERPARSE_ERROR_FRAME){ 218 + .filled = TRUE, 219 + .start_pos = StartPos, 220 + .typename_s = TypenameS, 221 + .fieldname = Fieldname, 222 + .reason = Reason, 223 + .error_code = ErrorCode 224 + } 225 + ); 226 + return; 227 + } 228 + } 229 + 230 + extern uint8_t *EverParseStreamOf(EVERPARSE_COPY_BUFFER_T uu___); 231 + 232 + extern uint64_t EverParseStreamLen(EVERPARSE_COPY_BUFFER_T c); 233 + 234 + typedef void *EVERPARSE_INV; 235 + 236 + typedef void *EVERPARSE_LIVENESS_PRESERVED; 237 + 238 + #if defined(__cplusplus) 239 + } 240 + #endif 241 + 242 + #define EverParse_H_DEFINED 243 + #endif /* EverParse_H */
+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
+5 -5
c/MC_Status_Reply.3d
··· 1 1 extern typedef struct _WireCtx WireCtx 2 2 3 - extern unit WireSetU8(mutable WireCtx *ctx, UINT32 idx, UINT8 v) 3 + extern unit MC_Status_ReplySetU8(mutable WireCtx *ctx, UINT32 idx, UINT8 v) 4 4 5 - extern unit WireSetU16BE(mutable WireCtx *ctx, UINT32 idx, UINT16BE v) 5 + extern unit MC_Status_ReplySetU16BE(mutable WireCtx *ctx, UINT32 idx, UINT16BE v) 6 6 7 7 entrypoint 8 8 typedef struct _MC_Status_Reply(mutable WireCtx *ctx) 9 9 { 10 - UINT8 Operational {:on-success WireSetU8(ctx, (UINT32) 0, Operational); return true; }; 11 - UINT16BE KeyCount {:on-success WireSetU16BE(ctx, (UINT32) 1, KeyCount); return true; }; 12 - UINT16BE SACount {:on-success WireSetU16BE(ctx, (UINT32) 2, SACount); return true; }; 10 + UINT8 Operational {:on-success MC_Status_ReplySetU8(ctx, (UINT32) 0, Operational); return true; }; 11 + UINT16BE KeyCount {:on-success MC_Status_ReplySetU16BE(ctx, (UINT32) 1, KeyCount); return true; }; 12 + UINT16BE SACount {:on-success MC_Status_ReplySetU16BE(ctx, (UINT32) 2, SACount); return true; }; 13 13 } MC_Status_Reply; 14 14 15 15
+160
c/MC_Status_Reply.c
··· 1 + 2 + 3 + #include "MC_Status_Reply.h" 4 + 5 + #include "MC_Status_Reply_ExternalAPI.h" 6 + 7 + uint64_t 8 + McStatusReplyValidateMcStatusReply( 9 + WIRECTX *Ctx, 10 + uint8_t *Ctxt, 11 + void 12 + (*ErrorHandlerFn)( 13 + EVERPARSE_STRING x0, 14 + EVERPARSE_STRING x1, 15 + EVERPARSE_STRING x2, 16 + uint64_t x3, 17 + uint8_t *x4, 18 + uint8_t *x5, 19 + uint64_t x6 20 + ), 21 + uint8_t *Input, 22 + uint64_t InputLength, 23 + uint64_t StartPosition 24 + ) 25 + { 26 + /* Validating field Operational */ 27 + /* Checking that we have enough space for a UINT8, i.e., 1 byte */ 28 + BOOLEAN hasBytes0 = 1ULL <= (InputLength - StartPosition); 29 + uint64_t positionAfterOperational0; 30 + if (hasBytes0) 31 + { 32 + positionAfterOperational0 = StartPosition + 1ULL; 33 + } 34 + else 35 + { 36 + positionAfterOperational0 = 37 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 38 + StartPosition); 39 + } 40 + uint64_t positionAfterMcStatusReply; 41 + if (EverParseIsError(positionAfterOperational0)) 42 + { 43 + positionAfterMcStatusReply = positionAfterOperational0; 44 + } 45 + else 46 + { 47 + uint8_t operational = Input[(uint32_t)StartPosition]; 48 + McStatusReplySetU8(Ctx, (uint32_t)0U, operational); 49 + BOOLEAN actionResult = TRUE; 50 + KRML_MAYBE_UNUSED_VAR(actionResult); 51 + positionAfterMcStatusReply = positionAfterOperational0; 52 + } 53 + uint64_t positionAfterOperational; 54 + if (EverParseIsSuccess(positionAfterMcStatusReply)) 55 + { 56 + positionAfterOperational = positionAfterMcStatusReply; 57 + } 58 + else 59 + { 60 + ErrorHandlerFn("_MC_Status_Reply", 61 + "Operational", 62 + EverParseErrorReasonOfResult(positionAfterMcStatusReply), 63 + EverParseGetValidatorErrorKind(positionAfterMcStatusReply), 64 + Ctxt, 65 + Input, 66 + StartPosition); 67 + positionAfterOperational = positionAfterMcStatusReply; 68 + } 69 + if (EverParseIsError(positionAfterOperational)) 70 + { 71 + return positionAfterOperational; 72 + } 73 + /* Validating field KeyCount */ 74 + /* Checking that we have enough space for a UINT16BE, i.e., 2 bytes */ 75 + BOOLEAN hasBytes1 = 2ULL <= (InputLength - positionAfterOperational); 76 + uint64_t positionAfterKeyCount0; 77 + if (hasBytes1) 78 + { 79 + positionAfterKeyCount0 = positionAfterOperational + 2ULL; 80 + } 81 + else 82 + { 83 + positionAfterKeyCount0 = 84 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 85 + positionAfterOperational); 86 + } 87 + uint64_t positionAfterMcStatusReply0; 88 + if (EverParseIsError(positionAfterKeyCount0)) 89 + { 90 + positionAfterMcStatusReply0 = positionAfterKeyCount0; 91 + } 92 + else 93 + { 94 + uint16_t keyCount = Load16Be(Input + (uint32_t)positionAfterOperational); 95 + McStatusReplySetU16be(Ctx, (uint32_t)1U, keyCount); 96 + BOOLEAN actionResult = TRUE; 97 + KRML_MAYBE_UNUSED_VAR(actionResult); 98 + positionAfterMcStatusReply0 = positionAfterKeyCount0; 99 + } 100 + uint64_t positionAfterKeyCount; 101 + if (EverParseIsSuccess(positionAfterMcStatusReply0)) 102 + { 103 + positionAfterKeyCount = positionAfterMcStatusReply0; 104 + } 105 + else 106 + { 107 + ErrorHandlerFn("_MC_Status_Reply", 108 + "KeyCount", 109 + EverParseErrorReasonOfResult(positionAfterMcStatusReply0), 110 + EverParseGetValidatorErrorKind(positionAfterMcStatusReply0), 111 + Ctxt, 112 + Input, 113 + positionAfterOperational); 114 + positionAfterKeyCount = positionAfterMcStatusReply0; 115 + } 116 + if (EverParseIsError(positionAfterKeyCount)) 117 + { 118 + return positionAfterKeyCount; 119 + } 120 + /* Validating field SACount */ 121 + /* Checking that we have enough space for a UINT16BE, i.e., 2 bytes */ 122 + BOOLEAN hasBytes = 2ULL <= (InputLength - positionAfterKeyCount); 123 + uint64_t positionAfterSACount; 124 + if (hasBytes) 125 + { 126 + positionAfterSACount = positionAfterKeyCount + 2ULL; 127 + } 128 + else 129 + { 130 + positionAfterSACount = 131 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 132 + positionAfterKeyCount); 133 + } 134 + uint64_t positionAfterMcStatusReply1; 135 + if (EverParseIsError(positionAfterSACount)) 136 + { 137 + positionAfterMcStatusReply1 = positionAfterSACount; 138 + } 139 + else 140 + { 141 + uint16_t sACount = Load16Be(Input + (uint32_t)positionAfterKeyCount); 142 + McStatusReplySetU16be(Ctx, (uint32_t)2U, sACount); 143 + BOOLEAN actionResult = TRUE; 144 + KRML_MAYBE_UNUSED_VAR(actionResult); 145 + positionAfterMcStatusReply1 = positionAfterSACount; 146 + } 147 + if (EverParseIsSuccess(positionAfterMcStatusReply1)) 148 + { 149 + return positionAfterMcStatusReply1; 150 + } 151 + ErrorHandlerFn("_MC_Status_Reply", 152 + "SACount", 153 + EverParseErrorReasonOfResult(positionAfterMcStatusReply1), 154 + EverParseGetValidatorErrorKind(positionAfterMcStatusReply1), 155 + Ctxt, 156 + Input, 157 + positionAfterKeyCount); 158 + return positionAfterMcStatusReply1; 159 + } 160 +
+37
c/MC_Status_Reply.h
··· 1 + 2 + 3 + #ifndef MC_Status_Reply_H 4 + #define MC_Status_Reply_H 5 + 6 + #if defined(__cplusplus) 7 + extern "C" { 8 + #endif 9 + 10 + #include "EverParse.h" 11 + #include "MC_Status_Reply_ExternalTypedefs.h" 12 + 13 + uint64_t 14 + McStatusReplyValidateMcStatusReply( 15 + WIRECTX *Ctx, 16 + uint8_t *Ctxt, 17 + void 18 + (*ErrorHandlerFn)( 19 + EVERPARSE_STRING x0, 20 + EVERPARSE_STRING x1, 21 + EVERPARSE_STRING x2, 22 + uint64_t x3, 23 + uint8_t *x4, 24 + uint8_t *x5, 25 + uint64_t x6 26 + ), 27 + uint8_t *Input, 28 + uint64_t InputLength, 29 + uint64_t StartPosition 30 + ); 31 + 32 + #if defined(__cplusplus) 33 + } 34 + #endif 35 + 36 + #define MC_Status_Reply_H_DEFINED 37 + #endif /* MC_Status_Reply_H */
+41
c/MC_Status_ReplyWrapper.c
··· 1 + #include "MC_Status_ReplyWrapper.h" 2 + #include "EverParse.h" 3 + #include "MC_Status_Reply.h" 4 + void MC_Status_ReplyEverParseError(const char *StructName, const char *FieldName, const char *Reason); 5 + 6 + static 7 + void DefaultErrorHandler( 8 + const char *typename_s, 9 + const char *fieldname, 10 + const char *reason, 11 + uint64_t error_code, 12 + uint8_t *context, 13 + EVERPARSE_INPUT_BUFFER input, 14 + uint64_t start_pos) 15 + { 16 + EVERPARSE_ERROR_FRAME *frame = (EVERPARSE_ERROR_FRAME*)context; 17 + EverParseDefaultErrorHandler( 18 + typename_s, 19 + fieldname, 20 + reason, 21 + error_code, 22 + frame, 23 + input, 24 + start_pos 25 + ); 26 + } 27 + 28 + BOOLEAN McStatusReplyCheckMcStatusReply(WIRECTX* ctx, uint8_t *base, uint32_t len) { 29 + EVERPARSE_ERROR_FRAME frame; 30 + frame.filled = FALSE; 31 + uint64_t result = McStatusReplyValidateMcStatusReply(ctx, (uint8_t*)&frame, &DefaultErrorHandler, base, len, 0); 32 + if (EverParseIsError(result)) 33 + { 34 + if (frame.filled) 35 + { 36 + MC_Status_ReplyEverParseError(frame.typename_s, frame.fieldname, frame.reason); 37 + } 38 + return FALSE; 39 + } 40 + return TRUE; 41 + }
+26
c/MC_Status_ReplyWrapper.h
··· 1 + #include "EverParseEndianness.h" 2 + #define EVERPARSE_SUCCESS 0ul 3 + #define EVERPARSE_ERROR_GENERIC 1uL 4 + #define EVERPARSE_ERROR_NOT_ENOUGH_DATA 2uL 5 + #define EVERPARSE_ERROR_IMPOSSIBLE 3uL 6 + #define EVERPARSE_ERROR_LIST_SIZE_NOT_MULTIPLE 4uL 7 + #define EVERPARSE_ERROR_ACTION_FAILED 5uL 8 + #define EVERPARSE_ERROR_CONSTRAINT_FAILED 6uL 9 + #define EVERPARSE_ERROR_UNEXPECTED_PADDING 7uL 10 + // Probe wrapper error codes 11 + #define EVERPARSE_PROBE_FAILURE_INCORRECT_SIZE 256uL 12 + #define EVERPARSE_PROBE_FAILURE_INIT 257uL 13 + #define EVERPARSE_PROBE_FAILURE_PROBE 258uL 14 + #define EVERPARSE_PROBE_FAILURE_VALIDATION 259uL 15 + 16 + 17 + #include "MC_Status_Reply_ExternalTypedefs.h" 18 + 19 + 20 + #ifdef __cplusplus 21 + extern "C" { 22 + #endif 23 + BOOLEAN McStatusReplyCheckMcStatusReply(WIRECTX* ctx, uint8_t *base, uint32_t len); 24 + #ifdef __cplusplus 25 + } 26 + #endif
+22
c/MC_Status_Reply_ExternalAPI.h
··· 1 + 2 + 3 + #ifndef MC_Status_Reply_ExternalAPI_H 4 + #define MC_Status_Reply_ExternalAPI_H 5 + 6 + #if defined(__cplusplus) 7 + extern "C" { 8 + #endif 9 + 10 + #include "EverParse.h" 11 + #include "MC_Status_Reply_ExternalTypedefs.h" 12 + 13 + extern void McStatusReplySetU8(WIRECTX *ctx, uint32_t idx, uint8_t v); 14 + 15 + extern void McStatusReplySetU16be(WIRECTX *ctx, uint32_t idx, uint16_t v); 16 + 17 + #if defined(__cplusplus) 18 + } 19 + #endif 20 + 21 + #define MC_Status_Reply_ExternalAPI_H_DEFINED 22 + #endif /* MC_Status_Reply_ExternalAPI_H */
+4
c/MC_Status_Reply_ExternalTypedefs.h
··· 1 + #ifndef WIRECTX_DEFINED 2 + #define WIRECTX_DEFINED 3 + typedef struct MC_Status_ReplyFields WIRECTX; 4 + #endif
+22
c/MC_Status_Reply_Fields.c
··· 1 + #include <stdint.h> 2 + #include "MC_Status_Reply_Fields.h" 3 + #include "MC_Status_Reply_ExternalTypedefs.h" 4 + #include "MC_Status_Reply_ExternalAPI.h" 5 + 6 + void McStatusReplySetU8(WIRECTX *ctx, uint32_t idx, uint8_t v) { 7 + MC_Status_ReplyFields *f = (MC_Status_ReplyFields *) ctx; 8 + switch (idx) { 9 + case 0: f->Operational = (uint32_t) v; break; 10 + default: (void) f; (void) v; break; 11 + } 12 + } 13 + 14 + void McStatusReplySetU16be(WIRECTX *ctx, uint32_t idx, uint16_t v) { 15 + MC_Status_ReplyFields *f = (MC_Status_ReplyFields *) ctx; 16 + switch (idx) { 17 + case 1: f->KeyCount = (uint16_t) v; break; 18 + case 2: f->SACount = (uint16_t) v; break; 19 + default: (void) f; (void) v; break; 20 + } 21 + } 22 +
+18
c/MC_Status_Reply_Fields.h
··· 1 + #ifndef MC_STATUS_REPLY_FIELDS_H 2 + #define MC_STATUS_REPLY_FIELDS_H 3 + #include <stdint.h> 4 + 5 + /* Field indices -- use with the schema's WireSet* callbacks in a 6 + custom [WIRECTX] if you only want to capture a subset. */ 7 + #define MC_STATUS_REPLY_IDX_OPERATIONAL 0 8 + #define MC_STATUS_REPLY_IDX_KEYCOUNT 1 9 + #define MC_STATUS_REPLY_IDX_SACOUNT 2 10 + 11 + /* Default plug: one typed member per named field. Pass a pointer to 12 + [MC_Status_ReplyFields] as [WIRECTX *] when you want every field populated. */ 13 + typedef struct MC_Status_ReplyFields { 14 + uint32_t Operational; 15 + uint16_t KeyCount; 16 + uint16_t SACount; 17 + } MC_Status_ReplyFields; 18 + #endif
+15 -3
c/dune.inc
··· 9 9 (rule 10 10 (alias gen) 11 11 (mode fallback) 12 - (targets EverParse.h EverParseEndianness.h EP_Header.h EP_Header.c MC_Status_Reply.h MC_Status_Reply.c test.c) 12 + (targets EverParse.h EverParseEndianness.h EP_Header.h EP_Header.c MC_Status_Reply.h MC_Status_Reply.c EP_Header_ExternalTypedefs.h EP_Header_ExternalAPI.h EP_HeaderWrapper.c EP_HeaderWrapper.h EP_Header_Fields.h EP_Header_Fields.c MC_Status_Reply_ExternalTypedefs.h MC_Status_Reply_ExternalAPI.h MC_Status_ReplyWrapper.c MC_Status_ReplyWrapper.h MC_Status_Reply_Fields.h MC_Status_Reply_Fields.c test.c) 13 13 (deps gen.exe EP_Header.3d MC_Status_Reply.3d) 14 14 (action 15 15 (run ./gen.exe c))) 16 16 17 17 (rule 18 18 (alias runtest) 19 - (deps test.c EverParse.h EverParseEndianness.h EP_Header.h EP_Header.c MC_Status_Reply.h MC_Status_Reply.c) 19 + (deps test.c EverParse.h EverParseEndianness.h EP_Header.h EP_Header.c MC_Status_Reply.h MC_Status_Reply.c EP_Header_ExternalTypedefs.h EP_Header_ExternalAPI.h EP_HeaderWrapper.c EP_HeaderWrapper.h EP_Header_Fields.h EP_Header_Fields.c MC_Status_Reply_ExternalTypedefs.h MC_Status_Reply_ExternalAPI.h MC_Status_ReplyWrapper.c MC_Status_ReplyWrapper.h MC_Status_Reply_Fields.h MC_Status_Reply_Fields.c) 20 20 (action 21 21 (system 22 - "cc -std=c11 -Wall -Wextra -Werror -o test_sdls test.c EP_Header.c MC_Status_Reply.c && ./test_sdls"))) 22 + "cc -std=c99 -Wall -Wextra -Werror -Wpedantic -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wcast-qual -o test_sdls test.c EP_Header.c MC_Status_Reply.c EP_Header_Fields.c MC_Status_Reply_Fields.c && ./test_sdls"))) 23 23 24 24 (install 25 25 (package sdls) ··· 31 31 (EP_Header.c as c/EP_Header.c) 32 32 (MC_Status_Reply.h as c/MC_Status_Reply.h) 33 33 (MC_Status_Reply.c as c/MC_Status_Reply.c) 34 + (EP_Header_ExternalTypedefs.h as c/EP_Header_ExternalTypedefs.h) 35 + (EP_Header_ExternalAPI.h as c/EP_Header_ExternalAPI.h) 36 + (EP_HeaderWrapper.c as c/EP_HeaderWrapper.c) 37 + (EP_HeaderWrapper.h as c/EP_HeaderWrapper.h) 38 + (EP_Header_Fields.h as c/EP_Header_Fields.h) 39 + (EP_Header_Fields.c as c/EP_Header_Fields.c) 40 + (MC_Status_Reply_ExternalTypedefs.h as c/MC_Status_Reply_ExternalTypedefs.h) 41 + (MC_Status_Reply_ExternalAPI.h as c/MC_Status_Reply_ExternalAPI.h) 42 + (MC_Status_ReplyWrapper.c as c/MC_Status_ReplyWrapper.c) 43 + (MC_Status_ReplyWrapper.h as c/MC_Status_ReplyWrapper.h) 44 + (MC_Status_Reply_Fields.h as c/MC_Status_Reply_Fields.h) 45 + (MC_Status_Reply_Fields.c as c/MC_Status_Reply_Fields.c) 34 46 (EverParse.h as c/EverParse.h) 35 47 (EverParseEndianness.h as c/EverParseEndianness.h)))
+127
c/test.c
··· 1 + #include <stdio.h> 2 + #include <stdlib.h> 3 + #include <stdint.h> 4 + #include <string.h> 5 + #include "EverParse.h" 6 + #include "EP_Header.h" 7 + #include "EP_Header_Fields.h" 8 + #include "MC_Status_Reply.h" 9 + #include "MC_Status_Reply_Fields.h" 10 + 11 + static int error_count; 12 + 13 + static void counting_error_handler( 14 + EVERPARSE_STRING t, EVERPARSE_STRING f, EVERPARSE_STRING r, 15 + uint64_t c, uint8_t *ctx, uint8_t *i, uint64_t p) { 16 + (void)t; (void)f; (void)r; (void)c; (void)ctx; (void)i; (void)p; 17 + error_count++; 18 + } 19 + 20 + #define CHECK(msg, cond) do { \ 21 + if (cond) { pass++; } \ 22 + else { fail++; fprintf(stderr, " FAIL: %s\n", msg); } \ 23 + } while(0) 24 + 25 + int main(void) { 26 + int failures = 0; 27 + 28 + /* EP_Header (3 bytes) */ 29 + { 30 + int pass = 0, fail = 0; 31 + uint8_t buf[3]; 32 + uint64_t r; 33 + EP_HeaderFields ctx = {0}; 34 + 35 + memset(buf, 0, 3); 36 + r = EpHeaderValidateEpHeader((WIRECTX *) &ctx, NULL, counting_error_handler, buf, 3, 0); 37 + if (!EverParseIsSuccess(r) || r != 3) { 38 + fprintf(stderr, 39 + "FATAL: EP_Header wire_size mismatch -- codec declared 3 bytes, " 40 + "EverParse validator returned %llu. Fix the OCaml codec's " 41 + "wire_size or the .3d projection.\n", 42 + (unsigned long long) r); 43 + return 2; 44 + } 45 + CHECK("zero buffer validates", EverParseIsSuccess(r)); 46 + CHECK("position advanced to 3", r == 3); 47 + 48 + r = EpHeaderValidateEpHeader((WIRECTX *) &ctx, NULL, counting_error_handler, buf, 6, 0); 49 + CHECK("larger buffer validates", EverParseIsSuccess(r)); 50 + CHECK("position is 3 not 6", r == 3); 51 + 52 + for (uint64_t len = 0; len < 3; len++) { 53 + error_count = 0; 54 + r = EpHeaderValidateEpHeader((WIRECTX *) &ctx, NULL, counting_error_handler, buf, len, 0); 55 + CHECK("truncated to len fails", EverParseIsError(r)); 56 + } 57 + 58 + r = EpHeaderValidateEpHeader((WIRECTX *) &ctx, NULL, counting_error_handler, buf, 0, 0); 59 + CHECK("empty input fails", EverParseIsError(r)); 60 + 61 + srand(42); 62 + for (int i = 0; i < 1000; i++) { 63 + for (int j = 0; j < 3; j++) 64 + buf[j] = (uint8_t)(rand() & 0xff); 65 + r = EpHeaderValidateEpHeader((WIRECTX *) &ctx, NULL, counting_error_handler, buf, 3, 0); 66 + CHECK("random buffer validates", EverParseIsSuccess(r)); 67 + CHECK("random position correct", r == 3); 68 + } 69 + 70 + (void) ctx; 71 + printf("ep_header: %d passed, %d failed\n", pass, fail); 72 + failures += fail; 73 + } 74 + 75 + /* MC_Status_Reply (5 bytes) */ 76 + { 77 + int pass = 0, fail = 0; 78 + uint8_t buf[5]; 79 + uint64_t r; 80 + MC_Status_ReplyFields ctx = {0}; 81 + 82 + memset(buf, 0, 5); 83 + r = McStatusReplyValidateMcStatusReply((WIRECTX *) &ctx, NULL, counting_error_handler, buf, 5, 0); 84 + if (!EverParseIsSuccess(r) || r != 5) { 85 + fprintf(stderr, 86 + "FATAL: MC_Status_Reply wire_size mismatch -- codec declared 5 bytes, " 87 + "EverParse validator returned %llu. Fix the OCaml codec's " 88 + "wire_size or the .3d projection.\n", 89 + (unsigned long long) r); 90 + return 2; 91 + } 92 + CHECK("zero buffer validates", EverParseIsSuccess(r)); 93 + CHECK("position advanced to 5", r == 5); 94 + 95 + r = McStatusReplyValidateMcStatusReply((WIRECTX *) &ctx, NULL, counting_error_handler, buf, 10, 0); 96 + CHECK("larger buffer validates", EverParseIsSuccess(r)); 97 + CHECK("position is 5 not 10", r == 5); 98 + 99 + for (uint64_t len = 0; len < 5; len++) { 100 + error_count = 0; 101 + r = McStatusReplyValidateMcStatusReply((WIRECTX *) &ctx, NULL, counting_error_handler, buf, len, 0); 102 + CHECK("truncated to len fails", EverParseIsError(r)); 103 + } 104 + 105 + r = McStatusReplyValidateMcStatusReply((WIRECTX *) &ctx, NULL, counting_error_handler, buf, 0, 0); 106 + CHECK("empty input fails", EverParseIsError(r)); 107 + 108 + srand(42); 109 + for (int i = 0; i < 1000; i++) { 110 + for (int j = 0; j < 5; j++) 111 + buf[j] = (uint8_t)(rand() & 0xff); 112 + r = McStatusReplyValidateMcStatusReply((WIRECTX *) &ctx, NULL, counting_error_handler, buf, 5, 0); 113 + CHECK("random buffer validates", EverParseIsSuccess(r)); 114 + CHECK("random position correct", r == 5); 115 + } 116 + 117 + (void) ctx; 118 + printf("mc_status_reply: %d passed, %d failed\n", pass, fail); 119 + failures += fail; 120 + } 121 + 122 + if (failures == 0) 123 + printf("All tests passed.\n"); 124 + else 125 + printf("%d test(s) failed.\n", failures); 126 + return failures ? 1 : 0; 127 + }