about summary refs log tree commit diff stats
path: root/src/librarian/library_private.h
blob: ebe4d027fc004e03c4c844f7e93bae9692f8c451 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#ifndef __LIBRARY_PRIVATE_H_
#define __LIBRARY_PRIVATE_H_
#include <stdint.h>
#include <elf.h>

#include "custommem.h"
#include "khash.h"
#include "wrappedlibs.h"
#include "box64context.h"

typedef struct lib_s    lib_t;
typedef struct bridge_s bridge_t;
typedef struct kh_bridgemap_s kh_bridgemap_t;
typedef struct kh_mapsymbols_s kh_mapsymbols_t;

typedef struct x64emu_s x64emu_t;
typedef void (*wrapper_t)(x64emu_t* emu, uintptr_t fnc);

typedef struct symbol2_s {
    wrapper_t    w;
    const char*  name;
    int          weak;
} symbol2_t;

KHASH_MAP_DECLARE_STR(symbolmap, wrapper_t)
KHASH_MAP_DECLARE_STR(symbol2map, symbol2_t)
KHASH_MAP_DECLARE_STR(datamap, uint64_t)


#ifndef MAX_PATH
#define MAX_PATH 4096
#endif

typedef struct wlib_s {
    bridge_t        *bridge;
    void*           lib;        // dlopen result
    void*           priv;       // actual private
    void*           box64lib;   // ref to the dlopen on box64 itself from context
    char*           altprefix;  // if function names are mangled..
    int             needed;
    char**          neededlibs;
} wlib_t;

typedef struct nlib_s {
    int             elf_index;
    int             finalized;
    kh_mapsymbols_t *mapsymbols;
    kh_mapsymbols_t *weaksymbols;
    kh_mapsymbols_t *localsymbols;
} nlib_t;

typedef struct library_s {
    char*               name;   // <> path
    char*               path;   // original path
    int                 nbdot;  // nombre of "." after .so
    int                 type;   // 0: native(wrapped) 1: emulated(elf) -1: undetermined
    int                 active;
    wrappedlib_fini_t   fini;
    wrappedlib_get_t    get;        // get weak and no weak
    wrappedlib_get_t    getnoweak;  // get only non weak symbol
    wrappedlib_get_t    getlocal;
    union {
        wlib_t  w;     
        nlib_t  n;
    }                   priv;       // private lib data
    box64context_t      *context;   // parent context
    kh_bridgemap_t      *bridgemap;
    kh_symbolmap_t      *symbolmap;
    kh_symbolmap_t      *wsymbolmap;
    kh_symbolmap_t      *mysymbolmap;
    kh_symbolmap_t      *wmysymbolmap;
    kh_symbolmap_t      *stsymbolmap;
    kh_symbol2map_t     *symbol2map;
    kh_datamap_t        *datamap;
    kh_datamap_t        *wdatamap;
    kh_datamap_t        *mydatamap;
    char                *altmy;     // to avoid duplicate symbol, like with SDL1/SDL2
    needed_libs_t       needed;
    needed_libs_t       depended;   // used to free library
    lib_t               *maplib;    // local maplib, for dlopen'd library with LOCAL binding (most of the dlopen)
} library_t;

// type for map elements
typedef struct map_onesymbol_s {
    const char* name;
    wrapper_t   w;
    int         weak;
} map_onesymbol_t;
typedef struct map_onesymbol2_s {
    const char* name;
    wrapper_t   w;
    int         weak;
    const char* name2;
} map_onesymbol2_t;
typedef struct map_onedata_s {
    const char* name;
    uint32_t    sz;                 // TODO: convert to size_t
    int         weak;
} map_onedata_t;

int getSymbolInMaps(library_t *lib, const char* name, int noweak, uintptr_t *addr, uintptr_t *size, int version, const char* vername, int local);  // Add bridges to functions

typedef struct linkmap_s {
    // actual struct link_map
    Elf64_Addr  l_addr;
    char*       l_name;
    Elf64_Dyn*  l_ld;
    struct linkmap_s *l_next, *l_prev;
    // custom
    library_t*  l_lib;

} linkmap_t;

linkmap_t* getLinkMapLib(library_t* lib);
linkmap_t* addLinkMapLib(library_t* lib);
void removeLinkMapLib(library_t* lib);

#endif //__LIBRARY_PRIVATE_H_