dlfcn_ext.h 2.1 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 58 59 60 61 62
 * @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);

#ifdef __cplusplus
}
#endif

#endif