Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Pintos_Student_Group
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
y2-rhymansaib
Pintos_Student_Group
Commits
8913470e
Commit
8913470e
authored
3 years ago
by
y2-rhymansaib
Browse files
Options
Downloads
Patches
Plain Diff
split strtok_r and saved the first argument as the pro_name
established the setup_stack to include the argv and argc
parent
de55c026
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/userprog/process.c
+38
-10
38 additions, 10 deletions
src/userprog/process.c
with
38 additions
and
10 deletions
src/userprog/process.c
+
38
−
10
View file @
8913470e
...
...
@@ -36,13 +36,17 @@ process_execute (const char *file_name)
fn_copy
=
palloc_get_page
(
0
);
if
(
fn_copy
==
NULL
)
return
TID_ERROR
;
char
*
save_ptr
,
*
pro_name
;
/*extracting file name from cmd*/
strlcpy
(
fn_copy
,
file_name
,
PGSIZE
);
pro_name
=
strtok_r
(
file_name
,
" "
,
&
save_ptr
);
/*cuts the file_name and saves the first argument as real name */
/* Create a new thread to execute FILE_NAME. */
tid
=
thread_create
(
file
_name
,
PRI_DEFAULT
,
start_process
,
fn_copy
);
tid
=
thread_create
(
pro
_name
,
PRI_DEFAULT
,
start_process
,
fn_copy
);
if
(
tid
==
TID_ERROR
)
if
(
tid
==
TID_ERROR
)
{
palloc_free_page
(
fn_copy
);
}
return
tid
;
}
...
...
@@ -119,6 +123,7 @@ process_exit (void)
pagedir_activate
(
NULL
);
pagedir_destroy
(
pd
);
}
printf
(
"%s: exit(%d)
\n
"
,
cur
->
name
,
cur
->
exit_code
);
/*prints out program name and exit code*/
}
/* Sets up the CPU for running user code in the current
...
...
@@ -197,10 +202,12 @@ struct Elf32_Phdr
/* Flags for p_flags. See [ELF3] 2-3 and 2-4. */
#define PF_X 1
/* Executable. */
#define PF_W 2
/* Writable. */
/
bin
/
bash
:
:
q
:
command
not
found
#define PF_R 4
/* Readable. */
static
bool
setup_stack
(
void
**
esp
);
static
bool
setup_stack
(
void
**
esp
,
char
**
argv
,
int
argc
);
/* argv(listing all arguments)
argc(no. of arguments passed including program name*/
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
,
...
...
@@ -219,6 +226,24 @@ load (const char *file_name, void (**eip) (void), void **esp)
off_t
file_ofs
;
bool
success
=
false
;
int
i
;
struct
kernel_thread_frame
*
kf
char
file_name_echo
[
100
];
strlcpy
(
file_name_echo
,
file_name
,
100
);
char
*
pro_name
=
file_name
;
char
*
argv
[
255
];
int
argc
;
char
*
save_ptr
;
argv
[
0
]
=
strtok_r
(
file_name
,
" "
,
&
save_ptr
);
if
(
DEBUG
)
printf
(
"1st strtok_r
\n
);
char *token;
argc = 1;
while((token = strtok_r(NULL, "
", &save_ptr))!=NULL){
argv[argc++] = token;
}
/* Allocate and activate page directory. */
t->pagedir = pagedir_create ();
...
...
@@ -231,7 +256,6 @@ load (const char *file_name, void (**eip) (void), void **esp)
if (file == NULL)
{
printf
(
"load: %s: open failed
\n
"
,
file_name
);
goto done;
}
...
...
@@ -308,7 +332,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. */
...
...
@@ -433,7 +457,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;
...
...
@@ -444,6 +468,10 @@ setup_stack (void **esp)
success = install_page (((uint8_t *) PHYS_BASE) - PGSIZE, kpage, true);
if (success) {
*esp = PHYS_BASE;
int i = argc;
uint32_t *arr[argc];
} 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