Changeset 79


Ignore:
Timestamp:
2006-06-16T02:50:51+02:00 (9 years ago)
Author:
moo
Message:

fix messy XCACHE_MAP_FAILED checking

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/mmap.c

    r61 r79  
    1818#else 
    1919#   include <unistd.h> 
     20/* make sure to mark(change) it to NULL to keep consistent */ 
    2021#   define XCACHE_MAP_FAILED MAP_FAILED 
    2122#endif 
     
    192193    } 
    193194 
    194     ro_ok = 0; 
     195    /* {{{ readonly protection, mmap it readonly and check if ptr_ro works */ 
    195196    if (readonly_protection) { 
     197        ro_ok = 0; 
     198 
    196199#ifdef ZEND_WIN32 
    197200        shm->hmap_ro = XCacheCreateFileMapping(size, PAGE_READONLY, shm->name); 
     
    200203        shm->ptr_ro = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0); 
    201204#endif 
     205        if (shm->ptr_ro == XCACHE_MAP_FAILED) { 
     206            shm->ptr_ro = NULL; 
     207        } 
    202208        romem = shm->ptr_ro; 
    203209 
    204         /* {{{ check if ptr_ro works */ 
    205210        do { 
    206             if (shm->ptr_ro == XCACHE_MAP_FAILED || shm->ptr_ro == shm->ptr) { 
     211            if (romem == NULL || romem == shm->ptr) { 
    207212                break; 
    208213            } 
     
    217222            ro_ok = 1; 
    218223        } while (0); 
    219     } 
    220  
    221     if (ro_ok) { 
    222         shm->diff = PTR_SUB(shm->ptr_ro, (char *) shm->ptr); 
    223         assert(abs(shm->diff) >= size); 
    224     } 
    225     else { 
    226         if (shm->ptr_ro != XCACHE_MAP_FAILED) { 
    227             munmap(shm->ptr_ro, size); 
    228         } 
    229         shm->ptr_ro = NULL; 
    230         shm->diff = 0; 
    231     } 
     224 
     225        if (ro_ok) { 
     226            shm->diff = PTR_SUB(shm->ptr_ro, (char *) shm->ptr); 
     227            /* no overlap */ 
     228            assert(abs(shm->diff) >= size); 
     229        } 
     230        else { 
     231            if (shm->ptr_ro) { 
     232                munmap(shm->ptr_ro, size); 
     233            } 
     234#ifdef ZEND_WIN32 
     235            if (shm->hmap_ro) { 
     236                CloseHandle(shm->hmap_ro); 
     237            } 
     238#endif 
     239            shm->ptr_ro = NULL; 
     240            shm->diff = 0; 
     241        } 
     242    } 
     243 
    232244    /* }}} */ 
    233245 
Note: See TracChangeset for help on using the changeset viewer.