Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
relibc
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
redox-os
relibc
Commits
920bafb1
Verified
Commit
920bafb1
authored
1 year ago
by
Jacob Lorentzon
Browse files
Options
Downloads
Patches
Plain Diff
Impl libredox getpid, kill, sigprocmask, sigaction.
parent
a1530dd1
No related branches found
No related tags found
1 merge request
!419
Implement (not yet the entire) libredox ABI
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/platform/redox/libredox.rs
+25
-3
25 additions, 3 deletions
src/platform/redox/libredox.rs
src/platform/redox/signal.rs
+46
-39
46 additions, 39 deletions
src/platform/redox/signal.rs
with
71 additions
and
42 deletions
src/platform/redox/libredox.rs
+
25
−
3
View file @
920bafb1
...
@@ -3,6 +3,8 @@ use core::{slice, str};
...
@@ -3,6 +3,8 @@ use core::{slice, str};
use
libc
::{
c_int
,
mode_t
};
use
libc
::{
c_int
,
mode_t
};
use
syscall
::{
Error
,
Result
,
EMFILE
,
WaitFlags
};
use
syscall
::{
Error
,
Result
,
EMFILE
,
WaitFlags
};
use
crate
::
header
::
signal
::
sigaction
;
pub
type
RawResult
=
usize
;
pub
type
RawResult
=
usize
;
pub
fn
open
(
path
:
&
str
,
oflag
:
c_int
,
mode
:
mode_t
)
->
Result
<
usize
>
{
pub
fn
open
(
path
:
&
str
,
oflag
:
c_int
,
mode
:
mode_t
)
->
Result
<
usize
>
{
...
@@ -18,8 +20,8 @@ pub fn open(path: &str, oflag: c_int, mode: mode_t) -> Result<usize> {
...
@@ -18,8 +20,8 @@ pub fn open(path: &str, oflag: c_int, mode: mode_t) -> Result<usize> {
}
}
#[no_mangle]
#[no_mangle]
pub
unsafe
extern
"C"
fn
redox_open_v1
(
path_base
:
*
const
u8
,
path_len
:
usize
,
flags
:
i
32
,
mode
:
u16
)
->
RawResult
{
pub
unsafe
extern
"C"
fn
redox_open_v1
(
path_base
:
*
const
u8
,
path_len
:
usize
,
flags
:
u
32
,
mode
:
u16
)
->
RawResult
{
Error
::
mux
(
open
(
str
::
from_utf8_unchecked
(
slice
::
from_raw_parts
(
path_base
,
path_len
)),
flags
,
mode
as
mode_t
))
Error
::
mux
(
open
(
str
::
from_utf8_unchecked
(
slice
::
from_raw_parts
(
path_base
,
path_len
)),
flags
as
c_int
,
mode
as
mode_t
))
}
}
#[no_mangle]
#[no_mangle]
...
@@ -64,6 +66,11 @@ pub unsafe extern "C" fn redox_close_v1(fd: usize) -> RawResult {
...
@@ -64,6 +66,11 @@ pub unsafe extern "C" fn redox_close_v1(fd: usize) -> RawResult {
Error
::
mux
(
syscall
::
close
(
fd
))
Error
::
mux
(
syscall
::
close
(
fd
))
}
}
#[no_mangle]
pub
unsafe
extern
"C"
fn
redox_get_pid_v1
()
->
RawResult
{
Error
::
mux
(
syscall
::
getpid
())
}
#[no_mangle]
#[no_mangle]
pub
unsafe
extern
"C"
fn
redox_get_euid_v1
()
->
RawResult
{
pub
unsafe
extern
"C"
fn
redox_get_euid_v1
()
->
RawResult
{
Error
::
mux
(
syscall
::
geteuid
())
Error
::
mux
(
syscall
::
geteuid
())
...
@@ -85,9 +92,24 @@ pub unsafe extern "C" fn redox_setrens_v1(rns: usize, ens: usize) -> RawResult {
...
@@ -85,9 +92,24 @@ pub unsafe extern "C" fn redox_setrens_v1(rns: usize, ens: usize) -> RawResult {
Error
::
mux
(
syscall
::
setrens
(
rns
,
ens
))
Error
::
mux
(
syscall
::
setrens
(
rns
,
ens
))
}
}
#[no_mangle]
#[no_mangle]
pub
unsafe
extern
"C"
fn
redox_waitpid_v1
(
pid
:
usize
,
status
:
*
mut
i32
,
options
:
i
32
)
->
RawResult
{
pub
unsafe
extern
"C"
fn
redox_waitpid_v1
(
pid
:
usize
,
status
:
*
mut
i32
,
options
:
u
32
)
->
RawResult
{
let
mut
sts
=
0_usize
;
let
mut
sts
=
0_usize
;
let
res
=
Error
::
mux
(
syscall
::
waitpid
(
pid
,
&
mut
sts
,
WaitFlags
::
from_bits_truncate
(
options
as
usize
)));
let
res
=
Error
::
mux
(
syscall
::
waitpid
(
pid
,
&
mut
sts
,
WaitFlags
::
from_bits_truncate
(
options
as
usize
)));
status
.write
(
sts
as
i32
);
status
.write
(
sts
as
i32
);
res
res
}
}
#[no_mangle]
pub
unsafe
extern
"C"
fn
redox_kill_v1
(
pid
:
usize
,
signal
:
u32
)
->
RawResult
{
Error
::
mux
(
syscall
::
kill
(
pid
,
signal
as
usize
))
}
#[no_mangle]
pub
unsafe
extern
"C"
fn
redox_sigaction_v1
(
signal
:
u32
,
new
:
*
const
sigaction
,
old
:
*
mut
sigaction
)
->
RawResult
{
Error
::
mux
(
super
::
signal
::
sigaction_impl
(
signal
as
i32
,
new
.as_ref
(),
old
.as_mut
())
.map
(|()|
0
))
}
#[no_mangle]
pub
unsafe
extern
"C"
fn
redox_sigprocmask_v1
(
how
:
u32
,
new
:
*
const
u64
,
old
:
*
mut
u64
)
->
RawResult
{
Error
::
mux
(
super
::
signal
::
sigprocmask_impl
(
how
as
i32
,
new
,
old
)
.map
(|()|
0
))
}
This diff is collapsed.
Click to expand it.
src/platform/redox/signal.rs
+
46
−
39
View file @
920bafb1
use
core
::
mem
;
use
core
::
mem
;
use
syscall
;
use
syscall
::{
self
,
Result
}
;
use
super
::{
use
super
::{
super
::{
types
::
*
,
Pal
,
PalSignal
},
super
::{
types
::
*
,
Pal
,
PalSignal
},
...
@@ -107,29 +107,7 @@ impl PalSignal for Sys {
...
@@ -107,29 +107,7 @@ impl PalSignal for Sys {
}
}
fn
sigaction
(
sig
:
c_int
,
act
:
Option
<&
sigaction
>
,
oact
:
Option
<&
mut
sigaction
>
)
->
c_int
{
fn
sigaction
(
sig
:
c_int
,
act
:
Option
<&
sigaction
>
,
oact
:
Option
<&
mut
sigaction
>
)
->
c_int
{
let
new_opt
=
act
.map
(|
act
|
{
e
(
sigaction_impl
(
sig
,
act
,
oact
)
.map
(|()|
0
))
as
c_int
let
m
=
act
.sa_mask
;
let
sa_handler
=
unsafe
{
mem
::
transmute
(
act
.sa_handler
)
};
syscall
::
SigAction
{
sa_handler
,
sa_mask
:
[
m
as
u64
,
0
],
sa_flags
:
syscall
::
SigActionFlags
::
from_bits
(
act
.sa_flags
as
usize
)
.expect
(
"sigaction: invalid bit pattern"
),
}
});
let
mut
old_opt
=
oact
.as_ref
()
.map
(|
_
|
syscall
::
SigAction
::
default
());
let
ret
=
e
(
syscall
::
sigaction
(
sig
as
usize
,
new_opt
.as_ref
(),
old_opt
.as_mut
(),
))
as
c_int
;
if
let
(
Some
(
old
),
Some
(
oact
))
=
(
old_opt
,
oact
)
{
oact
.sa_handler
=
unsafe
{
mem
::
transmute
(
old
.sa_handler
)
};
let
m
=
old
.sa_mask
;
oact
.sa_mask
=
m
[
0
]
as
sigset_t
;
oact
.sa_flags
=
old
.sa_flags
.bits
()
as
c_ulong
;
}
ret
}
}
fn
sigaltstack
(
ss
:
*
const
stack_t
,
old_ss
:
*
mut
stack_t
)
->
c_int
{
fn
sigaltstack
(
ss
:
*
const
stack_t
,
old_ss
:
*
mut
stack_t
)
->
c_int
{
...
@@ -144,21 +122,7 @@ impl PalSignal for Sys {
...
@@ -144,21 +122,7 @@ impl PalSignal for Sys {
}
}
fn
sigprocmask
(
how
:
c_int
,
set
:
*
const
sigset_t
,
oset
:
*
mut
sigset_t
)
->
c_int
{
fn
sigprocmask
(
how
:
c_int
,
set
:
*
const
sigset_t
,
oset
:
*
mut
sigset_t
)
->
c_int
{
let
new_opt
=
if
set
.is_null
()
{
e
(
sigprocmask_impl
(
how
,
set
,
oset
)
.map
(|()|
0
))
as
c_int
None
}
else
{
Some
([
unsafe
{
*
set
as
u64
},
0
])
};
let
mut
old_opt
=
if
oset
.is_null
()
{
None
}
else
{
Some
([
0
,
0
])
};
let
ret
=
e
(
syscall
::
sigprocmask
(
how
as
usize
,
new_opt
.as_ref
(),
old_opt
.as_mut
(),
))
as
c_int
;
if
let
Some
(
old
)
=
old_opt
{
unsafe
{
*
oset
=
old
[
0
]
as
sigset_t
};
}
ret
}
}
fn
sigsuspend
(
set
:
*
const
sigset_t
)
->
c_int
{
fn
sigsuspend
(
set
:
*
const
sigset_t
)
->
c_int
{
...
@@ -175,3 +139,46 @@ impl PalSignal for Sys {
...
@@ -175,3 +139,46 @@ impl PalSignal for Sys {
-
1
-
1
}
}
}
}
pub
(
crate
)
fn
sigaction_impl
(
sig
:
i32
,
act
:
Option
<&
sigaction
>
,
oact
:
Option
<&
mut
sigaction
>
)
->
Result
<
()
>
{
let
new_opt
=
act
.map
(|
act
|
{
let
m
=
act
.sa_mask
;
let
sa_handler
=
unsafe
{
mem
::
transmute
(
act
.sa_handler
)
};
syscall
::
SigAction
{
sa_handler
,
sa_mask
:
[
m
as
u64
,
0
],
sa_flags
:
syscall
::
SigActionFlags
::
from_bits
(
act
.sa_flags
as
usize
)
.expect
(
"sigaction: invalid bit pattern"
),
}
});
let
mut
old_opt
=
oact
.as_ref
()
.map
(|
_
|
syscall
::
SigAction
::
default
());
syscall
::
sigaction
(
sig
as
usize
,
new_opt
.as_ref
(),
old_opt
.as_mut
(),
)
?
;
if
let
(
Some
(
old
),
Some
(
oact
))
=
(
old_opt
,
oact
)
{
oact
.sa_handler
=
unsafe
{
mem
::
transmute
(
old
.sa_handler
)
};
let
m
=
old
.sa_mask
;
oact
.sa_mask
=
m
[
0
]
as
sigset_t
;
oact
.sa_flags
=
old
.sa_flags
.bits
()
as
c_ulong
;
}
Ok
(())
}
pub
(
crate
)
fn
sigprocmask_impl
(
how
:
i32
,
set
:
*
const
sigset_t
,
oset
:
*
mut
sigset_t
)
->
Result
<
()
>
{
let
new_opt
=
if
set
.is_null
()
{
None
}
else
{
Some
([
unsafe
{
*
set
as
u64
},
0
])
};
let
mut
old_opt
=
if
oset
.is_null
()
{
None
}
else
{
Some
([
0
,
0
])
};
syscall
::
sigprocmask
(
how
as
usize
,
new_opt
.as_ref
(),
old_opt
.as_mut
(),
)
?
;
if
let
Some
(
old
)
=
old_opt
{
unsafe
{
*
oset
=
old
[
0
]
as
sigset_t
};
}
Ok
(())
}
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