1.1 --- a/libfsserver/lib/pipes/pipe_opener_resource.cc Mon Mar 21 00:17:42 2022 +0100
1.2 +++ b/libfsserver/lib/pipes/pipe_opener_resource.cc Tue Mar 22 23:03:44 2022 +0100
1.3 @@ -1,7 +1,7 @@
1.4 /*
1.5 * A pipe opener resource.
1.6 *
1.7 - * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk>
1.8 + * Copyright (C) 2021, 2022 Paul Boddie <paul@boddie.org.uk>
1.9 *
1.10 * This program is free software; you can redistribute it and/or
1.11 * modify it under the terms of the GNU General Public License as
1.12 @@ -21,6 +21,8 @@
1.13
1.14 #include <ipc/cap_alloc.h>
1.15
1.16 +#include <l4/cxx/exceptions>
1.17 +
1.18 #include "pipe_opener_resource.h"
1.19 #include "pipe_opener_server.h"
1.20 #include "pipe_pager.h"
1.21 @@ -53,7 +55,16 @@
1.22 {
1.23 /* Both endpoints will employ a common paging coordinator. */
1.24
1.25 - PipePaging *paging = new PipePaging(_memory, size);
1.26 + PipePaging *paging;
1.27 +
1.28 + try
1.29 + {
1.30 + paging = new PipePaging(_memory, size);
1.31 + }
1.32 + catch (L4::Out_of_memory const &e)
1.33 + {
1.34 + return -L4_ENOMEM;
1.35 + }
1.36
1.37 /* Each endpoint will have its own pager. */
1.38
2.1 --- a/libmem/lib/src/memory_preallocated.cc Mon Mar 21 00:17:42 2022 +0100
2.2 +++ b/libmem/lib/src/memory_preallocated.cc Tue Mar 22 23:03:44 2022 +0100
2.3 @@ -21,6 +21,8 @@
2.4
2.5 #include "memory_preallocated.h"
2.6
2.7 +#include <l4/cxx/exceptions>
2.8 +
2.9
2.10
2.11 /* Initialise the memory pool with the given amount in bytes. */
2.12 @@ -28,16 +30,16 @@
2.13 MemoryPreallocated::MemoryPreallocated(Memory *memory, offset_t amount)
2.14 : _memory(memory), _amount(amount)
2.15 {
2.16 - // NOTE: Handle allocation failure.
2.17 -
2.18 offset_t remaining = amount;
2.19
2.20 while (remaining)
2.21 {
2.22 - _regions.push_back(memory->region());
2.23 + Region *region = memory->region();
2.24
2.25 - if (memory->region_size() >= remaining)
2.26 - break;
2.27 + if (region == NULL)
2.28 + throw L4::Out_of_memory();
2.29 +
2.30 + _regions.push_back(region);
2.31
2.32 remaining -= memory->region_size();
2.33 }