comparison src/ui/mfw/mfw_mfw.c @ 3:67bfe9f274f6

src/ui: import of src/ui3 from Magnetite
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 16 Oct 2020 06:33:10 +0000
parents
children 92abb46dc1ba
comparison
equal deleted inserted replaced
2:3a14ee9a9843 3:67bfe9f274f6
1 /*
2 +--------------------------------------------------------------------+
3 | PROJECT: MMI-Framework (8417) $Workfile:: mfw_mfw.c $|
4 | $Author:: Es $ CONDAT GmbH $Revision:: 11 $|
5 | CREATED: 21.09.98 $Modtime:: 23.03.00 10:47 $|
6 | STATE : code |
7 +--------------------------------------------------------------------+
8
9 MODULE : MFW_MFW
10
11 PURPOSE : element chaining functions
12
13 EXPORT :
14
15 TO DO :
16
17 $History:: mfw_mfw.c $
18 Sep 14, 2007 REF: OMAPS00145866 Adrian Salido
19 Description: FT - MMI: Wrong trace class
20 Solution: changed event traces to function traces because the information content of
21 this is low for non-MMI people and against TI coding convention.
22
23 Nov 05, 2005 REF: OMAPS00049571 Sumanth Kumar. C
24 Description: eZi Text function is not working
25 Solution: current_mfw_elem variable is updated when any of the elements
26 such as window, keyboard, timer, etc., are deleted so that the
27 current_mfw_element does not point to element that has already been freed.
28
29 Feb 28, 2004 REF: CRR 25608 Deepa M.D
30 The mfwEorc is made const.The changes will be present both in Color and Golite build .
31
32 Jan 27, 2005 REF: CRR MMI-SPR-28300 xnkulkar
33 Description: BMI: memory leak in mfwFree/mfwAlloc ??
34 Solution: Trace output to print memory address and size freed
35 modified in function mfwFree()
36
37 Dec 22, 2004 REF: CRR MFW-SPR-27847 xnkulkar
38 Description: MFW memory size variable changed from U16 -> U32
39 Solution: The use of variable U16 has been replaced with U32
40
41 Oct 06, 2004 REF: CRR 25608 Deepa M.D
42 Bug:Change "static MfwHdr mfwEorc =" to const
43 Fix: MfwHdr mfwEorc is made const to save memory.
44 *
45 * ***************** Version 11 *****************
46 * User: Es Date: 23.03.00 Time: 14:43
47 * Updated in $/GSM/Condat/MS/SRC/MFW
48 * Added 'mfwParent(elem)'
49 *
50 * ***************** Version 10 *****************
51 * User: Es Date: 18.02.00 Time: 15:45
52 * Updated in $/GSM/Condat/MS/SRC/MFW
53 * fixed alloc/free bug (shrink)
54 * changed MfwMemLarge macro
55 * added constants for MMI event handler return values
56 *
57 * ***************** Version 9 *****************
58 * User: Kk Date: 10.01.00 Time: 14:03
59 * Updated in $/GSM/Condat/MS/SRC/MFW
60 *
61 * ***************** Version 4 *****************
62 * User: Rm Date: 12/22/99 Time: 4:34p
63 * Updated in $/GSM/Condat/SND-MMI/MFW
64 *
65 * ***************** Version 3 *****************
66 * User: Be Date: 29.11.99 Time: 14:31
67 * Updated in $/GSM/Condat/SND-MMI/MFW
68 * target integration
69 *
70 * ***************** Version 2 *****************
71 * User: Es Date: 22.11.99 Time: 10:24
72 * Updated in $/GSM/Condat/SND-MMI/MFW
73 *
74 * ***************** Version 1 *****************
75 * User: Es Date: 18.11.99 Time: 16:35
76 * Created in $/GSM/Condat/SND-MMI/MFW
77 * Initial
78 *
79 * ***************** Version 6 *****************
80 * User: Es Date: 1.04.99 Time: 17:07
81 * Updated in $/GSM/DEV/MS/SRC/MFW
82 * removed lots of traces
83 *
84 * ***************** Version 5 *****************
85 * User: Es Date: 18.02.99 Time: 17:01
86 * Updated in $/GSM/DEV/MS/SRC/MFW
87 *
88 * ***************** Version 4 *****************
89 * User: Es Date: 17.02.99 Time: 19:11
90 * Updated in $/GSM/DEV/MS/SRC/MFW
91 *
92 * ***************** Version 3 *****************
93 * User: Es Date: 27.01.99 Time: 15:06
94 * Updated in $/GSM/DEV/MS/SRC/MFW
95 *
96 * ***************** Version 2 *****************
97 * User: Es Date: 23.12.98 Time: 16:19
98 * Updated in $/GSM/DEV/MS/SRC/MFW
99 */
100 #define ENTITY_MFW
101
102 #define TRACE_MEMORY_CHECK
103
104 #include <stdio.h>
105 #include <string.h>
106 #include <stdlib.h>
107
108 #if defined (NEW_FRAME)
109
110 #include "typedefs.h"
111 #include "vsi.h"
112 #include "pei.h"
113 #include "custom.h"
114 #include "gsm.h"
115
116 #else
117
118 #include "STDDEFS.H"
119 #include "custom.h"
120 #include "gsm.h"
121 #include "vsi.h"
122
123 #endif
124
125 //#include <stdio.h>
126 //#include <string.h>
127
128 #include "mfw_mfw.h"
129 #include "mfw_sys.h"
130 #include "mfw_win.h"
131 #include "mfw_sat.h" /* CQ16435 : Header Required */
132
133 // Dec 22, 2004 REF: CRR MFW-SPR-27847 xnkulkar
134 // Description: MFW memory size variable changed from U16 -> U32
135 // Solution: The use of variable U16 has been replaced with U32
136 U32 mfwMemDynTotal = 0; /* sample memory usage */
137 U32 mfwMemLowWater = 0xffffffff; /* sample memory usage */
138
139 MfwHdr *mfwFocus = 0; /* the focus node */
140 MfwHdr *mfwRoot = 0; /* root of MFW elements */
141 MfwCb mfwCommand [MfwTypMax]; /* MFW commands to modules */
142
143 static MfwHdr *mfwSatIdleWin = 0; /* CQ16435 : When this window gets focus, SAT will be informed */
144
145 static MfwMemHdr mfwMem; /* root of free memory list */
146 static U8 *mfwMemBase; /* mfw dynamic memory pool */
147 static U8 *mfwMemEnd; /* end of mfw memory */
148
149 // Dec 22, 2004 REF: CRR MFW-SPR-27847 xnkulkar
150 // Description: MFW memory size variable changed from U16 -> U32
151 // Solution: The use of variable U16 has been replaced with U32
152 static U32 mfwMemLeft; /* space left in pool */
153
154 //Feb 28, 2005 REF: CRR 25608 Deepa M.D
155 //The mfwEorc is made const.The changes will be present both in Color and Golite build
156 static const MfwHdr mfwEorc = {0, MfwTypMax, 0}; /* end of root chain */
157
158
159 /***************************Go-lite Optimization changes end***********************/
160
161 U8 mfwSignallingMethod = 0; /* default is focus+root */
162
163 EXTERN MfwHdr * current_mfw_elem;
164
165 #define SENTINAL_CHECK 1
166
167 // Dec 22, 2004 REF: CRR MFW-SPR-27847 xnkulkar
168 // Description: MFW memory size variable changed from U16 -> U32
169 // Solution: define SENTINEL_SIZE to a value of 4
170 #define SENTINEL_SIZE 4 //Will, Dec/07/2004-->Ti is 4 bytes
171 /*
172 +--------------------------------------------------------------------+
173 | PROJECT : MMI-Framework (8417) MODULE : MFW |
174 | STATE : code ROUTINE : mfwInit |
175 +--------------------------------------------------------------------+
176
177 PURPOSE : initialize framework
178
179 */
180
181 // Dec 22, 2004 REF: CRR MFW-SPR-27847 xnkulkar
182 // Description: MFW memory size variable changed from U16 -> U32
183 // Solution: The use of variable U16 has been replaced with U32
184 MfwRes mfwInit (void *externalRoot, U32 dynMemSize)
185 {
186 int i;
187
188 mfwSetFocus(0); /* initially no focus */
189 dynMemSize &= ~(sizeof(MfwMemHdr)-1); /* align to header size */
190 mfwMemDynTotal = dynMemSize;
191 if (dynMemSize)
192 {
193
194 /***************************Go-lite Optimization changes start***********************/
195 mfwRoot = (MfwHdr *)&mfwEorc; /* points to end of chain */
196
197 /***************************Go-lite Optimization changes end***********************/
198 mfwMemBase = (U8 *) externalRoot; /* setup memory handler */
199 mfwMemEnd = (U8 *) externalRoot + dynMemSize;
200 mfwMem.next = 0;
201 mfwMem.len = 0;
202 ((MfwMemHdr *) mfwMemBase)->next = dynMemSize;
203 ((MfwMemHdr *) mfwMemBase)->len = dynMemSize;
204 mfwMemLeft = dynMemSize;
205 memset(mfwMemBase+sizeof(MfwMemHdr),0,
206 dynMemSize-sizeof(MfwMemHdr));
207 }
208 else
209 {
210 mfwRoot = (MfwHdr *) externalRoot; /* setup root pointer */
211
212 /***************************Go-lite Optimization changes start***********************/
213 if (!mfwRoot)
214 mfwRoot = (MfwHdr *)&mfwEorc; /* points to end of chain */
215
216 /***************************Go-lite Optimization changes end***********************/
217 mfwMemBase = 0;
218 mfwMemEnd = 0;
219 mfwMem.next = 0;
220 mfwMem.len = 0;
221 }
222 for (i = 0; i < MfwTypMax; i++) /* init command table */
223 mfwCommand[i] = 0;
224
225 return MfwResOk;
226 }
227
228
229 /*
230 +--------------------------------------------------------------------+
231 | PROJECT : MMI-Framework (8417) MODULE : MFW |
232 | STATE : code ROUTINE : mfwExit |
233 +--------------------------------------------------------------------+
234
235 PURPOSE : finalize framework
236
237 */
238
239 void mfwExit (void)
240 {
241 TRACE_FUNCTION("mfwExit()");
242 }
243
244 /*
245 +--------------------------------------------------------------------+
246 | PROJECT : MMI-Framework (8417) MODULE : MFW |
247 | STATE : code ROUTINE : mfwSignallingMethod|
248 +--------------------------------------------------------------------+
249
250 PURPOSE : Defines the signalling method
251
252 */
253
254 MfwRes mfwSetSignallingMethod (U8 method)
255 {
256 mfwSignallingMethod = method;
257 return MfwResOk; /*return statement added for warning removal*/
258 }
259
260 /*
261 +--------------------------------------------------------------------+
262 | PROJECT : MMI-Framework (8417) MODULE : MFW |
263 | STATE : code ROUTINE : mfwSetFocus |
264 +--------------------------------------------------------------------+
265 PURPOSE : Assign Focus to the passed window
266
267 */
268
269 void mfwSetFocus(MfwHdr *w)
270 {
271 if (satEvtRegistered(SatEvtIdleScreenActivated) == TRUE)
272 {
273 if ((mfwSatIdleWin != 0) && (mfwSatIdleWin == w))
274 {
275 /* x0083025 on Sep 14, 2007 for OMAPS00145866 (adrian) */
276 MMI_TRACE_EVENT("NDH >>> CQ16435 : Send the Idle Screen Available Event to the SIM");
277 satEvtDownload(SatEvtIdleScreen);
278 }
279 }
280
281 mfwFocus = w;
282 return;
283 }
284
285 /*
286 +--------------------------------------------------------------------+
287 | PROJECT : MMI-Framework (8417) MODULE : MFW |
288 | STATE : code ROUTINE : mfwSetSatIdle |
289 +--------------------------------------------------------------------+
290
291 PURPOSE : Set the window which will trigger SAT Event Idle Activated if required
292
293 */
294 void mfwSetSatIdle(MfwHdr *w)
295 {
296 MfwWin *win;
297
298 if (!w)
299 {
300 mfwSatIdleWin = 0;
301 return;
302 }
303
304 win = w->data;
305
306 mfwSatIdleWin = win->elems;
307 return;
308 }
309
310 /*
311 +--------------------------------------------------------------------+
312 | PROJECT : MMI-Framework (8417) MODULE : MFW |
313 | STATE : code ROUTINE : mfwInsert |
314 +--------------------------------------------------------------------+
315
316 PURPOSE : chain up framework element
317
318 */
319
320 MfwHdr *mfwInsert (MfwHdr *h, MfwHdr *e)
321 {
322 if (!e) /* nothing to insert */
323 return 0;
324
325 if (!h) /* use root chain */
326 {
327 e->next = mfwRoot;
328 mfwRoot = e;
329 }
330 else if (h->type == MfwTypWin) /* use window chain */
331 {
332 e->next = ((MfwWin *) (h->data))->elems;
333 ((MfwWin *) h->data)->elems = e;
334 if (mfwFocus == e->next) /* was focus window ? */
335 mfwSetFocus(e); /* yes: reassign focus */
336 }
337 else /* insert into any chain */
338 {
339 return 0;
340 }
341
342 return e;
343 }
344
345
346 /*
347 +--------------------------------------------------------------------+
348 | PROJECT : MMI-Framework (8417) MODULE : MFW |
349 | STATE : code ROUTINE : mfwAppend |
350 +--------------------------------------------------------------------+
351
352 PURPOSE : chain up framework element at end of chain
353
354 */
355
356 MfwHdr *mfwAppend (MfwHdr **h, MfwHdr *e)
357 {
358 if (!e) /* nothing to append */
359 return 0;
360
361 if (!h) /* append to header chain */
362 h = &mfwRoot;
363
364 if ((*h)->type == MfwTypMax) /* empty chain */
365 {
366 if (mfwFocus == *h)
367 mfwSetFocus(e);
368 e->next = *h;
369 *h = e;
370 if(e->type == MfwTypWin || e->type == MfwTypKbd ||e->type == MfwTypTim ||
371 e->type == MfwTypEdt || e->type == MfwTypMnu || e->type == MfwTypIcn)
372 current_mfw_elem = e;
373 return e;
374 }
375
376 while ((*h)->next && (*h)->next->type != MfwTypMax)
377 h = &((*h)->next);
378
379 e->next = (*h)->next;
380 (*h)->next = e;
381 if(e->type == MfwTypWin || e->type == MfwTypKbd ||e->type == MfwTypTim ||
382 e->type == MfwTypEdt || e->type == MfwTypMnu || e->type == MfwTypIcn)
383 current_mfw_elem = e;
384
385 return e;
386 }
387
388
389 /*
390 +--------------------------------------------------------------------+
391 | PROJECT : MMI-Framework (8417) MODULE : MFW |
392 | STATE : code ROUTINE : mfwRemove |
393 +--------------------------------------------------------------------+
394
395 PURPOSE : unchain element and return its root
396
397 */
398
399 MfwHdr **mfwRemove (MfwHdr *e)
400 {
401 MfwHdr **rp, **rpr, *h;
402
403 if (!e) /* nothing to remove */
404 return 0;
405
406 h = e; /* find elements root */
407 while (h->next && h->type != MfwTypMax)
408 h = h->next;
409 if (h->type != MfwTypMax)
410 return 0;
411 h = h->next; /* h points to root element */
412 if (!h) /* remove from header chain */
413 rp = &mfwRoot;
414 else if (h->type == MfwTypWin) /* remove from window chain */
415 rp = &(((MfwWin*)(h->data))->elems);
416 else /* don't remove from normal */
417 return 0;
418
419 rpr = rp;
420 while (*rp && (*rp)->type != MfwTypMax)
421 {
422 if (*rp == e)
423 {
424 *rp = e->next;
425 if (mfwFocus == e) /* first element of window */
426 mfwSetFocus(e->next);
427 /* Nov 05, 2005 REF: OMAPS00049571 Sumanth Kumar. C
428 * Solution: current_mfw_elem variable is updated when any of the elements
429 * such as window, keyboard, timer, etc., are deleted so that the
430 * current_mfw_element does not point to element that has already been freed.
431 */
432 if(e->type == MfwTypWin || e->type == MfwTypKbd ||e->type == MfwTypTim ||
433 e->type == MfwTypEdt || e->type == MfwTypMnu || e->type == MfwTypIcn)
434 current_mfw_elem = e->next;
435 return rpr;
436 }
437 rp = &((*rp)->next);
438 }
439
440 return 0;
441 }
442
443
444 /*
445 +--------------------------------------------------------------------+
446 | PROJECT : MMI-Framework (8417) MODULE : MFW |
447 | STATE : code ROUTINE : mfwParent |
448 +--------------------------------------------------------------------+
449
450 PURPOSE : get parent of given element
451
452 */
453
454 MfwHnd mfwParent (MfwHdr *h)
455 {
456 if (!h) /* no element */
457 return 0;
458
459 while (h->next && h->type != MfwTypMax)
460 {
461 h = h->next;
462 if(!h)
463 {
464 return 0;
465 }
466 }
467 if (h->type != MfwTypMax)
468 return 0; /* ERROR ! */
469 h = h->next; /* h points to root element */
470 if (h && h->type == MfwTypWin) /* parent should be window */
471 return h;
472
473 return 0; /* root element */
474 }
475
476 /*
477 +--------------------------------------------------------------------+
478 | PROJECT : MMI-Framework (8417) MODULE : MFW |
479 | STATE : code ROUTINE : mfwHeader |
480 +--------------------------------------------------------------------+
481
482 PURPOSE : get header of a given element
483
484 */
485
486 MfwHnd mfwHeader (void)
487 {
488 return current_mfw_elem;
489 }
490
491
492 /*
493 +--------------------------------------------------------------------+
494 | PROJECT : MMI-Framework (8417) MODULE : MFW |
495 | STATE : code ROUTINE : mfwControl |
496 +--------------------------------------------------------------------+
497
498 PURPOSE : retrieve element control block
499
500 */
501
502 MfwHnd mfwControl (MfwHdr *h)
503 {
504 if (!h)
505 return 0;
506 if (h->type <= MfwTypNone || h->type >= MfwTypMax)
507 return 0;
508
509 return h->data;
510 }
511
512
513 /*
514 +--------------------------------------------------------------------+
515 | PROJECT : MMI-Framework (8417) MODULE : MFW |
516 | STATE : code ROUTINE : mfwAlloc |
517 +--------------------------------------------------------------------+
518
519 PURPOSE : alloc MFW memory
520
521 */
522
523 // Dec 22, 2004 REF: CRR MFW-SPR-27847 xnkulkar
524 // Description: MFW memory size variable changed from U16 -> U32
525 // Solution: The use of variable U16 has been replaced with U32
526 U8 *mfwAlloc (U32 size)
527 {
528 MfwMemHdr *p, *n, *l;
529 U8 *data_ptr;
530
531 if (!size)
532 {
533 TRACE_ERROR("mfwAlloc(): invalid memory request");
534 return 0;
535 }
536
537 #ifdef SENTINAL_CHECK
538 if (!mfwMemBase)
539 {
540 size += (SENTINEL_SIZE*2);
541 data_ptr = (U8 *) sysAlloc(size);
542 memset(data_ptr, 0x55, SENTINEL_SIZE);
543 memset(data_ptr + (size-SENTINEL_SIZE), 0x55, SENTINEL_SIZE);
544 data_ptr += SENTINEL_SIZE;
545 return data_ptr;
546 }
547
548 size = (U32) mfwMemLarge(size) + (SENTINEL_SIZE*2);
549
550 if (size >= mfwMemLeft)
551 {
552 TRACE_ERROR("mfwAlloc(): no memory");
553 return 0;
554 }
555
556 if (mfwMemBase + mfwMem.next > mfwMemEnd
557 || mfwMemBase + mfwMem.next < mfwMemBase)
558 {
559 TRACE_ERROR("mfwAlloc(): corrupted memory");
560 return 0;
561 }
562
563 p = &mfwMem; /* root of dyn memory */
564 n = (MfwMemHdr *) (mfwMemBase + p->next); /* first free block */
565 while ((U8 *) n < mfwMemEnd)
566 {
567 if (n->len == size) /* fits exactly: */
568 {
569 p->next = n->next; /* just remove from chain */
570
571 mfwMemLeft -= size;
572 if (mfwMemLeft < mfwMemLowWater)
573 mfwMemLowWater = mfwMemLeft;
574
575 data_ptr = (U8 *)n;
576
577 memset(data_ptr, 0x55, SENTINEL_SIZE);
578 memset(data_ptr + size-SENTINEL_SIZE, 0x55, SENTINEL_SIZE);
579 memset(data_ptr + SENTINEL_SIZE, 0, size-(SENTINEL_SIZE*2));
580
581 data_ptr += SENTINEL_SIZE;
582
583 #ifdef TRACE_MEMORY_CHECK
584 /* x0083025 on Sep 14, 2007 for OMAPS00145866 (adrian) */
585 MMI_TRACE_EVENT_P2("MFWAlloc %d bytes in address %p",size,n);
586 mfwCheckMemoryLeft();
587 #endif
588 return data_ptr;
589 }
590
591 if (n->len > size) /* take it from a big one */
592 {
593 l = (MfwMemHdr *) ((U8 *) n + size); /* new header */
594 l->next = n->next; /* setup chain to next */
595 l->len = (U32) (n->len - size); /* remaining memory */
596 p->next += size; /* link with previous block */
597
598 mfwMemLeft -= size;
599 if (mfwMemLeft < mfwMemLowWater)
600 mfwMemLowWater = mfwMemLeft;
601
602 data_ptr = (U8 *)n;
603
604 memset(data_ptr, 0x55, SENTINEL_SIZE);
605 memset(data_ptr + size-SENTINEL_SIZE, 0x55, SENTINEL_SIZE);
606 memset(data_ptr + SENTINEL_SIZE, 0, size-(SENTINEL_SIZE*2));
607
608 data_ptr += SENTINEL_SIZE;
609
610 #ifdef TRACE_MEMORY_CHECK
611 /* x0083025 on Sep 14, 2007 for OMAPS00145866 (adrian) */
612 MMI_TRACE_EVENT_P2("MFWAlloc %d bytes in address %p",size,n);
613 mfwCheckMemoryLeft();
614 #endif
615 return data_ptr; /* allocated me address */
616 }
617 p = n;
618 n = (MfwMemHdr *) (mfwMemBase + n->next);
619 }
620 #else
621 if (!mfwMemBase)
622 return (U8 *) sysAlloc(size);
623
624 size = (U32) mfwMemLarge(size);
625 if (size >= mfwMemLeft)
626 {
627 TRACE_ERROR("mfwAlloc(): no memory");
628 return 0;
629 }
630
631 if (mfwMemBase + mfwMem.next > mfwMemEnd
632 || mfwMemBase + mfwMem.next < mfwMemBase)
633 {
634 TRACE_ERROR("mfwAlloc(): corrupted memory");
635 return 0;
636 }
637
638 p = &mfwMem; /* root of dyn memory */
639 n = (MfwMemHdr *) (mfwMemBase + p->next); /* first free block */
640 while ((U8 *) n < mfwMemEnd)
641 {
642 if (n->len == size) /* fits exactly: */
643 {
644 p->next = n->next; /* just remove from chain */
645 mfwMemLeft -= size;
646 if (mfwMemLeft < mfwMemLowWater)
647 mfwMemLowWater = mfwMemLeft;
648 memset(n,0,size);
649 #ifdef TRACE_MEMORY_CHECK
650 /* x0083025 on Sep 14, 2007 for OMAPS00145866 (adrian) */
651 MMI_TRACE_EVENT_P2("MFWAlloc %d bytes in address %p",size,n);
652 mfwCheckMemoryLeft();
653 #endif
654 return (U8 *) n;
655 }
656 if (n->len > size) /* take it from a big one */
657 {
658 l = (MfwMemHdr *) ((U8 *) n + size); /* new header */
659 l->next = n->next; /* setup chain to next */
660 l->len = (U32) (n->len - size); /* remaining memory */
661 p->next += size; /* link with previous block */
662 mfwMemLeft -= size;
663 if (mfwMemLeft < mfwMemLowWater)
664 mfwMemLowWater = mfwMemLeft;
665 memset(n,0,size);
666 #ifdef TRACE_MEMORY_CHECK
667 /* x0083025 on Sep 14, 2007 for OMAPS00145866 (adrian) */
668 MMI_TRACE_EVENT_P2("MFWAlloc %d bytes in address %p",size,n);
669 mfwCheckMemoryLeft();
670 #endif
671 return (U8 *) n; /* allocated me address */
672 }
673 p = n;
674 n = (MfwMemHdr *) (mfwMemBase + n->next);
675 }
676 #endif
677
678 if ((U8 *)n == mfwMemEnd)
679 {
680 TRACE_ERROR("mfwAlloc(): no memory block big enough to allocate size requested");
681 }
682 else
683 {
684 TRACE_ERROR("mfwAlloc(): Error: free list corruption is likely");
685 }
686
687 return 0;
688 }
689
690
691 /*
692 +--------------------------------------------------------------------+
693 | PROJECT : MMI-Framework (8417) MODULE : MFW |
694 | STATE : code ROUTINE : mfwFree |
695 +--------------------------------------------------------------------+
696
697 PURPOSE : free allocated MFW memory
698
699 */
700
701 // Dec 22, 2004 REF: CRR MFW-SPR-27847 xnkulkar
702 // Description: MFW memory size variable changed from U16 -> U32
703 // Solution: The use of variable U16 has been replaced with U32
704 void mfwFree (U8 *mem, U32 size)
705 {
706 MfwMemHdr *p, *n;
707 U8 check_val[SENTINEL_SIZE];
708 // U32 check_val = 0x55555555;
709
710 memset(&check_val, 0x55, SENTINEL_SIZE);
711
712 #ifdef SENTINAL_CHECK
713 mem -= SENTINEL_SIZE;
714 #endif
715
716 if (!size || !mem )
717 {
718 TRACE_ERROR("mfwFree(): invalid");
719 return; /* nothing to free */
720 }
721
722 #ifdef SENTINAL_CHECK
723 /*
724 ** Check the 4 preceeding bytes to ensure they haven't been changed
725 */
726 if (memcmp(mem, &check_val, SENTINEL_SIZE) != 0)
727 {
728 TRACE_ERROR("mfwFree(): Error: Preceeding Sentinal Bytes have been corrupted");
729 }
730 #endif
731
732 #ifdef TRACE_MEMORY_CHECK
733 // Jan 27, 2005 REF: CRR MMI-SPR-28300 xnkulkar
734 // Description: BMI: memory leak in mfwFree/mfwAlloc ??
735 // Solution: Trace output to print memory address and size freed modified
736 /* x0083025 on Sep 14, 2007 for OMAPS00145866 (adrian) */
737 MMI_TRACE_EVENT_P2("MFWFree address = %p, size : %d bytes",mem,size);
738 #endif
739
740 if (!mfwMemBase)
741 {
742 void *m = mem;
743
744 #ifdef SENTINAL_CHECK
745 /*
746 ** Check the SENTINEL_SIZE last bytes to ensure they haven't been changed
747 */
748 if (memcmp(mem + size + SENTINEL_SIZE, &check_val, SENTINEL_SIZE) != 0)
749 {
750 TRACE_ERROR("mfwFree(): Error: Following Sentinal Bytes have been corrupted");
751 }
752 #endif
753 sysFree(m);
754 return;
755 }
756
757 #ifdef SENTINAL_CHECK
758
759 size = (U32) mfwMemLarge(size) + (SENTINEL_SIZE*2);
760 #else
761 size = (U32) mfwMemLarge(size);
762 #endif
763
764 if ( mem < mfwMemBase || mem >= mfwMemEnd ||
765 mem + size > mfwMemEnd ||
766 mem + size <= mfwMemBase)
767 {
768 TRACE_ERROR("mfwFree(): invalid");
769 return; /* nothing to free */
770 }
771
772 p = &mfwMem; /* root of dyn memory */
773 n = (MfwMemHdr *) (mfwMemBase + p->next); /* first free block */
774
775 /*
776 ** Skip through the Free Link List until we get to where the current pointer
777 ** should be added
778 */
779 while ((U8 *) n < mfwMemEnd && (U8 *) n < mem)
780 { /* search allocated area */
781 p = n;
782 n = (MfwMemHdr *) (mfwMemBase + n->next);
783 }
784
785 /*
786 ** Check that the select memory isn't already free
787 */
788 if (mem == (U8 *) p || mem == (U8 *) n)
789 {
790 TRACE_ERROR("mfwFree(): already free");
791 return; /* already free */
792 }
793
794 /*
795 ** Memory not already free
796 */
797
798 #ifdef SENTINAL_CHECK
799 /*
800 ** Check the 4 last bytes to ensure they haven't been changed
801 */
802 if (memcmp(mem + size - SENTINEL_SIZE, &check_val, SENTINEL_SIZE) != 0)
803 {
804 TRACE_ERROR("mfwFree(): Error: Following Sentinal Bytes have been corrupted");
805 }
806 #endif
807
808 /*
809 ** This memset should only be performed after we are sure that the memory should be freed
810 */
811 memset(mem, 0, size);
812
813 if (p != &mfwMem && (U8 *) p + p->len == mem)
814 { /* adjacent to left free: */
815 p->len += size; /* just add it */
816 }
817 else
818 {
819 p->next = (U32) (mem - mfwMemBase); /* new free link */
820 p = (MfwMemHdr *) mem; /* to new header */
821 p->next = (U32) ((U8 *) n - mfwMemBase); /* link to next */
822 p->len = size;
823 }
824
825 if ((U8 *) n < mfwMemEnd && ((mem + size) == (U8 *) n))
826 { /* adjacent to right free: */
827 p->next = n->next; /* eliminate link and */
828 p->len += n->len; /* eat up the space */
829 }
830
831 mfwMemLeft += size;
832 #ifdef TRACE_MEMORY_CHECK
833 mfwCheckMemoryLeft();
834 #endif
835 }
836
837 // Dec 22, 2004 REF: CRR MFW-SPR-27847 xnkulkar
838 // Description: MFW memory size variable changed from U16 -> U32
839 // Solution: The use of variable U16 has been replaced with U32
840 U32 mfwCheckMemoryLeft(void)
841 {
842 /* x0083025 on Sep 14, 2007 for OMAPS00145866 (adrian) */
843 MMI_TRACE_EVENT_P1("memory left %ld",mfwMemLeft);
844
845 return mfwMemLeft;
846 }
847
848 /*
849 ** This function gives the bounds safety of strncpy, but NULL terminates the string like strcpy
850 **
851 ** parameters : cpyto : the pointer to the destination string
852 ** : cpyfrm : the pointer to the source string
853 ** : len : the maximum length of the destination string including the NULL terminator
854 **
855 ** returns : A character pointer to the destination string if successful, otherwise NULL
856 **
857 ** CQ16507 : strcpy call for string without null termination causing hardware reset
858 */
859
860 char *mfwStrncpy(char *cpyto, const char *cpyfrm, size_t len)
861 {
862
863 if (len <= 0)
864 return (void *)0;
865
866 if (cpyto == (char *)0)
867 return (void *)0;
868
869 strncpy(cpyto, cpyfrm, len-1);
870
871 *(cpyto + (len -1)) = 0x00;
872
873 return cpyto;
874 }
875