Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

How to crash Win2k with CreateToolhelp32Snapshot

Sign in to follow this  
Evil Steve


I was working on a custom assert() statement for my MUD server, and I thought I should test it out. My server has 4 threads running, although they're usually all blocked, except for the main one. Using the default assert() causes the threadthat hit the assert to pause until you dismiss the dialog box, while the other threads carry on working. That could cause some rather nasty bugs, so I decided "Hey, why not enumerate all the threads, and call SuspendThread()?". Excelent, CreateToolhelp32Snapshot() can be set to enumerate all the threads, and I can use OpenThread() on the returned ID.
One problem. I didn't read the docs. So, to save you the trouble, let me post an excerpt:
TH32CS_SNAPTHREAD: Includes all threads in the system in the snapshot. To enumerate the threads, see Thread32First.
To identify the threads that belong to a specific process, compare its process identifier to the th32OwnerProcessID member of the THREADENTRY32 structure when enumerating the threads.

Well, I figured that since the function takes a process ID, it'd enumerate all threads in the process, right? Wrong. My assert() got hit, and immediately suspended all the threads on the machine. Including winamp, MSN, firefox, DruinkIM, and MSVC. Excelent.
Well at least it worked. It did stop the other 3 threads, although the message box didn't show up because explorer was dead. However, I have it working perfectly well just now, which is great. I can assert() away as much as I want.

Oh yeah, I forgot to mention that the image in the previous journal entry doesn't match the caption, since the image was rubbish, and I got a new one. I finished the plugin and released a new update of DruinkIM which includes it. I also got rid of D3DX, since GDI+ can load all sane file formats, and it made my DLL 536kb instead of 112Kb. Which was a rather large increase IMO...
Sign in to follow this  

1 Comment

Recommended Comments

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!