You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by tr...@apache.org on 2019/03/22 13:48:45 UTC
[qpid-dispatch] branch master updated (136940b -> 45332d3)
This is an automated email from the ASF dual-hosted git repository.
tross pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/qpid-dispatch.git.
from 136940b DISPATCH-1296 - Change use of pn_ssl_domain_allow_unsecured_client() to pn_transport_require_encryption() This closes #469 - pn_ssl_domain_unsecured_client() is deprecated and may be removed.
new c47b976 DISPATCH-1299 - Added safe-reference feature to the alloc-pool module. Note: alloc-malloc also has the same interface (will build), but does not provide the same safety.
new 16826bc DISPATCH-1285 - Updated the deferred receive handler to use safe pointers to links
new 45332d3 DISPATCH-1299 - Update safe-pointer use in the lookup client to use the newer API.
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
include/qpid/dispatch/alloc_malloc.h | 17 +++++--
include/qpid/dispatch/alloc_pool.h | 12 ++++-
include/qpid/dispatch/container.h | 2 +
src/container.c | 1 -
src/router_core/core_client_api.c | 2 +
src/router_core/core_timer.c | 1 -
.../modules/address_lookup_client/lookup_client.c | 53 ++++++++++++----------
.../address_lookup_server/address_lookup_server.c | 1 +
src/router_core/modules/edge_router/edge_mgmt.c | 1 +
.../modules/edge_router/link_route_proxy.c | 1 +
src/router_node.c | 39 ++++++++++------
tests/alloc_test.c | 23 ++++++++++
12 files changed, 108 insertions(+), 45 deletions(-)
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[qpid-dispatch] 02/03: DISPATCH-1285 - Updated the deferred receive
handler to use safe pointers to links
Posted by tr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
tross pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/qpid-dispatch.git
commit 16826bc29e8772feeda84c07f546a5db60d755a8
Author: Ted Ross <tr...@redhat.com>
AuthorDate: Thu Mar 21 13:57:16 2019 -0400
DISPATCH-1285 - Updated the deferred receive handler to use safe pointers to links
(cherry picked from commit 33d4a27f973037345f3db61390a998fd3cee2f94)
---
src/router_node.c | 39 +++++++++++++++++++++++++--------------
1 file changed, 25 insertions(+), 14 deletions(-)
diff --git a/src/router_node.c b/src/router_node.c
index 2c6771f..3ae2813 100644
--- a/src/router_node.c
+++ b/src/router_node.c
@@ -635,16 +635,23 @@ static bool AMQP_rx_handler(void* context, qd_link_t *link)
/**
* Deferred callback for inbound delivery handler
*/
-static void deferred_AMQP_rx_handler(void *context, bool discard) {
+static void deferred_AMQP_rx_handler(void *context, bool discard)
+{
+ qd_link_t_sp *safe_qdl = (qd_link_t_sp*) context;
+
if (!discard) {
- qd_link_t *qdl = (qd_link_t*)context;
- qd_router_t *qdr = (qd_router_t *)qd_link_get_node_context(qdl);
- assert(qdr != 0);
- while (true) {
- if (! AMQP_rx_handler(qdr, qdl))
- break;
+ qd_link_t *qdl = safe_deref_qd_link_t(*safe_qdl);
+ if (!!qdl) {
+ qd_router_t *qdr = (qd_router_t*) qd_link_get_node_context(qdl);
+ assert(qdr != 0);
+ while (true) {
+ if (!AMQP_rx_handler(qdr, qdl))
+ break;
+ }
}
}
+
+ free(safe_qdl);
}
@@ -782,20 +789,20 @@ static int AMQP_link_detach_handler(void* context, qd_link_t *link, qd_detach_ty
if (!link)
return 0;
- pn_link_t *pn_link = qd_link_pn(link);
-
+ pn_link_t *pn_link = qd_link_pn(link);
if (!pn_link)
return 0;
- pn_delivery_t *pnd = pn_link_current(pn_link);
-
+ pn_delivery_t *pnd = pn_link_current(pn_link);
if (pnd) {
qd_message_t *msg = qd_get_message_context(pnd);
if (msg) {
if (!qd_message_receive_complete(msg)) {
qd_link_set_q2_limit_unbounded(link, true);
qd_message_Q2_holdoff_disable(msg);
- deferred_AMQP_rx_handler((void *)link, false);
+ qd_link_t_sp *safe_ptr = NEW(qd_link_t_sp);
+ set_safe_ptr_qd_link_t(link, safe_ptr);
+ deferred_AMQP_rx_handler(safe_ptr, false);
}
}
@@ -1546,7 +1553,9 @@ static uint64_t CORE_link_deliver(void *context, qdr_link_t *link, qdr_delivery_
if (qdl_in) {
qd_connection_t *qdc_in = qd_link_connection(qdl_in);
if (qdc_in) {
- qd_connection_invoke_deferred(qdc_in, deferred_AMQP_rx_handler, qdl_in);
+ qd_link_t_sp *safe_ptr = NEW(qd_link_t_sp);
+ set_safe_ptr_qd_link_t(qdl_in, safe_ptr);
+ qd_connection_invoke_deferred(qdc_in, deferred_AMQP_rx_handler, safe_ptr);
}
}
}
@@ -1669,7 +1678,9 @@ static void CORE_delivery_update(void *context, qdr_delivery_t *dlv, uint64_t di
qdr_delivery_set_disposition(dlv, disp);
qd_message_set_discard(msg, true);
qd_message_Q2_holdoff_disable(msg);
- qd_connection_invoke_deferred(qd_conn, deferred_AMQP_rx_handler, link);
+ qd_link_t_sp *safe_ptr = NEW(qd_link_t_sp);
+ set_safe_ptr_qd_link_t(link, safe_ptr);
+ qd_connection_invoke_deferred(qd_conn, deferred_AMQP_rx_handler, safe_ptr);
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[qpid-dispatch] 01/03: DISPATCH-1299 - Added safe-reference feature
to the alloc-pool module. Note: alloc-malloc also has the same interface
(will build), but does not provide the same safety.
Posted by tr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
tross pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/qpid-dispatch.git
commit c47b976df339ea896b2ba5cf535b9bc07c13534c
Author: Ted Ross <tr...@redhat.com>
AuthorDate: Thu Mar 21 12:53:50 2019 -0400
DISPATCH-1299 - Added safe-reference feature to the alloc-pool module.
Note: alloc-malloc also has the same interface (will build), but does not provide the same safety.
---
include/qpid/dispatch/alloc_malloc.h | 17 +++++++++++++---
include/qpid/dispatch/alloc_pool.h | 12 ++++++++++-
include/qpid/dispatch/container.h | 2 ++
src/container.c | 1 -
src/router_core/core_client_api.c | 2 ++
src/router_core/core_timer.c | 1 -
.../address_lookup_server/address_lookup_server.c | 1 +
src/router_core/modules/edge_router/edge_mgmt.c | 1 +
.../modules/edge_router/link_route_proxy.c | 1 +
tests/alloc_test.c | 23 ++++++++++++++++++++++
10 files changed, 55 insertions(+), 6 deletions(-)
diff --git a/include/qpid/dispatch/alloc_malloc.h b/include/qpid/dispatch/alloc_malloc.h
index 12d683e..d89ed28 100644
--- a/include/qpid/dispatch/alloc_malloc.h
+++ b/include/qpid/dispatch/alloc_malloc.h
@@ -21,6 +21,7 @@
#include <stdint.h>
#include <string.h>
+#include <qpid/dispatch/ctools.h>
/**
*@file
@@ -29,9 +30,17 @@
* Useful for debugging with tools like valgrind.
*/
-#define ALLOC_DECLARE(T) \
- T *new_##T(void); \
- void free_##T(T *p)
+typedef struct {
+ void *ptr;
+ uint32_t seq;
+} qd_alloc_safe_ptr_t;
+
+#define ALLOC_DECLARE(T) \
+ T *new_##T(void); \
+ void free_##T(T *p); \
+ typedef qd_alloc_safe_ptr_t T##_sp; \
+ void set_safe_ptr_##T(T *p, T##_sp *sp); \
+ T *safe_deref_##T(T##_sp sp)
#define ALLOC_DEFINE_CONFIG(T,S,A,C) \
T *new_##T(void) { size_t *a = (A); \
@@ -41,6 +50,8 @@
void free_##T(T *p) { size_t *a = (A); \
QD_MEMORY_FILL(p, QD_MEMORY_FREE, (S) + (a ? *a : 0)); \
free(p); } \
+ void set_safe_ptr_##T(T *p, T##_sp *sp) { sp->ptr = (void*) p; sp->seq = qd_alloc_sequence((void*) p); } \
+ T *safe_deref_##T(T##_sp sp) { return sp.seq == qd_alloc_sequence((void*) sp.ptr) ? (T*) sp.ptr : (T*) 0; } \
void *unused##T
#define ALLOC_DEFINE(T) ALLOC_DEFINE_CONFIG(T, sizeof(T), 0, 0)
diff --git a/include/qpid/dispatch/alloc_pool.h b/include/qpid/dispatch/alloc_pool.h
index 6b66e88..4f6931c 100644
--- a/include/qpid/dispatch/alloc_pool.h
+++ b/include/qpid/dispatch/alloc_pool.h
@@ -69,6 +69,11 @@ typedef struct {
uint32_t trailer;
} qd_alloc_type_desc_t;
+typedef struct {
+ void *ptr;
+ uint32_t seq;
+} qd_alloc_safe_ptr_t;
+
/** Allocate in a thread pool. Use via ALLOC_DECLARE */
void *qd_alloc(qd_alloc_type_desc_t *desc, qd_alloc_pool_t **tpool);
/** De-allocate from a thread pool. Use via ALLOC_DECLARE */
@@ -81,7 +86,10 @@ uint32_t qd_alloc_sequence(void *p);
#define ALLOC_DECLARE(T) \
extern __thread qd_alloc_pool_t *__local_pool_##T; \
T *new_##T(void); \
- void free_##T(T *p)
+ void free_##T(T *p); \
+ typedef qd_alloc_safe_ptr_t T##_sp; \
+ void set_safe_ptr_##T(T *p, T##_sp *sp); \
+ T *safe_deref_##T(T##_sp sp)
/**
* Define allocator configuration.
@@ -92,6 +100,8 @@ uint32_t qd_alloc_sequence(void *p);
__thread qd_alloc_pool_t *__local_pool_##T = 0; \
T *new_##T(void) { return (T*) qd_alloc(&__desc_##T, &__local_pool_##T); } \
void free_##T(T *p) { qd_dealloc(&__desc_##T, &__local_pool_##T, (char*) p); } \
+ void set_safe_ptr_##T(T *p, T##_sp *sp) { sp->ptr = (void*) p; sp->seq = qd_alloc_sequence((void*) p); } \
+ T *safe_deref_##T(T##_sp sp) { return sp.seq == qd_alloc_sequence((void*) sp.ptr) ? (T*) sp.ptr : (T*) 0; } \
qd_alloc_stats_t *alloc_stats_##T(void) { return __desc_##T.stats; } \
void *unused##T
diff --git a/include/qpid/dispatch/container.h b/include/qpid/dispatch/container.h
index 047ac6e..fd35a48 100644
--- a/include/qpid/dispatch/container.h
+++ b/include/qpid/dispatch/container.h
@@ -71,6 +71,8 @@ typedef enum {
typedef struct qd_node_t qd_node_t;
typedef struct qd_link_t qd_link_t;
+ALLOC_DECLARE(qd_link_t);
+
typedef bool (*qd_container_delivery_handler_t) (void *node_context, qd_link_t *link);
typedef void (*qd_container_disposition_handler_t) (void *node_context, qd_link_t *link, pn_delivery_t *pnd);
typedef int (*qd_container_link_handler_t) (void *node_context, qd_link_t *link);
diff --git a/src/container.c b/src/container.c
index 2e9bace..12e6930 100644
--- a/src/container.c
+++ b/src/container.c
@@ -66,7 +66,6 @@ struct qd_link_t {
DEQ_DECLARE(qd_link_t, qd_link_list_t);
-ALLOC_DECLARE(qd_link_t);
ALLOC_DEFINE(qd_link_t);
ALLOC_DEFINE(qd_link_ref_t);
diff --git a/src/router_core/core_client_api.c b/src/router_core/core_client_api.c
index 3b32b31..5810207 100644
--- a/src/router_core/core_client_api.c
+++ b/src/router_core/core_client_api.c
@@ -55,6 +55,7 @@ struct qdrc_client_request_t {
qdrc_client_request_done_CT_t done_cb;
};
DEQ_DECLARE(qdrc_client_request_t, qdrc_client_request_list_t);
+ALLOC_DECLARE(qdrc_client_request_t);
ALLOC_DEFINE(qdrc_client_request_t);
@@ -83,6 +84,7 @@ struct qdrc_client_t {
qdrc_client_on_flow_CT_t on_flow_cb;
};
+ALLOC_DECLARE(qdrc_client_t);
ALLOC_DEFINE(qdrc_client_t);
diff --git a/src/router_core/core_timer.c b/src/router_core/core_timer.c
index d34beb1..7766488 100644
--- a/src/router_core/core_timer.c
+++ b/src/router_core/core_timer.c
@@ -21,7 +21,6 @@
#include <qpid/dispatch/ctools.h>
#include "router_core_private.h"
-ALLOC_DECLARE(qdr_core_timer_t);
ALLOC_DEFINE(qdr_core_timer_t);
void qdr_process_tick_CT(qdr_core_t *core, qdr_action_t *action, bool discard);
diff --git a/src/router_core/modules/address_lookup_server/address_lookup_server.c b/src/router_core/modules/address_lookup_server/address_lookup_server.c
index 7067aa7..278c675 100644
--- a/src/router_core/modules/address_lookup_server/address_lookup_server.c
+++ b/src/router_core/modules/address_lookup_server/address_lookup_server.c
@@ -31,6 +31,7 @@ typedef struct _endpoint_ref {
const char *container_id;
} _endpoint_ref_t;
DEQ_DECLARE(_endpoint_ref_t, _endpoint_ref_list_t);
+ALLOC_DECLARE(_endpoint_ref_t);
ALLOC_DEFINE(_endpoint_ref_t);
diff --git a/src/router_core/modules/edge_router/edge_mgmt.c b/src/router_core/modules/edge_router/edge_mgmt.c
index e3f8532..beee1c5 100644
--- a/src/router_core/modules/edge_router/edge_mgmt.c
+++ b/src/router_core/modules/edge_router/edge_mgmt.c
@@ -84,6 +84,7 @@ struct qcm_edge_mgmt_request_t {
qcm_edge_mgmt_reply_CT_t reply_callback;
qcm_edge_mgmt_error_CT_t error_callback;
};
+ALLOC_DECLARE(qcm_edge_mgmt_request_t);
ALLOC_DEFINE(qcm_edge_mgmt_request_t);
diff --git a/src/router_core/modules/edge_router/link_route_proxy.c b/src/router_core/modules/edge_router/link_route_proxy.c
index 44e164b..0e8cb7e 100644
--- a/src/router_core/modules/edge_router/link_route_proxy.c
+++ b/src/router_core/modules/edge_router/link_route_proxy.c
@@ -46,6 +46,7 @@ struct link_route_proxy_t {
link_route_proxy_state_t proxy_state;
qd_direction_t direction;
};
+ALLOC_DECLARE(link_route_proxy_t);
ALLOC_DEFINE(link_route_proxy_t);
DEQ_DECLARE(link_route_proxy_t, link_route_proxy_list_t);
diff --git a/tests/alloc_test.c b/tests/alloc_test.c
index 2f05f0c..6b1262c 100644
--- a/tests/alloc_test.c
+++ b/tests/alloc_test.c
@@ -72,12 +72,35 @@ static char* test_alloc_basic(void *context)
return 0;
}
+
+static char *test_safe_references(void *context)
+{
+ object_t *obj = new_object_t();
+ object_t_sp safe_obj;
+
+ set_safe_ptr_object_t(obj, &safe_obj);
+ object_t *alias = safe_deref_object_t(safe_obj);
+
+ if (obj != alias)
+ return "Safe alias was not equal to the original pointer";
+
+ free_object_t(obj);
+ alias = safe_deref_object_t(safe_obj);
+
+ if (alias != 0)
+ return "Safe dereference of a freed object was not null";
+
+ return 0;
+}
+
+
int alloc_tests(void)
{
int result = 0;
char *test_group = "alloc_tests";
TEST_CASE(test_alloc_basic, 0);
+ TEST_CASE(test_safe_references, 0);
return result;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[qpid-dispatch] 03/03: DISPATCH-1299 - Update safe-pointer use in
the lookup client to use the newer API.
Posted by tr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
tross pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/qpid-dispatch.git
commit 45332d36a1091d872cf857178432e04631af8456
Author: Ted Ross <tr...@redhat.com>
AuthorDate: Fri Mar 22 09:42:41 2019 -0400
DISPATCH-1299 - Update safe-pointer use in the lookup client to use the newer API.
(cherry picked from commit 1ee6aa76e2bdcbdcd4fc9d9f9fe7a7f0bd7a97a5)
---
.../modules/address_lookup_client/lookup_client.c | 53 ++++++++++++----------
1 file changed, 28 insertions(+), 25 deletions(-)
diff --git a/src/router_core/modules/address_lookup_client/lookup_client.c b/src/router_core/modules/address_lookup_client/lookup_client.c
index 1f9abd8..c71673f 100644
--- a/src/router_core/modules/address_lookup_client/lookup_client.c
+++ b/src/router_core/modules/address_lookup_client/lookup_client.c
@@ -43,13 +43,11 @@ static void on_request_done(qdr_core_t *core,
typedef struct qcm_addr_lookup_request_t {
DEQ_LINKS(struct qcm_addr_lookup_request_t);
- qdr_connection_t *conn;
- qdr_link_t *link;
- uint32_t conn_sequence;
- uint32_t link_sequence;
- qd_direction_t dir;
- qdr_terminus_t *source;
- qdr_terminus_t *target;
+ qdr_connection_t_sp conn_sp;
+ qdr_link_t_sp link_sp;
+ qd_direction_t dir;
+ qdr_terminus_t *source;
+ qdr_terminus_t *target;
} qcm_addr_lookup_request_t;
DEQ_DECLARE(qcm_addr_lookup_request_t, qcm_addr_lookup_request_list_t);
@@ -404,13 +402,19 @@ static void qdr_link_react_to_first_attach_CT(qdr_core_t *core,
static void qcm_addr_lookup_local_search(qcm_lookup_client_t *client, qcm_addr_lookup_request_t *request)
{
- bool link_route;
- bool unavailable;
- bool core_endpoint;
+ bool link_route;
+ bool unavailable;
+ bool core_endpoint;
+ qdr_connection_t *conn = safe_deref_qdr_connection_t(request->conn_sp);
+ qdr_link_t *link = safe_deref_qdr_link_t(request->link_sp);
+
+ if (conn == 0 || link == 0)
+ return;
+
qdr_terminus_t *term = request->dir == QD_INCOMING ? request->target : request->source;
qdr_address_t *addr = qdr_lookup_terminus_address_CT(client->core,
request->dir,
- request->conn,
+ conn,
term,
true,
true,
@@ -418,9 +422,9 @@ static void qcm_addr_lookup_local_search(qcm_lookup_client_t *client, qcm_addr_l
&unavailable,
&core_endpoint);
qdr_link_react_to_first_attach_CT(client->core,
- request->conn,
+ conn,
addr,
- request->link,
+ link,
request->dir,
request->source,
request->target,
@@ -516,15 +520,12 @@ static void qcm_addr_lookup_CT(void *context,
//
qcm_addr_lookup_request_t *request = new_qcm_addr_lookup_request_t();
DEQ_ITEM_INIT(request);
- request->conn = conn;
- request->link = link;
+ set_safe_ptr_qdr_connection_t(conn, &request->conn_sp);
+ set_safe_ptr_qdr_link_t(link, &request->link_sp);
request->dir = dir;
request->source = source;
request->target = target;
- request->conn_sequence = qd_alloc_sequence(conn);
- request->link_sequence = qd_alloc_sequence(link);
-
DEQ_INSERT_TAIL(client->pending_requests, request);
qcm_addr_lookup_process_pending_requests_CT(client);
return;
@@ -606,13 +607,15 @@ static uint64_t on_reply(qdr_core_t *core,
bool is_link_route;
bool has_destinations;
+ qdr_connection_t *conn = safe_deref_qdr_connection_t(request->conn_sp);
+ qdr_link_t *link = safe_deref_qdr_link_t(request->link_sp);
+
//
- // If the pointer sequences mismatch for either the connection or link,
- // exit without processing because either the connection or link has
- // been freed while the request was in-flight.
+ // If the connection or link pointers are NULL, exit without processing
+ // because either the connection or link has been freed while the
+ // request was in-flight.
//
- if (request->conn_sequence != qd_alloc_sequence(request->conn) ||
- request->link_sequence != qd_alloc_sequence(request->link)) {
+ if (conn == 0 || link == 0) {
qdr_terminus_free(request->source);
qdr_terminus_free(request->target);
return 0;
@@ -633,13 +636,13 @@ static uint64_t on_reply(qdr_core_t *core,
//
// The address is for a link route, but there are no destinations upstream. Fail with no-route.
//
- qdr_link_outbound_detach_CT(core, request->link, 0, QDR_CONDITION_NO_ROUTE_TO_DESTINATION, true);
+ qdr_link_outbound_detach_CT(core, link, 0, QDR_CONDITION_NO_ROUTE_TO_DESTINATION, true);
else
//
// The address is for a link route and there are destinations upstream. Directly forward the attach.
//
- qdr_forward_link_direct_CT(core, client->edge_conn, request->link, request->source, request->target, 0, 0);
+ qdr_forward_link_direct_CT(core, client->edge_conn, link, request->source, request->target, 0, 0);
} else {
//
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org