Embedded Xinu Kernel Programming 1 BINABUFFALO EDU UNIVERSITY
Embedded Xinu Kernel Programming 1 BINA@BUFFALO. EDU UNIVERSITY AT BUFFALO Amrita-UB-MSES-2013 -13 5/24/2013
Topics 2 �Creating a task/thread �Ready/adding to the queue �Resched/no rescheduling �Semaphores of synchronization and mutual exclusion �Memory operation errors including memory leak Amrita-UB-MSES-2013 -13 5/24/2013
Memory leaks etc. 3 �See http: //www. ibm. com/developerworks/aix/library/au-toughgame/ �IBM developer works is good source of valuable information �Good practices while working with small footprint systems �Though there are tools available to detect most of these, it is always good to know the best practices in any technology and field Amrita-UB-MSES-2013 -13 5/24/2013
Known Pitfalls 4 �These are some of the prominent pitfalls while working with memory at low level �Uninitialized memory char *p = malloc (10); memset(p, ’ ’, 10); �Memory overwrite char *name = (char *) malloc(11); // Assign some value to name memcpy ( p, name, 11); �Memory overead char *ptr = (char *)malloc(10); char name[20] ; memcpy ( name, ptr, 20); Amrita-UB-MSES-2013 -13 5/24/2013
Known Pitfalls (contd. ) 5 �Memory leak: reassignment char *memory. Area = malloc(10); char *new. Area = malloc(10); memory. Area = new. Area; �Memory leak: freeing the parent area first free(memory. Area); //wrong //correct method is given below free( memory. Area->new. Area); free(memory. Area); Amrita-UB-MSES-2013 -13 5/24/2013
Known Pitfalls (contd. ) 6 �Improper handling of return functions char *func ( ) { return malloc(20); // make sure to memset this location to ‘ ’… } void calling. Func ( ) { func ( ); // Problem lies here } Amrita-UB-MSES-2013 -13 5/24/2013
Summary 7 �We discussed some things to pay attention to when designing systems at low level and deal with dynamic memory management. �This is especially critical for small embedded systems with limited memory. �Memory leaks are serious problem resulting in dramatic system slow down at runtime. Amrita-UB-MSES-2013 -13 5/24/2013
- Slides: 7