First public contribution.
2 Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright notice, this
8 list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright notice,
10 this list of conditions and the following disclaimer in the documentation
11 and/or other materials provided with the distribution.
12 * Neither the name of Nokia Corporation nor the names of its contributors
13 may be used to endorse or promote products derived from this software
14 without specific prior written permission.
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 Description: Contains the WSD solution
32 #include "libssl_wsd_defs.h"
39 #include "wsd_solution.h"
41 //definition of all WSD related funcitons
43 #define MAX_NUMBER_OF_PROCESSES 100
52 #pragma data_seg(".wsd")
53 TInt NumOfProcesses = 0;
56 #pragma bss_seg(".wsd")
57 struct TWsdArray wsdArray[MAX_NUMBER_OF_PROCESSES];
60 // This function frees up the used slots within the wsdArray
61 // for use by other processes; internal to the implementation
62 // that provides WSD support
63 LOCAL_C TInt FindSlot();
67 HANDLE mutexHandle = NULL;
70 'l', 'i', 'b', 's', 's', 'l', '_', 'm','u','t','e','x'
73 if( !(mutexHandle = CreateMutex(NULL, TRUE, p)) )
75 // Mutex already created. Try to acquire it
76 mutexHandle = OpenMutex(SYNCHRONIZE, FALSE, p);
77 WaitForSingleObject(mutexHandle, INFINITE);
80 TProcessId procId = RProcess().Id();
81 TFullName fullName = RProcess().FullName();
82 TInt pid = *(TUint *)&procId;
85 for(int i=0 ; i < MAX_NUMBER_OF_PROCESSES ; ++i )
94 else if(wsdArray[i].iPid == pid)
96 ReleaseMutex(mutexHandle);
97 return wsdArray[i].iPtr;
103 if(MAX_NUMBER_OF_PROCESSES == NumOfProcesses)
105 // Find out if one of the slots reserved for previous processes
107 TInt returnValue = -1;
108 returnValue = FindSlot();
109 if(returnValue != -1)
115 User::Panic(_L("Pls() Reached the naximum number for the processes"),KErrNoMemory);
119 wsdArray[slot].iPid = pid;
120 wsdArray[slot].iFullName = fullName;
121 wsdArray[slot].iPtr = NULL;
123 // Increment the count for the number of processes
127 ReleaseMutex(mutexHandle);
128 return wsdArray[slot].iPtr;
131 LOCAL_C TInt FindSlot()
135 TInt currentCount = 0;
137 for(int i = 0 ; i < MAX_NUMBER_OF_PROCESSES ; ++i)
139 TFindProcess search(wsdArray[i].iFullName);
140 if(search.Next(fullName) == KErrNone)
146 // Process with the given name does not exist in
147 // the system. So the slot could be reused.
148 wsdArray[i].iPid = 0;
150 // Free the VAS associated with this "process" (terminated)
151 VirtualFree(wsdArray[i].iPtr, 0, MEM_RELEASE);
152 wsdArray[i].iPtr = NULL;
160 NumOfProcesses = currentCount;
164 TInt SetPls(void *aArg)
166 HANDLE mutexHandle = NULL;
169 'l', 'i', 'b', 's', 's', 'l', '_', 'm','u','t','e','x'
172 if( !(mutexHandle = CreateMutex(NULL, TRUE, p)) )
174 // Mutex already created. Try to acquire it
175 mutexHandle = OpenMutex(SYNCHRONIZE, FALSE, p);
176 WaitForSingleObject(mutexHandle, INFINITE);
179 TProcessId procId = RProcess().Id();
180 TFullName fullName = RProcess().FullName();
181 TInt pid = *(TUint *)&procId;
183 for(int i=0 ; i < MAX_NUMBER_OF_PROCESSES ; ++i )
185 if(wsdArray[i].iPid == pid)
187 wsdArray[i].iPtr = aArg;
188 ReleaseMutex(mutexHandle);
193 ReleaseMutex(mutexHandle);
197 void* AllocatePls(TInt aSize)
199 void *r = VirtualAlloc(NULL,
201 MEM_COMMIT | MEM_RESERVE,
205 User::Panic(_L("AllocatePls() VIRTUALALLOC"),KErrNoMemory);