1 /* 2 * Copyright (c) 2015-2020, Intel Corporation 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * 7 * * Redistributions of source code must retain the above copyright notice, 8 * this list of conditions and the following disclaimer. 9 * * Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * * Neither the name of Intel Corporation nor the names of its contributors 13 * may be used to endorse or promote products derived from this software 14 * without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #ifndef HS_COMPILE_H_ 30 #define HS_COMPILE_H_ 31 32 /** 33 * @file 34 * @brief The Hyperscan compiler API definition. 35 * 36 * Hyperscan is a high speed regular expression engine. 37 * 38 * This header contains functions for compiling regular expressions into 39 * Hyperscan databases that can be used by the Hyperscan runtime. 40 */ 41 42 #include "hs_common.h" 43 44 #ifdef __cplusplus 45 extern "C" 46 { 47 #endif 48 49 /** 50 * A type containing error details that is returned by the compile calls (@ref 51 * hs_compile(), @ref hs_compile_multi() and @ref hs_compile_ext_multi()) on 52 * failure. The caller may inspect the values returned in this type to 53 * determine the cause of failure. 54 * 55 * Common errors generated during the compile process include: 56 * 57 * - *Invalid parameter* 58 * 59 * An invalid argument was specified in the compile call. 60 * 61 * - *Unrecognised flag* 62 * 63 * An unrecognised value was passed in the flags argument. 64 * 65 * - *Pattern matches empty buffer* 66 * 67 * By default, Hyperscan only supports patterns that will *always* 68 * consume at least one byte of input. Patterns that do not have this 69 * property (such as `/(abc)?/`) will produce this error unless 70 * the @ref HS_FLAG_ALLOWEMPTY flag is supplied. Note that such 71 * patterns will produce a match for *every* byte when scanned. 72 * 73 * - *Embedded anchors not supported* 74 * 75 * Hyperscan only supports the use of anchor meta-characters (such as 76 * `^` and `$`) in patterns where they could *only* match 77 * at the start or end of a buffer. A pattern containing an embedded 78 * anchor, such as `/abc^def/`, can never match, as there is no 79 * way for `abc` to precede the start of the data stream. 80 * 81 * - *Bounded repeat is too large* 82 * 83 * The pattern contains a repeated construct with very large finite 84 * bounds. 85 * 86 * - *Unsupported component type* 87 * 88 * An unsupported PCRE construct was used in the pattern. 89 * 90 * - *Unable to generate bytecode* 91 * 92 * This error indicates that Hyperscan was unable to compile a pattern 93 * that is syntactically valid. The most common cause is a pattern that is 94 * very long and complex or contains a large repeated subpattern. 95 * 96 * - *Unable to allocate memory* 97 * 98 * The library was unable to allocate temporary storage used during 99 * compilation time. 100 * 101 * - *Allocator returned misaligned memory* 102 * 103 * The memory allocator (either malloc() or the allocator set with @ref 104 * hs_set_allocator()) did not correctly return memory suitably aligned 105 * for the largest representable data type on this platform. 106 * 107 * - *Internal error* 108 * 109 * An unexpected error occurred: if this error is reported, please contact 110 * the Hyperscan team with a description of the situation. 111 */ 112 typedef struct hs_compile_error { 113 /** 114 * A human-readable error message describing the error. 115 */ 116 char *message; 117 118 /** 119 * The zero-based number of the expression that caused the error (if this 120 * can be determined). If the error is not specific to an expression, then 121 * this value will be less than zero. 122 */ 123 int expression; 124 } hs_compile_error_t; 125 126 /** 127 * A type containing information on the target platform which may optionally be 128 * provided to the compile calls (@ref hs_compile(), @ref hs_compile_multi(), 129 * @ref hs_compile_ext_multi()). 130 * 131 * A hs_platform_info structure may be populated for the current platform by 132 * using the @ref hs_populate_platform() call. 133 */ 134 typedef struct hs_platform_info { 135 /** 136 * Information about the target platform which may be used to guide the 137 * optimisation process of the compile. 138 * 139 * Use of this field does not limit the processors that the resulting 140 * database can run on, but may impact the performance of the resulting 141 * database. 142 */ 143 unsigned int tune; 144 145 /** 146 * Relevant CPU features available on the target platform 147 * 148 * This value may be produced by combining HS_CPU_FEATURE_* flags (such as 149 * @ref HS_CPU_FEATURES_AVX2). Multiple CPU features may be or'ed together 150 * to produce the value. 151 */ 152 unsigned long long cpu_features; 153 154 /** 155 * Reserved for future use. 156 */ 157 unsigned long long reserved1; 158 159 /** 160 * Reserved for future use. 161 */ 162 unsigned long long reserved2; 163 } hs_platform_info_t; 164 165 /** 166 * A type containing information related to an expression that is returned by 167 * @ref hs_expression_info() or @ref hs_expression_ext_info. 168 */ 169 typedef struct hs_expr_info { 170 /** 171 * The minimum length in bytes of a match for the pattern. 172 * 173 * Note: in some cases when using advanced features to suppress matches 174 * (such as extended parameters or the @ref HS_FLAG_SINGLEMATCH flag) this 175 * may represent a conservative lower bound for the true minimum length of 176 * a match. 177 */ 178 unsigned int min_width; 179 180 /** 181 * The maximum length in bytes of a match for the pattern. If the pattern 182 * has an unbounded maximum length, this will be set to the maximum value 183 * of an unsigned int (UINT_MAX). 184 * 185 * Note: in some cases when using advanced features to suppress matches 186 * (such as extended parameters or the @ref HS_FLAG_SINGLEMATCH flag) this 187 * may represent a conservative upper bound for the true maximum length of 188 * a match. 189 */ 190 unsigned int max_width; 191 192 /** 193 * Whether this expression can produce matches that are not returned in 194 * order, such as those produced by assertions. Zero if false, non-zero if 195 * true. 196 */ 197 char unordered_matches; 198 199 /** 200 * Whether this expression can produce matches at end of data (EOD). In 201 * streaming mode, EOD matches are raised during @ref hs_close_stream(), 202 * since it is only when @ref hs_close_stream() is called that the EOD 203 * location is known. Zero if false, non-zero if true. 204 * 205 * Note: trailing `\b` word boundary assertions may also result in EOD 206 * matches as end-of-data can act as a word boundary. 207 */ 208 char matches_at_eod; 209 210 /** 211 * Whether this expression can *only* produce matches at end of data (EOD). 212 * In streaming mode, all matches for this expression are raised during 213 * @ref hs_close_stream(). Zero if false, non-zero if true. 214 */ 215 char matches_only_at_eod; 216 } hs_expr_info_t; 217 218 /** 219 * A structure containing additional parameters related to an expression, 220 * passed in at build time to @ref hs_compile_ext_multi() or @ref 221 * hs_expression_ext_info. 222 * 223 * These parameters allow the set of matches produced by a pattern to be 224 * constrained at compile time, rather than relying on the application to 225 * process unwanted matches at runtime. 226 */ 227 typedef struct hs_expr_ext { 228 /** 229 * Flags governing which parts of this structure are to be used by the 230 * compiler. See @ref HS_EXT_FLAG. 231 */ 232 unsigned long long flags; 233 234 /** 235 * The minimum end offset in the data stream at which this expression 236 * should match successfully. To use this parameter, set the 237 * @ref HS_EXT_FLAG_MIN_OFFSET flag in the hs_expr_ext::flags field. 238 */ 239 unsigned long long min_offset; 240 241 /** 242 * The maximum end offset in the data stream at which this expression 243 * should match successfully. To use this parameter, set the 244 * @ref HS_EXT_FLAG_MAX_OFFSET flag in the hs_expr_ext::flags field. 245 */ 246 unsigned long long max_offset; 247 248 /** 249 * The minimum match length (from start to end) required to successfully 250 * match this expression. To use this parameter, set the 251 * @ref HS_EXT_FLAG_MIN_LENGTH flag in the hs_expr_ext::flags field. 252 */ 253 unsigned long long min_length; 254 255 /** 256 * Allow patterns to approximately match within this edit distance. To use 257 * this parameter, set the @ref HS_EXT_FLAG_EDIT_DISTANCE flag in the 258 * hs_expr_ext::flags field. 259 */ 260 unsigned edit_distance; 261 262 /** 263 * Allow patterns to approximately match within this Hamming distance. To 264 * use this parameter, set the @ref HS_EXT_FLAG_HAMMING_DISTANCE flag in the 265 * hs_expr_ext::flags field. 266 */ 267 unsigned hamming_distance; 268 } hs_expr_ext_t; 269 270 /** 271 * @defgroup HS_EXT_FLAG hs_expr_ext_t flags 272 * 273 * These flags are used in @ref hs_expr_ext_t::flags to indicate which fields 274 * are used. 275 * 276 * @{ 277 */ 278 279 /** Flag indicating that the hs_expr_ext::min_offset field is used. */ 280 #define HS_EXT_FLAG_MIN_OFFSET 1ULL 281 282 /** Flag indicating that the hs_expr_ext::max_offset field is used. */ 283 #define HS_EXT_FLAG_MAX_OFFSET 2ULL 284 285 /** Flag indicating that the hs_expr_ext::min_length field is used. */ 286 #define HS_EXT_FLAG_MIN_LENGTH 4ULL 287 288 /** Flag indicating that the hs_expr_ext::edit_distance field is used. */ 289 #define HS_EXT_FLAG_EDIT_DISTANCE 8ULL 290 291 /** Flag indicating that the hs_expr_ext::hamming_distance field is used. */ 292 #define HS_EXT_FLAG_HAMMING_DISTANCE 16ULL 293 294 /** @} */ 295 296 /** 297 * The basic regular expression compiler. 298 * 299 * This is the function call with which an expression is compiled into a 300 * Hyperscan database which can be passed to the runtime functions (such as 301 * @ref hs_scan(), @ref hs_open_stream(), etc.) 302 * 303 * @param expression 304 * The NULL-terminated expression to parse. Note that this string must 305 * represent ONLY the pattern to be matched, with no delimiters or flags; 306 * any global flags should be specified with the @p flags argument. For 307 * example, the expression `/abc?def/i` should be compiled by providing 308 * `abc?def` as the @p expression, and @ref HS_FLAG_CASELESS as the @a 309 * flags. 310 * 311 * @param flags 312 * Flags which modify the behaviour of the expression. Multiple flags may 313 * be used by ORing them together. Valid values are: 314 * - HS_FLAG_CASELESS - Matching will be performed case-insensitively. 315 * - HS_FLAG_DOTALL - Matching a `.` will not exclude newlines. 316 * - HS_FLAG_MULTILINE - `^` and `$` anchors match any newlines in data. 317 * - HS_FLAG_SINGLEMATCH - Only one match will be generated for the 318 * expression per stream. 319 * - HS_FLAG_ALLOWEMPTY - Allow expressions which can match against an 320 * empty string, such as `.*`. 321 * - HS_FLAG_UTF8 - Treat this pattern as a sequence of UTF-8 characters. 322 * - HS_FLAG_UCP - Use Unicode properties for character classes. 323 * - HS_FLAG_PREFILTER - Compile pattern in prefiltering mode. 324 * - HS_FLAG_SOM_LEFTMOST - Report the leftmost start of match offset 325 * when a match is found. 326 * - HS_FLAG_COMBINATION - Parse the expression in logical combination 327 * syntax. 328 * - HS_FLAG_QUIET - Ignore match reporting for this expression. Used for 329 * the sub-expressions in logical combinations. 330 * 331 * @param mode 332 * Compiler mode flags that affect the database as a whole. One of @ref 333 * HS_MODE_STREAM or @ref HS_MODE_BLOCK or @ref HS_MODE_VECTORED must be 334 * supplied, to select between the generation of a streaming, block or 335 * vectored database. In addition, other flags (beginning with HS_MODE_) 336 * may be supplied to enable specific features. See @ref HS_MODE_FLAG for 337 * more details. 338 * 339 * @param platform 340 * If not NULL, the platform structure is used to determine the target 341 * platform for the database. If NULL, a database suitable for running 342 * on the current host platform is produced. 343 * 344 * @param db 345 * On success, a pointer to the generated database will be returned in 346 * this parameter, or NULL on failure. The caller is responsible for 347 * deallocating the buffer using the @ref hs_free_database() function. 348 * 349 * @param error 350 * If the compile fails, a pointer to a @ref hs_compile_error_t will be 351 * returned, providing details of the error condition. The caller is 352 * responsible for deallocating the buffer using the @ref 353 * hs_free_compile_error() function. 354 * 355 * @return 356 * @ref HS_SUCCESS is returned on successful compilation; @ref 357 * HS_COMPILER_ERROR on failure, with details provided in the error 358 * parameter. 359 */ 360 hs_error_t HS_CDECL hs_compile(const char *expression, unsigned int flags, 361 unsigned int mode, 362 const hs_platform_info_t *platform, 363 hs_database_t **db, hs_compile_error_t **error); 364 365 /** 366 * The multiple regular expression compiler. 367 * 368 * This is the function call with which a set of expressions is compiled into a 369 * database which can be passed to the runtime functions (such as @ref 370 * hs_scan(), @ref hs_open_stream(), etc.) Each expression can be labelled with 371 * a unique integer which is passed into the match callback to identify the 372 * pattern that has matched. 373 * 374 * @param expressions 375 * Array of NULL-terminated expressions to compile. Note that (as for @ref 376 * hs_compile()) these strings must contain only the pattern to be 377 * matched, with no delimiters or flags. For example, the expression 378 * `/abc?def/i` should be compiled by providing `abc?def` as the first 379 * string in the @p expressions array, and @ref HS_FLAG_CASELESS as the 380 * first value in the @p flags array. 381 * 382 * @param flags 383 * Array of flags which modify the behaviour of each expression. Multiple 384 * flags may be used by ORing them together. Specifying the NULL pointer 385 * in place of an array will set the flags value for all patterns to zero. 386 * Valid values are: 387 * - HS_FLAG_CASELESS - Matching will be performed case-insensitively. 388 * - HS_FLAG_DOTALL - Matching a `.` will not exclude newlines. 389 * - HS_FLAG_MULTILINE - `^` and `$` anchors match any newlines in data. 390 * - HS_FLAG_SINGLEMATCH - Only one match will be generated by patterns 391 * with this match id per stream. 392 * - HS_FLAG_ALLOWEMPTY - Allow expressions which can match against an 393 * empty string, such as `.*`. 394 * - HS_FLAG_UTF8 - Treat this pattern as a sequence of UTF-8 characters. 395 * - HS_FLAG_UCP - Use Unicode properties for character classes. 396 * - HS_FLAG_PREFILTER - Compile pattern in prefiltering mode. 397 * - HS_FLAG_SOM_LEFTMOST - Report the leftmost start of match offset 398 * when a match is found. 399 * - HS_FLAG_COMBINATION - Parse the expression in logical combination 400 * syntax. 401 * - HS_FLAG_QUIET - Ignore match reporting for this expression. Used for 402 * the sub-expressions in logical combinations. 403 * 404 * @param ids 405 * An array of integers specifying the ID number to be associated with the 406 * corresponding pattern in the expressions array. Specifying the NULL 407 * pointer in place of an array will set the ID value for all patterns to 408 * zero. 409 * 410 * @param elements 411 * The number of elements in the input arrays. 412 * 413 * @param mode 414 * Compiler mode flags that affect the database as a whole. One of @ref 415 * HS_MODE_STREAM or @ref HS_MODE_BLOCK or @ref HS_MODE_VECTORED must be 416 * supplied, to select between the generation of a streaming, block or 417 * vectored database. In addition, other flags (beginning with HS_MODE_) 418 * may be supplied to enable specific features. See @ref HS_MODE_FLAG for 419 * more details. 420 * 421 * @param platform 422 * If not NULL, the platform structure is used to determine the target 423 * platform for the database. If NULL, a database suitable for running 424 * on the current host platform is produced. 425 * 426 * @param db 427 * On success, a pointer to the generated database will be returned in 428 * this parameter, or NULL on failure. The caller is responsible for 429 * deallocating the buffer using the @ref hs_free_database() function. 430 * 431 * @param error 432 * If the compile fails, a pointer to a @ref hs_compile_error_t will be 433 * returned, providing details of the error condition. The caller is 434 * responsible for deallocating the buffer using the @ref 435 * hs_free_compile_error() function. 436 * 437 * @return 438 * @ref HS_SUCCESS is returned on successful compilation; @ref 439 * HS_COMPILER_ERROR on failure, with details provided in the @p error 440 * parameter. 441 * 442 */ 443 hs_error_t HS_CDECL hs_compile_multi(const char *const *expressions, 444 const unsigned int *flags, 445 const unsigned int *ids, 446 unsigned int elements, unsigned int mode, 447 const hs_platform_info_t *platform, 448 hs_database_t **db, 449 hs_compile_error_t **error); 450 451 /** 452 * The multiple regular expression compiler with extended parameter support. 453 * 454 * This function call compiles a group of expressions into a database in the 455 * same way as @ref hs_compile_multi(), but allows additional parameters to be 456 * specified via an @ref hs_expr_ext_t structure per expression. 457 * 458 * @param expressions 459 * Array of NULL-terminated expressions to compile. Note that (as for @ref 460 * hs_compile()) these strings must contain only the pattern to be 461 * matched, with no delimiters or flags. For example, the expression 462 * `/abc?def/i` should be compiled by providing `abc?def` as the first 463 * string in the @p expressions array, and @ref HS_FLAG_CASELESS as the 464 * first value in the @p flags array. 465 * 466 * @param flags 467 * Array of flags which modify the behaviour of each expression. Multiple 468 * flags may be used by ORing them together. Specifying the NULL pointer 469 * in place of an array will set the flags value for all patterns to zero. 470 * Valid values are: 471 * - HS_FLAG_CASELESS - Matching will be performed case-insensitively. 472 * - HS_FLAG_DOTALL - Matching a `.` will not exclude newlines. 473 * - HS_FLAG_MULTILINE - `^` and `$` anchors match any newlines in data. 474 * - HS_FLAG_SINGLEMATCH - Only one match will be generated by patterns 475 * with this match id per stream. 476 * - HS_FLAG_ALLOWEMPTY - Allow expressions which can match against an 477 * empty string, such as `.*`. 478 * - HS_FLAG_UTF8 - Treat this pattern as a sequence of UTF-8 characters. 479 * - HS_FLAG_UCP - Use Unicode properties for character classes. 480 * - HS_FLAG_PREFILTER - Compile pattern in prefiltering mode. 481 * - HS_FLAG_SOM_LEFTMOST - Report the leftmost start of match offset 482 * when a match is found. 483 * - HS_FLAG_COMBINATION - Parse the expression in logical combination 484 * syntax. 485 * - HS_FLAG_QUIET - Ignore match reporting for this expression. Used for 486 * the sub-expressions in logical combinations. 487 * 488 * @param ids 489 * An array of integers specifying the ID number to be associated with the 490 * corresponding pattern in the expressions array. Specifying the NULL 491 * pointer in place of an array will set the ID value for all patterns to 492 * zero. 493 * 494 * @param ext 495 * An array of pointers to filled @ref hs_expr_ext_t structures that 496 * define extended behaviour for each pattern. NULL may be specified if no 497 * extended behaviour is needed for an individual pattern, or in place of 498 * the whole array if it is not needed for any expressions. Memory used by 499 * these structures must be both allocated and freed by the caller. 500 * 501 * @param elements 502 * The number of elements in the input arrays. 503 * 504 * @param mode 505 * Compiler mode flags that affect the database as a whole. One of @ref 506 * HS_MODE_STREAM, @ref HS_MODE_BLOCK or @ref HS_MODE_VECTORED must be 507 * supplied, to select between the generation of a streaming, block or 508 * vectored database. In addition, other flags (beginning with HS_MODE_) 509 * may be supplied to enable specific features. See @ref HS_MODE_FLAG for 510 * more details. 511 * 512 * @param platform 513 * If not NULL, the platform structure is used to determine the target 514 * platform for the database. If NULL, a database suitable for running 515 * on the current host platform is produced. 516 * 517 * @param db 518 * On success, a pointer to the generated database will be returned in 519 * this parameter, or NULL on failure. The caller is responsible for 520 * deallocating the buffer using the @ref hs_free_database() function. 521 * 522 * @param error 523 * If the compile fails, a pointer to a @ref hs_compile_error_t will be 524 * returned, providing details of the error condition. The caller is 525 * responsible for deallocating the buffer using the @ref 526 * hs_free_compile_error() function. 527 * 528 * @return 529 * @ref HS_SUCCESS is returned on successful compilation; @ref 530 * HS_COMPILER_ERROR on failure, with details provided in the @p error 531 * parameter. 532 * 533 */ 534 hs_error_t HS_CDECL hs_compile_ext_multi(const char *const *expressions, 535 const unsigned int *flags, 536 const unsigned int *ids, 537 const hs_expr_ext_t *const *ext, 538 unsigned int elements, unsigned int mode, 539 const hs_platform_info_t *platform, 540 hs_database_t **db, hs_compile_error_t **error); 541 542 /** 543 * The basic pure literal expression compiler. 544 * 545 * This is the function call with which a pure literal expression (not a 546 * common regular expression) is compiled into a Hyperscan database which 547 * can be passed to the runtime functions (such as @ref hs_scan(), 548 * @ref hs_open_stream(), etc.) 549 * 550 * @param expression 551 * The NULL-terminated expression to parse. Note that this string must 552 * represent ONLY the pattern to be matched, with no delimiters or flags; 553 * any global flags should be specified with the @p flags argument. For 554 * example, the expression `/abc?def/i` should be compiled by providing 555 * `abc?def` as the @p expression, and @ref HS_FLAG_CASELESS as the @a 556 * flags. Meanwhile, the string content shall be fully parsed in a literal 557 * sense without any regular grammars. For example, the @p expression 558 * `abc?` simply means a char sequence of `a`, `b`, `c`, and `?`. The `?` 559 * here doesn't mean 0 or 1 quantifier under regular semantics. 560 * 561 * @param flags 562 * Flags which modify the behaviour of the expression. Multiple flags may 563 * be used by ORing them together. Compared to @ref hs_compile(), fewer 564 * valid values are provided: 565 * - HS_FLAG_CASELESS - Matching will be performed case-insensitively. 566 * - HS_FLAG_SINGLEMATCH - Only one match will be generated for the 567 * expression per stream. 568 * - HS_FLAG_SOM_LEFTMOST - Report the leftmost start of match offset 569 * when a match is found. 570 * 571 * @param len 572 * The length of the text content of the pure literal expression. As the 573 * text content indicated by @p expression is treated as single character 574 * one by one, the special terminating character `\0` should be allowed 575 * to appear in expression, and not treated as a terminator for a string. 576 * Thus, the end of a pure literal expression cannot be indicated by 577 * identifying `\0`, but by counting to the expression length. 578 * 579 * @param mode 580 * Compiler mode flags that affect the database as a whole. One of @ref 581 * HS_MODE_STREAM or @ref HS_MODE_BLOCK or @ref HS_MODE_VECTORED must be 582 * supplied, to select between the generation of a streaming, block or 583 * vectored database. In addition, other flags (beginning with HS_MODE_) 584 * may be supplied to enable specific features. See @ref HS_MODE_FLAG for 585 * more details. 586 * 587 * @param platform 588 * If not NULL, the platform structure is used to determine the target 589 * platform for the database. If NULL, a database suitable for running 590 * on the current host platform is produced. 591 * 592 * @param db 593 * On success, a pointer to the generated database will be returned in 594 * this parameter, or NULL on failure. The caller is responsible for 595 * deallocating the buffer using the @ref hs_free_database() function. 596 * 597 * @param error 598 * If the compile fails, a pointer to a @ref hs_compile_error_t will be 599 * returned, providing details of the error condition. The caller is 600 * responsible for deallocating the buffer using the @ref 601 * hs_free_compile_error() function. 602 * 603 * @return 604 * @ref HS_SUCCESS is returned on successful compilation; @ref 605 * HS_COMPILER_ERROR on failure, with details provided in the error 606 * parameter. 607 */ 608 hs_error_t HS_CDECL hs_compile_lit(const char *expression, unsigned flags, 609 const size_t len, unsigned mode, 610 const hs_platform_info_t *platform, 611 hs_database_t **db, 612 hs_compile_error_t **error); 613 /** 614 * The multiple pure literal expression compiler. 615 * 616 * This is the function call with which a set of pure literal expressions is 617 * compiled into a database which can be passed to the runtime functions (such 618 * as @ref hs_scan(), @ref hs_open_stream(), etc.) Each expression can be 619 * labelled with a unique integer which is passed into the match callback to 620 * identify the pattern that has matched. 621 * 622 * @param expressions 623 * The NULL-terminated expression to parse. Note that this string must 624 * represent ONLY the pattern to be matched, with no delimiters or flags; 625 * any global flags should be specified with the @p flags argument. For 626 * example, the expression `/abc?def/i` should be compiled by providing 627 * `abc?def` as the @p expression, and @ref HS_FLAG_CASELESS as the @a 628 * flags. Meanwhile, the string content shall be fully parsed in a literal 629 * sense without any regular grammars. For example, the @p expression 630 * `abc?` simply means a char sequence of `a`, `b`, `c`, and `?`. The `?` 631 * here doesn't mean 0 or 1 quantifier under regular semantics. 632 * 633 * @param flags 634 * Array of flags which modify the behaviour of each expression. Multiple 635 * flags may be used by ORing them together. Specifying the NULL pointer 636 * in place of an array will set the flags value for all patterns to zero. 637 * Compared to @ref hs_compile_multi(), fewer valid values are provided: 638 * - HS_FLAG_CASELESS - Matching will be performed case-insensitively. 639 * - HS_FLAG_SINGLEMATCH - Only one match will be generated for the 640 * expression per stream. 641 * - HS_FLAG_SOM_LEFTMOST - Report the leftmost start of match offset 642 * when a match is found. 643 * 644 * @param ids 645 * An array of integers specifying the ID number to be associated with the 646 * corresponding pattern in the expressions array. Specifying the NULL 647 * pointer in place of an array will set the ID value for all patterns to 648 * zero. 649 * 650 * @param lens 651 * Array of lengths of the text content of each pure literal expression. 652 * As the text content indicated by @p expression is treated as single 653 * character one by one, the special terminating character `\0` should be 654 * allowed to appear in expression, and not treated as a terminator for a 655 * string. Thus, the end of a pure literal expression cannot be indicated 656 * by identifying `\0`, but by counting to the expression length. 657 * 658 * @param elements 659 * The number of elements in the input arrays. 660 * 661 * @param mode 662 * Compiler mode flags that affect the database as a whole. One of @ref 663 * HS_MODE_STREAM or @ref HS_MODE_BLOCK or @ref HS_MODE_VECTORED must be 664 * supplied, to select between the generation of a streaming, block or 665 * vectored database. In addition, other flags (beginning with HS_MODE_) 666 * may be supplied to enable specific features. See @ref HS_MODE_FLAG for 667 * more details. 668 * 669 * @param platform 670 * If not NULL, the platform structure is used to determine the target 671 * platform for the database. If NULL, a database suitable for running 672 * on the current host platform is produced. 673 * 674 * @param db 675 * On success, a pointer to the generated database will be returned in 676 * this parameter, or NULL on failure. The caller is responsible for 677 * deallocating the buffer using the @ref hs_free_database() function. 678 * 679 * @param error 680 * If the compile fails, a pointer to a @ref hs_compile_error_t will be 681 * returned, providing details of the error condition. The caller is 682 * responsible for deallocating the buffer using the @ref 683 * hs_free_compile_error() function. 684 * 685 * @return 686 * @ref HS_SUCCESS is returned on successful compilation; @ref 687 * HS_COMPILER_ERROR on failure, with details provided in the error 688 * parameter. 689 */ 690 hs_error_t HS_CDECL hs_compile_lit_multi(const char * const *expressions, 691 const unsigned *flags, 692 const unsigned *ids, 693 const size_t *lens, 694 unsigned elements, unsigned mode, 695 const hs_platform_info_t *platform, 696 hs_database_t **db, 697 hs_compile_error_t **error); 698 699 /** 700 * Free an error structure generated by @ref hs_compile(), @ref 701 * hs_compile_multi() or @ref hs_compile_ext_multi(). 702 * 703 * @param error 704 * The @ref hs_compile_error_t to be freed. NULL may also be safely 705 * provided. 706 * 707 * @return 708 * @ref HS_SUCCESS on success, other values on failure. 709 */ 710 hs_error_t HS_CDECL hs_free_compile_error(hs_compile_error_t *error); 711 712 /** 713 * Utility function providing information about a regular expression. The 714 * information provided in @ref hs_expr_info_t includes the minimum and maximum 715 * width of a pattern match. 716 * 717 * Note: successful analysis of an expression with this function does not imply 718 * that compilation of the same expression (via @ref hs_compile(), @ref 719 * hs_compile_multi() or @ref hs_compile_ext_multi()) would succeed. This 720 * function may return @ref HS_SUCCESS for regular expressions that Hyperscan 721 * cannot compile. 722 * 723 * Note: some per-pattern flags (such as @ref HS_FLAG_ALLOWEMPTY, @ref 724 * HS_FLAG_SOM_LEFTMOST) are accepted by this call, but as they do not affect 725 * the properties returned in the @ref hs_expr_info_t structure, they will not 726 * affect the outcome of this function. 727 * 728 * @param expression 729 * The NULL-terminated expression to parse. Note that this string must 730 * represent ONLY the pattern to be matched, with no delimiters or flags; 731 * any global flags should be specified with the @p flags argument. For 732 * example, the expression `/abc?def/i` should be compiled by providing 733 * `abc?def` as the @p expression, and @ref HS_FLAG_CASELESS as the @a 734 * flags. 735 * 736 * @param flags 737 * Flags which modify the behaviour of the expression. Multiple flags may 738 * be used by ORing them together. Valid values are: 739 * - HS_FLAG_CASELESS - Matching will be performed case-insensitively. 740 * - HS_FLAG_DOTALL - Matching a `.` will not exclude newlines. 741 * - HS_FLAG_MULTILINE - `^` and `$` anchors match any newlines in data. 742 * - HS_FLAG_SINGLEMATCH - Only one match will be generated by the 743 * expression per stream. 744 * - HS_FLAG_ALLOWEMPTY - Allow expressions which can match against an 745 * empty string, such as `.*`. 746 * - HS_FLAG_UTF8 - Treat this pattern as a sequence of UTF-8 characters. 747 * - HS_FLAG_UCP - Use Unicode properties for character classes. 748 * - HS_FLAG_PREFILTER - Compile pattern in prefiltering mode. 749 * - HS_FLAG_SOM_LEFTMOST - Report the leftmost start of match offset 750 * when a match is found. 751 * - HS_FLAG_COMBINATION - Parse the expression in logical combination 752 * syntax. 753 * - HS_FLAG_QUIET - Ignore match reporting for this expression. Used for 754 * the sub-expressions in logical combinations. 755 * 756 * @param info 757 * On success, a pointer to the pattern information will be returned in 758 * this parameter, or NULL on failure. This structure is allocated using 759 * the allocator supplied in @ref hs_set_allocator() (or malloc() if no 760 * allocator was set) and should be freed by the caller. 761 * 762 * @param error 763 * If the call fails, a pointer to a @ref hs_compile_error_t will be 764 * returned, providing details of the error condition. The caller is 765 * responsible for deallocating the buffer using the @ref 766 * hs_free_compile_error() function. 767 * 768 * @return 769 * @ref HS_SUCCESS is returned on successful compilation; @ref 770 * HS_COMPILER_ERROR on failure, with details provided in the error 771 * parameter. 772 */ 773 hs_error_t HS_CDECL hs_expression_info(const char *expression, 774 unsigned int flags, 775 hs_expr_info_t **info, 776 hs_compile_error_t **error); 777 778 /** 779 * Utility function providing information about a regular expression, with 780 * extended parameter support. The information provided in @ref hs_expr_info_t 781 * includes the minimum and maximum width of a pattern match. 782 * 783 * Note: successful analysis of an expression with this function does not imply 784 * that compilation of the same expression (via @ref hs_compile(), @ref 785 * hs_compile_multi() or @ref hs_compile_ext_multi()) would succeed. This 786 * function may return @ref HS_SUCCESS for regular expressions that Hyperscan 787 * cannot compile. 788 * 789 * Note: some per-pattern flags (such as @ref HS_FLAG_ALLOWEMPTY, @ref 790 * HS_FLAG_SOM_LEFTMOST) are accepted by this call, but as they do not affect 791 * the properties returned in the @ref hs_expr_info_t structure, they will not 792 * affect the outcome of this function. 793 * 794 * @param expression 795 * The NULL-terminated expression to parse. Note that this string must 796 * represent ONLY the pattern to be matched, with no delimiters or flags; 797 * any global flags should be specified with the @p flags argument. For 798 * example, the expression `/abc?def/i` should be compiled by providing 799 * `abc?def` as the @p expression, and @ref HS_FLAG_CASELESS as the @a 800 * flags. 801 * 802 * @param flags 803 * Flags which modify the behaviour of the expression. Multiple flags may 804 * be used by ORing them together. Valid values are: 805 * - HS_FLAG_CASELESS - Matching will be performed case-insensitively. 806 * - HS_FLAG_DOTALL - Matching a `.` will not exclude newlines. 807 * - HS_FLAG_MULTILINE - `^` and `$` anchors match any newlines in data. 808 * - HS_FLAG_SINGLEMATCH - Only one match will be generated by the 809 * expression per stream. 810 * - HS_FLAG_ALLOWEMPTY - Allow expressions which can match against an 811 * empty string, such as `.*`. 812 * - HS_FLAG_UTF8 - Treat this pattern as a sequence of UTF-8 characters. 813 * - HS_FLAG_UCP - Use Unicode properties for character classes. 814 * - HS_FLAG_PREFILTER - Compile pattern in prefiltering mode. 815 * - HS_FLAG_SOM_LEFTMOST - Report the leftmost start of match offset 816 * when a match is found. 817 * - HS_FLAG_COMBINATION - Parse the expression in logical combination 818 * syntax. 819 * - HS_FLAG_QUIET - Ignore match reporting for this expression. Used for 820 * the sub-expressions in logical combinations. 821 * 822 * @param ext 823 * A pointer to a filled @ref hs_expr_ext_t structure that defines 824 * extended behaviour for this pattern. NULL may be specified if no 825 * extended parameters are needed. 826 * 827 * @param info 828 * On success, a pointer to the pattern information will be returned in 829 * this parameter, or NULL on failure. This structure is allocated using 830 * the allocator supplied in @ref hs_set_allocator() (or malloc() if no 831 * allocator was set) and should be freed by the caller. 832 * 833 * @param error 834 * If the call fails, a pointer to a @ref hs_compile_error_t will be 835 * returned, providing details of the error condition. The caller is 836 * responsible for deallocating the buffer using the @ref 837 * hs_free_compile_error() function. 838 * 839 * @return 840 * @ref HS_SUCCESS is returned on successful compilation; @ref 841 * HS_COMPILER_ERROR on failure, with details provided in the error 842 * parameter. 843 */ 844 hs_error_t HS_CDECL hs_expression_ext_info(const char *expression, 845 unsigned int flags, 846 const hs_expr_ext_t *ext, 847 hs_expr_info_t **info, 848 hs_compile_error_t **error); 849 850 /** 851 * Populates the platform information based on the current host. 852 * 853 * @param platform 854 * On success, the pointed to structure is populated based on the current 855 * host. 856 * 857 * @return 858 * @ref HS_SUCCESS on success, other values on failure. 859 */ 860 hs_error_t HS_CDECL hs_populate_platform(hs_platform_info_t *platform); 861 862 /** 863 * @defgroup HS_PATTERN_FLAG Pattern flags 864 * 865 * @{ 866 */ 867 868 /** 869 * Compile flag: Set case-insensitive matching. 870 * 871 * This flag sets the expression to be matched case-insensitively by default. 872 * The expression may still use PCRE tokens (notably `(?i)` and 873 * `(?-i)`) to switch case-insensitive matching on and off. 874 */ 875 #define HS_FLAG_CASELESS 1 876 877 /** 878 * Compile flag: Matching a `.` will not exclude newlines. 879 * 880 * This flag sets any instances of the `.` token to match newline characters as 881 * well as all other characters. The PCRE specification states that the `.` 882 * token does not match newline characters by default, so without this flag the 883 * `.` token will not cross line boundaries. 884 */ 885 #define HS_FLAG_DOTALL 2 886 887 /** 888 * Compile flag: Set multi-line anchoring. 889 * 890 * This flag instructs the expression to make the `^` and `$` tokens match 891 * newline characters as well as the start and end of the stream. If this flag 892 * is not specified, the `^` token will only ever match at the start of a 893 * stream, and the `$` token will only ever match at the end of a stream within 894 * the guidelines of the PCRE specification. 895 */ 896 #define HS_FLAG_MULTILINE 4 897 898 /** 899 * Compile flag: Set single-match only mode. 900 * 901 * This flag sets the expression's match ID to match at most once. In streaming 902 * mode, this means that the expression will return only a single match over 903 * the lifetime of the stream, rather than reporting every match as per 904 * standard Hyperscan semantics. In block mode or vectored mode, only the first 905 * match for each invocation of @ref hs_scan() or @ref hs_scan_vector() will be 906 * returned. 907 * 908 * If multiple expressions in the database share the same match ID, then they 909 * either must all specify @ref HS_FLAG_SINGLEMATCH or none of them specify 910 * @ref HS_FLAG_SINGLEMATCH. If a group of expressions sharing a match ID 911 * specify the flag, then at most one match with the match ID will be generated 912 * per stream. 913 * 914 * Note: The use of this flag in combination with @ref HS_FLAG_SOM_LEFTMOST 915 * is not currently supported. 916 */ 917 #define HS_FLAG_SINGLEMATCH 8 918 919 /** 920 * Compile flag: Allow expressions that can match against empty buffers. 921 * 922 * This flag instructs the compiler to allow expressions that can match against 923 * empty buffers, such as `.?`, `.*`, `(a|)`. Since Hyperscan can return every 924 * possible match for an expression, such expressions generally execute very 925 * slowly; the default behaviour is to return an error when an attempt to 926 * compile one is made. Using this flag will force the compiler to allow such 927 * an expression. 928 */ 929 #define HS_FLAG_ALLOWEMPTY 16 930 931 /** 932 * Compile flag: Enable UTF-8 mode for this expression. 933 * 934 * This flag instructs Hyperscan to treat the pattern as a sequence of UTF-8 935 * characters. The results of scanning invalid UTF-8 sequences with a Hyperscan 936 * library that has been compiled with one or more patterns using this flag are 937 * undefined. 938 */ 939 #define HS_FLAG_UTF8 32 940 941 /** 942 * Compile flag: Enable Unicode property support for this expression. 943 * 944 * This flag instructs Hyperscan to use Unicode properties, rather than the 945 * default ASCII interpretations, for character mnemonics like `\w` and `\s` as 946 * well as the POSIX character classes. It is only meaningful in conjunction 947 * with @ref HS_FLAG_UTF8. 948 */ 949 #define HS_FLAG_UCP 64 950 951 /** 952 * Compile flag: Enable prefiltering mode for this expression. 953 * 954 * This flag instructs Hyperscan to compile an "approximate" version of this 955 * pattern for use in a prefiltering application, even if Hyperscan does not 956 * support the pattern in normal operation. 957 * 958 * The set of matches returned when this flag is used is guaranteed to be a 959 * superset of the matches specified by the non-prefiltering expression. 960 * 961 * If the pattern contains pattern constructs not supported by Hyperscan (such 962 * as zero-width assertions, back-references or conditional references) these 963 * constructs will be replaced internally with broader constructs that may 964 * match more often. 965 * 966 * Furthermore, in prefiltering mode Hyperscan may simplify a pattern that 967 * would otherwise return a "Pattern too large" error at compile time, or for 968 * performance reasons (subject to the matching guarantee above). 969 * 970 * It is generally expected that the application will subsequently confirm 971 * prefilter matches with another regular expression matcher that can provide 972 * exact matches for the pattern. 973 * 974 * Note: The use of this flag in combination with @ref HS_FLAG_SOM_LEFTMOST 975 * is not currently supported. 976 */ 977 #define HS_FLAG_PREFILTER 128 978 979 /** 980 * Compile flag: Enable leftmost start of match reporting. 981 * 982 * This flag instructs Hyperscan to report the leftmost possible start of match 983 * offset when a match is reported for this expression. (By default, no start 984 * of match is returned.) 985 * 986 * For all the 3 modes, enabling this behaviour may reduce performance. And 987 * particularly, it may increase stream state requirements in streaming mode. 988 */ 989 #define HS_FLAG_SOM_LEFTMOST 256 990 991 /** 992 * Compile flag: Logical combination. 993 * 994 * This flag instructs Hyperscan to parse this expression as logical 995 * combination syntax. 996 * Logical constraints consist of operands, operators and parentheses. 997 * The operands are expression indices, and operators can be 998 * '!'(NOT), '&'(AND) or '|'(OR). 999 * For example: 1000 * (101&102&103)|(104&!105) 1001 * ((301|302)&303)&(304|305) 1002 */ 1003 #define HS_FLAG_COMBINATION 512 1004 1005 /** 1006 * Compile flag: Don't do any match reporting. 1007 * 1008 * This flag instructs Hyperscan to ignore match reporting for this expression. 1009 * It is designed to be used on the sub-expressions in logical combinations. 1010 */ 1011 #define HS_FLAG_QUIET 1024 1012 1013 /** @} */ 1014 1015 /** 1016 * @defgroup HS_CPU_FEATURES_FLAG CPU feature support flags 1017 * 1018 * @{ 1019 */ 1020 1021 /** 1022 * CPU features flag - Intel(R) Advanced Vector Extensions 2 (Intel(R) AVX2) 1023 * 1024 * Setting this flag indicates that the target platform supports AVX2 1025 * instructions. 1026 */ 1027 #define HS_CPU_FEATURES_AVX2 (1ULL << 2) 1028 1029 /** 1030 * CPU features flag - Intel(R) Advanced Vector Extensions 512 (Intel(R) AVX512) 1031 * 1032 * Setting this flag indicates that the target platform supports AVX512 1033 * instructions, specifically AVX-512BW. Using AVX512 implies the use of AVX2. 1034 */ 1035 #define HS_CPU_FEATURES_AVX512 (1ULL << 3) 1036 1037 /** 1038 * CPU features flag - Intel(R) Advanced Vector Extensions 512 1039 * Vector Byte Manipulation Instructions (Intel(R) AVX512VBMI) 1040 * 1041 * Setting this flag indicates that the target platform supports AVX512VBMI 1042 * instructions. Using AVX512VBMI implies the use of AVX512. 1043 */ 1044 #define HS_CPU_FEATURES_AVX512VBMI (1ULL << 4) 1045 1046 /** @} */ 1047 1048 /** 1049 * @defgroup HS_TUNE_FLAG Tuning flags 1050 * 1051 * @{ 1052 */ 1053 1054 /** 1055 * Tuning Parameter - Generic 1056 * 1057 * This indicates that the compiled database should not be tuned for any 1058 * particular target platform. 1059 */ 1060 #define HS_TUNE_FAMILY_GENERIC 0 1061 1062 /** 1063 * Tuning Parameter - Intel(R) microarchitecture code name Sandy Bridge 1064 * 1065 * This indicates that the compiled database should be tuned for the 1066 * Sandy Bridge microarchitecture. 1067 */ 1068 #define HS_TUNE_FAMILY_SNB 1 1069 1070 /** 1071 * Tuning Parameter - Intel(R) microarchitecture code name Ivy Bridge 1072 * 1073 * This indicates that the compiled database should be tuned for the 1074 * Ivy Bridge microarchitecture. 1075 */ 1076 #define HS_TUNE_FAMILY_IVB 2 1077 1078 /** 1079 * Tuning Parameter - Intel(R) microarchitecture code name Haswell 1080 * 1081 * This indicates that the compiled database should be tuned for the 1082 * Haswell microarchitecture. 1083 */ 1084 #define HS_TUNE_FAMILY_HSW 3 1085 1086 /** 1087 * Tuning Parameter - Intel(R) microarchitecture code name Silvermont 1088 * 1089 * This indicates that the compiled database should be tuned for the 1090 * Silvermont microarchitecture. 1091 */ 1092 #define HS_TUNE_FAMILY_SLM 4 1093 1094 /** 1095 * Tuning Parameter - Intel(R) microarchitecture code name Broadwell 1096 * 1097 * This indicates that the compiled database should be tuned for the 1098 * Broadwell microarchitecture. 1099 */ 1100 #define HS_TUNE_FAMILY_BDW 5 1101 1102 /** 1103 * Tuning Parameter - Intel(R) microarchitecture code name Skylake 1104 * 1105 * This indicates that the compiled database should be tuned for the 1106 * Skylake microarchitecture. 1107 */ 1108 #define HS_TUNE_FAMILY_SKL 6 1109 1110 /** 1111 * Tuning Parameter - Intel(R) microarchitecture code name Skylake Server 1112 * 1113 * This indicates that the compiled database should be tuned for the 1114 * Skylake Server microarchitecture. 1115 */ 1116 #define HS_TUNE_FAMILY_SKX 7 1117 1118 /** 1119 * Tuning Parameter - Intel(R) microarchitecture code name Goldmont 1120 * 1121 * This indicates that the compiled database should be tuned for the 1122 * Goldmont microarchitecture. 1123 */ 1124 #define HS_TUNE_FAMILY_GLM 8 1125 1126 /** 1127 * Tuning Parameter - Intel(R) microarchitecture code name Icelake 1128 * 1129 * This indicates that the compiled database should be tuned for the 1130 * Icelake microarchitecture. 1131 */ 1132 #define HS_TUNE_FAMILY_ICL 9 1133 1134 /** 1135 * Tuning Parameter - Intel(R) microarchitecture code name Icelake Server 1136 * 1137 * This indicates that the compiled database should be tuned for the 1138 * Icelake Server microarchitecture. 1139 */ 1140 #define HS_TUNE_FAMILY_ICX 10 1141 1142 /** @} */ 1143 1144 /** 1145 * @defgroup HS_MODE_FLAG Compile mode flags 1146 * 1147 * The mode flags are used as values for the mode parameter of the various 1148 * compile calls (@ref hs_compile(), @ref hs_compile_multi() and @ref 1149 * hs_compile_ext_multi()). 1150 * 1151 * A mode value can be built by ORing these flag values together; the only 1152 * required flag is one of @ref HS_MODE_BLOCK, @ref HS_MODE_STREAM or @ref 1153 * HS_MODE_VECTORED. Other flags may be added to enable support for additional 1154 * features. 1155 * 1156 * @{ 1157 */ 1158 1159 /** 1160 * Compiler mode flag: Block scan (non-streaming) database. 1161 */ 1162 #define HS_MODE_BLOCK 1 1163 1164 /** 1165 * Compiler mode flag: Alias for @ref HS_MODE_BLOCK. 1166 */ 1167 #define HS_MODE_NOSTREAM 1 1168 1169 /** 1170 * Compiler mode flag: Streaming database. 1171 */ 1172 #define HS_MODE_STREAM 2 1173 1174 /** 1175 * Compiler mode flag: Vectored scanning database. 1176 */ 1177 #define HS_MODE_VECTORED 4 1178 1179 /** 1180 * Compiler mode flag: use full precision to track start of match offsets in 1181 * stream state. 1182 * 1183 * This mode will use the most stream state per pattern, but will always return 1184 * an accurate start of match offset regardless of how far back in the past it 1185 * was found. 1186 * 1187 * One of the SOM_HORIZON modes must be selected to use the @ref 1188 * HS_FLAG_SOM_LEFTMOST expression flag. 1189 */ 1190 #define HS_MODE_SOM_HORIZON_LARGE (1U << 24) 1191 1192 /** 1193 * Compiler mode flag: use medium precision to track start of match offsets in 1194 * stream state. 1195 * 1196 * This mode will use less stream state than @ref HS_MODE_SOM_HORIZON_LARGE and 1197 * will limit start of match accuracy to offsets within 2^32 bytes of the 1198 * end of match offset reported. 1199 * 1200 * One of the SOM_HORIZON modes must be selected to use the @ref 1201 * HS_FLAG_SOM_LEFTMOST expression flag. 1202 */ 1203 #define HS_MODE_SOM_HORIZON_MEDIUM (1U << 25) 1204 1205 /** 1206 * Compiler mode flag: use limited precision to track start of match offsets in 1207 * stream state. 1208 * 1209 * This mode will use less stream state than @ref HS_MODE_SOM_HORIZON_LARGE and 1210 * will limit start of match accuracy to offsets within 2^16 bytes of the 1211 * end of match offset reported. 1212 * 1213 * One of the SOM_HORIZON modes must be selected to use the @ref 1214 * HS_FLAG_SOM_LEFTMOST expression flag. 1215 */ 1216 #define HS_MODE_SOM_HORIZON_SMALL (1U << 26) 1217 1218 /** @} */ 1219 1220 #ifdef __cplusplus 1221 } /* extern "C" */ 1222 #endif 1223 1224 #endif /* HS_COMPILE_H_ */ 1225