1.1 --- a/libipc/lib/src/server.c Fri Feb 23 01:29:50 2024 +0100
1.2 +++ b/libipc/lib/src/server.c Fri Feb 23 01:33:47 2024 +0100
1.3 @@ -1,7 +1,7 @@
1.4 /*
1.5 * Server binding/registration.
1.6 *
1.7 - * Copyright (C) 2018, 2019, 2020, 2021, 2022 Paul Boddie <paul@boddie.org.uk>
1.8 + * Copyright (C) 2018-2022, 2024 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 @@ -88,26 +88,6 @@
1.13 return l4_error(l4_kobject_dec_refcnt(cap, 1));
1.14 }
1.15
1.16 -
1.17 -
1.18 -/* Bind the main thread to the named capability, employing an identifier for
1.19 - the IPC gate and returning the capability index. */
1.20 -
1.21 -long ipc_server_bind(const char *name, l4_umword_t id, l4_cap_idx_t *server)
1.22 -{
1.23 - /* Obtain a reference to the device. */
1.24 -
1.25 - *server = l4re_env_get_cap(name);
1.26 -
1.27 - if (l4_is_invalid_cap(*server))
1.28 - return -L4_ENOENT;
1.29 -
1.30 - /* Bind to an IPC gate with the label identifying the server as message
1.31 - destination. */
1.32 -
1.33 - return l4_error(l4_rcv_ep_bind_thread(*server, l4re_env()->main_thread, id));
1.34 -}
1.35 -
1.36 /* Initialise a new server capability, binding it to the main thread. */
1.37
1.38 long ipc_server_new(l4_cap_idx_t *cap, void *obj)
1.39 @@ -168,11 +148,7 @@
1.40 long err;
1.41
1.42 if (name != NULL)
1.43 - {
1.44 - err = ipc_server_bind(name, (l4_umword_t) &config, &config.server);
1.45 - if (err)
1.46 - return err;
1.47 - }
1.48 + config.server = l4re_env_get_cap(name);
1.49
1.50 _ipc_server_init_for(&config, default_config, handler_obj);
1.51
1.52 @@ -247,6 +223,13 @@
1.53
1.54 label = label & ~3UL;
1.55
1.56 + /* Since we interpret the label as a pointer, we should detect zero labels
1.57 + and report them since they are likely to be interrupts inappropriately
1.58 + bound to this thread. */
1.59 +
1.60 + if (!label)
1.61 + continue;
1.62 +
1.63 /* Ignore erroneous messages. */
1.64
1.65 if (l4_ipc_error(msg.tag, l4_utcb()))
1.66 @@ -379,12 +362,15 @@
1.67 /* Allocate a new IPC gate if one is not already defined. */
1.68
1.69 if (l4_is_invalid_cap(config->server))
1.70 - {
1.71 err = ipc_server_new_for_thread(&config->server, config, config->thread);
1.72
1.73 - if (err)
1.74 - return err;
1.75 - }
1.76 + /* Otherwise, bind the existing IPC gate to the thread. */
1.77 +
1.78 + else
1.79 + err = l4_error(l4_rcv_ep_bind_thread(config->server, config->thread, (l4_umword_t) config));
1.80 +
1.81 + if (err)
1.82 + return err;
1.83
1.84 /* Allocate an IRQ for notifications if requested. */
1.85