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

How to crash Win2k with CreateToolhelp32Snapshot

Sign in to follow this  
Evil Steve

281 views

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:
Quote:
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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!