source: trunk/src/s60main/newallocator_hook.cpp@ 890

Last change on this file since 890 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 5.4 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the Symbian application wrapper of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41#include <e32std.h>
42#include <qglobal.h>
43
44#ifdef QT_EXPORTS_NOT_FROZEN
45// If exports in Qt DLLs are not frozen in this build, then we have to pick up the
46// allocator creation function by import link. We know the function will be present
47// in the DLLs we test with, as we have to use the DLLs we have built.
48
49struct SStdEpocThreadCreateInfo;
50
51Q_CORE_EXPORT TInt qt_symbian_SetupThreadHeap(TBool aNotFirst, SStdEpocThreadCreateInfo& aInfo);
52
53
54/* \internal
55 *
56 * Uses link-time symbol preemption to capture a call from the application
57 * startup. On return, there is some kind of heap allocator installed on the
58 * thread.
59*/
60TInt UserHeap::SetupThreadHeap(TBool aNotFirst, SStdEpocThreadCreateInfo& aInfo)
61{
62 return qt_symbian_SetupThreadHeap(aNotFirst, aInfo);
63}
64
65#else // QT_EXPORTS_NOT_FROZEN
66// If we are using an export frozen build, it should be compatible with all 4.7.x Qt releases.
67// We want to use the allocator creation function introduced in qtcore.dll after 4.7.1. But we
68// can't import link to it, as it may not be present in whatever 4.7.x DLLs we are running with.
69// So the function is found and called dynamically, by library lookup. If it is not found, we
70// use the OS allocator creation functions instead.
71
72#if defined(QT_LIBINFIX)
73# define QT_LSTRING2(x) L##x
74# define QT_LSTRING(x) QT_LSTRING2(x)
75# define QT_LIBINFIX_UNICODE QT_LSTRING(QT_LIBINFIX)
76#else
77# define QT_LIBINFIX_UNICODE L""
78#endif
79
80_LIT(QtCoreLibName, "qtcore" QT_LIBINFIX_UNICODE L".dll");
81
82struct SThreadCreateInfo
83 {
84 TAny* iHandle;
85 TInt iType;
86 TThreadFunction iFunction;
87 TAny* iPtr;
88 TAny* iSupervisorStack;
89 TInt iSupervisorStackSize;
90 TAny* iUserStack;
91 TInt iUserStackSize;
92 TInt iInitialThreadPriority;
93 TPtrC iName;
94 TInt iTotalSize; // Size including any extras (must be a multiple of 8 bytes)
95 };
96
97struct SStdEpocThreadCreateInfo : public SThreadCreateInfo
98 {
99 RAllocator* iAllocator;
100 TInt iHeapInitialSize;
101 TInt iHeapMaxSize;
102 TInt iPadding; // Make structure size a multiple of 8 bytes
103 };
104
105
106/* \internal
107 *
108 * Uses link-time symbol preemption to capture a call from the application
109 * startup. On return, there is some kind of heap allocator installed on the
110 * thread.
111*/
112TInt UserHeap::SetupThreadHeap(TBool aNotFirst, SStdEpocThreadCreateInfo& aInfo)
113{
114 TInt r = KErrNone;
115
116#ifndef __WINS__
117 // attempt to create the fast allocator through a known export ordinal in qtcore.dll
118 RLibrary qtcore;
119 if (qtcore.Load(QtCoreLibName) == KErrNone)
120 {
121 const int qt_symbian_SetupThreadHeap_eabi_ordinal = 3713;
122 TLibraryFunction libFunc = qtcore.Lookup(qt_symbian_SetupThreadHeap_eabi_ordinal);
123 if (libFunc)
124 {
125 typedef int (*TSetupThreadHeapFunc)(TBool aNotFirst, SStdEpocThreadCreateInfo& aInfo);
126 TSetupThreadHeapFunc p_qt_symbian_SetupThreadHeap = TSetupThreadHeapFunc(libFunc);
127 r = (*p_qt_symbian_SetupThreadHeap)(aNotFirst, aInfo);
128 }
129 qtcore.Close();
130 if (libFunc)
131 return r;
132 }
133#endif
134
135 // no fast allocator support - use default allocator creation
136 if (!aInfo.iAllocator && aInfo.iHeapInitialSize>0)
137 {
138 // new heap required
139 RHeap* pH = NULL;
140 r = UserHeap::CreateThreadHeap(aInfo, pH);
141 }
142 else if (aInfo.iAllocator)
143 {
144 // sharing a heap
145 RAllocator* pA = aInfo.iAllocator;
146 pA->Open();
147 User::SwitchAllocator(pA);
148 r = KErrNone;
149 }
150 return r;
151}
152
153#endif // QT_EXPORTS_NOT_FROZEN
Note: See TracBrowser for help on using the repository browser.