1.1 --- a/libipc/lib/src/cap_alloc.c Tue Apr 26 22:48:33 2022 +0200
1.2 +++ b/libipc/lib/src/cap_alloc.c Tue Apr 26 22:52:40 2022 +0200
1.3 @@ -1,7 +1,7 @@
1.4 /*
1.5 * Capability allocation and management.
1.6 *
1.7 - * Copyright (C) 2019, 2021 Paul Boddie <paul@boddie.org.uk>
1.8 + * Copyright (C) 2019, 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 @@ -20,6 +20,7 @@
1.13 */
1.14
1.15 #include <l4/re/c/util/cap_alloc.h>
1.16 +#include <l4/sys/err.h>
1.17
1.18 #include "cap_alloc.h"
1.19 #include "semaphore.h"
1.20 @@ -52,6 +53,41 @@
1.21 return cap;
1.22 }
1.23
1.24 +/* Reserve and return many capability indexes. */
1.25 +
1.26 +long ipc_cap_alloc_many(l4_cap_idx_t caps[], int count)
1.27 +{
1.28 + int i;
1.29 + long err;
1.30 +
1.31 + /* Allocate a capability in the critical section, then return. */
1.32 +
1.33 + err = ipc_semaphore_down(ipc_cap_alloc_semaphore);
1.34 + if (err)
1.35 + return err;
1.36 +
1.37 + for (i = 0; i < count; i++)
1.38 + {
1.39 + caps[i] = l4re_util_cap_alloc();
1.40 +
1.41 + if (l4_is_invalid_cap(caps[i]))
1.42 + {
1.43 + err = -L4_ENOMEM;
1.44 + break;
1.45 + }
1.46 + }
1.47 +
1.48 + /* Free allocated capabilities if not all could be allocated. */
1.49 +
1.50 + if (err)
1.51 + for (; i >= 0; i--)
1.52 + l4re_util_cap_free(caps[i]);
1.53 +
1.54 + ipc_semaphore_up(ipc_cap_alloc_semaphore);
1.55 +
1.56 + return err;
1.57 +}
1.58 +
1.59 /* Release a capability. */
1.60
1.61 int ipc_cap_free(l4_cap_idx_t cap)