blob: f14d45a2b2a1d19a8b95fe470f5c4f040059c4c0 [file] [log] [blame]
Peter Collingbourneeee71ae2013-08-07 22:47:26 +00001//===-- dfsan_interface.h -------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file is a part of DataFlowSanitizer.
11//
12// Public interface header.
13//===----------------------------------------------------------------------===//
14#ifndef DFSAN_INTERFACE_H
15#define DFSAN_INTERFACE_H
16
17#include <stddef.h>
18#include <stdint.h>
19#include <sanitizer/common_interface_defs.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25typedef uint16_t dfsan_label;
26
27/// Stores information associated with a specific label identifier. A label
28/// may be a base label created using dfsan_create_label, with associated
29/// text description and user data, or an automatically created union label,
30/// which represents the union of two label identifiers (which may themselves
31/// be base or union labels).
32struct dfsan_label_info {
33 // Fields for union labels, set to 0 for base labels.
34 dfsan_label l1;
35 dfsan_label l2;
36
37 // Fields for base labels.
38 const char *desc;
39 void *userdata;
40};
41
Peter Collingbourne249cdca2013-08-12 23:47:37 +000042/// Computes the union of \c l1 and \c l2, possibly creating a union label in
43/// the process.
44dfsan_label dfsan_union(dfsan_label l1, dfsan_label l2);
45
Peter Collingbourneeee71ae2013-08-07 22:47:26 +000046/// Creates and returns a base label with the given description and user data.
47dfsan_label dfsan_create_label(const char *desc, void *userdata);
48
49/// Sets the label for each address in [addr,addr+size) to \c label.
50void dfsan_set_label(dfsan_label label, void *addr, size_t size);
51
52/// Sets the label for each address in [addr,addr+size) to the union of the
53/// current label for that address and \c label.
54void dfsan_add_label(dfsan_label label, void *addr, size_t size);
55
56/// Retrieves the label associated with the given data.
57///
58/// The type of 'data' is arbitrary. The function accepts a value of any type,
59/// which can be truncated or extended (implicitly or explicitly) as necessary.
60/// The truncation/extension operations will preserve the label of the original
61/// value.
62dfsan_label dfsan_get_label(long data);
63
Peter Collingbourne1528c6c2013-08-13 22:15:40 +000064/// Retrieves the label associated with the data at the given address.
65dfsan_label dfsan_read_label(const void *addr, size_t size);
66
Peter Collingbourneeee71ae2013-08-07 22:47:26 +000067/// Retrieves a pointer to the dfsan_label_info struct for the given label.
68const struct dfsan_label_info *dfsan_get_label_info(dfsan_label label);
69
70/// Returns whether the given label label contains the label elem.
71int dfsan_has_label(dfsan_label label, dfsan_label elem);
72
73/// If the given label label contains a label with the description desc, returns
74/// that label, else returns 0.
75dfsan_label dfsan_has_label_with_desc(dfsan_label label, const char *desc);
76
77#ifdef __cplusplus
78} // extern "C"
79
80template <typename T>
Dmitry Vyukov734647c2013-08-13 16:52:07 +000081void dfsan_set_label(dfsan_label label, T &data) { // NOLINT
Peter Collingbourneeee71ae2013-08-07 22:47:26 +000082 dfsan_set_label(label, (void *)&data, sizeof(T));
83}
84
85#endif
86
87#endif // DFSAN_INTERFACE_H