ReactOS 0.4.16-dev-1878-g24e88af
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 203 of file int10.c.

204{
208}
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42
#define FALSE
Definition: types.h:117
#define NT_ASSERT
Definition: rtlfuncs.h:3327

Referenced by IntVideoPortDispatchOpen().

◆ IntInt10AllocateBuffer()

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

Definition at line 213 of file int10.c.

218{
220#ifdef _M_IX86
221 PVOID MemoryAddress;
222 PKPROCESS CallingProcess;
224 SIZE_T Size;
225
226 TRACE_(VIDEOPRT, "IntInt10AllocateBuffer\n");
227
228 /* Perform the call in the CSRSS context */
229 if (!IntAttachToCSRSS(&CallingProcess, &ApcState))
231
232 Size = *Length;
233 MemoryAddress = (PVOID)0x20000;
234
235 Status = ZwAllocateVirtualMemory(NtCurrentProcess(),
236 &MemoryAddress,
237 0,
238 &Size,
241 if (!NT_SUCCESS(Status))
242 {
243 WARN_(VIDEOPRT, "- ZwAllocateVirtualMemory failed\n");
244 IntDetachFromCSRSS(CallingProcess, &ApcState);
246 }
247
248 if (MemoryAddress > (PVOID)(0x100000 - Size))
249 {
250 ZwFreeVirtualMemory(NtCurrentProcess(),
251 &MemoryAddress,
252 &Size,
254 WARN_(VIDEOPRT, "- Unacceptable memory allocated\n");
255 IntDetachFromCSRSS(CallingProcess, &ApcState);
257 }
258
259 IntDetachFromCSRSS(CallingProcess, &ApcState);
260
261 *Length = (ULONG)Size;
262 *Seg = (USHORT)((ULONG_PTR)MemoryAddress >> 4);
263 *Off = (USHORT)((ULONG_PTR)MemoryAddress & 0xF);
264
265 INFO_(VIDEOPRT, "- Segment: %x\n", *Seg);
266 INFO_(VIDEOPRT, "- Offset: %x\n", *Off);
267 INFO_(VIDEOPRT, "- Length: %x\n", *Length);
268
269 return NO_ERROR;
270#else
273#endif
274}
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:33
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define TRACE_(x)
Definition: compat.h:76
Status
Definition: gdiplustypes.h:25
#define NtCurrentProcess()
Definition: nt_native.h:1660
#define MEM_RELEASE
Definition: nt_native.h:1319
#define MEM_COMMIT
Definition: nt_native.h:1316
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1311
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
_Out_ PKAPC_STATE ApcState
Definition: mm.h:1768
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(_In_ PKPROCESS CallingProcess, _In_ PKAPC_STATE ApcState)
Detach the current thread from the CSRSS process. This routine is to be invoked after a previous succ...
Definition: videoprt.c:616
BOOLEAN FASTCALL IntAttachToCSRSS(_Outptr_ PKPROCESS *CallingProcess, _Out_ PKAPC_STATE ApcState)
Attach the current thread to the CSRSS process. The caller must detach from the process by invoking I...
Definition: videoprt.c:589
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4539
NTSTATUS NTAPI x86BiosAllocateBuffer(_Inout_ ULONG *Size, _Out_ USHORT *Segment, _Out_ USHORT *Offset)
Definition: x86bios.c:151
KAPC_STATE
Definition: ketypes.h:1711

Referenced by VideoPortQueryServices().

◆ IntInt10CallBios()

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

Definition at line 394 of file int10.c.

397{
398#ifdef _M_AMD64
400#else
402#endif
404 PKPROCESS CallingProcess;
406
407 /* Clear the context and fill out the BIOS arguments */
409 BiosContext.Eax = BiosArguments->Eax;
410 BiosContext.Ebx = BiosArguments->Ebx;
411 BiosContext.Ecx = BiosArguments->Ecx;
412 BiosContext.Edx = BiosArguments->Edx;
413 BiosContext.Esi = BiosArguments->Esi;
414 BiosContext.Edi = BiosArguments->Edi;
415 BiosContext.Ebp = BiosArguments->Ebp;
416 BiosContext.SegDs = BiosArguments->SegDs;
417 BiosContext.SegEs = BiosArguments->SegEs;
418
419 /* Perform the call in the CSRSS context */
420 if (!IntAttachToCSRSS(&CallingProcess, &ApcState))
422
423 /* Do the ROM BIOS call */
425 Executive,
427 FALSE,
428 NULL);
429
430 /* The kernel needs access here */
432#ifdef _M_AMD64
434#else
436#endif
438
440
441 IntDetachFromCSRSS(CallingProcess, &ApcState);
442
443 /* Return the arguments */
444 BiosArguments->Eax = BiosContext.Eax;
445 BiosArguments->Ebx = BiosContext.Ebx;
446 BiosArguments->Ecx = BiosContext.Ecx;
447 BiosArguments->Edx = BiosContext.Edx;
448 BiosArguments->Esi = BiosContext.Esi;
449 BiosArguments->Edi = BiosContext.Edi;
450 BiosArguments->Ebp = BiosContext.Ebp;
451 BiosArguments->SegDs = (USHORT)BiosContext.SegDs;
452 BiosArguments->SegEs = (USHORT)BiosContext.SegEs;
453
455}
CALLBACK16 BiosContext
Definition: bios32.c:45
#define NULL
Definition: types.h:112
static VOID UnprotectLowV86Mem(VOID)
Definition: int10.c:62
static VOID ProtectLowV86Mem(VOID)
Definition: int10.c:39
#define KernelMode
Definition: asm.h:38
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:628
KMUTEX VideoPortInt10Mutex
Definition: videoprt.c:42
BOOLEAN NTAPI x86BiosCall(_In_ ULONG InterruptNumber, _Inout_ PX86_BIOS_REGISTERS Registers)
Definition: x86bios.c:410
#define KeWaitForMutexObject
Definition: kefuncs.h:543
@ Executive
Definition: ketypes.h:467

Referenced by VideoPortInt10(), and VideoPortQueryServices().

◆ IntInt10FreeBuffer()

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

Definition at line 278 of file int10.c.

282{
284#ifdef _M_IX86
285 PVOID MemoryAddress = (PVOID)((ULONG_PTR)(Seg << 4) | Off);
286 PKPROCESS CallingProcess;
288 SIZE_T Size = 0;
289
290 TRACE_(VIDEOPRT, "IntInt10FreeBuffer\n");
291 INFO_(VIDEOPRT, "- Segment: %x\n", Seg);
292 INFO_(VIDEOPRT, "- Offset: %x\n", Off);
293
294 /* Perform the call in the CSRSS context */
295 if (!IntAttachToCSRSS(&CallingProcess, &ApcState))
297
298 Status = ZwFreeVirtualMemory(NtCurrentProcess(),
299 &MemoryAddress,
300 &Size,
302
303 IntDetachFromCSRSS(CallingProcess, &ApcState);
304
305 return Status;
306#else
307 Status = x86BiosFreeBuffer(Seg, Off);
309#endif
310}
NTSTATUS NTAPI x86BiosFreeBuffer(_In_ USHORT Segment, _In_ USHORT Offset)
Definition: x86bios.c:180

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 314 of file int10.c.

320{
321#ifdef _M_IX86
322 PKPROCESS CallingProcess;
324
325 TRACE_(VIDEOPRT, "IntInt10ReadMemory\n");
326 INFO_(VIDEOPRT, "- Segment: %x\n", Seg);
327 INFO_(VIDEOPRT, "- Offset: %x\n", Off);
328 INFO_(VIDEOPRT, "- Buffer: %x\n", Buffer);
329 INFO_(VIDEOPRT, "- Length: %x\n", Length);
330
331 /* Perform the call in the CSRSS context */
332 if (!IntAttachToCSRSS(&CallingProcess, &ApcState))
334
335 if (IsLowV86Mem(Seg, Off))
337 RtlCopyMemory(Buffer, (PVOID)((ULONG_PTR)(Seg << 4) | Off), Length);
338 if (IsLowV86Mem(Seg, Off))
340
341 IntDetachFromCSRSS(CallingProcess, &ApcState);
342
343 return NO_ERROR;
344#else
346
349#endif
350}
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:204

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 354 of file int10.c.

360{
361#ifdef _M_IX86
362 PKPROCESS CallingProcess;
364
365 TRACE_(VIDEOPRT, "IntInt10WriteMemory\n");
366 INFO_(VIDEOPRT, "- Segment: %x\n", Seg);
367 INFO_(VIDEOPRT, "- Offset: %x\n", Off);
368 INFO_(VIDEOPRT, "- Buffer: %x\n", Buffer);
369 INFO_(VIDEOPRT, "- Length: %x\n", Length);
370
371 /* Perform the call in the CSRSS context */
372 if (!IntAttachToCSRSS(&CallingProcess, &ApcState))
374
375 if (IsLowV86Mem(Seg, Off))
377 RtlCopyMemory((PVOID)((ULONG_PTR)(Seg << 4) | Off), Buffer, Length);
378 if (IsLowV86Mem(Seg, Off))
380
381 IntDetachFromCSRSS(CallingProcess, &ApcState);
382
383 return NO_ERROR;
384#else
386
389#endif
390}
NTSTATUS NTAPI x86BiosWriteMemory(_In_ USHORT Segment, _In_ USHORT Offset, _In_reads_bytes_(Size) PVOID Buffer, _In_ ULONG Size)
Definition: x86bios.c:231

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:1305
PKPROCESS CsrProcess
Definition: videoprt.c:39
#define PsGetCurrentProcess
Definition: psfuncs.h:17

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:1307

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

◆ VideoPortInt10()

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

Definition at line 464 of file int10.c.

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

Referenced by VbeSetMode().