1.1 --- a/libipc/lib/src/server.c Wed Mar 22 16:15:04 2023 +0100
1.2 +++ b/libipc/lib/src/server.c Wed Mar 22 17:31:05 2023 +0100
1.3 @@ -34,18 +34,16 @@
1.4
1.5
1.6
1.7 -/* Associate an IRQ with the IPC gate in the main thread to handle gate deletion
1.8 - notifications. */
1.9 +/* Associate an IRQ with the main thread. */
1.10
1.11 -long ipc_server_apply_irq(l4_cap_idx_t cap, l4_cap_idx_t *irq)
1.12 +long ipc_server_apply_irq(l4_cap_idx_t *irq)
1.13 {
1.14 - return ipc_server_apply_irq_for_thread(cap, irq, l4re_env()->main_thread);
1.15 + return ipc_server_apply_irq_for_thread(irq, l4re_env()->main_thread);
1.16 }
1.17
1.18 -/* Associate an IRQ with the IPC gate in the given thread to handle gate deletion
1.19 - notifications. */
1.20 +/* Associate an IRQ with the given thread. */
1.21
1.22 -long ipc_server_apply_irq_for_thread(l4_cap_idx_t cap, l4_cap_idx_t *irq, l4_cap_idx_t thread)
1.23 +long ipc_server_apply_irq_for_thread(l4_cap_idx_t *irq, l4_cap_idx_t thread)
1.24 {
1.25 /* Create an IRQ for the gate. */
1.26
1.27 @@ -65,14 +63,23 @@
1.28 return err;
1.29 }
1.30
1.31 + return L4_EOK;
1.32 +}
1.33 +
1.34 +/* Associate the given IRQ with gate deletion notifications, also decreasing the
1.35 + IPC gate reference count so that such a notification will be delivered when
1.36 + the final client of the IPC gate releases its reference to it. */
1.37 +
1.38 +long ipc_server_apply_deletion_for_thread(l4_cap_idx_t cap, l4_cap_idx_t irq, l4_cap_idx_t thread)
1.39 +{
1.40 /* Register for notifications. The thread associated with the gate seems to be
1.41 needed. */
1.42
1.43 - err = l4_error(l4_thread_register_del_irq(thread, *irq));
1.44 + long err = l4_error(l4_thread_register_del_irq(thread, irq));
1.45
1.46 if (err)
1.47 {
1.48 - ipc_cap_free_um(*irq);
1.49 + ipc_cap_free_um(irq);
1.50 return err;
1.51 }
1.52
1.53 @@ -249,7 +256,7 @@
1.54
1.55 irq_label = (l4_umword_t) config->irq;
1.56
1.57 - if (!config->notifications || (config->notifications && (label != irq_label)))
1.58 + if (label != irq_label)
1.59 {
1.60 config_from_label = (ipc_server_config_type *) label;
1.61 config_from_label->handler(&msg, config_from_label->handler_obj);
1.62 @@ -257,7 +264,7 @@
1.63
1.64 /* Message involves the IRQ or a termination condition occurred. */
1.65
1.66 - else if ((config->notifications && (label == irq_label)) || msg.terminating)
1.67 + else if ((label == irq_label) || msg.terminating)
1.68 break;
1.69 }
1.70
1.71 @@ -355,10 +362,12 @@
1.72 config->thread = l4re_env()->main_thread;
1.73 config->server = L4_INVALID_CAP;
1.74
1.75 - /* No notifications and with IRQ to be potentially allocated. */
1.76 + /* No notifications and with IRQ to be potentially allocated. Auto-deletion is
1.77 + also disabled by default. */
1.78
1.79 config->notifications = 0;
1.80 config->irq = L4_INVALID_CAP;
1.81 + config->auto_deletion = 0;
1.82 }
1.83
1.84 /* Initialise but do not start a server using the given configuration. */
1.85 @@ -381,11 +390,21 @@
1.86
1.87 if (config->notifications)
1.88 {
1.89 - err = ipc_server_apply_irq_for_thread(config->server, &config->irq, config->thread);
1.90 + err = ipc_server_apply_irq_for_thread(&config->irq, config->thread);
1.91
1.92 if (err)
1.93 return err;
1.94
1.95 + /* Apply auto-deletion if appropriate. */
1.96 +
1.97 + if (config->auto_deletion)
1.98 + {
1.99 + err = ipc_server_apply_deletion_for_thread(config->server, config->irq, config->thread);
1.100 +
1.101 + if (err)
1.102 + return err;
1.103 + }
1.104 +
1.105 /* Unmask the interrupt. */
1.106
1.107 ipc_init_irq(config->irq);