diff options
Diffstat (limited to 'src/standalone/upg5')
| -rw-r--r-- | src/standalone/upg5/pagedir.c | 8 | ||||
| -rw-r--r-- | src/standalone/upg5/pagedir.h | 42 | ||||
| -rw-r--r-- | src/standalone/upg5/thread.h | 16 | ||||
| -rw-r--r-- | src/standalone/upg5/verify_adr.c | 90 |
4 files changed, 156 insertions, 0 deletions
diff --git a/src/standalone/upg5/pagedir.c b/src/standalone/upg5/pagedir.c new file mode 100644 index 0000000..7ef78a3 --- /dev/null +++ b/src/standalone/upg5/pagedir.c @@ -0,0 +1,8 @@ +/* The code that simulates and tests your address verification. How + this is done is disclosed. As a student you shall not compile this + file, but instead compile your program with the .o file as: + + gcc -Wall -Wextra -std=c99 -pedantic -g verify_adr.c pagedir.o + */ +#error Read comment above. Leave this line in place. + diff --git a/src/standalone/upg5/pagedir.h b/src/standalone/upg5/pagedir.h new file mode 100644 index 0000000..2919d1a --- /dev/null +++ b/src/standalone/upg5/pagedir.h @@ -0,0 +1,42 @@ +#ifndef PAGEDIR_H +#define PAGEDIR_H + +typedef int bool; +#define false 0 +#define true 1 + +/* Returns true iff 'adr' contains a null-character ('\0'). */ +bool is_end_of_string(char* adr); + +/* Returns the start address of the page that contains 'adr'. */ +void* pg_round_down(const void* adr); + +/* Returns the page number of the page that contains 'adr'. + * Page numbers are counted with start at zero (0). + */ +unsigned pg_no(const void* adr); + +/* Uses the page table to translate from logic to physical + * address. Returns NULL if the translation fail. + * + * The first parameter specify the top level page table to + * use. Normally you will find it in the structure corresponding + * to your operating systems PCB (Process Control Block). + */ +void *pagedir_get_page (void *pagetable, const void *adr); + +/* Page size: The number of bytes in each page. */ +#define PGSIZE 100 + +/* Functions used to simulate a paging system and testing your + * solution. */ +void start_evaluate_algorithm(void* start, int size); +void evaluate(bool result); +void end_evaluate_algorithm(); + +/* Let us decide how costly a simulated page fault is in terms of + * time. Does not exist in Pintos. Set to zero (0) for faster + * testing. */ +void simulator_set_pagefault_time(unsigned i); + +#endif diff --git a/src/standalone/upg5/thread.h b/src/standalone/upg5/thread.h new file mode 100644 index 0000000..62568ab --- /dev/null +++ b/src/standalone/upg5/thread.h @@ -0,0 +1,16 @@ +#ifndef THREAD_H +#define THREAD_H + +struct thread +{ + /* This is just a part of the Pintos Thread. */ + void* pagedir; +}; + +/* Initiate the threading system. */ +void thread_init(); + +/* Return a pointer to the currently active thread. */ +struct thread* thread_current(); + +#endif diff --git a/src/standalone/upg5/verify_adr.c b/src/standalone/upg5/verify_adr.c new file mode 100644 index 0000000..6aba06e --- /dev/null +++ b/src/standalone/upg5/verify_adr.c @@ -0,0 +1,90 @@ +#include <stdlib.h> +#include "pagedir.h" +#include "thread.h" + +/* verfy_*_lenght are intended to be used in a system call that accept + * parameters containing suspisious (user mode) adresses. The + * operating system (executng the system call in kernel mode) must not + * be fooled into using (reading or writing) addresses not available + * to the user mode process performing the system call. + * + * In pagedir.h you can find some supporting functions that will help + * you dermining if a logic address can be translated into a physical + * addrerss using the process pagetable. A single translation is + * costly. Work out a way to perform as few translations as + * possible. + * + * Recommended compilation command: + * + * gcc -Wall -Wextra -std=gnu99 -pedantic -g pagedir.o verify_adr.c + */ +#error Read comment above and then remove this line. + +/* Verify all addresses from and including 'start' up to but excluding + * (start+length). */ +bool verify_fix_length(void* start, int length) +{ + // ADD YOUR CODE HERE +} + +/* Verify all addresses from and including 'start' up to and including + * the address first containg a null-character ('\0'). (The way + * C-strings are stored.) + */ +bool verify_variable_length(char* start) +{ + // ADD YOUR CODE HERE +} + +/* Definition of test cases. */ +struct test_case_t +{ + void* start; + unsigned length; +}; + +#define TEST_CASE_COUNT 6 + +const struct test_case_t test_case[TEST_CASE_COUNT] = +{ + {(void*)100, 100}, /* one full page */ + {(void*)199, 102}, + {(void*)101, 98}, + {(void*)250, 190}, + {(void*)250, 200}, + {(void*)250, 210} +}; + +/* This main program will evalutate your solution. */ +int main(int argc, char* argv[]) +{ + int i; + bool result; + + if ( argc == 2 ) + { + simulator_set_pagefault_time( atoi(argv[1]) ); + } + thread_init(); + + /* Test the algorithm with a given intervall (a buffer). */ + for (i = 0; i < TEST_CASE_COUNT; ++i) + { + start_evaluate_algorithm(test_case[i].start, test_case[i].length); + result = verify_fix_length(test_case[i].start, test_case[i].length); + evaluate(result); + end_evaluate_algorithm(); + } + + /* Test the algorithm with a C-string (start address with + * terminating null-character). + */ + for (i = 0; i < TEST_CASE_COUNT; ++i) + { + start_evaluate_algorithm(test_case[i].start, test_case[i].length); + result = verify_variable_length(test_case[i].start); + evaluate(result); + end_evaluate_algorithm(); + } + return 0; +} |
