Changeset 2937


Ignore:
Timestamp:
Jan 3, 2007, 3:03:12 AM (19 years ago)
Author:
bird
Message:

Made libc07.dll link and load. still some init and term work left.

Location:
trunk/libc
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/libc/include/InnoTekLIBC/sharedpm.h

    r2819 r2937  
    653653
    654654/**
    655  * Initializes the shared process management for this process.
    656  *
    657  * This might actually initialize the SPM globally too if this is the
    658  * first process using it.
    659  *
    660  * @returns 0 on success.
    661  * @returns Negative error code (errno.h) on failure.
    662  */
    663 int __libc_spmInit(void);
    664 
    665 /**
    666655 * Gets the current process.
    667656 *
     
    669658 * @returns NULL and errno on failure.
    670659 * @remark  For this too __libc_spmRelease() must be called when done.
    671  */
    672 __LIBC_PSPMPROCESS __libc_spmSelf(void);
     660 * @param   fAutoInit   Set if it's ok to automatically initialize SPM.
     661 */
     662__LIBC_PSPMPROCESS __libc_spmSelf(int fAutoInit);
    673663
    674664/**
  • trunk/libc/src/kNIX/Makefile.kmk

    r2936 r2937  
    3636libc_kNIX_SOURCES = \
    3737    $(PATH_LIBC_SRC)/kNIX/b_initterm.c \
     38    $(PATH_LIBC_SRC)/kNIX/b_initArgv.c \
    3839    $(PATH_LIBC_SRC)/kNIX/b_fhImport.c \
    3940    $(PATH_LIBC_SRC)/kNIX/b_fhValidate.c \
     
    178179    $(PATH_LIBC_SRC)/kNIX/os2/_os2_bad.c \
    179180    $(PATH_LIBC_SRC)/kNIX/os2/__spawnve.c \
    180     $(PATH_LIBC_SRC)/kNIX/os2/__read_kbd.c
     181    $(PATH_LIBC_SRC)/kNIX/os2/__read_kbd.c \
     182    $(PATH_LIBC_SRC)/kNIX/os2/__select.c
    181183TODO= \
    182184    $(PATH_LIBC_SRC)/kNIX/os2/__init.c \
  • trunk/libc/src/kNIX/b_initterm.c

    r2936 r2937  
    134134     */
    135135    const int32_t cRefs = __atomic_increment_s32(&g_ckNIXUsers);
    136     if (cRefs != 1)
    137         LIBCLOG_RETURN_MSG(0, "ret 0 (g_ckNIXUsers=%d)\n", cRefs);
    138     int rc = __libc_back_init(hmod, pvOS, fFlags);
     136    int rc;
     137    if (cRefs == 1)
     138        rc = __libc_back_init(hmod, pvOS, fFlags);
     139    else
     140        /* (Might later add initialization code for every module here.) */
     141        rc = 0;
    139142    if (!rc)
    140143        LIBCLOG_RETURN_INT(0);
     144
     145    /* failure */
    141146    __atomic_decrement_s32(&g_ckNIXUsers);
    142147    LIBCLOG_ERROR_RETURN_INT(rc);
    143148}
    144149
     150
     151/**
     152 * Terminates the backend.
     153 * Called when a frontend shuts down.
     154 *
     155 * @returns 0 on success, non-zero on failure.
     156 * @param   hmod        The handle of the module that's causing the frontend to shut down.
     157 * @param   pvOS        OS specific argument.
     158 * @param   fFlags      Termination flags.
     159 */
     160int __libc_Back_term(uintptr_t hmod, void *pvOS, unsigned fFlags)
     161{
     162    /** @todo */
     163    return 0;
     164}
  • trunk/libc/src/kNIX/os2/b_initterm-os2.c

    r2936 r2937  
    7070{
    7171    LIBCLOG_ENTER("hmod=%tx pvOS=%p fFlags=%#x\n", hmod, pvOS, fFlags);
    72     int rc = __libc_spmInit();
     72    /*
     73     * Initialize _osmajor and _osminor.
     74     */
     75    ULONG aul[2] = {0, 0};
     76    DosQuerySysInfo(QSV_VERSION_MAJOR, QSV_VERSION_MINOR, &aul[0], sizeof(aul));
     77    _osminor = (unsigned char)aul[1];
     78    _osmajor = (unsigned char)aul[0];
     79
     80    /*
     81     * Check for high memory (>512MB) support.
     82     */
     83    ULONG ul;
     84    __libc_back_gcbVirtualAddressLimit = 512 * 1024 * 1024;
     85    if (    !DosQuerySysInfo(QSV_VIRTUALADDRESSLIMIT, QSV_VIRTUALADDRESSLIMIT, &ul, sizeof(ul))
     86        &&  ul > 512
     87        &&  (   (_osmajor == 20 && _osminor >= 40)
     88             || _osmajor > 20 /* yeah, sure! */) )
     89        __libc_back_gcbVirtualAddressLimit = ul * 1024*1024;
     90
     91    /*
     92     * Initialize TLS.
     93     */
     94    int rc = DosAllocThreadLocalMemory(1, (PULONG*)(void*)&__libc_gpTLS);
    7395    if (!rc)
    7496    {
    75         /*
    76          * Initialize _osmajor and _osminor.
    77          */
    78         ULONG aul[2] = {0, 0};
    79         DosQuerySysInfo(QSV_VERSION_MAJOR, QSV_VERSION_MINOR, &aul[0], sizeof(aul));
    80         _osminor = (unsigned char)aul[1];
    81         _osmajor = (unsigned char)aul[0];
    82 
    83         /*
    84          * Check for high memory (>512MB) support.
    85          */
    86         ULONG ul;
    87         __libc_back_gcbVirtualAddressLimit = 512 * 1024 * 1024;
    88         if (    !DosQuerySysInfo(QSV_VIRTUALADDRESSLIMIT, QSV_VIRTUALADDRESSLIMIT, &ul, sizeof(ul))
    89             &&  ul > 512
    90             &&  (   (_osmajor == 20 && _osminor >= 40)
    91                  || _osmajor > 20 /* yeah, sure! */) )
    92             __libc_back_gcbVirtualAddressLimit = ul * 1024*1024;
    93 
    94         /*
    95          * Initialize TLS.
    96          */
    97         rc = DosAllocThreadLocalMemory(1, (PULONG*)(void*)&__libc_gpTLS);
     97        rc = _fmutex_create2(&__libc_gmtxExec,  0, "LIBC SYS Exec Mutex");
    9898        if (!rc)
    9999        {
    100             rc = _fmutex_create2(&__libc_gmtxExec,  0, "LIBC SYS Exec Mutex");
    101             if (!rc)
     100            /* Ensure that SPM is initialized. */
     101            __LIBC_PSPMPROCESS pSelf = __libc_spmSelf(1 /* auto init */);
     102            if (pSelf)
    102103            {
    103                 __LIBC_PSPMPROCESS pSelf = __libc_spmSelf();
    104                 if (!pSelf)
    105                 {
    106                     /*
    107                      * Done here.
    108                      */
    109                     LIBCLOG_RETURN_INT(0);
    110                 }
    111                 else
    112                 {
    113                     LIBC_ASSERTM_FAILED("__libc_spmSelf() failed\n");
    114                     rc = -ESRCH;
    115                 }
    116                 _fmutex_close(&__libc_gmtxExec);
     104                __libc_spmRelease(pSelf);
     105
     106                /*
     107                 * Done here.
     108                 */
     109                LIBCLOG_RETURN_INT(0);
    117110            }
    118             DosFreeThreadLocalMemory((PULONG)__libc_gpTLS);
    119             __libc_gpTLS = NULL;
    120         }
    121         else
    122             LIBC_ASSERTM_FAILED("DosAllocThreadLocalMemory() failed. rc=%d\n", rc);
    123     }
     111            else
     112            {
     113                LIBC_ASSERTM_FAILED("__libc_spmSelf() failed\n");
     114                rc = -ESRCH;
     115            }
     116            _fmutex_close(&__libc_gmtxExec);
     117        }
     118        DosFreeThreadLocalMemory((PULONG)__libc_gpTLS);
     119        __libc_gpTLS = NULL;
     120    }
     121    else
     122        LIBC_ASSERTM_FAILED("DosAllocThreadLocalMemory() failed. rc=%d\n", rc);
     123    /** @todo terminate SPM */
    124124    LIBCLOG_ERROR_RETURN_INT(rc);
    125125}
     
    142142    DosFreeThreadLocalMemory((PULONG)__libc_gpTLS);
    143143    __libc_gpTLS = NULL;
     144
     145    /*
     146     * Terminate SPM.
     147     */
     148    /** @todo terminate SPM */
    144149
    145150    LIBCLOG_RETURN_VOID();
  • trunk/libc/src/kNIX/os2/libcfork.c

    r2929 r2937  
    350350        __libc_Timebomb();
    351351#endif
    352 
    353352        /*
    354353         * Find the SPM process.
    355354         */
    356         pProcess = __libc_spmSelf();
     355        pProcess = __libc_spmSelf(1 /* auto init */);
    357356        if (!pProcess)
    358357        {
     
    417416        {
    418417            pTib->tib_pexchain = XcptRegRec.Core.prev_structure;
     418            __libc_spmRelease(pProcess);
    419419            LIBCLOG_RETURN_INT(0);
    420420        }
     
    425425         */
    426426        pForkHandle = forkChlOpenHandle(pProcess->pvForkHandle);
     427        __libc_spmRelease(pProcess);
    427428        if (!pForkHandle)
    428429        {
     
    499500        /*
    500501         * Don't deregister modules which has already been deregistered.
    501          * Don't deregister if we're in shutting down the process (waste of time and
    502          * SPM might already be shut down).
     502         * Don't deregister if we're in shutting down the process (waste of time and SPM might already be shut down).
    503503         */
    504504        if (pModule->fFlags & __LIBC_FORKMODULE_FLAGS_DEREGISTERED)
     
    521521         * Find the SPM process.
    522522         */
    523         __LIBC_PSPMPROCESS pProcess = __libc_spmSelf();
     523        __LIBC_PSPMPROCESS pProcess = __libc_spmSelf(0 /* don't auto init */);
    524524        if (!pProcess)
    525525        {
    526526            pTib->tib_pexchain = XcptRegRec.Core.prev_structure;
    527             LIBC_ASSERTM_FAILED("can't find the process! weird!\n");
     527            LIBC_ASSERTM_FAILED("can't find the process! weird!\n"); /* DLL termination order might be screwed up... */
    528528            LIBCLOG_RETURN_VOID();
    529529        }
     
    559559        pModule->fFlags |= __LIBC_FORKMODULE_FLAGS_DEREGISTERED;
    560560
     561        __libc_spmRelease(pProcess);
    561562        pTib->tib_pexchain = XcptRegRec.Core.prev_structure;
    562563        LIBCLOG_RETURN_VOID();
     
    15661567     */
    15671568    forkBthCloseHandle(pForkHandle, __LIBC_FORK_CTX_CHILD);
    1568     __LIBC_PSPMPROCESS pProcess = __libc_spmSelf();
     1569    __LIBC_PSPMPROCESS pProcess = __libc_spmSelf(0 /* no init */);
    15691570    LIBC_ASSERTM(pProcess, "No self process!!!\n");
    15701571    pProcess->pvForkHandle = NULL;
    1571 
    1572     /*
    1573      * The return here will go back to the inline assmebly which called us in forkChlDoFork()
     1572    __libc_spmRelease(pProcess);
     1573
     1574
     1575    /*
     1576     * The return here will go back to the inline assembly which called us in forkChlDoFork()
    15741577     * and restore the stack pointer to the __libc_Back_processFork() and jump to the fork_ret
    15751578     * label in __libc_Back_processFork().
     
    22172220{
    22182221    __LIBC_PFORKMODULE  pModules;
    2219     __LIBC_PSPMPROCESS  pProcessSelf = __libc_spmSelf();
     2222    __LIBC_PSPMPROCESS  pProcessSelf = __libc_spmSelf(0 /* no init */);
    22202223    if (pProcessSelf)
    22212224    {
  • trunk/libc/src/kNIX/os2/sharedpm.c

    r2929 r2937  
    9393static int  spmRequestMutex(__LIBC_PSPMXCPTREGREC pRegRec);
    9494static int  spmReleaseMutex(__LIBC_PSPMXCPTREGREC pRegRec);
     95static int  spmInit(__LIBC_PSPMXCPTREGREC pRegRec);
    9596static VOID APIENTRY spmExitList(ULONG ulReason);
    9697static void spmCleanup(void);
     
    337338 *
    338339 * @returns Pointer to the current process.
    339  * @returns NULL and errno on failure.
     340 * @returns NULL on failure.
    340341 * @remark  For this too __libc_spmRelease() must be called when done.
    341  */
    342 __LIBC_PSPMPROCESS __libc_spmSelf(void)
    343 {
    344     LIBCLOG_ENTER("\n");
     342 * @param   fAutoInit   Set if it's ok to automatically initialize SPM.
     343 */
     344__LIBC_PSPMPROCESS __libc_spmSelf(int fAutoInit)
     345{
     346    LIBCLOG_ENTER("fAutoInit=%d\n", fAutoInit);
    345347    __LIBC_PSPMPROCESS pProcess;
    346348
     
    350352
    351353    /*
    352      * Check if we've already registered (we're allways registred).
    353      * If we have we'll simply return.
     354     * Read the cached variable.
     355     * If the caller permits automatic initialization, we'll give it a shot.
    354356     */
    355357    pProcess = gpSPMSelf;
    356     if (!pProcess)
    357     {
    358         __LIBC_SPMXCPTREGREC    RegRec;
    359         if (spmRequestMutexErrno(&RegRec))
    360             LIBCLOG_RETURN_P(NULL);
    361         if (!gpSPMSelf)
    362             pProcess = gpSPMSelf;
     358    if (!pProcess && fAutoInit)
     359    {
     360        /* Don't try initialize unless we're in a virgin state. */
     361        if (!gpSPMHdr && !gcNesting)
     362        {
     363            __LIBC_SPMXCPTREGREC RegRec;
     364            int rc = spmInit(&RegRec);
     365            if (!rc)
     366            {
     367                pProcess = gpSPMSelf;
     368                spmReleaseMutex(&RegRec);
     369                LIBC_ASSERT(pProcess);
     370            }
     371            else
     372                LIBCLOG_ERROR("rc=%d\n", rc);
     373        }
    363374        else
    364         {
    365             PTIB                    pTib;
    366             PPIB                    pPib;
    367             PLINFOSEG               pLIS = GETLINFOSEG();
    368             FS_VAR()
    369             FS_SAVE_LOAD();
    370             DosGetInfoBlocks(&pTib, &pPib);
    371             pProcess = spmRegisterSelf(pPib->pib_ulpid, pPib->pib_ulppid, pLIS->sgCurrent);
    372             FS_RESTORE();
    373         }
    374         spmReleaseMutex(&RegRec);
     375            LIBCLOG_MSG("fAutoInit=%d gpSPMHdr=%p gcNesting=%d\n", fAutoInit, gpSPMHdr, gcNesting);
    375376    }
    376377
     
    19661967    {
    19671968        /*
    1968          * Before exec we must ensure that we're opened
    1969          * for the logic below to work.
     1969         * Before exec we must ensure that we're opened for the logic below to work.
     1970         * (This is probably not necessary, but it doesn't hurt.)
    19701971         */
    19711972        case __LIBC_FORK_OP_EXEC_CHILD:
    19721973            if (!gpSPMSelf)
    1973                 __libc_spmSelf();
     1974                __libc_spmSelf(1 /* auto init */);
    19741975            LIBCLOG_RETURN_INT(0);
    19751976
     
    20442045
    20452046/**
    2046  * Requests the shared mutex semphore and checks that we're
    2047  * successfully initialized.
     2047 * Requests the shared mutex semphore and checks that we're successfully initialized.
     2048 *
    20482049 * @returns 0 on success.
    20492050 * @returns Negative error code (errno.h) on failure.
     
    20772078
    20782079    /*
    2079      * Check if initatied.
     2080     * Check if initiated.
    20802081     */
    20812082    if (!ghmtxSPM || !gpSPMHdr)
    20822083    {
    2083         LIBC_ASSERTM_FAILED("not initialized!\n");
     2084        LIBC_ASSERTM_FAILED("not initialized! rc=%d\n", rc);
    20842085        DosUnsetExceptionHandler(&pRegRec->Core);
    20852086        FS_RESTORE();
     
    21772178 * first process using it.
    21782179 *
    2179  * @returns 0 on success.
     2180 * @returns 0 on success, mutex owned.
    21802181 * @returns Negative error code (errno.h) on failure.
    2181  */
    2182 int __libc_spmInit(void)
     2182 *
     2183 * @param   pRegRec     Same as with spmRequestMutex().
     2184 */
     2185static int spmInit(__LIBC_PSPMXCPTREGREC pRegRec)
    21832186{
    21842187    LIBCLOG_ENTER("\n");
     
    22112214
    22122215    /*
     2216     * Install the exception handler.
     2217     */
     2218    FS_SAVE_LOAD();
     2219    pRegRec->Core.prev_structure   = (void *)~0;
     2220    pRegRec->Core.ExceptionHandler = spmXcptHandler;
     2221    DosSetExceptionHandler(&pRegRec->Core);
     2222
     2223    /*
     2224     * Check stack.
     2225     */
     2226    if (spmRequestMutexStackChecker())
     2227    {
     2228        DosUnsetExceptionHandler(&pRegRec->Core);
     2229        FS_RESTORE();
     2230        LIBC_ASSERTM_FAILED("Too little stack left!\n");
     2231        LIBCLOG_RETURN_INT(-EFAULT);
     2232    }
     2233
     2234    /*
    22132235     * Get current process id and parent process id
    22142236     * and install the exception handler.
     
    22192241     * Open or create mutex.
    22202242     */
    2221     FS_SAVE_LOAD();
    22222243    rc = DosOpenMutexSem((PCSZ)SPM_MUTEX_NAME, &ghmtxSPM);
    22232244    if (rc)
     
    22302251            if (rc2)
    22312252            {
     2253                DosUnsetExceptionHandler(&pRegRec->Core);
    22322254                FS_RESTORE();
    22332255                /* too bad, can create it for some reason. */
     
    23352357             */
    23362358            rc = DosExitList(0x9800 | EXLST_ADD, spmExitList);
     2359            LIBC_ASSERTM(!rc, "DosExitList failed with rc=%d\n", rc);
    23372360            FS_RESTORE();
    2338             DosReleaseMutexSem(ghmtxSPM);
    2339             DosExitMustComplete(&ul);
    2340             LIBC_ASSERTM(!rc, "DosExitList failed with rc=%d\n", rc);
    23412361            LIBCLOG_RETURN_INT(0);
    23422362        }
     
    23562376    gpSPMHdr = NULL;
    23572377    gpSPMSelf = NULL;
     2378    DosUnsetExceptionHandler(&pRegRec->Core);
    23582379    FS_RESTORE();
    23592380    rc = -__libc_back_native2errno(rc);
  • trunk/libc/src/libc/libc.def

    r2936 r2937  
    19531953    "__std_getdirents" @1951
    19541954    "___libc_Back_ioFileControlStandard" @1952
    1955     "___libc_Back_termDll" @1953
     1955    ; dead "___libc_Back_termDll" @1953
    19561956    "___libc_ForkDeregisterModule" @1954
    19571957    "__std_nan" @1955
     
    19601960
    19611961    ; new stuff 0.7
    1962     "__libc_back_envInitAsm" @1958
    1963     "__std_adjtime" @1959
    1964     "__std_getrusage" @1960
    1965     "__std_ttyname_r" @1961
     1962    "__std_adjtime" @1958
     1963    "__std_getrusage" @1959
     1964    "__std_ttyname_r" @1960
  • trunk/libc/src/libc/startup/initterm.c

    r2936 r2937  
    160160
    161161    /*
    162      * The remaining bits are only done once.
    163      *
    164      * We currently IGNORE the posibility that two thread might be racing here and
    165      * the loser begin able to call into LIBC while it's begin initialized.
    166      */
    167     const int32_t cRefs = __atomic_increment_s32(&g_cCrtUsers);
    168     if (cRefs != 1)
    169         LIBCLOG_RETURN_MSG(0, "ret 0 (g_cCrtUsers=%d)\n", cRefs);
    170 
    171     /*
    172162     * The backend must be initialized first.
    173163     */
     
    175165    if (!rc)
    176166    {
     167        /*
     168         * The remaining bits are only done once.
     169         *
     170         * We currently IGNORE the posibility that two thread might be racing here and
     171         * the loser begin able to call into LIBC while it's begin initialized.
     172         */
     173        const int32_t cRefs = __atomic_increment_s32(&g_cCrtUsers);
     174        if (cRefs != 1)
     175            LIBCLOG_RETURN_MSG(0, "ret 0 (g_cCrtUsers=%d)\n", cRefs);
     176
    177177        /*
    178178         * Init the frontend.
     
    182182         */
    183183
    184         /* weak initializers. */
    185         __ctordtorTerm1(&__crtinit1__);
    186 
    187         LIBCLOG_RETURN_INT(0);
     184        {
     185            /* weak initializers. */
     186            __ctordtorTerm1(&__crtinit1__);
     187
     188            LIBCLOG_RETURN_INT(0);
     189        }
     190        __atomic_decrement_s32(&g_cCrtUsers);
    188191    }
    189192
    190     __atomic_decrement_s32(&g_cCrtUsers);
    191193    LIBCLOG_ERROR_RETURN_INT(rc);
    192194}
  • trunk/libc/src/libc/startup/os2/x86/dll0.s

    r2936 r2937  
    6969     * What are we in for?
    7070     */
    71     movl    8(%ebp), %eax
     71    movl    0xc(%ebp), %eax
    7272    orl     %eax, %eax
    7373    je      dll0_init
Note: See TracChangeset for help on using the changeset viewer.