Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ACS
Public
HermitCore
libhermit-rs
Commits
1d59a9a4
Commit
1d59a9a4
authored
Sep 13, 2021
by
Martin Kröning
🦀
Browse files
Implement sys_free_tx_buffer
parent
8966c60a
Changes
5
Show whitespace changes
Inline
Side-by-side
src/drivers/net/mod.rs
View file @
1d59a9a4
...
...
@@ -26,8 +26,12 @@ pub trait NetworkInterface {
/// Returns the current MTU of the device.
fn
get_mtu
(
&
self
)
->
u16
;
/// Get buffer to create a TX packet
///
/// This returns ownership of the TX buffer.
fn
get_tx_buffer
(
&
mut
self
,
len
:
usize
)
->
Result
<
(
*
mut
u8
,
usize
),
()
>
;
/// Send TC packets
/// Frees the TX buffer (takes ownership)
fn
free_tx_buffer
(
&
self
,
token
:
usize
);
/// Send TC packets (takes TX buffer ownership)
fn
send_tx_buffer
(
&
mut
self
,
tkn_handle
:
usize
,
len
:
usize
)
->
Result
<
(),
()
>
;
/// Check if a packet is available
fn
has_packet
(
&
self
)
->
bool
;
...
...
src/drivers/net/rtl8139.rs
View file @
1d59a9a4
...
...
@@ -241,6 +241,10 @@ impl NetworkInterface for RTL8139Driver {
}
}
fn
free_tx_buffer
(
&
self
,
_token
:
usize
)
{
// get_tx_buffer did not allocate
}
fn
send_tx_buffer
(
&
mut
self
,
id
:
usize
,
len
:
usize
)
->
Result
<
(),
()
>
{
// send the packet
unsafe
{
...
...
src/drivers/net/virtio_net.rs
View file @
1d59a9a4
...
...
@@ -543,6 +543,10 @@ impl NetworkInterface for VirtioNetDriver {
}
}
fn
free_tx_buffer
(
&
self
,
token
:
usize
)
{
unsafe
{
drop
(
Box
::
from_raw
(
token
as
*
mut
BufferToken
))
}
}
fn
send_tx_buffer
(
&
mut
self
,
tkn_handle
:
usize
,
_len
:
usize
)
->
Result
<
(),
()
>
{
// This does not result in a new assignment, or in a drop of the BufferToken, which
// would be dangerous, as the memory is freed then.
...
...
src/syscalls/interfaces/mod.rs
View file @
1d59a9a4
...
...
@@ -154,6 +154,19 @@ pub trait SyscallInterface: Send + Sync {
Err
(())
}
fn
free_tx_buffer
(
&
self
,
handle
:
usize
)
->
Result
<
(),
()
>
{
#[cfg(all(feature
=
"pci"
,
not(target_arch
=
"aarch64"
)))]
match
arch
::
kernel
::
pci
::
get_network_driver
()
{
Some
(
driver
)
=>
{
driver
.lock
()
.free_tx_buffer
(
handle
);
Ok
(())
}
_
=>
Err
(()),
}
#[cfg(not(all(feature
=
"pci"
,
not(target_arch
=
"aarch64"
))))]
Err
(())
}
fn
send_tx_buffer
(
&
self
,
handle
:
usize
,
len
:
usize
)
->
Result
<
(),
()
>
{
#[cfg(all(feature
=
"pci"
,
not(target_arch
=
"aarch64"
)))]
match
arch
::
kernel
::
pci
::
get_network_driver
()
{
...
...
src/syscalls/mod.rs
View file @
1d59a9a4
...
...
@@ -114,6 +114,16 @@ extern "C" fn __sys_get_tx_buffer(len: usize, ret: &mut Result<(*mut u8, usize),
*
ret
=
unsafe
{
SYS
.get_tx_buffer
(
len
)
};
}
#[allow(improper_ctypes_definitions)]
extern
"C"
fn
__sys_free_tx_buffer
(
handle
:
usize
)
->
Result
<
(),
()
>
{
unsafe
{
SYS
.free_tx_buffer
(
handle
)
}
}
#[no_mangle]
pub
fn
sys_free_tx_buffer
(
handle
:
usize
)
->
Result
<
(),
()
>
{
kernel_function!
(
__sys_free_tx_buffer
(
handle
))
}
#[no_mangle]
pub
fn
sys_get_tx_buffer
(
len
:
usize
)
->
Result
<
(
*
mut
u8
,
usize
),
()
>
{
let
mut
ret
=
Err
(());
...
...
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