From 5167d1577d6b4074f46ad90864d6e0d6119089a3 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 25 Feb 2019 10:13:52 -0500 Subject: kernel/handle_table: Allow process capabilities to limit the handle table size The kernel allows restricting the total size of the handle table through the process capability descriptors. Until now, this functionality wasn't hooked up. With this, the process handle tables become properly restricted. In the case of metadata-less executables, the handle table will assume the maximum size is requested, preserving the behavior that existed before these changes. --- src/core/hle/kernel/handle_table.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/core/hle/kernel/handle_table.h') diff --git a/src/core/hle/kernel/handle_table.h b/src/core/hle/kernel/handle_table.h index 5fa55c783..44901391b 100644 --- a/src/core/hle/kernel/handle_table.h +++ b/src/core/hle/kernel/handle_table.h @@ -49,6 +49,20 @@ public: HandleTable(); ~HandleTable(); + /** + * Sets the number of handles that may be in use at one time + * for this handle table. + * + * @param handle_table_size The desired size to limit the handle table to. + * + * @returns an error code indicating if initialization was successful. + * If initialization was not successful, then ERR_OUT_OF_MEMORY + * will be returned. + * + * @pre handle_table_size must be within the range [0, 1024] + */ + ResultCode SetSize(s32 handle_table_size); + /** * Allocates a handle for the given object. * @return The created Handle or one of the following errors: @@ -103,6 +117,13 @@ private: */ std::array generations; + /** + * The limited size of the handle table. This can be specified by process + * capabilities in order to restrict the overall number of handles that + * can be created in a process instance + */ + u16 table_size = static_cast(MAX_COUNT); + /** * Global counter of the number of created handles. Stored in `generations` when a handle is * created, and wraps around to 1 when it hits 0x8000. -- cgit v1.2.3