add globalexit API support.
it is not fully functional yet, but initial version is good enough.
developed by Igor, reviewed by miked
fix gcc warnings