-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#6] Basic syscall handler and skeleton for each syscall #42
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do your codes always have lots of INVALID coding styles? PLEASE CHECK yourself before (and even after) pushing your commits. 💢
src/userprog/syscall.c
Outdated
#include "threads/init.h" | ||
#include "threads/malloc.h" | ||
|
||
#define WORD_SIZE sizeof(uintptr_t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parenthesis, Spacing
src/userprog/syscall.c
Outdated
|
||
static void syscall_handler (struct intr_frame *); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blank line
src/userprog/syscall.c
Outdated
void | ||
syscall_init (void) | ||
{ | ||
intr_register_int (0x30, 3, INTR_ON, syscall_handler, "syscall"); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blank line
src/userprog/syscall.c
Outdated
for (i = 1; i <= 3; i++) | ||
args[i] = f->esp + WORD_SIZE * i; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blank line
src/userprog/syscall.c
Outdated
|
||
switch (syscall_num) | ||
{ | ||
case SYS_HALT: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation
src/userprog/syscall.c
Outdated
power_off(); | ||
} | ||
|
||
static void syscall_exit (void ** args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spacing (Same for all the cases below)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also on prototypes.
src/userprog/syscall.c
Outdated
static int syscall_write (void ** args); | ||
static void syscall_seek (void ** args); | ||
static unsigned syscall_tell (void ** args); | ||
static void syscall_close (void ** args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use vertical aligning.
src/userprog/syscall.c
Outdated
static int syscall_write (void ** args); | ||
static void syscall_seek (void ** args); | ||
static unsigned syscall_tell (void ** args); | ||
static void syscall_close (void ** args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Above prototypes should move to line 12.
src/userprog/syscall.c
Outdated
syscall_exit(args); | ||
break; | ||
case SYS_EXEC: | ||
f->eax = syscall_exec (void ** args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does each of your f->eax = syscall_xxxx (void ** args);
lines has void **
?
src/userprog/syscall.c
Outdated
|
||
static void syscall_halt (void) | ||
{ | ||
power_off(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this implemented? It's not for this issue.
I asked you to make your infrastructure helps other contributor to implement each system call without thinking other things. It means if I'm the assignee for implementing |
src/userprog/syscall.c
Outdated
static void syscall_seek (void ** args); | ||
static unsigned syscall_tell (void ** args); | ||
static void syscall_close (void ** args); | ||
|
||
static void | ||
syscall_handler (struct intr_frame *f UNUSED) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment is missing.
Let me review later for other things about your logic, algorithm, and implementation AFTER you fix above requests. |
src/userprog/syscall.c
Outdated
static void | ||
syscall_handler (struct intr_frame *f UNUSED) | ||
{ | ||
printf ("system call!\n"); | ||
thread_exit (); | ||
enum old_level = intr_disable(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reference for why interrupt should be disable? I think syscall_handler
invokes in interrupt already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In 31 pg of pintos manual, it says Your system call implementation must treat the file system code as a critical section.
I regarded it as 'Syscall handler must be in mutally excluded state, by using locks, semaphores, monitors, etc... or, disabling interrupt.' Am I totally wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Read carefully.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can get intr level and check whether exec is by intr or not in handler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Lment Check this plz.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hangpark Now I think interrupt should not be turned off. Instead it should be handled with locks and semaphores. And also, intr_disable()
cannot turn off synchronous internal interrupts, as memtioned in pintos manual. 70pg
.
src/userprog/syscall.c
Outdated
thread_exit (); | ||
enum old_level = intr_disable(); | ||
int syscall_num = *((int *) f->esp); | ||
void **args = (void **) malloc (3 * WORD_SIZE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason for allocating memory to store arguments? It is already put on the stack. Why don't you just use that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then, there would be *(esp + 1), *(esp +2), *(esp + 3)
, instead of *args[0], *args[1], *args[2]
. I thought argv-statement more intuitive to viewers, If you strongly recommends, I would get rid of these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kernel programming should use recource minimally.
static void | ||
syscall_handler (struct intr_frame *f UNUSED) | ||
{ | ||
printf ("system call!\n"); | ||
thread_exit (); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think thread_exit()
should be called if none of system call matched. So I request you to move this to default
clause of theswitch
statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to be commented on deleted region. Default case now has thread_exit()
in it,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please follow the coding convention.
src/userprog/syscall.c
Outdated
switch (syscall_num) | ||
{ | ||
case SYS_HALT: | ||
syscall_halt(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spacing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modifed
src/userprog/syscall.c
Outdated
syscall_halt(); | ||
break; | ||
case SYS_EXIT: | ||
syscall_exit((int) *args[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spacing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modified.
src/userprog/syscall.c
Outdated
syscall_close ((int) *args[0]); | ||
break; | ||
} | ||
intr_set_level(old_level); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spacing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modified.
src/userprog/syscall.c
Outdated
static void | ||
syscall_handler (struct intr_frame *f UNUSED) | ||
{ | ||
printf ("system call!\n"); | ||
thread_exit (); | ||
enum old_level = intr_disable(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spacing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modified.
18a87f3
to
29623fd
Compare
src/userprog/syscall.c
Outdated
syscall_close ((int) *args[0]); | ||
break; | ||
default: | ||
printf ("system call!\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line seems to be not neccessary.
src/userprog/syscall.c
Outdated
#include "threads/init.h" | ||
#include "threads/malloc.h" | ||
|
||
#define WORD_SIZE sizeof (uintptr_t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this in use?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My fault.
src/userprog/syscall.c
Outdated
#include "threads/malloc.h" | ||
|
||
#define WORD_SIZE sizeof (uintptr_t) | ||
#define pid_t int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you define pid_t
customly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to here, this states that pid_t should be in header files <unistd.h> and <sys/types.h>, but compiler says that it can't find both of them. So, I followed "The pid_t data type is a signed integer type which is capable of representing a process ID. In the GNU C Library, this is an int", and customly defined it, to avoid compiler errors shouting that it could not find type pid_t.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your link is for GNU C. Our pintos's library is in src/lib/
. See here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implement the following system calls. The prototypes listed are those seen by a user program that includes ‘lib/user/syscall.h’. (This header, and all others in ‘lib/user’, are for use by user programs only.) - pintos manual 28pg.
Linked file is inside dir 'user', which I thought I should not include. I looked for other files that include pid_t definition, but nothing else came up, so I decided I should customly define it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
src/userprog/syscall.c
Outdated
|
||
/* array saving arguments that could or could not be | ||
placed on esp + 4, esp + 8, esp + 12. */ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My fault.
src/userprog/syscall.c
Outdated
#include "threads/interrupt.h" | ||
#include "threads/thread.h" | ||
#include "threads/init.h" | ||
#include "threads/malloc.h" | ||
#include <unistd.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why are these new includes necessary for your implementation? On my env, building without these 5 includes is in success.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My fault.
8d63a06
to
c9c9158
Compare
src/userprog/syscall.c
Outdated
void | ||
syscall_init (void) | ||
{ | ||
intr_register_int (0x30, 3, INTR_ON, syscall_handler, "syscall"); | ||
lock_init(&sys_lock); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this lock is used for file system interactions. I mean, not necessary in general. It would be inserted when it becomes needed in a specific system call. So I recommend you to delete it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Order of execution becomes important such as read(), write()
. Yes, they do not interfere with each other directly, but they could read/write to same memory space, and then order of execution would be significant to results. So I think we should use lock.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, according to one of OS TA, she said she applied lock to handlers while taking this course. Testing this synchronization problem might not be in test cases, but it would be better solution, i suppose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also used lock
last year, and that is for filesystem
. Pintos must let at most one thread use the file system at the specific time. Some of system calls should be able to use the file system, and also should process_execute()
. But, for other system calls, is this lock
still needed? I don't think so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I'm so sorry. You just initialized lock, not acquired. Then, if you explain the usage for this lock, then I will follow you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It means, you should give a specific explanation above the line 10.
+) I suggest you to switch the order of execution for lock_init()
and intr_register_int()
to each other.
+) If you want to use sys_lock
, consider whether it should be static
or not. If it is not need to be static, then it should moved to the header file to make other source files can use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hangpark Re-pushed, lock defined in header file as you suggested.
458dd51
to
d1c431e
Compare
src/userprog/syscall.c
Outdated
break; | ||
default: | ||
thread_exit (); | ||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need this.
src/userprog/syscall.c
Outdated
which acquired a lock is calling a file system code. This lock must be | ||
released immediately when a thread is no longer running a code which | ||
must be executed in mutually exclueded state. */ | ||
static struct lock sys_lock; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You said that you move this to the header file in the comment above, but it is still in c
file.
src/userprog/syscall.c
Outdated
/* Structure lock defined in synch.h, which would ensure only one thread | ||
which acquired a lock is calling a file system code. This lock must be | ||
released immediately when a thread is no longer running a code which | ||
must be executed in mutually exclueded state. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you explain lock
is defined in synch.h
and its functionality? Nobody cares it. Please summary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is your detail commit message?
Basic system call infrastructure, which dispatches appropriate handler to specific system call. Detailed handlers that handle system calls are not yet implemented.
👍 |
Basic syscall handler, and skeleton code to start writing each system call.
System call which has return value must put its result to
eax
, which is accessible byf->eax
.Skeleton with return has return value when fully implemented.