DSMCC
15.3.1
|
00001 /******************************************************************************* 00002 * Copyright © 2014 The DTVKit Open Software Foundation Ltd (www.dtvkit.org) 00003 * Copyright © 2004 Ocean Blue Software Ltd 00004 * 00005 * This file is part of a DTVKit Software Component 00006 * You are permitted to copy, modify or distribute this file subject to the terms 00007 * of the DTVKit 1.0 Licence which can be found in licence.txt or at www.dtvkit.org 00008 * 00009 * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 00010 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES 00011 * OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. 00012 * 00013 * If you or your organisation is not a member of DTVKit then you have access 00014 * to this source code outside of the terms of the licence agreement 00015 * and you are expected to delete this and any associated files immediately. 00016 * Further information on DTVKit, membership and terms can be found at www.dtvkit.org 00017 *******************************************************************************/ 00024 #ifndef _CLDSMMEMMGRAPI_H_ 00025 #define _CLDSMMEMMGRAPI_H_ 00026 00027 00028 /*-------------------------------- Includes ----------------------------------*/ 00029 00030 #include "techtype.h" 00031 00032 /*-------------------------------- Defines -----------------------------------*/ 00033 00034 /* 00035 -- ERROR CODES 00036 -- 00037 -- To reduce unneccessary overheads in the final code, most of the memory 00038 -- manager API functions do not return error codes. It is expected that the 00039 -- caller (if necessary) will check parameters for legality before making the 00040 -- the memory manager API call. It is sensible to do error checking 00041 -- (via asserts) inside the memory manager functions during DEBUG. 00042 -- 00043 -- Error codes are only returned by functions that can generate valid run-time 00044 -- errors (ie. not due to coding errors). These errors codes are returned via 00045 -- the S32BIT return value of the API funcs. 00046 */ 00047 00048 typedef enum { 00049 MEM_NO_ERR, 00050 MEM_ERR_CACHE_FULL, 00051 MEM_ERR_ALLOC_FAILED, 00052 MEM_ERR_SEQ_OPEN_LIMIT, 00053 MEM_ERR_SEQ_END_OF_DATA, 00054 } E_DsmMemErr; 00055 00056 00057 /* 00058 -- DEFAULT SIZE LIMITS 00059 */ 00060 00061 #define MEM_BLOCK_SIZE_DFLT (256) 00062 #define MEM_HEAP_SIZE_DFLT (512*1024) 00063 #define MEM_SEQ_OPEN_DFLT (256) /* -- concurrently used MemSeqRef values */ 00064 00065 00066 #if defined(VGR_TRK_MEM) && !defined(USE_DSM_MEMCHK) && !defined(DBG_STORE_LINE) 00067 #define DBG_STORE_LINE 00068 #endif 00069 00070 00071 /*-------------------------------- Types -------------------------------------*/ 00072 00073 /* 00074 -- Generic MemHandle definition 00075 -- 00076 -- If clDsm is supplied as a pre-built library for a particular platform it 00077 -- will store a MemHandle as this type (ie. a standard pointer). This could 00078 -- be cast to a different type in the memory manager if required. 00079 -- 00080 -- If clDsm is being compiled from source then MemHandle can be (re)defined to 00081 -- anything appropriate. 00082 -- 00083 -- NOTE: 00084 -- 1) Zero (Null) MUST NOT be a legal value for a MemHandle. 00085 -- 2) If possible, avoid the use of void* (void*) since the compiler may 00086 -- not detect differing levels of indirection (eg void** and void* are 00087 -- treated the same). 00088 */ 00089 typedef U32BIT * MemHandle; 00090 00091 00092 /* 00093 -- Generic MemSeqRef definition 00094 -- 00095 -- If clDsm is supplied as a pre-built library for a particular platform it 00096 -- will store a MemSeqRef as this type (ie. a pointer to a structure). This can 00097 -- be cast to the appropriate (structure) type in the memory manager. 00098 -- 00099 -- If clDsm is being compiled from source then MemSeqRef can be (re)defined to 00100 -- anything appropriate. 00101 -- 00102 */ 00103 /*typedef struct _MemSeqRef_struct *MemSeqRef; */ 00104 00105 typedef U8BIT *MemSeqRef; 00106 00107 /*----------------------------- Exported Data --------------------------------*/ 00108 00109 /*------------------------------ Prototypes ----------------------------------*/ 00110 00111 #ifdef DSM_NO_MEM_CONTEXT 00112 #define memStop( x ) memStop() 00113 #ifdef DBG_STORE_LINE 00114 #define memAlloc( x, i, a, b, l ) memAlloc( i, a, b, l ) 00115 #else 00116 #define memAlloc( x, i, a, b, l ) memAlloc( i, a, b ) 00117 #endif 00118 #define memRelease( x, i, a ) memRelease( i, a ) 00119 #define memOpen( x, a, b ) memOpen( a, b ) 00120 #define memClose( x, a ) memClose( a ) 00121 #define memSeqOpen( x, a, b, c, d, e ) memSeqOpen( a, b, c, d, e ) 00122 #define memNumOpen( x ) memNumOpen() 00123 #define memSeqNumOpen( x ) memSeqNumOpen() 00124 #else 00125 #ifndef DBG_STORE_LINE 00126 #define memAlloc( x, i, a, b, l ) memAlloc( x, i, a, b ) 00127 #endif 00128 #endif 00129 00130 /* 00131 -- Start memory manager [SYNCHRONOUS] 00132 -- 00133 -- Specifies minimum contiguous memory block size in bytes (mandatory). 00134 -- Specifies minimum size of heap memory in bytes (mandatory). 00135 -- Specifies minimum number of MemSeq areas that can be opened 00136 -- simultaneously (mandatory). 00137 -- Requests total size of heap memory in bytes (optional - set to memHeapSizeMin 00138 -- value if not used). 00139 -- Supplies reference for memSetup parameters (optional). 00140 -- 00141 -- Returns pointer to this memory manager context (if implemented, otherewise 00142 -- should be returned as Null), this will be supplied to any subsequent mem 00143 -- function calls that require it. 00144 -- 00145 -- If any problems encountered (eg. in block/heap sizes) abort start and return 00146 -- error code: MEM_ERR_START_PROBLEM 00147 -- 00148 */ 00149 E_DsmMemErr memStart( 00150 /*I*/ U16BIT memBlockSizeMin, U32BIT memHeapSizeMin, U16BIT memSeqOpenMin, 00151 void* memSetup, 00152 /*O*/ void* *memContext ); 00153 00154 00155 /* 00156 -- Stop (forcibly) the memory manager [SYNCHRONOUS] 00157 -- 00158 -- If any problems noticed (eg. memory objects still open) still complete 00159 -- stop (eg. free memory) but return error code: MEM_ERR_STOP_PROBLEM 00160 -- 00161 */ 00162 E_DsmMemErr memStop( void* context ); 00163 00164 00165 /* 00166 -- Allocate an area of managed (heap) memory [SYNCHRONOUS] 00167 */ 00168 E_DsmMemErr memAlloc( void* context, pclDsmSetup_t setup, 00169 U32BIT size, MemHandle *memArea, int line ); 00170 00171 /* 00172 -- Release a previously allocated area of managed (heap) memory [SYNCHRONOUS] 00173 */ 00174 U32BIT memRelease( void* context, pclDsmSetup_t setup, MemHandle memArea ); 00175 00176 00177 /* 00178 -- Check if a MemHandle is valid [SYNCHRONOUS] 00179 -- 00180 -- NB. This should be 100% reliable at determining if a MemHandle reperesents 00181 -- a currently allocated (ie. not free) memory area in the memory heap. 00182 -- 00183 */ 00184 BOOLEAN memValidate( void* memArea ); 00185 00186 00187 /* 00188 -- Open/lock a memory area [SYNCHRONOUS] 00189 -- 00190 -- Call before making any direct (via pointer) access to the start of a managed 00191 -- (heap) memory area. Supplies a _real_ pointer to the start of the requested 00192 -- memory area. 00193 -- 00194 -- The memory manager must guarantee that memBlockSizeMin bytes after this 00195 -- start pointer can be always be accessed as contiguous memory. It must also 00196 -- guarantee that any memory item that is 'open' is 'locked' in memory and 00197 -- cannot be re-located (eg. due to de-fragmentation) until it is closed. 00198 -- 00199 -- NB. Unless memStart returned memContig as True, access to managed memory data 00200 -- after memBlockSizeMin bytes must be done via the memCopy (etc) API calls. 00201 -- 00202 -- memOpen calls on the same memory area can be nested to any depth but 00203 -- MUST be matched by an equal number of memClose calls. This enables, eg. a 00204 -- de-fragmenting memory manager to count open instances and only unlock an 00205 -- object (for de-fragmenting) on memClose when the open count reaches zero. 00206 -- 00207 */ 00208 void memOpen( void* context, MemHandle memArea, void* *memPtr ); 00209 00210 00211 /* 00212 -- ************************************************************************ 00213 -- NB. FOR DEBUG ONLY [SYNCHRONOUS]: 00214 -- Return a count of number of currently open (via memOpen) memory objects. 00215 -- Can be used to help detect objects left open erroneously. 00216 -- ************************************************************************ 00217 */ 00218 #ifndef NDEBUG 00219 U32BIT memNumOpen( void* context ); 00220 #endif 00221 00222 00223 /* 00224 -- SEQUENTIAL ('FILE TYPE') MEMORY ACCESS FUNCTIONS: 00225 -- 00226 -- NOTES: 00227 -- memOpen does NOT NEED to be called before using these functions but 00228 -- they may be nested between memOpen/Close calls if required. 00229 -- 00230 -- Only memSeqOpen requires a context to be passed (if supported). Memory 00231 -- managers that do support a context must store the context value via the 00232 -- MemSeqRef pointer which is passed to all other memSeq*** functions (nb. this 00233 -- is because asynchronous clients using these calls will not have access to 00234 -- the context value) 00235 -- 00236 -- It is legal for a memory sequence cursor to incremented or set to the 00237 -- position _immediately_ after the last byte of the sequential memory 00238 -- area (ie. an error should not be generated in this case). However, it 00239 -- is illegal (should generate an error) if an attempt is made to read or 00240 -- write at this cursor position. 00241 -- 00242 */ 00243 00244 00245 /* -- SYNCHRONOUS ONLY FUNCTIONS */ 00246 00247 /* 00248 -- Open all or part of a memory area for sequential ('file type') access 00249 -- [SYNCHRONOUS] 00250 -- 00251 -- Offset and length specify which part of the memory area is being 00252 -- accessed sequentially. They must always be set appropriately even if access 00253 -- to the whole area is required (note - this should make end of data (EOF) 00254 -- detection easier to implement in the memory manager). 00255 -- 00256 -- Different parts of a single memory area can be concurrently opened if 00257 -- required (note - if they overlap, then behaviour if writing asynchronously 00258 -- will be unpredictable !). 00259 -- 00260 -- The asyncAccess flag indicates whether subsequent read/write access to this 00261 -- area (via the memSeq* functions) will be asynchronous or synchronous. This 00262 -- holds true until the subsequent memSeqClose for this memory area (or part). 00263 -- 00264 -- If the number of memory areas (or parts) opened concurrently for sequential 00265 -- access reaches the memory manager limit (minimum value memSeqOpenMin passed 00266 -- in at memStart), return error code: MEM_ERR_SEQ_OPEN_LIMIT 00267 -- 00268 */ 00269 E_DsmMemErr memSeqOpen( void* context, 00270 MemHandle memArea, U32BIT offset, U32BIT length, BOOLEAN asyncAccess, 00271 MemSeqRef *memAreaRef ); 00272 00273 00274 /* 00275 -- Clone/copy an open sequential memory area reference (including current cursor 00276 -- position) [SYNCHRONOUS] 00277 -- 00278 -- Allocates, opens and returns another sequential memory area (MemSeqRef value) 00279 -- 00280 -- NB. Context can be determined from memAreaRefOrig (if needed). 00281 -- 00282 -- If the number of memory areas (or parts) opened concurrently for sequential 00283 -- access reaches the memory manager limit (minimum value memSeqOpenMin passed 00284 -- in at memStart), return error code: MEM_ERR_SEQ_OPEN_LIMIT 00285 -- 00286 */ 00287 E_DsmMemErr memSeqOpenClone( 00288 MemSeqRef memAreaRefOrig, MemSeqRef *memAreaRefClone ); 00289 00290 00291 /* 00292 -- Close a memory area for sequential ('file type') access [SYNCHRONOUS] 00293 -- 00294 -- NB. Context can be determined from memAreaRef (if needed). 00295 -- 00296 */ 00297 void memSeqClose( MemSeqRef memAreaRef ); 00298 00299 00300 /* 00301 -- Get a _real_ memory pointer for the current 'cursor' position and indicate 00302 -- the number of contiguous bytes of memory directly accessible from this 00303 -- pointer (within this memSeq area). Advance 'cursor' by numBytesContig 00304 -- [SYNCHRONOUS] 00305 -- 00306 -- Once called, the cursor should either end up pointing to the start of the 00307 -- next block (in block based memory managers) or the end of the memSeq area 00308 -- (in block based or contiguous memory managers). In either case the 00309 -- function can then be called again to access the next block or determine 00310 -- if the end of the memSeq area has been reached. If the 'cursor' is at the 00311 -- end of the memSeq area when this function is called then memPtr is returned 00312 -- as Null and numContigBytes set to 0. 00313 -- 00314 -- NB. This must be used VERY CAREFULLY since directly accessing beyond the 00315 -- supplied numContigBytes is likely to cause a fatal error (especially with 00316 -- block based memory managers). 00317 -- 00318 */ 00319 void memSeqAccessContig( 00320 MemSeqRef memAreaRef, U8BIT* *memPtr, U32BIT *numContigBytes ); 00321 00322 void memSeqAccessCurrent( 00323 MemSeqRef memAreaRef, U8BIT* *memPtr, U32BIT *numContigBytes ); 00324 00325 /* 00326 -- ************************************************************************ 00327 -- NB. FOR DEBUG ONLY [SYNCHRONOUS]: 00328 -- Return a count of number of currently open (via memSeqOpen or 00329 -- meSeqOpenClone) memory sequences 00330 -- Can be used to help detect MemSeqRef areas left open erroneously. 00331 -- ************************************************************************ 00332 */ 00333 #ifndef NDEBUG 00334 U32BIT memSeqNumOpen( void* context ); 00335 #endif 00336 00337 00338 00339 /* -- SYNCHRONOUS/ASYNCHRONOUS FUNCTIONS */ 00340 00341 /* 00342 -- Check if a MemSeqRef is valid [SYNCHRONOUS/ASYNCHRONOUS] 00343 */ 00344 void memSeqValidate( MemSeqRef memAreaRef, BOOLEAN *valid ); 00345 00346 00347 /* 00348 -- Get size of a sequential memory area [SYNCHRONOUS/ASYNCHRONOUS] 00349 -- 00350 -- NB. The size returned should be the exact number of bytes supplied as the 00351 -- length parameter at memSeqOpen. 00352 -- 00353 */ 00354 void memSeqSize( MemSeqRef memAreaRef, U32BIT *size ); 00355 00356 00357 /* 00358 -- Read single byte from current 'cursor' position in managed memory, 00359 -- increment cursor [SYNCHRONOUS/ASYNCHRONOUS] 00360 -- 00361 -- If call attempts to read past end of the sequential memory area, 00362 -- return error code: MEM_ERR_SEQ_END_OF_DATA 00363 -- 00364 */ 00365 E_DsmMemErr memSeqReadByte( MemSeqRef src, U8BIT *byte ); 00366 00367 00368 /* 00369 -- Put single byte to current 'cursor' position in managed memory, 00370 -- increment cursor [SYNCHRONOUS/ASYNCHRONOUS] 00371 -- 00372 -- If call attempts to write past end of the sequential memory area, 00373 -- return error code: MEM_ERR_SEQ_END_OF_DATA 00374 -- 00375 */ 00376 E_DsmMemErr memSeqWriteByte( U8BIT byte, MemSeqRef dest ); 00377 00378 00379 /* 00380 -- Read numBytes into contiguous memory (starting at current 'cursor' position 00381 -- in managed memory), increment 'cursor' position by numBytes 00382 -- [SYNCHRONOUS/ASYNCHRONOUS] 00383 -- 00384 -- If call attempts to read past end of the sequential memory area, 00385 -- read as many bytes as possible, store the number actually read in 00386 -- numBytesActual and return error code: MEM_ERR_SEQ_END_OF_DATA 00387 -- 00388 */ 00389 E_DsmMemErr memSeqRead( 00390 MemSeqRef src, U8BIT *dest, U32BIT numBytes, U32BIT *numBytesActual ); 00391 00392 00393 /* 00394 -- Write numBytes from contiguous memory into managed memory (starting at 00395 -- current 'cursor' position in managed memory), increment 'cursor' position by 00396 -- numBytes [SYNCHRONOUS/ASYNCHRONOUS] 00397 -- 00398 -- If call attempts to write past end of the sequential memory area, 00399 -- write as many bytes as possible, store the number actually written in 00400 -- numBytesActual and return error code: MEM_ERR_SEQ_END_OF_DATA 00401 -- 00402 */ 00403 E_DsmMemErr memSeqWrite( 00404 U8BIT *src, MemSeqRef dest, U32BIT numBytes, U32BIT *numBytesActual ); 00405 00406 00407 /* 00408 -- Copy numBytes from one managed memory area into another managed memory area 00409 -- (starting at current 'cursor' positions in each), increment 'cursor' 00410 -- positions in each by numBytes [SYNCHRONOUS/ASYNCHRONOUS] 00411 -- 00412 -- If call attempts to write/read past the end of either of the sequential 00413 -- memory areas, copy as many bytes as possible, store the number actually 00414 -- copied in numBytesActual and return error code: MEM_ERR_SEQ_END_OF_DATA 00415 -- 00416 */ 00417 E_DsmMemErr memSeqCopy( 00418 MemSeqRef src, MemSeqRef dest, U32BIT numBytes, U32BIT *numBytesActual ); 00419 00420 00421 /* 00422 -- Compare sequence of bytes (numBytes long) in contiguous memory with bytes 00423 -- in managed memory (starting at current 'cursor' position), do not change 00424 -- 'cursor' position [SYNCHRONOUS/ASYNCHRONOUS] 00425 -- 00426 -- If call attempts to compare bytes past the end of the sequential 00427 -- memory area, return error code: MEM_ERR_SEQ_END_OF_DATA 00428 -- 00429 */ 00430 E_DsmMemErr memSeqCompContig( 00431 U8BIT* contig, MemSeqRef memAreaRef, U32BIT numBytes, BOOLEAN *equal ); 00432 00433 00434 /* 00435 -- Compare sequence of bytes (numBytes long) in one managed memory area with 00436 -- bytes in another managed memory area (starting at current 'cursor' positions 00437 -- in each), do not change 'cursor' positions for either memory area 00438 -- [SYNCHRONOUS/ASYNCHRONOUS] 00439 -- 00440 -- If call attempts to compare bytes past the end of either of the sequential 00441 -- memory areas, return error code: MEM_ERR_SEQ_END_OF_DATA 00442 -- 00443 */ 00444 E_DsmMemErr memSeqCompMgd( 00445 MemSeqRef memAreaRef1, MemSeqRef memAreaRef2, U32BIT numBytes, 00446 BOOLEAN *equal ); 00447 00448 00449 /* 00450 -- Set sequential access 'cursor' position relative to current position 00451 -- [SYNCHRONOUS/ASYNCHRONOUS] 00452 -- 00453 -- If call attempts to set cursor past the end of the sequential memory area, 00454 -- return error code: MEM_ERR_SEQ_END_OF_DATA 00455 -- 00456 */ 00457 E_DsmMemErr memSeqSetPosRel( MemSeqRef memAreaRef, S32BIT position ); 00458 00459 00460 /* 00461 -- Set absolute sequential access 'cursor' position [SYNCHRONOUS/ASYNCHRONOUS] 00462 -- 00463 -- If call attempts to set cursor past the end of the sequential memory area, 00464 -- return error code: MEM_ERR_SEQ_END_OF_DATA 00465 -- 00466 */ 00467 E_DsmMemErr memSeqSetPosAbs( MemSeqRef memAreaRef, U32BIT position ); 00468 00469 00470 /* 00471 -- Read sequential access 'cursor' position [SYNCHRONOUS/ASYNCHRONOUS] 00472 -- 00473 -- Value returned in 'position' is the offset from the start of the memory area 00474 -- to the next byte to be read. If the current position has passed the end of 00475 -- the memory area, then the position returned is equal to the memory area size. 00476 -- The value returned therefore ranges from 0 to (memory area size). 00477 */ 00478 void memSeqReadPos( MemSeqRef memAreaRef, U32BIT *position ); 00479 00480 00481 /*----------------------------------------------------------------------------*/ 00482 #endif /* _CLDSMMEMMGRAPI_H_ */ 00483