OSDN Git Service

Correct project name references in mingwrt source files.
[mingw/mingw-org-wsl.git] / mingwrt / mingwex / jmpstub.sx
1 /*
2  * jmpstub.sx
3  *
4  * Generic trampoline, mapping any conventional function name to the entry
5  * point for an implementation within the "__mingw_" pseudo-namespace.
6  *
7  * $Id$
8  *
9  * Written by Keith Marshall <keith@users.osdn.me>
10  * Copyright (C) 2013, 2014, 2017, 2022, MinGW.OSDN Project
11  *
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining a
14  * copy of this software and associated documentation files (the "Software"),
15  * to deal in the Software without restriction, including without limitation
16  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17  * and/or sell copies of the Software, and to permit persons to whom the
18  * Software is furnished to do so, subject to the following conditions:
19  *
20  * The above copyright notice and this permission notice (including the next
21  * paragraph) shall be included in all copies or substantial portions of the
22  * Software.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30  * DEALINGS IN THE SOFTWARE.
31  *
32  *
33  * This file implements a generic trampoline stub, which remaps a specified
34  * function, via a CPU "jmp" instruction, to an alternative entry point; it
35  * may be compiled using a command such as:
36  *
37  *   $(CC) -c $(CPPFLAGS) -D FUNCTION=funcname -o funcname.o jmpstub.sx
38  *
39  * to create a free standing object module, providing a physically addressable
40  * entry point for __CRT_ALIAS function, "funcname".  (Note that any version of
41  * GCC predating GCC-4.3 may also require the "-x assembler-with-cpp" option).
42  *
43  * By default, the generated stub redirects calls to function "funcname()",
44  * such that they invoke the equivalent library function, with entry point at
45  * "__mingw_funcname()"; this default may be overriden, by specification of
46  * an additional "-D REMAPPED=entryname" option, resulting in redirection
47  * of "funcname()" calls to the "entryname()" function entry point.
48  *
49  * Alternatively, calls to "funcname()" may be redirected to a DLL entry point,
50  * via its importable name within the DLL's export table, by specification of
51  * the "-D DLLENTRY=entryname" option, instead of "-D REMAPPED=entryname".
52  *
53  */
54 #define __entry__(__suffix__)  __label__(_,__suffix__)
55 #define __label__(__prefix__,__suffix__)  __prefix__##__suffix__
56
57 #if defined LLENTRY && ! defined DLLENTRY
58 /* This is a convenience for users; it allows specification of a DLLENTRY
59  * option as simply "-DLLENTRY=entryname", as an alternative to specifying
60  * it fully, as "-D DLLENTRY=entryname".
61  */
62 #define DLLENTRY  LLENTRY
63 #endif
64
65 .text
66 #ifdef DLLENTRY
67  /* This represents the case of redirection to a function implementation
68   * residing within a DLL...
69   */
70 # define __dllentry__(__suffix__)  __label__(__imp__,__suffix__)
71 # define __redirect__  *__dllentry__(DLLENTRY)
72
73 #else
74  /* ...whereas this redirection to an alternative static library function,
75   * or to a DLL implementation accessed via an import library trampoline.
76   */
77 # ifndef REMAPPED
78   /* No explicit entry point redirection specified; use the default entry
79    * point name, within the "__mingw_" pseudo-namespace.
80    */
81 #  define __mingw__(__suffix__)  __label__(__mingw_,__suffix__)
82 #  define REMAPPED  __mingw__(FUNCTION)
83 # endif
84 # define __redirect__  __entry__(REMAPPED)
85 .def    __entry__(REMAPPED); .scl 2; .type 32; .endef
86 #endif
87
88 .global __entry__(FUNCTION)
89 .def    __entry__(FUNCTION); .scl 2; .type 32; .endef
90
91 __entry__(FUNCTION): jmp __redirect__
92
93 /* $RCSfile$: end of file */