Skip to content

Commit f33dece

Browse files
uudiinsuryasaimadhu
authored andcommitted
selftests/sgx: Use getauxval() to simplify test code
Use the library function getauxval() instead of a custom function to get the base address of the vDSO. [ bp: Massage commit message. ] Signed-off-by: Tianjia Zhang <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Acked-by: Shuah Khan <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 4284f7a commit f33dece

File tree

1 file changed

+4
-20
lines changed
  • tools/testing/selftests/sgx

1 file changed

+4
-20
lines changed

tools/testing/selftests/sgx/main.c

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <sys/stat.h>
1616
#include <sys/time.h>
1717
#include <sys/types.h>
18+
#include <sys/auxv.h>
1819
#include "defines.h"
1920
#include "main.h"
2021
#include "../kselftest.h"
@@ -28,24 +29,6 @@ struct vdso_symtab {
2829
Elf64_Word *elf_hashtab;
2930
};
3031

31-
static void *vdso_get_base_addr(char *envp[])
32-
{
33-
Elf64_auxv_t *auxv;
34-
int i;
35-
36-
for (i = 0; envp[i]; i++)
37-
;
38-
39-
auxv = (Elf64_auxv_t *)&envp[i + 1];
40-
41-
for (i = 0; auxv[i].a_type != AT_NULL; i++) {
42-
if (auxv[i].a_type == AT_SYSINFO_EHDR)
43-
return (void *)auxv[i].a_un.a_val;
44-
}
45-
46-
return NULL;
47-
}
48-
4932
static Elf64_Dyn *vdso_get_dyntab(void *addr)
5033
{
5134
Elf64_Ehdr *ehdr = addr;
@@ -162,7 +145,7 @@ static int user_handler(long rdi, long rsi, long rdx, long ursp, long r8, long r
162145
return 0;
163146
}
164147

165-
int main(int argc, char *argv[], char *envp[])
148+
int main(int argc, char *argv[])
166149
{
167150
struct sgx_enclave_run run;
168151
struct vdso_symtab symtab;
@@ -203,7 +186,8 @@ int main(int argc, char *argv[], char *envp[])
203186
memset(&run, 0, sizeof(run));
204187
run.tcs = encl.encl_base;
205188

206-
addr = vdso_get_base_addr(envp);
189+
/* Get vDSO base address */
190+
addr = (void *)getauxval(AT_SYSINFO_EHDR);
207191
if (!addr)
208192
goto err;
209193

0 commit comments

Comments
 (0)