Changeset 1676


Ignore:
Timestamp:
Dec 2, 2004, 2:42:51 AM (21 years ago)
Author:
bird
Message:

Fixed fork() problem by adding DosLoadModuleEx and DosFreeModuleEx. (also fixed heap problem)

Location:
trunk/src/emx
Files:
2 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/include/emx/startup.h

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1675 r1676  
    88#endif
    99
    10 extern int  _CRT_init (void);
    11 extern void _CRT_term (void);
    12 extern void __ctordtorInit (void);
    13 extern void __ctordtorTerm (void);
     10extern int  _CRT_init(void);
     11extern void _CRT_term(void);
     12extern void __ctordtorInit(void);
     13extern void __ctordtorTerm(void);
     14
     15extern void __ctordtorInit1(int *);
     16extern void __ctordtorTerm1(int *);
     17
     18/** init and term vectors.
     19 * @{
     20 */
     21/** Array of CRT init functions. */
     22extern int __crtinit1__;
     23/** Array of CRT exit functions. */
     24extern int __crtexit1__;
     25/** Array of exception handlers something. */
     26extern int __eh_init__;
     27/** Array of exception handlers something. */
     28extern int __eh_term__;
     29/** Array of constructors. */
     30extern int __CTOR_LIST__;
     31/** Array of destructors. */
     32extern int __DTOR_LIST__;
     33/** @} */
     34
    1435
    1536/* argv[i][-1] contains some flag bits: */
  • trunk/src/emx/include/os2emx.h

    • Property cvs2svn:cvs-rev changed from 1.25 to 1.26
    r1675 r1676  
    1352913529APIRET APIENTRY DosCloseEventSemEx(HEV hev);
    1353013530
     13531/**
     13532 * Extended DosLoadModule() which will make sure the loaded module is
     13533 * loaded in a forked process.
     13534 */
     13535APIRET APIENTRY DosLoadModuleEx(PSZ pszObject, ULONG cbObject, PCSZ pszModule, PHMODULE phmod);
     13536
     13537/**
     13538 * Free module loaded using the extended APIs.
     13539 */
     13540APIRET APIENTRY DosFreeModuleEx(HMODULE hmod);
     13541
     13542
    1353113543#ifdef INCL_EXAPIS_MAPPINGS
    1353213544
     
    1354213554#define DosCloseEventSem(a)        DosCloseEventSemEx((a))
    1354313555
     13556#define DosLoadModule(a,b,c,d)     DosLoadModuleEx(a,b,c,d)
     13557#define DosFreeModule(a)           DosFreeModuleEx(a)
     13558
    1354413559#endif /* INCL_EXAPIS_MAPPINGS */
    1354513560
  • trunk/src/emx/include/sys/fmutex.h

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1675 r1676  
    100100}
    101101
     102/**
     103 * Release a semaphore in the child process after the
     104 * semaphore was locked for the forking the parent.
     105 *
     106 * @param   pSem    Semaphore to unlock.
     107 */
     108static __inline__ void _fmutex_release_fork(_fmutex *pSem)
     109{
     110    pSem->fs = _FMS_AVAILABLE;
     111    pSem->Owner = 0;
     112}
    102113
    103114unsigned _fmutex_create (_fmutex *, unsigned);
  • trunk/src/emx/src/lib/libc.def

    • Property cvs2svn:cvs-rev changed from 1.82 to 1.83
    r1675 r1676  
    12731273    "_warnc" @1291
    12741274    ; new stuff
     1275    "DosLoadModuleEx" @1292
     1276    "DosFreeModuleEx" @1293
  • trunk/src/emx/src/lib/malloc/initr.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1675 r1676  
    167167        LIBCLOG_MSG("Unlocking the heaps.\n");
    168168        if (_um_tiled_heap)
    169             _um_heap_unlock(_um_tiled_heap);
     169            _fmutex_release_fork(&_um_tiled_heap->fsem);
    170170        if (_um_high_heap)
    171             _um_heap_unlock(_um_high_heap);
     171            _fmutex_release_fork(&_um_high_heap->fsem);
    172172        if (_um_low_heap)
    173             _um_heap_unlock(_um_low_heap);
     173            _fmutex_release_fork(&_um_low_heap->fsem);
    174174        gfForkCleanupDone = 1;
    175175    }
  • trunk/src/emx/src/lib/startup/cleanup.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1675 r1676  
    22
    33#include <stdio.h>
    4 #include <emx\startup.h>
    5 
    6 extern int __crtexit1__;
    7 extern void __ctordtorTerm1 (int *ptr);
     4#include <emx/startup.h>
    85
    96void _CRT_term (void)
  • trunk/src/emx/src/lib/startup/ctor1.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1675 r1676  
    22
    33#include <stdlib.h>
     4#include <emx/startup.h>
    45
    5 void __ctordtorInit1 (int *ptr);
    66void __ctordtorInit1 (int *ptr)
    77{
  • trunk/src/emx/src/lib/startup/startup.c

    • Property cvs2svn:cvs-rev changed from 1.12 to 1.13
    r1675 r1676  
    1111#define __LIBC_LOG_GROUP    __LIBC_LOG_GRP_INITTERM
    1212#include <InnoTekLIBC/logstrict.h>
    13 
    14 extern int __crtinit1__;
    15 extern void __ctordtorInit1 (int *ptr);
    1613
    1714
  • trunk/src/emx/src/lib/sys/DosEx.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r1675 r1676  
    158158static int  dosexForkPreEventCreate(PDOSEX pEntry);
    159159static int  dosexForkPreEventOpen(PDOSEX pEntry);
     160static int  dosexForkPreLoadModule(PDOSEX pEntry);
    160161static int  dosexForkChild(__LIBC_PFORKHANDLE pForkHandle, __LIBC_FORKOP enmOperation);
    161162static void dosexForkCleanup(void *pvArg, int rc, __LIBC_FORKCTX enmCtx);
     
    192193 * @returns OS/2 error code on failure.
    193194 */
    194 int  dosexRequestMutex(void)
     195static int  dosexRequestMutex(void)
    195196{
    196197    LIBCLOG_ENTER("\n");
     
    227228 * Release mutex succesfully obtained by dosexRequestMutex().
    228229 */
    229 void dosexReleaseMutex(void)
     230static void dosexReleaseMutex(void)
    230231{
    231232    LIBCLOG_ENTER("\n");
     
    255256 * @remark  Caller owns mutex.
    256257 */
    257 int dosexAllocPool(void)
     258static int dosexAllocPool(void)
    258259{
    259260    LIBCLOG_ENTER("\n");
     
    495496 *
    496497 */
    497 int dosexFreeEntry(DOSEXTYPE enmType, PDOSEX pCur, PDOSEX pPrev, PDOSEXHDR pPool)
     498static int dosexFreeEntry(DOSEXTYPE enmType, PDOSEX pCur, PDOSEX pPrev, PDOSEXHDR pPool)
    498499{
    499500    int         rc;
     
    550551            break;
    551552
     553        case DOSEX_TYPE_LOAD_MODULE:
     554            rc = DosFreeModule(pCur->u.LoadModule.hmte);
     555            if (rc && rc != ERROR_INVALID_HANDLE)
     556                fUnlink = 0;
     557            else
     558            {
     559                pCur->u.LoadModule.cLoads--;
     560                if (pCur->u.LoadModule.cLoads > 0)
     561                    fUnlink = 0;
     562            }
     563            break;
     564
    552565        default:
    553566            rc = ERROR_INVALID_PARAMETER;
     
    714727 * @param   pForkHandle     Pointer to the fork handle.
    715728 */
    716 int     dosexForkOpExecParent(__LIBC_PFORKHANDLE pForkHandle)
     729static int     dosexForkOpExecParent(__LIBC_PFORKHANDLE pForkHandle)
    717730{
    718731    LIBCLOG_ENTER("pForkHandle=%p\n", (void *)pForkHandle);
     
    833846 * @param   pForkHandle     Pointer to the fork handle.
    834847 */
    835 int  dosexForkOpForkParent(__LIBC_PFORKHANDLE pForkHandle)
     848static int  dosexForkOpForkParent(__LIBC_PFORKHANDLE pForkHandle)
    836849{
    837850    LIBCLOG_ENTER("pForkHandle=%p\n", (void *)pForkHandle);
     
    885898 * @param   cbArg           sizeof(DOSEXFORKCHILDALLOC).
    886899 */
    887 int dosexForkChildAlloc(__LIBC_PFORKHANDLE pForkHandle, void *pvArg, size_t cbArg)
     900static int dosexForkChildAlloc(__LIBC_PFORKHANDLE pForkHandle, void *pvArg, size_t cbArg)
    888901{
    889902    LIBCLOG_ENTER("pForkHandle=%p pvArg=%p cbArg=%d\n", (void *)pForkHandle, pvArg, cbArg);
     
    912925 * @param   cbArg           sizeof(PDOSEXHDR).
    913926 */
    914 int dosexForkChildProcess(__LIBC_PFORKHANDLE pForkHandle, void *pvArg, size_t cbArg)
     927static int dosexForkChildProcess(__LIBC_PFORKHANDLE pForkHandle, void *pvArg, size_t cbArg)
    915928{
    916929    LIBCLOG_ENTER("pForkHandle=%p pvArg=%p:{%p} cbArg=%d\n", (void *)pForkHandle, pvArg, *(void **)pvArg, cbArg);
     
    961974        if (rc)
    962975            break;
     976
     977        /* Module loading. */
     978        for (pEntry = pPool->apHeads[DOSEX_TYPE_LOAD_MODULE];   !rc && pEntry; pEntry = pEntry->pNext)
     979            rc = dosexForkPreLoadModule(pEntry);
     980        if (rc)
     981            break;
    963982    }
    964983
     
    967986
    968987/**
    969  * Allocates the memory described in the entry.
     988 * Allocates the memory object described in the entry.
    970989 *
    971990 * @returns 0 on success.
     
    973992 * @param   pEntry  Entry containing a memory allocation.
    974993 */
    975 int dosexForkPreMemAlloc(PDOSEX pEntry)
     994static int dosexForkPreMemAlloc(PDOSEX pEntry)
    976995{
    977996    int rc;
     
    9861005
    9871006/**
    988  * Allocates the memory described in the entry.
     1007 * Allocates the memory object described in the entry.
    9891008 *
    9901009 * @returns 0 on success.
     
    9921011 * @param   pEntry  Entry containing a memory allocation.
    9931012 */
    994 int dosexForkPreMemOpen(PDOSEX pEntry)
     1013static int dosexForkPreMemOpen(PDOSEX pEntry)
    9951014{
    9961015    unsigned    cOpens = pEntry->u.MemOpen.cOpens;
     
    10071026
    10081027/**
    1009  * Allocates the memory described in the entry.
     1028 * Creates the mutex semaphore described in the entry.
    10101029 *
    10111030 * @returns 0 on success.
     
    10131032 * @param   pEntry  Entry containing a memory allocation.
    10141033 */
    1015 int dosexForkPreMutexCreate(PDOSEX pEntry)
     1034static int dosexForkPreMutexCreate(PDOSEX pEntry)
    10161035{
    10171036    int                 i;
     
    10841103
    10851104/**
    1086  * Allocates the memory described in the entry.
     1105 * Opens the mutex semaphore described in the entry.
    10871106 *
    10881107 * @returns 0 on success.
     
    10901109 * @param   pEntry  Entry containing a memory allocation.
    10911110 */
    1092 int dosexForkPreMutexOpen(PDOSEX pEntry)
     1111static int dosexForkPreMutexOpen(PDOSEX pEntry)
    10931112{
    10941113    int cOpens = pEntry->u.MutexOpen.cOpens;
     
    11051124
    11061125/**
    1107  * Allocates the memory described in the entry.
     1126 * Creates the event semaphore described in the entry.
    11081127 *
    11091128 * @returns 0 on success.
     
    11111130 * @param   pEntry  Entry containing a memory allocation.
    11121131 */
    1113 int dosexForkPreEventCreate(PDOSEX pEntry)
     1132static int dosexForkPreEventCreate(PDOSEX pEntry)
    11141133{
    11151134    int                 i;
     
    11821201
    11831202/**
    1184  * Allocates the memory described in the entry.
     1203 * Opens the event semaphore described in the entry.
    11851204 *
    11861205 * @returns 0 on success.
     
    11881207 * @param   pEntry  Entry containing a memory allocation.
    11891208 */
    1190 int dosexForkPreEventOpen(PDOSEX pEntry)
     1209static int dosexForkPreEventOpen(PDOSEX pEntry)
    11911210{
    11921211    int cOpens = pEntry->u.EventOpen.cOpens;
     
    11951214        int rc = DosOpenEventSem(NULL, &pEntry->u.EventOpen.hev);
    11961215        LIBC_ASSERTM(!rc, "DosOpenEventSem(,%#lx) -> rc=%d\n", pEntry->u.EventOpen.hev, rc);
     1216        if (rc)
     1217            return -__libc_native2errno(rc);
     1218    }
     1219    return 0;
     1220}
     1221
     1222
     1223/**
     1224 * Loads the module described in the entry.
     1225 *
     1226 * @returns 0 on success.
     1227 * @returns -errno on failure.
     1228 * @param   pEntry  Entry containing a memory allocation.
     1229 */
     1230static int dosexForkPreLoadModule(PDOSEX pEntry)
     1231{
     1232    char    szName[CCHMAXPATH];
     1233    int     cLoads = pEntry->u.LoadModule.cLoads;
     1234
     1235    /*
     1236     * Figure out the name first.
     1237     */
     1238    int     rc = DosQueryModuleName(pEntry->u.LoadModule.hmte, sizeof(szName), szName);
     1239    if (rc)
     1240    {
     1241        LIBC_ASSERTM(!rc, "DosQueryModuleName(%#lx,%d,%p) -> rc=%d \n", pEntry->u.LoadModule.hmte, sizeof(szName), szName, rc);
     1242        if (rc)
     1243            return -__libc_native2errno(rc);
     1244    }
     1245
     1246    /*
     1247     * Perform the loads.
     1248     */
     1249    while (cLoads-- > 0)
     1250    {
     1251        HMODULE hmod = 0;
     1252        rc = DosLoadModule(NULL, 0, (PCSZ)szName, &hmod);
     1253        LIBC_ASSERTM(!rc, "DosLoadModule(,,'%s',) -> rc=%d (hmte=%#lx)\n", szName, rc, pEntry->u.LoadModule.hmte);
    11971254        if (rc)
    11981255            return -__libc_native2errno(rc);
     
    12641321}
    12651322
    1266 
  • trunk/src/emx/src/lib/sys/DosEx.h

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1675 r1676  
    4949    /** Event open. */
    5050    DOSEX_TYPE_EVENT_OPEN,
     51    /** Load module. */
     52    DOSEX_TYPE_LOAD_MODULE,
    5153    /** Max type (exclusive). */
    5254    DOSEX_TYPE_MAX
     
    6971    {
    7072        /** Search key.
    71          * We assume that sizeof(unsigned) == sizeof(PVOID) == sizeof(HMTX) == sizeof(HEV).
     73         * We assume that sizeof(unsigned) == sizeof(PVOID) == sizeof(HMTX) == sizeof(HEV) == sizeof(HMODULE).
    7274         */
    7375        unsigned        uKey;
     
    151153            unsigned    cOpens;
    152154        }   EventOpen;
     155
     156        /**
     157         * Loaded module.
     158         */
     159        struct
     160        {
     161            /** Module handle. */
     162            HMODULE     hmte;
     163            /** Load count. */
     164            unsigned    cLoads;
     165        }   LoadModule;
    153166    }       u;
    154167} DOSEX;
  • trunk/src/emx/src/lib/sys/b_ldrClose.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r1675 r1676  
    3131#include "libc-alias.h"
    3232#define INCL_BASE
     33#define INCL_EXAPIS
    3334#define INCL_FSMACROS
    3435#include <os2emx.h>
     
    5051    FS_VAR();
    5152    FS_SAVE_LOAD();
    52     int rc = DosFreeModule((HMODULE)pvModule);
     53    int rc = DosFreeModuleEx((HMODULE)pvModule);
    5354    FS_RESTORE();
    5455    LIBCLOG_RETURN_INT(rc);
  • trunk/src/emx/src/lib/sys/b_ldrOpen.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r1675 r1676  
    3232#define INCL_BASE
    3333#define INCL_FSMACROS
     34#define INCL_EXAPIS
    3435#include <os2emx.h>
    3536#include <InnoTekLIBC/backend.h>
     
    5556    FS_VAR();
    5657    FS_SAVE_LOAD();
    57     int rc = DosLoadModule((PSZ)pszError, cchError, (PCSZ)pszLibrary, &hmod);
     58    int rc = DosLoadModuleEx((PSZ)pszError, cchError, (PCSZ)pszLibrary, &hmod);
    5859    FS_RESTORE();
    5960    if (!rc)
Note: See TracChangeset for help on using the changeset viewer.