VirtualBox

Changeset 3162 in kBuild


Ignore:
Timestamp:
Mar 20, 2018 3:13:12 AM (7 years ago)
Author:
bird
Message:

kmk/win: Pretty sure I made this lpReserved2 mistake before. Duh.

Location:
trunk/src/kmk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/kmkbuiltin/redirect.c

    r3161 r3162  
    979979        StartupInfo.cb = sizeof(StartupInfo);
    980980        GetStartupInfoA(&StartupInfo);
     981        StartupInfo.lpReserved2 = 0; /* No CRT file handle + descriptor info possible, sorry. */
     982        StartupInfo.cbReserved2 = 0;
    981983        StartupInfo.dwFlags &= ~STARTF_USESTDHANDLES;
    982984
     
    10341036                /*
    10351037                 * Start the process in suspended animation so we can inject handles.
    1036                  *
    1037                  * We clear the reserved 2 pointer + size to avoid passing the wrong
    1038                  * filehandle info to the child.  We may later want to generate this.
    10391038                 */
    1040                 StartupInfo.cbReserved2 = 0;
    1041                 StartupInfo.lpReserved2 = 0;
    1042 
    10431039                if (CreateProcessA(pszExecutable, pszCmdLine, NULL /*pProcAttrs*/, NULL /*pThreadAttrs*/,
    10441040                                   FALSE /*fInheritHandles*/, CREATE_SUSPENDED, pszzEnv, pszCwd, &StartupInfo, &ProcInfo))
  • trunk/src/kmk/makeint.h

    r3156 r3162  
    653653#define OSSNS(_t,_a,_f,_s1,_s2,_n,_s3) _t((_a), strlen (_s1) + strlen (_s2) + strlen (_s3) + INTSTR_LENGTH, \
    654654                                          (_f), (_s1), (_s2), (_n), (_s3))          /* bird */
     655#define ONNS(_t,_a,_f,_n1,_n2,_s1)     _t((_a), INTSTR_LENGTH * 2 + strlen (_s1), \
     656                                          (_f), (_n1), (_n2), (_s1))                /* bird */
     657#define ONNNS(_t,_a,_f,_n1,_n2,_n3,_s1) _t((_a), INTSTR_LENGTH * 3 + strlen (_s1), \
     658                                          (_f), (_n1), (_n2), (_n3), (_s1))         /* bird */
    655659
    656660#define OUT_OF_MEM() O (fatal, NILF, _("virtual memory exhausted"))
  • trunk/src/kmk/w32/winchildren.c

    r3161 r3162  
    396396     */
    397397    InitializeSRWLock(&g_RWLock);
     398
     399    /*
     400     * This is dead code that was thought to fix a problem observed doing
     401     * `tcc.exe /c "kmk |& tee bld.log"` and leading to a crash in cl.exe
     402     * when spawned with fInheritHandles = FALSE, see hStdErr=NULL in the
     403     * child.  However, it turns out this was probably caused by not clearing
     404     * the CRT file descriptor and handle table in the startup info.
     405     * Leaving the code here in case it comes in handy after all.
     406     */
     407#if 0
     408    {
     409        struct
     410        {
     411            DWORD  uStdHandle;
     412            HANDLE hHandle;
     413        } aHandles[3] = { { STD_INPUT_HANDLE, NULL }, { STD_OUTPUT_HANDLE, NULL }, { STD_ERROR_HANDLE, NULL } };
     414        int i;
     415
     416        for (i = 0; i < 3; i++)
     417            aHandles[i].hHandle = GetStdHandle(aHandles[i].uStdHandle);
     418
     419        for (i = 0; i < 3; i++)
     420            if (   aHandles[i].hHandle == NULL
     421                || aHandles[i].hHandle == INVALID_HANDLE_VALUE)
     422            {
     423                int fd = open("nul", _O_RDWR);
     424                if (fd >= 0)
     425                {
     426                    if (_dup2(fd, i) >= 0)
     427                    {
     428                        assert((HANDLE)_get_osfhandle(i) != aHandles[i].hHandle);
     429                        assert((HANDLE)_get_osfhandle(i) == GetStdHandle(aHandles[i].uStdHandle));
     430                    }
     431                    else
     432                        ONNNS(fatal, NILF, "_dup2(%d('nul'), %d) failed: %u (%s)", fd, i, errno, strerror(errno));
     433                    if (fd != i)
     434                        close(fd);
     435                }
     436                else
     437                    ONNS(fatal, NILF, "open(nul,RW) failed: %u (%s)", i, errno, strerror(errno));
     438            }
     439            else
     440            {
     441                int j;
     442                for (j = i + 1; j < 3; j++)
     443                    if (aHandles[j].hHandle == aHandles[i].hHandle)
     444                    {
     445                        int fd = _dup(j);
     446                        if (fd >= 0)
     447                        {
     448                            if (_dup2(fd, j) >= 0)
     449                            {
     450                                aHandles[j].hHandle = (HANDLE)_get_osfhandle(j);
     451                                assert(aHandles[j].hHandle != aHandles[i].hHandle);
     452                                assert(aHandles[j].hHandle == GetStdHandle(aHandles[j].uStdHandle));
     453                            }
     454                            else
     455                                ONNNS(fatal, NILF, "_dup2(%d, %d) failed: %u (%s)", fd, j, errno, strerror(errno));
     456                            if (fd != j)
     457                                close(fd);
     458                        }
     459                        else
     460                            ONNS(fatal, NILF, "_dup(%d) failed: %u (%s)", j, errno, strerror(errno));
     461                    }
     462            }
     463    }
     464#endif
    398465}
    399466
     
    538605    StartupInfo.cb = sizeof(StartupInfo);
    539606    GetStartupInfoW(&StartupInfo);
     607    StartupInfo.lpReserved2 = 0; /* No CRT file handle + descriptor info possible, sorry. */
     608    StartupInfo.cbReserved2 = 0;
    540609    if (!fHaveHandles)
    541610        StartupInfo.dwFlags &= ~STARTF_USESTDHANDLES;
     
    544613        fFlags |= CREATE_SUSPENDED;
    545614        StartupInfo.dwFlags &= ~STARTF_USESTDHANDLES;
    546 
    547         /* Don't pass CRT inheritance info to the child (from our parent actually). */
    548         StartupInfo.cbReserved2 = 0;
    549         StartupInfo.lpReserved2 = 0;
    550615    }
    551616
     
    24042469}
    24052470
     2471#if 0  /* no longer needed */
    24062472/** Serialization with kmkbuiltin_redirect. */
    24072473void MkWinChildExclusiveAcquire(void)
     
    24152481    ReleaseSRWLockExclusive(&g_RWLock);
    24162482}
     2483#endif
    24172484
    24182485/**
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette