# HG changeset patch # User Merten Sach # Date 1308228075 -7200 # Node ID 9ddbb071142df55aa6e3f11a481b32a40f67165f # Parent f6990e1ba998c12eca4f19791f3669d89eeb8850 make hardware independent and port to 64bit diff -r f6990e1ba998 -r 9ddbb071142d CoreLoop.c --- a/CoreLoop.c Thu Jun 02 13:55:51 2011 +0200 +++ b/CoreLoop.c Thu Jun 16 14:41:15 2011 +0200 @@ -7,8 +7,10 @@ #include "VMS.h" #include "Queue_impl/BlockingQueue.h" +#include "SwitchAnimators.h" #include +#include #include #include @@ -35,7 +37,7 @@ int thisCoresIdx; VirtProcr *currPr; VMSQueueStruc *readyToAnimateQ; - unsigned long coreMask; //has 1 in bit positions of allowed cores + cpu_set_t coreMask; //has 1 in bit positions of allowed cores int errorCode; //work-stealing struc on stack to prevent false-sharing in cache-line @@ -66,7 +68,9 @@ //set thread affinity //Linux requires pinning thd to core inside thread-function //Designate a core by a 1 in bit-position corresponding to the core - coreMask = 1 << coreLoopThdParams->coreNum; + CPU_ZERO(&coreMask); + CPU_SET(coreLoopThdParams->coreNum,&coreMask); + //coreMask = 1L << coreLoopThdParams->coreNum; pthread_t selfThd = pthread_self(); errorCode = @@ -76,7 +80,7 @@ //Save the return address in the SwitchVP function - saveCoreLoopReturnAddr(&(_VMSMasterEnv->coreLoopReturnPt)); + saveCoreLoopReturnAddr((void**)&(_VMSMasterEnv->coreLoopReturnPt)); while(1){ diff -r f6990e1ba998 -r 9ddbb071142d SwitchAnimators.h --- a/SwitchAnimators.h Thu Jun 02 13:55:51 2011 +0200 +++ b/SwitchAnimators.h Thu Jun 16 14:41:15 2011 +0200 @@ -8,9 +8,9 @@ #ifndef _SwitchAnimators_H #define _SwitchAnimators_H -#define __USE_GNU +#define _GNU_SOURCE -void saveCoreLoopReturnAddr(void *returnAddress); +void saveCoreLoopReturnAddr(void **returnAddress); void switchToVP(VirtProcr *nextProcr); @@ -18,8 +18,10 @@ void masterSwitchToCoreLoop(VirtProcr *nextProcr); +void startVirtProcrFn(); + #define flushRegisters() \ - asm volatile ("":::"%eax","%ebx", "%ecx", "%edx","%edi","%esi") + asm volatile ("":::"%rbx", "%r12", "%r13","%r14","%r15") /*Isolating code for switching between animators within these macros -- at * some point will make switches to compile for 32 bit or for 64 bit, which diff -r f6990e1ba998 -r 9ddbb071142d VMS.c --- a/VMS.c Thu Jun 02 13:55:51 2011 +0200 +++ b/VMS.c Thu Jun 16 14:41:15 2011 +0200 @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "VMS.h" @@ -138,7 +139,7 @@ readyToAnimateQs[ coreIdx ] = makeVMSQ(); //Q: should give masterVP core-specific info as its init data? - masterVPs[ coreIdx ] = VMS__create_procr( &masterLoop, masterEnv ); + masterVPs[ coreIdx ] = VMS__create_procr( (VirtProcrFnPtr)&masterLoop, (void*)masterEnv ); masterVPs[ coreIdx ]->coreAnimatedBy = coreIdx; allSchedSlots[ coreIdx ] = create_sched_slots(); //makes for one core _VMSMasterEnv->numMasterInARow[ coreIdx ] = 0; @@ -175,7 +176,7 @@ "master lock high time hist"); #endif - MakeTheMeasHists + MakeTheMeasHists(); //======================================================================== } @@ -293,26 +294,38 @@ */ inline VirtProcr * create_procr_helper( VirtProcr *newPr, VirtProcrFnPtr fnPtr, - void *initialData, char *stackLocs ) + void *initialData, void *stackLocs ) { - char *stackPtr; + void *stackPtr; newPr->startOfStack = stackLocs; newPr->procrID = _VMSMasterEnv->numProcrsCreated++; - newPr->nextInstrPt = fnPtr; newPr->initialData = initialData; newPr->requests = NULL; newPr->schedSlot = NULL; - //fnPtr takes two params -- void *initData & void *animProcr - //alloc stack locations, make stackPtr be the highest addr minus room - // for 2 params + return addr. Return addr (NULL) is in loc pointed to - // by stackPtr, initData at stackPtr + 4 bytes, animatingPr just above - stackPtr = ( (char *)stackLocs + VIRT_PROCR_STACK_SIZE - 0x10 ); + /* + * Hardware dependent part + */ + //instead of calling the function directly, call a wrapper function to fetch + //arguments from stack + newPr->nextInstrPt = (VirtProcrFnPtr)&startVirtProcrFn; + + //fnPtr takes two params -- void *initData & void *animProcr + //alloc stack locations, make stackPtr be the highest addr minus room + // for 2 params + return addr. Return addr (NULL) is in loc pointed to + // by stackPtr, initData at stackPtr + 8 bytes, animatingPr just above + stackPtr = ( (void *)stackLocs + VIRT_PROCR_STACK_SIZE - 4*sizeof(void*)); //setup __cdecl on stack -- coreloop will switch to stackPtr before jmp - *( (int *)stackPtr + 2 ) = (int) newPr; //rightmost param -- 32bit pointer - *( (int *)stackPtr + 1 ) = (int) initialData; //next param to left + *((VirtProcr**)stackPtr + 2 ) = newPr; //rightmost param + *((void**)stackPtr + 1 ) = initialData; //next param to left + *((void**)stackPtr) = (void*)fnPtr; + + /* + * end of Hardware dependent part + */ + newPr->stackPtr = stackPtr; //core loop will switch to this, then newPr->framePtr = stackPtr; //suspend loop will save new stack & frame ptr @@ -331,7 +344,7 @@ inline VirtProcr * VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData ) { VirtProcr *newPr; - char *stackLocs; + void *stackLocs; newPr = VMS__malloc( sizeof(VirtProcr) ); stackLocs = VMS__malloc( VIRT_PROCR_STACK_SIZE ); @@ -585,7 +598,6 @@ ResumePrFnPtr resumePrFnPtr ) { VMSSemReq *semReq; IntervalProbe *newProbe; - int32 nameLen; semReq = req->semReqData; diff -r f6990e1ba998 -r 9ddbb071142d VMS.h --- a/VMS.h Thu Jun 02 13:55:51 2011 +0200 +++ b/VMS.h Thu Jun 16 14:41:15 2011 +0200 @@ -8,7 +8,7 @@ #ifndef _VMS_H #define _VMS_H -#define __USE_GNU +#define _GNU_SOURCE #include "VMS_primitive_data_types.h" #include "Queue_impl/PrivateQueue.h" @@ -17,33 +17,32 @@ #include "Hash_impl/PrivateHash.h" #include "vmalloc.h" -//#include #include #include //=============================== Debug =================================== // - //When SEQUENTIAL is defined, VMS does sequential exe in the main thread - // It still does co-routines and all the mechanisms are the same, it just - // has only a single thread and animates VPs one at a time +//When SEQUENTIAL is defined, VMS does sequential exe in the main thread +// It still does co-routines and all the mechanisms are the same, it just +// has only a single thread and animates VPs one at a time //#define SEQUENTIAL //#define USE_WORK_STEALING - //turns on the probe-instrumentation in the application -- when not - // defined, the calls to the probe functions turn into comments +//turns on the probe-instrumentation in the application -- when not +// defined, the calls to the probe functions turn into comments #define STATS__ENABLE_PROBES //#define TURN_ON_DEBUG_PROBES - //These defines turn types of bug messages on and off - // be sure debug messages are un-commented (next block of defines) +//These defines turn types of bug messages on and off +// be sure debug messages are un-commented (next block of defines) #define dbgAppFlow TRUE /* Top level flow of application code -- general*/ #define dbgProbes FALSE /* for issues inside probes themselves*/ #define dbgB2BMaster FALSE /* in coreloop, back to back master VPs*/ #define dbgRqstHdlr FALSE /* in request handler code*/ - //Comment or un- the substitute half to turn on/off types of debug message +//Comment or un- the substitute half to turn on/off types of debug message #define DEBUG( bool, msg) \ // if( bool){ printf(msg); fflush(stdin);} #define DEBUG1( bool, msg, param) \ @@ -51,15 +50,15 @@ #define DEBUG2( bool, msg, p1, p2) \ // if(bool) {printf(msg, p1, p2); fflush(stdin);} -#define ERROR(msg) printf(msg); //fflush(stdin); -#define ERROR1(msg, param) printf(msg, param); fflush(stdin); -#define ERROR2(msg, p1, p2) printf(msg, p1, p2); fflush(stdin); +#define ERROR(msg) printf(msg); +#define ERROR1(msg, param) printf(msg, param); +#define ERROR2(msg, p1, p2) printf(msg, p1, p2); //=========================== STATS ======================= //when MEAS__TIME_STAMP_SUSP is defined, causes code to be inserted and // compiled-in that saves the low part of the time stamp count just before - // suspending a processor and just after resuming that processor. It is + // suspending a processor and just after resuming that processorsrc/VPThread_lib/VMS/VMS.h:322: warning: previous declaration of ‘VMS__create_procr’ was here. It is // saved into a field added to VirtProcr. Have to sanity-check for // rollover of low portion into high portion. //#define MEAS__TIME_STAMP_SUSP @@ -188,7 +187,7 @@ SchedSlot *schedSlot; VMSReqst *requests; - void *semanticData; //this lives here for the life of VP + void *semanticData; //this livesUSE_GNU here for the life of VP void *dataRetFromReq;//values returned from plugin to VP go here //=========== MEASUREMENT STUFF ========== @@ -197,7 +196,7 @@ unsigned int postSuspTSCLow; #endif #ifdef MEAS__TIME_MASTER /* in VirtProcr because multiple masterVPs*/ - unsigned int startMasterTSCLow; + unsigned int startMasterTSCLow;USE_GNU unsigned int endMasterTSCLow; #endif //======================================== @@ -319,7 +318,7 @@ void VMS__start_the_work_then_wait_until_done_Seq(); -VirtProcr * +inline VirtProcr * VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData ); void @@ -374,7 +373,7 @@ //======================== STATS ====================== -//===== RDTSC wrapper ===== +//===== RDTSC wrapper ===== //Also runs with x86_64 code #define saveTimeStampCountInto(low, high) \ asm volatile("RDTSC; \ @@ -411,7 +410,7 @@ #define condWaitHistIdx 4 #define condSignalHistIdx 5 -#define MakeTheMeasHists \ +#define MakeTheMeasHists() \ _VMSMasterEnv->measHistsInfo = \ makePrivDynArrayOfSize( (void***)&(_VMSMasterEnv->measHists), 200); \ makeAMeasHist( createHistIdx, "Create", 50, 0, 100 ) \ @@ -429,7 +428,7 @@ #define spawnHistIdx 1 #define syncHistIdx 2 -#define MakeTheMeasHists \ +#define MakeTheMeasHists() \ _VMSMasterEnv->measHistsInfo = \ makePrivDynArrayOfSize( (void***)&(_VMSMasterEnv->measHists), 200); \ makeAMeasHist( spawnHistIdx, "Spawn", 50, 0, 200 ) \ @@ -446,7 +445,7 @@ #define ReceiveFromToHistIdx 3 #define ReceiveOfTypeHistIdx 4 -#define MakeTheMeasHists \ +#define MakeTheMeasHists() \ _VMSMasterEnv->measHistsInfo = \ makePrivDynArrayOfSize( (void***)&(_VMSMasterEnv->measHists), 200); \ makeAMeasHist( SendFromToHistIdx, "SendFromTo", 50, 0, 100 ) \ diff -r f6990e1ba998 -r 9ddbb071142d contextSwitch.s --- a/contextSwitch.s Thu Jun 02 13:55:51 2011 +0200 +++ b/contextSwitch.s Thu Jun 16 14:41:15 2011 +0200 @@ -7,64 +7,70 @@ //Arguments: Pointer to variable holding address .globl saveCoreLoopReturnAddr saveCoreLoopReturnAddr: - movl 0x4(%esp) , %eax #load pointer - movl $coreLoopReturn, %ecx #load label address - movl %ecx, (%eax) #save address + movq $coreLoopReturn, %rcx #load label address + movq %rcx, (%rdi) #save address to pointer ret +//Initializes VirtProcrFn at first run for 64 bit mode +//Puts argument from stack into registers +.globl startVirtProcrFn +startVirtProcrFn: + movq %rdi , %rsi #get second argument from first argument of switchVP + movq 0x08(%rsp), %rdi #get first argument + movq (%rsp) , %rax #get function addr + jmp *%rax -//Switches form CoreLoop to VP ether normal VP or the Master Loop +//Switches form CoreLoop to VP ether a normal VP or the Master Loop //switch to virt procr's stack and frame ptr then jump to virt procr fn /* VirtProcr offsets: - * 0xc stackPtr - * 0x10 framePtr - * 0x14 nextInstrPt - * 0x1c coreLoopFramePtr - * 0x20 coreLoopStackPtr + * 0x10 stackPtr + * 0x18 framePtr + * 0x20 nextInstrPt + * 0x30 coreLoopFramePtr + * 0x38 coreLoopStackPtr * * _VMSMasterEnv offsets: - * 0x24 coreLoopReturnPt - * 0x2c masterLock + * 0x48 coreLoopReturnPt + * 0x54 masterLock */ .globl switchToVP switchToVP: - movl 0x4(%esp) , %ecx #get VirtProcr - movl %esp , 0x20(%ecx) #save core loop stack pointer - movl %ebp , 0x1c(%ecx) #save core loop frame pointer - movl 0x0c(%ecx), %esp #restore stack pointer - movl 0x10(%ecx), %ebp #restore frame pointer - movl 0x14(%ecx), %eax #get jmp pointer - jmp *%eax #jmp to VP + #VirtProcr in %rdi + movq %rsp , 0x38(%rdi) #save core loop stack pointer + movq %rbp , 0x30(%rdi) #save core loop frame pointer + movq 0x10(%rdi), %rsp #restore stack pointer + movq 0x18(%rdi), %rbp #restore frame pointer + movq 0x20(%rdi), %rax #get jmp pointer + jmp *%rax #jmp to VP coreLoopReturn: ret //switches to core loop. saves return address /* VirtProcr offsets: - * 0xc stackPtr - * 0x10 framePtr - * 0x14 nextInstrPt - * 0x1c coreLoopFramePtr - * 0x20 coreLoopStackPtr + * 0x10 stackPtr + * 0x18 framePtr + * 0x20 nextInstrPt + * 0x30 coreLoopFramePtr + * 0x38 coreLoopStackPtr * * _VMSMasterEnv offsets: - * 0x24 coreLoopReturnPt - * 0x28 coreLoopEndPt - * 0x2c masterLock + * 0x48 coreLoopReturnPt + * 0x54 masterLock */ .globl switchToCoreLoop switchToCoreLoop: - movl 0x4(%esp) , %ecx #get VirtProcr - movl $VPReturn , 0x14(%ecx) #store return address - movl %esp , 0x0c(%ecx) #save stack pointer - movl %ebp , 0x10(%ecx) #save frame pointer - movl 0x20(%ecx), %esp #restore stack pointer - movl 0x1c(%ecx), %ebp #restore frame pointer - movl $_VMSMasterEnv, %ecx - movl (%ecx) , %ecx - movl 0x24(%ecx), %eax #get CoreLoopStartPt - jmp *%eax #jmp to CoreLoop + #VirtProcr in %rdi + movq $VPReturn , 0x20(%rdi) #store return address + movq %rsp , 0x10(%rdi) #save stack pointer + movq %rbp , 0x18(%rdi) #save frame pointer + movq 0x38(%rdi), %rsp #restore stack pointer + movq 0x30(%rdi), %rbp #restore frame pointer + movq $_VMSMasterEnv, %rcx + movq (%rcx) , %rcx + movq 0x48(%rcx), %rax #get CoreLoopStartPt + jmp *%rax #jmp to CoreLoop VPReturn: ret @@ -73,55 +79,57 @@ //switches to core loop from master. saves return address //Releases masterLock so the next MasterLoop can be executed /* VirtProcr offsets: - * 0xc stackPtr - * 0x10 framePtr - * 0x14 nextInstrPt - * 0x1c coreLoopFramePtr - * 0x20 coreLoopStackPtr + * 0x10 stackPtr + * 0x18 framePtr + * 0x20 nextInstrPt + * 0x30 coreLoopFramePtr + * 0x38 coreLoopStackPtr * * _VMSMasterEnv offsets: - * 0x24 coreLoopReturnPt - * 0x2c masterLock + * 0x48 coreLoopReturnPt + * 0x54 masterLock */ .globl masterSwitchToCoreLoop masterSwitchToCoreLoop: - movl 0x4(%esp) , %ecx #get VirtProcr - movl $MasterReturn, 0x14(%ecx) #store return address - movl %esp , 0x0c(%ecx) #save stack pointer - movl %ebp , 0x10(%ecx) #save frame pointer - movl 0x20(%ecx), %esp #restore stack pointer - movl 0x1c(%ecx), %ebp #restore frame pointer - movl $_VMSMasterEnv, %ecx - movl (%ecx) , %ecx - movl 0x24(%ecx), %eax #get CoreLoopStartPt - movl $0x0 , 0x2c(%ecx) #release lock - jmp *%eax #jmp to CoreLoop + #VirtProcr in %rdi + movq $MasterReturn, 0x20(%rdi) #store return address + movq %rsp , 0x10(%rdi) #save stack pointer + movq %rbp , 0x18(%rdi) #save frame pointer + movq 0x38(%rdi), %rsp #restore stack pointer + movq 0x30(%rdi), %rbp #restore frame pointer + movq $_VMSMasterEnv, %rcx + movq (%rcx) , %rcx + movq 0x48(%rcx), %rax #get CoreLoopStartPt + movl $0x0 , 0x54(%rcx) #release lock + jmp *%rax #jmp to CoreLoop MasterReturn: ret //Switch to terminateCoreLoop +//therefor switch to coreLoop context from master context // no need to call because the stack is already set up for switchVP +// and virtPr is in %rdi // and both functions have the same argument. // do not save register of VP because this function will never return /* VirtProcr offsets: - * 0xc stackPtr - * 0x10 framePtr - * 0x14 nextInstrPt - * 0x1c coreLoopFramePtr - * 0x20 coreLoopStackPtr + * 0x10 stackPtr + * 0x18 framePtr + * 0x20 nextInstrPt + * 0x30 coreLoopFramePtr + * 0x38 coreLoopStackPtr * * _VMSMasterEnv offsets: - * 0x24 coreLoopReturnPt - * 0x2c masterLock + * 0x48 coreLoopReturnPt + * 0x58 masterLock */ .globl asmTerminateCoreLoop asmTerminateCoreLoop: - movl 0x4(%esp) , %ecx #get VirtProcr - movl 0x20(%ecx), %esp #restore stack pointer - movl 0x1c(%ecx), %ebp #restore frame pointer - movl $terminateCoreLoop, %eax - jmp *%eax #jmp to CoreLoop + #VirtProcr in %rdi + movq 0x38(%rdi), %rsp #restore stack pointer + movq 0x30(%rdi), %rbp #restore frame pointer + movq $terminateCoreLoop, %rax + jmp *%rax #jmp to CoreLoop /* @@ -130,13 +138,12 @@ */ .globl asmTerminateCoreLoopSeq asmTerminateCoreLoopSeq: - movl 0x4(%esp) , %ecx #get VirtProcr - movl 0x20(%ecx), %esp #restore stack pointer - movl 0x1c(%ecx), %ebp #restore frame pointer - sub $0x4 , %esp - movl %ecx , (%esp) #put argument on stack + #VirtProcr in %rdi + movq 0x38(%rdi), %rsp #restore stack pointer + movq 0x30(%rdi), %rbp #restore frame pointer + #argument is in %rdi call VMS__dissipate_procr - movl %ebp , %esp #goto the coreLoops stack - pop %ebp #restore the old framepointer + movq %rbp , %rsp #goto the coreLoops stack + pop %rbp #restore the old framepointer ret #return from core loop diff -r f6990e1ba998 -r 9ddbb071142d probes.c --- a/probes.c Thu Jun 02 13:55:51 2011 +0200 +++ b/probes.c Thu Jun 16 14:41:15 2011 +0200 @@ -5,10 +5,8 @@ */ #include -#include #include #include -#include #include "VMS.h" #include "Queue_impl/BlockingQueue.h" @@ -111,7 +109,7 @@ */ IntervalProbe * create_generic_probe( char *nameStr, VirtProcr *animPr ) - { IntervalProbe *newProbe; +{ VMSSemReq reqData; reqData.reqType = createProbe; @@ -297,20 +295,21 @@ { printf( "\nprobe: %s, ", probe->nameStr ); + if( probe->schedChoiceWasRecorded ) - { printf( "coreNum: %d, procrID: %d, procrCreated: %.6lf | ", + { printf( "coreNum: %d, procrID: %d, procrCreated: %0.6f | ", probe->coreNum, probe->procrID, probe->procrCreateSecs ); } if( probe->endSecs == 0 ) //just a single point in time { - printf( " time point: %.6lf\n", + printf( " time point: %.6f\n", probe->startSecs - _VMSMasterEnv->createPtInSecs ); } else if( probe->hist == NULL ) //just an interval { - printf( " startSecs: %.6lf, interval: %.6lf\n", - probe->startSecs - _VMSMasterEnv->createPtInSecs, probe->interval); + printf( " startSecs: %.6f interval: %.6f\n", + (probe->startSecs - _VMSMasterEnv->createPtInSecs), probe->interval); } else //a full histogram of intervals { @@ -338,16 +337,16 @@ void generic_print_probe( void *_probe ) - { IntervalProbe *probe; - - probe = (IntervalProbe *)_probe; - print_probe_helper( probe ); + { + IntervalProbe *probe = (IntervalProbe *)_probe; + + //TODO segfault in printf + //print_probe_helper( probe ); } void VMS_impl__print_stats_of_all_probes() - { IntervalProbe *probe; - + { forAllInDynArrayDo( _VMSMasterEnv->dynIntervalProbesInfo, &generic_print_probe ); fflush( stdout ); diff -r f6990e1ba998 -r 9ddbb071142d probes.h --- a/probes.h Thu Jun 02 13:55:51 2011 +0200 +++ b/probes.h Thu Jun 16 14:41:15 2011 +0200 @@ -8,7 +8,7 @@ #ifndef _PROBES_H #define _PROBES_H -#define __USE_GNU +#define _GNU_SOURCE #include "VMS_primitive_data_types.h" diff -r f6990e1ba998 -r 9ddbb071142d vmalloc.c --- a/vmalloc.c Thu Jun 02 13:55:51 2011 +0200 +++ b/vmalloc.c Thu Jun 16 14:41:15 2011 +0200 @@ -8,7 +8,9 @@ */ #include +#include #include +#include #include "VMS.h" #include "Histogram/Histogram.h" @@ -45,10 +47,10 @@ * *Will find a */ -void * -VMS__malloc( int32 sizeRequested ) +void *VMS__malloc( size_t sizeRequested ) { MallocProlog *foundElem = NULL, *currElem, *newElem; - int32 amountExtra, foundElemIsTopOfHeap, sizeConsumed,sizeOfFound; + ssize_t amountExtra, sizeConsumed,sizeOfFound; + uint32 foundElemIsTopOfHeap; //============================= MEASUREMENT STUFF ======================== #ifdef MEAS__TIME_MALLOC @@ -63,7 +65,7 @@ while( currElem != NULL ) { //check if size of currElem is big enough - sizeOfFound=(int32)((char*)currElem->nextHigherInMem -(char*)currElem); + sizeOfFound=(size_t)((uintptr_t)currElem->nextHigherInMem -(uintptr_t)currElem); amountExtra = sizeOfFound - sizeRequested - sizeof(MallocProlog); if( amountExtra > 0 ) { //found it, get out of loop @@ -99,7 +101,7 @@ if( amountExtra > 64 ) { //make new elem by adding to addr of curr elem then casting sizeConsumed = sizeof(MallocProlog) + sizeRequested; - newElem = (MallocProlog *)( (char *)foundElem + sizeConsumed ); + newElem = (MallocProlog *)( (uintptr_t)foundElem + sizeConsumed ); newElem->nextHigherInMem = foundElem->nextHigherInMem; newElem->nextLowerInMem = foundElem; foundElem->nextHigherInMem = newElem; @@ -124,7 +126,7 @@ //======================================================================== //skip over the prolog by adding its size to the pointer return - return (void *)((char *)foundElem + sizeof(MallocProlog)); + return (void*)((uintptr_t)foundElem + sizeof(MallocProlog)); } @@ -137,7 +139,8 @@ void VMS__free( void *ptrToFree ) { MallocProlog *elemToFree, *nextLowerElem, *nextHigherElem; - int32 lowerExistsAndIsFree, higherExistsAndIsFree, sizeOfElem; + size_t sizeOfElem; + uint32 lowerExistsAndIsFree, higherExistsAndIsFree; //============================= MEASUREMENT STUFF ======================== #ifdef MEAS__TIME_MALLOC @@ -152,8 +155,8 @@ return; } //subtract size of prolog to get pointer to prolog, then cast - elemToFree = (MallocProlog *)((char *)ptrToFree - sizeof(MallocProlog)); - sizeOfElem =(int32)((char*)elemToFree->nextHigherInMem-(char*)elemToFree); + elemToFree = (MallocProlog *)((uintptr_t)ptrToFree - sizeof(MallocProlog)); + sizeOfElem =(size_t)((uintptr_t)elemToFree->nextHigherInMem-(uintptr_t)elemToFree); if( elemToFree->prevChunkInFreeList != NULL ) { printf( "error: freeing same element twice!" ); exit(1); @@ -257,7 +260,7 @@ * empty or not -- */ void * -VMS__malloc_in_ext( int32 sizeRequested ) +VMS__malloc_in_ext( size_t sizeRequested ) { /* //This is running in the master, so no chance for multiple cores to be @@ -323,14 +326,14 @@ //Use this addr to free the heap when cleanup freeListHead->nextLowerInMem = firstChunk; //to identify top-of-heap elem, compare this addr to elem's next higher - freeListHead->nextHigherInMem = (void*)( (char*)firstChunk + + freeListHead->nextHigherInMem = (void*)( (uintptr_t)firstChunk + MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE); freeListHead->nextChunkInFreeList = firstChunk; firstChunk->nextChunkInFreeList = NULL; firstChunk->prevChunkInFreeList = freeListHead; //next Higher has to be set to top of chunk, so can calc size in malloc - firstChunk->nextHigherInMem = (void*)( (char*)firstChunk + + firstChunk->nextHigherInMem = (void*)( (uintptr_t)firstChunk + MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE); firstChunk->nextLowerInMem = NULL; //identifies as bott of heap diff -r f6990e1ba998 -r 9ddbb071142d vmalloc.h --- a/vmalloc.h Thu Jun 02 13:55:51 2011 +0200 +++ b/vmalloc.h Thu Jun 16 14:41:15 2011 +0200 @@ -11,6 +11,7 @@ #define _VMALLOC_H #include +#include #include "VMS_primitive_data_types.h" typedef struct _MallocProlog MallocProlog; @@ -27,12 +28,12 @@ typedef struct { MallocProlog *firstChunkInFreeList; - int32 numInList; + int32 numInList; //TODO not used } FreeListHead; void * -VMS__malloc( int32 sizeRequested ); +VMS__malloc( size_t sizeRequested ); void VMS__free( void *ptrToFree ); @@ -40,7 +41,7 @@ /*Allocates memory from the external system -- higher overhead */ void * -VMS__malloc_in_ext( int32 sizeRequested ); +VMS__malloc_in_ext( size_t sizeRequested ); /*Frees memory that was allocated in the external system -- higher overhead */