Changeset 1461


Ignore:
Timestamp:
Sep 6, 2004, 6:22:46 AM (21 years ago)
Author:
bird
Message:

Fixing, extending, optimizing.

Location:
trunk/src/emx
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/Makefile

    • Property cvs2svn:cvs-rev changed from 1.48 to 1.49
    r1460 r1461  
    200200#       must use the shell.
    201201EMXOMF = $(call GETTOOL2,emxomf)
    202 DO.EMXOMF = $(EMXOMF) $(strip $1 -o) $@ $(if $<,$<, $(subst /omf/,/aout/,$(@:.obj=.o)) )
     202DO.EMXOMF = $(EMXOMF) $(strip $1 -o) $@ $(if $<,$<, $(subst /omf-prof/,/aout-prof/,$(subst /omf-log/,/aout-log/,$(subst /omf/,/aout/,$(@:.obj=.o)))) )
    203203
    204204# How to copy some file to installation directory
     
    343343        @$(call ECHO,smak don't generate rules anylonger!)
    344344
    345 # The general a.out -> OMF conversion rule for object files
     345# The general a.out -> OMF conversion rules for object files
    346346$.omf/%.obj:   
     347        $(call DO.EMXOMF)
     348$.omf-log/%.obj:       
     349        $(call DO.EMXOMF)
     350$.omf-prof/%.obj:       
    347351        $(call DO.EMXOMF)
    348352
  • trunk/src/emx/include/InnoTekLIBC/fork.h

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r1460 r1461  
    494494    /* Priority of this callback */
    495495    unsigned                uPriority;
    496     /** Pointer to the next record in a sorted callback list.
    497      * @remark This is initialized to point to self in order to shut up the compiler.
    498      * (Encountered some limitations of the GNU inline assmebler which prevents me from
    499      * referencing the symbol.)
    500      */
    501     struct __libc_ForkCallback *pNext;
     496    /** Pointer to self.
     497     * This is a hack to allow the callbacks to be static without gcc
     498     * optimizing them away as unused.
     499     */
     500    const struct __libc_ForkCallback *pSelf;
    502501} __LIBC_FORKCALLBACK, *__LIBC_PFORKCALLBACK;
    503502
     
    513512 */
    514513#define _FORK_PARENT1(uPriority, pfnCallback) \
    515     static __LIBC_FORKCALLBACK __fork_parent1_##pfnCallback = { pfnCallback, uPriority, &__fork_parent1_##pfnCallback }; \
     514    static const __LIBC_FORKCALLBACK __fork_parent1_##pfnCallback = { pfnCallback, uPriority, &__fork_parent1_##pfnCallback }; \
    516515    __asm__ (".stabs \"___fork_parent1__\", 25, 0, 0, ___fork_parent1_" #pfnCallback);
    517516
     
    526525 */
    527526#define _FORK_CHILD1(uPriority, pfnCallback) \
    528     static __LIBC_FORKCALLBACK __fork_child1_##pfnCallback  = { pfnCallback, uPriority, &__fork_child1_##pfnCallback  }; \
     527    static const __LIBC_FORKCALLBACK __fork_child1_##pfnCallback  = { pfnCallback, uPriority, &__fork_child1_##pfnCallback  }; \
    529528    __asm__ (".stabs \"___fork_child1__\",  25, 0, 0, ___fork_child1_" #pfnCallback );
    530529
  • trunk/src/emx/include/InnoTekLIBC/sharedpm.h

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1460 r1461  
    233233    /** Pointer to fork handle which a child should use when spawned by fork(). */
    234234    void                       *pvForkHandle;
     235    /** Creation timestamp. */
     236    unsigned                    uTimestamp;
    235237
    236238    /** Reserved pool pointer field with default value 0. */
    237     unsigned                    aReserved[40 - 13];
     239    unsigned                    aReserved[40 - 14];
    238240
    239241    /** Number of possible pointers to shared memory starting at pvInherit.
     
    243245    /** Pointer to data inherited from the parent process. */
    244246    __LIBC_PSPMINHERIT volatile pInherit;
     247    /** Pointer to data inherited from the parent process when it's locked.
     248     * When locked pInherit is NULL and this member points to the data instead.
     249     * This prevents spmAlloc() from reclaiming it while it's in use. */
     250    __LIBC_PSPMINHERIT volatile pInheritLocked;
    245251} __LIBC_SPMPROCESS, *__LIBC_PSPMPROCESS;
    246252
     
    367373
    368374/**
     375 * Gets the inherit data associated with the current process.
     376 * This call prevents it from being release by underrun handling.
     377 *
     378 * @returns Pointer to inherit data.
     379 *          The caller must call __libc_spmInheritRelease() when done.
     380 * @returns NULL and errno if no inherit data.
     381 */
     382__LIBC_PSPMINHERIT  __libc_spmInheritRequest(void);
     383
     384/**
     385 * Releases the inherit data locked by the __libc_spmInheritRequest() call.
     386 *
     387 * @returns 0 on success.
     388 * @returns -1 and errno on failure.
     389 */
     390int  __libc_spmInheritRelease(void);
     391
     392/**
     393 * Frees the inherit data of this process.
     394 * This is called when the executable is initialized.
     395 */
     396void  __libc_spmInheritFree(void);
     397
     398/**
    369399 * Create an embryo related to the current process.
    370400 *
  • trunk/src/emx/src/lib/libc.def

    • Property cvs2svn:cvs-rev changed from 1.60 to 1.61
    r1460 r1461  
    11181118    ; new stuff.
    11191119
     1120    "___libc_SpmCheck" @1140
  • trunk/src/emx/src/lib/libc.smak

    • Property cvs2svn:cvs-rev changed from 1.42 to 1.43
    r1460 r1461  
    5757LIBC.IMPLIB     := $.omf/libc_dll.lib $.aout/libc_dll.a
    5858LIBC.DEF        := $.omf/libc.def
    59 LIBC.OBJS       := $.omf/src/lib/startup/dll0hifork.obj $.omf/src/lib/startup/dllinit.obj
     59LIBC.OBJS.COMMON := \
     60        $.omf/src/lib/sys/libcfork.obj \
     61        $.omf/src/lib/sys/sharedpm.obj \
     62        $.omf/src/lib/sys/__initdll.obj \
     63        $.omf/src/lib/malloc/_heapvoting.obj \
     64        $.omf/src/lib/process/fmutex.obj \
     65        $.omf/src/lib/sys/DosCreateEventSemEx.obj \
     66        $.omf/src/lib/sys/DosEx.obj \
     67        $.omf/src/lib/str/386/bzero.obj \
     68        $.omf/src/lib/sys/386/__init_environ.obj \
     69        $.omf/src/lib/malloc/_hmalloc.obj \
     70        $.omf/src/lib/malloc/_hinitheap.obj \
     71        $.omf/src/lib/sys/heaphigh.obj \
     72        $.omf/src/lib/sys/DosAllocMemEx.obj \
     73        $.omf/src/lib/malloc/ucreate2.obj \
     74        $.omf/src/lib/malloc/iaddmem.obj \
     75        $.omf/src/lib/malloc/imisc.obj \
     76        $.omf/src/lib/malloc/uopen.obj \
     77        $.omf/src/lib/sys/DosOpenEventSemEx.obj \
     78        $.omf/src/lib/malloc/umalloc.obj \
     79        $.omf/src/lib/malloc/ialloc.obj \
     80        $.omf/src/lib/sys/largefileio.obj \
     81        $.omf/src/lib/sys/filehandles.obj \
     82        $.omf/src/lib/malloc/_hcalloc.obj \
     83        $.omf/src/lib/malloc/ucalloc.obj \
     84        $.omf/src/lib/startup/dllinit.obj \
     85        $.omf/src/lib/startup/startup.obj \
     86        $.omf/src/lib/startup/ctor1.obj \
     87        $.omf/src/lib/sys/tcpipver.obj \
     88        $.omf/src/lib/sys/tcpipver43.obj \
     89        $.omf/src/lib/sys/pathrewrite.obj \
     90        $.omf/src/lib/app/getenv.obj \
     91        $.omf/src/lib/str/386/strlen.obj \
     92        $.omf/src/lib/str/strncmp.obj \
     93        $.omf/src/lib/app/stdio.obj \
     94        $.omf/src/lib/process/fmutex2.obj \
     95        $.omf/src/lib/io/_tmp.obj \
     96        $.omf/src/lib/process/thread_internals.obj \
     97        $.omf/src/lib/sys/b_threadInit.obj \
     98        $.omf/src/lib/malloc/malloc.obj \
     99        $.omf/src/lib/malloc/initr.obj \
     100        $.omf/src/lib/malloc/_linitheap.obj \
     101        $.omf/src/lib/sys/uflags.obj \
     102        $.omf/src/lib/sys/sbrk.obj \
     103        $.omf/src/lib/sys/heap.obj \
     104        $.omf/src/lib/sys/__init.obj
     105LIBC.OBJS       := \
     106        $.omf/src/lib/startup/dll0hifork.obj \
     107        $(LIBC.OBJS.COMMON)
    60108LIBC.LIBS       := $.omf/libc_s.lib $.omf/libc_app.lib
    61109LIBC.DEPS       := $(LIBC.STUB) $.omf/libc_alias.lib
     
    65113LIBC.PRF.DLL    := $(LIBC.DLL:.dll=.prf)
    66114LIBC.PRF.DEF    := $.omf/libc.prf.def
    67 LIBC.PRF.OBJS   := $.omf/src/lib/startup/dll0hifork.obj $.omf-prof/src/lib/startup/dllinit.obj
     115LIBC.PRF.OBJS   := \
     116        $.omf/src/lib/startup/dll0hifork.obj \
     117        $(subst /omf/,/omf-prof/,$(LIBC.OBJS.COMMON))
    68118LIBC.PRF.LIBS   := $.omf-prof/libc_p_s.lib $.omf-prof/libc_app_p.lib
    69119LIBC.PRF.DEPS   := $(LIBC.DEPS)
     
    72122LIBC.ELH.DLL    := $(LIBC.DLL:.dll=.elh)
    73123LIBC.ELH.DEF    := $.omf/libc.elh.def
    74 LIBC.ELH.OBJS   := $(LIBC.OBJS)
     124LIBC.ELH.OBJS   := \
     125        $.omf/src/lib/startup/dll0hifork.obj \
     126        $.omf/src/lib/startup/dllinit.obj
    75127LIBC.ELH.LIBS   := $(LIBC.LIBS)
    76128LIBC.ELH.DEPS   := $(LIBC.DEPS)
     
    79131LIBC.LOG.DLL    := $(LIBC.DLL:.dll=.logchk)
    80132LIBC.LOG.DEF    := $(LIBC.DEF)
    81 LIBC.LOG.OBJS   := $.omf/src/lib/startup/dll0hifork.obj $.omf/src/lib/startup/dllinit.obj
     133LIBC.LOG.OBJS   := \
     134        $.omf/src/lib/startup/dll0hifork.obj \
     135        $(subst /omf/,/omf-log/,$(LIBC.OBJS.COMMON))
    82136LIBC.LOG.LIBS   := $.omf-log/libc_l_s.lib $.omf-log/libc_app_l.lib
    83137LIBC.LOG.DEPS   := $(LIBC.DEPS)
  • trunk/src/emx/src/lib/startup/startup.c

    • Property cvs2svn:cvs-rev changed from 1.11 to 1.12
    r1460 r1461  
    5555 *      - dll0.s gets control and calls __init_dll in sys/__initdll.c
    5656 *          - __init_dll calls __libc_HeapVote() to do the heap voting.
    57  *          - __init_dll calls __init_os_version() to set _osminor,_osmajor globals.
     57 *          - __init_dll initiates the _osminor and _osmajor globals.
     58 *          - __init_dll initiates _sys_gcbVirtualAddressLimit global.
    5859 *          - __init_dll initiates _sys_pid and _sys_ppid globals.
    59  *          - __init_dll creates _sys_heap_fmutex and _sys_gmtxHimem.
     60 *          - __init_dll creates _sys_heap_fmutex, _sys_gmtxHimem and __libc_gmtxExec.
    6061 *          - __init_dll then initiates __libc_gpTLS with an allocated TLS ULONG.
    6162 *            The thread structure it self isn't initialized untill it's actually
    6263 *            referenced, and when it is there is static structure for the first
    6364 *            thread needing its per thread area.
    64  *          - __init_dll calls __init_environ() which initializes environ and _org_environ.
    65  *              - __init_environ() will call _hmalloc() thus initiating the high heap.
     65 *          - __init_dll calls _sys_init_environ() which initializes environ and _org_environ.
     66 *              - _sys_init_environ() will call _hmalloc() thus initiating the high heap.
     67 *          - __init_dll calls __libc_spmSelf() which checks initiates SPM and gets
     68 *            any inherited properties.
    6669 *          - __init_dll calls _sys_init_largefileio() which checks for LFN APIs.
    67  *          - __init_dll calls _sys_init_filehandles() which initiates filehandle table.
    68  *              - _sys_init_filehandles() will call _hmalloc() and a number of OS/2 APIs
     70 *          - __init_dll calls __libc_fhInit() which initiates filehandle table.
     71 *              - __libc_fhInit() will call _hmalloc() and a number of OS/2 APIs
    6972 *                to figure out what handles was inherited.
    7073 *          - __init_dll then intializes _sys_clock0_ms with the current MS count.
     
    100103 *          - __init() parse the commandline creating argv and it's strings using the
    101104 *            allocated stack space.
     105 *          - __init() calls __libc_spmInheritFree() to release the inherit data (shared)
     106 *            associated with the current process.
    102107 *          - __init() installs the exception handler.
    103108 *          - __init() set the signal focus.
     
    112117 *
    113118 * @todo update this with file handle changes!
     119 * @todo update this with fork and performance changes!
    114120 */
  • trunk/src/emx/src/lib/sys/__init.c

    • Property cvs2svn:cvs-rev changed from 1.13 to 1.14
    r1460 r1461  
    2626#include <alloca.h>
    2727#include <InnoTekLIBC/thread.h>
     28#include <InnoTekLIBC/sharedpm.h>
    2829#define __LIBC_LOG_GROUP    __LIBC_LOG_GRP_INITTERM
    2930#include <InnoTekLIBC/logstrict.h>
     
    214215
    215216    /*
     217     * Free the SPM inherit data.
     218     */
     219    __libc_spmInheritFree();
     220
     221    /*
    216222     * Install exception handler.
    217223     */
     
    442448{
    443449    __asm__ ("cld");              /* Don't trust */
    444 LIBCLOG_MSG2("!!! num %08lx flags %08lx nested %p whatever %p\n", report->ExceptionNum, report->fHandlerFlags, report->NestedExceptionReportRecord, whatever);
     450    LIBCLOG_MSG2("!!! num %08lx flags %08lx nested %p whatever %p\n",
     451                 report->ExceptionNum, report->fHandlerFlags, (void *)report->NestedExceptionReportRecord, whatever);
    445452    if (report->fHandlerFlags & (EH_UNWINDING | EH_EXIT_UNWIND))
    446453        return XCPT_CONTINUE_SEARCH;
     
    509516
    510517
    511 void _sys_get_clock(unsigned long *ms)
    512 {
    513     ULONG val_ms;
    514     FS_VAR();
    515 
    516     FS_SAVE_LOAD();
    517     DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &val_ms, sizeof (val_ms));
    518     FS_RESTORE();
    519     *ms = val_ms;
    520 }
    521 
    522 
  • trunk/src/emx/src/lib/sys/__initdll.c

    • Property cvs2svn:cvs-rev changed from 1.11 to 1.12
    r1460 r1461  
    1717#include "libc-alias.h"
    1818#define INCL_DOS
     19#define INCL_FSMACROS
    1920#include <os2emx.h>
    2021#define _osmajor __osminor
     
    4041#pragma weak __init_largefileio
    4142
     43
    4244/*******************************************************************************
    4345*   Structures and Typedefs                                                    *
     
    8385    PPIB                ppib;
    8486    __LIBC_PSPMPROCESS  pSelf;
     87
    8588    static int fInitialized = 0;
    8689
     
    177180     * Init file handles.
    178181     */
    179     rc = __libc_fhInit(pSelf->pInherit ? pSelf->pInherit->pFHBundles : NULL);
     182    rc = __libc_fhInit();
    180183    if (rc)
    181184    {
     
    190193    return 0;
    191194}
     195
     196
     197/**
     198 * Get the current MS timestamp.
     199 * @param   pms     Where to store the current timestamp.
     200 */
     201void _sys_get_clock(unsigned long *pms)
     202{
     203    ULONG val_ms;
     204    FS_VAR();
     205
     206    FS_SAVE_LOAD();
     207    DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &val_ms, sizeof(val_ms));
     208    FS_RESTORE();
     209    *pms = val_ms;
     210}
     211
    192212
    193213
  • trunk/src/emx/src/lib/sys/__spawnve.c

    • Property cvs2svn:cvs-rev changed from 1.7 to 1.8
    r1460 r1461  
    77#include <errno.h>
    88#include <alloca.h>
     9#include <386/builtin.h>
     10#include <sys/fmutex.h>
    911#define INCL_DOSPROCESS
    1012#define INCL_FSMACROS
     
    192194  *arg_ptr++ = '\0';
    193195  *arg_ptr++ = '\0';
     196
     197  _fmutex_request(&__libc_gmtxExec, 0);
    194198
    195199  /*
     
    218222              if (arg_buf != NULL)
    219223                  _tfree (arg_buf);
     224              _fmutex_release(&__libc_gmtxExec);
    220225
    221226              /* exit depends on the mode. */
     
    246251  if (arg_buf != NULL)
    247252    _tfree (arg_buf);
     253  _fmutex_release(&__libc_gmtxExec);
    248254  return -1;
    249255}
  • trunk/src/emx/src/lib/sys/filehandles.c

    • Property cvs2svn:cvs-rev changed from 1.10 to 1.11
    r1460 r1461  
    4141#include "libc-alias.h"
    4242#include <malloc.h>
     43#include <string.h>
    4344#include <sys/fcntl.h>
    4445#include <errno.h>
     
    9596 * @returns 0 on success.
    9697 * @returns -1 on failure.
    97  * @param   pInherit    Pointer to inherited filehandle data.
    98  */
    99 int __libc_fhInit(__LIBC_PSPMINHFHBHDR  pInherit)
    100 {
    101     ULONG   cMaxFHs = 0;
    102     LONG    lDeltaFHs = 0;
    103     int     rc;
    104     int     i;
     98 */
     99int __libc_fhInit(void)
     100{
     101    __LIBC_PSPMINHERIT  pInherit;
     102    ULONG               cMaxFHs = 0;
     103    LONG                lDeltaFHs = 0;
     104    int                 rc;
     105    int                 i;
    105106
    106107    /*
     
    136137    gcPreAllocatedAvail = sizeof(gaPreAllocated) / sizeof(gaPreAllocated[0]);
    137138
    138 
    139     if (!pInherit)
     139    /*
     140     * Check if we inherited flags and stuff from parent.
     141     */
     142    pInherit = __libc_spmInheritRequest();
     143    if (!pInherit || pInherit->pFHBundles)
    140144    {
    141145        /*
     
    165169            void                   *pv;
    166170        } u;
    167         u.pHdr = pInherit;
     171        u.pHdr = pInherit->pFHBundles;
    168172        while (u.pHdr->uchType != __LIBC_SPM_INH_FHB_TYPE_END)
    169173        {
     
    179183                        {
    180184                            LIBC_ASSERTM_FAILED("Failed to allocated inherited file handle! iFH=%d\n", iFH);
     185                            __libc_spmInheritRelease();
    181186                            return -1;
    182187                        }
     
    192197                            LIBC_ASSERTM_FAILED("Failed to allocated inherited socket (4.4) handle! iFH=%d iSocket=%d\n",
    193198                                                iFH, u.pSockets->aHandles[i].usSocket);
     199                            __libc_spmInheritRelease();
    194200                            return -1;
    195201                        }
     
    205211                            LIBC_ASSERTM_FAILED("Failed to allocated inherited socket (4.3) handle! iFH=%d iSocket=%d\n",
    206212                                                iFH, u.pSockets->aHandles[i].usSocket);
     213                            __libc_spmInheritRelease();
    207214                            return -1;
    208215                        }
     
    224231            }
    225232        }
     233        __libc_spmInheritRelease();
    226234    }
    227235
  • trunk/src/emx/src/lib/sys/sharedpm.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1460 r1461  
    113113static VOID APIENTRY spmExitList(ULONG ulReason);
    114114static void spmZombieOrFree(__LIBC_PSPMPROCESS pProcess);
     115static unsigned spmTimestamp(void);
    115116static __LIBC_PSPMPROCESS spmRegisterSelf(pid_t pid, pid_t pidParent);
    116117static __LIBC_PSPMPROCESS spmAllocProcess(void);
     
    121122static ULONG _System spmXcptHandler(PEXCEPTIONREPORTRECORD pRepRec, PEXCEPTIONREGISTRATIONRECORD pRegRec, PCONTEXTRECORD pCtx, PVOID pvWhatever);
    122123static int  spmCheck(int fBreakpoint, int fVerbose);
    123 
    124124
    125125
     
    296296
    297297/**
     298 * Gets the inherit data associated with the current process.
     299 * This call prevents it from being release by underrun handling.
     300 *
     301 * @returns Pointer to inherit data.
     302 *          The caller must call __libc_spmInheritRelease() when done.
     303 * @returns NULL and errno if no inherit data.
     304 */
     305__LIBC_PSPMINHERIT  __libc_spmInheritRequest(void)
     306{
     307    LIBCLOG_ENTER("\n");
     308    __LIBC_PSPMINHERIT      pRet = NULL;
     309    __LIBC_SPMXCPTREGREC    RegRec;
     310    if (!spmRequestMutex(&RegRec))
     311    {
     312        if ((pRet = gpSPMSelf->pInherit) != NULL)
     313            gpSPMSelf->pInheritLocked = (void *)__atomic_xchg((unsigned *)(void *)&gpSPMSelf->pInherit, 0);
     314        else if (gpSPMSelf->pInheritLocked)
     315        {
     316            errno = EBUSY;
     317            LIBC_ASSERTM_FAILED("Already locked!\n");
     318        }
     319        else
     320            errno = 0;
     321        spmReleaseMutex(&RegRec);
     322    }
     323
     324    LIBCLOG_RETURN_P(pRet);
     325}
     326
     327
     328/**
     329 * Releases the inherit data locked by the __libc_spmInheritRequest() call.
     330 *
     331 * @returns 0 on success.
     332 * @returns -1 and errno on failure.
     333 */
     334int  __libc_spmInheritRelease(void)
     335{
     336    LIBCLOG_ENTER("\n");
     337    __LIBC_SPMXCPTREGREC    RegRec;
     338    int rc = spmRequestMutex(&RegRec);
     339    if (!rc)
     340    {
     341        gpSPMSelf->pInheritLocked = (void *)__atomic_xchg((unsigned *)(void *)&gpSPMSelf->pInherit, (unsigned)gpSPMSelf->pInheritLocked);
     342        spmReleaseMutex(&RegRec);
     343    }
     344    else
     345    {
     346        errno = EINVAL;
     347        rc = -1;
     348        LIBC_ASSERTM_FAILED("Not initialized!\n");
     349    }
     350
     351    LIBCLOG_RETURN_INT(rc);
     352}
     353
     354
     355/**
     356 * Frees the inherit data of this process.
     357 * This is called when the executable is initialized.
     358 */
     359void  __libc_spmInheritFree(void)
     360{
     361    LIBCLOG_ENTER("\n");
     362    if (gpSPMSelf && (gpSPMSelf->pInherit || gpSPMSelf->pInheritLocked))
     363    {
     364        __LIBC_SPMXCPTREGREC    RegRec;
     365        if (!spmRequestMutex(&RegRec))
     366        {
     367            if (gpSPMSelf->pInherit)
     368            {
     369                int rc = spmFree(gpSPMSelf->pInherit);
     370                LIBC_ASSERTM(!rc, "Failed to free inherit memory %p, errno=%d.\n",
     371                             (void *)gpSPMSelf->pInherit, errno);
     372                __atomic_xchg((unsigned *)(void *)&gpSPMSelf->pInherit, 0);
     373                rc = rc;
     374            }
     375            LIBC_ASSERTM(!gpSPMSelf->pInheritLocked, "Trying to free a locked inherit struct!\n");
     376
     377            spmReleaseMutex(&RegRec);
     378        }
     379    }
     380    LIBCLOG_RETURN_VOID();
     381}
     382
     383
     384
     385/**
    298386 * Create an embryo related to the current process.
    299387 *
     
    325413
    326414    /*
     415     * Reap old embryos.
     416     */
     417    pProcess = gpSPMHdr->apHeads[__LIBC_PROCSTATE_EMBRYO];
     418    if (pProcess)
     419    {
     420        unsigned uTimestamp = spmTimestamp();
     421        do
     422        {
     423            SPM_ASSERT_PTR_NULL(pProcess);
     424            SPM_ASSERT_PTR_NULL(pProcess->pPrev);
     425            SPM_ASSERT_PTR_NULL(pProcess->pNext);
     426            if (    pProcess->pidParent == pidParent
     427                &&  pProcess->cReferences == 0
     428                &&  uTimestamp - pProcess->uTimestamp >= 1*60*1000)
     429            {
     430                __LIBC_PSPMPROCESS      pProcessNext = pProcess->pNext;
     431                spmFreeProcess(pProcess);
     432                pProcess = pProcessNext;
     433                continue;
     434            }
     435
     436            /* next */
     437            pProcess = pProcess->pNext;
     438        } while (pProcess);
     439    }
     440
     441    /*
    327442     * Create a new process block.
    328443     */
     
    333448         * Initialize the new process block.
    334449         */
    335         pProcess->uVersion   = SPM_VERSION;
    336         pProcess->cReferences = 1;
    337         pProcess->pid        = -1;
    338         pProcess->pidParent  = pidParent;
    339         pProcess->enmState   = __LIBC_PROCSTATE_EMBRYO;
    340         pProcess->cPoolPointers = 1; /** @todo define for this! */
     450        pProcess->uVersion      = SPM_VERSION;
     451        pProcess->cReferences   = 1;
     452        pProcess->pid           = -1;
     453        pProcess->pidParent     = pidParent;
     454        pProcess->enmState      = __LIBC_PROCSTATE_EMBRYO;
     455        pProcess->uTimestamp    = spmTimestamp();
     456        pProcess->cPoolPointers = 2; /** @todo define for this! */
    341457
    342458        /* link into list. */
     
    488604    /*
    489605     * Free the process.
    490      */
    491     if (pProcess->cReferences == 0)
     606     * Note that we do not free embryos. We'll reap them at other places
     607     * if they don't become alive.
     608     */
     609    if (pProcess->cReferences == 0 && pProcess->enmState != __LIBC_PROCSTATE_EMBRYO)
    492610        spmFreeProcess(pProcess);
    493611
     
    11681286    else if (pProcess->enmState != __LIBC_PROCSTATE_ZOMBIE)
    11691287    {
     1288        /* free data a zombie won't be needing. */
     1289        if (pProcess->pInherit)
     1290        {
     1291            spmFree(pProcess->pInherit);
     1292            pProcess->pInherit = NULL;
     1293        }
     1294
    11701295        /* unlink. */
    11711296        if (pProcess->pNext)
     
    11851310    }
    11861311    /* else already zombie */
     1312}
     1313
     1314
     1315/**
     1316 * Gets the current timestamp.
     1317 *
     1318 * @returns The current timestamp.
     1319 */
     1320static unsigned spmTimestamp(void)
     1321{
     1322    ULONG   ul;
     1323    int     rc;
     1324    FS_VAR();
     1325    FS_SAVE_LOAD();
     1326    ul = 0;
     1327    rc = DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &ul, sizeof(ul));
     1328    LIBC_ASSERTM(!rc, "DosQuerySysInfo failed rc=%d\n", rc);
     1329    FS_RESTORE();
     1330    rc = rc;
     1331    return (unsigned)ul;
    11871332}
    11881333
     
    12981443         * Initialize the new process block.
    12991444         */
    1300         pProcess->uVersion   = SPM_VERSION;
    1301         pProcess->cReferences = 1;
    1302         pProcess->pid        = pid;
    1303         pProcess->pidParent  = pidParent;
    1304         pProcess->enmState   = __LIBC_PROCSTATE_ALIVE;
    1305         pProcess->cPoolPointers = 1; /** @todo define for this! */
     1445        pProcess->uVersion      = SPM_VERSION;
     1446        pProcess->cReferences   = 1;
     1447        pProcess->pid           = pid;
     1448        pProcess->pidParent     = pidParent;
     1449        pProcess->enmState      = __LIBC_PROCSTATE_ALIVE;
     1450        pProcess->uTimestamp    = spmTimestamp();
     1451        pProcess->cPoolPointers = 2; /** @todo define for this! */
    13061452
    13071453        /* link into list. */
     
    14441590    {
    14451591        __LIBC_PSPMPROCESS  pProcess;
     1592
     1593        /*
     1594         * Free embryos which are more than 15 seconds old.
     1595         */
     1596        pProcess = gpSPMHdr->apHeads[__LIBC_PROCSTATE_EMBRYO];
     1597        if (pProcess)
     1598        {
     1599            unsigned    uTimestamp = spmTimestamp();
     1600            do
     1601            {
     1602                SPM_ASSERT_PTR_NULL(pProcess);
     1603                SPM_ASSERT_PTR_NULL(pProcess->pNext);
     1604                SPM_ASSERT_PTR_NULL(pProcess->pPrev);
     1605                if (    pProcess->cReferences == 0
     1606                    &&  uTimestamp - pProcess->uTimestamp >= 15*1000)
     1607                {
     1608                    __LIBC_PSPMPROCESS      pProcessNext = pProcess->pNext;
     1609                    spmFreeProcess(pProcess);
     1610                    pProcess = pProcessNext;
     1611                    continue;
     1612                }
     1613
     1614                /* next */
     1615                pProcess = pProcess->pNext;
     1616            } while (pProcess);
     1617        }
     1618
    14461619        /*
    14471620         * Free up free processes.
     
    14491622        while ((pProcess = gpSPMHdr->apHeads[__LIBC_PROCSTATE_FREE]) != NULL)
    14501623        {
     1624            SPM_ASSERT_PTR_NULL(pProcess);
     1625            SPM_ASSERT_PTR_NULL(pProcess->pNext);
     1626            SPM_ASSERT_PTR_NULL(pProcess->pPrev);
     1627            gpSPMHdr->apHeads[__LIBC_PROCSTATE_FREE] = pProcess->pNext;
    14511628            if (pProcess->pNext)
    14521629                pProcess->pNext->pPrev = NULL;
     
    14581635
    14591636        /*
    1460          * Free up inherit data.
     1637         * Free up inherit data of processes in the alive list.
    14611638         */
    14621639        for (pProcess = gpSPMHdr->apHeads[__LIBC_PROCSTATE_ALIVE]; pProcess; pProcess = pProcess->pNext)
     1640        {
     1641            SPM_ASSERT_PTR_NULL(pProcess);
     1642            SPM_ASSERT_PTR_NULL(pProcess->pNext);
     1643            SPM_ASSERT_PTR_NULL(pProcess->pPrev);
    14631644            if (pProcess->pInherit)
    14641645            {
    1465                 void *pv = pProcess->pInherit;
    1466                 pProcess->pInherit = NULL;
     1646                void *pv = (void *)__atomic_xchg((unsigned *)(void *)&gpSPMSelf->pInherit, 0);
    14671647                spmFree(pv);
    14681648            }
    1469 
    1470         /*
    1471          * Free embryos which are more than a minutte old.
    1472          */
    1473         /** @todo */
     1649        }
    14741650
    14751651        /*
     
    17081884        SPM_ASSERT_PTR_NULL(pLeft->core.pPrev);
    17091885
    1710         if (pLeft == pFree->core.pPrev)
     1886        if ((__LIBC_PSPMPOOLCHUNK)pLeft == pFree->core.pPrev)
    17111887        {   /* merge with left free chunk. */
    17121888            pLeft->core.pNext = pFree->core.pNext;
     
    17331909
    17341910    /* Check if we can merge with right hand free chunk. */
    1735     if (pRight && pRight == pFree->core.pNext)
     1911    if (pRight && (__LIBC_PSPMPOOLCHUNK)pRight == pFree->core.pNext)
    17361912    {   /* merge with right free chunk. */
    17371913        pFree->core.pNext = pRight->core.pNext;
  • trunk/src/emx/src/lib/sys/syscalls.h

    • Property cvs2svn:cvs-rev changed from 1.11 to 1.12
    r1460 r1461  
    166166extern int              _sys_init_environ(const char *pszEnv);
    167167extern void             _sys_init_largefileio(void);
    168 extern int              __libc_fhInit(__LIBC_PSPMINHFHBHDR  pInherit);
     168extern int              __libc_fhInit(void);
    169169/** @} */
    170170
Note: See TracChangeset for help on using the changeset viewer.