# HG changeset patch # User Paul Boddie # Date 1647986624 -3600 # Node ID 3b8dd301c9c4eb3c7e7e3a5ac42a654be025895e # Parent 5c3d7f228d1f716a0d1f27da4e349c2998820b9b Raise an exception when failing to allocate memory for a pipe, catching the exception and returning the appropriate error code for the pipe-opening operation. diff -r 5c3d7f228d1f -r 3b8dd301c9c4 libfsserver/lib/pipes/pipe_opener_resource.cc --- a/libfsserver/lib/pipes/pipe_opener_resource.cc Mon Mar 21 00:17:42 2022 +0100 +++ b/libfsserver/lib/pipes/pipe_opener_resource.cc Tue Mar 22 23:03:44 2022 +0100 @@ -1,7 +1,7 @@ /* * A pipe opener resource. * - * Copyright (C) 2021 Paul Boddie + * Copyright (C) 2021, 2022 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -21,6 +21,8 @@ #include +#include + #include "pipe_opener_resource.h" #include "pipe_opener_server.h" #include "pipe_pager.h" @@ -53,7 +55,16 @@ { /* Both endpoints will employ a common paging coordinator. */ - PipePaging *paging = new PipePaging(_memory, size); + PipePaging *paging; + + try + { + paging = new PipePaging(_memory, size); + } + catch (L4::Out_of_memory const &e) + { + return -L4_ENOMEM; + } /* Each endpoint will have its own pager. */ diff -r 5c3d7f228d1f -r 3b8dd301c9c4 libmem/lib/src/memory_preallocated.cc --- a/libmem/lib/src/memory_preallocated.cc Mon Mar 21 00:17:42 2022 +0100 +++ b/libmem/lib/src/memory_preallocated.cc Tue Mar 22 23:03:44 2022 +0100 @@ -21,6 +21,8 @@ #include "memory_preallocated.h" +#include + /* Initialise the memory pool with the given amount in bytes. */ @@ -28,16 +30,16 @@ MemoryPreallocated::MemoryPreallocated(Memory *memory, offset_t amount) : _memory(memory), _amount(amount) { - // NOTE: Handle allocation failure. - offset_t remaining = amount; while (remaining) { - _regions.push_back(memory->region()); + Region *region = memory->region(); - if (memory->region_size() >= remaining) - break; + if (region == NULL) + throw L4::Out_of_memory(); + + _regions.push_back(region); remaining -= memory->region_size(); }