From 7cdcd90ca146cd1322051385d92114b9b927776b Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Fri, 16 Apr 2010 15:42:29 +0000 Subject: [PATCH] * cygerrno.h (seterrno_from_nt_status): Declare. (__seterrno_from_nt_status): Call seterrno_from_nt_status. * errno.cc (seterrno_from_win_error): Set errno without calling set_errno to avoid packing strace output with errno messages. (seterrno_from_nt_status): New function to print NT status as well as resulting Windows error. --- winsup/cygwin/ChangeLog | 9 +++++++++ winsup/cygwin/cygerrno.h | 10 +++------- winsup/cygwin/errno.cc | 17 +++++++++++++++-- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 409a97c0a..e7331627c 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,12 @@ +2010-04-16 Corinna Vinschen + + * cygerrno.h (seterrno_from_nt_status): Declare. + (__seterrno_from_nt_status): Call seterrno_from_nt_status. + * errno.cc (seterrno_from_win_error): Set errno without calling + set_errno to avoid packing strace output with errno messages. + (seterrno_from_nt_status): New function to print NT status as well as + resulting Windows error. + 2010-04-15 Corinna Vinschen * kernel32.cc (CreateEventW): Create event object with EVENT_ALL_ACCESS diff --git a/winsup/cygwin/cygerrno.h b/winsup/cygwin/cygerrno.h index e6ec7c556..e1a1af07d 100644 --- a/winsup/cygwin/cygerrno.h +++ b/winsup/cygwin/cygerrno.h @@ -1,6 +1,6 @@ /* cygerrno.h: main Cygwin header file. - Copyright 2000, 2001, 2002, 2003, 2004 Red Hat, Inc. + Copyright 2000, 2001, 2002, 2003, 2004, 2010 Red Hat, Inc. This file is part of Cygwin. @@ -13,17 +13,13 @@ details. */ #include void __stdcall seterrno_from_win_error (const char *file, int line, DWORD code) __attribute__ ((regparm(3))); +void __stdcall seterrno_from_nt_status (const char *file, int line, NTSTATUS status) __attribute__ ((regparm(3))); void __stdcall seterrno (const char *, int line) __attribute__ ((regparm(2))); int __stdcall geterrno_from_win_error (DWORD code = GetLastError (), int deferrno = 13 /*EACCESS*/) __attribute__ ((regparm(2))); #define __seterrno() seterrno (__FILE__, __LINE__) #define __seterrno_from_win_error(val) seterrno_from_win_error (__FILE__, __LINE__, val) -#define __seterrno_from_nt_status(status) \ - ({ \ - DWORD winerr = RtlNtStatusToDosError (status); \ - SetLastError (winerr); \ - __seterrno_from_win_error (winerr); \ - }) +#define __seterrno_from_nt_status(status) seterrno_from_nt_status (__FILE__, __LINE__, status) inline int __set_errno (const char *fn, int ln, int val) diff --git a/winsup/cygwin/errno.cc b/winsup/cygwin/errno.cc index 617970a72..736510169 100644 --- a/winsup/cygwin/errno.cc +++ b/winsup/cygwin/errno.cc @@ -1,7 +1,7 @@ /* errno.cc: errno-related functions Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, - 2006, 2008, 2009 Red Hat, Inc. + 2006, 2008, 2009, 2010 Red Hat, Inc. This file is part of Cygwin. @@ -14,6 +14,7 @@ details. */ #define _sys_errlist FOO_sys_errlist #include "winsup.h" #include "cygtls.h" +#include "ntdll.h" #undef _sys_nerr #undef sys_nerr #undef _sys_errlist @@ -316,7 +317,19 @@ void __stdcall seterrno_from_win_error (const char *file, int line, DWORD code) { syscall_printf ("%s:%d windows error %d", file, line, code); - set_errno (geterrno_from_win_error (code, EACCES)); + errno = _impure_ptr->_errno = geterrno_from_win_error (code, EACCES); +} + +/* seterrno_from_nt_status: Given a NT status code, set errno + as appropriate. */ +void __stdcall +seterrno_from_nt_status (const char *file, int line, NTSTATUS status) +{ + DWORD code = RtlNtStatusToDosError (status); + SetLastError (code); + syscall_printf ("%s:%d status %p -> windows error %d", + file, line, status, code); + errno = _impure_ptr->_errno = geterrno_from_win_error (code, EACCES); } /* seterrno: Set `errno' based on GetLastError (). */