dlfcn_ext.h 2.8 KB
Newer Older
W
wangjiahui 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef DLFCN_EXT_H
#define DLFCN_EXT_H

#include <dlfcn.h>
W
wangjiahui 已提交
20
#include <stddef.h>
W
wangjiahui 已提交
21 22 23 24 25 26

#ifdef __cplusplus
extern "C" {
#endif

/* for dl_extinfo flag */
W
wangjiahui 已提交
27 28
#define DL_EXT_WRITE_RELRO 0x1
#define DL_EXT_USE_RELRO 0x2
W
wangjiahui 已提交
29
#define DL_EXT_RESERVED_ADDRESS_RECURSIVE 0x4
W
wangjiahui 已提交
30 31
#define DL_EXT_RESERVED_ADDRESS 0x8
#define DL_EXT_RESERVED_ADDRESS_HINT 0x10
W
wangjiahui 已提交
32 33

/** Mask of valid bits. */
W
wangjiahui 已提交
34 35 36
#define DL_EXT_VALID_FLAG_BITS                                                                             \
    (DL_EXT_WRITE_RELRO | DL_EXT_USE_RELRO | DL_EXT_RESERVED_ADDRESS_RECURSIVE | DL_EXT_RESERVED_ADDRESS | \
        DL_EXT_RESERVED_ADDRESS_HINT)
W
wangjiahui 已提交
37 38 39 40

typedef struct {
    int flag;
    int relro_fd;
W
wangjiahui 已提交
41 42
    void *reserved_addr;
    size_t reserved_size;
W
wangjiahui 已提交
43 44 45 46 47
} dl_extinfo;

/**
 * @brief Loads the dynamic shared object (shared library) file with the extended feature.
 *        If extinfo is NULL, it is equivalent to dlopen.
W
wangjiahui 已提交
48
 *        If DL_EXT_WRITE_RELRO is set in extinfo, the GNU RELRO section will be written to relro_fd and allowed to
W
wangjiahui 已提交
49
 *        reused by other process loading the same library at the same address.
W
wangjiahui 已提交
50
 *        IF DL_EXT_USE_RELRO is set in extinfo, the GNU RELRO section written in relro_fd will be reused.
W
wangjiahui 已提交
51 52 53 54 55 56 57
 * @param file Equivalent to the argument of dlopen.
 * @param mode Equivalent to the argument of dlopen.
 * @param extinfo Indicates the dl_extinfo struct.
 * @return Returns a non-NULL handle for the loaded object on success. On error returns NULL.
 */
void *dlopen_ext(const char *file, int mode, const dl_extinfo *extinfo);

X
XUBO 已提交
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
/**
  * @brief open dso in given namespace which has own lib search paths,
  *        when namespace is null, it's same to dlopen_ext().
  *        avoid using "default" as namespace, which is the default namespace.
  * @param Dl_namespace * Carry the naming information of the namespace.
  * @param char * the name of the so file you want to open.
  * @param int open file mode.
  *    -- RTLD_LAZY.
  *    -- RTLD_NOW.
  *    -- RTLD_NOLOAD.
  *    -- RTLD_NODELETE.
  *    -- RTLD_GLOBAL.
  *    -- RTLD_LOCAL.
  * @param dl_extinfo * indicates the dl_extinfo struct,include flag and relro_fd.
  * @return success: dynamic library handleoid,failed: NULL.
  * @retval none.
  */
void *dlopen_ns_ext(Dl_namespace *, const char *, int, const dl_extinfo *);

W
wangjiahui 已提交
77 78 79 80 81
#ifdef __cplusplus
}
#endif

#endif