X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=platform%2Fposix%2Ffunctions%2F_PDCLIB%2F_PDCLIB_allocpages.c;fp=platform%2Fposix%2Ffunctions%2F_PDCLIB%2F_PDCLIB_allocpages.c;h=c63e7809ad0c2275e3e0d3fb73355c79c5631dc9;hb=9fcf1b27fc705cc131b258478d95ce9de65aabc0;hp=0000000000000000000000000000000000000000;hpb=f9ee8785d3c18603033ffbf7099f2a032186f2f9;p=pdclib.old diff --git a/platform/posix/functions/_PDCLIB/_PDCLIB_allocpages.c b/platform/posix/functions/_PDCLIB/_PDCLIB_allocpages.c new file mode 100644 index 0000000..c63e780 --- /dev/null +++ b/platform/posix/functions/_PDCLIB/_PDCLIB_allocpages.c @@ -0,0 +1,40 @@ +/* _PDCLIB_allocpages( int const ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +/* This is an example implementation of _PDCLIB_allocpages() (declared in + _PDCLIB_config.h), fit for use with POSIX kernels. +*/ + +#ifndef REGTEST +#include +#include +#include +#include <_PDCLIB_glue.h> + +void * _PDCLIB_allocpages( size_t n ) +{ + void *addr = mmap( + NULL, n * _PDCLIB_MALLOC_PAGESIZE, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_PRIVATE, -1, 0); + + if(addr != MAP_FAILED) { + return addr; + } else { + return NULL; + } +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + return TEST_RESULTS; +} + +#endif