commsfwutils/commsbufs/version1/mbufmgr/src/MB_CELL.CPP
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // C++ storage support
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <nifmbuf.h>
       
    19 
       
    20 //
       
    21 // MBuf Packet Information Base
       
    22 //
       
    23 
       
    24 EXPORT_C RMBufCell* RMBufCell::CopyL()
       
    25 /**
       
    26 Pseudo Copy Constructor	
       
    27 - refer RMBufChain::AllocL notes regarding the deliberate decision not to provide an overloaded min/max mbuf size variant
       
    28 */
       
    29 	{
       
    30 	RMBuf* mbuf = RMBuf::AllocL(iThisMBuf->Size());
       
    31 
       
    32 	Mem::FillZ(mbuf->Buffer() + iThisMBuf->Length(), mbuf->Size() - iThisMBuf->Length());	// trs; wasteful to fill memory, but removing this constitutes a functional break, hence it has been kept as is
       
    33 	mbuf->SetType(EMBufHeader);			// trs; internally only used for UDEB so could in theory be compiled out for UREL, but left as is to avoid a functional break
       
    34 	
       
    35 	// memory is copied to the length specified by the destination (instead of the source) because;
       
    36 	// a. avoid overrun if source is larger than the destination
       
    37 	// b. avoid FC break whereby legacy code derives from an RMBufCell object, but does not request the correct size during allocation
       
    38 	//    eg. tcpip6 wrongly typecasts RMBufPktInfo object to RMBufRecvInfo & assumes the mbuf is large enough for any additional members
       
    39 	//        - this works (but is still a very poor assumption) if mbufs are of K_MBufSmallSize, but fails when copying between 
       
    40 	//			RMBufCell's unless the entire mbuf is copied (ie. not just the length specified iLength)
       
    41 	Mem::Copy(mbuf->Buffer(), iThisMBuf->Buffer(), mbuf->Size());	// trs; ideally length should length min(iThisMBuf->Length(), mbuf->Size())
       
    42 	
       
    43 	RMBufCell* hdr = (RMBufCell*)mbuf->Ptr();
       
    44 	hdr->iThisMBuf = mbuf;
       
    45 	return hdr;
       
    46 	}
       
    47 
       
    48 
       
    49 EXPORT_C TAny* RMBufCell::operator new(TUint aSize, TLeave /*aLeave*/, TUint aExtra)
       
    50 /**
       
    51 new operator.
       
    52 - refer RMBufChain::AllocL notes regarding the deliberate decision not to provide an overloaded min/max mbuf size variant
       
    53 @param aSize A size of the cell
       
    54 @param aExtra Extra size
       
    55 */
       
    56 	{
       
    57 	aSize += aExtra;
       
    58 
       
    59 	// for backward compatibility (refer es_mbuf.h notes) cells are assumed to always be allocated within an K_MBufSmallSize sized mbuf
       
    60 	// - removing this assumption requires a SC break on consumers that (wrongly) assume that cells are always of this size
       
    61 	// - this assumption is unforunate as it restricts cells to no larger (or smaller) than this size
       
    62 	__ASSERT_ALWAYS(aSize <= (TUint)KMBufSmallSize, MBufExtPanic(EMbExtPanic_MBufAllocTooBig));
       
    63 
       
    64 	RMBuf* mbuf = RMBuf::AllocL(aSize); 
       
    65 	mbuf->SetType(EMBufHeader);			// trs; internally only used for UDEB so could in theory be compiled out for UREL, but left as is to avoid a functional break
       
    66 	mbuf->FillZ();						// trs; wasteful to fill memory, but removing this constitutes a functional break, hence it has been kept as is
       
    67 
       
    68 	RMBufCell* hdr = (RMBufCell*)mbuf->Ptr();
       
    69 	hdr->iThisMBuf = mbuf;
       
    70 	return hdr;
       
    71 	}
       
    72 
       
    73 
       
    74 EXPORT_C TAny* RMBufCell::operator new(TUint aSize, TUint aExtra)  __NO_THROW
       
    75 /**
       
    76 new operator.
       
    77 - refer RMBufChain::AllocL notes regarding the deliberate decision not to provide an overloaded min/max mbuf size variant
       
    78 @param aSize A size of the cell
       
    79 @param aExtra Extra size
       
    80 */
       
    81 	{
       
    82 	aSize += aExtra;
       
    83 
       
    84 	// cells are assumed to always be allocated within an K_MBufSmallSize sized mbuf, refer ::new() throw notes
       
    85 	__ASSERT_ALWAYS(aSize <= (TUint)KMBufSmallSize, MBufExtPanic(EMbExtPanic_MBufAllocTooBig));
       
    86 	
       
    87 	RMBuf* mbuf = RMBuf::Alloc(aSize);
       
    88 	if(!mbuf)
       
    89 		{
       
    90 		return mbuf;
       
    91 		}
       
    92 	mbuf->SetType(EMBufHeader);	// trs; internally only used for UDEB so could in theory be compiled out for UREL, but left as is to avoid a functional break
       
    93 	mbuf->FillZ();				// trs; wasteful to fill memory, but removing this constitutes a functional break, hence it has been kept as is
       
    94 
       
    95 	RMBufCell* hdr = (RMBufCell*)mbuf->Ptr();
       
    96 	hdr->iThisMBuf = mbuf;
       
    97 	return hdr;
       
    98 	}
       
    99 
       
   100 
       
   101 EXPORT_C void RMBufCell::operator delete(TAny* aPtr)
       
   102 /**
       
   103 delete operator
       
   104 deletes the cell
       
   105 */
       
   106  	{
       
   107 	((RMBufCell*)aPtr)->iThisMBuf->Free();
       
   108 	}
       
   109 
       
   110 
       
   111 void RMBufCell::operator delete(TAny* aPtr, TLeave, TUint)
       
   112 /**
       
   113 extra delete operator for exception unwinding in Code Warrior
       
   114 */
       
   115 	{
       
   116 	RMBufCell::operator delete(aPtr);
       
   117 	}
       
   118 
       
   119 void RMBufCell::operator delete(TAny* aPtr, TUint)
       
   120 /**
       
   121 extra delete operator for exception unwinding in Code Warrior
       
   122 */
       
   123 	{
       
   124 	RMBufCell::operator delete(aPtr);
       
   125 	}
       
   126 
       
   127 
       
   128 
       
   129