MCPcopy Create free account
hub / github.com/BlitterStudio/amiberry / debugmem_allocate

Function debugmem_allocate

src/debugmem.cpp:914–994  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

912}
913
914static struct debugmemallocs *debugmem_allocate(uae_u32 size, uae_u32 flags, uae_u32 parentid)
915{
916 struct debugmemallocs *dm = getallocblock();
917 if (!dm)
918 return NULL;
919 if (size >= totalmemdata) {
920 console_out_f(_T("debugmem allocation larger than free space! Alloc size %d (%08x), flags %08x\n"), size, size, flags);
921 return 0;
922 }
923 int offset = debugmemptr / PAGE_SIZE;
924 bool gotit = true;
925 int totalsize = 0;
926 int extrasize = 0;
927 for (extrasize = HUNK_GAP; extrasize >= PAGE_SIZE; extrasize /= 2) {
928 totalsize = (extrasize + size + PAGE_SIZE - 1) & ~PAGE_SIZE_MASK;
929 for (int i = 0; i < totalmemdata; i++) {
930 struct debugmemdata *dm = dmd[offset];
931 if (offset + totalsize / PAGE_SIZE >= totalmemdata) {
932 offset = 0;
933 continue;
934 }
935 gotit = true;
936 // extra + size continous space available?
937 if (!(dm->flags & DEBUGMEM_ALLOCATED)) {
938 for (int j = 0; j < totalsize / PAGE_SIZE; j++) {
939 struct debugmemdata *dm2 = dmd[offset + j];
940 if (dm->flags & DEBUGMEM_ALLOCATED) {
941 gotit = false;
942 break;
943 }
944 }
945 }
946 if (gotit)
947 break;
948 offset++;
949 offset = offset % totalmemdata;
950 }
951 if (gotit)
952 break;
953 }
954 if (!gotit || !totalsize || !extrasize) {
955 console_out_f(_T("debugmem out of free space! Alloc size %d (%08x), flags %08x\n"), size, size, flags);
956 return 0;
957 }
958 dm->parentid = parentid;
959 dm->start_page = offset;
960 dm->pages = totalsize / PAGE_SIZE;
961 for (int j = 0; j < dm->pages; j++) {
962 struct debugmemdata *dm2 = dmd[offset + j];
963 dm2->flags |= DEBUGMEM_ALLOCATED;
964 dm2->id = dm->id;
965 }
966 memset(debugmem_bank.baseaddr + offset * PAGE_SIZE, 0xa3, totalsize);
967 int startoffset = extrasize / PAGE_SIZE;
968 dm->start = (offset + startoffset) * PAGE_SIZE;
969 dm->size = size;
970 dm->pc = M68K_GETPC;
971 for (int j = 0; j < (size + PAGE_SIZE - 1) / PAGE_SIZE; j++) {

Callers 4

debugmem_allocmemFunction · 0.85
loaddebugmemhunkfileFunction · 0.85
debugmem_relocFunction · 0.85
loadelffileFunction · 0.85

Calls 2

getallocblockFunction · 0.85
console_out_fFunction · 0.50

Tested by

no test coverage detected