ReactOS 0.4.15-dev-5895-g2687c1b
int10.c File Reference
#include "videoprt.h"
#include <ndk/kefuncs.h>
#include <ndk/halfuncs.h>
#include <ndk/mmfuncs.h>
#include <debug.h>
Include dependency graph for int10.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define IsLowV86Mem(_Seg, _Off)   ((((_Seg) << 4) + (_Off)) < (0xa0000))
 

Functions

static VOID ProtectLowV86Mem (VOID)
 
static VOID UnprotectLowV86Mem (VOID)
 
NTSTATUS NTAPI IntInitializeVideoAddressSpace (VOID)
 
VP_STATUS NTAPI IntInt10AllocateBuffer (IN PVOID Context, OUT PUSHORT Seg, OUT PUSHORT Off, IN OUT PULONG Length)
 
VP_STATUS NTAPI IntInt10FreeBuffer (IN PVOID Context, IN USHORT Seg, IN USHORT Off)
 
VP_STATUS NTAPI IntInt10ReadMemory (IN PVOID Context, IN USHORT Seg, IN USHORT Off, OUT PVOID Buffer, IN ULONG Length)
 
VP_STATUS NTAPI IntInt10WriteMemory (IN PVOID Context, IN USHORT Seg, IN USHORT Off, IN PVOID Buffer, IN ULONG Length)
 
VP_STATUS NTAPI IntInt10CallBios (IN PVOID Context, IN OUT PINT10_BIOS_ARGUMENTS BiosArguments)
 
VP_STATUS NTAPI VideoPortInt10 (IN PVOID HwDeviceExtension, IN PVIDEO_X86_BIOS_ARGUMENTS BiosArguments)
 

Macro Definition Documentation

◆ IsLowV86Mem

#define IsLowV86Mem (   _Seg,
  _Off 
)    ((((_Seg) << 4) + (_Off)) < (0xa0000))

Definition at line 33 of file int10.c.

◆ NDEBUG

#define NDEBUG

Definition at line 28 of file int10.c.

Function Documentation

◆ IntInitializeVideoAddressSpace()

NTSTATUS NTAPI IntInitializeVideoAddressSpace ( VOID  )

Definition at line 200 of file int10.c.

201{
205}
#define UNIMPLEMENTED
Definition: debug.h:115
#define FALSE
Definition: types.h:117
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
#define NT_ASSERT
Definition: rtlfuncs.h:3310

Referenced by IntVideoPortDispatchOpen().

◆ IntInt10AllocateBuffer()

VP_STATUS NTAPI IntInt10AllocateBuffer ( IN PVOID  Context,
OUT PUSHORT  Seg,
OUT PUSHORT  Off,
IN OUT PULONG  Length 
)

Definition at line 210 of file int10.c.

215{
217#ifdef _M_IX86
218 PVOID MemoryAddress;
219 PKPROCESS CallingProcess = (PKPROCESS)PsGetCurrentProcess();
221 SIZE_T Size;
222
223 TRACE_(VIDEOPRT, "IntInt10AllocateBuffer\n");
224
225 IntAttachToCSRSS(&CallingProcess, &ApcState);
226
227 Size = *Length;
228 MemoryAddress = (PVOID)0x20000;
229
230 Status = ZwAllocateVirtualMemory(NtCurrentProcess(),
231 &MemoryAddress,
232 0,
233 &Size,
236 if (!NT_SUCCESS(Status))
237 {
238 WARN_(VIDEOPRT, "- ZwAllocateVirtualMemory failed\n");
239 IntDetachFromCSRSS(&CallingProcess, &ApcState);
241 }
242
243 if (MemoryAddress > (PVOID)(0x100000 - Size))
244 {
245 ZwFreeVirtualMemory(NtCurrentProcess(),
246 &MemoryAddress,
247 &Size,
249 WARN_(VIDEOPRT, "- Unacceptable memory allocated\n");
250 IntDetachFromCSRSS(&CallingProcess, &ApcState);
252 }
253
254 *Length = (ULONG)Size;
255 *Seg = (USHORT)((ULONG_PTR)MemoryAddress >> 4);
256 *Off = (USHORT)((ULONG_PTR)MemoryAddress & 0xF);
257
258 INFO_(VIDEOPRT, "- Segment: %x\n", (ULONG_PTR)MemoryAddress >> 4);
259 INFO_(VIDEOPRT, "- Offset: %x\n", (ULONG_PTR)MemoryAddress & 0xF);
260 INFO_(VIDEOPRT, "- Length: %x\n", *Length);
261
262 IntDetachFromCSRSS(&CallingProcess, &ApcState);
263
264 return NO_ERROR;
265#else
268#endif
269}
LONG NTSTATUS
Definition: precomp.h:26
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define NO_ERROR
Definition: dderror.h:5
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define TRACE_(x)
Definition: compat.h:76
Status
Definition: gdiplustypes.h:25
#define NtCurrentProcess()
Definition: nt_native.h:1657
#define MEM_RELEASE
Definition: nt_native.h:1316
#define MEM_COMMIT
Definition: nt_native.h:1313
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
_Out_ PKAPC_STATE ApcState
Definition: mm.h:1727
unsigned short USHORT
Definition: pedump.c:61
#define INFO_(ch,...)
Definition: debug.h:159
#define WARN_(ch,...)
Definition: debug.h:157
void * PVOID
Definition: typedefs.h:50
ULONG_PTR SIZE_T
Definition: typedefs.h:80
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
VOID FASTCALL IntDetachFromCSRSS(PKPROCESS *CallingProcess, PKAPC_STATE ApcState)
Definition: videoprt.c:511
VOID FASTCALL IntAttachToCSRSS(PKPROCESS *CallingProcess, PKAPC_STATE ApcState)
Definition: videoprt.c:498
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
struct _KPROCESS * PKPROCESS
Definition: wdm.template.h:201
NTSTATUS NTAPI x86BiosAllocateBuffer(_In_ ULONG *Size, _In_ USHORT *Segment, _In_ USHORT *Offset)
Definition: x86bios.c:152
KAPC_STATE
Definition: ketypes.h:1285
#define PsGetCurrentProcess
Definition: psfuncs.h:17

Referenced by VideoPortQueryServices().

◆ IntInt10CallBios()

VP_STATUS NTAPI IntInt10CallBios ( IN PVOID  Context,
IN OUT PINT10_BIOS_ARGUMENTS  BiosArguments 
)

Definition at line 380 of file int10.c.

383{
384#ifdef _M_AMD64
385 X86_BIOS_REGISTERS BiosContext;
386#else
388#endif
390 PKPROCESS CallingProcess = (PKPROCESS)PsGetCurrentProcess();
392
393 /* Attach to CSRSS */
394 IntAttachToCSRSS(&CallingProcess, &ApcState);
395
396 /* Clear the context */
398
399 /* Fill out the bios arguments */
400 BiosContext.Eax = BiosArguments->Eax;
401 BiosContext.Ebx = BiosArguments->Ebx;
402 BiosContext.Ecx = BiosArguments->Ecx;
403 BiosContext.Edx = BiosArguments->Edx;
404 BiosContext.Esi = BiosArguments->Esi;
405 BiosContext.Edi = BiosArguments->Edi;
406 BiosContext.Ebp = BiosArguments->Ebp;
407 BiosContext.SegDs = BiosArguments->SegDs;
408 BiosContext.SegEs = BiosArguments->SegEs;
409
410 /* Do the ROM BIOS call */
412 Executive,
414 FALSE,
415 NULL);
416
417 /* The kernel needs access here */
419#ifdef _M_AMD64
421#else
423#endif
425
427
428 /* Return the arguments */
429 BiosArguments->Eax = BiosContext.Eax;
430 BiosArguments->Ebx = BiosContext.Ebx;
431 BiosArguments->Ecx = BiosContext.Ecx;
432 BiosArguments->Edx = BiosContext.Edx;
433 BiosArguments->Esi = BiosContext.Esi;
434 BiosArguments->Edi = BiosContext.Edi;
435 BiosArguments->Ebp = BiosContext.Ebp;
436 BiosArguments->SegDs = (USHORT)BiosContext.SegDs;
437 BiosArguments->SegEs = (USHORT)BiosContext.SegEs;
438
439 /* Detach and return status */
440 IntDetachFromCSRSS(&CallingProcess, &ApcState);
441
442 if (NT_SUCCESS(Status))
443 {
444 return NO_ERROR;
445 }
446
448}
CALLBACK16 BiosContext
Definition: bios32.c:45
#define NULL
Definition: types.h:112
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
static VOID UnprotectLowV86Mem(VOID)
Definition: int10.c:62
static VOID ProtectLowV86Mem(VOID)
Definition: int10.c:39
#define KernelMode
Definition: asm.h:34
LONG NTAPI KeReleaseMutex(IN PKMUTEX Mutex, IN BOOLEAN Wait)
Definition: mutex.c:189
#define STATUS_SUCCESS
Definition: shellext.h:65
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
NTSTATUS NTAPI Ke386CallBios(IN ULONG Int, OUT PCONTEXT Context)
Definition: v86vdm.c:614
KMUTEX VideoPortInt10Mutex
Definition: videoprt.c:42
BOOLEAN NTAPI x86BiosCall(_In_ ULONG InterruptNumber, _Inout_ PX86_BIOS_REGISTERS Registers)
Definition: x86bios.c:411
#define KeWaitForMutexObject
Definition: kefuncs.h:557
@ Executive
Definition: ketypes.h:403

Referenced by VideoPortInt10(), and VideoPortQueryServices().

◆ IntInt10FreeBuffer()

VP_STATUS NTAPI IntInt10FreeBuffer ( IN PVOID  Context,
IN USHORT  Seg,
IN USHORT  Off 
)

Definition at line 273 of file int10.c.

277{
279#ifdef _M_IX86
280 PVOID MemoryAddress = (PVOID)((ULONG_PTR)(Seg << 4) | Off);
281 PKPROCESS CallingProcess = (PKPROCESS)PsGetCurrentProcess();
283 SIZE_T Size = 0;
284
285 TRACE_(VIDEOPRT, "IntInt10FreeBuffer\n");
286 INFO_(VIDEOPRT, "- Segment: %x\n", Seg);
287 INFO_(VIDEOPRT, "- Offset: %x\n", Off);
288
289 IntAttachToCSRSS(&CallingProcess, &ApcState);
290 Status = ZwFreeVirtualMemory(NtCurrentProcess(),
291 &MemoryAddress,
292 &Size,
294
295 IntDetachFromCSRSS(&CallingProcess, &ApcState);
296
297 return Status;
298#else
299 Status = x86BiosFreeBuffer(Seg, Off);
301#endif
302}
NTSTATUS NTAPI x86BiosFreeBuffer(_In_ USHORT Segment, _In_ USHORT Offset)
Definition: x86bios.c:181

Referenced by VideoPortQueryServices().

◆ IntInt10ReadMemory()

VP_STATUS NTAPI IntInt10ReadMemory ( IN PVOID  Context,
IN USHORT  Seg,
IN USHORT  Off,
OUT PVOID  Buffer,
IN ULONG  Length 
)

Definition at line 306 of file int10.c.

312{
313#ifdef _M_IX86
314 PKPROCESS CallingProcess = (PKPROCESS)PsGetCurrentProcess();
316
317 TRACE_(VIDEOPRT, "IntInt10ReadMemory\n");
318 INFO_(VIDEOPRT, "- Segment: %x\n", Seg);
319 INFO_(VIDEOPRT, "- Offset: %x\n", Off);
320 INFO_(VIDEOPRT, "- Buffer: %x\n", Buffer);
321 INFO_(VIDEOPRT, "- Length: %x\n", Length);
322
323 IntAttachToCSRSS(&CallingProcess, &ApcState);
324
325 if (IsLowV86Mem(Seg, Off))
327 RtlCopyMemory(Buffer, (PVOID)((ULONG_PTR)(Seg << 4) | Off), Length);
328 if (IsLowV86Mem(Seg, Off))
330
331 IntDetachFromCSRSS(&CallingProcess, &ApcState);
332
333 return NO_ERROR;
334#else
336
339#endif
340}
Definition: bufpool.h:45
#define IsLowV86Mem(_Seg, _Off)
Definition: int10.c:33
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
NTSTATUS NTAPI x86BiosReadMemory(_In_ USHORT Segment, _In_ USHORT Offset, _Out_writes_bytes_(Size) PVOID Buffer, _In_ ULONG Size)
Definition: x86bios.c:205

Referenced by VideoPortQueryServices().

◆ IntInt10WriteMemory()

VP_STATUS NTAPI IntInt10WriteMemory ( IN PVOID  Context,
IN USHORT  Seg,
IN USHORT  Off,
IN PVOID  Buffer,
IN ULONG  Length 
)

Definition at line 344 of file int10.c.

350{
351#ifdef _M_IX86
352 PKPROCESS CallingProcess = (PKPROCESS)PsGetCurrentProcess();
354
355 TRACE_(VIDEOPRT, "IntInt10WriteMemory\n");
356 INFO_(VIDEOPRT, "- Segment: %x\n", Seg);
357 INFO_(VIDEOPRT, "- Offset: %x\n", Off);
358 INFO_(VIDEOPRT, "- Buffer: %x\n", Buffer);
359 INFO_(VIDEOPRT, "- Length: %x\n", Length);
360
361 IntAttachToCSRSS(&CallingProcess, &ApcState);
362 if (IsLowV86Mem(Seg, Off))
364 RtlCopyMemory((PVOID)((ULONG_PTR)(Seg << 4) | Off), Buffer, Length);
365 if (IsLowV86Mem(Seg, Off))
367 IntDetachFromCSRSS(&CallingProcess, &ApcState);
368
369 return NO_ERROR;
370#else
372
375#endif
376}
NTSTATUS NTAPI x86BiosWriteMemory(_In_ USHORT Segment, _In_ USHORT Offset, _In_reads_bytes_(Size) PVOID Buffer, _In_ ULONG Size)
Definition: x86bios.c:232

Referenced by VideoPortQueryServices().

◆ ProtectLowV86Mem()

static VOID ProtectLowV86Mem ( VOID  )
static

Definition at line 39 of file int10.c.

40{
41 /* We pass a non-NULL address so that ZwAllocateVirtualMemory really does it
42 * And we truncate one page to get the right range spanned. */
45 SIZE_T ViewSize = 0xa0000 - PAGE_SIZE;
46
47 /* We should only do that for CSRSS. */
49
50 /* Commit (again) the pages, but with PAGE_NOACCESS protection */
51 Status = ZwAllocateVirtualMemory(NtCurrentProcess(),
53 0,
54 &ViewSize,
58}
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define ASSERT(a)
Definition: mode.c:44
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T ViewSize
Definition: mmfuncs.h:408
#define PAGE_NOACCESS
Definition: nt_native.h:1302
PKPROCESS CsrProcess
Definition: videoprt.c:39

Referenced by IntInt10CallBios(), IntInt10ReadMemory(), and IntInt10WriteMemory().

◆ UnprotectLowV86Mem()

static VOID UnprotectLowV86Mem ( VOID  )
static

Definition at line 62 of file int10.c.

63{
64 /* We pass a non-NULL address so that ZwAllocateVirtualMemory really does it
65 * And we truncate one page to get the right range spanned. */
68 SIZE_T ViewSize = 0xa0000 - PAGE_SIZE;
69
70 /* We should only do that for CSRSS, for the v86 address space */
72
73 /* Commit (again) the pages, but with PAGE_READWRITE protection */
74 Status = ZwAllocateVirtualMemory(NtCurrentProcess(),
76 0,
77 &ViewSize,
81}
#define PAGE_READWRITE
Definition: nt_native.h:1304

Referenced by IntInt10CallBios(), IntInt10ReadMemory(), and IntInt10WriteMemory().

◆ VideoPortInt10()

VP_STATUS NTAPI VideoPortInt10 ( IN PVOID  HwDeviceExtension,
IN PVIDEO_X86_BIOS_ARGUMENTS  BiosArguments 
)

Definition at line 457 of file int10.c.

460{
461 INT10_BIOS_ARGUMENTS Int10BiosArguments;
463
464 if (!CsrProcess)
465 {
467 }
468
469 /* Copy arguments to other format */
470 RtlCopyMemory(&Int10BiosArguments, BiosArguments, sizeof(*BiosArguments));
471 Int10BiosArguments.SegDs = 0;
472 Int10BiosArguments.SegEs = 0;
473
474 /* Do the BIOS call */
475 Status = IntInt10CallBios(NULL, &Int10BiosArguments);
476
477 /* Copy results back */
478 RtlCopyMemory(BiosArguments, &Int10BiosArguments, sizeof(*BiosArguments));
479
480 return Status;
481}
VP_STATUS NTAPI IntInt10CallBios(IN PVOID Context, IN OUT PINT10_BIOS_ARGUMENTS BiosArguments)
Definition: int10.c:380
LONG VP_STATUS
Definition: video.h:153

Referenced by VbeSetMode().