• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     // variables for segment header
61     void *shdr_allocated_buf;
62     size_t shsize;
63 
64     void *dyn_map;
65     size_t dyn_map_len;
66     size_t *dyn_addr;
67     void *str_map;
68     size_t str_map_len;
69     char *str_addr;
70     struct tls_module tls;
71 };
72 
73 // dynamic array for loadtask
74 struct loadtasks {
75     struct loadtask **array;
76     size_t capacity;
77     size_t length;
78 };
79 
80 hidden void *add_handle_node(void *handle, struct dso *dso);
81 hidden struct dso *find_dso_by_handle(void *handle);
82 hidden void remove_handle_node(void *handle);
83 hidden void *assign_valid_handle(struct dso *p);
84 
85 hidden struct loadtasks *create_loadtasks(void);
86 hidden bool append_loadtasks(struct loadtasks *tasks, struct loadtask *item);
87 hidden void free_task(struct loadtask *task);
88 hidden struct loadtask *get_loadtask(struct loadtasks *tasks, size_t index);
89 hidden void free_loadtasks(struct loadtasks *tasks);
90 hidden void shuffle_loadtasks(struct loadtasks *tasks);
91 hidden struct loadtask *create_loadtask(const char *name, struct dso *needed_by, ns_t *ns, bool check_inherited);
92 
93 #ifdef __cplusplus
94 }
95 #endif
96 
97 #endif