Re: VWIN32_SysErrorBox equvalent in NT\Win2k

From
Alex Fedotov ()
To
Yan Vugenfirer ()
Date
2001-07-16T06:59:27Z
Area
SU.WINDOWS.NT.PROG
From: "Alex Fedotov" <alexf@3cube.com>

Yan Vugenfirer wrote:

> I need to display an error message from the device driver in NT\Win2k.
> In win98 i used VWIN32_SysErrorBox for this purpose.
> What is equvalent function(s) in NT\Win2k.

Это ничего, что я по русски? Вообще-то так делать не принято. В таких
случаях принято иметь user-mode сервис поддержки, который постоянно имеет
pending IRP в драйвере. Когда нужно что-то сообщить в user-mode, ты
завершаешь этот IRP и сервис выводит на экран все, что посчитает
необходимым, хоть с музыкой.

Но если очень хочется, то NTDLL экспортирует функцию ZwRaiseHardError,
которая описана у Неббета (я опять приступаю к своему излюбленному
занятию). Есть, однако, на вскидку пара проблем с ее использованием:

1. Функция не экспортируется из NTOSKRNL, так что непосредственно
слинковаться с ней в ядре не получится. Но это легко обходится путем поиска
ее точки входа в таблице системных сервисов, так же, как это делают
программы, которые перехватывают системные вызовы. Масса таких примеров
есть на www.sysinternals.com (то, что я ковырял -- TokenMon, там точно
есть).

2. Поскольку ZwRaiseHardError предполагается быть вызванной из user mode,
она должна вызываться на PASSIVE_LEVEL и из nonarbitrary thread context.
Кроме того, могут возникнуть проблемы с валидацией параметров.

--
Alex Fedotov

P.S. Приложение. Описание ZwRaiseHardError из "Windows NT/2000 Native API
Reference" by Gary Nebbett.

ZwRaiseHardError

ZwRaiseHardError displays a message box containing an error message.

NTSYSAPI
NTSTATUS
NTAPI
ZwRaiseHardError(
    IN NTSTATUS Status,
    IN ULONG NumberOfArguments,
    IN ULONG StringArgumentsMask,
    IN PULONG Arguments,
    IN HARDERROR_RESPONSE_OPTION ResponseOption,
    OUT PHARDERROR_RESPONSE Response
    );

Parameters

Status
    The error status that is to be raised.

NumberOfArguments
    The number of substitution directives in the string associated with the
    error status.

StringArgumentMask
    Specifies which of the substitution directives indicate a string
    substitution.

Arguments
    Points to an array of substitution values; the values are either ULONGs
    or PUNICODE_STRINGs.

ResponseOption
    Specifies the type of the message box. Permitted values are drawn from
    the enumeration HARDERROR_RESPONSE_OPTION:

        typedef enum _HARDERROR_RESPONSE_OPTION {
            OptionAbortRetryIgnore,
            OptionOk,
            OptionOkCancel,
            OptionRetryCancel,
            OptionYesNo,
            OptionYesNoCancel,
            OptionShutdownSystem
        } HARDERROR_RESPONSE_OPTION, * PHARDERROR_RESPONSE_OPTION;

Response
    Points to a variable that receives the result of the user interaction
    with the message box. Possible values received are drawn from the
    enumeration HARDERROR_RESPONSE:

        typedef enum _HARDERROR_RESPONSE {
            ResponseReturnToCaller,
            ResponseNotHandled,
            ResponseAbort,
            ResponseCancel,
            ResponseIgnore,
            ResponseNo,
            ResponseOk,
            ResponseRetry,
            ResponseYes
        } HARDERROR_RESPONSE, * PHARDERROR_RESPONSE;

Return Value

Returns STATUS_SUCCESS or an error status.


Related Win32 Functions

None.


Remarks
SeShutdownPrivilege is required to use the option OptionShutdownSystem. The
information on the number and type of arguments is needed to correctly pack
the arguments into a message to be sent to the default hard error port. The
recipient of  the message uses the Status parameter to select a format
string and then inserts the arguments (which should match the directives in
the string).

An example of the use of ZwRaiseHardError is:

    UNICODE_STRING s = { 16, 18, L"Recalled" };
    ULONG x,args[] = { 0x11111111, 0x22222222, ULONG(&s) };
    ZwRaiseHardError(STATUS_ACCESS_VIOLATION, 3, 4, args, MB_OKCANCEL,&x);



Отправлено через сервер Talk.Ru - http://www.talk.ru
--- ifmail v.2.15dev5
 * Origin: 3Cube, Inc. (www.3cube.com) (2:5020/400)