Changeset 2021 for trunk


Ignore:
Timestamp:
Jun 13, 2005, 4:16:10 AM (20 years ago)
Author:
bird
Message:

o Changed the LIBC_PATHREADWRITERS to a generic LIBC_HOOK_DLLS.

See src/emx/src/lib/sys/hooks.c for details.

Location:
trunk/src/emx
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/ChangeLog.LIBC

    • Property cvs2svn:cvs-rev changed from 1.53 to 1.54
    r2020 r2021  
    11/* $Id$ */
     2
     32005-06-12: knut st. osmundsen <bird-gccos2-spam@anduin.net>
     4    - libc:
     5        o Changed the LIBC_PATHREADWRITERS to a generic LIBC_HOOK_DLLS.
     6          See src/emx/src/lib/sys/hooks.c for details.
    27
    382005-06-11: knut st. osmundsen <bird-gccos2-spam@anduin.net>
  • trunk/src/emx/include/InnoTekLIBC/pathrewrite.h

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r2020 r2021  
    44 * InnoTek LIBC - Path Rewrite.
    55 *
    6  * Copyright (c) 2004 knut st. osmundsen <bird-srcspam@anduin.net>
     6 * Copyright (c) 2004-2005 knut st. osmundsen <bird-srcspam@anduin.net>
    77 *
    88 *
     
    5757    /** Length of to path. */
    5858    unsigned        cchTo;
     59    /** Reserved 0 - intended for function pointer to special open. */
     60    unsigned        uReserved0;
     61    /** Reserved 1 - intended for function pointer to special parser. */
     62    unsigned        uReserved1;
     63    /** Reserved 2 - 8 byte alignment*/
     64    unsigned        uReserved2;
    5965} __LIBC_PATHREWRITE, *__LIBC_PPATHREWRITE;
    6066
  • trunk/src/emx/src/lib/startup/386/dll0.s

    • Property cvs2svn:cvs-rev changed from 1.15 to 1.16
    r2020 r2021  
    8181do_init:
    8282#endif
     83    pushl   4(%esp)
    8384    pushl   $(FLAG_HIGHMEM + FLAG_NOUNIX)
    8485    call    ___init_dll
    85     add     $4, %esp
     86    add     $8, %esp
    8687    orl     %eax, %eax
    8788    jz      do_initterm
  • trunk/src/emx/src/lib/startup/startup.c

    • Property cvs2svn:cvs-rev changed from 1.13 to 1.14
    r2020 r2021  
    6868 *              - __libc_fhInit() will call _hmalloc() and a number of OS/2 APIs
    6969 *                to figure out what handles was inherited.
     70 *          - __init_dll checks for LIBC_HOOK_DLLS and calls __libc_back_hooksInit()
     71 *                to process it if it is present in the environment.
    7072 *          - __init_dll then intializes _sys_clock0_ms with the current MS count.
    7173 *      - dll0.s calls _DLL_InitTerm in startup/dllinit.c.
  • trunk/src/emx/src/lib/sys/__init.c

    • Property cvs2svn:cvs-rev changed from 1.21 to 1.22
    r2020 r2021  
    184184     * Then end the heap voting.
    185185     */
    186     if (__init_dll(fFlags))
     186    if (__init_dll(fFlags, 0))
    187187        goto failure;
    188188
  • trunk/src/emx/src/lib/sys/__initdll.c

    • Property cvs2svn:cvs-rev changed from 1.20 to 1.21
    r2020 r2021  
    3636#include "b_fs.h"
    3737#include "b_signal.h"
     38#include "backend.h"
    3839#include <InnoTekLIBC/thread.h>
    3940#include <InnoTekLIBC/libc.h>
     
    8990 *                         If clear all unix like features are enabled.
    9091 *                  Passed on to __init_dll().
    91  */
    92 int __init_dll(int fFlags)
     92 * @param   hmod    The handle of the calling module. This is 0 when we're called from crt0.s.
     93 *                  If we're not already initialized, this will be the handle of the libc dll.
     94 */
     95int __init_dll(int fFlags, unsigned long hmod)
    9396{
    9497    ULONG               aul[2];
     
    213216        return -1;
    214217    }
     218
     219    /*
     220     * Load and call hook DLLs.
     221     */
     222    const char *psz = getenv("LIBC_HOOK_DLLS");
     223    if (psz)
     224        __libc_back_hooksInit(psz, hmod);
    215225
    216226    /*
  • trunk/src/emx/src/lib/sys/backend.h

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r2020 r2021  
    4747int __libc_native2errno(unsigned long rc);
    4848
     49/**
     50 * Initializes the various LIBC hooks using the given
     51 * specification string.
     52 */
     53void __libc_back_hooksInit(const char *pszSpec, unsigned long hmod);
    4954
    5055__END_DECLS
  • trunk/src/emx/src/lib/sys/pathrewrite.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r2020 r2021  
    2626
    2727
    28 /** @page PathRewrite   Path Rewrite Feature
     28/** @page pg_pathRewrite   Path Rewrite Feature
    2929 *
    3030 * The Path Rewrite Feature was designed as a replacement for the hardcoded
    3131 * mapping of /dev/null to nul and /dev/tty to con in __open.c. It allows
    32  * the user of LIBC to automatically rewrite (map) paths given to LIBC APIS.
     32 * the user of LIBC to automatically rewrite (map) paths given to LIBC APIs.
    3333 * The user can dynamically add and remove rewrite rules. The environment
    34  * variable LIBC_PATHREWRITERS can be used to dynamically load DLLs containing
    35  * rewrite rules and add it to the process.
    36  *
    37  *
    38  * @subsection  LIBC_PATHREWRITERS
    39  *
    40  * The format is <dllname>@<export>. LIBC will load <dllname>, resolve <export>
    41  * and call <export> with pointers to the three __libc_PathRewrite interfaces.
    42  * The <export> function will then register and remove rules as it pleases it.
    43  * Single of double quotes can be applied to the <dllname>. Multiple rewriters
    44  * must be separated by space.
    45  *
    46  * Examples:
    47  *      set LIBC_PATHREWRITERS=prwhome.dll@_instprws
    48  *      set LIBC_PATHREWRITERS=/usr/lib/prwhome.dll@_instprws
    49  *      set LIBC_PATHREWRITERS="c:\My Plugins\prwhome.dll"@_instprws
    50  *      set LIBC_PATHREWRITERS=prwhome@_insthomeprws prwhome@_instetcprws
     34 * variable LIBC_HOOK_DLLS can be used to dynamically load DLLs containing
     35 * rewrite rules and add it to the process. See \ref pg_hooks for further
     36 * details.
    5137 */
    5238
     
    207193
    208194
    209 /** Flag which tells if we're initialized or not. */
    210 static int gfInited;
    211 
    212195/*******************************************************************************
    213196*   Internal Functions                                                         *
    214197*******************************************************************************/
    215198static void __libc_pathRewriteDeleteDir(PDIRECTORY pDir);
    216 static void __libc_pathRewriteInit(void);
    217 /* static void __libc_pathRewriteTerm(void); */
    218 
    219 _CRT_INIT1(__libc_pathRewriteInit)
    220 
    221 /**
    222  * Init rewriters if LIBC_PATHREWRITERS contains anything useful.
    223  * @remark  Cannot be static as GCC will optimize it away then.
    224  */
    225 static void __libc_pathRewriteInit(void)
    226 {
    227     static void *pfnDummy = __libc_pathRewriteInit;
    228     LIBCLOG_ENTER("\n");
    229     if (gfInited)
    230         LIBCLOG_RETURN_VOID();
    231     gfInited = 1;
    232 
    233     /*
    234      * Check for the presense of the variable.
    235      */
    236     const char *psz = getenv("LIBC_PATHREWRITERS");
    237     if (!psz || !*psz)
    238         LIBCLOG_RETURN_MSG_VOID("no rewriters\n");
    239 
    240     /*
    241      * Parse the variable.
    242      */
    243     for (;;)
    244     {
    245         char        chQuote;
    246         const char *pszDll;
    247         const char *pszDllEnd;
    248         const char *pszSym;
    249         const char *pszSymEnd;
    250         char        szSym[CCHMAXPATH];
    251         char        szDll[CCHMAXPATH];
    252         HMODULE     hmod;
    253         APIRET      rc;
    254 
    255         /*
    256          * Trimming off blanks.
    257          */
    258         while ((chQuote = *psz) == ' ' || chQuote == '\t' || chQuote == ';')
    259             psz++;
    260         if (!chQuote)
    261             break;
    262 
    263         /*
    264          * Check for quotes and find the end of the spec.
    265          */
    266         if (chQuote != '\'' && chQuote != '"')
    267         {
    268             pszDll = psz;
    269             chQuote = 0;
    270             pszDllEnd = strpbrk(psz, " \t;@");
    271             if (!pszDllEnd)
    272             {
    273                 LIBC_ASSERTM_FAILED("missformed dll specification; '%s'\n", psz);
    274                 LIBCLOG_RETURN_MSG_VOID("ret void. bad spec (1)! stopped parsing!\n");
    275             }
    276             pszSym = pszDllEnd;
    277         }
    278         else
    279         {   /* quoted */
    280             pszDll = psz + 1;
    281             pszDllEnd = strchr(pszDll, chQuote);
    282             if (!pszDllEnd)
    283             {
    284                 LIBC_ASSERTM_FAILED("mismatching quotes '%s'\n", psz);
    285                 LIBCLOG_RETURN_MSG_VOID("ret void. bad spec (2)! stopped parsing!\n");
    286             }
    287             pszSym = pszDllEnd + 1;
    288         }
    289 
    290         if (*pszSym != '@' || pszSym[1] == ' ' || pszSym[1] == '\t' || pszSym[1] == '\0')
    291         {
    292             LIBC_ASSERTM_FAILED("missformed export specification; '%s'\n", psz);
    293             LIBCLOG_RETURN_MSG_VOID("ret void. bad spec (3)! stopped parsing!\n");
    294         }
    295         pszSym++;
    296         pszSymEnd = strpbrk(pszSym, " \t;@'\"");
    297         if (!pszSymEnd)
    298             pszSymEnd = strchr(pszSym, '\0');
    299 
    300         if (pszDllEnd - pszDll >= sizeof(szDll))
    301         {
    302             LIBC_ASSERTM_FAILED("dll name is too long! %d bytes ; '%s'\n", pszDllEnd - pszDll, psz);
    303             LIBCLOG_RETURN_MSG_VOID("ret void. bad spec (4)! stopped parsing!\n");
    304         }
    305 
    306         if (pszSymEnd - pszSym >= sizeof(szSym))
    307         {
    308             LIBC_ASSERTM_FAILED("symbol name is too long! %d bytes ; '%s'\n", pszSymEnd - pszSym, psz);
    309             LIBCLOG_RETURN_MSG_VOID("ret void. bad spec (4)! stopped parsing!\n");
    310         }
    311 
    312         /*
    313          * Load the DLL.
    314          */
    315         memcpy(szDll, pszDll, pszDllEnd - pszDll);
    316         szDll[pszDllEnd - pszDll] = '\0';
    317         #if defined(DEBUG_LOGGING) || defined(__LIBC_STRICT)
    318         rc = DosLoadModule((PSZ)szSym, sizeof(szSym), (PCSZ)szDll, &hmod);
    319         #else
    320         rc = DosLoadModule(NULL, 0, (PCSZ)szDll, &hmod);
    321         #endif
    322         if (!rc)
    323         {
    324             void (*pfnRewriter)(int (*pfnAdd)(), int (*pfnRemove)(), int (*pfnRewrite)());
    325 
    326             /*
    327              * Resolve the symbol.
    328              */
    329             memcpy(szSym, pszSym, pszSymEnd - pszSym);
    330             szSym[pszSymEnd - pszSym] = '\0';
    331             rc = DosQueryProcAddr(hmod, 0, (PSZ)szSym, (PFN*)(void *)&pfnRewriter);
    332             if (!rc)
    333             {
    334                 LIBCLOG_MSG("Successfully loaded and resolved rewriter '%s' in '%s' to %p\n",
    335                             szSym, szDll, (void*)pfnRewriter);
    336                 pfnRewriter(__libc_PathRewriteAdd, __libc_PathRewriteRemove, __libc_PathRewrite);
    337             }
    338             else
    339                 LIBC_ASSERTM_FAILED("Failed to resolve rewriter '%s' in '%s', rc=%lu\n", szSym, szDll, rc);
    340         }
    341         else
    342             LIBC_ASSERTM_FAILED("Failed to load rewriter '%s', rc=%lu szObj='%s'\n", szDll, rc, szSym);
    343 
    344         /*
    345          * Next part.
    346          */
    347         psz = pszSymEnd;
    348     }
    349 
    350     LIBCLOG_RETURN_VOID();
    351     pfnDummy = pfnDummy;
    352 }
    353 
    354 
    355 
    356 /** @todo proper cleanup for non process term. */
    357 #if 0
    358 void __libc_pathRewriteTerm(void)
    359 {
    360 
    361 }
    362 _CRT_TERM1(__libc_pathRewriteTerm);
    363 #endif
    364 
    365 
    366199
    367200/**
     
    553386    LIBCLOG_ENTER("paRules=%p cRules=%d\n", (void*)paRules, cRules);
    554387    int i;
    555 
    556     /* 'Random' init order forces this. :/ */
    557     if (!gfInited)
    558          __libc_pathRewriteInit();
    559388
    560389    /*
     
    699528    int i;
    700529
    701     /* 'Random' init order forces this. :/ */
    702     if (!gfInited)
    703          __libc_pathRewriteInit();
    704 
    705530    /*
    706531     * Validation.
     
    842667    const char         *psz;
    843668    const char         *pszBest;
    844 
    845     /* 'Random' init order forces this. :/ */
    846     if (!gfInited)
    847          __libc_pathRewriteInit();
    848669
    849670    /*
  • trunk/src/emx/src/lib/sys/syscalls.h

    • Property cvs2svn:cvs-rev changed from 1.15 to 1.16
    r2020 r2021  
    117117 * @{ */
    118118extern void             __init(int fFlags);
    119 extern int              __init_dll(int fFlags);
     119extern int              __init_dll(int fFlags, unsigned long hmod);
    120120extern void /*volatile*/_sys_init_ret(void *stack) __attribute__((__noreturn__));
    121121extern int              _sys_init_environ(const char *pszEnv);
Note: See TracChangeset for help on using the changeset viewer.