Blame libipt/internal/include/pt_retstack.h

Packit b1f7ae
/*
Packit b1f7ae
 * Copyright (c) 2013-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_RETSTACK_H
Packit b1f7ae
#define PT_RETSTACK_H
Packit b1f7ae
Packit b1f7ae
#include <stdint.h>
Packit b1f7ae
Packit b1f7ae
Packit b1f7ae
/* The size of the call/return stack in number of entries. */
Packit b1f7ae
enum {
Packit b1f7ae
	pt_retstack_size	= 64
Packit b1f7ae
};
Packit b1f7ae
Packit b1f7ae
/* A stack of return addresses used for return compression. */
Packit b1f7ae
struct pt_retstack {
Packit b1f7ae
	/* The stack of return addresses.
Packit b1f7ae
	 *
Packit b1f7ae
	 * We use one additional entry in order to distinguish a full from
Packit b1f7ae
	 * an empty stack.
Packit b1f7ae
	 */
Packit b1f7ae
	uint64_t stack[pt_retstack_size + 1];
Packit b1f7ae
Packit b1f7ae
	/* The top of the stack. */
Packit b1f7ae
	uint8_t top;
Packit b1f7ae
Packit b1f7ae
	/* The bottom of the stack. */
Packit b1f7ae
	uint8_t bottom;
Packit b1f7ae
};
Packit b1f7ae
Packit b1f7ae
/* Initialize (or reset) a call/return stack. */
Packit b1f7ae
extern void pt_retstack_init(struct pt_retstack *);
Packit b1f7ae
Packit b1f7ae
/* Test a call/return stack for emptiness.
Packit b1f7ae
 *
Packit b1f7ae
 * Returns zero if @retstack contains at least one element.
Packit b1f7ae
 * Returns a positive integer if @retstack is empty.
Packit b1f7ae
 * Returns -pte_invalid if @retstack is NULL.
Packit b1f7ae
 */
Packit b1f7ae
extern int pt_retstack_is_empty(const struct pt_retstack *retstack);
Packit b1f7ae
Packit b1f7ae
/* Pop and return the topmost IP.
Packit b1f7ae
 *
Packit b1f7ae
 * If @ip is not NULL, provides the topmost return address on success.
Packit b1f7ae
 * If @retstack is not empty, pops the topmost return address on success.
Packit b1f7ae
 *
Packit b1f7ae
 * Returns zero on success.
Packit b1f7ae
 * Returns -pte_invalid if @retstack is NULL.
Packit b1f7ae
 * Returns -pte_noip if @retstack is empty.
Packit b1f7ae
 */
Packit b1f7ae
extern int pt_retstack_pop(struct pt_retstack *retstack, uint64_t *ip);
Packit b1f7ae
Packit b1f7ae
/* Push a return address onto the stack.
Packit b1f7ae
 *
Packit b1f7ae
 * Pushes @ip onto @retstack.
Packit b1f7ae
 * If @retstack is full, drops the oldest return address.
Packit b1f7ae
 *
Packit b1f7ae
 * Returns zero on success.
Packit b1f7ae
 */
Packit b1f7ae
extern int pt_retstack_push(struct pt_retstack *retstack, uint64_t ip);
Packit b1f7ae
Packit b1f7ae
#endif /* PT_RETSTACK_H */