/*
 *  Copyright 2009 OpenSourceCodeStewardshipFoundation.org
 *  Licensed under GNU General Public License version 2
 *
 * Author: seanhalle@yahoo.com
 *
 * Created on November 14, 2009, 9:07 PM
 */
#ifndef _VMALLOC_H
#define	_VMALLOC_H

#include <malloc.h>
#include <inttypes.h>
#include "VMS_primitive_data_types.h"
#include "ProcrContext.h"

typedef struct _MallocProlog MallocProlog;

struct _MallocProlog
 {
   MallocProlog *nextChunkInFreeList;
   MallocProlog *prevChunkInFreeList;
   MallocProlog *nextHigherInMem;
   MallocProlog *nextLowerInMem;
 }; 
//MallocProlog
 
 typedef struct
 {
     uintptr_t procrID;
     MallocProlog *prevChunkInFreeList;
     MallocProlog *nextHigherInMem;
     MallocProlog *nextLowerInMem;
 } MallocPrologAllocated;

typedef struct
 {
   MallocProlog *firstChunkInFreeList;
   int32         numInList; //TODO not used
 } FreeListHead;

void *
VMS__malloc_on_core(size_t sizeRequested, int procrID);

void *
VMS__malloc(size_t sizeRequested);

void *
VMS__malloc_in_lib(size_t sizeRequested, VirtProcr *VProc);

void
VMS__free( void *ptrToFree );

void
VMS__free_in_lib(void *ptrToFree, VirtProcr *VProc);

void
VMS__free_on_core(void *ptrToFree, int procrID);

/*Allocates memory from the external system -- higher overhead
 */
void *
VMS__malloc_in_ext( size_t sizeRequested );

/*Frees memory that was allocated in the external system -- higher overhead
 */
void
VMS__free_in_ext( void *ptrToFree );


MallocProlog *
VMS_ext__create_free_list();

void
VMS_ext__free_free_list( MallocProlog *freeListHead );

#endif