ANDROID: ashmem_rust: define Rust ashmem driver

For now, we just register a miscdevice with no operations defined on it.

Bug: 370906207
Change-Id: I9ea307095ffd66859239ec4926523222466d3602
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
This commit is contained in:
Alice Ryhl
2024-09-13 12:51:30 +00:00
committed by Treehugger Robot
parent 3bc1a0a8e5
commit 306f5648d8
4 changed files with 78 additions and 1 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ obj-$(CONFIG_VME_BUS) += vme_user/
obj-$(CONFIG_IIO) += iio/
obj-$(CONFIG_FB_SM750) += sm750fb/
obj-$(CONFIG_MFD_NVEC) += nvec/
obj-$(CONFIG_ASHMEM) += android/
obj-$(CONFIG_ANDROID_STAGING) += android/
obj-$(CONFIG_LTE_GDM724X) += gdm724x/
obj-$(CONFIG_FB_TFT) += fbtft/
obj-$(CONFIG_MOST) += most/
+16
View File
@@ -1,9 +1,25 @@
# SPDX-License-Identifier: GPL-2.0
menu "Android"
config ANDROID_STAGING
bool
config ASHMEM
bool "Enable the Anonymous Shared Memory Subsystem"
depends on SHMEM
select ANDROID_STAGING
help
The ashmem subsystem is a new shared memory allocator, similar to
POSIX SHM but with different behavior and sporting a simpler
file-based API.
It is, in theory, a good memory allocator for low-memory devices,
because it can discard shared memory units when under memory pressure.
config ASHMEM_RUST
bool "Enable the Anonymous Shared Memory Subsystem in Rust"
depends on SHMEM && RUST && !ASHMEM
select ANDROID_STAGING
help
The ashmem subsystem is a new shared memory allocator, similar to
POSIX SHM but with different behavior and sporting a simpler
+1
View File
@@ -2,3 +2,4 @@
ccflags-y += -I$(src) # needed for trace events
obj-$(CONFIG_ASHMEM) += ashmem.o
obj-$(CONFIG_ASHMEM_RUST) += ashmem_rust.o
+60
View File
@@ -0,0 +1,60 @@
// SPDX-License-Identifier: GPL-2.0
// Copyright (C) 2024 Google LLC.
//! Anonymous Shared Memory Subsystem for Android.
//!
//! The ashmem subsystem is a new shared memory allocator, similar to POSIX SHM but with different
//! behavior and sporting a simpler file-based API.
//!
//! It is, in theory, a good memory allocator for low-memory devices, because it can discard shared
//! memory units when under memory pressure.
use core::pin::Pin;
use kernel::{
c_str,
error::Result,
fs::File,
miscdevice::{MiscDevice, MiscDeviceOptions, MiscDeviceRegistration},
prelude::*,
};
module! {
type: AshmemModule,
name: "ashmem_rust",
author: "Alice Ryhl",
description: "Anonymous Shared Memory Subsystem",
license: "GPL",
}
struct AshmemModule {
_misc: Pin<Box<MiscDeviceRegistration<Ashmem>>>,
}
impl kernel::Module for AshmemModule {
fn init(_module: &'static kernel::ThisModule) -> Result<Self> {
pr_info!("Using Rust implementation.");
Ok(Self {
_misc: Box::pin_init(
MiscDeviceRegistration::register(MiscDeviceOptions {
name: c_str!("ashmem"),
}),
GFP_KERNEL,
)?,
})
}
}
/// Represents an open ashmem file.
#[pin_data]
struct Ashmem {}
#[vtable]
impl MiscDevice for Ashmem {
type Ptr = Pin<Box<Self>>;
fn open(_: &File, _: &MiscDeviceRegistration<Ashmem>) -> Result<Pin<Box<Self>>> {
Box::try_pin_init(Ashmem {}, GFP_KERNEL)
}
}