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
|
"""
Copyright (C) 2018-2023 Oracle and/or its affiliates.
This file is part of VirtualBox base platform packages, as
available from https://www.virtualbox.org.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation, in version 3 of the
License.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see <https://www.gnu.org/licenses>.
SPDX-License-Identifier: GPL-3.0-only
"""
import sys
def GenerateForwarders():
# Get list of functions.
exports_file = open(sys.argv[1], "r")
if not exports_file:
print("Error: couldn't open %s file!" % filename)
sys.exit()
names = []
cbArgs = []
for line in exports_file.readlines():
line = line.strip()
if len(line) > 0 and line[0] != ';' and line != 'EXPORTS':
# Parse 'glAccum = glAccum@8'
words = line.split('=', 1)
# Function name
names.append(words[0].strip())
# Size of arguments in bytes
words = words[1].split('@')
cbArgs.append(words[1].strip())
exports_file.close()
#
# Assembler forwarders
#
asm_file = open(sys.argv[2], "w")
if not asm_file:
print("Error: couldn't open %s file!" % filename)
sys.exit()
asm_file.write('%include "iprt/asmdefs.mac"\n')
asm_file.write('\n')
asm_file.write(';;;; Enable ICD_LAZY_LOAD to lazy load the ICD DLL (does not work on Win64)\n')
asm_file.write('; %define ICD_LAZY_LOAD 1\n')
asm_file.write('\n')
asm_file.write('%ifdef RT_ARCH_AMD64\n')
asm_file.write('%define PTR_SIZE_PREFIX qword\n')
asm_file.write('%else ; X86\n')
asm_file.write('%define PTR_SIZE_PREFIX dword\n')
asm_file.write('%endif\n')
asm_file.write('\n')
asm_file.write('%ifdef ICD_LAZY_LOAD\n')
asm_file.write('extern NAME(VBoxLoadICD)\n')
asm_file.write('%endif\n')
asm_file.write('extern NAME(g_hmodICD)\n')
for index in range(len(names)):
fn = names[index]
cbRet = cbArgs[index]
asm_file.write('\n')
asm_file.write('BEGINPROC_EXPORTED %s\n' % fn)
asm_file.write(' extern NAME(pfn_%s)\n' % fn)
asm_file.write('; int3\n')
asm_file.write('%ifdef ICD_LAZY_LOAD\n')
asm_file.write(' mov xAX, PTR_SIZE_PREFIX NAME(g_hmodICD)\n')
asm_file.write(' mov xAX, [xAX]\n')
asm_file.write(' or xAX, xAX\n')
asm_file.write(' jnz l_icd_loaded_%s\n' % fn)
asm_file.write(' call NAME(VBoxLoadICD)\n')
asm_file.write('l_icd_loaded_%s:\n' % fn)
asm_file.write('%endif\n')
asm_file.write(' mov xAX, PTR_SIZE_PREFIX NAME(pfn_%s)\n' % fn)
asm_file.write(' mov xAX, [xAX]\n')
asm_file.write(' or xAX, xAX\n')
asm_file.write(' jnz l_jmp_to_%s\n' % fn)
asm_file.write('%ifdef RT_ARCH_AMD64\n')
asm_file.write(' ret\n')
asm_file.write('%else ; X86\n')
asm_file.write(' ret %s\n' % cbRet)
asm_file.write('%endif\n')
asm_file.write('l_jmp_to_%s:\n' % fn)
asm_file.write(' jmp xAX\n')
asm_file.write('ENDPROC %s\n' % fn)
asm_file.close()
GenerateForwarders()
|