1 /* 2 * Thread-related initialisation activities. 3 * 4 * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #include <l4/re/c/util/cap_alloc.h> 23 #include <l4/re/env.h> 24 #include <l4/sys/factory.h> 25 #include <l4/sys/semaphore.h> 26 27 #include "cap_alloc.h" 28 #include "semaphore.h" 29 #include "thread.h" 30 31 32 33 /* Bootstrap the semaphore support needed by the allocation function. */ 34 35 static long ipc_semaphore_init(l4_cap_idx_t *semaphore) 36 { 37 if (l4_is_invalid_cap(*semaphore)) 38 { 39 *semaphore = l4re_util_cap_alloc(); 40 41 if (l4_is_invalid_cap(*semaphore)) 42 return -L4_ENOENT; 43 44 if (l4_error(l4_factory_create(l4re_env()->factory, L4_PROTO_SEMAPHORE, *semaphore))) 45 { 46 ipc_cap_free_um(*semaphore); 47 return -L4_ENOENT; 48 } 49 50 return ipc_semaphore_up(*semaphore); 51 } 52 else 53 return L4_EOK; 54 } 55 56 /* Bootstrap the semaphore support needed by the allocation functions. */ 57 58 extern l4_cap_idx_t ipc_cap_alloc_semaphore; 59 60 long ipc_cap_alloc_init() 61 { 62 return ipc_semaphore_init(&ipc_cap_alloc_semaphore); 63 } 64 65 /* Bootstrap the semaphore support needed by the memory functions. */ 66 67 extern l4_cap_idx_t ipc_mem_semaphore; 68 69 long ipc_mem_init() 70 { 71 return ipc_semaphore_init(&ipc_mem_semaphore); 72 } 73 74 /* General semaphore initialisation. */ 75 76 long ipc_thread_init() 77 { 78 long err; 79 80 err = ipc_cap_alloc_init(); 81 if (err) 82 return err; 83 84 return ipc_mem_init(); 85 } 86 87 // vim: tabstop=2 expandtab shiftwidth=2