VXDCALL.C
Upload User: lx1888888
Upload Date: 2007-01-04
Package Size: 136k
Code Size: 2k
Category:

Driver Develop

Development Platform:

Visual C++

  1. /* vxdcall.c
  2.  * Copyright (c) 1996 Vireo Software, Inc.
  3.  *
  4.  * Vireo Software offers VtoolsD, the professional toolkit
  5.  * for VxD development in C and C++.
  6.  *
  7.  * Vireo Software
  8.  *      21 Half Moon Hill
  9.  *      Acton, MA  01720
  10.  *      voice: (508) 264-9200
  11.  *      fax:   (508) 264-9205
  12.  *      http:  //world.std.com/~vireo
  13.  *      email: Vireo@vireo.com
  14.  *
  15.  *  This code may be freely used and distributed, as long as
  16.  *  this copyright and permission notice is not removed or modified.
  17.  */
  18. /*
  19.  * This utility routine is used to back-patch the caller
  20.  * to a CD xxxx xxxx instruction.  This hack is required 
  21.  * to work around a bug in the MSVC 4.1 compiler which prevents
  22.  * VxDjmp/ VxDcall from working correctly.
  23.  *
  24.  * See VXDCALL.H for instructions on installing and using this patch.
  25.  *
  26.  * (The compiler generates bad code when an ENUM is used within
  27.  *  inline assembly code.)
  28.  */
  29. // The following is applied if using MSVC 4.1 (4.0 = 1000, 4.1 = 1010)
  30. #if _MSC_VER == 1010
  31. #define PUSHSIZE 5
  32. #define CALLSIZE 5
  33. #define CODESIZE (PUSHSIZE+CALLSIZE)
  34. #define INT20H  0x20CD
  35. #define NOPS    0x90909090
  36. void __declspec(naked) __stdcall  __vxdcallorjmp__(unsigned long svcid)
  37. {
  38.     _asm {
  39.       pushfd                        // protect code we are patching
  40.       cli                           // from re-entry
  41.       push  eax                         
  42.       mov   eax, [esp+8]            // pick up return addr
  43.       lea   eax, [eax-CODESIZE]     // back up to start of call
  44.       mov   word ptr [eax], INT20H  // insert INT 20h instruction
  45.       push  dword ptr [esp+12]      // pick up service id
  46.       pop   dword ptr [eax+2]       // store in instruction stream
  47.       mov   dword ptr [eax+6],NOPS  // filler
  48.       mov   [esp+8], eax            // set return address
  49.       pop   eax
  50.       popfd
  51.       ret   4
  52.     }
  53. }
  54. #endif