1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef DYNLINK_RAND_H 17 #define DYNLINK_RAND_H 18 19 #include <limits.h> 20 #include <stdbool.h> 21 #include <stddef.h> 22 23 #include "libc.h" 24 #include "dynlink.h" 25 #include "namespace.h" 26 27 #ifdef __cplusplus 28 extern "C" { 29 #endif 30 31 struct dso; 32 33 #define READ_ELF_LENGTH 896 34 35 // load library context 36 struct loadtask { 37 // parameters 38 const char *name; 39 struct dso *needed_by; 40 ns_t *namespace; 41 bool check_inherited; 42 bool isloaded; 43 44 // variables for load library 45 char buf[PATH_MAX + 1]; 46 const char *pathname; 47 struct dso *p; 48 int fd; 49 uint64_t file_offset; /* Used to read an uncompress library from a zip file, file_offset is relative offset of start of zip file. */ 50 51 // variables for map library 52 Ehdr ehdr_buf[(READ_ELF_LENGTH + sizeof(Ehdr)) / sizeof(Ehdr)]; 53 void *allocated_buf; 54 size_t phsize; 55 Ehdr *eh; 56 Phdr *ph0; 57 size_t dyn; 58 size_t tls_image; 59 60 void *dyn_map; 61 size_t dyn_map_len; 62 size_t *dyn_addr; 63 void *str_map; 64 size_t str_map_len; 65 char *str_addr; 66 struct tls_module tls; 67 }; 68 69 // dynamic array for loadtask 70 struct loadtasks { 71 struct loadtask **array; 72 size_t capacity; 73 size_t length; 74 }; 75 76 hidden void *add_handle_node(void *handle, struct dso *dso); 77 hidden struct dso *find_dso_by_handle(void *handle); 78 hidden void remove_handle_node(void *handle); 79 hidden void *assign_valid_handle(struct dso *p); 80 81 hidden struct loadtasks *create_loadtasks(void); 82 hidden bool append_loadtasks(struct loadtasks *tasks, struct loadtask *item); 83 hidden void free_task(struct loadtask *task); 84 hidden struct loadtask *get_loadtask(struct loadtasks *tasks, size_t index); 85 hidden void free_loadtasks(struct loadtasks *tasks); 86 hidden void shuffle_loadtasks(struct loadtasks *tasks); 87 hidden struct loadtask *create_loadtask(const char *name, struct dso *needed_by, ns_t *ns, bool check_inherited); 88 89 #ifdef __cplusplus 90 } 91 #endif 92 93 #endif