Commit fbe7e755 authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

ws: Almost ban direct access to the workspace front

Proving that this always needed for use cases dealing with workspace
reservations.

Well, almost always, for now vmod_vtc and the panic subsystem are left
alone.
parent 8a2cde41
...@@ -674,7 +674,7 @@ HSH_Purge(struct worker *wrk, struct objhead *oh, vtim_real ttl_now, ...@@ -674,7 +674,7 @@ HSH_Purge(struct worker *wrk, struct objhead *oh, vtim_real ttl_now,
more = 0; more = 0;
spc = ospc; spc = ospc;
nobj = 0; nobj = 0;
ocp = (void*)wrk->aws->f; ocp = WS_Reservation(wrk->aws);
Lck_Lock(&oh->mtx); Lck_Lock(&oh->mtx);
assert(oh->refcnt > 0); assert(oh->refcnt > 0);
VTAILQ_FOREACH(oc, &oh->objcs, hsh_list) { VTAILQ_FOREACH(oc, &oh->objcs, hsh_list) {
......
...@@ -403,7 +403,7 @@ http_CollectHdrSep(struct http *hp, const char *hdr, const char *sep) ...@@ -403,7 +403,7 @@ http_CollectHdrSep(struct http *hp, const char *hdr, const char *sep)
if (b == NULL) { if (b == NULL) {
/* Found second header, start our collection */ /* Found second header, start our collection */
ml = WS_ReserveAll(hp->ws); ml = WS_ReserveAll(hp->ws);
b = hp->ws->f; b = WS_Reservation(hp->ws);
e = b + ml; e = b + ml;
x = Tlen(hp->hd[f]); x = Tlen(hp->hd[f]);
if (b + x >= e) { if (b + x >= e) {
...@@ -444,7 +444,7 @@ http_CollectHdrSep(struct http *hp, const char *hdr, const char *sep) ...@@ -444,7 +444,7 @@ http_CollectHdrSep(struct http *hp, const char *hdr, const char *sep)
hp->nhd = (uint16_t)d; hp->nhd = (uint16_t)d;
AN(e); AN(e);
*b = '\0'; *b = '\0';
hp->hd[f].b = hp->ws->f; hp->hd[f].b = WS_Reservation(hp->ws);
hp->hd[f].e = b; hp->hd[f].e = b;
WS_ReleaseP(hp->ws, b + 1); WS_ReleaseP(hp->ws, b + 1);
} }
......
...@@ -124,7 +124,7 @@ ses_res_attr(struct sess *sp, enum sess_attr a, void **dst, int sz) ...@@ -124,7 +124,7 @@ ses_res_attr(struct sess *sp, enum sess_attr a, void **dst, int sz)
o = WS_ReserveSize(sp->ws, sz); o = WS_ReserveSize(sp->ws, sz);
if (o < sz) if (o < sz)
return (0); return (0);
*dst = sp->ws->f; *dst = WS_Reservation(sp->ws);
o = sp->ws->f - sp->ws->s; o = sp->ws->f - sp->ws->s;
WS_Release(sp->ws, sz); WS_Release(sp->ws, sz);
assert(o >= 0 && o <= 0xffff); assert(o >= 0 && o <= 0xffff);
...@@ -210,19 +210,19 @@ HTC_Status(enum htc_status_e e) ...@@ -210,19 +210,19 @@ HTC_Status(enum htc_status_e e)
void void
HTC_RxInit(struct http_conn *htc, struct ws *ws) HTC_RxInit(struct http_conn *htc, struct ws *ws)
{ {
unsigned r;
ssize_t l; ssize_t l;
CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC); CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC);
htc->ws = ws; htc->ws = ws;
(void)WS_ReserveAll(htc->ws); r = WS_ReserveAll(htc->ws);
htc->rxbuf_b = ws->f; htc->rxbuf_b = htc->rxbuf_e = WS_Reservation(ws);
htc->rxbuf_e = ws->f;
if (htc->pipeline_b != NULL) { if (htc->pipeline_b != NULL) {
AN(htc->pipeline_e); AN(htc->pipeline_e);
// assert(WS_Inside(ws, htc->pipeline_b, htc->pipeline_e)); // assert(WS_Inside(ws, htc->pipeline_b, htc->pipeline_e));
l = htc->pipeline_e - htc->pipeline_b; l = htc->pipeline_e - htc->pipeline_b;
assert(l > 0); assert(l > 0);
assert(l <= ws->r - htc->rxbuf_b); assert(l <= r);
memmove(htc->rxbuf_b, htc->pipeline_b, l); memmove(htc->rxbuf_b, htc->pipeline_b, l);
htc->rxbuf_e += l; htc->rxbuf_e += l;
htc->pipeline_b = NULL; htc->pipeline_b = NULL;
...@@ -415,7 +415,7 @@ ses_handle(struct waited *wp, enum wait_event ev, vtim_real now) ...@@ -415,7 +415,7 @@ ses_handle(struct waited *wp, enum wait_event ev, vtim_real now)
CAST_OBJ_NOTNULL(sp, wp->priv1, SESS_MAGIC); CAST_OBJ_NOTNULL(sp, wp->priv1, SESS_MAGIC);
CAST_OBJ_NOTNULL(xp, (const void*)wp->priv2, TRANSPORT_MAGIC); CAST_OBJ_NOTNULL(xp, (const void*)wp->priv2, TRANSPORT_MAGIC);
AN(wp->priv2); AN(wp->priv2);
assert((void *)sp->ws->f == wp); assert(WS_Reservation(sp->ws) == wp);
wp->magic = 0; wp->magic = 0;
wp = NULL; wp = NULL;
...@@ -434,7 +434,7 @@ ses_handle(struct waited *wp, enum wait_event ev, vtim_real now) ...@@ -434,7 +434,7 @@ ses_handle(struct waited *wp, enum wait_event ev, vtim_real now)
CHECK_OBJ_NOTNULL(pp, POOL_MAGIC); CHECK_OBJ_NOTNULL(pp, POOL_MAGIC);
/* SES_Wait() guarantees the next will not assert. */ /* SES_Wait() guarantees the next will not assert. */
assert(sizeof *tp <= WS_ReserveSize(sp->ws, sizeof *tp)); assert(sizeof *tp <= WS_ReserveSize(sp->ws, sizeof *tp));
tp = (void*)sp->ws->f; tp = WS_Reservation(sp->ws);
tp->func = xp->unwait; tp->func = xp->unwait;
tp->priv = sp; tp->priv = sp;
if (Pool_Task(pp, tp, TASK_QUEUE_REQ)) if (Pool_Task(pp, tp, TASK_QUEUE_REQ))
......
...@@ -234,10 +234,10 @@ VRY_Prep(struct req *req) ...@@ -234,10 +234,10 @@ VRY_Prep(struct req *req)
AZ(req->vary_e); AZ(req->vary_e);
(void)WS_ReserveAll(req->ws); (void)WS_ReserveAll(req->ws);
} else { } else {
AN(req->ws->r); AN(WS_Reservation(req->ws));
} }
req->vary_b = (void*)req->ws->f; req->vary_b = WS_Reservation(req->ws);
req->vary_e = (void*)req->ws->r; req->vary_e = req->vary_b + WS_ReservationSize(req->ws);
if (req->vary_b + 2 < req->vary_e) if (req->vary_b + 2 < req->vary_e)
req->vary_b[2] = '\0'; req->vary_b[2] = '\0';
} }
......
...@@ -366,7 +366,7 @@ VRT_String(struct ws *ws, const char *h, const char *p, va_list ap) ...@@ -366,7 +366,7 @@ VRT_String(struct ws *ws, const char *h, const char *p, va_list ap)
va_list aq; va_list aq;
u = WS_ReserveAll(ws); u = WS_ReserveAll(ws);
e = b = ws->f; e = b = WS_Reservation(ws);
e += u; e += u;
va_copy(aq, ap); va_copy(aq, ap);
...@@ -422,7 +422,7 @@ VRT_String(struct ws *ws, const char *h, const char *p, va_list ap) ...@@ -422,7 +422,7 @@ VRT_String(struct ws *ws, const char *h, const char *p, va_list ap)
return (NULL); return (NULL);
} }
e = b; e = b;
b = ws->f; b = WS_Reservation(ws);
WS_Release(ws, e - b); WS_Release(ws, e - b);
return (b); return (b);
} }
...@@ -710,7 +710,7 @@ VRT_IP_string(VRT_CTX, VCL_IP ip) ...@@ -710,7 +710,7 @@ VRT_IP_string(VRT_CTX, VCL_IP ip)
WS_Release(ctx->ws, 0); WS_Release(ctx->ws, 0);
return (NULL); return (NULL);
} }
p = ctx->ws->f; p = WS_Reservation(ctx->ws);
VTCP_name(ip, p, len, NULL, 0); VTCP_name(ip, p, len, NULL, 0);
WS_Release(ctx->ws, strlen(p) + 1); WS_Release(ctx->ws, strlen(p) + 1);
return (p); return (p);
......
...@@ -130,7 +130,7 @@ VRT_regsub(VRT_CTX, int all, const char *str, void *re, ...@@ -130,7 +130,7 @@ VRT_regsub(VRT_CTX, int all, const char *str, void *re,
} }
u = WS_ReserveAll(ctx->ws); u = WS_ReserveAll(ctx->ws);
res_e = res_b = b0 = ctx->ws->f; res_e = res_b = b0 = WS_Reservation(ctx->ws);
res_e += u; res_e += u;
do { do {
......
...@@ -246,9 +246,9 @@ Pool_Task_Arg(struct worker *wrk, enum task_prio prio, task_func_t *func, ...@@ -246,9 +246,9 @@ Pool_Task_Arg(struct worker *wrk, enum task_prio prio, task_func_t *func,
} }
AZ(wrk2->task->func); AZ(wrk2->task->func);
assert(arg_len <= WS_ReserveSize(wrk2->aws, arg_len)); assert(arg_len <= WS_ReserveSize(wrk2->aws, arg_len));
memcpy(wrk2->aws->f, arg, arg_len); memcpy(WS_Reservation(wrk2->aws), arg, arg_len);
wrk2->task->func = func; wrk2->task->func = func;
wrk2->task->priv = wrk2->aws->f; wrk2->task->priv = WS_Reservation(wrk2->aws);
Lck_Unlock(&pp->mtx); Lck_Unlock(&pp->mtx);
// see signaling_note at the top for explanation // see signaling_note at the top for explanation
if (retval) if (retval)
......
...@@ -112,7 +112,7 @@ V1L_Open(struct worker *wrk, struct ws *ws, int *fd, struct vsl_log *vsl, ...@@ -112,7 +112,7 @@ V1L_Open(struct worker *wrk, struct ws *ws, int *fd, struct vsl_log *vsl,
u = IOV_MAX; u = IOV_MAX;
if (niov != 0 && u > niov) if (niov != 0 && u > niov)
u = niov; u = niov;
v1l->iov = (void*)ws->f; v1l->iov = WS_Reservation(ws);
v1l->siov = u; v1l->siov = u;
v1l->ciov = u; v1l->ciov = u;
v1l->wfd = fd; v1l->wfd = fd;
......
...@@ -183,7 +183,7 @@ h2h_decode_init(const struct h2_sess *h2) ...@@ -183,7 +183,7 @@ h2h_decode_init(const struct h2_sess *h2)
* space. Require non-zero size. * space. Require non-zero size.
*/ */
XXXAN(d->out_l); XXXAN(d->out_l);
d->out = h2->new_req->http->ws->f; d->out = WS_Reservation(h2->new_req->http->ws);
d->reset = d->out; d->reset = d->out;
} }
......
...@@ -76,7 +76,7 @@ vmod_updown(VRT_CTX, int up, VCL_STRANDS s) ...@@ -76,7 +76,7 @@ vmod_updown(VRT_CTX, int up, VCL_STRANDS s)
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
u = WS_ReserveAll(ctx->ws); u = WS_ReserveAll(ctx->ws);
e = b = ctx->ws->f; e = b = WS_Reservation(ctx->ws);
e += u; e += u;
for (i = 0; i < s->n && b < e; i++) { for (i = 0; i < s->n && b < e; i++) {
p = s->p[i]; p = s->p[i];
...@@ -96,7 +96,7 @@ vmod_updown(VRT_CTX, int up, VCL_STRANDS s) ...@@ -96,7 +96,7 @@ vmod_updown(VRT_CTX, int up, VCL_STRANDS s)
return (NULL); return (NULL);
} else { } else {
e = b; e = b;
b = ctx->ws->f; b = WS_Reservation(ctx->ws);
WS_Release(ctx->ws, e - b); WS_Release(ctx->ws, e - b);
return (b); return (b);
} }
......
...@@ -81,7 +81,7 @@ vmod_querysort(VRT_CTX, VCL_STRING url) ...@@ -81,7 +81,7 @@ vmod_querysort(VRT_CTX, VCL_STRING url)
return (url); return (url);
u = WS_ReserveLumps(ctx->ws, sizeof(const char **)); u = WS_ReserveLumps(ctx->ws, sizeof(const char **));
pp = (const char**)(void*)(ctx->ws->f); pp = WS_Reservation(ctx->ws);
if (u < 4) { if (u < 4) {
WS_Release(ctx->ws, 0); WS_Release(ctx->ws, 0);
WS_MarkOverflow(ctx->ws); WS_MarkOverflow(ctx->ws);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment