mirror of
https://github.com/reactos/reactos.git
synced 2025-08-03 05:55:48 +00:00
modified dll/win32/kernel32/debug/output.c
KJK::Hyperion vs KJK::Hyperion: finishing the job I started in 2003 "please uncomment when GCC supports SEH": it kind of does now, but it's totally unnecessary in K32CreateDBMonMutex "FIXME: this will be pointless until GCC does SEH": no longer pointless, I guess. 6 years after the fact, OutputDebugStringA finally sends the string to the user-mode debugger. Now if only we could test it... Use DBG_PRINTEXCEPTION_C symbolic constant instead of hardcoding its value Some [FORMATTING] Make K32CreateDBMonMutex, for symbol table hygiene My e-mail address changed svn path=/trunk/; revision=38828
This commit is contained in:
parent
c331fd3dad
commit
5b30cdcd87
1 changed files with 182 additions and 222 deletions
|
@ -4,7 +4,7 @@
|
|||
* PROJECT: ReactOS system libraries
|
||||
* FILE: lib/kernel32/debug/debugger.c
|
||||
* PURPOSE: OutputDebugString()
|
||||
* PROGRAMMER: KJK::Hyperion <noog@libero.it>
|
||||
* PROGRAMMER: KJK::Hyperion <hackbunny@reactos.com>
|
||||
*/
|
||||
|
||||
/* INCLUDES ******************************************************************/
|
||||
|
@ -14,6 +14,7 @@
|
|||
/* FUNCTIONS *****************************************************************/
|
||||
|
||||
/* Open or create the mutex used to communicate with the debug monitor */
|
||||
static
|
||||
HANDLE
|
||||
K32CreateDBMonMutex(void)
|
||||
{
|
||||
|
@ -64,12 +65,6 @@ K32CreateDBMonMutex(void)
|
|||
}
|
||||
|
||||
/* if the mutex doesn't exist, create it */
|
||||
#if 0 /* please uncomment when GCC supports SEH */
|
||||
__try
|
||||
{
|
||||
#else
|
||||
#define __leave goto l_Cleanup
|
||||
#endif
|
||||
|
||||
/* first, set up the mutex security */
|
||||
/* allocate the NT AUTHORITY\SYSTEM SID */
|
||||
|
@ -86,7 +81,7 @@ K32CreateDBMonMutex(void)
|
|||
&psidSystem);
|
||||
|
||||
/* failure */
|
||||
if(!NT_SUCCESS(nErrCode)) __leave;
|
||||
if(!NT_SUCCESS(nErrCode)) goto l_Cleanup;
|
||||
|
||||
/* allocate the BUILTIN\Administrators SID */
|
||||
nErrCode = RtlAllocateAndInitializeSid(&siaNTAuth,
|
||||
|
@ -102,7 +97,7 @@ K32CreateDBMonMutex(void)
|
|||
&psidAdministrators);
|
||||
|
||||
/* failure */
|
||||
if(!NT_SUCCESS(nErrCode)) __leave;
|
||||
if(!NT_SUCCESS(nErrCode)) goto l_Cleanup;
|
||||
|
||||
/* allocate the Everyone SID */
|
||||
nErrCode = RtlAllocateAndInitializeSid(&siaWorldAuth,
|
||||
|
@ -118,7 +113,7 @@ K32CreateDBMonMutex(void)
|
|||
&psidEveryone);
|
||||
|
||||
/* failure */
|
||||
if(!NT_SUCCESS(nErrCode)) __leave;
|
||||
if(!NT_SUCCESS(nErrCode)) goto l_Cleanup;
|
||||
|
||||
/* allocate space for the SIDs too */
|
||||
nDaclBufSize += RtlLengthSid(psidSystem);
|
||||
|
@ -129,13 +124,13 @@ K32CreateDBMonMutex(void)
|
|||
pDaclBuf = GlobalAlloc(GMEM_FIXED, nDaclBufSize);
|
||||
|
||||
/* failure */
|
||||
if(pDaclBuf == NULL) __leave;
|
||||
if(pDaclBuf == NULL) goto l_Cleanup;
|
||||
|
||||
/* create the DACL */
|
||||
nErrCode = RtlCreateAcl(pDaclBuf, nDaclBufSize, ACL_REVISION);
|
||||
|
||||
/* failure */
|
||||
if(!NT_SUCCESS(nErrCode)) __leave;
|
||||
if(!NT_SUCCESS(nErrCode)) goto l_Cleanup;
|
||||
|
||||
/* grant the minimum required access to Everyone */
|
||||
nErrCode = RtlAddAccessAllowedAce(pDaclBuf,
|
||||
|
@ -146,7 +141,7 @@ K32CreateDBMonMutex(void)
|
|||
psidEveryone);
|
||||
|
||||
/* failure */
|
||||
if(!NT_SUCCESS(nErrCode)) __leave;
|
||||
if(!NT_SUCCESS(nErrCode)) goto l_Cleanup;
|
||||
|
||||
/* grant full access to BUILTIN\Administrators */
|
||||
nErrCode = RtlAddAccessAllowedAce(pDaclBuf,
|
||||
|
@ -155,7 +150,7 @@ K32CreateDBMonMutex(void)
|
|||
psidAdministrators);
|
||||
|
||||
/* failure */
|
||||
if(!NT_SUCCESS(nErrCode)) __leave;
|
||||
if(!NT_SUCCESS(nErrCode)) goto l_Cleanup;
|
||||
|
||||
/* grant full access to NT AUTHORITY\SYSTEM */
|
||||
nErrCode = RtlAddAccessAllowedAce(pDaclBuf,
|
||||
|
@ -164,14 +159,14 @@ K32CreateDBMonMutex(void)
|
|||
psidSystem);
|
||||
|
||||
/* failure */
|
||||
if(!NT_SUCCESS(nErrCode)) __leave;
|
||||
if(!NT_SUCCESS(nErrCode)) goto l_Cleanup;
|
||||
|
||||
/* create the security descriptor */
|
||||
nErrCode = RtlCreateSecurityDescriptor(&sdMutexSecurity,
|
||||
SECURITY_DESCRIPTOR_REVISION);
|
||||
|
||||
/* failure */
|
||||
if(!NT_SUCCESS(nErrCode)) __leave;
|
||||
if(!NT_SUCCESS(nErrCode)) goto l_Cleanup;
|
||||
|
||||
/* set the descriptor's DACL to the ACL we created */
|
||||
nErrCode = RtlSetDaclSecurityDescriptor(&sdMutexSecurity,
|
||||
|
@ -180,26 +175,17 @@ K32CreateDBMonMutex(void)
|
|||
FALSE);
|
||||
|
||||
/* failure */
|
||||
if(!NT_SUCCESS(nErrCode)) __leave;
|
||||
if(!NT_SUCCESS(nErrCode)) goto l_Cleanup;
|
||||
|
||||
/* create the mutex */
|
||||
hMutex = CreateMutexW(&saMutexAttribs, FALSE, L"DBWinMutex");
|
||||
#if 0
|
||||
}
|
||||
__finally
|
||||
{
|
||||
#else
|
||||
l_Cleanup:
|
||||
#endif
|
||||
|
||||
l_Cleanup:
|
||||
/* free the buffers */
|
||||
if(pDaclBuf) GlobalFree(pDaclBuf);
|
||||
if(psidEveryone) RtlFreeSid(psidEveryone);
|
||||
if(psidAdministrators) RtlFreeSid(psidAdministrators);
|
||||
if(psidSystem) RtlFreeSid(psidSystem);
|
||||
#if 0
|
||||
}
|
||||
#endif
|
||||
|
||||
return hMutex;
|
||||
}
|
||||
|
@ -212,9 +198,7 @@ VOID
|
|||
WINAPI
|
||||
OutputDebugStringA(LPCSTR _OutputString)
|
||||
{
|
||||
#if 0
|
||||
/* FIXME: this will be pointless until GCC does SEH */
|
||||
__try
|
||||
_SEH2_TRY
|
||||
{
|
||||
ULONG_PTR a_nArgs[2];
|
||||
|
||||
|
@ -222,12 +206,10 @@ OutputDebugStringA(LPCSTR _OutputString)
|
|||
a_nArgs[1] = (ULONG_PTR)_OutputString;
|
||||
|
||||
/* send the string to the user-mode debugger */
|
||||
RaiseException(0x40010006, 0, 2, a_nArgs);
|
||||
RaiseException(DBG_PRINTEXCEPTION_C, 0, 2, a_nArgs);
|
||||
}
|
||||
__except(EXCEPTION_EXECUTE_HANDLER)
|
||||
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
#endif
|
||||
|
||||
/* no user-mode debugger: try the systemwide debug message monitor, or the
|
||||
kernel debugger as a last resort */
|
||||
|
||||
|
@ -262,11 +244,8 @@ OutputDebugStringA(LPCSTR _OutputString)
|
|||
s_hDBMonMutex = hDBMonMutex;
|
||||
}
|
||||
|
||||
#if 0
|
||||
__try
|
||||
_SEH2_TRY
|
||||
{
|
||||
#endif
|
||||
|
||||
/* opening the mutex failed */
|
||||
if(hDBMonMutex == NULL)
|
||||
{
|
||||
|
@ -304,8 +283,7 @@ OutputDebugStringA(LPCSTR _OutputString)
|
|||
if(hDBMonBufferReady == NULL) break;
|
||||
|
||||
/* open the event to be signaled when the buffer has been filled */
|
||||
hDBMonDataReady =
|
||||
OpenEventW(EVENT_MODIFY_STATE, FALSE, L"DBWIN_DATA_READY");
|
||||
hDBMonDataReady = OpenEventW(EVENT_MODIFY_STATE, FALSE, L"DBWIN_DATA_READY");
|
||||
}
|
||||
while(0);
|
||||
|
||||
|
@ -314,11 +292,7 @@ OutputDebugStringA(LPCSTR _OutputString)
|
|||
if(hDBMonDataReady == NULL) ReleaseMutex(hDBMonMutex);
|
||||
}
|
||||
|
||||
#if 0
|
||||
__try
|
||||
#else
|
||||
do
|
||||
#endif
|
||||
_SEH2_TRY
|
||||
{
|
||||
/* size of the current output block */
|
||||
SIZE_T nRoundLen;
|
||||
|
@ -389,30 +363,17 @@ OutputDebugStringA(LPCSTR _OutputString)
|
|||
}
|
||||
/* repeat until the string has been fully output */
|
||||
while (nOutputStringLen > 0);
|
||||
|
||||
}
|
||||
#if 0
|
||||
/* ignore access violations and let other exceptions fall through */
|
||||
__except
|
||||
(
|
||||
(GetExceptionCode() == STATUS_ACCESS_VIOLATION) ?
|
||||
EXCEPTION_EXECUTE_HANDLER :
|
||||
EXCEPTION_CONTINUE_SEARCH
|
||||
)
|
||||
_SEH2_EXCEPT((_SEH2_GetExceptionCode() == STATUS_ACCESS_VIOLATION) ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
|
||||
{
|
||||
/* string copied verbatim from Microsoft's kernel32.dll */
|
||||
DbgPrint("\nOutputDebugString faulted during output\n");
|
||||
}
|
||||
#else
|
||||
while(0);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
_SEH2_END;
|
||||
}
|
||||
__finally
|
||||
_SEH2_FINALLY
|
||||
{
|
||||
#endif
|
||||
|
||||
/* close all the still open resources */
|
||||
if(hDBMonBufferReady) CloseHandle(hDBMonBufferReady);
|
||||
if(pDBMonBuffer) UnmapViewOfFile(pDBMonBuffer);
|
||||
|
@ -422,11 +383,10 @@ OutputDebugStringA(LPCSTR _OutputString)
|
|||
/* leave the critical section */
|
||||
if(hDBMonDataReady != NULL)
|
||||
ReleaseMutex(hDBMonMutex);
|
||||
|
||||
#if 0
|
||||
}
|
||||
_SEH2_END;
|
||||
}
|
||||
#endif
|
||||
_SEH2_END;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue