Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust/kernel: remove config #ifdef in mutex.rs file #357

Merged
merged 1 commit into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions rust/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <linux/highmem.h>
#include <linux/uio.h>
#include <linux/errname.h>
#include <linux/mutex.h>

void rust_helper_BUG(void)
{
Expand Down Expand Up @@ -123,6 +124,12 @@ const char *rust_helper_errname(int err)
return errname(err);
}

void rust_helper_mutex_lock(struct mutex *lock)
{
mutex_lock(lock);
}
EXPORT_SYMBOL_GPL(rust_helper_mutex_lock);

/* We use bindgen's --size_t-is-usize option to bind the C size_t type
* as the Rust usize type, so we can use it in contexts where Rust
* expects a usize like slice (array) indices. usize is defined to be
Expand Down
15 changes: 7 additions & 8 deletions rust/kernel/sync/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,18 @@ impl<T: ?Sized> NeedsLockClass for Mutex<T> {
}
}

extern "C" {
fn rust_helper_mutex_lock(mutex: *mut bindings::mutex);
}

impl<T: ?Sized> Lock for Mutex<T> {
type Inner = T;

#[cfg(not(CONFIG_DEBUG_LOCK_ALLOC))]
fn lock_noguard(&self) {
// SAFETY: `mutex` points to valid memory.
unsafe { bindings::mutex_lock(self.mutex.get()) };
}

#[cfg(CONFIG_DEBUG_LOCK_ALLOC)]
fn lock_noguard(&self) {
// SAFETY: `mutex` points to valid memory.
unsafe { bindings::mutex_lock_nested(self.mutex.get(), 0) };
unsafe {
rust_helper_mutex_lock(self.mutex.get());
}
}

unsafe fn unlock(&self) {
Expand Down