aboutsummaryrefslogtreecommitdiff
path: root/ldelf/include/ldelf.h
blob: d43d7445f5b4ff86f91b7038fce65dff835854fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* SPDX-License-Identifier: BSD-2-Clause */
/*
 * Copyright (c) 2019, Linaro Limited
 */

#ifndef __LDELF_H
#define __LDELF_H

#include <types_ext.h>
#include <tee_api_types.h>
#include <user_ta_header.h>

/* Size of stack for TEE Core to allocate */
#define LDELF_STACK_SIZE	(4096 * 2)

/*
 * struct ldelf_arg - argument for ldelf
 * @uuid:	  [in] UUID of TA to load
 * @is_32bit:	  [out] 1 if a 32bit TA or 0 if a 64bit TA
 * @flags:	  [out] Flags field of TA header
 * @entry_func:	  [out] TA entry function
 * @stack_ptr:	  [out] TA stack pointer
 * @dump_entry:	  [out] Dump TA mappings and stack trace
 * @ftrace_entry: [out] Dump TA mappings and ftrace buffer
 * @fbuf:         [out] ftrace buffer pointer
 * @dl_entry:     [out] Dynamic linking interface (for libdl)
 */
struct ldelf_arg {
	TEE_UUID uuid;
	uint32_t is_32bit;
	uint32_t flags;
	uint64_t entry_func;
	uint64_t stack_ptr;
	uint64_t dump_entry;
	uint64_t ftrace_entry;
	uint64_t dl_entry;
	struct ftrace_buf *fbuf;
};

#define DUMP_MAP_READ	BIT(0)
#define DUMP_MAP_WRITE	BIT(1)
#define DUMP_MAP_EXEC	BIT(2)
#define DUMP_MAP_SECURE	BIT(3)
#define DUMP_MAP_EPHEM	BIT(4)
#define DUMP_MAP_LDELF	BIT(7)

/*
 * struct dump_entry_arg - argument for ldelf_arg::dump_entry()
 */
struct dump_entry_arg {
	union {
		struct {
			uint32_t regs[16];
		} arm32;
		struct {
			uint64_t fp;
			uint64_t sp;
			uint64_t pc;
		} arm64;
	};
	bool is_arm32;
	size_t num_maps;
	struct dump_map {
		vaddr_t va;
		paddr_t pa;
		size_t sz;
		uint32_t flags;
	} maps[];
};

/*
 * struct dl_entry_arg - argument for ldelf_arg::dl_entry()
 */
struct dl_entry_arg {
	uint32_t cmd;
	TEE_Result ret;
	union {
		struct {
			TEE_UUID uuid;	/* in */
			uint32_t flags;	/* in */
		} dlopen;
		struct {
			TEE_UUID uuid;	/* in */
			vaddr_t val;	/* out */
			char symbol[];	/* in */
		} dlsym;
	};
};

/*
 * Values for dl_entry_arg::cmd
 */
#define LDELF_DL_ENTRY_DLOPEN	0
#define LDELF_DL_ENTRY_DLSYM	1

/*
 * Values for dl_entry_arg::dlopen::flags
 */
#define RTLD_NOW	2
#define RTLD_GLOBAL	0x100
#define RTLD_NODELETE	0x1000

/*
 * ldelf is loaded into memory by TEE Core. BSS is initialized and a
 * stack is allocated and supplied in SP register. A struct ldelf_arg
 * is placed in the stack and a pointer to the struct is provided in
 * r0/x0.
 *
 * ldelf relocates itself to the address where it is loaded before the main
 * C routine is called.
 *
 * In the main C routine the TA is loaded using the PTA System interface.
 */

#endif /*__LDELF_H*/