infix
A JIT-Powered FFI Library for C
Loading...
Searching...
No Matches
fuzz_helpers.h
Go to the documentation of this file.
1#pragma once
36#include <infix/infix.h>
37#include <stdbool.h>
38#include <stddef.h>
39#include <stdint.h>
40#include <stdio.h>
41#include <stdlib.h>
42#include <string.h>
43
45#define MAX_RECURSION_DEPTH 32
47#define MAX_MEMBERS 16
49#define MAX_ARRAY_ELEMENTS 128
51#define MAX_TYPES_IN_POOL 16
53#define MAX_ARGS_IN_SIGNATURE 16
56#define MAX_TOTAL_FUZZ_FIELDS 256
57
62typedef struct {
63 const uint8_t * data;
64 size_t size;
66
79static inline const uint8_t * consume_bytes(fuzzer_input * in, size_t n) {
80 if (in->size < n)
81 return NULL;
82 const uint8_t * ptr = in->data;
83 in->data += n;
84 in->size -= n;
85 return ptr;
86}
87
96#define DEFINE_CONSUME_T(type) \
97 static inline bool consume_##type(fuzzer_input * in, type * out) { \
98 const uint8_t * bytes = consume_bytes(in, sizeof(type)); \
99 if (!bytes) \
100 return false; \
101 memcpy(out, bytes, sizeof(type)); \
102 return true; \
103 }
104
105// Generate consumer functions for common types used in the fuzzers.
106DEFINE_CONSUME_T(uint8_t)
107DEFINE_CONSUME_T(size_t)
108
109
121infix_type * generate_random_type(infix_arena_t * arena, fuzzer_input * in, int depth, size_t * total_fields);
infix_arena_t * arena
Definition 005_layouts.c:68
#define DEFINE_CONSUME_T(type)
Definition fuzz_helpers.h:96
infix_type * generate_random_type(infix_arena_t *arena, fuzzer_input *in, int depth, size_t *total_fields)
Recursively generates a random infix_type graph from a fuzzer input stream.
Definition fuzz_helpers.c:55
static const uint8_t * consume_bytes(fuzzer_input *in, size_t n)
Definition fuzz_helpers.h:79
The public interface for the infix FFI library.
Internal data structures, function prototypes, and constants.
Represents the fuzzer's input data as a consumable stream.
Definition fuzz_helpers.h:62
size_t size
Definition fuzz_helpers.h:64
const uint8_t * data
Definition fuzz_helpers.h:63
Internal definition of a memory arena.
Definition infix_internals.h:146
A semi-opaque structure that describes a C type.
Definition infix.h:211