1.1 --- a/libipc/include/ipc/cap_alloc.h Tue Apr 26 22:48:33 2022 +0200
1.2 +++ b/libipc/include/ipc/cap_alloc.h 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 @@ -26,6 +26,7 @@
1.13 EXTERN_C_BEGIN
1.14
1.15 l4_cap_idx_t ipc_cap_alloc(void);
1.16 +long ipc_cap_alloc_many(l4_cap_idx_t caps[], int count);
1.17 int ipc_cap_free(l4_cap_idx_t cap);
1.18 int ipc_cap_free_um(l4_cap_idx_t cap);
1.19
2.1 --- a/libipc/lib/src/cap_alloc.c Tue Apr 26 22:48:33 2022 +0200
2.2 +++ b/libipc/lib/src/cap_alloc.c Tue Apr 26 22:52:40 2022 +0200
2.3 @@ -1,7 +1,7 @@
2.4 /*
2.5 * Capability allocation and management.
2.6 *
2.7 - * Copyright (C) 2019, 2021 Paul Boddie <paul@boddie.org.uk>
2.8 + * Copyright (C) 2019, 2021, 2022 Paul Boddie <paul@boddie.org.uk>
2.9 *
2.10 * This program is free software; you can redistribute it and/or
2.11 * modify it under the terms of the GNU General Public License as
2.12 @@ -20,6 +20,7 @@
2.13 */
2.14
2.15 #include <l4/re/c/util/cap_alloc.h>
2.16 +#include <l4/sys/err.h>
2.17
2.18 #include "cap_alloc.h"
2.19 #include "semaphore.h"
2.20 @@ -52,6 +53,41 @@
2.21 return cap;
2.22 }
2.23
2.24 +/* Reserve and return many capability indexes. */
2.25 +
2.26 +long ipc_cap_alloc_many(l4_cap_idx_t caps[], int count)
2.27 +{
2.28 + int i;
2.29 + long err;
2.30 +
2.31 + /* Allocate a capability in the critical section, then return. */
2.32 +
2.33 + err = ipc_semaphore_down(ipc_cap_alloc_semaphore);
2.34 + if (err)
2.35 + return err;
2.36 +
2.37 + for (i = 0; i < count; i++)
2.38 + {
2.39 + caps[i] = l4re_util_cap_alloc();
2.40 +
2.41 + if (l4_is_invalid_cap(caps[i]))
2.42 + {
2.43 + err = -L4_ENOMEM;
2.44 + break;
2.45 + }
2.46 + }
2.47 +
2.48 + /* Free allocated capabilities if not all could be allocated. */
2.49 +
2.50 + if (err)
2.51 + for (; i >= 0; i--)
2.52 + l4re_util_cap_free(caps[i]);
2.53 +
2.54 + ipc_semaphore_up(ipc_cap_alloc_semaphore);
2.55 +
2.56 + return err;
2.57 +}
2.58 +
2.59 /* Release a capability. */
2.60
2.61 int ipc_cap_free(l4_cap_idx_t cap)