6 #include "pixman-private.h" /* For 'inline' definition */
7 #include "utils-prng.h"
10 #define snprintf _snprintf
11 #define strcasecmp _stricmp
14 #define ARRAY_LENGTH(A) ((int) (sizeof (A) / sizeof ((A) [0])))
16 /* A primitive pseudorandom number generator,
17 * taken from POSIX.1-2001 example
20 extern prng_t prng_state_data;
21 extern prng_t *prng_state;
23 #pragma omp threadprivate(prng_state_data)
24 #pragma omp threadprivate(prng_state)
27 static inline uint32_t
30 return prng_rand_r (prng_state);
34 prng_srand (uint32_t seed)
38 /* Without setting a seed, PRNG does not work properly (is just
39 * returning zeros). So we only initialize the pointer here to
40 * make sure that 'prng_srand' is always called before any
41 * other 'prng_*' function. The wrongdoers violating this order
42 * will get a segfault. */
43 prng_state = &prng_state_data;
45 prng_srand_r (prng_state, seed);
48 static inline uint32_t
51 return prng_rand () % max;
55 prng_randmemset (void *buffer, size_t size, prng_randmemset_flags_t flags)
57 prng_randmemset_r (prng_state, buffer, size, flags);
63 compute_crc32 (uint32_t in_crc32,
68 compute_crc32_for_image (uint32_t in_crc32,
69 pixman_image_t *image);
71 /* Print the image in hexadecimal */
73 print_image (pixman_image_t *image);
75 /* Returns TRUE if running on a little endian system
77 static force_inline pixman_bool_t
78 is_little_endian (void)
80 unsigned long endian_check_var = 1;
81 return *(unsigned char *)&endian_check_var == 1;
84 /* perform endian conversion of pixel data
87 image_endian_swap (pixman_image_t *img);
89 /* Allocate memory that is bounded by protected pages,
90 * so that out-of-bounds access will cause segfaults
93 fence_malloc (int64_t len);
96 fence_free (void *data);
98 /* Generate n_bytes random bytes in fence_malloced memory */
100 make_random_bytes (int n_bytes);
102 /* Return current time in seconds */
107 get_random_seed (void);
109 /* main body of the fuzzer test */
111 fuzzer_test_main (const char *test_name,
112 int default_number_of_iterations,
113 uint32_t expected_checksum,
114 uint32_t (*test_function)(int testnum, int verbose),
119 fail_after (int seconds, const char *msg);
121 /* If possible, enable traps for floating point exceptions */
122 void enable_divbyzero_exceptions(void);
124 /* Converts a8r8g8b8 pixels to pixels that
125 * - are not premultiplied,
126 * - are stored in this order in memory: R, G, B, A, regardless of
127 * the endianness of the computer.
128 * It is allowed for @src and @dst to point to the same memory buffer.
131 a8r8g8b8_to_rgba_np (uint32_t *dst, uint32_t *src, int n_pixels);
134 write_png (pixman_image_t *image, const char *filename);
137 draw_checkerboard (pixman_image_t *image,
139 uint32_t color1, uint32_t color2);
141 /* A pair of macros which can help to detect corruption of
142 * floating point registers after a function call. This may
143 * happen if _mm_empty() call is forgotten in MMX/SSE2 fast
144 * path code, or ARM NEON assembly optimized function forgets
145 * to save/restore d8-d15 registers before use.
148 #define FLOAT_REGS_CORRUPTION_DETECTOR_START() \
149 static volatile double frcd_volatile_constant1 = 123451; \
150 static volatile double frcd_volatile_constant2 = 123452; \
151 static volatile double frcd_volatile_constant3 = 123453; \
152 static volatile double frcd_volatile_constant4 = 123454; \
153 static volatile double frcd_volatile_constant5 = 123455; \
154 static volatile double frcd_volatile_constant6 = 123456; \
155 static volatile double frcd_volatile_constant7 = 123457; \
156 static volatile double frcd_volatile_constant8 = 123458; \
157 double frcd_canary_variable1 = frcd_volatile_constant1; \
158 double frcd_canary_variable2 = frcd_volatile_constant2; \
159 double frcd_canary_variable3 = frcd_volatile_constant3; \
160 double frcd_canary_variable4 = frcd_volatile_constant4; \
161 double frcd_canary_variable5 = frcd_volatile_constant5; \
162 double frcd_canary_variable6 = frcd_volatile_constant6; \
163 double frcd_canary_variable7 = frcd_volatile_constant7; \
164 double frcd_canary_variable8 = frcd_volatile_constant8;
166 #define FLOAT_REGS_CORRUPTION_DETECTOR_FINISH() \
167 assert (frcd_canary_variable1 == frcd_volatile_constant1); \
168 assert (frcd_canary_variable2 == frcd_volatile_constant2); \
169 assert (frcd_canary_variable3 == frcd_volatile_constant3); \
170 assert (frcd_canary_variable4 == frcd_volatile_constant4); \
171 assert (frcd_canary_variable5 == frcd_volatile_constant5); \
172 assert (frcd_canary_variable6 == frcd_volatile_constant6); \
173 assert (frcd_canary_variable7 == frcd_volatile_constant7); \
174 assert (frcd_canary_variable8 == frcd_volatile_constant8);
176 /* Try to get an aligned memory chunk */
178 aligned_malloc (size_t align, size_t size);
181 convert_srgb_to_linear (double component);
184 convert_linear_to_srgb (double component);
187 initialize_palette (pixman_indexed_t *palette, uint32_t depth, int is_rgb);
190 operator_name (pixman_op_t op);
193 format_name (pixman_format_code_t format);
201 do_composite (pixman_op_t op,
206 pixman_bool_t component_alpha);
209 round_color (pixman_format_code_t format, color_t *color);
213 pixman_format_code_t format;
214 uint32_t am, rm, gm, bm;
215 uint32_t as, rs, gs, bs;
216 uint32_t aw, rw, gw, bw;
220 pixel_checker_init (pixel_checker_t *checker, pixman_format_code_t format);
223 pixel_checker_split_pixel (const pixel_checker_t *checker, uint32_t pixel,
224 int *a, int *r, int *g, int *b);
227 pixel_checker_get_max (const pixel_checker_t *checker, color_t *color,
228 int *a, int *r, int *g, int *b);
231 pixel_checker_get_min (const pixel_checker_t *checker, color_t *color,
232 int *a, int *r, int *g, int *b);
235 pixel_checker_check (const pixel_checker_t *checker,
236 uint32_t pixel, color_t *color);
239 pixel_checker_convert_pixel_to_color (const pixel_checker_t *checker,
240 uint32_t pixel, color_t *color);
243 pixel_checker_get_masks (const pixel_checker_t *checker,