| 1 | /* $Id: resolver2.c 1545 2004-10-07 06:36:42Z bird $ */
|
|---|
| 2 | /** @file
|
|---|
| 3 | *
|
|---|
| 4 | * Lazy Import - resolver2.
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright (c) 2004 knut st. osmundsen <bird@innotek.de>
|
|---|
| 7 | *
|
|---|
| 8 | *
|
|---|
| 9 | * This file is part of InnoTek LIBC.
|
|---|
| 10 | *
|
|---|
| 11 | * InnoTek LIBC is free software; you can redistribute it and/or modify
|
|---|
| 12 | * it under the terms of the GNU Lesser General Public License as published
|
|---|
| 13 | * by the Free Software Foundation; either version 2 of the License, or
|
|---|
| 14 | * (at your option) any later version.
|
|---|
| 15 | *
|
|---|
| 16 | * InnoTek LIBC is distributed in the hope that it will be useful,
|
|---|
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 19 | * GNU Lesser General Public License for more details.
|
|---|
| 20 | *
|
|---|
| 21 | * You should have received a copy of the GNU Lesser General Public License
|
|---|
| 22 | * along with InnoTek LIBC; if not, write to the Free Software
|
|---|
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|---|
| 24 | *
|
|---|
| 25 | */
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 | /*******************************************************************************
|
|---|
| 29 | * Header Files *
|
|---|
| 30 | *******************************************************************************/
|
|---|
| 31 | #include <386/builtin.h>
|
|---|
| 32 | #include <dlfcn.h>
|
|---|
| 33 | #include <unistd.h>
|
|---|
| 34 | #include <string.h>
|
|---|
| 35 | #include <stdlib.h>
|
|---|
| 36 |
|
|---|
| 37 | void *__lazyimp_resolver2(unsigned uEAX, unsigned uEDX, unsigned uECX,
|
|---|
| 38 | void **ppvModule, const char *pszModule, void **ppvResolved, const char *pszSymbol);
|
|---|
| 39 |
|
|---|
| 40 | /**
|
|---|
| 41 | * This function is called by __lazyimp_resolver, and assembly worker.
|
|---|
| 42 | * __lazyimp_resolver was in turn called by a stub in the lazy import record.
|
|---|
| 43 | *
|
|---|
| 44 | * @returns Resolved address and *ppvModule and *ppvResovled set.
|
|---|
| 45 | */
|
|---|
| 46 | void *__lazyimp_resolver2(unsigned uEAX, unsigned uEDX, unsigned uECX,
|
|---|
| 47 | void **ppvModule, const char *pszModule, void **ppvResolved, const char *pszSymbol)
|
|---|
| 48 | {
|
|---|
| 49 | /*
|
|---|
| 50 | * Load the module.
|
|---|
| 51 | */
|
|---|
| 52 | void *pvModule;
|
|---|
| 53 | if (!(pvModule = *ppvModule))
|
|---|
| 54 | {
|
|---|
| 55 | pvModule = dlopen(pszModule, 0);
|
|---|
| 56 | if (!pvModule)
|
|---|
| 57 | {
|
|---|
| 58 | static char szMsg[] = "lazy import failure!\n\r";
|
|---|
| 59 | const char *pszErr = dlerror();
|
|---|
| 60 | write(2, szMsg, sizeof(szMsg) - 1);
|
|---|
| 61 | write(2, pszErr, strlen(pszErr));
|
|---|
| 62 | write(2, "\r\n", 2);
|
|---|
| 63 | abort();
|
|---|
| 64 | for (;;)
|
|---|
| 65 | exit(127);
|
|---|
| 66 | }
|
|---|
| 67 | __atomic_xchg((volatile unsigned *)ppvModule, (unsigned)pvModule);
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | /*
|
|---|
| 71 | * Resolve the symbol.
|
|---|
| 72 | */
|
|---|
| 73 | void *pvSym = dlsym(pvModule, pszSymbol);
|
|---|
| 74 | if (pvSym)
|
|---|
| 75 | {
|
|---|
| 76 | __atomic_xchg((volatile unsigned *)ppvResolved, (unsigned)pvSym);
|
|---|
| 77 | return pvSym;
|
|---|
| 78 | }
|
|---|
| 79 | else
|
|---|
| 80 | {
|
|---|
| 81 | static char szMsg[] = "lazy import failure!\n\r";
|
|---|
| 82 | const char *pszErr = dlerror();
|
|---|
| 83 | write(2, szMsg, sizeof(szMsg) - 1);
|
|---|
| 84 | write(2, pszErr, strlen(pszErr));
|
|---|
| 85 | write(2, "\r\n", 2);
|
|---|
| 86 | abort();
|
|---|
| 87 | for (;;)
|
|---|
| 88 | exit(127);
|
|---|
| 89 | }
|
|---|
| 90 | return 0;
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|