Skip to content
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

Merged
merged 1 commit into from
Apr 9, 2017
Merged

Conversation

Lment
Copy link
Contributor

@Lment Lment commented Apr 7, 2017

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 by f->eax.
Skeleton with return has return value when fully implemented.

@Lment Lment requested a review from hangpark April 7, 2017 16:46
@Lment Lment added the feature label Apr 7, 2017
@Lment Lment added this to the Project #2 milestone Apr 7, 2017
Copy link
Owner

@hangpark hangpark left a 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. 💢

#include "threads/init.h"
#include "threads/malloc.h"

#define WORD_SIZE sizeof(uintptr_t)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parenthesis, Spacing


static void syscall_handler (struct intr_frame *);


Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blank line

void
syscall_init (void)
{
intr_register_int (0x30, 3, INTR_ON, syscall_handler, "syscall");
}


Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blank line

for (i = 1; i <= 3; i++)
args[i] = f->esp + WORD_SIZE * i;


Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blank line


switch (syscall_num)
{
case SYS_HALT:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation

power_off();
}

static void syscall_exit (void ** args)
Copy link
Owner

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)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also on prototypes.

static int syscall_write (void ** args);
static void syscall_seek (void ** args);
static unsigned syscall_tell (void ** args);
static void syscall_close (void ** args);
Copy link
Owner

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.

static int syscall_write (void ** args);
static void syscall_seek (void ** args);
static unsigned syscall_tell (void ** args);
static void syscall_close (void ** args);
Copy link
Owner

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.

syscall_exit(args);
break;
case SYS_EXEC:
f->eax = syscall_exec (void ** args);
Copy link
Owner

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 ** ?


static void syscall_halt (void)
{
power_off();
Copy link
Owner

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.

@hangpark
Copy link
Owner

hangpark commented Apr 7, 2017

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 write() system call, your infrastructure should give me an environment that I can start with int fd, const void *buffer, and unsigned size, NOT with void **args.

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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment is missing.

@hangpark
Copy link
Owner

hangpark commented Apr 7, 2017

Let me review later for other things about your logic, algorithm, and implementation AFTER you fix above requests.

static void
syscall_handler (struct intr_frame *f UNUSED)
{
printf ("system call!\n");
thread_exit ();
enum old_level = intr_disable();
Copy link
Owner

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.

Copy link
Contributor Author

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?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read carefully.

Copy link
Owner

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.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Lment Check this plz.

Copy link
Contributor Author

@Lment Lment Apr 8, 2017

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.

thread_exit ();
enum old_level = intr_disable();
int syscall_num = *((int *) f->esp);
void **args = (void **) malloc (3 * WORD_SIZE);
Copy link
Owner

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?

Copy link
Contributor Author

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.

Copy link
Owner

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 ();
Copy link
Owner

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modified.

Copy link
Contributor Author

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,

Copy link
Owner

@hangpark hangpark left a 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.

switch (syscall_num)
{
case SYS_HALT:
syscall_halt();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spacing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modifed

syscall_halt();
break;
case SYS_EXIT:
syscall_exit((int) *args[0]);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spacing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modified.

syscall_close ((int) *args[0]);
break;
}
intr_set_level(old_level);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spacing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modified.

static void
syscall_handler (struct intr_frame *f UNUSED)
{
printf ("system call!\n");
thread_exit ();
enum old_level = intr_disable();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spacing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modified.

@Lment Lment force-pushed the iss/6 branch 2 times, most recently from 18a87f3 to 29623fd Compare April 7, 2017 19:48
syscall_close ((int) *args[0]);
break;
default:
printf ("system call!\n");
Copy link
Owner

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.

#include "threads/init.h"
#include "threads/malloc.h"

#define WORD_SIZE sizeof (uintptr_t)
Copy link
Owner

@hangpark hangpark Apr 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this in use?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My fault.

#include "threads/malloc.h"

#define WORD_SIZE sizeof (uintptr_t)
#define pid_t int
Copy link
Owner

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?

Copy link
Contributor Author

@Lment Lment Apr 8, 2017

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.

Copy link
Owner

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.

Copy link
Contributor Author

@Lment Lment Apr 8, 2017

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.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


/* array saving arguments that could or could not be
placed on esp + 4, esp + 8, esp + 12. */

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My fault.

#include "threads/interrupt.h"
#include "threads/thread.h"
#include "threads/init.h"
#include "threads/malloc.h"
#include <unistd.h>
Copy link
Owner

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My fault.

@Lment Lment force-pushed the iss/6 branch 2 times, most recently from 8d63a06 to c9c9158 Compare April 8, 2017 09:48
void
syscall_init (void)
{
intr_register_int (0x30, 3, INTR_ON, syscall_handler, "syscall");
lock_init(&sys_lock);
Copy link
Owner

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Owner

@hangpark hangpark Apr 8, 2017

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.

Copy link
Owner

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.

Copy link
Owner

@hangpark hangpark Apr 8, 2017

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.

Copy link
Contributor Author

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.

@Lment Lment force-pushed the iss/6 branch 4 times, most recently from 458dd51 to d1c431e Compare April 9, 2017 04:23
break;
default:
thread_exit ();
break;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need this.

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;
Copy link
Owner

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.

/* 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. */
Copy link
Owner

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.

Copy link
Owner

@hangpark hangpark left a 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.
@hangpark
Copy link
Owner

hangpark commented Apr 9, 2017

👍

@hangpark hangpark merged commit 3f74056 into develop Apr 9, 2017
@hangpark hangpark deleted the iss/6 branch April 9, 2017 10:13
@hangpark hangpark mentioned this pull request Apr 14, 2017
@hangpark hangpark mentioned this pull request May 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants