Changeset 333

Show
Ignore:
Timestamp:
08/20/07 18:40:16 (9 months ago)
Author:
bart
Message:

Add code that checks the shared memory chunks if needed to make sure no data

was written past the boundary. Change #undef MM_CHECK in mm.c to
#define MM_CHECK

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • eaccelerator/trunk/ChangeLog

    r332 r333  
    2020        * Rewrite the fixup_* functions so they no longer use the EAG(mem) global. 
    2121        * Rewrite store_* functions so they no longer use the EAG(mem) global. 
     22        * Add code that checks the shared memory chunks if needed to make sure 
     23          no data was written past the boundary. Change #undef MM_CHECK in mm.c 
     24          to #define MM_CHECK 
    2225 
    23262007-08-19  Bart Vanbrabant <bart.vanbrabant at zoeloelip.be> 
  • eaccelerator/trunk/eaccelerator.c

    r330 r333  
    749749      p->removed  = 1; 
    750750    } 
     751    mm_check_mem(p);  
    751752    return p; 
    752753  } 
     
    800801  int ret = 0; 
    801802  int size = 0; 
     803  void *data = NULL; 
    802804 
    803805  zend_try { 
     
    815817  EACCELERATOR_UNPROTECT(); 
    816818  EAG(mem) = eaccelerator_malloc(size); 
     819  data = EAG(mem); 
    817820  if (EAG(mem) == NULL) { 
    818821    EAG(mem) = eaccelerator_malloc2(size TSRMLS_CC); 
     
    825828  if (EAG(mem)) { 
    826829    memset(EAG(mem), 0, size); 
    827     p = eaccelerator_store_int(key, len, op_array, f, c TSRMLS_CC); 
     830                p = (ea_cache_entry *)EAG(mem); 
     831    eaccelerator_store_int(p, key, len, op_array, f, c TSRMLS_CC); 
    828832    p->mtime    = buf->st_mtime; 
    829833    p->filesize = buf->st_size; 
     
    846850      EACCELERATOR_PROTECT(); 
    847851      ret = 1; 
     852      mm_check_mem(data); 
    848853    } else { 
    849854      ret =  hash_add_file(p TSRMLS_CC); 
  • eaccelerator/trunk/mm.c

    r301 r333  
    6767#endif 
    6868 
     69#undef MM_CHECK  
     70#define MM_PATTERN  0xdeadbeef 
     71 
    6972#if defined(MM_SHM_MMAP_FILE) || defined(MM_SHM_MMAP_ZERO) || defined(MM_SHM_MMAP_ANON) || defined(MM_SHM_MMAP_POSIX) || defined(HAVE_MPROTECT) 
    7073#  include <sys/mman.h> 
     
    10661069    mm_mem_head* x = NULL; 
    10671070    size_t realsize = (size_t)MM_ALIGN(MM_SIZE(size)); 
     1071#if MM_CHECK 
     1072    realsize += (size_t)MM_ALIGN(sizeof(int)); 
     1073#endif 
    10681074    if (realsize <= mm->available) { 
    10691075      /* Search for free bucket */ 
     
    10841090          break; 
    10851091        } else if (p->size > realsize && (best == NULL || best->size > p->size)) { 
    1086           /* Found best bucket (smallest bucket with the grater size) */ 
     1092          /* Found best bucket (smallest bucket with the bigger size) */ 
    10871093          best = p; 
    10881094          best_prev = q; 
     
    11191125    } 
    11201126    if (x != NULL) { 
     1127#ifdef MM_CHECK 
     1128      *(int *)((char *)x + realsize - (size_t)MM_ALIGN(sizeof(int))) = MM_PATTERN; 
     1129#endif 
    11211130      return HEAD_TO_PTR(x); 
    11221131    } 
     
    13191328} 
    13201329 
     1330#if defined(MM_CHECK) && !(defined(MM_TEST_SHM) || defined(MM_TEST_SEM)) 
     1331void mm_check_mem(void *x) { 
     1332  mm_mem_head *p = PTR_TO_HEAD(x); 
     1333  if (*((unsigned int *)((char *)p + p->size - (size_t)MM_ALIGN(sizeof(int)))) != MM_PATTERN) { 
     1334    ea_debug_error("[EACCELERATOR] Corrupted memory detected\n"); 
     1335  } 
     1336} 
     1337#else 
     1338void mm_check_mem(void *x) {} 
     1339#endif 
     1340 
    13211341#ifdef MM_TEST_SHM 
    13221342int main() { 
  • eaccelerator/trunk/mm.h

    r286 r333  
    6767const char* mm_shm_type(); 
    6868const char* mm_sem_type(); 
     69void mm_check_mem(void *x); 
    6970 
    7071#define MM_PROT_NONE  1