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

Method FixupArray

NULLC/Executor.cpp:2015–2079  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2013}
2014
2015void Executor::FixupArray(char* ptr, const ExternTypeInfo& type)
2016{
2017 ExternTypeInfo *subType = type.nameHash == ExPriv::autoArrayName ? NULL : &exTypes[type.subType];
2018 unsigned int size = type.arrSize;
2019 if(type.arrSize == TypeInfo::UNSIZED_ARRAY)
2020 {
2021 // Get real array size
2022 size = *(int*)(ptr + NULLC_PTR_SIZE);
2023 // Switch pointer to array data
2024 char **rPtr = (char**)ptr;
2025
2026 // If it points to stack, fix it and return
2027 if(*rPtr >= ExPriv::oldBase && *rPtr < (ExPriv::oldBase + ExPriv::oldSize))
2028 {
2029 *rPtr = *rPtr - ExPriv::oldBase + ExPriv::newBase;
2030 return;
2031 }
2032 ptr = *rPtr;
2033 // If uninitialized, return
2034 if(!ptr || ptr <= (char*)0x00010000)
2035 return;
2036 // Get base pointer
2037 unsigned int *basePtr = (unsigned int*)NULLC::GetBasePointer(ptr);
2038 markerType *marker = (markerType*)((char*)basePtr - sizeof(markerType));
2039 // If there is no base pointer or memory already marked, exit
2040 if(!basePtr || !(*marker & 1))
2041 return;
2042 // Mark memory as used
2043 *marker &= ~1;
2044 }else if(type.nameHash == ExPriv::autoArrayName){
2045 NULLCAutoArray *data = (NULLCAutoArray*)ptr;
2046 // Get real variable type
2047 subType = &exTypes[data->typeID];
2048 // skip uninitialized array
2049 if(!data->ptr)
2050 return;
2051 // Mark target data
2052 FixupPointer(data->ptr, *subType);
2053 // Switch pointer to target
2054 ptr = data->ptr;
2055 // Get array size
2056 size = data->len;
2057 }
2058 if(!subType->pointerCount)
2059 return;
2060 switch(subType->subCat)
2061 {
2062 case ExternTypeInfo::CAT_ARRAY:
2063 for(unsigned int i = 0; i < size; i++, ptr += subType->size)
2064 FixupArray(ptr, *subType);
2065 break;
2066 case ExternTypeInfo::CAT_POINTER:
2067 for(unsigned int i = 0; i < size; i++, ptr += subType->size)
2068 FixupPointer(ptr, *subType);
2069 break;
2070 case ExternTypeInfo::CAT_CLASS:
2071 for(unsigned int i = 0; i < size; i++, ptr += subType->size)
2072 FixupClass(ptr, *subType);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected