Changeset 14676
- Timestamp:
- Aug 27, 2007, 1:14:35 PM (19 years ago)
- Location:
- trunk/psLib/src/sys
- Files:
-
- 3 edited
-
psAssert.h (modified) (1 diff)
-
psMemory.c (modified) (3 diffs)
-
psMemory.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sys/psAssert.h
r12596 r14676 20 20 } 21 21 22 // Ensure this is a psLib pointer , by checking for the memblock bounds.23 #define PS_ASSERT_PTR( NAME, RVAL) \22 // Ensure this is a psLib pointer 23 #define PS_ASSERT_PTR(PTR, RVAL) \ 24 24 { \ 25 if (NAME == NULL) return(RVAL); \ 26 psMemBlock *mb = (psMemBlock*)(NAME) - 1; \ 27 if (mb->startblock != P_PS_MEMMAGIC || mb->endblock != P_PS_MEMMAGIC || \ 28 *(psU32 *)((char *)(mb + 1) + mb->userMemorySize) != P_PS_MEMMAGIC) { \ 25 if (PTR == NULL) return RVAL; \ 26 if (!psMemIsAlloced(PTR)) { \ 29 27 psError(PS_ERR_MEMORY_CORRUPTION, false, \ 30 "Error: Pointer %sis corrupted or not on the PS memory system.", \31 #NAME); \32 return (RVAL); \28 "Error: Pointer %p is corrupted or not on the PS memory system.", \ 29 PTR); \ 30 return RVAL; \ 33 31 } \ 34 32 } -
trunk/psLib/src/sys/psMemory.c
r12886 r14676 10 10 * @author Joshua Hoblitt, University of Hawaii 11 11 * 12 * @version $Revision: 1.9 6$ $Name: not supported by cvs2svn $13 * @date $Date: 2007-0 4-18 19:38:10$12 * @version $Revision: 1.97 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2007-08-27 23:14:35 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 374 374 MUTEX_UNLOCK(&memBlockListMutex); 375 375 PS_MEM_ABORT(__func__, "Detected memory corruption"); 376 return nbad;377 376 } 378 377 } … … 383 382 384 383 return nbad; 384 } 385 386 bool p_psMemIsAlloced(const char *file, 387 unsigned int lineno, 388 const char *func, 389 const void *ptr) 390 { 391 // if ptr is a psAlloc()'d memory, find the actual address of the memBlock 392 psMemBlock *addr = ((psMemBlock *)ptr) - 1; 393 394 // get exclusive access to the memBlock list to avoid it changing on us 395 // while we use it. 396 MUTEX_LOCK(&memBlockListMutex); 397 398 // loop through the linked list of memBlocks looking for a matching pointer 399 for (psMemBlock *memBlock = lastMemBlockAllocated; memBlock != NULL; memBlock = memBlock->nextBlock) { 400 if (memBlock == addr) { 401 // we found the memBlock 402 HANDLE_BAD_BLOCK(memBlock, file, lineno, func); 403 404 MUTEX_UNLOCK(&memBlockListMutex); 405 return true; 406 } 407 } 408 409 // release the lock on the memblock list 410 MUTEX_UNLOCK(&memBlockListMutex); 411 412 return false; 385 413 } 386 414 -
trunk/psLib/src/sys/psMemory.h
r12380 r14676 15 15 * @ingroup MemoryManagement 16 16 * 17 * @version $Revision: 1. 69$ $Name: not supported by cvs2svn $18 * @date $Date: 2007-0 3-09 20:11:04$17 * @version $Revision: 1.70 $ $Name: not supported by cvs2svn $ 18 * @date $Date: 2007-08-27 23:14:35 $ 19 19 * 20 20 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 407 407 #endif // ifdef DOXYGEN 408 408 409 /** Checks to see if a pointer is to a region of memory that was allocated by psAlloc(). 410 * @return bool 411 * 412 */ 413 #ifdef DOXYGEN 414 bool psMemIsAlloced( 415 const void *ptr ///< pointer to memory 416 ); 417 #else // ifdef DOXYGEN 418 bool p_psMemIsAlloced( 419 const char *file, 420 unsigned int lineno, 421 const char *func, 422 const void *ptr 423 ); 424 #ifndef SWIG 425 #define psMemIsAlloced(ptr) \ 426 p_psMemIsAlloced(__FILE__, __LINE__, __func__, ptr) 427 #endif // ifndef SWIG 428 #endif // ifdef DOXYGEN 429 409 430 410 431 /** Return reference counter
Note:
See TracChangeset
for help on using the changeset viewer.
