Skip to content

Commit 8ef8151

Browse files
Fix ordinal imports on Windows. (#54808)
Co-authored-by: madewokherd <madewokherd@users.noreply.github.com>
1 parent db9c3f1 commit 8ef8151

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/mono/mono/metadata/native-library.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,16 +1098,6 @@ pinvoke_probe_for_symbol (MonoDl *module, MonoMethodPInvoke *piinfo, const char
10981098

10991099
g_assert (error_msg_out);
11001100

1101-
#ifdef HOST_WIN32
1102-
if (import && import [0] == '#' && isdigit (import [1])) {
1103-
char *end;
1104-
long id;
1105-
1106-
id = strtol (import + 1, &end, 10);
1107-
if (id > 0 && *end == '\0')
1108-
import++;
1109-
}
1110-
#endif
11111101
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_DLLIMPORT,
11121102
"Searching for '%s'.", import);
11131103

src/mono/mono/utils/mono-dl-windows.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,21 @@ mono_dl_lookup_symbol (MonoDl *module, const char *symbol_name)
157157

158158
/* get the symbol directly from the specified module */
159159
if (!module->main_module)
160+
{
161+
if (symbol_name[0] == '#')
162+
{
163+
/* lookup by ordinal */
164+
unsigned long ord;
165+
char *end;
166+
167+
ord = strtoul(symbol_name + 1, &end, 10);
168+
169+
if (*end == '\0' && ord > 0 && ord < 65536)
170+
symbol_name = (const char*)(uintptr_t)ord;
171+
}
172+
160173
return (void*)GetProcAddress ((HMODULE)module->handle, symbol_name);
174+
}
161175

162176
/* get the symbol from the main module */
163177
proc = (gpointer)GetProcAddress ((HMODULE)module->handle, symbol_name);

0 commit comments

Comments
 (0)