dfsan_interface.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //===-- dfsan_interface.h -------------------------------------------------===//
  2. //
  3. // This file is distributed under the University of Illinois Open Source
  4. // License. See LICENSE.TXT for details.
  5. //
  6. //===----------------------------------------------------------------------===//
  7. //
  8. // This file is a part of DataFlowSanitizer.
  9. //
  10. // Public interface header.
  11. //===----------------------------------------------------------------------===//
  12. #ifndef DFSAN_INTERFACE_H
  13. #define DFSAN_INTERFACE_H
  14. #include <stddef.h>
  15. #include <stdint.h>
  16. #include <sanitizer/common_interface_defs.h>
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. typedef uint16_t dfsan_label;
  21. /// Stores information associated with a specific label identifier. A label
  22. /// may be a base label created using dfsan_create_label, with associated
  23. /// text description and user data, or an automatically created union label,
  24. /// which represents the union of two label identifiers (which may themselves
  25. /// be base or union labels).
  26. struct dfsan_label_info {
  27. // Fields for union labels, set to 0 for base labels.
  28. dfsan_label l1;
  29. dfsan_label l2;
  30. // Fields for base labels.
  31. const char *desc;
  32. void *userdata;
  33. };
  34. /// Signature of the callback argument to dfsan_set_write_callback().
  35. typedef void (*dfsan_write_callback_t)(int fd, const void *buf, size_t count);
  36. /// Computes the union of \c l1 and \c l2, possibly creating a union label in
  37. /// the process.
  38. dfsan_label dfsan_union(dfsan_label l1, dfsan_label l2);
  39. /// Creates and returns a base label with the given description and user data.
  40. dfsan_label dfsan_create_label(const char *desc, void *userdata);
  41. /// Sets the label for each address in [addr,addr+size) to \c label.
  42. void dfsan_set_label(dfsan_label label, void *addr, size_t size);
  43. /// Sets the label for each address in [addr,addr+size) to the union of the
  44. /// current label for that address and \c label.
  45. void dfsan_add_label(dfsan_label label, void *addr, size_t size);
  46. /// Retrieves the label associated with the given data.
  47. ///
  48. /// The type of 'data' is arbitrary. The function accepts a value of any type,
  49. /// which can be truncated or extended (implicitly or explicitly) as necessary.
  50. /// The truncation/extension operations will preserve the label of the original
  51. /// value.
  52. dfsan_label dfsan_get_label(long data);
  53. /// Retrieves the label associated with the data at the given address.
  54. dfsan_label dfsan_read_label(const void *addr, size_t size);
  55. /// Retrieves a pointer to the dfsan_label_info struct for the given label.
  56. const struct dfsan_label_info *dfsan_get_label_info(dfsan_label label);
  57. /// Returns whether the given label label contains the label elem.
  58. int dfsan_has_label(dfsan_label label, dfsan_label elem);
  59. /// If the given label label contains a label with the description desc, returns
  60. /// that label, else returns 0.
  61. dfsan_label dfsan_has_label_with_desc(dfsan_label label, const char *desc);
  62. /// Returns the number of labels allocated.
  63. size_t dfsan_get_label_count(void);
  64. /// Sets a callback to be invoked on calls to write(). The callback is invoked
  65. /// before the write is done. The write is not guaranteed to succeed when the
  66. /// callback executes. Pass in NULL to remove any callback.
  67. void dfsan_set_write_callback(dfsan_write_callback_t labeled_write_callback);
  68. #ifdef __cplusplus
  69. } // extern "C"
  70. template <typename T>
  71. void dfsan_set_label(dfsan_label label, T &data) { // NOLINT
  72. dfsan_set_label(label, (void *)&data, sizeof(T));
  73. }
  74. #endif
  75. #endif // DFSAN_INTERFACE_H