Advanced Memory Management Douglas Boling President Boling Consulting Inc. www.bolingconsulting.com.

Slides:



Advertisements
Similar presentations
4/6/2017 2:06 PM © 2005 Microsoft Corporation. All rights reserved.
Advertisements

MHK200 Module 1: Introduction to Windows CE. MHK200 Overivew Windows CE Design Goals Windows CE Architecture Supported Technologies, Libraries, and Tools.
EMB306 Building Windows CE Devices With DX Support John L. Marcantonio Program Manager Windows CE Multimedia Microsoft Corporation.
Rob Tiffany Mobility Architect Microsoft Corporation WMB306.
EMB304 Building Trustworthy Windows CE Embedded Devices and Applications Ganapathy Raman Program Manager Windows CE Security Team Microsoft Corporation.
INTRODUCTION OS/2 was initially designed to extend the capabilities of DOS by IBM and Microsoft Corporations. To create a single industry-standard operating.
OPERATING SYSTEMS Introduction
Matt Young Windows Mobile Joint Development Program (JDP) Microsoft
Amit Chopra APP209 Introducing “Orcas” Huh ? What’s “Orcas”?
What’s new for Rich Clients? Martin Parry Developer & Platform Group Microsoft Ltd
EMB321 How To Write A Windows CE SDIO Client
Rob Hwacinski Sr. Program Manager Lead Microsoft Corporation WEM206 Ashwin Kulkarni Sr. Product Manager Microsoft Corporation.
Douglas Boling President Boling Consulting Inc. WEM202.
Douglas Boling President Boling Consulting Inc. WEM201.
EMB313 Increasing Developer Productivity With Windows CE 5.0 Matt Young Windows Mobile Joint Development Program (JDP) Microsoft.
CLI339 Building Bluetooth Applications On The Windows CE 5.0 And Windows Mobile Platforms Anil Dhawan Program Manager Windows Mobile.
Future Directions For The Windows CE Operating System Architecture John Hatch Program Manager.
 Demand Technology Software, Inc. Memory Leaks Demand Technology 1020 Eighth Avenue South, Suite 6, Naples, FL phone: (941) fax: (941)
What is Windows Embedded all about? Don Kerr Embedded Strategy Manager Microsoft Australia Andrew McGrath PrincipalBluBits SOL215.
EMB425 Using Advanced Platform Builder Debugger Features James Stulz Program Manager Windows CE Core Tools Microsoft Corporation.
EMB313 Increasing Developer Productivity With Windows CE 5.0
Windows 2000 Memory Management Computing Department, Lancaster University, UK.
Chapter 8 Windows Outline Programming Windows 2000 System structure Processes and threads in Windows 2000 Memory management The Windows 2000 file.
EMB318 Improve Product Quality Using Windows CE Error Reporting (Watson) James Stulz Program Manager Windows CE Core Tools Microsoft Corporation.
EMB315 Non-Volatile Object Store And Hive Based Registry Design For Windows CE Rick Austin Principle Engineer Intermec Corporation.
Windows CE 5.0 Memory Architecture Li-Ming Fan Escalation Engineer Microsoft GCR-GTSC.
EMB426 Windows CE Memory Architecture Steve Maillet CEO/Chief Software Architect EmbeddedFusion.
CLI324 Tablet PC Platform Advanced Topics Software Design Engineer/Test Lead
BIZ208 Windows CE 5.0 Bringing to Market a Broad Range of Devices Dan Javnozon Product Manager MEDG Microsoft Corporation Business Track Presentation.
A+ Guide to Software Managing, Maintaining and Troubleshooting THIRD EDITION Chapter 9 Managing Memory.
EMB423 Creating A Trusted Environment For Windows CE 5.0 Nat Frampton President Real Time Development
Introduction to Embedded Software Development School of software Engineering Introduction to Windows CE.
EMB320 Windows CE 5.0 Image Configuration, Boot Loaders, And Security
Memory Leak Detection Douglas Boling President Boling Consulting Inc.
Win32 Programming Lesson 16: Virtual Memory. Where are we?  We’ve covered the theory of Windows memory, and poked around some  Now let’s use how to.
DEV325 Deploying Visual Studio.NET Applications Billy Hollis Author / Consultant.
EMB422 Advanced Embedded Visual C++ Application Development Control - View Nat Frampton President Real Time Development
Android architecture & setting up. Android operating system comprises of different software components arranges in stack. Different components of android.
Windows Memory Architecture 井民全製作. A Process ’ s Virtual Address Space Every Process has its own private virtual address 32-bits processes  4 GB address.
ME-I-US Windows CE The next version Base on Presentations at Medc 2006 by Boar-Ming Hsieh and John Hatch Avi Kcholi Mobile&Embedded Israeli User Society.
EMB424 Implementing Fault Tolerant Systems in Windows CE 5.0 Nat Frampton President Real Time Development
Rob Tiffany Mobility Architect Microsoft Corporation MOB401.
New Managed Messaging, State, And Notification APIs In Windows Mobile 2005 Gaurav Khanna Developer Evangelist Microsoft India.
EMB427 Writing Real-Time Applications On Windows CE 5.0 Nat Frampton President Real Time Development Corporation
CLI205 Basic Considerations For Mobile PC Application Development Tablet and Mobile PC Technical Evangelist Microsoft Corporation.
PRIOR TO WEB SERVICES THE OTHER TECHNOLOGIES ARE:.
MBL490 Deploying Applications to Smartphone and Microsoft® Powered Pocket PC Marcus Perryman Consultant.
EMB432 Developing Bus Agnostic Drivers for Windows CE David G. Heil Chief Engineer Solutions Division CalAmp Corporation.
CLI325 In Depth – Ink Data Management Mark Hopkins Programmer Writer Tablet and Mobile PC Group Microsoft Corporation.
Best Practices Steve Maillet Chief Software Architect EmbeddedFusion ECE401 Best Practices For Driver Development.
SVR201 SQL Server 2005 Mobile Edition: The Evolution Of SQL Server CE Scott Smith Program Manager Visual Studio for Devices Microsoft Corporation.
CLI210 Introduction To Managed Development For Devices With Visual Studio 2005 Scott D. Smith Program Manager Visual Studio for Devices Microsoft Corporation.
Ibraheem Osama Mohamed Mobile Developer-Rashdan IT.
Win32 Programming Lesson 19: Introduction to DLLs.
Step-by-Step Migration and Adoption Mark Michaelis Architect, Author, and Trainer Eric Lee Microsoft Product Manager Visual Studio 2005 Team Foundation.
Windows CE Services Douglas Boling President Boling Consulting Inc.
Windows Small Business Server 2003 R2 Powering Small Businesses.
COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.
Gowtham Prasad K N Partner Technical Consultant | Microsoft Corporation |
Windows CE Overview Features & Architecture 김동혁.
Introduction to ASP.NET 2.0
Developing Hybrid Apps on Microsoft Azure Stack
Windows Internals Brown-Bag Seminar Chapter 1 – Concepts and Tools
Deploying Windows Embedded with Style
Windows CE Memory Management
MAP & ACT Pre deployment planning for Windows 7 or Server 2008 R2
1/14/2019 3:57 AM © 2004 Microsoft Corporation. All rights reserved.
Delivering great hardware solutions for Windows
Overview of System Development for Windows CE.NET
Introduction to ASP.NET Parts 1 & 2
Presentation transcript:

Advanced Memory Management Douglas Boling President Boling Consulting Inc.

Speaker Douglas Boling bolingconsulting.com Author – “Programming Microsoft Windows CE 3 rd Edition” Trainer – Classes on Windows CE App Development Windows CE OAL Development Consultant – Work with companies to help their application and platform development efforts

M anagement T ools C ommunications & M essaging Device Update Agent Software Update Services Live Communications Server Exchange Server Internet Security and Acceleration Server Speech Server Image Update L ocation S ervices M ultimedia MapPoint DirectX Windows Media Visual Studio 2005 D evelopment T ools MFC 8.0, ATL 8.0 Win32 N ative M anaged S erver S ide L ightweight R elational SQL Server 2005 Express EditionEDB D ata P rogramming M odel D evice B uilding T ools D evice B uilding T ools H ardware/ D rivers Windows XP DDK Windows Embedded Studio Platform Builder OEM/IHV Supplied BSP (ARM, SH4, MIPS) OEM Hardware and Standard Drivers Standard PC Hardware and Drivers SQL Server 2005SQL Server 2005 Mobile Edition ASP.NET Mobile ControlsASP.NET.NET Compact Framework.NET Framework Microsoft Operations Manager Systems Management Server

Agenda Slot Based Memory Model DLL Loading Issues Managed Applications

Virtual Address Space 0000 FFFF User Mode Space Kernel Mode Space Accessible in user and kernel modes Accessible in kernel mode only

Windows CE Memory Architecture Windows CE uses a unified, 4 Gigabyte virtual address space The address space is divided into kernel and user mode spaces Kernel mode code has access to the entire address space User mode code can only access the lower 2 Gigabytes

Active Process Windows XP Memory Map System Reserved (kernel mode space) FFFF ApplicationSpace

Windows CE Memory Map System Reserved (kernel mode space) FFFF Active Process Application Space Reserved Large Memory Area (memory mapped files) Application Space

Large Memory Area (memory mapped files) User Virtual Space Resource only DLLs (Slot 63) Application Slots (Slots 2-33) Current Application (Slots 0-1) 2 Gigabytes Divided into MByte Slots 30 slots for LMA 31 slots for applications 2 slots for current application 1 resource slot

System Memory Map Memory space is divided into 33 slots One process per slot Slot 0 contains active process Remainder of memory shared or reserved

Application Memory Map COREDLL.DLL Read only data 03FF FFFF Code Read write data reserved Other ROM DLLs Resources Stack (reserved space) Heap (reserved space) Free virtual space Application Specific Space ROM DLL space DLL Space (Constant for all applications) non-ROM DLLs

Application Memory Map Application space 64 Megabytes DLLs mapped into upper 32 Meg DLL static data mapped into lower 32M EXE code, heaps, stack, and RAM DLL use lower 32 Meg No way for an application to allocate memory above 32M

Problems with Memory Architecture 32 Meg isn’t that big Application code, data DLLs loaded by application DLLs must be loaded at a system wide unique address Windows CE loads all DLLs at a unique address across the entire system Gaps between XIP regions are not used by Windows CE for loading DLLs

Living in the Box Process limit of 32 Meg virtual space Is this a problem? Where? Virtual Allocations Large Allocations

VirtualAlloc The base memory allocation function is Parameters lpAddressCommit Address dwSizeSize of block flAllocationTypeMEM_RESERVE, MEM_COMMIT flProtect Protection flags LPVOID VirtualAlloc (LPVOID lpAddress, DWORD dwSize, DWORD flAllocationType, DWORD flProtect);

Virtual Memory Max 32 Meg address space per process You can get around this by using memory mapped objects Allocated on a page basis Virtual memory reserved on 64K boundaries Reserve large blocks then commit later

Limited Virtual Mem Space Applications need to consider their limited virtual memory NT applications have 2 Gigabytes CE applications have only 32 Megabytes Remember: virtual memory is reserved on 64K boundaries int i; PBYTE pMem[512]; // Allocate 512 pages with one call each allocation for (i = 0; i < 512; i++) { pMem[i] = (PBYTE)VirtualAlloc (0, PAGESIZE, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); }

Limited Virtual Mem Space Solutions: Reserve virtual memory in large amounts... …then commit later as needed Or, use Memory Mapped Objects They are not placed in the process’s slot int i; PBYTE pBase, pMem[512]; pBase = (PBYTE)VirtualAlloc (0, 512*PAGESIZE, MEM_RESERVE, PAGE_READWRITE); for (i = 0; i < 512; i++) { pMem[i] = (PBYTE)VirtualAlloc (pBase[PAGESIZE * i], PAGESIZE, MEM_COMMIT, PAGE_READWRITE); }

Large Virtual Allocs Windows CE supports requests for large (> 2Meg) VirtualAlloc calls Space is allocated outside of the 32M box Same “shared” space used by memory mapped objects Block is not protected from other apps Allocations must be reserved first then committed later

Large Virtual Allocs FFFF Active Process Application Space Large Memory Area Application Space Large VAllocs go here

DLL Load Positioning Windows CE has specific rules on how DLLs are positioned in memory These rules can cause problems for the unaware…

DLL Load Positioning 0000 DLLs Stack Heap DLL A Code DLLs Stack Heap DLL A DLL B DLL C Code DLLs Stack Heap DLL A DLL D DLL C Code

DLL Load Positioning DLL load address is dependant on all processes loaded in the system On open systems, you can’t predict if this problem will hit you DLLs are loaded on 64K boundaries The more DLLs the bigger the problem Misuse of multiple XIP Regions exacerbate the problem

Multiple XIP Regions OS DLLs Code Stack Heap First XIP Region XIP Region 2 XIP Region 3 Reserved Stack Heap DLL A Code First Load Address

Multiple XIP Regions The system reserves the space from the top of the first region to the bottom of the last Any gaps are not used to locate DLLs Windows Mobile systems before 5.0 use multiple XIP regions

DLL Problem Workarounds Fewer DLLs Every DLL takes up at least 64 Kbytes DLL size just under multiples of 64K It’s the regions that are important Move code from.DLL to.EXE Load DLLs in specific order Have large EXEs load their DLLs first

Windows Mobile 5.0 Updates no longer depend on multiple XIP regions This will solve the problem Check out the talks here at the DevCon

Kernel DLLs Kernel DLLs are quite powerful Inject a DLL into the kernel’s process space Have access to all sorts of cool information This is how lots of tools work CeLog Shim Engine Profiling (5.0) KCover

Kernel DLLs Don’t link to standard Win32 APIs The ‘reserved’ parameter in LibMain points to KernelLibIoControl BOOL KernelLibIoControl (HANDLE hModule, DWORD dwIoControlCode, LPVOID lpInBuf, DWORD nInBufSize, LPVOID lpOutBuf, DWORD nOutBufSize, LPDWORD lpBytesReturned );

Kernel DLLs All of this discussion is interesting, but almost all is unsupported. DON’T COMPLAIN if it doesn’t work Today, tomorrow, or ever!

Managed Code Managed Applications live within the slot Memory is allocated within the slot No matter how large the allocation

Managed Code Managed code loads DLLs on demand Native DLLs are treated as Win32 DLLs Managed DLLs are not Loaded as data by the runtime

Summary 32/64 MB Limit This problem has only been pushed out DLL Load Issue Problem in older devices Managed processes still have limits Memory allocated within slot

Questions bolingconsulting.com

While at MEDC 2005… Fill out an evaluation for this session Randomly selected instant WIN prizes! Randomly selected instant WIN prizes! Use real technology in a lab Instructor led Reef E/F & Breakers L Self-paced Reef B/C Self-paced Reef B/C Visit the Microsoft Product Pavilion in the Exhibit Hall Shorelines B in the Exhibit Hall Shorelines B

After The Conference… Develop Build InstallBuildJoin Install Enter Enter Join Full-featured trial versions of Windows CE and/or Windows XP Embedded Cool stuff & tell us about it: msdn.microsoft.com/embedded/community msdn.microsoft.com/embedded/community Windows Embedded Partner Program: Windows Mobile 5.0 Eval Kit including Visual Studio 2005 Beta 2 Mobile2Market Contest and win up to $25000: mobile2marketcontest.com mobile2marketcontest.com Microsoft Solutions Partner Program: partner.microsoft.com partner.microsoft.com

Tools & Resources msdn.microsoft.com/ embedded microsoft.public. windowsxp.embedded windowsce.platbuilder windowsce.platbuilder windowsce.embedded.vc windowsce.embedded.vc blogs.msdn.com/ mikehall Windows CE 5.0 Eval Kit Windows XP Embedded Eval Kit msdn.microsoft.com/ mobility microsoft.public. pocketpc.developer smartphone.developer dotnet.framework.compactframework blogs.msdn.com/ windowsmobile vsdteam netcfteam Windows Mobile 5.0 Eval Kit Websites Newsgroups Blogs Tools Build Develop

© 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.