[master] 4d9f776 Convert pointers to uintptr_t before sticking them in the pipe.

Poul-Henning Kamp phk at FreeBSD.org
Fri Jan 23 12:49:00 CET 2015


commit 4d9f776abfda4714fb1d1e5c060ef9a3c52bc2b5
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Fri Jan 23 10:36:52 2015 +0000

    Convert pointers to uintptr_t before sticking them in the pipe.

diff --git a/bin/varnishd/waiter/cache_waiter.c b/bin/varnishd/waiter/cache_waiter.c
index ec8aebb..ab07081 100644
--- a/bin/varnishd/waiter/cache_waiter.c
+++ b/bin/varnishd/waiter/cache_waiter.c
@@ -182,6 +182,7 @@ int
 Wait_Enter(const struct waiter *w, struct waited *wp)
 {
 	ssize_t written;
+	uintptr_t up;
 
 	CHECK_OBJ_NOTNULL(w, WAITER_MAGIC);
 	CHECK_OBJ_NOTNULL(wp, WAITED_MAGIC);
@@ -193,10 +194,12 @@ Wait_Enter(const struct waiter *w, struct waited *wp)
 
 	assert(w->pipes[1] > 0);
 
-	written = write(w->pipes[1], &wp, sizeof wp);
-	if (written != sizeof wp && (errno == EAGAIN || errno == EWOULDBLOCK))
+	up = (uintptr_t)wp;
+	AZ(up & 1);
+	written = write(w->pipes[1], &up, sizeof up);
+	if (written != sizeof up && (errno == EAGAIN || errno == EWOULDBLOCK))
 		return (-1);
-	assert (written == sizeof wp);
+	assert (written == sizeof up);
 	return (0);
 }
 
@@ -220,7 +223,8 @@ wait_updidle(struct waiter *w, double now)
 void
 Wait_Handle(struct waiter *w, struct waited *wp, enum wait_event ev, double now)
 {
-	struct waited *ss[NEV], *wp2;
+	uintptr_t ss[NEV];
+	struct waited *wp2;
 	int i, j, dotimer = 0;
 
 	CHECK_OBJ_NOTNULL(w, WAITER_MAGIC);
@@ -245,15 +249,17 @@ Wait_Handle(struct waiter *w, struct waited *wp, enum wait_event ev, double now)
 		return;
 
 	for (j = 0; i >= sizeof ss[0]; j++, i -= sizeof ss[0]) {
-		CHECK_OBJ_ORNULL(ss[j], WAITED_MAGIC);
-		if (ss[j] == NULL) {
+		if (ss[j] == 0) {
 			AN(w->dismantle);
-		} else if (ss[j] == w->pipe_w) {
+			continue;
+		}
+		CAST_OBJ_NOTNULL(wp2, (void*)ss[j], WAITED_MAGIC);
+		if (wp2 == w->pipe_w) {
 			dotimer = 1;
 		} else {
-			assert(ss[j]->fd >= 0);
-			VTAILQ_INSERT_TAIL(&w->waithead, ss[j], list);
-			w->impl->inject(w, ss[j]);
+			assert(wp2->fd >= 0);
+			VTAILQ_INSERT_TAIL(&w->waithead, wp2, list);
+			w->impl->inject(w, wp2);
 		}
 	}
 	AZ(i);
diff --git a/bin/varnishd/waiter/cache_waiter_poll.c b/bin/varnishd/waiter/cache_waiter_poll.c
index 81763a1..355ab38 100644
--- a/bin/varnishd/waiter/cache_waiter_poll.c
+++ b/bin/varnishd/waiter/cache_waiter_poll.c
@@ -88,6 +88,7 @@ vwp_inject(const struct waiter *w, struct waited *wp)
 	CAST_OBJ_NOTNULL(vwp, w->priv, VWP_MAGIC);
 	CHECK_OBJ_NOTNULL(wp, WAITED_MAGIC);
 	fd = wp->fd;
+VSL(SLT_Debug, 0, "POLL Inject %d", fd);
 	assert(fd >= 0);
 	vwp_pollspace(vwp, (unsigned)fd);
 	assert(fd < vwp->npoll);
@@ -111,6 +112,7 @@ vwp_evict(const struct waiter *w, struct waited *wp)
 	CAST_OBJ_NOTNULL(vwp, w->priv, VWP_MAGIC);
 	CHECK_OBJ_NOTNULL(wp, WAITED_MAGIC);
 	fd = wp->fd;
+VSL(SLT_Debug, 0, "POLL Evict %d", fd);
 	assert(fd >= 0);
 	assert(fd < vwp->npoll);
 	vwp_pollspace(vwp, (unsigned)fd);
@@ -151,6 +153,7 @@ vwp_main(void *priv)
 				break;
 			CHECK_OBJ_NOTNULL(sp, WAITED_MAGIC);
 			fd = sp->fd;
+VSL(SLT_Debug, 0, "POLL Handle %d %x", fd, vwp->pollfd[fd].revents);
 			assert(fd >= 0);
 			assert(fd <= vwp->hpoll);
 			assert(fd < vwp->npoll);



More information about the varnish-commit mailing list