apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jor...@apache.org
Subject cvs commit: apr-util/misc apr_rmm.c
Date Wed, 07 Jul 2004 17:01:13 GMT
jorton      2004/07/07 10:01:13

  Modified:    test     testrmm.c
               misc     apr_rmm.c
  Log:
  * misc/apr_rmm.c: Ensure allocated blocks use default address
  alignment by using aligned structure sizes throughout.
  
  * test/testrmm.c (test_rmm): Check for address alignment.
  
  PR: 29873
  
  Revision  Changes    Path
  1.7       +19 -1     apr-util/test/testrmm.c
  
  Index: testrmm.c
  ===================================================================
  RCS file: /home/cvs/apr-util/test/testrmm.c,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -d -w -u -r1.6 -r1.7
  --- testrmm.c	20 Mar 2004 21:30:19 -0000	1.6
  +++ testrmm.c	7 Jul 2004 17:01:13 -0000	1.7
  @@ -51,7 +51,7 @@
       }
   
       /* We're going to want 10 blocks of data from our target rmm. */
  -    size = SHARED_SIZE + apr_rmm_overhead_get(FRAG_COUNT);
  +    size = SHARED_SIZE + apr_rmm_overhead_get(FRAG_COUNT + 1);
       printf("Creating anonymous shared memory (%"
              APR_SIZE_T_FMT " bytes).....", size); 
       rv = apr_shm_create(&shm, size, NULL, pool);
  @@ -87,6 +87,24 @@
       else {
           return APR_EGENERAL;  
       }
  +
  +    printf("Checking each fragment for address alignment.....");
  +    for (i = 0; i < FRAG_COUNT; i++) {
  +        char *c = apr_rmm_addr_get(rmm, off[i]);
  +        apr_size_t sc = (apr_size_t)c;
  +
  +        if (off[i] == 0) {
  +            printf("allocation failed for offset %d\n", i);
  +            return APR_ENOMEM;
  +        }
  +
  +        if (sc & 7) {
  +            printf("Bad alignment for fragment %d; %p not %p!\n",
  +                   i, c, (void *)APR_ALIGN_DEFAULT((apr_size_t)c));
  +            return APR_EGENERAL;
  +        }
  +    }
  +    fprintf(stdout, "OK\n");   
       
       printf("Setting each fragment to a unique value..........");
       for (i = 0; i < FRAG_COUNT; i++) {
  
  
  
  1.25      +15 -12    apr-util/misc/apr_rmm.c
  
  Index: apr_rmm.c
  ===================================================================
  RCS file: /home/cvs/apr-util/misc/apr_rmm.c,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -d -w -u -r1.24 -r1.25
  --- apr_rmm.c	20 Mar 2004 21:30:19 -0000	1.24
  +++ apr_rmm.c	7 Jul 2004 17:01:13 -0000	1.25
  @@ -33,6 +33,9 @@
       apr_rmm_off_t /* rmm_block_t */ firstfree;
   } rmm_hdr_block_t;
   
  +#define RMM_HDR_BLOCK_SIZE (APR_ALIGN_DEFAULT(sizeof(rmm_hdr_block_t)))
  +#define RMM_BLOCK_SIZE (APR_ALIGN_DEFAULT(sizeof(rmm_block_t)))
  +
   struct apr_rmm_t {
       apr_pool_t *p;
       rmm_hdr_block_t *base;
  @@ -87,7 +90,7 @@
           next = blk->next;
       }
   
  -    if (bestsize > sizeof(rmm_block_t) + size) {
  +    if (bestsize > RMM_BLOCK_SIZE + size) {
           struct rmm_block_t *blk = (rmm_block_t*)((char*)rmm->base + best);
           struct rmm_block_t *new = (rmm_block_t*)((char*)rmm->base + best + size);
   
  @@ -205,7 +208,7 @@
   
       (*rmm)->base->abssize = size;
       (*rmm)->base->firstused = 0;
  -    (*rmm)->base->firstfree = sizeof(rmm_hdr_block_t);
  +    (*rmm)->base->firstfree = RMM_HDR_BLOCK_SIZE;
   
       blk = (rmm_block_t *)((char*)base + (*rmm)->base->firstfree);
   
  @@ -281,15 +284,15 @@
   {
       apr_rmm_off_t this;
       
  -    reqsize = APR_ALIGN_DEFAULT(reqsize);
  +    reqsize = APR_ALIGN_DEFAULT(reqsize) + RMM_BLOCK_SIZE;
   
       APR_ANYLOCK_LOCK(&rmm->lock);
   
  -    this = find_block_of_size(rmm, reqsize + sizeof(rmm_block_t));
  +    this = find_block_of_size(rmm, reqsize);
   
       if (this) {
           move_block(rmm, this, 0);
  -        this += sizeof(rmm_block_t);
  +        this += RMM_BLOCK_SIZE;
       }
   
       APR_ANYLOCK_UNLOCK(&rmm->lock);
  @@ -300,16 +303,16 @@
   {
       apr_rmm_off_t this;
           
  -    reqsize = APR_ALIGN_DEFAULT(reqsize);
  +    reqsize = APR_ALIGN_DEFAULT(reqsize) + RMM_BLOCK_SIZE;
   
       APR_ANYLOCK_LOCK(&rmm->lock);
   
  -    this = find_block_of_size(rmm, reqsize + sizeof(rmm_block_t));
  +    this = find_block_of_size(rmm, reqsize);
   
       if (this) {
           move_block(rmm, this, 0);
  -        this += sizeof(rmm_block_t);
  -        memset((char*)rmm->base + this, 0, reqsize);
  +        this += RMM_BLOCK_SIZE;
  +        memset((char*)rmm->base + this, 0, reqsize - RMM_BLOCK_SIZE);
       }
   
       APR_ANYLOCK_UNLOCK(&rmm->lock);
  @@ -353,11 +356,11 @@
       /* A little sanity check is always healthy, especially here.
        * If we really cared, we could make this compile-time
        */
  -    if (this < sizeof(rmm_hdr_block_t) + sizeof(rmm_block_t)) {
  +    if (this < RMM_HDR_BLOCK_SIZE + RMM_BLOCK_SIZE) {
           return APR_EINVAL;
       }
   
  -    this -= sizeof(rmm_block_t);
  +    this -= RMM_BLOCK_SIZE;
   
       blk = (rmm_block_t*)((char*)rmm->base + this);
   
  @@ -413,5 +416,5 @@
   
   APU_DECLARE(apr_size_t) apr_rmm_overhead_get(int n) 
   {
  -    return sizeof(rmm_hdr_block_t) + n * sizeof(rmm_block_t);
  +    return RMM_HDR_BLOCK_SIZE + n * RMM_BLOCK_SIZE;
   }
  
  
  

Mime
View raw message