Вы находитесь на странице: 1из 6

Real Time Module for Windows 7/XP - CodeProject

Not quite what you are looking for? You may want to try: ×
Bypassing Windows XP Logon Password using bootkit
Designing Asynchronous Processing Using COM+ Queued Services
highlights off

7,678,783 members and growing! (24,734 online)

Email Password Sign in Join ✔


Remember me? Lost password?

Home Articles Questions & Answers Learning Zones Features Help! The Lounge Real-Time module windows XP

» General Reading » Hardware & System » General

Licence CPOL See Also


Real Time Module for Windows 7/XP First Posted
Views
2 Sep 2007
55,097
More like this
More by this author
By khavkin@sandy.ru | 1 Mar 2011 Downloads 594
Bookmarked 58 times
WinXP C++ Visual-Studio Dev Advanced Win7

This article presents the Hadcon's real time module for Windows 7/XP

Article Browse Code Stats Revisions (4) 2.98 (21 votes) 32 Sponsored Links

New Team Foundation Server 2010


Download source files - 597.8 KB Hosting - Click Here!
Download demo project - 1.36 MB Get NEW Hosted Team Foundation
Server (TFS)...
www.discountasp.net

Data Dynamics Reports for Windows


Forms, ASP.NET
Data Dynamics Reports for Business
Reporting...
www.gcpowertools.com

Resco MobileApp Studio


Resco MobileApp Studio is a
Microsoft Visual...
www.resco.net

See Also...
XFxDetect - A utility to detect which
versions of .Net are installed
XFxDetect inspects registry and file
system of...
Http Monitor for Webbrowser
Control
The ATL COM DLL that captures
requests from...
A Type-safe Generic Pointer
A safer alternative to void*, any_ptr
Introduction can...
Suppress Flickering Scrollbars in
For a variety of business and technical reasons, Microsoft Windows Vista, XP/2000 operating systems Autosizing CListCtrl
are increasingly being considered as a platform for deployment of real-time systems. The reasons How to avoid flickering scrollbars
include: that appear...

1. The many applications available on the platform AI for Target Number Game Using
2. The variety of development tools available on the platform Genetic Algorithm
3. The richness of the Microsoft Win32 application programming interface (API) Implementing AI for Target Number
4. The large number of developers, support personnel, and end users who are familiar with the Game using a...
system

The Hadcon's real time module (RTM) has been developed to bring "hard " real time capabilities (such Announcements
as creation of timers, system thread, of management by resources – memory, ports, interrupts) to
Windows, excepting necessity of creating of the driver.

http://www.codeproject.com/KB/system/RealTimeModule.aspx[03/04/2011 21:32:26]
Real Time Module for Windows 7/XP - CodeProject

The Daily Insider


RTM Architecture 30 free programming books
Daily News: Signup now.
Precise execution of events is critical in a real-time system. RTM provides complete flexibility to the
developer to determine the appropriate timer resolution for their system. Timer interval values can be
set between 100 microsecond and 1 millisecond (100,200,500,1000). The timer interval is default inside
of [AddNewInst] section rtmdrv.inf file's HKR,,TimerQuantum,,500 .

RTM uses the "mixed" code i.e. timer's, interrupt's routines (working in Ring 0) and user routines
(working in Ring 3) are incorporated in one DLL module.
Real-time components (timer, system thread and interrupt routines) must be locked in memory to
avoid latencies due to page faults. Therefore RTM defines its own sections for location of a code, data
and stack using the data_seg , code_seg , and bss_seg pragmas.

Collapse | Copy Code


//
//
#pragma code_seg( "RTMCODE ")
Specifies a code section where functions are to be allocated.
For example:
#pragma code_seg( "RTMCODE ")
void timer1(unsigned dwmess )
{
/*
code
*/
..................
}
#pragma code_seg()
#pragma data_seg( "RTMDATA ")
Specifies a code section where initialized data are to be allocated.
For example:
#pragma data_seg( "RTMDATA ")
char buff[10] = {0};
int k1 = 0;
#pragma data_seg()
#pragma bss_seg( "RTMBSS ")
char buff[10];
int k1;
#pragma bss_seg()

Timers
RTM uses the system timer.The system timer generates system ticks at a fixed rate of one tick per
millisecond(or 100, 200 ,500 microsecond), which is the rate at which a timer interrupt is generated
and serviced by the operating system (interrupt service routine ISR).
RTmCreateTimer function lets you attach a handling routine to an timer interrupt, much the same
way that the RTM timer routines allow you to associate a handling routine with a given timer expiration.
RTM timers are not synchronization objects which means threads cannot wait for single objects with an
RTM timer handle.

This is in contrast to the Windows waitable timer, which is an object on which a thread can wait, or
against which a thread can receive notification.

http://www.codeproject.com/KB/system/RealTimeModule.aspx[03/04/2011 21:32:26]
Real Time Module for Windows 7/XP - CodeProject

Example Code

Collapse | Copy Code


#pragma code_seg( "RTMCODE ")
//
//
void timer1(unsigned dwmess )
{
int i;
unsigned nstate;
unsigned nvalue;
unsigned short ndigport;
if(nstop ) return ;
if(initLpt == 0)
{
_asm {
mov dx,378h
mov ax,0
out dx,ax ;//outp(BASE_LPT,0);
add dx,2; CR
mov ax,2eh
out dx,ax ;//outp(BASE_LPT+CR,0x2e);
}
initLpt =1;
rtmsqrt(1.5);
/*
code
*/
..................
}
#pragma code_seg()
void func()
{
int error;
HANDLE tm;
if(RtmInit(hRTMDLL,KERNEL_MODE) == -1) return 0;
RtmDebug(hRTMDLL ,TRUE);
tm = RtmCreateTimer
(hRTMDLL ,timer_anl,0x2000,stanl.quantum,KERNEL_MODE);
RtmStartTimer(hRTMDLL ,tm,0x3000);
error = RtmTimerPostMessage(hRTMDLL ,tm,0x100);
}

Using Threads
The RtmCreateThread function creates a system thread (See: PsCreateSystemThread in the
DDK for Windows XP/2000).
You can set the priority value for the specified thread using KeSetPriorityThread and
KeSetBasePriorityThread functions.
Inside of the body thread function, we can use majority DDK functions.
RTM thread defines own sections for location of a code.

Collapse | Copy Code


#pragma code_seg( "RTMTHR ")
//
// thread code
//
#pragma code_seg()

Example Code

Collapse | Copy Code


#pragma code_seg( "RTMTHR ")
//
//
void writetofile(PWSTR pfl,UINT addr,int nsize)
{
IO_STATUS_BLOCK IoStatus;
OBJECT_ATTRIBUTES objectAttributes;
HANDLE FileHandle = NULL;
UNICODE_STRING fileName1;
NTSTATUS status;
fileName1.Buffer = NULL;
fileName1.Length = 0;
fileName1.MaximumLength = 256;
DbgPrint("start");
fileName1.Buffer = (unsigned short *)ExAllocatePool(PagedPool,
fileName1.MaximumLength);
DbgPrint("111");
RtlZeroMemory(fileName1.Buffer, fileName1.MaximumLength);
status = RtlAppendUnicodeToString(&fileName1, pfl);
InitializeObjectAttributes (&objectAttributes,
(PUNICODE_STRING)&fileName1,
OBJ_CASE_INSENSITIVE,
NULL,
NULL );
status = ZwCreateFile(&FileHandle,
FILE_APPEND_DATA,
&objectAttributes,
&IoStatus,

http://www.codeproject.com/KB/system/RealTimeModule.aspx[03/04/2011 21:32:26]
Real Time Module for Windows 7/XP - CodeProject

0,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_WRITE,
FILE_OPEN_IF,
FILE_SYNCHRONOUS_IO_NONALERT,
NULL,
0 );
if(NT_SUCCESS(status))
{
ZwWriteFile(FileHandle,
NULL,
NULL,
NULL,
&IoStatus,
(void *)addr,
nsize,
NULL,
NULL );
ZwClose(FileHandle);
DbgPrint ("Close file");
}
if(fileName1.Buffer)
ExFreePool(fileName1.Buffer);
}
int systhread(void *param)
{
unsigned int _cr3 = 0;
PVOID pv;
PHYSICAL_ADDRESS pf;

n_count_task++;
if(n_count_task == 10)
{
_asm mov eax,cr3
_asm mov _cr3,eax

pf.HighPart = 0;
pf.LowPart = _cr3;
pv = MmGetVirtualForPhysical (pf);
writetofile(L"\\??\\C:\\tmp\\qqq1",(UINT)pv ,0x1000);
}
return 0;
}
#pragma code_seg()
void func()
{
int error;
HANDLE tm;
HANDLE th;
if(RtmInit(hRTMDLL,KERNEL_MODE) == -1) return 0;
th = RtmCreateThread(hRTMDLL ,(THREAD_START_ROUTINE)systhread,NULL);
}

Interrupts
RTM allows a process to directly interface with a device without having to write a Windows driver via
RtmConnectInterrupt or RtmHookInterrupt functions. A process can attach to an interrupt
handler using RtmConnectInterrupt function (See: HalGetInterruptVector in the DDK for
Windows XP/2000).
The RtmHookInterrupt function allows to hook an interrupt.

Collapse | Copy Code


typedef struct _tagRTMINTERUPT {
INTERFACE_TYPE itype;
ULONG nVector ;
ULONG BusNumber ;
ULONG VenID ;
ULONG DevID;
unsigned char bShared;
void *lpParameter;
INTERRUPT_ROUTINE newintr;
) RTMINTERRUPT;

Example Code

Collapse | Copy Code


#pragma data_seg( "RTMDATA ")
int _isr = 0;
#pragma data_seg()
//
//
void newintr(void *pv)
{
_isr++;
/*
-------------------------
*/
}
int func1()
{
HANDLE tm; int count;
RTMCONNINTERRUPT cinter;
HANDLE pi,pi1;

http://www.codeproject.com/KB/system/RealTimeModule.aspx[03/04/2011 21:32:26]
Real Time Module for Windows 7/XP - CodeProject

if(RtmInit(hRTMDLL, KERNEL_MODE) == -1) return 0;


cinter.BusNumber = 1;
cinter.DevID = 0x2f00;
cinter.nVector =0;
cinter.VenID = 0x14f1;
cinter.itype = PCIBus;
cinter.lpParameter = NULL;
cinter.newintr = newintr;
pi = RtmConnectInterrupt(hRTMDLL ,&cinter);
cinter.BusNumber = 0;
cinter.nVector =1;
cinter.itype = Isa;
cinter.lpParameter = NULL;
cinter.newintr = newintr;

pi1 = RtmHookInterrupt (hRTMDLL ,&cinter);


count = _isr;
count = _isr;
count = _isr;
RtmUnhookInterrupt (hRTMDLL ,pi1);
}

E-mail: info@hadcon.ru
URL: http://www.hadcon.ru

License
This article, along with any associated source code and files, is licensed under The Code Project Open
License (CPOL)

About the Author

khavkin@sandy.ru

Russian Federation

Member

Sign Up to vote for this article


Article Top

Comments and Discussions

You must Sign In to use this message board. (secure sign-in)


FAQ Search

Noise Tolerance Medium


Medium Layout Normal
Normal Per page 25
25 Update

Msgs 1 to 25 of 32 (Total in Forum: 32) (Refresh) First Prev Next

visual studio 2005 LNK1104 LIBC.LIB not found devCoder 3:43 30 May '09

IOPL_x macro or const not defined devCoder 4:52 30 May '09

demo does not work-and missing function exporting from dll devCoder 23:26 30 May '09

devioctl.h smart_dummies 22:54 12 Mar '09

Re: devioctl.h khavkin@sandy.ru 0:19 13 Mar '09

Re: devioctl.h smart_dummies 3:45 13 Mar '09

http://www.codeproject.com/KB/system/RealTimeModule.aspx[03/04/2011 21:32:26]
Real Time Module for Windows 7/XP - CodeProject

Hardware RealTime Jarin 12:55 6 Jan '09

[Message Deleted] Mikael Sundfors 12:49 25 Nov '08

Re: My vote of 1 khavkin@sandy.ru 2:58 26 Nov '08

Did not heal me NGS 549672 6:51 25 Nov '08

lib fiels JimmyO 0:55 17 Dec '07

Where is the source code ? Bruce Zhao 4:14 30 Sep '07

useless & unstable hledejto 22:38 17 Sep '07

Re: useless & unstable khavkin@sandy.ru 0:34 18 Sep '07

Re: useless & unstable khavkin@sandy.ru 2:05 26 Sep '07

Realtime applications? Shawn Poulson 3:40 4 Sep '07

Hard job to do this..... kennychou 0:15 4 Sep '07

Compilation Error Vep 22:51 3 Sep '07

Re: Compilation Error khavkin@sandy.ru 23:44 3 Sep '07

Re: Compilation Error khavkin@sandy.ru 2:01 26 Sep '07

Naive..... Anton Bassov 14:00 3 Sep '07

Re: Naive..... khavkin@sandy.ru 23:40 3 Sep '07

Re: Naive..... [modified] Valery A. Boronin 1:35 6 Sep '07

Re: Naive..... khavkin@sandy.ru 3:24 6 Sep '07

Re: Naive..... Anton Bassov 9:23 7 Sep '07

Last Visit: 19:00 31 Dec '99 Last Update: 15:30 3 Apr '11 1 2 Next »

General News Question Answer Joke Rant Admin

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+PgUp/PgDown to switch pages.

link | Privacy | Terms of Use | Mobile Copyright 2007 by khavkin@sandy.ru


Last Updated: 1 Mar 2011 Everything else Copyright © CodeProject, 1999- 2011
Web24 | Advertise on the Code Project

http://www.codeproject.com/KB/system/RealTimeModule.aspx[03/04/2011 21:32:26]