Changeset 1677


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

Fixed potential deadlock/error in child on failed fork().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gcc/gcc/config/i386/emx-ctordtor.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1676 r1677  
    22   Optionally initializes frame unwind info (if emx-eh is linked in). */
    33
    4 extern int __CTOR_LIST__;
    5 extern int __DTOR_LIST__;
    6 extern int __eh_init__;
    7 extern int __eh_term__;
    8 extern void __ctordtorInit1 (int *);
    9 extern void __ctordtorTerm1 (int *);
    104
     5/*******************************************************************************
     6*   Header Files                                                               *
     7*******************************************************************************/
     8#include <InnoTekLIBC/fork.h>
     9#include <emx/startup.h>
     10
     11
     12/*******************************************************************************
     13*   Global Variables                                                           *
     14*******************************************************************************/
    1115/** Init indicator. 0 means not inited, 1 means inited. */
    1216static int inited;
    13 extern void __ctordtorInit (void);
    14 extern void __ctordtorTerm (void);
     17
     18
     19/*******************************************************************************
     20*   Internal Functions                                                         *
     21*******************************************************************************/
     22static int ctordtorForkChild(__LIBC_PFORKHANDLE pForkHandle, __LIBC_FORKOP enmOperation);
     23static void ctordtorForkComplete(void *pvArg, int rc, __LIBC_FORKCTX enmCtx);
     24
    1525
    1626/**
    1727 * Create static C++ objects.
    1828 */
    19 void __ctordtorInit (void)
     29void __ctordtorInit(void)
    2030{
    21   if (!inited)
     31    if (!inited)
    2232    {
    23       inited = 1;
    24       __ctordtorInit1 (&__eh_init__);
    25       __ctordtorInit1 (&__CTOR_LIST__);
     33        inited = 1;
     34        __ctordtorInit1(&__eh_init__);
     35        __ctordtorInit1(&__CTOR_LIST__);
    2636    }
    2737}
     38
    2839
    2940/**
    3041 * Destroy static C++ objects.
    3142 */
    32 void __ctordtorTerm (void)
     43void __ctordtorTerm(void)
    3344{
    34   if (inited)
     45    if (inited)
    3546    {
    36       inited = 0;
    37       __ctordtorTerm1 (&__DTOR_LIST__);
    38       __ctordtorTerm1 (&__eh_term__);
     47        inited = 0;
     48        __ctordtorTerm1(&__DTOR_LIST__);
     49        __ctordtorTerm1(&__eh_term__);
    3950    }
    4051}
     52
     53
     54_FORK_CHILD1(0xfffffffe, ctordtorForkChild)
     55
     56/**
     57 * Fork callback which will prevent the dtors from running
     58 * unless the fork is successful.
     59 *
     60 * @returns 0 on success.
     61 * @returns -errno on failure.
     62 * @param   pForkHandle     Pointer to fork handle.
     63 * @param   enmOperation    Fork operation.
     64 */
     65int ctordtorForkChild(__LIBC_PFORKHANDLE pForkHandle, __LIBC_FORKOP enmOperation)
     66{
     67    int     rc = 0;
     68    switch (enmOperation)
     69    {
     70        /*
     71         * Register a completion callback.
     72         */
     73        case __LIBC_FORK_OP_FORK_CHILD:
     74            rc = pForkHandle->pfnCompletionCallback(pForkHandle, ctordtorForkComplete, (void *)inited, __LIBC_FORK_CTX_CHILD);
     75        case __LIBC_FORK_OP_EXEC_CHILD:
     76            inited = 0;
     77            break;
     78
     79        default:
     80            break;
     81
     82    }
     83    return 0;
     84}
     85
     86
     87/**
     88 * Fork completion (child) callback for restoring inited to the correct value.
     89 *
     90 * @param   pvArg   The original value of inited.
     91 * @param   rc      The fork result. This is 0 on success. On failure it is the
     92 *                  negative errno value.
     93 * @param   enmCtx  The context the completion callback function is called in.
     94 */
     95static void ctordtorForkComplete(void *pvArg, int rc, __LIBC_FORKCTX enmCtx)
     96{
     97    /*
     98     * Restore the inited flag.
     99     */
     100    inited = !rc && pvArg;
     101
     102    /* unreferenced */
     103    enmCtx = enmCtx;
     104}
Note: See TracChangeset for help on using the changeset viewer.