From afa7a6727f2515076443a935af011367a7643c09 Mon Sep 17 00:00:00 2001 From: Jim Jagielski Date: Tue, 11 Jan 2011 17:30:59 +0000 Subject: [PATCH] revert... git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1057748 13f79535-47bb-0310-9956-ffa450edef68 --- modules/slotmem/mod_slotmem_shm.c | 100 ++++++++++++++---------------- 1 file changed, 45 insertions(+), 55 deletions(-) diff --git a/modules/slotmem/mod_slotmem_shm.c b/modules/slotmem/mod_slotmem_shm.c index 8c12142bf6..e3c688fc57 100644 --- a/modules/slotmem/mod_slotmem_shm.c +++ b/modules/slotmem/mod_slotmem_shm.c @@ -42,8 +42,7 @@ #endif #endif -#define AP_SLOTMEM_IS_PREGRAB(t) (t->slot.type & AP_SLOTMEM_TYPE_PREGRAB) -#define PADME(x) ((((x) / sizeof(void *)) + 1 ) * sizeof(void *)) +#define AP_SLOTMEM_IS_PREGRAB(t) (t->desc.type & AP_SLOTMEM_TYPE_PREGRAB) /* The description of the slots to reuse the slotmem */ typedef struct { @@ -58,16 +57,14 @@ struct ap_slotmem_instance_t { void *base; /* data set start */ apr_pool_t *gpool; /* per segment global pool */ char *inuse; /* in-use flag table*/ - sharedslotdesc_t slot; /* per slot desc */ + sharedslotdesc_t desc; /* per slot desc */ struct ap_slotmem_instance_t *next; /* location of next allocated segment */ }; /* * Memory layout: - * sharedslotdesc_t [padding] | slots [padding] | isuse array [padding] - * - * We pad to ensure the pointer conversions don't mangle things + * sharedslotdesc_t | slots | isuse array */ /* global pool and list of slotmem we are handling */ @@ -157,8 +154,8 @@ static void store_slotmem(ap_slotmem_instance_t *slotmem) if (rv != APR_SUCCESS) { return; } - nbytes = (slotmem->slot.size * slotmem->slot.num) + - (slotmem->slot.num * sizeof(char)); + nbytes = (slotmem->desc.size * slotmem->desc.num) + + (slotmem->desc.num * sizeof(char)); apr_file_write(fp, slotmem->base, &nbytes); apr_file_close(fp); } @@ -221,7 +218,7 @@ static apr_status_t slotmem_doall(ap_slotmem_instance_t *mem, void *data, apr_pool_t *pool) { unsigned int i; - char *ptr; + void *ptr; char *inuse; apr_status_t retval = APR_SUCCESS; @@ -231,14 +228,14 @@ static apr_status_t slotmem_doall(ap_slotmem_instance_t *mem, ptr = mem->base; inuse = mem->inuse; - for (i = 0; i < mem->slot.num; i++, inuse++) { + for (i = 0; i < mem->desc.num; i++, inuse++) { if (!AP_SLOTMEM_IS_PREGRAB(mem) || (AP_SLOTMEM_IS_PREGRAB(mem) && *inuse)) { retval = func((void *) ptr, data, pool); if (retval != APR_SUCCESS) break; } - ptr += mem->slot.size; + ptr += mem->desc.size; } return retval; } @@ -249,23 +246,17 @@ static apr_status_t slotmem_create(ap_slotmem_instance_t **new, ap_slotmem_type_t type, apr_pool_t *pool) { /* void *slotmem = NULL; */ - char *ptr; - sharedslotdesc_t slot; + void *ptr; + sharedslotdesc_t desc; ap_slotmem_instance_t *res; ap_slotmem_instance_t *next = globallistmem; const char *fname; apr_shm_t *shm; - apr_size_t basesize; - apr_size_t descsize = PADME(sizeof(sharedslotdesc_t)); - apr_size_t inusesize = item_num * sizeof(char); - apr_size_t size; + apr_size_t basesize = (item_size * item_num); + apr_size_t size = sizeof(sharedslotdesc_t) + + (item_num * sizeof(char)) + basesize; apr_status_t rv; - item_size = PADME(item_size); - inusesize = PADME(inusesize); - basesize = (item_size * item_num); - size = descsize + basesize + inusesize; - if (gpool == NULL) return APR_ENOSHMAVAIL; if (name) { @@ -309,15 +300,15 @@ static apr_status_t slotmem_create(ap_slotmem_instance_t **new, return APR_EINVAL; } ptr = apr_shm_baseaddr_get(shm); - memcpy(&slot, ptr, sizeof(slot)); - if (slot.size != item_size || slot.num != item_num) { + memcpy(&desc, ptr, sizeof(desc)); + if (desc.size != item_size || desc.num != item_num) { apr_shm_detach(shm); return APR_EINVAL; } - ptr = ptr + descsize; + ptr = ptr + sizeof(desc); } else { - apr_size_t dsize = size - descsize; + apr_size_t dsize = size - sizeof(sharedslotdesc_t); if (name && name[0] != ':') { apr_shm_remove(fname, gpool); rv = apr_shm_create(&shm, size, fname, gpool); @@ -338,11 +329,11 @@ static apr_status_t slotmem_create(ap_slotmem_instance_t **new, unixd_set_shm_perms(fname); } ptr = apr_shm_baseaddr_get(shm); - slot.size = item_size; - slot.num = item_num; - slot.type = type; - memcpy(ptr, &slot, sizeof(slot)); - ptr = ptr + descsize; + desc.size = item_size; + desc.num = item_num; + desc.type = type; + memcpy(ptr, &desc, sizeof(desc)); + ptr = ptr + sizeof(desc); memset(ptr, 0, dsize); /* * TODO: Error check the below... What error makes @@ -358,7 +349,7 @@ static apr_status_t slotmem_create(ap_slotmem_instance_t **new, res->name = apr_pstrdup(gpool, fname); res->shm = shm; res->base = ptr; - res->slot = slot; + res->desc = desc; res->gpool = gpool; res->next = NULL; res->inuse = ptr + basesize; @@ -378,13 +369,12 @@ static apr_status_t slotmem_attach(ap_slotmem_instance_t **new, unsigned int *item_num, apr_pool_t *pool) { /* void *slotmem = NULL; */ - char *ptr; + void *ptr; ap_slotmem_instance_t *res; ap_slotmem_instance_t *next = globallistmem; - sharedslotdesc_t slot; + sharedslotdesc_t desc; const char *fname; apr_shm_t *shm; - apr_size_t descsize = PADME(sizeof(sharedslotdesc_t)); apr_status_t rv; if (gpool == NULL) { @@ -408,8 +398,8 @@ static apr_status_t slotmem_attach(ap_slotmem_instance_t **new, if (strcmp(next->name, fname) == 0) { /* we already have it */ *new = next; - *item_size = next->slot.size; - *item_num = next->slot.num; + *item_size = next->desc.size; + *item_num = next->desc.num; return APR_SUCCESS; } if (!next->next) { @@ -427,8 +417,8 @@ static apr_status_t slotmem_attach(ap_slotmem_instance_t **new, /* Read the description of the slotmem */ ptr = apr_shm_baseaddr_get(shm); - memcpy(&slot, ptr, sizeof(slot)); - ptr = ptr + descsize; + memcpy(&desc, ptr, sizeof(desc)); + ptr = ptr + sizeof(desc); /* For the chained slotmem stuff */ res = (ap_slotmem_instance_t *) apr_pcalloc(gpool, @@ -436,9 +426,9 @@ static apr_status_t slotmem_attach(ap_slotmem_instance_t **new, res->name = apr_pstrdup(gpool, fname); res->shm = shm; res->base = ptr; - res->slot = slot; + res->desc = desc; res->gpool = gpool; - res->inuse = ptr + (slot.size * slot.num); + res->inuse = ptr + (desc.size * desc.num); res->next = NULL; if (globallistmem == NULL) { globallistmem = res; @@ -448,24 +438,24 @@ static apr_status_t slotmem_attach(ap_slotmem_instance_t **new, } *new = res; - *item_size = slot.size; - *item_num = slot.num; + *item_size = desc.size; + *item_num = desc.num; return APR_SUCCESS; } static apr_status_t slotmem_dptr(ap_slotmem_instance_t *slot, unsigned int id, void **mem) { - char *ptr; + void *ptr; if (!slot) { return APR_ENOSHMAVAIL; } - if (id >= slot->slot.num) { + if (id >= slot->desc.num) { return APR_ENOSHMAVAIL; } - ptr = (char *) slot->base + slot->slot.size * id; + ptr = slot->base + slot->desc.size * id; if (!ptr) { return APR_ENOSHMAVAIL; } @@ -485,14 +475,14 @@ static apr_status_t slotmem_get(ap_slotmem_instance_t *slot, unsigned int id, } inuse = slot->inuse + id; - if (id >= slot->slot.num || (AP_SLOTMEM_IS_PREGRAB(slot) && !*inuse)) { + if (id >= slot->desc.num || (AP_SLOTMEM_IS_PREGRAB(slot) && !*inuse)) { return APR_NOTFOUND; } ret = slotmem_dptr(slot, id, &ptr); if (ret != APR_SUCCESS) { return ret; } - memcpy(dest, (char *)ptr, dest_len); /* bounds check? */ + memcpy(dest, ptr, dest_len); /* bounds check? */ return APR_SUCCESS; } @@ -508,25 +498,25 @@ static apr_status_t slotmem_put(ap_slotmem_instance_t *slot, unsigned int id, } inuse = slot->inuse + id; - if (id >= slot->slot.num || (AP_SLOTMEM_IS_PREGRAB(slot) && !*inuse)) { + if (id >= slot->desc.num || (AP_SLOTMEM_IS_PREGRAB(slot) && !*inuse)) { return APR_NOTFOUND; } ret = slotmem_dptr(slot, id, &ptr); if (ret != APR_SUCCESS) { return ret; } - memcpy((char *)ptr, src, src_len); /* bounds check? */ + memcpy(ptr, src, src_len); /* bounds check? */ return APR_SUCCESS; } static unsigned int slotmem_num_slots(ap_slotmem_instance_t *slot) { - return slot->slot.num; + return slot->desc.num; } static apr_size_t slotmem_slot_size(ap_slotmem_instance_t *slot) { - return slot->slot.size; + return slot->desc.size; } /* @@ -544,12 +534,12 @@ static apr_status_t slotmem_grab(ap_slotmem_instance_t *slot, unsigned int *id) inuse = slot->inuse; - for (i = 0; i < slot->slot.num; i++, inuse++) { + for (i = 0; i < slot->desc.num; i++, inuse++) { if (!*inuse) { break; } } - if (i >= slot->slot.num) { + if (i >= slot->desc.num) { return APR_ENOSHMAVAIL; } *inuse = 1; @@ -568,7 +558,7 @@ static apr_status_t slotmem_release(ap_slotmem_instance_t *slot, inuse = slot->inuse; - if (id >= slot->slot.num || !inuse[id] ) { + if (id >= slot->desc.num || !inuse[id] ) { return APR_NOTFOUND; } inuse[id] = 0; -- 2.40.0