ECS150 Project3 Solved

35.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: zip solution files instantly, after Payment

Securely Powered by: Secure Checkout

Description

5/5 - (1 vote)

You will be continuing the development of your virtual machine. You will be adding the ability to create, allocate, deallocate, query, and delete memory pools. Except were specified in this description the API will remain as stated in the Project 2 description. The memory pools allow for dynamic memory allocation from specified pools of memory,

there is a main system memory pool (VM_MEMORY_POOL_ID_SYSTEM) that is

dynamically allocated by the virtual machine at the beginning of execution. The stack space for each of the threads must be allocated from this memory pool. Space is allocated from the memory pools using a first fit algorithm.

The communication between the virtual machine and machine has changed. The MachineFileRead and MachineFileWrite functions require that shared memory locations be used to transfer data to/from the machine. In addition the maximum amount of data transferred must be limited to 512 bytes.

 

A working example of the vm and apps can be found in /home/cjnitta/ecs150. The vm syntax is vm [options] appname [appargs]. The possible options for vm are -t, -h, -m, and -s; -t specifies the tick time in millisecond, -h specifies the size of the heap this is the size of the VM_MEMORY_POOL_ID_SYSTEM memory pool, -m specifies the machine

timeout/responsiveness in milliseconds, and -s specifies the size of the shared memory used between the virtual machine and machine. By default the times are set to 10ms, for debugging purposes you can increase these values to slow the running of the vm. The size of the heap by default is 16MiB, and the shared memory is 16KiB. When specifying the application name the ./ should be prepended otherwise vm may fail to load the shared object file.

 

The function specifications for both the virtual machine and machine are provided in the subsequent pages.

 

You should avoid using existing source code as a primer that is currently available on the Internet. You must specify in your readme file any sources of code that you or your partner have viewed to help you complete this project. All class projects will be submitted to MOSS to determine if pairs of students have excessively collaborated with other pairs. Excessive collaboration, or failure to list external code sources will result in the matter being transferred to Student Judicial Affairs.

Name

VMStart – Start the virtual machine.

Synopsys

#include “VirtualMachine.h”

 

TVMStatus VMStart(int tickms, TVMMemorySize heapsize,  int machinetickms, TVMMemorySize sharedsize, int argc,  char *argv[]);

Description

VMStart() starts the virtual machine by loading the module specified by argv[0]. The argc and argv are passed directly into the VMMain() function that exists in the loaded module. The time in milliseconds of the virtual machine tick is specified by the tickms parameter, the machine responsiveness is specified by the machinetickms. The heap size

of the virtual machine is specified by heapsize. The heap is accessed by the applications through the VM_MEMORY_POOL_ID_SYSTEM memory pool. The size of the shared memory space between the virtual machine and the machine is specified by the sharedsize.

Return Value

Upon successful loading and running of the VMMain() function, VMStart() will return VM_STATUS_SUCCESS after VMMain() returns. If the module fails to load, or the module does not contain a VMMain() function, VM_STATUS_FAILURE is returned.

 

Name

VMMemoryPoolCreate – Creates a memory pool from an array of memory.

Synopsys

#include “VirtualMachine.h”

 

TVMStatus VMMemoryPoolCreate(void *base, TVMMemorySize size,

TVMMemoryPoolIDRef memory);

Description

VMMemoryPoolCreate() creates a memory pool from an array of memory. The base and size of the memory array are specified by base and size parameters respectively. The memory pool identifier is put into the location specified by the memory parameter.

Return Value

Upon successful creation of the memory pool, VMMemoryPoolCreate() will return

VM_STATUS_SUCCESS. If the base or memory are NULL, or size is zero VM_STATUS_ERROR_INVALID_PARAMETER is returned.

Name

VMMemoryPoolDelete – Deletes a memory pool from the virtual machine.

Synopsys

#include “VirtualMachine.h”

 

TVMStatus VMMemoryPoolDelete(TVMMemoryPoolID memory);

Description

VMMemoryPoolDelete() deletes a memory pool that has no memory allocated from the pool. The memory pool to delete is specified by the memory parameter.

Return Value

Upon successful deletion of the memory pool, VMMemoryPoolDelete() will return VM_STATUS_SUCCESS. If the memory pool specified by memory is not a valid

memory pool, VM_STATUS_ERROR_INVALID_PARAMETER is returned. If any memory has been allocated from the pool and not deallocated, then VM_STATUS_ERROR_INVALID_STATE is returned.

 

 

Name

VMMemoryPoolQuery – Queries the available space in the memory pool.

Synopsys

#include “VirtualMachine.h”

 

TVMStatus VMMemoryPoolQuery(TVMMemoryPoolID memory,

TVMMemorySizeRef byesleft);

Description

VMMemoryPoolQuery() queries a memory pool for the available memory left in the pool. The memory pool to query is specified by the memory parameter. The space left unallocated in the memory pool is placed in the location specified by bytesleft.

Return Value

Upon successful querying of the memory pool, VMMemoryPoolQuery() will return VM_STATUS_SUCCESS. If the memory pool specified by memory is not a valid memory pool or bytesleft is NULL, VM_STATUS_ERROR_INVALID_PARAMETER is returned.

 

Name

VMMemoryPoolAllocate – Allocates memory from the memory pool.

Synopsys

#include “VirtualMachine.h”

 

TVMStatus VMMemoryPoolAllocate(TVMMemoryPoolID memory,

TVMMemorySize size, void **pointer);

Description

VMMemoryPoolAllocate() allocates memory from the memory pool. The memory pool to allocate from is specified by the memory parameter. The size of the allocation is specified by size and the base of the allocated array is put in the location specified by pointer.

Return Value

Upon successful allocation from the memory pool, VMMemoryPoolAllocate() will return VM_STATUS_SUCCESS. If the memory pool specified by memory is not a valid memory pool, size is zero, or pointer is NULL,

VM_STATUS_ERROR_INVALID_PARAMETER is returned. If the memory pool does

not have sufficient memory to allocate the array of size bytes,

VM_STATUS_ERROR_INSUFFICIENT_RESOURCES is returned.

 

Name

VMMemoryPoolDeallocate – Deallocates memory to the memory pool.

Synopsys

#include “VirtualMachine.h”

 

TVMStatus VMMemoryPoolDeallocate(TVMMemoryPoolID memory,  void *pointer);

Description

VMMemoryPoolDeallocate() deallocates memory to the memory pool. The memory pool to deallocate to is specified by the memory parameter. The base of the previously allocated array is specified by pointer.

Return Value

Upon successful deallocation from the memory pool, VMMemoryPoolDeallocate() will return VM_STATUS_SUCCESS. If the memory pool specified by memory is not a valid

memory pool, or pointer is NULL, VM_STATUS_ERROR_INVALID_PARAMETER

is returned. If pointer does not specify a memory location that was previously allocated from the memory pool, VM_STATUS_ERROR_INVALID_PARAMETER is returned.

 

 

Name

MachineInitialize – Initializes the machine abstraction layer.

Synopsys

#include “Machine.h”

void *MachineInitialize(int timeout, size_t sharesize);

Description

MachineInitialize() initializes the machine abstraction layer. The timeout parameter specifies the number of milliseconds the machine will sleep between checking for requests. Reducing this number will increase its responsiveness. The sharesize parameter specifies the size of the shared memory location to be used by the machine. The size of the shared memory will be set to an integral number of pages (4096 bytes) that covers the size of sharesize.

Return Value

Upon successful initialization MachineInitialize returns the base address of the shared memory. NULL is returned if the machine has already been initialized. If the memory queues or shared memory fail to be allocated the program exits.

 

Name

MachineFileRead – Reads from a file in the machine abstraction.

Synopsys

#include “Machine.h”

typedef void (*TMachineFileCallback)(void *calldata, int result);

 

void MachineFileRead(int fd, void *data, int length, TMachineFileCallback callback, void *calldata);

Description

MachineFileRead() attempts to read the number of bytes specified in by length into the location specified by data from the file specified by fd. If the data value is not a location in the shared memory, MachineFileRead will fail; in addition if length is greater than 512 bytes MachineFileRead will also fail. The fd should have been obtained by a previous call to MachineFileOpen(). The actual number of bytes transferred will be returned in the result parameter when the callback function is called. Upon failure the result will be less than zero. The calldata parameter will also be passed into the callback function upon completion of the read file request. MachineFileRead () should return immediately, but will call the callback function asynchronously when completed.

Return Value

N/A

 

Name

MachineFileWrite – Writes to a file in the machine abstraction.

Synopsys

#include “Machine.h”

typedef void (*TMachineFileCallback)(void *calldata, int result);

 

void MachineFileWrite(int fd, void *data, int length, TMachineFileCallback callback, void *calldata);

Description

MachineFileWrite() attempts to write the number of bytes specified in by length into the location specified by data to the file specified by fd. If the data value is not a location in the shared memory, MachineFileWrite will fail; in addition if length is greater than 512 bytes MachineFileWrite will also fail. The fd should have been obtained by a previous call to MachineFileOpen(). The actual number of bytes transferred will be returned in the result parameter when the callback function is called. Upon failure the result will be less than zero. The calldata parameter will also be passed into the callback function upon completion of the write file request. MachineFileWrite() should return immediately, but will call the callback function asynchronously when completed.

Return Value

N/A

  • P3-wjxrrp.zip