Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Pintos
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Project Purple Stallion
Pintos
Commits
1ff119e8
Commit
1ff119e8
authored
5 years ago
by
a2-stratford
Browse files
Options
Downloads
Patches
Plain Diff
Alex - Added Argument Passing
parent
061e88ba
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
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
userprog/process.c
+45
-4
45 additions, 4 deletions
userprog/process.c
with
46 additions
and
4 deletions
.gitignore
+
1
−
0
View file @
1ff119e8
...
...
@@ -2,3 +2,4 @@ cscope.files
cscope.out
TAGS
tags
/.vs
This diff is collapsed.
Click to expand it.
userprog/process.c
+
45
−
4
View file @
1ff119e8
...
...
@@ -28,6 +28,9 @@ static bool load (const char *cmdline, void (**eip) (void), void **esp);
tid_t
process_execute
(
const
char
*
file_name
)
{
char
*
save_ptr
,
*
real_name
;
real_name
=
strtok_r
(
file_name
,
" "
,
&
save_ptr
);
puts
(
real_name
)
char
*
fn_copy
;
tid_t
tid
;
...
...
@@ -207,7 +210,7 @@ struct Elf32_Phdr
#define PF_W 2
/* Writable. */
#define PF_R 4
/* Readable. */
static
bool
setup_stack
(
void
**
esp
);
static
bool
setup_stack
(
void
**
esp
,
char
**
argv
,
int
argc
);
static
bool
validate_segment
(
const
struct
Elf32_Phdr
*
,
struct
file
*
);
static
bool
load_segment
(
struct
file
*
file
,
off_t
ofs
,
uint8_t
*
upage
,
uint32_t
read_bytes
,
uint32_t
zero_bytes
,
...
...
@@ -227,6 +230,21 @@ load (const char *file_name, void (**eip) (void), void **esp)
bool
success
=
false
;
int
i
;
/* extract arguments */
// create a copy of file_name and operate on it (modifying it)
char
file_name_copy
[
100
];
strlcpy
(
file_name_copy
,
file_name
,
100
);
char
*
argv
[
255
];
int
argc
;
char
*
save_ptr
;
argv
[
0
]
=
strtok_r
(
file_name_copy
,
" "
,
&
save_ptr
);
char
*
token
;
argc
=
1
;
while
((
token
=
strtok_r
(
NULL
,
" "
,
&
save_ptr
))
!=
NULL
)
{
argv
[
argc
++
]
=
token
;
}
/* Allocate and activate page directory. */
t
->
pagedir
=
pagedir_create
();
if
(
t
->
pagedir
==
NULL
)
...
...
@@ -315,7 +333,7 @@ load (const char *file_name, void (**eip) (void), void **esp)
}
/* Set up stack. */
if
(
!
setup_stack
(
esp
))
if
(
!
setup_stack
(
esp
,
argv
,
argc
))
goto
done
;
/* Start address. */
...
...
@@ -440,7 +458,7 @@ load_segment (struct file *file, off_t ofs, uint8_t *upage,
/* Create a minimal stack by mapping a zeroed page at the top of
user virtual memory. */
static
bool
setup_stack
(
void
**
esp
)
setup_stack
(
void
**
esp
,
char
**
argv
,
int
argc
)
{
uint8_t
*
kpage
;
bool
success
=
false
;
...
...
@@ -450,7 +468,30 @@ setup_stack (void **esp)
{
success
=
install_page
(((
uint8_t
*
)
PHYS_BASE
)
-
PGSIZE
,
kpage
,
true
);
if
(
success
)
{
*
esp
=
PHYS_BASE
-
12
;
*
esp
=
PHYS_BASE
;
int
i
=
argc
;
// this array holds reference to differences arguments in the stack
uint32_t
*
arr
[
argc
];
while
(
--
i
>=
0
)
{
*
esp
=
*
esp
-
(
strlen
(
argv
[
i
])
+
1
)
*
sizeof
(
char
);
arr
[
i
]
=
(
uint32_t
*
)
*
esp
;
memcpy
(
*
esp
,
argv
[
i
],
strlen
(
argv
[
i
])
+
1
);
}
*
esp
=
*
esp
-
4
;
(
*
(
int
*
)(
*
esp
))
=
0
;
//sentinel
i
=
argc
;
while
(
--
i
>=
0
)
{
*
esp
=
*
esp
-
4
;
//32bit
(
*
(
uint32_t
**
)(
*
esp
))
=
arr
[
i
];
}
*
esp
=
*
esp
-
4
;
(
*
(
uintptr_t
**
)(
*
esp
))
=
(
*
esp
+
4
);
*
esp
=
*
esp
-
4
;
*
(
int
*
)(
*
esp
)
=
argc
;
*
esp
=
*
esp
-
4
;
(
*
(
int
*
)(
*
esp
))
=
0
;
}
else
palloc_free_page
(
kpage
);
}
...
...
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