| {{/* |
| * Copyright (C) 2015 The Android Open Source Project |
| * |
| * 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. |
| */}} |
| |
| {{Include "cpp_common.tmpl"}} |
| {{Include "opengl32_exports.tmpl"}} |
| {{$ | Macro "opengl32_x64.asm" | Reflow 4 | Write "opengl32_x64.asm"}} |
| |
| {{/* |
| ------------------------------------------------------------------------------- |
| Entry point. |
| ------------------------------------------------------------------------------- |
| */}} |
| {{define "opengl32_x64.asm"}} |
| ; Copyright (C) 2015 The Android Open Source Project |
| ; |
| ; 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. |
| ¶ |
| ; This masm exposes trampoline functions for OpenGL 1.1 and WGL functions that |
| ; are expected to be exposed by OpenGL32.dll but not declared by the API files. |
| ¶ |
| ; Lazy resolve all functions, then trampoline to the resolved address |
| TRAMPOLINE macro FUNC, REAL» |
| local skip |
| public FUNC |
| extern REAL:proc |
| ¶ |
| «FUNC PROC» |
| mov eax, resolved |
| cmp eax, 0 |
| jnz skip |
| ; Function are not resolved, resolve now... |
| ¶ |
| ; Preserve arguments stored in registers (ecx, edx, r8 and r9) |
| push rcx |
| push rdx |
| push r8 |
| push r9 |
| ¶ |
| ; give resolve() the necessary 32 byte 'shadow space', and call resolve |
| sub rsp, 28h |
| call resolve |
| add rsp, 28h |
| ¶ |
| ; Reload argument registers |
| pop r9 |
| pop r8 |
| pop rdx |
| pop rcx |
| «skip:» |
| mov rax, [REAL] |
| mov rax, [rax] |
| jmp rax |
| «FUNC ENDP» |
| endm |
| « |
| ¶ |
| extern resolve:proc |
| extern resolved:SDWORD |
| ¶ |
| .CODE |
| {{/* This is the list of functions that OpenGL32.dll needs to export. */}} |
| {{$opengl32_exports := Strings (Macro "OpenGL32Exports") | SplitOn "\n"}} |
| |
| {{/* This is the list of functions that the spy exports. */}} |
| {{$api_exports := (ForEach (AllCommands $) "CmdName") | Strings "wglGetProcAddress"}} |
| |
| {{/* This is list of functions we need to create trampolines for. */}} |
| {{$trampolines := $opengl32_exports | FilterOut $api_exports}} |
| |
| {{range $f := $trampolines}} |
| TRAMPOLINE {{$f}}, real__{{$f}} |
| {{end}} |
| end |
| ¶ |
| {{end}} |