Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/sgx: Dump enclave memory map

Often, it's useful to check whether /proc/self/maps looks sane when
dealing with memory mapped objects, especially when they are JIT'ish
dynamically constructed objects. Therefore, dump "/dev/sgx_enclave"
matching lines from the memory map in FIXTURE_SETUP().

Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Jarkko Sakkinen and committed by
Shuah Khan
040efd1c 235d1c9c

+14
+14
tools/testing/selftests/sgx/main.c
··· 117 117 Elf64_Sym *sgx_enter_enclave_sym = NULL; 118 118 struct vdso_symtab symtab; 119 119 struct encl_segment *seg; 120 + char maps_line[256]; 121 + FILE *maps_file; 120 122 unsigned int i; 121 123 void *addr; 122 124 ··· 168 166 169 167 memset(&self->run, 0, sizeof(self->run)); 170 168 self->run.tcs = self->encl.encl_base; 169 + 170 + maps_file = fopen("/proc/self/maps", "r"); 171 + if (maps_file != NULL) { 172 + while (fgets(maps_line, sizeof(maps_line), maps_file) != NULL) { 173 + maps_line[strlen(maps_line) - 1] = '\0'; 174 + 175 + if (strstr(maps_line, "/dev/sgx_enclave")) 176 + TH_LOG("%s", maps_line); 177 + } 178 + 179 + fclose(maps_file); 180 + } 171 181 172 182 err: 173 183 if (!sgx_enter_enclave_sym)