Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xv6-riscv-tp
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
Container registry
Model registry
Operate
Environments
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
cidre-public
Systemes d exploitation
xv6-riscv-tp
Commits
0bbae1fc
Commit
0bbae1fc
authored
5 years ago
by
Tronel Frederic
Browse files
Options
Downloads
Patches
Plain Diff
Simplification du code assembleur de la payload, et ajout d'un cas d'exécution sur le tas.
parent
0707d4d8
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
user/stack-exec.c
+71
-70
71 additions, 70 deletions
user/stack-exec.c
with
71 additions
and
70 deletions
user/stack-exec.c
+
71
−
70
View file @
0bbae1fc
...
@@ -14,16 +14,9 @@
...
@@ -14,16 +14,9 @@
# syscall write -> a7 = 16
# syscall write -> a7 = 16
li a7, 16
li a7, 16
# looking for the address of the string to print, after ret (0x82, 0x80)
# looking for the address of the string to print,
j .mystring
auipc a1, 0
.back:
.loop:
lbu t0, 0(a1)
addi a1, a1, 1
li t1, 0x80
beq t0, t1, .endloop
j .loop
.endloop:
# computing the length of the string, look for 0 byte
# computing the length of the string, look for 0 byte
mv a2, a1
mv a2, a1
...
@@ -35,93 +28,101 @@
...
@@ -35,93 +28,101 @@
.endloop2:
.endloop2:
sub a2, a2, a1
sub a2, a2, a1
# Syscall !
ecall
ecall
ret
ret
.mystring:
.mystring:
auipc a1, 4
jal a1, .back
ret
.data
"Hello"
.asciz "Hello"
.mystringend:
auipc a2, -4
ret
*/
*/
char
code
[]
=
{
char
code
[]
=
{
// li a0, 1
// li a0, 1
0x05
,
0x45
,
0x05
,
0x45
,
// li a7, 16
// li a7, 16
0xc1
,
0x48
,
0xc1
,
0x48
,
// auipc a1, 0
// j .mystring
0x97
,
0x05
,
0x00
,
0x00
,
0x21
,
0xa8
,
// .loop:
// mv a2, a1
// lbu t0, 0(a1)
0x2e
,
0x86
,
0x83
,
0xc2
,
0x05
,
0x00
,
// .loop2:
// addi a1, a1, 1
// lbu t0, 0(a2)
0x85
,
0x05
,
0x83
,
0x42
,
0x06
,
0x00
,
//li t1, 0x80
// addi a2, a2, 1
0x13
,
0x03
,
0x00
,
0x08
,
0x05
,
0x06
,
// beq t0 t1, .endloop
// beqz t0, .endloop2
0x63
,
0x83
,
0x62
,
0x00
,
0x63
,
0x83
,
0x02
,
0x00
,
// j .loop
// j .loop2
0xcd
,
0xbf
,
0xdd
,
0xbf
,
// .endloop:
// .endloop2
// mv a2, a1
// sub a2, a2, a1
0x2e
,
0x86
,
0x0d
,
0x8e
,
// .loop2:
// ecall
// lbu t0, 0(a2)
0x73
,
0x00
,
0x00
,
0x00
,
0x83
,
0x42
,
0x06
,
0x00
,
// ret
// addi a2, a2, 1
0x82
,
0x80
,
0x05
,
0x06
,
// jal a1,6 <.back>
// beqz t0, .endloop2
0xef
,
0xf5
,
0xbf
,
0xfe
,
0x63
,
0x83
,
0x02
,
0x00
,
'H'
,
'e'
,
'l'
,
'l'
,
'o'
,
'!'
,
0x0a
,
0
};
// j .loop2
0xdd
,
0xbf
,
void
do_fork
(
void
(
*
fn
)(
void
))
// .endloop2
{
// sub a2, a2, a1
0x0d
,
0x8e
,
// ecall
0x73
,
0x00
,
0x00
,
0x00
,
// ret
0x82
,
0x80
,
'H'
,
'e'
,
'l'
,
'l'
,
'o'
,
'!'
,
0x0a
,
0
};
void
do_fork
(
void
(
*
fn
)(
void
)){
int
pid
=
fork
();
int
pid
=
fork
();
if
(
pid
<
0
){
if
(
pid
<
0
)
printf
(
"fork failed
\n
"
);
exit
(
1
);
{
}
else
if
(
pid
==
0
){
printf
(
"fork failed
\n
"
);
exit
(
1
);
}
else
if
(
pid
==
0
)
{
fn
();
fn
();
}
else
{
}
else
{
wait
(
0
);
wait
(
0
);
}
}
}
}
void
test_code1
(){
void
test_code1
()
((
void
(
*
)(
void
))(
code
))();
{
((
void
(
*
)(
void
))(
code
))();
printf
(
"code1: cette ligne devrait-elle s'afficher ?
\n
"
);
printf
(
"code1: cette ligne devrait-elle s'afficher ?
\n
"
);
exit
(
0
);
exit
(
0
);
}
}
void
test_code2
(){
void
test_code2
()
{
char
code2
[
100
];
char
code2
[
100
];
for
(
int
i
=
0
;
i
<
sizeof
(
code
);
i
++
){
for
(
int
i
=
0
;
i
<
sizeof
(
code
);
i
++
)
{
code2
[
i
]
=
code
[
i
];
code2
[
i
]
=
code
[
i
];
}
}
((
void
(
*
)(
void
))(
code2
))();
((
void
(
*
)(
void
))(
code2
))();
printf
(
"code2: cette ligne devrait-elle s'afficher ?
\n
"
);
printf
(
"code2: cette ligne devrait-elle s'afficher ?
\n
"
);
exit
(
0
);
exit
(
0
);
}
}
int
void
test_code3
()
main
(
int
argc
,
char
*
argv
[])
{
char
*
code3
;
code3
=
sbrk
(
sizeof
(
code
));
for
(
int
i
=
0
;
i
<
sizeof
(
code
);
i
++
)
{
code3
[
i
]
=
code
[
i
];
}
((
void
(
*
)(
void
))(
code3
))();
printf
(
"code3: cette ligne devrait-elle s'afficher ?
\n
"
);
exit
(
0
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
{
do_fork
(
test_code1
);
do_fork
(
test_code1
);
do_fork
(
test_code2
);
do_fork
(
test_code2
);
do_fork
(
test_code3
);
exit
(
0
);
exit
(
0
);
}
}
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