Skip to content

Commit

Permalink
Fixing header and removing unused function
Browse files Browse the repository at this point in the history
  • Loading branch information
tesonep committed Apr 8, 2022
1 parent 2c5abc1 commit e9f3a44
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 45 deletions.
1 change: 0 additions & 1 deletion extracted/vm/include/common/sq.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
* If the attempt fails, answer null. If the attempt succeeds, answer the
* start of the region and assign its size through asp.
*/
extern void *sqAllocateMemorySegmentOfSizeAboveAllocatedSizeInto(sqInt sz, void *minAddr, sqInt *asp);
extern void sqDeallocateMemorySegmentAtOfSize(void *addr, sqInt sz);
#endif /* SPURVM */
/* Platform-dependent memory size adjustment macro. */
Expand Down
6 changes: 3 additions & 3 deletions extracted/vm/src/win/sqWin32SpurAlloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ sqAllocateMemorySegmentOfSizeAboveAllocatedSizeInto(sqInt size, void *minAddress
continue;
}
alloc = VirtualAlloc(address, bytes, MEM_COMMIT|MEM_RESERVE, PAGE_READWRITE);
logError("%p %p %lld", alloc, address, bytes);
/* For some reason (large page support?) we can ask for a page-aligned
* address such as 0xNNNNf000 but VirtualAlloc will answer 0xNNNN0000.
* So accept allocs above minAddress rather than allocs above address
Expand All @@ -168,9 +169,8 @@ sqAllocateMemorySegmentOfSizeAboveAllocatedSizeInto(sqInt size, void *minAddress
return alloc;
}
if (!alloc) {
DWORD lastError = GetLastError();
logWarn("Unable to VirtualAlloc committed memory at desired address (%lld bytes requested at %p, above %p), Error: %lu\n",
bytes, address, minAddress, lastError);
logWarn("Unable to VirtualAlloc committed memory at desired address (%lld bytes requested at %p, above %p)", bytes, address, minAddress);
logErrorFromGetLastError("Unable to VirtualAlloc committed memory at desired address");
return 0;
}
/* VirtualAlloc answered a mapping well away from where Spur prefers.
Expand Down
41 changes: 0 additions & 41 deletions src/memoryUnix.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,44 +196,3 @@ sqDeallocateMemorySegmentAtOfSize(void *addr, sqInt sz)
logErrorFromErrno("sqDeallocateMemorySegment... munmap");
}

void *
sqAllocateMemorySegmentOfSizeAboveAllocatedSizeInto(sqInt size, void *minAddress, sqInt *allocatedSizePointer)
{
void *alloc;
long bytes = roundUpToPage(size);
void *startAddress;
int count = 0;

if (!pageSize) {
pageSize = getpagesize();
pageMask = pageSize - 1;
}
*allocatedSizePointer = bytes;
while ((char *)minAddress + bytes > (char *)minAddress) {
startAddress = (void*)roundUpToPage((sqInt)minAddress);

alloc = mmap(startAddress, bytes,
PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0);
if (alloc == MAP_FAILED) {
logWarnFromErrno("sqAllocateMemorySegmentOfSizeAboveAllocatedSizeInto mmap");
return 0;
}

if(count >= 6){
logTrace("More than 6 retries... maybe something is wrong\n");
}

logTrace("Asked: %10p %10p %10p\n", alloc, minAddress, startAddress);
if (alloc >= minAddress){
logTrace("Allocated Piece: %10p\n", alloc);
return alloc;
}

count++;

if (munmap(alloc, bytes) != 0)
logWarnFromErrno("sqAllocateMemorySegment... munmap");
minAddress = (void *)((char *)minAddress + bytes);
}
return 0;
}

0 comments on commit e9f3a44

Please sign in to comment.