Permission is granted to use, modify, and / or redistribute at will.
 */
 
-/* This is a stub implementation of _PDCLIB_allocpages
-*/
-
 #include <stdint.h>
 #include <stddef.h>
 #include <_PDCLIB_glue.h>
 #include <errno.h>
+#include <gd_bal.h>
 
 void * _PDCLIB_allocpages( size_t n )
 {
-    errno = ENOTSUP;
-    return NULL;
+    void *p = NULL;
+    int rv = gd_alloc_pages( gd_loader_data, &p, n );
+
+    if (rv) {
+        errno = rv;
+        return NULL;
+    } else {
+        return p;
+    }
 }
 
 #ifdef TEST
 
 #include <stddef.h>\r
 #include <_PDCLIB_glue.h>\r
 #include <errno.h>\r
+#include <gd_bal.h>\r
 \r
 void _PDCLIB_freepages( void * p, size_t n )\r
 {\r
-    return;\r
+    int rv = 0;\r
+    if((rv = gd_free_pages( p, n ))) {\r
+        perror("_PDCLIB_freepages");\r
+        abort();\r
+    }\r
 }\r
 \r
 #ifdef TEST\r