Example #1
0
void ProvReg_Dump(
    ProvReg* self,
    FILE* os)
{
    ProvRegEntry* p;

    for (p = self->head; p; p = p->next)
    {
        Ftprintf(os, PAL_T("==== ProvRegEntry\n"));
        Ftprintf(os, PAL_T("provInterface[%u]\n"), p->provInterface);
        Ftprintf(os, PAL_T("nameSpace[%T]\n"), tcs(p->nameSpace));
        Ftprintf(os, PAL_T("className[%T]\n"), tcs(p->className));
        Ftprintf(os, PAL_T("libraryName[%s]\n"), scs(p->libraryName));
    }
}
Example #2
0
/*
* Discover reg info of given class and all its children
* and add into list
*/
static int _DiscoverClassAndChildrenClasses(
    _In_opt_z_ const MI_Char* cn,
    _In_z_ const MI_Char* ns,
    _Inout_ IndicationClassList *list,
    _Inout_ MI_Uint32* classcount,
    _In_ MI_Boolean children,
    _In_ ProvRegType regtype)
{
    /* Find the class first */
    MI_Result r;
    ProvRegPosition pos;
    const ProvRegEntry* e = ProvReg_FindProviderForClassByType(list->provreg, ns, cn, regtype, &r);
    if (e)
    {
        if (IndicationClassList_AddEntry(list, e))
        {
            trace_DiscoverClassesFoundTypeClass( GetRegClassTypeName(regtype), e->className );
            (*classcount)++;
        }
        else
            trace_DiscoverClassesFailedToAdd(e->className, r);
    }
    else
        trace_DiscoverClassesNoRegInfo(GetRegClassTypeName(regtype), (cn) ? cn : PAL_T(""), ns);

    /* return if no need to discover children class */
    if (MI_FALSE == children)
        return 0;

    /* Begin enumeration of classes for this request */
    {
        r = ProvReg_BeginClasses(list->provreg, ns, cn, MI_TRUE, &pos, MI_FALSE);
        if (MI_RESULT_OK != r)
        {
            trace_DiscoverClassesBeginFailed(r, tcs(Result_ToString(r)), tcs(ns), tcs(cn));
            return -1;
        }
    }

    /* While more classes */
    for (;;)
    {
        const ZChar* derived = NULL;
        MI_Boolean done;

        r = ProvReg_NextClass(&pos, &derived, &done);

        if (done)
            break;

        if (MI_RESULT_OK != r)
        {
            trace_DiscoverClassesNextFailed(r, tcs(Result_ToString(r)), tcs(ns), tcs(cn));
            return -1;
        }
        e = ProvReg_FindProviderForClassByType(list->provreg, ns, derived, regtype, &r);
        if (e)
        {
            if (IndicationClassList_AddEntry(list, e))
            {
                trace_DiscoverClassesFoundTypeClass(GetRegClassTypeName(regtype), e->className);
                (*classcount)++;
            }
            else
                trace_DiscoverClassesFailedToAdd(e->className, r);
        }
    }

    /* Finalize enumeration */
    {
        r = ProvReg_EndClasses(&pos);
        if (MI_RESULT_OK != r)
        {
            trace_DiscoverClassesEndFailed(r, tcs(Result_ToString(r)));
            return -1;
        }
    }
    return 0;
}
int File_CopyT(_In_z_ const PAL_Char* src, _In_z_ const PAL_Char* dest)
{
    FILE* is = NULL;
    FILE* os = NULL;
    char buf[4096];

    /* Open input file */
    is = File_OpenT(src, PAL_T("rb"));
    if (!is)
        return -1;

#if defined(CONFIG_POSIX)
#ifndef CONFIG_ENABLE_WCHAR

    /* Unlink output file if it exists */
    if (access(dest, F_OK) == 0)
    {
        unlink(dest);
    }
#endif
#endif

    /* Open output file */
    os = File_OpenT(dest, PAL_T("wb"));
    if (!os)
    {
        File_Close(is);
        return -1;
    }

    /* Copy file */
    for (;;)
    {
#if defined(_MSC_VER)
        long n = (long)fread(buf, 1, sizeof(buf), is);
        long m;
#else
        ssize_t n = fread(buf, 1, sizeof(buf), is);
        ssize_t m;
#endif

        if (n <= 0)
            break;

#if defined(_MSC_VER)
        m  = (long)fwrite(buf, 1, n, os);
#else
        m  = (ssize_t)fwrite(buf, 1, n, os);
#endif

        if (m != n)
        {
            File_Close(is);
            File_Close(os);
            return -1;
        }
    }

    File_Close(is);
    File_Close(os);
    return 0;
}
Example #4
0
void SignalInjector()
{
    PAL_Char nameSignal[128] = PAL_T(CONFIG_SEMNAMELOCALPREFIX) PAL_T("NitsInjectorIn_");
    PAL_Char nameWait[128] = PAL_T(CONFIG_SEMNAMELOCALPREFIX) PAL_T("NitsInjectorOut_");
    PAL_Char nameLock[128] = PAL_T(CONFIG_SEMNAMELOCALPREFIX) PAL_T("NitsInjectorLock_");
    NamedSem semaphore;
    NamedSem lockSemaphore;    
    PAL_Char conversionBuf[64] = PAL_T("");
    const PAL_Char *convertedStr = NULL;
    size_t convertedSize = 0;
    // int waitSemValue = 0;
    int waitMilliSeconds = 100;    
    int waitForLockMilliSeconds = 500;
#ifndef _MSC_VER
    waitForLockMilliSeconds = 1000;
#endif

    TcsFromUInt64(conversionBuf, Process_ID(), &convertedStr, &convertedSize);
    Tcscat(nameSignal, 128, convertedStr);
    Tcscat(nameWait, 128, convertedStr);
    Tcscat(nameLock, 128, convertedStr);

    if(NamedSem_Open_Injected(&lockSemaphore, SEM_USER_ACCESS_ALLOW_ALL, 0, nameLock, 0, NitsReservedCallSite()) != 0)
    {
        /* The injector isn't there. */
        return;
    }

    if(NamedSem_TimedWait(&lockSemaphore, waitForLockMilliSeconds) != 0)
    {
        // could not acquire lock to the injector; some further shouldFault call will attempt to
        NamedSem_Close(&lockSemaphore);
        return;
    }

    if(NamedSem_Open_Injected(&semaphore, SEM_USER_ACCESS_ALLOW_ALL, 0, nameSignal, 0, NitsReservedCallSite()) != 0)
    {
        /* The injector isn't there. */
        goto End;
    }

    NamedSem_Post(&semaphore, 1);
    NamedSem_Close(&semaphore);

    if(NamedSem_Open_Injected(&semaphore, SEM_USER_ACCESS_ALLOW_ALL, 0, nameWait, 0, NitsReservedCallSite()) != 0)
    {
        /* The injector isn't there. */
        goto End;
    }

    /* Use a short timeout to prevent undesired behavior. In the worst
     * case, the injector thread will be starved and the patching will
     * happen later. */

#ifndef _MSC_VER
    // for non-windows the wait required is greater; this looks like a problem with the timedwait of namedsem; 
    waitMilliSeconds = 1000;
#endif
    NamedSem_TimedWait(&semaphore, waitMilliSeconds);
    NamedSem_Close(&semaphore);

End:
    NamedSem_Post(&lockSemaphore, 1);
    NamedSem_Close(&lockSemaphore);
    return;
}