Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Pintos_Student
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
s2-fidan
Pintos_Student
Commits
3706ef78
Commit
3706ef78
authored
2 years ago
by
s2-fidan
Browse files
Options
Downloads
Patches
Plain Diff
SYSTEM CALL IMPLEMENT
parent
b35e7104
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/userprog/syscall.c
+156
-5
156 additions, 5 deletions
src/userprog/syscall.c
src/userprog/syscall.h
+7
-0
7 additions, 0 deletions
src/userprog/syscall.h
with
163 additions
and
5 deletions
src/userprog/syscall.c
+
156
−
5
View file @
3706ef78
...
...
@@ -3,19 +3,170 @@
#include
<syscall-nr.h>
#include
"threads/interrupt.h"
#include
"threads/thread.h"
#include
"devices/shutdown.h"
static
void
syscall_handler
(
struct
intr_frame
*
);
void
syscall_halt
(
void
);
void
syscall_exit
(
int
status
);
int
syscall_wait
(
pid_t
pid
);
bool
syscall_create
(
const
char
*
file_name
,
unsigned
initial_size
);
bool
syscall_remove
(
const
char
*
file_name
,
unsigned
initial_size
);
/*System call initializer*/
void
syscall_init
(
void
)
{
//LOOK AT LOCK_INIT
lock_init
(
&
filesys_lock
);
intr_register_int
(
0x30
,
3
,
INTR_ON
,
syscall_handler
,
"syscall"
);
}
/*Handler for system commands.*/
static
void
syscall_handler
(
struct
intr_frame
*
f
UNUSED
)
syscall_handler
(
struct
intr_frame
*
f
)
{
//LOOK AGAIN UNTIL SWITCH-CASE
if
(
!
FILE_LOCK_INIT
)
{
lock_init
(
&
file_system_lock
);
FILE_LOCK_INIT
=
true
;
}
int
syscall_number
;
ASSERT
(
sizeof
(
syscall_number
)
==
4
);
// 4byte x86
read
(
f
->
esp
,
&
syscall_number
,
sizeof
(
syscall_number
));
thread_current
()
->
current_esp
=
f
->
esp
;
switch
(
syscall_number
)
{
case
SYSCALL_HALT
:
// 0
{
/*Terminate PintOS*/
syscall_halt
();
break
;
}
case
SYSCALL_EXIT
:
// 1
{
int
arg
;
/*Get argument*/
read
(
f
->
esp
+
4
,
&
arg
,
sizeof
(
arg
));
/*Terminate program*/
syscall_exit
(
arg
);
break
;
}
case
SYSCALL_WAIT
:
// 2
{
printf
(
"system call!
\n
"
);
pid_t
pid
;
/*Get argument*/
read
(
f
->
esp
+
4
,
&
pid
,
sizeof
(
pid_t
));
/*Wait for child process*/
f
->
eax
=
syscall_wait
(
pid
);
break
;
}
case
SYSCALL_CREATE
:
// 3
{
const
char
*
file_name
;
unsigned
initial_size
;
/*Get file name and size*/
read
(
f
->
esp
+
4
,
&
file_name
,
sizeof
(
file_name
));
read
(
f
->
esp
+
8
,
&
initial_size
,
sizeof
(
initial_size
));
/*Create file*/
f
->
eax
=
syscall_create
(
file_name
,
initial_size
);
break
;
}
case
SYSCALL_REMOVE
:
// 4
{
const
char
*
file_name
;
bool
return_code
;
/*Get file name*/
read
(
f
->
esp
+
4
,
&
file_name
,
sizeof
(
file_name
));
/*Remove file*/
f
->
eax
=
syscall_remove
(
file_name
);
break
;
}
/* Unimplemented system calls */
default:
printf
(
"ERROR: system call ( %d ) has not implemented!
\n
"
,
syscall_number
);
/* Terminate. */
sys_exit
(
-
1
);
break
;
}
}
/********SYSTEMCALLS********/
/* Halt */
void
syscall_halt
(
void
)
{
shutdown_power_off
();
/* From shutdown.h */
}
/* Exit */
void
syscall_exit
(
int
status
)
{
printf
(
"%s: exit(%d)
\n
"
,
thread_current
()
->
name
,
status
);
//LOOK AT PCB
struct
process_control_block
*
pcb
=
thread_current
()
->
pcb
;
if
(
pcb
!=
NULL
)
{
pcb
->
exitcode
=
status
;
}
thread_exit
();
}
/* Wait */
int
syscall_wait
(
pid_t
pid
)
{
return
process_wait
(
pid
);
}
/* Create File */
bool
syscall_create
(
const
char
*
file_name
,
unsigned
initial_size
)
{
bool
if_created
=
false
;
//LOOK AT ACQUIRE AND RELEASE
lock_acquire
(
&
filesys_lock
);
if
(
filesys_create
(
file_name
,
initial_size
)
==
true
){
if_created
=
true
;
}
lock_release
(
&
filesys_lock
);
return
if_created
;
}
/* Remove File */
bool
syscall_remove
(
const
char
*
file_name
,
unsigned
initial_size
)
{
bool
if_removed
=
false
;
//LOOK AT ACQUIRE AND RELEASE
lock_acquire
(
&
filesys_lock
);
if
(
filesys_remove
(
file_name
,
initial_size
)
==
true
){
if_removed
=
true
;
}
lock_release
(
&
filesys_lock
);
return
if_removed
;
}
/****OTHER FUNCTIONS****/
static
int
read
(
void
*
src
,
void
*
dst
,
size_t
bytes
)
{
int32_t
value
;
size_t
i
;
for
(
i
=
0
;
i
<
bytes
;
i
++
)
{
value
=
get_user
(
src
+
i
);
if
(
value
==
-
1
)
// segfault or invalid memory access
fail_invalid_access
();
*
(
char
*
)(
dst
+
i
)
=
value
&
0xff
;
}
return
(
int
)
bytes
;
}
This diff is collapsed.
Click to expand it.
src/userprog/syscall.h
+
7
−
0
View file @
3706ef78
...
...
@@ -3,4 +3,11 @@
void
syscall_init
(
void
);
/*PROTOTYPES*/
void
syscall_halt
(
void
);
void
syscall_exit
(
int
status
);
int
syscall_wait
(
pid_t
pid
);
bool
syscall_create
(
const
char
*
file_name
,
unsigned
initial_size
);
bool
syscall_remove
(
const
char
*
file_name
,
unsigned
initial_size
);
#endif
/* userprog/syscall.h */
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment