1 /*
2 * %CopyrightBegin%
3 *
4 * Copyright Ericsson AB 1996-2018. All Rights Reserved.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * %CopyrightEnd%
19 */
20
21 #ifndef __EXPORT_H__
22 #define __EXPORT_H__
23
24 #include "sys.h"
25 #include "index.h"
26 #include "code_ix.h"
27
28 /*
29 ** Export entry
30 */
31
32 typedef struct export
33 {
34 void* addressv[ERTS_NUM_CODE_IX]; /* Pointer to code for function. */
35
36 ErtsCodeInfo info; /* MUST be just before beam[] */
37
38 /*
39 * beam[0]: This entry is 0 unless the 'addressv' field points to it.
40 * Threaded code instruction to load function
41 * (em_call_error_handler), execute BIF (em_apply_bif),
42 * or a breakpoint instruction (op_i_generic_breakpoint).
43 * beam[1]: Function pointer to BIF function (for BIFs only),
44 * or pointer to threaded code if the module has an
45 * on_load function that has not been run yet, or pointer
46 * to code if function beam[0] is a breakpoint instruction.
47 * Otherwise: 0.
48 */
49 BeamInstr beam[2];
50 } Export;
51
52
53 void init_export_table(void);
54 void export_info(fmtfn_t, void *);
55
56 ERTS_GLB_INLINE Export* erts_active_export_entry(Eterm m, Eterm f, unsigned a);
57 Export* erts_export_put(Eterm mod, Eterm func, unsigned int arity);
58
59 Export* erts_export_get_or_make_stub(Eterm, Eterm, unsigned);
60
61 Export *export_list(int,ErtsCodeIndex);
62 int export_list_size(ErtsCodeIndex);
63 int export_table_sz(void);
64 int export_entries_sz(void);
65 Export *export_get(Export*);
66 void export_start_staging(void);
67 void export_end_staging(int commit);
68
69 extern erts_mtx_t export_staging_lock;
70 #define export_staging_lock() erts_mtx_lock(&export_staging_lock)
71 #define export_staging_unlock() erts_mtx_unlock(&export_staging_lock)
72
73 #include "beam_load.h" /* For em_* extern declarations */
74 #define ExportIsBuiltIn(EntryPtr) \
75 (((EntryPtr)->addressv[erts_active_code_ix()] == (EntryPtr)->beam) && \
76 (BeamIsOpCode((EntryPtr)->beam[0], op_apply_bif)))
77
78 #if ERTS_GLB_INLINE_INCL_FUNC_DEF
79
80 ERTS_GLB_INLINE Export*
erts_active_export_entry(Eterm m,Eterm f,unsigned int a)81 erts_active_export_entry(Eterm m, Eterm f, unsigned int a)
82 {
83 extern Export* erts_find_export_entry(Eterm m, Eterm f, unsigned a, ErtsCodeIndex);
84 return erts_find_export_entry(m, f, a, erts_active_code_ix());
85 }
86
87 #endif /* ERTS_GLB_INLINE_INCL_FUNC_DEF */
88
89 #endif /* __EXPORT_H__ */
90
91