Logo Search packages:      
Sourcecode: virtualbox-ose version File versions  Download package

KHLP_DECL ( int   ) 

Allocate a chunk of memory with page granularity.

Returns:
0 on success, non-zero OS status code on failure.
Parameters:
ppv Where to store the address of the allocated memory. If fFixed is set, *ppv will on entry contain the desired address (page aligned).
cb Number of bytes. Page aligned.
enmProt The new protection. Copy-on-write is invalid.
Change the protection of one or more pages in an allocation.

(This will of course only work correctly on memory allocated by kHlpPageAlloc().)

Returns:
0 on success, non-zero OS status code on failure.
Parameters:
pv First page. Page aligned.
cb Number of bytes. Page aligned.
enmProt The new protection. Copy-on-write is invalid.
Free memory allocated by kHlpPageAlloc().

Returns:
0 on success, non-zero OS status code on failure.
Parameters:
pv The address returned by kHlpPageAlloc().
cb The byte count requested from kHlpPageAlloc().

Todo:
convert errno -> kErrors

Definition at line 153 of file kHlpPage.c.

References DWORD, and NULL.

{
#if K_OS == K_OS_DARWIN \
 || K_OS == K_OS_FREEBSD \
 || K_OS == K_OS_LINUX \
 || K_OS == K_OS_NETBSD \
 || K_OS == K_OS_OPENBSD \
 || K_OS == K_OS_SOLARIS
    void *pv;

    pv = kHlpSys_mmap(fFixed ? *ppv : NULL, cb, kHlpPageProtToNative(enmProt),
                      fFixed ? MAP_FIXED | MAP_ANON: MAP_ANON, -1, 0);
    if ((KIPTR)pv < 256)
    {
        kHlpAssert(0);
        return (int)(KIPTR)pv; /** @todo convert errno to kErrors */
    }
    *ppv = pv;
    return 0;

#elif K_OS == K_OS_OS2
    APIRET  rc;
    ULONG   fFlags = kHlpPageProtToNative(enmProt);

    if (!fFixed)
    {
        /* simple */
        rc = DosAllocMem(ppv, cb, fFlags | OBJ_ANY);
        if (rc == ERROR_INVALID_PARAMETER)
            rc = DosAllocMem(ppv, cb, fFlags);
    }
    else
    {
        /* not so simple. */
        /** @todo I've got code for this in libc somewhere. */
        rc = -1;
    }
    if (!rc)
        return 0;
    kHlpAssert(0);
    return rc;

#elif  K_OS == K_OS_WINDOWS
    /* (We don't have to care about the stub here, because the stub will be unmapped before we get here.) */
    int     rc;
    DWORD   fProt = kHlpPageProtToNative(enmProt);

    if (!g_SystemInfo.dwPageSize)
        GetSystemInfo(&g_SystemInfo);

    *ppv = VirtualAlloc(fFixed ? *ppv : NULL, cb, MEM_COMMIT, fProt);
    if (*ppv != NULL)
        return 0;
    rc = GetLastError();
    kHlpAssert(0);
    return rc;

#else
# error "port me"
#endif
}


Generated by  Doxygen 1.6.0   Back to index