Lines Matching +full:tcs +full:- +full:offset
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2016-20 Intel Corporation. */
26 if (encl->encl_base) in encl_delete()
27 munmap((void *)encl->encl_base, encl->encl_size); in encl_delete()
29 if (encl->bin) in encl_delete()
30 munmap(encl->bin, encl->bin_size); in encl_delete()
32 if (encl->fd) in encl_delete()
33 close(encl->fd); in encl_delete()
35 if (encl->segment_tbl) { in encl_delete()
36 heap_seg = &encl->segment_tbl[encl->nr_segments - 1]; in encl_delete()
37 munmap(heap_seg->src, heap_seg->size); in encl_delete()
38 free(encl->segment_tbl); in encl_delete()
52 if (fd == -1) { in encl_map_bin()
69 encl->bin = bin; in encl_map_bin()
70 encl->bin_size = sb.st_size; in encl_map_bin()
82 struct sgx_secs *secs = &encl->secs; in encl_ioc_create()
86 assert(encl->encl_base != 0); in encl_ioc_create()
89 secs->ssa_frame_size = 1; in encl_ioc_create()
90 secs->attributes = SGX_ATTR_MODE64BIT; in encl_ioc_create()
91 secs->xfrm = 3; in encl_ioc_create()
92 secs->base = encl->encl_base; in encl_ioc_create()
93 secs->size = encl->encl_size; in encl_ioc_create()
96 rc = ioctl(encl->fd, SGX_IOC_ENCLAVE_CREATE, &ioc); in encl_ioc_create()
99 munmap((void *)secs->base, encl->encl_size); in encl_ioc_create()
113 secinfo.flags = seg->flags; in encl_ioc_add_pages()
115 ioc.src = (uint64_t)seg->src; in encl_ioc_add_pages()
116 ioc.offset = seg->offset; in encl_ioc_add_pages()
117 ioc.length = seg->size; in encl_ioc_add_pages()
119 if (seg->measure) in encl_ioc_add_pages()
124 rc = ioctl(encl->fd, SGX_IOC_ENCLAVE_ADD_PAGES, &ioc); in encl_ioc_add_pages()
146 ehdr = encl->bin; in encl_get_entry()
147 sections = encl->bin + ehdr->e_shoff; in encl_get_entry()
149 for (i = 0; i < ehdr->e_shnum; i++) { in encl_get_entry()
151 symtab = (Elf64_Sym *)((char *)encl->bin + sections[i].sh_offset); in encl_get_entry()
157 for (i = 0; i < ehdr->e_shnum; i++) { in encl_get_entry()
159 sym_names = (char *)encl->bin + sections[i].sh_offset; in encl_get_entry()
170 if (!strcmp(symbol, sym_names + sym->st_name)) in encl_get_entry()
171 return (uint64_t)sym->st_value; in encl_get_entry()
188 int fd = -1; in encl_load()
205 if (ptr == (void *)-1) { in encl_load()
215 " If so, remount it executable: mount -o remount,exec /dev\n\n" in encl_load()
218 if (ptr == (void *)-1) { in encl_load()
224 encl->fd = fd; in encl_load()
229 ehdr = encl->bin; in encl_load()
230 phdr_tbl = encl->bin + ehdr->e_phoff; in encl_load()
232 encl->nr_segments = 1; /* one for the heap */ in encl_load()
234 for (i = 0; i < ehdr->e_phnum; i++) { in encl_load()
237 if (phdr->p_type == PT_LOAD) in encl_load()
238 encl->nr_segments++; in encl_load()
241 encl->segment_tbl = calloc(encl->nr_segments, in encl_load()
243 if (!encl->segment_tbl) in encl_load()
246 for (i = 0, j = 0; i < ehdr->e_phnum; i++) { in encl_load()
248 unsigned int flags = phdr->p_flags; in encl_load()
250 if (phdr->p_type != PT_LOAD) in encl_load()
253 seg = &encl->segment_tbl[j]; in encl_load()
258 phdr->p_flags); in encl_load()
264 "TCS has invalid segment flags 0x%02x.\n", in encl_load()
265 phdr->p_flags); in encl_load()
270 src_offset = phdr->p_offset & PAGE_MASK; in encl_load()
271 encl->src = encl->bin + src_offset; in encl_load()
273 seg->prot = PROT_READ | PROT_WRITE; in encl_load()
274 seg->flags = SGX_PAGE_TYPE_TCS << 8; in encl_load()
276 seg->prot = (phdr->p_flags & PF_R) ? PROT_READ : 0; in encl_load()
277 seg->prot |= (phdr->p_flags & PF_W) ? PROT_WRITE : 0; in encl_load()
278 seg->prot |= (phdr->p_flags & PF_X) ? PROT_EXEC : 0; in encl_load()
279 seg->flags = (SGX_PAGE_TYPE_REG << 8) | seg->prot; in encl_load()
282 seg->offset = (phdr->p_offset & PAGE_MASK) - src_offset; in encl_load()
283 seg->size = (phdr->p_filesz + PAGE_SIZE - 1) & PAGE_MASK; in encl_load()
284 seg->src = encl->src + seg->offset; in encl_load()
285 seg->measure = true; in encl_load()
290 assert(j == encl->nr_segments - 1); in encl_load()
292 seg = &encl->segment_tbl[j]; in encl_load()
293 seg->offset = encl->segment_tbl[j - 1].offset + encl->segment_tbl[j - 1].size; in encl_load()
294 seg->size = heap_size; in encl_load()
295 seg->src = mmap(NULL, heap_size, PROT_READ | PROT_WRITE, in encl_load()
296 MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); in encl_load()
297 seg->prot = PROT_READ | PROT_WRITE; in encl_load()
298 seg->flags = (SGX_PAGE_TYPE_REG << 8) | seg->prot; in encl_load()
299 seg->measure = false; in encl_load()
301 if (seg->src == MAP_FAILED) in encl_load()
304 encl->src_size = encl->segment_tbl[j].offset + encl->segment_tbl[j].size; in encl_load()
306 for (encl->encl_size = 4096; encl->encl_size < encl->src_size; ) in encl_load()
307 encl->encl_size <<= 1; in encl_load()
312 if (fd != -1) in encl_load()
320 size_t encl_size = encl->encl_size; in encl_map_area()
324 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); in encl_map_area()
330 encl->encl_base = ((uint64_t)area + encl_size - 1) & ~(encl_size - 1); in encl_map_area()
332 munmap(area, encl->encl_base - (uint64_t)area); in encl_map_area()
333 munmap((void *)(encl->encl_base + encl_size), in encl_map_area()
334 (uint64_t)area + encl_size - encl->encl_base); in encl_map_area()
355 for (i = 0; i < encl->nr_segments; i++) { in encl_build()
356 struct encl_segment *seg = &encl->segment_tbl[i]; in encl_build()
362 ioc.sigstruct = (uint64_t)&encl->sigstruct; in encl_build()
363 ret = ioctl(encl->fd, SGX_IOC_ENCLAVE_INIT, &ioc); in encl_build()