Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
Labs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TDDE47 Pintos
Labs
Commits
1be77d96
Commit
1be77d96
authored
2 years ago
by
Isak Hall
Browse files
Options
Downloads
Patches
Plain Diff
lab3 finally running benim happy
parent
7c2c7b92
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/threads/thread.h
+3
-7
3 additions, 7 deletions
src/threads/thread.h
src/userprog/process.c
+32
-46
32 additions, 46 deletions
src/userprog/process.c
src/userprog/syscall.c
+5
-5
5 additions, 5 deletions
src/userprog/syscall.c
with
40 additions
and
58 deletions
src/threads/thread.h
+
3
−
7
View file @
1be77d96
...
@@ -116,17 +116,13 @@ struct child_parent{
...
@@ -116,17 +116,13 @@ struct child_parent{
int
exit_status
;
int
exit_status
;
int
yani_count
;
int
yani_count
;
struct
list_elem
list_elem
;
struct
list_elem
list_elem
;
struct
thread
*
child
;
struct
thread
*
child
;
struct
thread
*
parent
;
struct
thread
*
parent
;
bool
loaded
;
tid_t
child_tid
;
tid_t
child_tid
;
struct
lock
lock
;
struct
lock
exit_lock
;
char
*
exec_file_name
;
char
*
exec_file_name
;
//struct semaphore yäni_sema;
struct
semaphore
s
;
struct
semaphore
exit_s
;
};
};
...
...
This diff is collapsed.
Click to expand it.
src/userprog/process.c
+
32
−
46
View file @
1be77d96
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
#include
"threads/init.h"
#include
"threads/init.h"
#include
"threads/interrupt.h"
#include
"threads/interrupt.h"
#include
"threads/palloc.h"
#include
"threads/palloc.h"
#include
"threads/malloc.h"
#include
"threads/thread.h"
#include
"threads/thread.h"
#include
"threads/vaddr.h"
#include
"threads/vaddr.h"
#include
<stdlib.h>
#include
<stdlib.h>
...
@@ -51,37 +52,30 @@ tid_t process_execute(const char *file_name){
...
@@ -51,37 +52,30 @@ tid_t process_execute(const char *file_name){
return
TID_ERROR
;
return
TID_ERROR
;
strlcpy
(
fn_copy
,
file_name
,
PGSIZE
);
strlcpy
(
fn_copy
,
file_name
,
PGSIZE
);
//Vi vill initiera vårat reletionship med barnet
struct
child_parent
*
relation
=
(
struct
child_parent
*
)
malloc
(
sizeof
(
struct
child_parent
));
//declare child parent relationship
struct
child_parent
*
relation
=
malloc
(
sizeof
(
struct
child_parent
));
lock_init
(
&
relation
->
lock
);
sema_init
(
&
relation
->
s
,
0
);
//semaphore that locks before list insertion.
lock_init
(
&
relation
->
exit_lock
);
sema_init
(
&
relation
->
exit_s
,
0
);
//semaphore used in process_exit.
relation
->
exec_file_name
=
fn_copy
;
relation
->
exec_file_name
=
fn_copy
;
//file name thats used in execution.
relation
->
exit_status
=-
1
;
relation
->
exit_status
=-
1
;
//used for indication of when we should exit
relation
->
yani_count
=
2
;
relation
->
yani_count
=
2
;
//alive count with scuffed name, used to check if the relation is still alive.
thread_current
()
->
child_parent
=
relation
;
relation
->
parent
=
thread_current
();
//set parent to current thread.
//lägga till reltionen till våran lista
relation
->
parent
=
thread_current
();
/* Create a new thread to execute FILE_NAME. */
/* Create a new thread to execute FILE_NAME. */
tid
=
thread_create
(
file_name
,
PRI_DEFAULT
,
start_process
,
relation
);
tid
=
thread_create
(
file_name
,
PRI_DEFAULT
,
start_process
,
relation
);
// Använda oss av semaphorer för att se till så att threadsen inte låser sig
lock_acquire
(
&
relation
->
lock
);
if
(
tid
==
TID_ERROR
){
if
(
tid
==
TID_ERROR
){
free
(
relation
);
free
(
relation
);
palloc_free_page
(
fn_copy
);
palloc_free_page
(
fn_copy
);
return
tid
;
return
tid
;
}
}
sema_down
(
&
relation
->
s
);
//sema down before critical section.
/* if(!relation -> loaded){
tid = TID_ERROR;
}*/
list_push_back
(
&
thread_current
()
->
barn_list
,
relation
);
list_push_back
(
&
thread_current
()
->
barn_list
,
&
relation
->
list_elem
);
//insert relation.
return
tid
;
return
tid
;
}
}
...
@@ -92,11 +86,13 @@ static void
...
@@ -92,11 +86,13 @@ static void
start_process
(
void
*
x
)
start_process
(
void
*
x
)
{
{
struct
child_parent
*
relation
=
(
struct
parent_child
*
)
x
;
struct
child_parent
*
relation
=
(
struct
parent_child
*
)
x
;
//initiate relation in start process
relation
->
child
=
thread_current
();
struct
thread
*
child
=
thread_current
();
//current thread set to child.
char
*
file_name
=
relation
->
exec_file_name
;
relation
->
child
=
child
;
//set the child in relation
char
*
file_name
=
relation
->
exec_file_name
;
struct
intr_frame
if_
;
struct
intr_frame
if_
;
bool
success
;
bool
success
;
child
->
child_parent
=
relation
;
/* Initialize interrupt frame and load executable. */
/* Initialize interrupt frame and load executable. */
...
@@ -104,7 +100,7 @@ start_process (void *x)
...
@@ -104,7 +100,7 @@ start_process (void *x)
if_
.
gs
=
if_
.
fs
=
if_
.
es
=
if_
.
ds
=
if_
.
ss
=
SEL_UDSEG
;
if_
.
gs
=
if_
.
fs
=
if_
.
es
=
if_
.
ds
=
if_
.
ss
=
SEL_UDSEG
;
if_
.
cs
=
SEL_UCSEG
;
if_
.
cs
=
SEL_UCSEG
;
if_
.
eflags
=
FLAG_IF
|
FLAG_MBS
;
if_
.
eflags
=
FLAG_IF
|
FLAG_MBS
;
success
=
load
(
file_name
,
&
if_
.
eip
,
&
if_
.
esp
);
success
=
load
(
file_name
,
&
if_
.
eip
,
&
if_
.
esp
);
//load file_name.
...
@@ -116,10 +112,11 @@ start_process (void *x)
...
@@ -116,10 +112,11 @@ start_process (void *x)
if
(
!
success
)
{
if
(
!
success
)
{
//current_thread->child_parent->exit_status = -1;
//current_thread->child_parent->exit_status = -1;
sema_up
(
&
relation
->
s
);
thread_exit
();
thread_exit
();
}
}
lock_release
(
&
relation
->
lock
);
sema_up
(
&
relation
->
s
);
//critical section is done, sema_up to continue.
asm
volatile
(
"movl %0, %%esp; jmp intr_exit"
:
:
"g"
(
&
if_
)
:
"memory"
);
asm
volatile
(
"movl %0, %%esp; jmp intr_exit"
:
:
"g"
(
&
if_
)
:
"memory"
);
NOT_REACHED
();
NOT_REACHED
();
...
@@ -147,35 +144,24 @@ process_exit (void)
...
@@ -147,35 +144,24 @@ process_exit (void)
{
{
struct
thread
*
cur
=
thread_current
();
struct
thread
*
cur
=
thread_current
();
struct
child_parent
*
relation
=
cur
->
child_parent
;
struct
child_parent
*
relation
=
cur
->
child_parent
;
struct
list
*
list
=
&
cur
->
barn_list
;
struct
list
*
list
=
&
cur
->
barn_list
;
//children list
relation
->
yani_count
--
;
//when we are in exit it is time do remove relation
/*if (relation != NULL)
{
sema_down(&relation->yani_sema);
//check if parent bond is dead
//relation->yani_count--;
if (relation->yani_count == 0)
{
free(relation);
}
else{
sema_up(&relation->yani_sema);
}
}*/
while
(
!
list_empty
(
list
)){
while
(
!
list_empty
(
list
)){
struct
list_elem
*
e
=
list_pop_front
(
list
);
struct
list_elem
*
e
=
list_pop_front
(
list
);
//remove first element from list
relation
=
list_entry
(
e
,
struct
child_parent
,
list_elem
);
relation
=
list_entry
(
e
,
struct
child_parent
,
list_elem
);
//set relation.
lock_acquire
(
&
relation
->
exit_
lock
);
sema_down
(
&
relation
->
exit_
s
);
//enter critical section where we change variables inside of the relation
relation
->
yani_count
--
;
relation
->
yani_count
--
;
relation
->
exit_status
=
cur
->
status
;
if
(
relation
->
yani_count
==
0
){
if
(
relation
->
yani_count
==
0
){
free
(
relation
);
free
(
relation
);
//free the relation that we malloced earlier.
}
}
else
{
else
{
lock_release
(
&
relation
->
exit_
lock
);
sema_up
(
&
relation
->
exit_
s
);
//critical section done.
}
}
relation
->
exit_status
=
cur
->
status
;
}
if
(
relation
->
yani_count
==
0
){
free
(
relation
);
}
}
uint32_t
*
pd
;
uint32_t
*
pd
;
...
...
This diff is collapsed.
Click to expand it.
src/userprog/syscall.c
+
5
−
5
View file @
1be77d96
...
@@ -84,7 +84,7 @@ syscall_handler (struct intr_frame *f UNUSED)
...
@@ -84,7 +84,7 @@ syscall_handler (struct intr_frame *f UNUSED)
}
}
case
(
SYS_EXEC
):{
case
(
SYS_EXEC
):{
const
char
*
cmd_line
=
*
(
(
char
**
)(
f
->
esp
+
4
)
)
;
const
char
*
cmd_line
=
*
(
char
**
)(
f
->
esp
+
4
);
f
->
eax
=
exec
(
cmd_line
);
f
->
eax
=
exec
(
cmd_line
);
break
;
break
;
}
}
...
@@ -97,7 +97,7 @@ void halt (void){
...
@@ -97,7 +97,7 @@ void halt (void){
void
exit
(
int
status
){
void
exit
(
int
status
){
/* Exit status */
/* Exit status */
//
thread_current()->child_parent->exit_status = status;
thread_current
()
->
child_parent
->
exit_status
=
status
;
/* For make check */
/* For make check */
//printf("%s: exit(%d)\n", thread_current()->name, status);
//printf("%s: exit(%d)\n", thread_current()->name, status);
...
@@ -211,11 +211,11 @@ tid_t exec(const char *cmd_line){
...
@@ -211,11 +211,11 @@ tid_t exec(const char *cmd_line){
}
}
bool
validate
(
int
fd
){
bool
validate
(
int
fd
){
if
(
fd
>=
2
&&
fd
<=
130
)
if
(
fd
<
0
||
fd
>=
130
)
{
{
return
tru
e
;
return
fals
e
;
}
}
else
{
else
{
return
fals
e
;
return
tru
e
;
}
}
}
}
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