From a7a589df15f4ba3d6642aa8ae031a9b3ed0f5a1f Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Wed, 31 Jul 2024 01:59:54 +0300 Subject: libcamera: base: Add MemFd helper class libcamera creates memfds in two locations already, duplicating some code. Move the code to a new MemFd helper class. Signed-off-by: Laurent Pinchart Reviewed-by: Milan Zamazal Reviewed-by: Kieran Bingham Tested-by: Milan Zamazal Tested-by: Hans de Goede Reviewed-by: Hans de Goede --- include/libcamera/base/memfd.h | 34 ++++++++++++++++++++++++++++++++++ include/libcamera/base/meson.build | 1 + 2 files changed, 35 insertions(+) create mode 100644 include/libcamera/base/memfd.h (limited to 'include') diff --git a/include/libcamera/base/memfd.h b/include/libcamera/base/memfd.h new file mode 100644 index 00000000..b0edd2de --- /dev/null +++ b/include/libcamera/base/memfd.h @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2024, Ideas on Board Oy + * + * Anonymous file creation + */ + +#pragma once + +#include + +#include +#include + +namespace libcamera { + +class MemFd +{ +public: + enum class Seal { + None = 0, + Shrink = (1 << 0), + Grow = (1 << 1), + }; + + using Seals = Flags; + + static UniqueFD create(const char *name, std::size_t size, + Seals seals = Seal::None); +}; + +LIBCAMERA_FLAGS_ENABLE_OPERATORS(MemFd::Seal) + +} /* namespace libcamera */ diff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build index bace25d5..2a0cee31 100644 --- a/include/libcamera/base/meson.build +++ b/include/libcamera/base/meson.build @@ -21,6 +21,7 @@ libcamera_base_private_headers = files([ 'event_notifier.h', 'file.h', 'log.h', + 'memfd.h', 'message.h', 'mutex.h', 'private.h', -- cgit v1.2.1