Blame libipt/internal/include/posix/pt_section_posix.h

Packit b1f7ae
/*
Packit b1f7ae
 * Copyright (c) 2015-2017, Intel Corporation
Packit b1f7ae
 *
Packit b1f7ae
 * Redistribution and use in source and binary forms, with or without
Packit b1f7ae
 * modification, are permitted provided that the following conditions are met:
Packit b1f7ae
 *
Packit b1f7ae
 *  * Redistributions of source code must retain the above copyright notice,
Packit b1f7ae
 *    this list of conditions and the following disclaimer.
Packit b1f7ae
 *  * Redistributions in binary form must reproduce the above copyright notice,
Packit b1f7ae
 *    this list of conditions and the following disclaimer in the documentation
Packit b1f7ae
 *    and/or other materials provided with the distribution.
Packit b1f7ae
 *  * Neither the name of Intel Corporation nor the names of its contributors
Packit b1f7ae
 *    may be used to endorse or promote products derived from this software
Packit b1f7ae
 *    without specific prior written permission.
Packit b1f7ae
 *
Packit b1f7ae
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Packit b1f7ae
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit b1f7ae
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit b1f7ae
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
Packit b1f7ae
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
Packit b1f7ae
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
Packit b1f7ae
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Packit b1f7ae
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
Packit b1f7ae
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
Packit b1f7ae
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
Packit b1f7ae
 * POSSIBILITY OF SUCH DAMAGE.
Packit b1f7ae
 */
Packit b1f7ae
Packit b1f7ae
#ifndef PT_SECTION_POSIX_H
Packit b1f7ae
#define PT_SECTION_POSIX_H
Packit b1f7ae
Packit b1f7ae
#include <stdint.h>
Packit b1f7ae
#include <sys/stat.h>
Packit b1f7ae
Packit b1f7ae
struct pt_section;
Packit b1f7ae
Packit b1f7ae
Packit b1f7ae
/* Fstat-based file status. */
Packit b1f7ae
struct pt_sec_posix_status {
Packit b1f7ae
	/* The file status. */
Packit b1f7ae
	struct stat stat;
Packit b1f7ae
};
Packit b1f7ae
Packit b1f7ae
/* MMAP-based section mapping information. */
Packit b1f7ae
struct pt_sec_posix_mapping {
Packit b1f7ae
	/* The mmap base address. */
Packit b1f7ae
	uint8_t *base;
Packit b1f7ae
Packit b1f7ae
	/* The mapped memory size. */
Packit b1f7ae
	uint64_t size;
Packit b1f7ae
Packit b1f7ae
	/* The begin and end of the mapped memory. */
Packit b1f7ae
	const uint8_t *begin, *end;
Packit b1f7ae
};
Packit b1f7ae
Packit b1f7ae
Packit b1f7ae
/* Map a section.
Packit b1f7ae
 *
Packit b1f7ae
 * On success, sets @section's mapping, unmap, and read pointers.
Packit b1f7ae
 *
Packit b1f7ae
 * Returns zero on success, a negative error code otherwise.
Packit b1f7ae
 * Returns -pte_internal if @section or @file are NULL.
Packit b1f7ae
 * Returns -pte_invalid if @section can't be mapped.
Packit b1f7ae
 */
Packit b1f7ae
extern int pt_sec_posix_map(struct pt_section *section, int fd);
Packit b1f7ae
Packit b1f7ae
/* Unmap a section.
Packit b1f7ae
 *
Packit b1f7ae
 * On success, clears @section's mapping, unmap, and read pointers.
Packit b1f7ae
 *
Packit b1f7ae
 * Returns zero on success, a negative error code otherwise.
Packit b1f7ae
 * Returns -pte_internal if @section is NULL.
Packit b1f7ae
 * Returns -pte_internal if @section has not been mapped.
Packit b1f7ae
 */
Packit b1f7ae
extern int pt_sec_posix_unmap(struct pt_section *section);
Packit b1f7ae
Packit b1f7ae
/* Read memory from an mmaped section.
Packit b1f7ae
 *
Packit b1f7ae
 * Reads at most @size bytes from @section at @offset into @buffer.
Packit b1f7ae
 *
Packit b1f7ae
 * Returns the number of bytes read on success, a negative error code otherwise.
Packit b1f7ae
 * Returns -pte_invalid if @section or @buffer are NULL.
Packit b1f7ae
 * Returns -pte_nomap if @offset is beyond the end of the section.
Packit b1f7ae
 */
Packit b1f7ae
extern int pt_sec_posix_read(const struct pt_section *section, uint8_t *buffer,
Packit b1f7ae
			     uint16_t size, uint64_t offset);
Packit b1f7ae
Packit b1f7ae
#endif /* PT_SECTION_POSIX_H */