2 * Copyright (c) 2013-2018, Intel Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
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 notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * 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.
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.
32 #include "pt_mapped_section.h"
39 /* A list of sections. */
40 struct pt_section_list {
41 /* The next list element. */
42 struct pt_section_list *next;
44 /* The mapped section. */
45 struct pt_mapped_section section;
47 /* The image section identifier. */
51 /* A traced image consisting of a collection of sections. */
53 /* The optional image name. */
56 /* The list of sections. */
57 struct pt_section_list *sections;
59 /* An optional read memory callback. */
61 /* The callback function. */
62 read_memory_callback_t *callback;
64 /* The callback context. */
69 /* Initialize an image with an optional @name. */
70 extern void pt_image_init(struct pt_image *image, const char *name);
74 * This removes all sections and frees the name.
76 extern void pt_image_fini(struct pt_image *image);
78 /* Add a section to an image.
80 * Add @section identified by @isid to @image at @vaddr in @asid. If @section
81 * overlaps with existing sections, the existing sections are shrunk, split, or
82 * removed to accomodate @section. Absence of a section identifier is indicated
83 * by an @isid of zero.
85 * Returns zero on success.
86 * Returns -pte_internal if @image, @section, or @asid is NULL.
88 extern int pt_image_add(struct pt_image *image, struct pt_section *section,
89 const struct pt_asid *asid, uint64_t vaddr, int isid);
91 /* Remove a section from an image.
93 * Returns zero on success.
94 * Returns -pte_internal if @image, @section, or @asid is NULL.
95 * Returns -pte_bad_image if @image does not contain @section at @vaddr.
97 extern int pt_image_remove(struct pt_image *image, struct pt_section *section,
98 const struct pt_asid *asid, uint64_t vaddr);
100 /* Read memory from an image.
102 * Reads at most @size bytes from @image at @addr in @asid into @buffer.
104 * Returns the number of bytes read on success, a negative error code otherwise.
105 * Returns -pte_internal if @image, @isid, @buffer, or @asid is NULL.
106 * Returns -pte_nomap if the section does not contain @addr.
108 extern int pt_image_read(struct pt_image *image, int *isid, uint8_t *buffer,
109 uint16_t size, const struct pt_asid *asid,
112 /* Find an image section.
114 * Find the section containing @vaddr in @asid and provide it in @msec. On
115 * success, takes a reference of @msec->section that the caller needs to put
118 * Returns the section's identifier on success, a negative error code otherwise.
119 * Returns -pte_internal if @image, @msec, or @asid is NULL.
120 * Returns -pte_nomap if there is no such section in @image.
122 extern int pt_image_find(struct pt_image *image, struct pt_mapped_section *msec,
123 const struct pt_asid *asid, uint64_t vaddr);
125 /* Validate an image section.
127 * Validate that a lookup of @vaddr in @msec->asid in @image would result in
128 * @msec identified by @isid.
130 * Validation may fail sporadically.
132 * Returns zero on success, a negative error code otherwise.
133 * Returns -pte_invalid if @image or @msec is NULL.
134 * Returns -pte_nomap if validation failed.
136 extern int pt_image_validate(const struct pt_image *image,
137 const struct pt_mapped_section *msec,
138 uint64_t vaddr, int isid);
140 #endif /* PT_IMAGE_H */