diff mbox series

[for_v2?,v2,05/14] selftests/x86/sgx: Move vDSO setup to a helper function

Message ID 20191017030340.18301-6-sean.j.christopherson@intel.com (mailing list archive)
State New, archived
Headers show
Series selftests/x86/sgx: Improve tests | expand

Commit Message

Sean Christopherson Oct. 17, 2019, 3:03 a.m. UTC
Move the vDSO setup code to a helper function so that it is more obvious
that it's run-once setup, and that setting eenter is the end goal of the
code.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 tools/testing/selftests/x86/sgx/main.c | 41 ++++++++++++++++----------
 1 file changed, 26 insertions(+), 15 deletions(-)
diff mbox series

Patch

diff --git a/tools/testing/selftests/x86/sgx/main.c b/tools/testing/selftests/x86/sgx/main.c
index e87e445f6de1..2510cacb5154 100644
--- a/tools/testing/selftests/x86/sgx/main.c
+++ b/tools/testing/selftests/x86/sgx/main.c
@@ -309,16 +309,36 @@  static bool load_sigstruct(const char *path, void *sigstruct)
 	return true;
 }
 
+static bool setup_vdso(void)
+{
+	struct vdso_symtab symtab;
+	Elf64_Sym *eenter_sym;
+	void *addr;
+
+	addr = vdso_get_base_addr();
+	if (!addr)
+		return false;
+
+	if (!vdso_get_symtab(addr, &symtab))
+		return false;
+
+	eenter_sym = vdso_symtab_get(&symtab, "__vdso_sgx_enter_enclave");
+	if (!eenter_sym)
+		return false;
+
+	/* eenter is used by sgx_call_vdso() to call into the vDSO. */
+	eenter = addr + eenter_sym->st_value;
+
+	return true;
+}
+
 int main(int argc, char *argv[], char *envp[])
 {
 	struct sgx_enclave_exception exception;
 	struct sgx_sigstruct sigstruct;
-	struct vdso_symtab symtab;
-	Elf64_Sym *eenter_sym;
 	struct sgx_secs secs;
 	uint64_t result = 0;
 	off_t bin_size;
-	void *addr;
 	void *bin;
 
 	if (!encl_data_map("encl.bin", &bin, &bin_size))
@@ -340,20 +360,11 @@  int main(int argc, char *argv[], char *envp[])
 
 	printf("Output: 0x%lx\n", result);
 
+	if (!setup_vdso())
+		exit(1);
+
 	memset(&exception, 0, sizeof(exception));
 
-	addr = vdso_get_base_addr();
-	if (!addr)
-		exit(1);
-
-	if (!vdso_get_symtab(addr, &symtab))
-		exit(1);
-
-	eenter_sym = vdso_symtab_get(&symtab, "__vdso_sgx_enter_enclave");
-	if (!eenter_sym)
-		exit(1);
-	eenter = addr + eenter_sym->st_value;
-
 	printf("Input: 0x%lx\n", MAGIC);
 
 	sgx_call_vdso((void *)&MAGIC, &result, NULL, NULL, NULL, NULL,