Skip to content

Commit

Permalink
Change loadPharoImage function + try memory map works
Browse files Browse the repository at this point in the history
  • Loading branch information
PalumboN committed Feb 10, 2022
1 parent 3f0101c commit f9b484e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 36 deletions.
2 changes: 1 addition & 1 deletion extracted/vm/include/common/sq.h
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ sqInt ioDisableImageWrite(void);

#include "pharovm/imageAccess.h"

size_t readImageFromFileStartingAt(sqImageFile f, squeakFileOffsetType imageOffset);
sqInt readImageNamed(char* fileName);

/* Clipboard (cut/copy/paste). */
sqInt clipboardSize(void);
Expand Down
2 changes: 1 addition & 1 deletion include/pharovm/pharo.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ void *readAddress(sqInt anExternalAddress);
EXPORT(int) isVMRunOnWorkerThread();
void setMaxStacksToPrint(sqInt anInteger);

#define allocateMemoryBaseAddress(a, b) sqAllocateMemory(a, a, b)
#define allocateMemoryBaseAddress(desiredSize, baseAddress) sqAllocateMemory(0, desiredSize, baseAddress)
20 changes: 6 additions & 14 deletions src/client.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <sys/stat.h>
#include "pharovm/pharo.h"
#include "pharovm/pharoClient.h"
#include "pharovm/fileDialog.h"
Expand Down Expand Up @@ -209,24 +210,15 @@ vm_main(int argc, const char** argv, const char** env)
static int
loadPharoImage(const char* fileName)
{
size_t imageSize = 0;
sqImageFile imageFile = NULL;
struct stat sb;

/* Open the image file. */
imageFile = sqImageFileOpen(fileName, "rb");
if(!imageFile)
{
logErrorFromErrno("Opening Image");
/* Check image exists */
if (stat(fileName, &sb) == -1) {
logErrorFromErrno("Image file not found");
return false;
}

/* Get the size of the image file*/
sqImageFileSeekEnd(imageFile, 0);
imageSize = sqImageFilePosition(imageFile);
sqImageFileSeek(imageFile, 0);

readImageFromFileStartingAt(imageFile, 0);
sqImageFileClose(imageFile);
readImageNamed(fileName);

char* fullImageName = alloca(FILENAME_MAX);
fullImageName = getFullPath(fileName, fullImageName, FILENAME_MAX);
Expand Down
24 changes: 4 additions & 20 deletions src/memoryUnix.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ sqInt uxMemoryExtraBytesLeft(sqInt includingSwap);
int overallocateMemory = 0;

static sqInt devZero = -1;
static char *heap = 0;
static sqInt heapSize = 0;
static sqInt heapLimit = 0;

#ifndef max
# define max(a, b) (((a) > (b)) ? (a) : (b))
Expand Down Expand Up @@ -123,16 +120,14 @@ void* allocateJITMemory(usqInt desiredSize, usqInt desiredPosition){
/* answer the address of (minHeapSize <= N <= desiredHeapSize) bytes of memory. */
usqInt
sqAllocateMemory(usqInt minHeapSize, usqInt desiredHeapSize, usqInt desiredBaseAddress) {

if (heap) {
logError("uxAllocateMemory: already called\n");
exit(1);
}
char *heap = 0;
sqInt heapSize = 0;
sqInt heapLimit = 0;

pageSize = getpagesize();
pageMask = ~(pageSize - 1);

heapLimit = valign(max(desiredHeapSize, 1));
heapLimit = valign(max(desiredHeapSize, 1)) + pageSize; // Add 1 page more just in case (G & N)
usqInt desiredBaseAddressAligned = valign(desiredBaseAddress);

logDebug("Trying to load the image in %p\n",
Expand Down Expand Up @@ -183,17 +178,6 @@ sqAllocateMemory(usqInt minHeapSize, usqInt desiredHeapSize, usqInt desiredBaseA
return (usqInt) heap;
}

/* answer the number of bytes available for growing the heap. */

sqInt uxMemoryExtraBytesLeft(sqInt includingSwap)
{
return heapLimit - heapSize;
}


sqInt sqMemoryExtraBytesLeft(sqInt includingSwap) { return uxMemoryExtraBytesLeft(includingSwap); }


/* Deallocate a region of memory previously allocated by
* sqAllocateMemorySegmentOfSizeAboveAllocatedSizeInto. Cannot fail.
*/
Expand Down

0 comments on commit f9b484e

Please sign in to comment.