TDDB68/TDDE47
Lesson 1
Felipe Boeira Based on previous slides from the course
TDDB68/TDDE47 Lesson 1 Felipe Boeira Based on previous slides from - - PowerPoint PPT Presentation
TDDB68/TDDE47 Lesson 1 Felipe Boeira Based on previous slides from the course Contents Overview of the labs General information about Pintos System calls Lab 0/Lab 1 details Debugging Administration Webreg: If you still
Felipe Boeira Based on previous slides from the course
Webreg:
(developed at Stanford University)
how pintos is structured and what you should do: you do not need to write a lot of code
time debugging!
These labs tend to be time-consuming
earn 4 bonus points on the exam
with Pintos
the given number of milliseconds
child process
lot of time to finish!
arguments according to the x86 convention
layout and pointer arithmetic
executing
have already created
calls, leads to an invalid state (open, close, write, read, and so on)
algorithm, and more)
struct Node { int data; struct Node* next; };
Node next next next NULL Node Node
next next
struct list_elem { struct list_elem *prev; /* Previous list element. */ struct list_elem *next; /* Next list element. */ }; struct list { struct list_elem head; /* List head. */ struct list_elem tail; /* List tail. */ }; struct Node { int data; struct list_elem elem; };
Node Node
prev prev
NULL
prev next prev
Head Tail NULL
next
together with the syscall no.;
supervisor mode;
delegates it to the appropriate subhandler, in this case, the syscall handler;
Already implemented!
... ...
esp+4 esp Stack growth syscall no. first argument User Stack Virtual Memory
/* Invokes syscall NUMBER, passing argument ARG0, and returns the return value as an `int'. */ #define syscall1(NUMBER, ARG0) \ ({ \ int retval; \ asm volatile \ ("pushl %[arg0]; pushl %[number]; int $0x30; addl $8, %%esp" \ : "=a" (retval) \ : [number] "i" (NUMBER), \ [arg0] "g" (ARG0) \ : "memory"); \ retval; \ }) int
{ return syscall1 (SYS_OPEN, file); }
lib/user/syscall.[h|c] - The syscall wrapper
arguments from the stack, and performs the syscall.
directly: bool create(const char *file, unsigned size) To get them you have to read them from the stack: f->esp
a pointer to the first character of the string.
This is the assignment!
Files to study:
process
earlier
decide the number of arguments
File descriptors (FD)
input/output resources
network sockets, and so on
knows what concrete resource it represents
stdout)
What to think about when implementing:
decide on a FD and how do we map it to an opened file? Every process has its own collection of opened files. FD values 0 and 1 are reserved for the console. Hint: Modify the struct thread to track file descriptors.
the FD with the file. Hint: Use already implemented functions.
revisit this syscall in Lab 3. Hint: Free resources in thread_exit.
What to think about when implementing:
gives a buffer (a piece of memory) in which the read bytes are written to. Return the number of read bytes. Hint: Use already implemented functions. Use input_getc to read from the console.
process gives a buffer with the content that should be written. Return the number of written bytes. Hint: Use already implemented
stdio.h and lib/kernel/console.c).
already implemented functions.
What to think about when implementing all of them:
files opened at the same time
We will revisit this topic in future labs
syscall are invalid? Such as NULL pointers, invalid buffer size, FDs with no associated file, and if the process has opened too many files
Frequently Asked Questions:
structure of the calling process
function file_close(file *) closes it
whilst the function thread_init(…) initialises the thread module (once, when Pintos starts up). If you need to do some initialisation for every thread, modify the former function (at the end of it)
pintos --qemu -- rm test0 rm test1 rm test2
ensure that there are no special cases
then something likely freed the memory
break Pintos in very obscure ways, and it is often easier to go back to a working version and redo the changes
Backtrace example:
Call stack: 0xc0106eff 0xc01102fb 0xc010dc22 0xc010cf67 0xc0102319 0xc010325a 0x804812c 0x8048a96 0x8048ac8
backtrace kernel.o 0xc0106eff 0xc01102fb 0xc010dc22 0xc010cf67 0xc0102319 0xc010325a 0x804812c 0x8048a96 0x8048ac8
0xc0106eff: debug_panic (lib/debug.c:86) 0xc01102fb: file_seek (filesys/file.c:405) 0xc010dc22: seek (userprog/syscall.c:744) 0xc010cf67: syscall_handler (userprog/syscall.c:444) 0xc0102319: intr_handler (threads/interrupt.c:334) 0xc010325a: intr_entry (threads/intr-stubs.S:38) …