MCPcopy Create free account
hub / github.com/WheretIB/nullc / MarkPointer

Function MarkPointer

NULLC/translation/runtime.cpp:829–862  ·  view source on GitHub ↗

Function that marks memory blocks belonging to GC

Source from the content-addressed store, hash-verified

827
828 // Function that marks memory blocks belonging to GC
829 void MarkPointer(char* ptr, const NULLCTypeInfo& type, bool takeSubtype)
830 {
831 // We have pointer to stack that has a pointer inside, so 'ptr' is really a pointer to pointer
832 char **rPtr = (char**)ptr;
833 // Check for unmanageable ranges. Range of 0x00000000-0x00010000 is unmanageable by default due to upvalues with offsets inside closures.
834 if(*rPtr > (char*)0x00010000 && (*rPtr < unmanageableBase || *rPtr > unmanageableTop))
835 {
836 // Get type that pointer points to
837 GC_DEBUG_PRINT("\tGlobal pointer %s %p (at %p)\r\n", type.name, *rPtr, ptr);
838
839 // Get pointer to the start of memory block. Some pointers may point to the middle of memory blocks
840 unsigned int *basePtr = (unsigned int*)NULLC::GetBasePointer(*rPtr);
841 // If there is no base, this pointer points to memory that is not GCs memory
842 if(!basePtr)
843 return;
844 GC_DEBUG_PRINT("\tPointer base is %p\r\n", basePtr);
845 // Marker is 4 bytes before the block
846 unsigned int *marker = (unsigned int*)(basePtr)-1;
847 GC_DEBUG_PRINT("\tMarker is %d\r\n", *marker & 0xff);
848
849 // If block is unmarked
850 if((*marker & 0xff) == 0)
851 {
852 // Mark block as used
853 *marker |= 1;
854 GC_DEBUG_PRINT("Type near memory %d, type %d (%d)\n", *marker >> 8, type.subTypeID, takeSubtype);
855 // And if type is not simple, check memory to which pointer points to
856 if(type.category != NULLC_NONE)
857 CheckVariable(*rPtr, takeSubtype ? __nullcTypeList[/*type.subTypeID*/*marker >> 8] : type);
858 }else if(takeSubtype && __nullcTypeList[type.subTypeID].category == NULLC_POINTER){
859 MarkPointer(*rPtr, __nullcTypeList[type.subTypeID], true);
860 }
861 }
862 }
863
864 // Function that checks arrays for pointers
865 void CheckArray(char* ptr, const NULLCTypeInfo& type)

Callers 3

CheckArrayFunction · 0.70
CheckFunctionFunction · 0.70
CheckVariableFunction · 0.70

Calls 1

CheckVariableFunction · 0.70

Tested by

no test coverage detected