Changeset 106661 in vbox for trunk/src/VBox/Additions
- Timestamp:
- Oct 24, 2024 1:09:07 PM (3 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/3D/win/VBoxICD/icd_forwarders.py
r106658 r106661 1 #!/usr/bin/env python 2 # -*- coding: utf-8 -*- 3 # $Id$ 4 5 """ 6 Generates forwards from a .def file. 7 """ 8 9 __copyright__ = \ 1 10 """ 2 11 Copyright (C) 2018-2024 Oracle and/or its affiliates. … … 20 29 SPDX-License-Identifier: GPL-3.0-only 21 30 """ 31 __version__ = "$Revision$" 22 32 33 # Standard python imports""" 23 34 import sys 24 35 25 def GenerateForwarders(): 36 37 def GenerateForwarders(asArgs): 26 38 27 39 # Get list of functions. 28 exports_file = open(sys.argv[1], "r") 29 if not exports_file: 30 print("Error: couldn't open %s file!" % filename) 31 sys.exit() 40 asNames = [] 41 asParamSizes = [] 42 with open(asArgs[1], "r") as oInFile: 43 for line in oInFile.readlines(): 44 line = line.strip() 45 if len(line) > 0 and line[0] != ';' and line != 'EXPORTS': 46 # Parse 'glAccum = glAccum@8' 47 words = line.split('=', 1) 32 48 33 names = [] 34 cbArgs = [] 35 for line in exports_file.readlines(): 36 line = line.strip() 37 if len(line) > 0 and line[0] != ';' and line != 'EXPORTS': 38 # Parse 'glAccum = glAccum@8' 39 words = line.split('=', 1) 49 # Function name 50 asNames.append(words[0].strip()) 40 51 41 # Function name 42 names.append(words[0].strip()) 43 44 # Size of arguments in bytes 45 words = words[1].split('@') 46 cbArgs.append(words[1].strip()) 47 48 exports_file.close() 52 # Size of arguments in bytes 53 words = words[1].split('@') 54 asParamSizes.append(words[1].strip()) 49 55 50 56 … … 52 58 # Assembler forwarders 53 59 # 54 asm_file = open(sys.argv[2], "w") 55 if not asm_file: 56 print("Error: couldn't open %s file!" % filename) 57 sys.exit() 60 asLines = [ 61 '; AUTOGENERATED - DO NOT EDIT!', 62 '%include "iprt/asmdefs.mac"', 63 '', 64 ';;;; Enable ICD_LAZY_LOAD to lazy load the ICD DLL - bird 2024-10-24: it should work again now', 65 '; %define ICD_LAZY_LOAD 1', 66 '', 67 '%ifdef ICD_LAZY_LOAD', 68 'extern NAME(g_hmodICD)', 69 'extern NAME(VBoxLoadICD)', 70 '', 71 'BEGINPROC VBoxLoadICDWrapper' 72 ' ; Check if loaded', 73 ' mov xAX, [NAME(g_hmodICD) xWrtRIP]', 74 ' test xAX, xAX', 75 ' jz .needs_loading', 76 ' ret', 77 ' ; Save parameter registers', 78 '.needs_loading:', 79 ' %ifdef RT_ARCH_AMD64', 80 ' push rcx', 81 ' push rdx', 82 ' push r8', 83 ' push r9', 84 ' %ifdef ASM_CALL64_GCC', 85 ' push rsi', 86 ' push rdi', 87 ' sub rsp, 8h', 88 ' %else', 89 ' sub rsp, 28h', 90 ' %endif', 91 ' %endif', 92 ' call NAME(VBoxLoadICD)', 93 ' ; Restore parameter registers', 94 ' %ifdef RT_ARCH_AMD64', 95 ' %ifdef ASM_CALL64_GCC', 96 ' add rsp, 8h', 97 ' pop rdi', 98 ' pop rsi', 99 ' %else', 100 ' add rsp, 28h', 101 ' %endif', 102 ' pop r9', 103 ' pop r8', 104 ' pop rdx', 105 ' pop rcx', 106 ' %endif', 107 ' ret', 108 'ENDPROC VBoxLoadICDWrapper', 109 '%endif ; ICD_LAZY_LOAD', 110 ]; 58 111 59 asm_file.write('; AUTOGENERATED - DO NOT EDIT!\n') 60 asm_file.write('%include "iprt/asmdefs.mac"\n') 61 asm_file.write('\n') 62 asm_file.write(';;;; Enable ICD_LAZY_LOAD to lazy load the ICD DLL (does not work on Win64)\n') 63 asm_file.write('; %define ICD_LAZY_LOAD 1\n') 64 asm_file.write('\n') 65 asm_file.write('%ifdef ICD_LAZY_LOAD\n') 66 asm_file.write('extern NAME(VBoxLoadICD)\n') 67 asm_file.write('%endif\n') 68 asm_file.write('extern NAME(g_hmodICD)\n') 112 for index in range(len(asNames)): 113 sFnNm = asNames[index] 114 cbRet = asParamSizes[index] 115 asLines.extend([ 116 '', 117 'BEGINPROC_EXPORTED %s' % sFnNm, 118 ' extern NAME(pfn_%s)' % sFnNm, 119 '; int3', 120 '%ifdef ICD_LAZY_LOAD', 121 ' call VBoxLoadICDWrapper', 122 '%endif', 123 ' mov xAX, [NAME(pfn_%s) xWrtRIP]' % sFnNm, 124 ' test xAX, xAX', 125 ' jz .return', 126 ' jmp xAX', 127 '.return:', 128 '%ifdef RT_ARCH_AMD64', 129 ' ret', 130 '%else ; X86', 131 ' ret %s' % cbRet, 132 '%endif', 133 'ENDPROC %s' % sFnNm, 134 ]); 69 135 70 for index in range(len(names)): 71 fn = names[index] 72 cbRet = cbArgs[index] 73 asm_file.write('\n') 74 asm_file.write('BEGINPROC_EXPORTED %s\n' % fn) 75 asm_file.write(' extern NAME(pfn_%s)\n' % fn) 76 asm_file.write('; int3\n') 77 asm_file.write('%ifdef ICD_LAZY_LOAD\n') 78 asm_file.write(' mov xAX, [NAME(g_hmodICD) xWrtRIP]\n') 79 asm_file.write(' test xAX, xAX\n') 80 asm_file.write(' jnz .already_loaded\n') 81 asm_file.write(' call NAME(VBoxLoadICD)\n') 82 asm_file.write('.already_loaded:\n') 83 asm_file.write('%endif\n') 84 asm_file.write(' mov xAX, [NAME(pfn_%s) xWrtRIP]\n' % fn) 85 asm_file.write(' test xAX, xAX\n') 86 asm_file.write(' jz .return\n') 87 asm_file.write(' jmp xAX\n') 88 asm_file.write('.return:\n') 89 asm_file.write('%ifdef RT_ARCH_AMD64\n') 90 asm_file.write(' ret\n') 91 asm_file.write('%else ; X86\n') 92 asm_file.write(' ret %s\n' % cbRet) 93 asm_file.write('%endif\n') 94 asm_file.write('ENDPROC %s\n' % fn) 136 # 137 # Write it out. 138 # 139 with open(asArgs[2], "w") as oOutFile: 140 oOutFile.write('\n'.join(asLines)); 95 141 96 asm_file.close()142 return 0; 97 143 98 GenerateForwarders() 144 if __name__ == '__main__': 145 sys.exit(GenerateForwarders(sys.argv)); 146
Note:
See TracChangeset
for help on using the changeset viewer.