Acer 1420P Leaky Handle Driver Fix

Posted January 31, 2010 5:07 PM Categories: Acer 1420p | C/C++ | PDC2009

Download: SDTabletPCFix_1.0.0.0.zip

I wasn’t lucky enough to receive the Acer 1420P laptop given out at PDC this year since I was “staff”, however I wound up picking one up on eBay for a very reasonable price.  I received it last week, added an additional 2GB of RAM, used my Windows Home Server to save off the original hard drive image, and then repaved the machine, installing Windows 7 Ultimate x64, drivers, and applications from scratch.  Earlier this week I noticed the machine was consuming over 3GB of memory with only 1 or 2 applications open.  Looking at Task Manager, the RAM usage by process looked normal, which didn’t match the total memory usage.  After reading the Performance tab a bit more, I saw that the operating system had over 5 million handles open!

Back on the Processes tab, I turned on the Handles column and saw that a process named SDTabletPC.exe was consuming 5 million handles, and it was growing by 10 handles per second.  Check it out for yourself.

SDTabletPC.exe file is installed and run after installing the latest accelerometer driver (v1.00.00.16) from Acer’s support site.  This driver and executable are responsible for rotating the screen based on the machine orientation in tablet mode.  On the original PDC laptop image, an older version of the driver is used which uses rundll32 and load SDTablet.dll.  This version suffers from the same issue but I did not write this fix to work with that version since the newer driver is available.  Back to the research…

Next, I fired up Processor Explorer and saw that almost all of the 5 million handles were open file handles to \Device\STHall, which is the device name for the internal accelerometer.  I downloaded the free copy of IDA, an extremely powerful native code disassembler, and started poking around the executable.  I found several functions which made calls to CreateFile, trying to open the above device, but never closed those handles with a call to CloseHandle.  Excellent.

I was unable to fix the executable by patching in calls to CloseHandle, so I took another approach.  I wrote a very small app in C which finds the SDTabletPC.exe process, opens a process handle to it, enumerates all of its open handles, and forcefully closes all those that are handles to \Device\STHall.  The application then sleeps for 5 seconds and repeats the process forever.

I have put the application and its source code up for download here.

Note that this fix is only for the latest version of the driver shown here, version 1.00.00.16.  Another note:  The leaky handle issue exists in both the original driver included with the PDC laptop image (which runs as a rundll32 process against SDTablet.dll), and this updated driver, but my fix only works for the updated driver.  I know it won’t work with the driver installed in the default PDC image and I can’t guarantee it’ll work with newer drivers, or that newer drivers will even need the fix.

Why force you to upgrade to this version?  Well, as noted on Microsoft’s PDC Tablet site, there’s supposed to be an updated driver on Windows Update that gets rid of the amazingly annoying “Portrait mode may not work with certain applications" (or words to that effect) message box every single time you rotate the machine, however, it’s not on Windows Update.  This driver on Acer’s site is the updated version that fixes that issue.  Sadly, it doesn’t fix the leaking problem.  I know the tablet site says “don’t install any drivers outside Windows Update”, but this is the only way to get the updated rotation driver, or to install the driver with a clean Win7 install.

Update 2/6/10: An additional note for those of you on the original PDC image updating to this newer driver: Be sure to check for the following registry key and if it exists, remove it:

HKLM\Software\Microsoft\Windows\CurrentVersion\Run, SDTablet = Rundll32 %SystemRoot%\System32\SDTablet.dll,MainThread

This key starts the original version of the rotation driver, and it appears it is not properly cleaned up for everyone and may result in TWO processes eating 10 handles per second.  Thanks to Chad Boles for getting the key location for me.

So, if you’re still running the original PDC driver, make sure you head to Acer’s support site and download this version:

image

If you don’t care about the details, download and give it a try.  For those that care about down and dirty C, let’s continue to the details on how it works…

Step 1: Find the SDTabletPC.exe process and get its process ID

Digging around, I found this sample from MSDN which demonstrates how to use the Tool Help Library to take a snapshot of all system processes and query information about them.  For this application, the code can be shortened to just enumerate the running processes, find the one whose process name matches SDTabletPC.exe, and get its process ID:

// Take a snapshot of all processes in the system.
hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if(hProcessSnap == INVALID_HANDLE_VALUE)
{
    DisplayError(L"Could not take snapshot of processes");
    return 1;
}
 
// Set the size of the structure before using it.
pe32.dwSize = sizeof(PROCESSENTRY32);
 
// Retrieve information about the first process,
// and exit if unsuccessful
if(!Process32First(hProcessSnap, &pe32))
{
    DisplayError(L"Could not query first process");
    CloseHandle(hProcessSnap);          // clean the snapshot object
    return(FALSE);
}
 
// Now walk the snapshot of processes, and
// display information about each process in turn
do
{
    if(_wcsicmp(L"SDTabletPC.exe", pe32.szExeFile) == 0)
    {
        pid = pe32.th32ProcessID;
        break;
    }
}
while(Process32Next(hProcessSnap, &pe32));
 
CloseHandle(hProcessSnap);
 

 

Next up, I found this sample from SysInternals which tells us the rest of what we need to know: how to enumerate handles belonging to a specific process, get the name of the handle, and close the handle.  I was able to modify that code into the following:

Step 2: Open a duplicable handle to the process

A handle can be opened to any process by calling OpenProcess and passing in the process ID of the process to open.  By passing the PROCESS_DUP_HANDLE argument, we can later use this handle in a call to NtDuplicateObject to get a queryable handle.

/* open the SDTabletPC.exe process */
if (!(processHandle = OpenProcess(PROCESS_DUP_HANDLE, FALSE, pid)))
{
    DisplayError(L"Could not open SDTabletPC.exe PID.");
    return 1;
}

Step 3: Get all system handles

This code retrieves all system handles from all processes via the NtQuerySystemInformation method.

/* NtQuerySystemInformation won't give us the correct buffer size, so we guess by doubling the buffer size. */
while ((status = NtQuerySystemInformation(SystemHandleInformation, handleInfo, handleInfoSize, NULL)) == STATUS_INFO_LENGTH_MISMATCH)
    handleInfo = (PSYSTEM_HANDLE_INFORMATION)realloc(handleInfo, handleInfoSize *= 2);

Step 4: Enumerate the handles, close those that match

The handles are enumerated, looking for those that belong to the SDTabletPC.exe process based on the process ID which owns the handle.  For each of the handles that match, its ObjectNameInformation is retrieved using the NtQueryObject method.  This stru

ct contains the handle name.  This name is compared with \Device\STHall, and, if it matches, it is closed with a call to DuplicateHandle, which closes the handle by passing in the DUPLICATE_CLOSE_SOURCE parameter.  The application then sleeps for 5 seconds and repeats this process again.

for (i = 0; i < handleInfo->HandleCount; i++)
{
    SYSTEM_HANDLE handle = handleInfo->Handles[ i ];
    HANDLE dupHandle = NULL;
    UNICODE_STRING objectName;
    ULONG returnLength;
 
    /* Check if this handle belongs to the PID the user specified or if it has the access mask below which will hang NtQueryObject */
    if (handle.ProcessId != pid || handle.GrantedAccess == 0x0012019f)
        continue;
 
    /* Duplicate the handle so we can query it. */
    if(!NT_SUCCESS(NtDuplicateObject(processHandle, (HANDLE)handle.Handle, GetCurrentProcess(), &dupHandle, 0, 0, 0)))
        continue;
 
    /* query the handle for its name information */
    if (!NT_SUCCESS(NtQueryObject(dupHandle, ObjectNameInformation, objectNameInfo, objectNameInfoSize, &returnLength)))
    {
        objectNameInfoSize = returnLength;
 
        /* Reallocate the buffer and try again. */
        objectNameInfo = realloc(objectNameInfo, returnLength);
        if (!NT_SUCCESS(NtQueryObject(dupHandle, ObjectNameInformation, objectNameInfo, returnLength, NULL)))
        {
            CloseHandle(dupHandle);
            continue;
        }
    }
 
    /* Cast our buffer into an UNICODE_STRING. */
    objectName = *(PUNICODE_STRING)objectNameInfo;
 
    /* Kill the original handle */
    if (objectName.Length && _wcsicmp(objectName.Buffer, L"\\Device\\STHall") == 0)
        DuplicateHandle(processHandle, (HANDLE)handle.Handle, NULL, NULL, 0, FALSE, DUPLICATE_CLOSE_SOURCE);
 
    /* Kill the duplicated handle */
    CloseHandle(dupHandle);
}

There is a little more going on in the actual application, so be sure to check out the included source code if you’re interested in this kind of thing.  Give it a try and let me know how it works for you.  It’s been running stably for myself and a few other testers, so please let me know if it does not work for you.

And a huge “thank you” to Greg Duncan for testing out the app several times as I wrote it!

Comments (39) -

G. Andrew Duthie
G. Andrew Duthie
2/5/2010 1:37:27 PM #

IIRC, the advice given at PDC was that you should *not* install drivers from Acer&#39;s website for the 1420p, since both the BIOS and image were custom. That may not apply given that you paved the machine, but is it possible that the driver on the Acer website isn&#39;t playing nicely in part due to the custom BIOS?

Reply

Brian Peek
Brian Peek
2/5/2010 1:40:56 PM #

&lt;p&gt;@G Andrew Duthie, I know that&#39;s the advice, but as stated in the blog post above, *every version* of the driver, including the one running on the original, default PDC image, suffer from the leaky handle issue, so it&#39;s not an incompatibility with the new version...it&#39;s every version.&amp;nbsp; If you look at the disassembled code for either version, it&#39;s plain as day:&amp;nbsp; CreateFile(), no CloseHandle().&amp;nbsp; Custom BIOS or not, that&#39;s just bad code.&amp;nbsp; Smile&lt;/p&gt;

Reply

G. Andrew Duthie
G. Andrew Duthie
2/5/2010 2:23:00 PM #

Interesting...just checked and indeed, there&#39;s lots of handles open with the default driver on the default image. Ick.

Reply

Brian Peek
Brian Peek
2/5/2010 2:35:53 PM #

@G Andrdew Duthie, told ya.  ;)  Please try the updated driver and the fix and let me know how it works for you.  Thanks!

Reply

G. Andrew Duthie
G. Andrew Duthie
2/5/2010 2:39:58 PM #

Backing up my current state to WHS, then I&#39;ll try the new driver + fix.

Reply

George V. Reilly
George V. Reilly
2/5/2010 4:20:15 PM #

Sounds like Acer are not using Application Verifier, msdn.microsoft.com/en-us/library/aa468624.aspx, or even elementary stress testing. Or code reviews, for that matter.

Reply

Diego Pérez
Diego Pérez
2/6/2010 12:15:28 AM #

They&#39;re not running &#39;common sense test&#39; either: instead of using the screen rotation API they simulate a hotkey press? try disabling hotkeys in the Graphic options (right click on the desktop , look for the submenu)

Sad... I want to rewrite that code!

Reply

Brian Peek
Brian Peek
2/6/2010 9:56:43 AM #

&lt;p&gt;@Diego, You&#39;re absolutely correct. &amp;nbsp;Digging a bit further into the code, I found 4 functions which send &amp;lt;CTRL&amp;gt; + &amp;lt;ALT&amp;gt; + &amp;lt;ARROW&amp;gt; where &amp;lt;ARROW&amp;gt; is Up/Down/Left/Right (one function for each), which are the exact hot-keys provided by the Intel graphics control panel for screen rotation. &amp;nbsp;Awesome.&lt;/p&gt;

Reply

Dan Tower
Dan Tower
2/11/2010 2:15:22 PM #

Cool, thanks for the fix.  Anyone else have a problem with multi-touch reverting to default mouse mode when coming back from sleep?  I like the touch scroll but I have to reset the touch driver every time I wake it up.

Reply

SonnyZ
SonnyZ
2/11/2010 7:45:43 PM #

@Dan Tower
I don&#39;t have that problem.

The only problem I have is that it won&#39;t shut down correctly. It just sits there saying &quot;Logging Off&quot; for hours.

Reply

Dan Tower
Dan Tower
2/14/2010 2:17:55 AM #

I wasn&#39;t quite right.  It happens for me every time when I return from hibernate but is fine returning from sleep.

Reply

Bobby D
Bobby D
2/15/2010 9:05:00 AM #

Ha!  I have been going back and forth with Acer Technical support for the past couple of days.  They have been continually telling me that my system does not exist (even though I have submitted multiple photos) and attempting to close my ticket.  I&#39;ll drop a line to their executive customer support and see what I can do.  All I have been trying to do is get word on whether or not STMicro will be issuing an updated driver..

Reply

Gary Johnson
Gary Johnson
2/28/2010 2:16:17 PM #

Thank you! This has been driving me crazy.

Reply

Armen Nakashian
Armen Nakashian
3/14/2010 12:29:41 PM #

Does anyone have any information about exactly how/what the rotation software does?  

I think it&#39;s useless/superfluous garbage.  I want to completely disable it and re-purpose the Alt-Ctrl-Del key as a single toggle that will flip between a single portrait and vertical orientation (do we really need to use  it upside down?  Do we really need the 90 and 270 degree orientation?)  

Reply

Brian Peek
Brian Peek
3/14/2010 12:33:49 PM #

@Armen, the rotation software polls the accelerometers 10 times per second and calculates a rough orientation of the device.  It then sends the appropriate ctrl+alt+&lt;arrow&gt; keyboard combination which the Intel tray app for the video card intercepts which does the actual screen rotation.

Reply

Armen
Armen
3/14/2010 12:42:07 PM #

So it sounds like all I need to do is figure is how that Ctrl-Alt-Del key works and do something similar.   Do you happen to know if the the video driver&#39;s rotation also changes the orientation of the mouse/touch surface?  I&#39;ve woken it up a few times from sleep and found that the pointer was not tracking with the display rotation.

Reply

Brian Peek
Brian Peek
3/14/2010 12:45:25 PM #

@Armen, the video driver should be handling the mouse, not sure on the touch.

Not sure if you could intercept that key...it might just be tied directly to the ctrl, alt and del keys.

Reply

Offbeatmammal
Offbeatmammal
3/18/2010 4:37:34 PM #

just wondering what your fix does to battery life and CPU perf on the poor little machine?
Gotta hope Acer decide to release a fix as this is probably already impacting both the battery and performance with a mostly unrequired task (does it at least sleep if the machine is in laptop mode and only activate in tablet mode?)

Reply

Brian Peek
Brian Peek
3/18/2010 5:32:23 PM #

@Offbeatmammal, I haven&#39;t noticed any battery degradation on my machine...it&#39;s not doing a whole lot, is asleep a lot, and runs at the lowest possible tread priority.

Their driver is running constantly....it does not sleep based on orientation mode.

Reply

Diego Perez
Diego Perez
3/26/2010 7:21:11 PM #

Brian, did you take any additional notes about how the driver is consumed by the SDTablet process? I&#39;ve been digging into the disassembled code (using the disassembler you pointed out, which is awsome), but I ended feeling a little dizzy. That would be of help to me since I&#39;d like to re-write the SDTable process.

Reply

Brian Peek
Brian Peek
3/27/2010 1:52:39 AM #

@Diego, I did...I&#39;ll see if I can put it into something a bit more coherent when I have some free time.

Reply

joj
joj
4/17/2010 8:07:36 PM #

I actually get the same behavior on a rundll32 process that is running something related to the driver (I think). Killing it solves the problem, and it doesn&#39;t seem to affect my capability to rotate the screen. I don&#39;t do that much anyway, only when I&#39;m looking at a video or playing some of the touch games.

Reply

Brian Peek
Brian Peek
4/17/2010 8:10:36 PM #

@joj, see the &quot;Update 2/6/10&quot; note in the post.  That&#39;s the original driver still running in the background.

Reply

Gary
Gary
5/9/2010 2:59:16 PM #

Just wanted to point out that you can get driver version 1.00.00.18 (04/06/2010) under Acer Aspire 1825PTZ, but it doesn&#39;t seem to have improved on either the leaky handles or using hotkeys to orient the screen. It also still doesn&#39;t register under the Location and Sensor API, which is a bummer (not holding my breath on that one though). There is one thing, however, which may be my imagination -- the 1420P always kind of sucked in regards to the orientation and standby. I&#39;ve had a few times where it wouldn&#39;t rotate back, or the touch points weren&#39;t in the right place, etc. after resuming from standby and hibernation. I haven&#39;t had that happen so far with these drivers. Again, might be in my head.

Reply

Brian Peek
Brian Peek
5/9/2010 3:14:28 PM #

@Gary, others have reported that issue with standby/hibernation.  It would be nice if the newer version fixes it.  Is my fix still working with this later version?

Reply

Todd Millett
Todd Millett
5/29/2010 11:08:48 AM #

Thanks so much for this fix.  I have noticed this problem for months with my PDC Acer, and was never able to track it down.  I was forced to reboot my machine every few days just to clear the memory.  This fixes the problem.

Reply

Gary
Gary
5/31/2010 10:50:32 PM #

Yup, your fix still works with it. I don&#39;t use it as my primary machine, but so far I&#39;ve had less issues with it.

Reply

Chris
Chris
8/8/2010 4:52:09 AM #

Thanks! I was struggling with this problem since months, and already have given up the machine.

Shame on Acer for releasing such a flawed driver. And shame on Microsoft for not dealing with this issue. And anyway, why does such a basic feature like screen rotation require a custom written driver of a vendor?! I guess this is why Windows tablets will never have the same experience as &quot;You-Know-Who&quot;.

Reply

Tim
Tim
8/9/2010 7:50:24 AM #

Thanks for this fix, Brian.  I have a PDC tablet and this problem was driving me nuts.  There&#39;s another problem that I&#39;ve not seen discussed anywhere and I was wondering if others have seen it (or even if it is related to this bug).  I use my tablet with external monitor/keyboard/mouse.  I&#39;ve tried several different keyboards with the same result - random dropped keystrokes.  Sometimes the keydown takes and sometimes it doesn&#39;t.  Additionally, sometimes the key UP takes and sometimes it doesn&#39;t - tough to blame fat fingers when you hit the . key and stop typing but the screen fills with ...................... until you hit escape.  I was hoping that the handle leak fix would fix this problem as well but it didn&#39;t.  I spoke to one other person who has this system and he reported the same behavior so I don&#39;t think it&#39;s just me...

Reply

heath
heath
8/14/2010 8:45:38 AM #

hi i have the 1420p w7 64 bit and ive just read your posts and managed to check amd i to have overe 1 million and growing at 10 psec . so hears the hard bit . what are handles what rate and how many should i have ? what does this fault do ? and can you describe how a layman like and many others out there can fix it . its too difficult to follow yoyur thread when you guys are speeking geek ? many thanks
heath
ps i love this machine

Reply

Brian Peek
Brian Peek
8/14/2010 2:40:23 PM #

@heath, you can fix it by applying the fix attached to the top of this post.  Just open and run it...nothing more to do.

Reply

Richard
Richard
10/12/2010 8:58:27 AM #

This is truly astonishingly incompetent driver development - and testing!

I&#39;m seeing the same problem with the original driver (often 7+ million handles).  It not only leaks file handles as you found, but regkey handles (HKCU\Software\STMicroelectronics\SDRotation) too - about 1:1.  Does the updated driver leak these as well?

I also have the slow shutdown - mine will get there, but it can take 10s of minutes.

Reply

Brian Peek
Brian Peek
10/12/2010 12:22:35 PM #

@Richard, I don&#39;t recall seeing the registry leak in the later version, but I&#39;m not positive.

Reply

Richard
Richard
10/12/2010 10:32:12 PM #

@Brian, I installed the updated version and I don&#39;t see the registry leak either.  Looks like they fixed one half of the problem and not the other.

Thanks for developing this neat little fix Smile

Reply

Brian Peek
Brian Peek
10/12/2010 10:34:27 PM #

@Richard, thanks for the follow-up.  Glad they managed to fix something along the way.  Smile

Reply

diseño web
diseño web
10/29/2010 10:40:16 PM #

Thanks so much for this fix.  I have noticed this problem for months with my PDC Acer, and was never able to track it down.  I was forced to reboot my machine every few days just to clear the memory.  This fixes the problem.

Reply

acer
acer
11/2/2010 9:04:40 AM #

Yup, your fix still works with it. I don&#39;t use it as my primary machine, but so far I&#39;ve had less issues with it.

Reply

Tim
Tim
12/10/2010 1:23:20 PM #

So since I posted about the dropped keystrokes back in August I&#39;ve resolved the problem.  Instead of plugging directly into the tablet itself, I use an externally powered USB hub for my keyboard and mouse.  Once I put the hub between my keyboard/mouse and the tablet, everything just plain works.

Reply

Brian Baker
Brian Baker United States
12/29/2011 7:13:46 PM #

Brian, thanks for this great fix! I have been dealing with a PDC Laptop that would not shut down properly 99% of the time. A few months ago I noticed that the problem seemed to be related to leaks in the paged pool and non-paged pool. And now finally I have a fix! The system no longer eats up most of the available memory and it shuts down properly every time. Thanks again!

Reply

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

My Info

  • View Brian Peek's profile on LinkedIn

Sponsored Ad

My Book

Sponsored Ad

Calendar

<<  May 2012  >>
MoTuWeThFrSaSu
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

View posts in large calendar