Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
K
kernel
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
23
Issues
23
List
Boards
Labels
Service Desk
Milestones
Merge Requests
10
Merge Requests
10
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
redox-os
kernel
Commits
8fcbf152
Verified
Commit
8fcbf152
authored
Dec 31, 2018
by
Jeremy Soller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add mprotect
parent
b18e322c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
7 deletions
+55
-7
Cargo.lock
Cargo.lock
+5
-5
src/syscall/mod.rs
src/syscall/mod.rs
+1
-0
src/syscall/process.rs
src/syscall/process.rs
+48
-1
syscall
syscall
+1
-1
No files found.
Cargo.lock
View file @
8fcbf152
...
...
@@ -65,7 +65,7 @@ dependencies = [
"semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.83 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.83 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.3
3
(registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.3
4
(registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
...
...
@@ -178,7 +178,7 @@ dependencies = [
"goblin 0.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
"linked_list_allocator 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"raw-cpuid 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.
49
",
"redox_syscall 0.1.
50
",
"slab_allocator 0.3.1",
"spin 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
"x86 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
...
...
@@ -279,7 +279,7 @@ dependencies = [
[[package]]
name = "redox_syscall"
version = "0.1.
49
"
version = "0.1.
50
"
[[package]]
name = "regex"
...
...
@@ -358,7 +358,7 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.3
3
"
version = "1.0.3
4
"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
...
...
@@ -526,7 +526,7 @@ dependencies = [
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
"checksum serde 1.0.83 (registry+https://github.com/rust-lang/crates.io-index)" = "157e12af46859e968da75dea9845530e13d03bcab2009a41b9b7bb3cf4eb3ec2"
"checksum serde_derive 1.0.83 (registry+https://github.com/rust-lang/crates.io-index)" = "9469829702497daf2daf3c190e130c3fa72f719920f73c86160d43e8f8d76951"
"checksum serde_json 1.0.3
3 (registry+https://github.com/rust-lang/crates.io-index)" = "c37ccd6be3ed1fdf419ee848f7c758eb31b054d7cd3ae3600e3bae0adf569811
"
"checksum serde_json 1.0.3
4 (registry+https://github.com/rust-lang/crates.io-index)" = "bdf540260cfee6da923831f4776ddc495ada940c30117977c70f1313a6130545
"
"checksum spin 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ceac490aa12c567115b40b7b7fceca03a6c9d53d5defea066123debc83c5dc1f"
"checksum syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)" = "9545a6a093a3f0bd59adb472700acc08cad3776f860f16a897dfce8c88721cbc"
"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
...
...
src/syscall/mod.rs
View file @
8fcbf152
...
...
@@ -106,6 +106,7 @@ pub fn syscall(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize, bp: u
SYS_GETGID
=>
getgid
(),
SYS_GETNS
=>
getns
(),
SYS_GETUID
=>
getuid
(),
SYS_MPROTECT
=>
mprotect
(
b
,
c
,
d
),
SYS_MKNS
=>
mkns
(
validate_slice
(
b
as
*
const
[
usize
;
2
],
c
)
?
),
SYS_SETPGID
=>
setpgid
(
ContextId
::
from
(
b
),
ContextId
::
from
(
c
)),
SYS_SETREUID
=>
setreuid
(
b
as
u32
,
c
as
u32
),
...
...
src/syscall/process.rs
View file @
8fcbf152
...
...
@@ -9,6 +9,7 @@ use spin::Mutex;
use
memory
::
allocate_frames
;
use
paging
::{
ActivePageTable
,
InactivePageTable
,
Page
,
VirtualAddress
};
use
paging
::
entry
::
EntryFlags
;
use
paging
::
mapper
::
MapperFlushAll
;
use
paging
::
temporary_page
::
TemporaryPage
;
use
start
::
usermode
;
use
interrupt
;
...
...
@@ -22,7 +23,9 @@ use scheme::FileHandle;
use
syscall
;
use
syscall
::
data
::{
SigAction
,
Stat
};
use
syscall
::
error
::
*
;
use
syscall
::
flag
::{
CLONE_VFORK
,
CLONE_VM
,
CLONE_FS
,
CLONE_FILES
,
CLONE_SIGHAND
,
SIG_DFL
,
SIGCONT
,
SIGTERM
,
WCONTINUED
,
WNOHANG
,
WUNTRACED
,
wifcontinued
,
wifstopped
};
use
syscall
::
flag
::{
CLONE_VFORK
,
CLONE_VM
,
CLONE_FS
,
CLONE_FILES
,
CLONE_SIGHAND
,
PROT_EXEC
,
PROT_READ
,
PROT_WRITE
,
SIG_DFL
,
SIGCONT
,
SIGTERM
,
WCONTINUED
,
WNOHANG
,
WUNTRACED
,
wifcontinued
,
wifstopped
};
use
syscall
::
validate
::{
validate_slice
,
validate_slice_mut
};
pub
fn
brk
(
address
:
usize
)
->
Result
<
usize
>
{
...
...
@@ -1127,6 +1130,50 @@ pub fn kill(pid: ContextId, sig: usize) -> Result<usize> {
}
}
pub
fn
mprotect
(
address
:
usize
,
size
:
usize
,
flags
:
usize
)
->
Result
<
usize
>
{
println!
(
"mprotect {:#X}, {}, {:#X}"
,
address
,
size
,
flags
);
let
end_offset
=
size
.checked_sub
(
1
)
.ok_or
(
Error
::
new
(
EFAULT
))
?
;
let
end_address
=
address
.checked_add
(
end_offset
)
.ok_or
(
Error
::
new
(
EFAULT
))
?
;
let
mut
active_table
=
unsafe
{
ActivePageTable
::
new
()
};
let
mut
flush_all
=
MapperFlushAll
::
new
();
let
start_page
=
Page
::
containing_address
(
VirtualAddress
::
new
(
address
));
let
end_page
=
Page
::
containing_address
(
VirtualAddress
::
new
(
end_address
));
for
page
in
Page
::
range_inclusive
(
start_page
,
end_page
)
{
if
let
Some
(
mut
page_flags
)
=
active_table
.translate_page_flags
(
page
)
{
if
flags
&
PROT_EXEC
>
0
{
page_flags
.remove
(
EntryFlags
::
NO_EXECUTE
);
}
else
{
page_flags
.insert
(
EntryFlags
::
NO_EXECUTE
);
}
if
flags
&
PROT_WRITE
>
0
{
//TODO: Not allowing gain of write privileges
}
else
{
page_flags
.remove
(
EntryFlags
::
WRITABLE
);
}
if
flags
&
PROT_READ
>
0
{
//TODO: No flags for readable pages
}
else
{
//TODO: No flags for readable pages
}
let
flush
=
active_table
.remap
(
page
,
page_flags
);
flush_all
.consume
(
flush
);
}
else
{
return
Err
(
Error
::
new
(
EFAULT
));
}
}
flush_all
.flush
(
&
mut
active_table
);
Ok
(
0
)
}
pub
fn
setpgid
(
pid
:
ContextId
,
pgid
:
ContextId
)
->
Result
<
usize
>
{
let
contexts
=
context
::
contexts
();
...
...
syscall
@
9a3734c4
Compare
6909fb1c
...
9a3734c4
Subproject commit
6909fb1c32d2c4dd75c0967ab06b894c8f7ed308
Subproject commit
9a3734c41ac452bc3f8fe6d9a6b687c96cc3ca15
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment