51
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "MemSpyDriverXferBuffer.h"
|
|
19 |
|
|
20 |
// System includes
|
|
21 |
#include <u32hal.h>
|
|
22 |
|
|
23 |
// Shared includes
|
|
24 |
#include <memspy/driver/memspydriverobjectsshared.h>
|
|
25 |
#include "MemSpyDriverObjectsInternal.h"
|
|
26 |
|
|
27 |
// User includes
|
|
28 |
#include "MemSpyDriverUtils.h"
|
|
29 |
#include "MemSpyDriverDevice.h"
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
DMemSpyDriverXferBuffer::DMemSpyDriverXferBuffer( DMemSpyDriverDevice& aDevice, DThread& aThread )
|
|
34 |
: iDevice( aDevice ), iClientThread( aThread )
|
|
35 |
{
|
|
36 |
TRACE( Kern::Printf("DMemSpyDriverXferBuffer::DMemSpyDriverXferBuffer() - this: 0x%08x", this ));
|
|
37 |
}
|
|
38 |
|
|
39 |
|
|
40 |
DMemSpyDriverXferBuffer::~DMemSpyDriverXferBuffer()
|
|
41 |
{
|
|
42 |
TRACE( Kern::Printf("DMemSpyDriverXferBuffer::~DMemSpyDriverXferBuffer() - START - this: 0x%08x", this ));
|
|
43 |
|
62
|
44 |
if (iBuffer)
|
|
45 |
{
|
|
46 |
NKern::ThreadEnterCS();
|
|
47 |
delete iBuffer;
|
|
48 |
NKern::ThreadLeaveCS();
|
|
49 |
}
|
51
|
50 |
|
|
51 |
TRACE( Kern::Printf("DMemSpyDriverXferBuffer::~DMemSpyDriverXferBuffer() - END - this: 0x%08x", this ));
|
|
52 |
}
|
|
53 |
|
|
54 |
|
|
55 |
TInt DMemSpyDriverXferBuffer::Construct( TInt aSize )
|
|
56 |
{
|
|
57 |
TRACE( Kern::Printf("DMemSpyDriverXferBuffer::Construct() - START - this: 0x%08x, newSize: %d, iSize: %d", this, aSize, iSize ));
|
|
58 |
TInt ret = KErrNone;
|
|
59 |
//
|
|
60 |
iBuffer = Kern::AllocZ( aSize );
|
|
61 |
if ( iBuffer == NULL )
|
|
62 |
{
|
|
63 |
ret = KErrNoMemory;
|
|
64 |
}
|
|
65 |
else
|
|
66 |
{
|
|
67 |
iSize = aSize;
|
|
68 |
}
|
|
69 |
//
|
|
70 |
TRACE( Kern::Printf("DMemSpyDriverXferBuffer::Construct() - END - this: 0x%08x, newSize: %d, iSize: %d", this, aSize, iSize ));
|
|
71 |
return ret;
|
|
72 |
}
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
TInt DMemSpyDriverXferBuffer::Size() const
|
|
77 |
{
|
|
78 |
return iSize;
|
|
79 |
}
|
|
80 |
|
|
81 |
|
|
82 |
TInt DMemSpyDriverXferBuffer::GrowBy( TInt aSize )
|
|
83 |
{
|
|
84 |
TRACE( Kern::Printf("DMemSpyDriverXferBuffer::GrowBy() - START - this: 0x%08x, newSize: %d, iSize: %d", this, iSize + aSize, iSize ));
|
|
85 |
//
|
|
86 |
TInt ret = KErrNone;
|
|
87 |
const TInt newSize = iSize + aSize;
|
|
88 |
if ( newSize > iSize )
|
|
89 |
{
|
|
90 |
NKern::ThreadEnterCS();
|
|
91 |
ret = Kern::SafeReAlloc( iBuffer, iSize, newSize );
|
|
92 |
if ( ret == KErrNone )
|
|
93 |
{
|
|
94 |
iSize = newSize;
|
|
95 |
}
|
|
96 |
NKern::ThreadLeaveCS();
|
|
97 |
}
|
|
98 |
else
|
|
99 |
{
|
|
100 |
TRACE( Kern::Printf("DMemSpyDriverXferBuffer::GrowBy() - WARNING - new size would shrink buffer (or have no effect)!" ));
|
|
101 |
}
|
|
102 |
//
|
|
103 |
TRACE( Kern::Printf("DMemSpyDriverXferBuffer::GrowBy() - END - this: 0x%08x, err: %d, iSize: %d", this, ret, iSize ));
|
|
104 |
return ret;
|
|
105 |
}
|
|
106 |
|
|
107 |
|
|
108 |
TInt DMemSpyDriverXferBuffer::EnsureCapacity( TInt aSize )
|
|
109 |
{
|
|
110 |
TRACE( Kern::Printf("DMemSpyDriverXferBuffer::EnsureCapacity() - START - this: 0x%08x, aSize: %d, iSize: %d", this, aSize, iSize ));
|
|
111 |
//
|
|
112 |
TInt ret = KErrNone;
|
|
113 |
if ( aSize > iSize )
|
|
114 |
{
|
|
115 |
const TInt newSize = aSize;
|
|
116 |
//
|
|
117 |
NKern::ThreadEnterCS();
|
|
118 |
ret = Kern::SafeReAlloc( iBuffer, iSize, newSize );
|
|
119 |
if ( ret == KErrNone )
|
|
120 |
{
|
|
121 |
iSize = newSize;
|
|
122 |
}
|
|
123 |
NKern::ThreadLeaveCS();
|
|
124 |
}
|
|
125 |
else
|
|
126 |
{
|
|
127 |
TRACE( Kern::Printf("DMemSpyDriverXferBuffer::EnsureCapacity() - WARNING - new size would shrink buffer (or have no effect)!" ));
|
|
128 |
}
|
|
129 |
//
|
|
130 |
TRACE( Kern::Printf("DMemSpyDriverXferBuffer::EnsureCapacity() - END - this: 0x%08x, err: %d, iSize: %d", this, ret, iSize ));
|
|
131 |
return ret;
|
|
132 |
}
|
|
133 |
|
|
134 |
|
|
135 |
void DMemSpyDriverXferBuffer::Reset()
|
|
136 |
{
|
|
137 |
memclr( iBuffer, iSize );
|
|
138 |
}
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
|
149 |
TInt DMemSpyDriverXferBuffer::WriteToClient( TDes8* aDestinationPointer, TInt aLength )
|
|
150 |
{
|
|
151 |
// Check the client has enough space
|
|
152 |
TInt err = Kern::ThreadGetDesMaxLength( &iClientThread, aDestinationPointer );
|
|
153 |
if ( err >= 0 )
|
|
154 |
{
|
|
155 |
if ( aLength > err )
|
|
156 |
{
|
|
157 |
Kern::Printf("DMemSpyDriverXferBuffer::WriteToClient() - client descriptor max len: %d, amount to write: %d => KErrOverflow", err, aLength );
|
|
158 |
err = KErrOverflow;
|
|
159 |
}
|
|
160 |
else
|
|
161 |
{
|
|
162 |
const TPtrC8 pData( (const TUint8*) iBuffer, aLength );
|
|
163 |
err = Kern::ThreadDesWrite( &iClientThread, aDestinationPointer, pData, 0, KChunkShiftBy0 | KTruncateToMaxLength, &iClientThread );
|
|
164 |
}
|
|
165 |
}
|
|
166 |
|
|
167 |
// Check for bad descriptor and panic the client
|
|
168 |
if ( err == KErrBadDescriptor )
|
|
169 |
{
|
|
170 |
MemSpyDriverUtils::PanicThread( iClientThread, EPanicBadDescriptor );
|
|
171 |
}
|
|
172 |
//
|
|
173 |
return err;
|
|
174 |
}
|
|
175 |
|
|
176 |
|
|
177 |
DThread& DMemSpyDriverXferBuffer::ClientThread()
|
|
178 |
{
|
|
179 |
return iClientThread;
|
|
180 |
}
|
|
181 |
|
|
182 |
|
|
183 |
TUint8* DMemSpyDriverXferBuffer::Ptr()
|
|
184 |
{
|
|
185 |
return (TUint8*) iBuffer;
|
|
186 |
}
|
|
187 |
|
|
188 |
|
|
189 |
|
|
190 |
|
|
191 |
|
|
192 |
|