Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
Loading items

Target

Select target project
  • y2-rhymansaib/pintos_student
1 result
Select Git revision
Loading items
Show changes
Commits on Source (2)
Showing with 283 additions and 13 deletions
......@@ -4,7 +4,7 @@ SRCDIR = ..
# To add a new test, put its name on the PROGS list
# and then add a name_SRC line that lists its source files.
PROGS = cat cmp cp echo halt hex-dump ls mcat mcp mkdir pwd rm shell \
bubsort insult lineup matmult recursor my
bubsort insult lineup matmult recursor my mycreate mywait myremove overflow
# Should work from project 2 onward.
cat_SRC = cat.c
......@@ -19,6 +19,11 @@ ls_SRC = ls.c
recursor_SRC = recursor.c
rm_SRC = rm.c
my_SRC = my.c
mycreate_SRC = mycreate.c
mywait_SRC = mywait.c
myremove_SRC = myremove.c
overflow_SRC = overflow.c
# Should work in project 3; also in project 4 if VM is included.
bubsort_SRC = bubsort.c
......
......@@ -4,7 +4,8 @@
int
main (void)
{
printf("Hello, World\n");
halt();
//dfgvdf
return EXIT_SUCCESS;
}
File added
#include <stdio.h>
#include <syscall.h>
//This file has been created too test the create system call
int
main (void)
{
create("myfile.txt", 1024);
return EXIT_SUCCESS;
}
File added
#include <stdio.h>
#include <syscall.h>
//This file has been created too test the remove system call
int
main (void)
{
remove("myfile.txt");
return EXIT_SUCCESS;
}
#include <stdio.h>
#include <syscall.h>
//This file has been created too test the create system call
int
main (void)
{
exit(-1);
return EXIT_SUCCESS;
}
File added
#include <stdio.h>
#include <syscall.h>
//This file has been created too test the create system call
int main (void)
{
wait(1);
return EXIT_SUCCESS;
}
File added
#include <stdio.h>
#include <syscall.h>
//This file has been created too test the overflow exploit
int
main (void)
{
remove("\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41");
//return EXIT_SUCCESS;
}
\ No newline at end of file
......@@ -18,6 +18,7 @@ size_t strspn (const char *, const char *);
char *strstr (const char *, const char *);
void *memset (void *, int, size_t);
size_t strlen (const char *);
char *strcpy(char *dest, const char *src);
/* Extensions. */
size_t strlcpy (char *, const char *, size_t);
......@@ -26,7 +27,7 @@ char *strtok_r (char *, const char *, char **);
size_t strnlen (const char *, size_t);
/* Try to be helpful. */
#define strcpy dont_use_strcpy_use_strlcpy
//#define strcpy dont_use_strcpy_use_strlcpy
#define strncpy dont_use_strncpy_use_strlcpy
#define strcat dont_use_strcat_use_strlcat
#define strncat dont_use_strncat_use_strlcat
......
......@@ -89,7 +89,7 @@ struct thread
uint8_t *stack; /* Saved stack pointer. */
int priority; /* Priority. */
struct list_elem allelem; /* List element for all threads list. */
struct file **fd_table;
/* Shared between thread.c and synch.c. */
struct list_elem elem; /* List element. */
......
......@@ -29,6 +29,10 @@ tid_t
process_execute (const char *file_name)
{
char *fn_copy;
char *save_ptr;
int file_name_size = strlen(file_name)+1;
char program_name[file_name_size];
tid_t tid;
/* Make a copy of FILE_NAME.
......@@ -38,8 +42,12 @@ process_execute (const char *file_name)
return TID_ERROR;
strlcpy (fn_copy, file_name, PGSIZE);
strlcpy(program_name,file_name,file_name_size);
strtok_r(program_name, " ", &save_ptr);
printf("Program name is --> %s\n", program_name);
/* Create a new thread to execute FILE_NAME. */
tid = thread_create (file_name, PRI_DEFAULT, start_process, fn_copy);
tid = thread_create (program_name, PRI_DEFAULT, start_process, fn_copy);
if (tid == TID_ERROR)
palloc_free_page (fn_copy);
......@@ -55,13 +63,27 @@ start_process (void *file_name_)
struct intr_frame if_;
bool success;
char *token, *save_ptr;
char *tokens[32];
int i = 0;
for(token = strtok_r(file_name, " ", &save_ptr); token != NULL; token = strtok_r(NULL, " ", &save_ptr)){
tokens[i] = token;
i++;
printf("Atay Debug : %s\n",tokens[i-1]);
}
printf("Argument count -->> %d\n",i);
/* Initialize interrupt frame and load executable. */
memset (&if_, 0, sizeof if_);
if_.gs = if_.fs = if_.es = if_.ds = if_.ss = SEL_UDSEG;
if_.cs = SEL_UCSEG;
if_.eflags = FLAG_IF | FLAG_MBS;
success = load (file_name, &if_.eip, &if_.esp);
success = load (tokens[0], &if_.eip, &if_.esp);
/* If load failed, quit. */
palloc_free_page (file_name);
......@@ -443,7 +465,7 @@ setup_stack (void **esp)
{
success = install_page (((uint8_t *) PHYS_BASE) - PGSIZE, kpage, true);
if (success) {
*esp = PHYS_BASE;
*esp = PHYS_BASE - 12;
} else
palloc_free_page (kpage);
}
......
#include "userprog/syscall.h"
#include <stdio.h>
//#include <string.h>
#include <syscall-nr.h>
#include "threads/interrupt.h"
#include "threads/thread.h"
#include <devices/shutdown.h>
#include "threads/init.h"
#include "filesys/filesys.h"
#include "lib/user/syscall.h"
#include "filesys/file.h"
#include "threads/synch.h"
#include <stdlib.h>
#include "threads/vaddr.h"
#include "threads/vaddr.h"
struct file* process_get_file (int fd); // FOR READ
void halt (void) NO_RETURN;
void exit (int status) NO_RETURN;
pid_t exec (const char *file);
int wait (pid_t pid);
bool create (const char *file, unsigned initial_size);
bool remove (const char *file);
int open (const char *file);
int filesize (int fd);
int read (int fd, void *buffer, unsigned length);
int write (int fd, const void *buffer, unsigned length);
void seek (int fd, unsigned position);
unsigned tell (int fd);
void close (int fd);
static int32_t usergrab (const uint8_t *uaddr);
int input_getc (void); // for read
struct file_descriptor
{
int fd;
struct file *file;
struct list_elem elem;
};
struct process_file
{
int fd;
struct file *file;
struct list_elem elem;
};
void strcpy(char *dest, const char *src)
{
int i = 0;
while ((dest[i] = src[i]) != '\0')
{
i++;
}
}
void strcpytest()
{
char a;
char b;
a = ("letsgetit");
b = ("empty");
printf(a);
printf(b);
strcpy(b, a);
printf(a);
printf(b);
}
static int
scanmem (void *src, void *dst, size_t bytes)
{
int32_t value;
size_t i;
for(i=0; i<bytes; i++) {
value = usergrab(src + i);
*(char*)(dst + i) = value & 0xff;
}
return (int)bytes;
}
//GET USER CODE
static int32_t
usergrab (const uint8_t *uaddr) {
// check that a user pointer `uaddr` points below PHYS_BASE
if (! ((void*)uaddr < PHYS_BASE)) {
return -1;
}
// as suggested in the reference manual, see (3.1.5)
int result;
asm ("movl $1f, %0; movzbl %1, %0; 1:"
: "=&a" (result) : "m" (*uaddr));
return result;
}
bool
create (const char *file, unsigned initial_size)
{
printf("file: %s\n", file);
printf("initial size: %d\n", initial_size);
printf("File generated succsessfully!");
//char str[20] = "fresh2refresh.com";
//char target[25] ="ello";
//printf("\n %s \n", str);
//printf("%s \n", target);
//strcpy(target, str);
//printf("%s \n", str);
//printf("%s \n", target);
return filesys_create (file, initial_size);
}
bool remove(const char* filename) {
//bool return_code;
char buf [100];
// memory validation missing no check user function // added now
printf ("CHECK USER RUN\n");
strcpy (buf, filename);
printf ("File removed --->");
printf (buf);
filesys_remove(buf);
}
static void syscall_handler (struct intr_frame *);
static uint32_t load_stack(struct intr_frame *f, int offset){
return *((uint32_t*)(f->esp + offset));
}
void
syscall_init (void)
{
intr_register_int (0x30, 3, INTR_ON, syscall_handler, "syscall");
}
struct file* //GET FILE FUNCTION
process_get_file (int fd)
{
struct thread *t = thread_current ();
if (fd < 0 || fd >= 128)
return NULL;
return t->fd_table[fd];
}
static void
syscall_handler (struct intr_frame *f UNUSED)
syscall_handler (struct intr_frame *f){
int code = (int)load_stack(f, 0);
switch (code){
case SYS_HALT:
printf("SYSTEM HALT CALL RUN SUCCSESSFULLY \n");
shutdown_power_off();
break;
case SYS_EXIT:
printf("EXIT DONE");
break;
case SYS_READ:
{
}
case SYS_CREATE:
{
const char *file;
unsigned initial_size;
scanmem (f->esp + 4, &file, sizeof file);
scanmem (f->esp + 8, &initial_size, sizeof initial_size);
f->eax = create (file, initial_size);
break;
}
case SYS_WAIT:
{
printf ("system call!\n");
}
case SYS_REMOVE:
{
const char* filename;
bool return_code;
scanmem(f->esp + 4, &filename, sizeof(filename));
return_code = remove(filename);
f->eax = return_code;
break;
}
}
thread_exit ();
}
......@@ -3,4 +3,5 @@
void syscall_init (void);
#endif /* userprog/syscall.h */
#! /bin/sh
# Path to GDB macros file. Customize for your site.
GDBMACROS=/usr/class/cs140/pintos/pintos/src/misc/gdb-macros
GDBMACROS=/home/dev/uwe_os/gitdown/pintos_student/src/misc
# Choose correct GDB.
if command -v i386-elf-gdb >/dev/null 2>&1; then
......