1.1 --- a/libfsserver/lib/generic/resource_server.cc Thu Mar 10 23:23:07 2022 +0100
1.2 +++ b/libfsserver/lib/generic/resource_server.cc Fri Mar 11 22:09:09 2022 +0100
1.3 @@ -34,7 +34,7 @@
1.4
1.5 long ResourceServer::bind(const char *name)
1.6 {
1.7 - return ipc_server_bind(name, (l4_umword_t) _resource, &_config->server);
1.8 + return ipc_server_bind(name, (l4_umword_t) _config, &_config->server);
1.9 }
1.10
1.11 /* Start in the same thread with no deletion notifications or finalisation. */
2.1 --- a/libipc/include/ipc/server.h Thu Mar 10 23:23:07 2022 +0100
2.2 +++ b/libipc/include/ipc/server.h Fri Mar 11 22:09:09 2022 +0100
2.3 @@ -1,7 +1,7 @@
2.4 /*
2.5 * Server binding/registration.
2.6 *
2.7 - * Copyright (C) 2018, 2019, 2020, 2021 Paul Boddie <paul@boddie.org.uk>
2.8 + * Copyright (C) 2018, 2019, 2020, 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 @@ -27,12 +27,6 @@
2.13
2.14 EXTERN_C_BEGIN
2.15
2.16 -/* A convenience macro for invoking the server mainloop. */
2.17 -
2.18 -#define ipc_server_loop_for(TYPE, POINTER) \
2.19 - ipc_server_loop(TYPE##_expected_items, (TYPE *) POINTER, \
2.20 - (ipc_server_handler_type) handle_##TYPE)
2.21 -
2.22 /* A handler function type. */
2.23
2.24 typedef void (*ipc_server_handler_type)(ipc_message_t *, void *);
2.25 @@ -113,13 +107,12 @@
2.26
2.27 /* Handle incoming messages for a server. */
2.28
2.29 -long ipc_server_loop(int expected_items, void *obj,
2.30 - ipc_server_handler_type handler);
2.31 +long ipc_server_loop(int expected_items, ipc_server_config_type *config);
2.32
2.33 /* Handle incoming messages and IRQ notifications for a server. */
2.34
2.35 -long ipc_server_managed_loop(int expected_items, void *obj, l4_cap_idx_t irq,
2.36 - ipc_server_handler_type handler);
2.37 +long ipc_server_managed_loop(int expected_items, ipc_server_config_type *config,
2.38 + l4_cap_idx_t irq);
2.39
2.40 /* A pthread-compatible mainloop initiation function. */
2.41
3.1 --- a/libipc/lib/src/server.c Thu Mar 10 23:23:07 2022 +0100
3.2 +++ b/libipc/lib/src/server.c Fri Mar 11 22:09:09 2022 +0100
3.3 @@ -153,21 +153,24 @@
3.4
3.5 /* A server main loop with no endpoint deletion detection. */
3.6
3.7 -long ipc_server_loop(int expected_items, void *obj,
3.8 - ipc_server_handler_type handler)
3.9 +long ipc_server_loop(int expected_items, ipc_server_config_type *config)
3.10 {
3.11 - return ipc_server_managed_loop(expected_items, obj, L4_INVALID_CAP, handler);
3.12 + return ipc_server_managed_loop(expected_items, config, L4_INVALID_CAP);
3.13 }
3.14
3.15 /* A server main loop handling endpoint deletion for an IPC gate dedicated to
3.16 a particular object within its own thread. */
3.17
3.18 -long ipc_server_managed_loop(int expected_items, void *obj, l4_cap_idx_t irq,
3.19 - ipc_server_handler_type handler)
3.20 +long ipc_server_managed_loop(int expected_items, ipc_server_config_type *config,
3.21 + l4_cap_idx_t irq)
3.22 {
3.23 ipc_message_t msg;
3.24 l4_umword_t label, irq_label = (l4_umword_t) irq;
3.25
3.26 + /* Permit other endpoints by dynamically interpreting the label. */
3.27 +
3.28 + ipc_server_config_type *config_from_label;
3.29 +
3.30 /* Declare the extent to which capabilities are expected in messages. */
3.31
3.32 long err = ipc_message_expect(&msg, expected_items);
3.33 @@ -198,7 +201,10 @@
3.34 /* Message involves the IPC gate itself. */
3.35
3.36 if (label != irq_label)
3.37 - handler(&msg, obj);
3.38 + {
3.39 + config_from_label = (ipc_server_config_type *) label;
3.40 + config_from_label->handler(&msg, config_from_label->handler_obj);
3.41 + }
3.42
3.43 /* Message involves the IRQ or a termination condition occurred. */
3.44
3.45 @@ -219,8 +225,8 @@
3.46 {
3.47 ipc_server_config_type *config = (ipc_server_config_type *) data;
3.48
3.49 - long err = ipc_server_managed_loop(config->expected_items, config->handler_obj,
3.50 - config->irq, config->handler);
3.51 + long err = ipc_server_managed_loop(config->expected_items, config,
3.52 + config->irq);
3.53
3.54 if (config->finaliser != NULL)
3.55 config->finaliser(config);
3.56 @@ -317,7 +323,7 @@
3.57
3.58 if (l4_is_invalid_cap(config->server))
3.59 {
3.60 - err = ipc_server_new_for_thread(&config->server, config->handler_obj, config->thread);
3.61 + err = ipc_server_new_for_thread(&config->server, config, config->thread);
3.62
3.63 if (err)
3.64 return err;