2000-01-24 21:59:45 +01:00
|
|
|
/*
|
|
|
|
* NTDLL error handling
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
2000-01-24 21:59:45 +01:00
|
|
|
* Copyright 2000 Alexandre Julliard
|
2002-09-09 21:25:29 +02:00
|
|
|
* Copyright 2002 Andriy Palamarchuk
|
2010-08-16 19:46:39 +02:00
|
|
|
* Copyright 2010 André Hentschel
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2000-01-24 21:59:45 +01:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "ntstatus.h"
|
2005-11-28 17:32:54 +01:00
|
|
|
#define WIN32_NO_STATUS
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2002-09-13 00:07:02 +02:00
|
|
|
#include "winternl.h"
|
2000-01-24 21:59:45 +01:00
|
|
|
#include "winerror.h"
|
2021-10-12 15:30:48 +02:00
|
|
|
#include "error.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2000-01-24 21:59:45 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
|
2000-01-24 21:59:45 +01:00
|
|
|
|
|
|
|
/**************************************************************************
|
2003-12-12 06:56:44 +01:00
|
|
|
* RtlNtStatusToDosErrorNoTeb (NTDLL.@)
|
2003-09-24 07:14:39 +02:00
|
|
|
*
|
|
|
|
* Convert an NTSTATUS code to a Win32 error code.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* status [I] Nt error code to map.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The mapped Win32 error code, or ERROR_MR_MID_NOT_FOUND if there is no
|
|
|
|
* mapping defined.
|
2000-01-24 21:59:45 +01:00
|
|
|
*/
|
2003-12-12 06:56:44 +01:00
|
|
|
ULONG WINAPI RtlNtStatusToDosErrorNoTeb( NTSTATUS status )
|
2000-01-24 21:59:45 +01:00
|
|
|
{
|
2020-02-13 09:40:26 +01:00
|
|
|
ULONG ret;
|
2000-01-24 21:59:45 +01:00
|
|
|
|
|
|
|
if (!status || (status & 0x20000000)) return status;
|
|
|
|
|
|
|
|
/* 0xd... is equivalent to 0xc... */
|
|
|
|
if ((status & 0xf0000000) == 0xd0000000) status &= ~0x10000000;
|
|
|
|
|
|
|
|
/* now some special cases */
|
2020-02-13 09:40:26 +01:00
|
|
|
if (HIWORD(status) == 0xc001 || HIWORD(status) == 0x8007 || HIWORD(status) == 0xc007)
|
|
|
|
return LOWORD( status );
|
2009-12-03 19:29:41 +01:00
|
|
|
|
2020-02-13 09:40:26 +01:00
|
|
|
ret = map_status( status );
|
|
|
|
if (ret == ERROR_MR_MID_NOT_FOUND && status != STATUS_MESSAGE_NOT_FOUND)
|
2021-05-04 04:42:53 +02:00
|
|
|
WARN( "no mapping for %08x\n", status );
|
2020-02-13 09:40:26 +01:00
|
|
|
return ret;
|
2000-01-24 21:59:45 +01:00
|
|
|
}
|
|
|
|
|
2003-12-12 06:56:44 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* RtlNtStatusToDosError (NTDLL.@)
|
|
|
|
*
|
|
|
|
* Convert an NTSTATUS code to a Win32 error code.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* status [I] Nt error code to map.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The mapped Win32 error code, or ERROR_MR_MID_NOT_FOUND if there is no
|
|
|
|
* mapping defined.
|
|
|
|
*/
|
|
|
|
ULONG WINAPI RtlNtStatusToDosError( NTSTATUS status )
|
|
|
|
{
|
2005-01-04 13:09:32 +01:00
|
|
|
NtCurrentTeb()->LastStatusValue = status;
|
2003-12-12 06:56:44 +01:00
|
|
|
return RtlNtStatusToDosErrorNoTeb( status );
|
|
|
|
}
|
|
|
|
|
2005-01-04 13:09:32 +01:00
|
|
|
/**********************************************************************
|
|
|
|
* RtlGetLastNtStatus (NTDLL.@)
|
|
|
|
*
|
|
|
|
* Get the current per-thread status.
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI RtlGetLastNtStatus(void)
|
|
|
|
{
|
|
|
|
return NtCurrentTeb()->LastStatusValue;
|
|
|
|
}
|
|
|
|
|
2003-12-12 06:56:44 +01:00
|
|
|
/**********************************************************************
|
|
|
|
* RtlGetLastWin32Error (NTDLL.@)
|
|
|
|
*
|
|
|
|
* Get the current per-thread error value set by a system function or the user.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The current error value for the thread, as set by SetLastWin32Error() or SetLastError().
|
|
|
|
*/
|
|
|
|
DWORD WINAPI RtlGetLastWin32Error(void)
|
|
|
|
{
|
|
|
|
return NtCurrentTeb()->LastErrorValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RtlSetLastWin32Error (NTDLL.@)
|
|
|
|
* RtlRestoreLastWin32Error (NTDLL.@)
|
|
|
|
*
|
|
|
|
* Set the per-thread error value.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* err [I] The new error value to set
|
2005-11-09 11:30:57 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing.
|
2003-12-12 06:56:44 +01:00
|
|
|
*/
|
|
|
|
void WINAPI RtlSetLastWin32Error( DWORD err )
|
|
|
|
{
|
|
|
|
NtCurrentTeb()->LastErrorValue = err;
|
|
|
|
}
|
2000-01-24 21:59:45 +01:00
|
|
|
|
2005-01-04 13:09:32 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* RtlSetLastWin32ErrorAndNtStatusFromNtStatus (NTDLL.@)
|
|
|
|
*
|
|
|
|
* Set the per-thread status and error values.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* err [I] The new status value to set
|
2005-11-09 11:30:57 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing.
|
2005-01-04 13:09:32 +01:00
|
|
|
*/
|
|
|
|
void WINAPI RtlSetLastWin32ErrorAndNtStatusFromNtStatus( NTSTATUS status )
|
|
|
|
{
|
|
|
|
NtCurrentTeb()->LastErrorValue = RtlNtStatusToDosError( status );
|
|
|
|
}
|