1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3  * Copyright (c) 2019, Linaro Limited
4  */
5 #include <ldelf.h>
6 #include <string.h>
7 
8 #include "dl.h"
9 #include "ta_elf.h"
10 
dlopen_entry(struct dl_entry_arg * arg)11 TEE_Result dlopen_entry(struct dl_entry_arg *arg)
12 {
13 	TEE_UUID zero = { };
14 
15 	if (arg->dlopen.flags != (RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE))
16 		return TEE_ERROR_BAD_PARAMETERS;
17 
18 	if (!memcmp(&arg->dlopen.uuid, &zero, sizeof(zero)))
19 		return TEE_SUCCESS;
20 
21 	return ta_elf_add_library(&arg->dlopen.uuid);
22 }
23 
dlsym_entry(struct dl_entry_arg * arg)24 TEE_Result dlsym_entry(struct dl_entry_arg *arg)
25 {
26 	struct ta_elf *elf = NULL;
27 	TEE_UUID zero = { };
28 
29 	if (memcmp(&arg->dlsym.uuid, &zero, sizeof(zero))) {
30 		elf = ta_elf_find_elf(&arg->dlsym.uuid);
31 		if (!elf)
32 			return TEE_ERROR_ITEM_NOT_FOUND;
33 	}
34 
35 	return ta_elf_resolve_sym(arg->dlsym.symbol, &arg->dlsym.val, NULL,
36 				  elf);
37 }
38 
39