* cygerrno.h (__seterrno_from_nt_status): Define. Always set Win32

error code as well as errno. Use throughout where errno is set from
	NT status.
	(set_errno): Evaluate val only once.
	* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Fix typo in
	debug output.
	* fhandler_mem.cc (fhandler_dev_mem::open): Rely on
	__seterrno_from_nt_status setting Win32 error code in debug output.
	* fhandler_proc.cc (format_proc_uptime): Ditto.
	(format_proc_stat): Ditto.
	* fhandler_process.cc (format_process_stat): Ditto.
	* sysconf.cc (sysconf): Ditto.
This commit is contained in:
Corinna Vinschen 2005-04-13 16:41:33 +00:00
parent f134945dcb
commit 7460bfd32b
10 changed files with 54 additions and 38 deletions

View File

@ -1,3 +1,18 @@
2005-04-13 Corinna Vinschen <corinna@vinschen.de>
* cygerrno.h (__seterrno_from_nt_status): Define. Always set Win32
error code as well as errno. Use throughout where errno is set from
NT status.
(set_errno): Evaluate val only once.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Fix typo in
debug output.
* fhandler_mem.cc (fhandler_dev_mem::open): Rely on
__seterrno_from_nt_status setting Win32 error code in debug output.
* fhandler_proc.cc (format_proc_uptime): Ditto.
(format_proc_stat): Ditto.
* fhandler_process.cc (format_process_stat): Ditto.
* sysconf.cc (sysconf): Ditto.
2005-04-13 Christopher Faylor <cgf@timesys.com> 2005-04-13 Christopher Faylor <cgf@timesys.com>
* fhandler.h (fhandler_base::utimes_fs): New method. * fhandler.h (fhandler_base::utimes_fs): New method.

View File

@ -16,9 +16,15 @@ int __stdcall geterrno_from_win_error (DWORD code, int deferrno) __attribute__ (
#define __seterrno() seterrno (__FILE__, __LINE__) #define __seterrno() seterrno (__FILE__, __LINE__)
#define __seterrno_from_win_error(val) seterrno_from_win_error (__FILE__, __LINE__, val) #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); \
})
#ifndef DEBUGGING #ifndef DEBUGGING
#define set_errno(val) (errno = (val), _impure_ptr->_errno = (val)) #define set_errno(val) (errno = _impure_ptr->_errno = (val))
#else #else
int __stdcall __set_errno (const char *ln, int ln, int val) __attribute ((regparm(3))); int __stdcall __set_errno (const char *ln, int ln, int val) __attribute ((regparm(3)));
#define set_errno(val) __set_errno (__PRETTY_FUNCTION__, __LINE__, (val)) #define set_errno(val) __set_errno (__PRETTY_FUNCTION__, __LINE__, (val))

View File

@ -665,7 +665,7 @@ fhandler_base::open (int flags, mode_t mode)
create_disposition, create_options, NULL, 0); create_disposition, create_options, NULL, 0);
if (!NT_SUCCESS (status)) if (!NT_SUCCESS (status))
{ {
__seterrno_from_win_error (RtlNtStatusToDosError (status)); __seterrno_from_nt_status (status);
if (!nohandle ()) if (!nohandle ())
goto done; goto done;
} }

View File

@ -141,7 +141,7 @@ fhandler_base::fstat_by_handle (struct __stat64 *buf)
pfai->InternalInformation.IndexNumber.LowPart, pfai->InternalInformation.IndexNumber.LowPart,
pfai->StandardInformation.NumberOfLinks); pfai->StandardInformation.NumberOfLinks);
debug_printf ("%u = NtQuerynformationFile)", debug_printf ("%u = NtQueryInformationFile)",
RtlNtStatusToDosError (status)); RtlNtStatusToDosError (status));
} }

View File

@ -48,9 +48,8 @@ fhandler_dev_mem::open (int flags, mode_t)
if ((ret = NtQuerySystemInformation (SystemBasicInformation, (PVOID) &sbi, if ((ret = NtQuerySystemInformation (SystemBasicInformation, (PVOID) &sbi,
sizeof sbi, NULL)) != STATUS_SUCCESS) sizeof sbi, NULL)) != STATUS_SUCCESS)
{ {
__seterrno_from_win_error (RtlNtStatusToDosError (ret)); __seterrno_from_nt_status (ret);
debug_printf("NtQuerySystemInformation: ret %d, Dos(ret) %d", debug_printf("NtQuerySystemInformation: ret %d, Dos(ret) %E", ret);
ret, RtlNtStatusToDosError (ret));
mem_size = 0; mem_size = 0;
} }
else else
@ -109,7 +108,7 @@ fhandler_dev_mem::open (int flags, mode_t)
NTSTATUS ret = NtOpenSection (&mem, section_access, &attr); NTSTATUS ret = NtOpenSection (&mem, section_access, &attr);
if (!NT_SUCCESS (ret)) if (!NT_SUCCESS (ret))
{ {
__seterrno_from_win_error (RtlNtStatusToDosError (ret)); __seterrno_from_nt_status (ret);
set_io_handle (NULL); set_io_handle (NULL);
return 0; return 0;
} }
@ -151,7 +150,7 @@ fhandler_dev_mem::write (const void *ptr, size_t ulen)
0, 0,
PAGE_READONLY)) != STATUS_SUCCESS) PAGE_READONLY)) != STATUS_SUCCESS)
{ {
__seterrno_from_win_error (RtlNtStatusToDosError (ret)); __seterrno_from_nt_status (ret);
return -1; return -1;
} }
@ -159,7 +158,7 @@ fhandler_dev_mem::write (const void *ptr, size_t ulen)
if (!NT_SUCCESS (ret = NtUnmapViewOfSection (INVALID_HANDLE_VALUE, viewmem))) if (!NT_SUCCESS (ret = NtUnmapViewOfSection (INVALID_HANDLE_VALUE, viewmem)))
{ {
__seterrno_from_win_error (RtlNtStatusToDosError (ret)); __seterrno_from_nt_status (ret);
return -1; return -1;
} }
@ -203,7 +202,7 @@ fhandler_dev_mem::read (void *ptr, size_t& ulen)
0, 0,
PAGE_READONLY)) != STATUS_SUCCESS) PAGE_READONLY)) != STATUS_SUCCESS)
{ {
__seterrno_from_win_error (RtlNtStatusToDosError (ret)); __seterrno_from_nt_status (ret);
ulen = (size_t) -1; ulen = (size_t) -1;
return; return;
} }
@ -212,7 +211,7 @@ fhandler_dev_mem::read (void *ptr, size_t& ulen)
if (!NT_SUCCESS (ret = NtUnmapViewOfSection (INVALID_HANDLE_VALUE, viewmem))) if (!NT_SUCCESS (ret = NtUnmapViewOfSection (INVALID_HANDLE_VALUE, viewmem)))
{ {
__seterrno_from_win_error (RtlNtStatusToDosError (ret)); __seterrno_from_nt_status (ret);
ulen = (size_t) -1; ulen = (size_t) -1;
return; return;
} }
@ -303,7 +302,7 @@ fhandler_dev_mem::mmap (caddr_t *addr, size_t len, DWORD access,
NTSTATUS ret = NtOpenSection (&h, section_access, &attr); NTSTATUS ret = NtOpenSection (&h, section_access, &attr);
if (!NT_SUCCESS (ret)) if (!NT_SUCCESS (ret))
{ {
__seterrno_from_win_error (RtlNtStatusToDosError (ret)); __seterrno_from_nt_status (ret);
syscall_printf ("-1 = mmap(): NtOpenSection failed with %E"); syscall_printf ("-1 = mmap(): NtOpenSection failed with %E");
return INVALID_HANDLE_VALUE; return INVALID_HANDLE_VALUE;
} }
@ -325,7 +324,7 @@ fhandler_dev_mem::mmap (caddr_t *addr, size_t len, DWORD access,
0, 0,
protect)) != STATUS_SUCCESS) protect)) != STATUS_SUCCESS)
{ {
__seterrno_from_win_error (RtlNtStatusToDosError (ret)); __seterrno_from_nt_status (ret);
syscall_printf ("-1 = mmap(): NtMapViewOfSection failed with %E"); syscall_printf ("-1 = mmap(): NtMapViewOfSection failed with %E");
return INVALID_HANDLE_VALUE; return INVALID_HANDLE_VALUE;
} }
@ -347,7 +346,7 @@ fhandler_dev_mem::munmap (HANDLE h, caddr_t addr, size_t len)
NTSTATUS ret; NTSTATUS ret;
if (!NT_SUCCESS (ret = NtUnmapViewOfSection (INVALID_HANDLE_VALUE, addr))) if (!NT_SUCCESS (ret = NtUnmapViewOfSection (INVALID_HANDLE_VALUE, addr)))
{ {
__seterrno_from_win_error (RtlNtStatusToDosError (ret)); __seterrno_from_nt_status (ret);
return -1; return -1;
} }
CloseHandle (h); CloseHandle (h);
@ -391,7 +390,7 @@ fhandler_dev_mem::fixup_mmap_after_fork (HANDLE h, DWORD access, int flags,
0, 0,
protect)) != STATUS_SUCCESS) protect)) != STATUS_SUCCESS)
{ {
__seterrno_from_win_error (RtlNtStatusToDosError (ret)); __seterrno_from_nt_status (ret);
syscall_printf ("-1 = fixup_mmap_after_fork(): NtMapViewOfSection failed with %E"); syscall_printf ("-1 = fixup_mmap_after_fork(): NtMapViewOfSection failed with %E");
return false; return false;
} }

View File

@ -477,9 +477,8 @@ format_proc_uptime (char *destbuf, size_t maxsize)
} }
else if (ret != STATUS_SUCCESS) else if (ret != STATUS_SUCCESS)
{ {
__seterrno_from_win_error (RtlNtStatusToDosError (ret)); __seterrno_from_nt_status (ret);
debug_printf("NtQuerySystemInformation: ret %d, Dos(ret) %d", debug_printf("NtQuerySystemInformation: ret %d, Dos(ret) %E", ret);
ret, RtlNtStatusToDosError (ret));
return 0; return 0;
} }
} }
@ -514,9 +513,8 @@ format_proc_stat (char *destbuf, size_t maxsize)
(PVOID) &sbi, sizeof sbi, NULL)) (PVOID) &sbi, sizeof sbi, NULL))
!= STATUS_SUCCESS) != STATUS_SUCCESS)
{ {
__seterrno_from_win_error (RtlNtStatusToDosError (ret)); __seterrno_from_nt_status (ret);
debug_printf ("NtQuerySystemInformation: ret %d, Dos(ret) %d", debug_printf ("NtQuerySystemInformation: ret %d, Dos(ret) %E", ret);
ret, RtlNtStatusToDosError (ret));
sbi.NumberProcessors = 1; sbi.NumberProcessors = 1;
} }
@ -556,9 +554,8 @@ format_proc_stat (char *destbuf, size_t maxsize)
sizeof stodi, NULL); sizeof stodi, NULL);
if (ret != STATUS_SUCCESS) if (ret != STATUS_SUCCESS)
{ {
__seterrno_from_win_error (RtlNtStatusToDosError (ret)); __seterrno_from_nt_status (ret);
debug_printf("NtQuerySystemInformation: ret %d, Dos(ret) %d", debug_printf("NtQuerySystemInformation: ret %d, Dos(ret) %E", ret);
ret, RtlNtStatusToDosError (ret));
return 0; return 0;
} }
pages_in = spi.PagesRead; pages_in = spi.PagesRead;

View File

@ -683,9 +683,8 @@ format_process_stat (_pinfo *p, char *destbuf, size_t maxsize)
sizeof spt, NULL); sizeof spt, NULL);
if (ret != STATUS_SUCCESS) if (ret != STATUS_SUCCESS)
{ {
__seterrno_from_win_error (RtlNtStatusToDosError (ret)); __seterrno_from_nt_status (ret);
debug_printf ("NtQueryInformationProcess: ret %d, Dos(ret) %d", debug_printf ("NtQueryInformationProcess: ret %d, Dos(ret) %E", ret);
ret, RtlNtStatusToDosError (ret));
return 0; return 0;
} }
fault_count = vmc.PageFaultCount; fault_count = vmc.PageFaultCount;

View File

@ -1115,7 +1115,7 @@ fhandler_disk_file::mmap (caddr_t *addr, size_t len, DWORD access,
base ? AT_ROUND_TO_PAGE : 0, protect); base ? AT_ROUND_TO_PAGE : 0, protect);
if (ret != STATUS_SUCCESS) if (ret != STATUS_SUCCESS)
{ {
__seterrno_from_win_error (RtlNtStatusToDosError (ret)); __seterrno_from_nt_status (ret);
base = NULL; base = NULL;
} }
else else
@ -1196,7 +1196,7 @@ fhandler_disk_file::fixup_mmap_after_fork (HANDLE h, DWORD access, int flags,
ulen, &phys, &ulen, ViewShare, ulen, &phys, &ulen, ViewShare,
AT_ROUND_TO_PAGE, protect); AT_ROUND_TO_PAGE, protect);
if (ret != STATUS_SUCCESS) if (ret != STATUS_SUCCESS)
__seterrno_from_win_error (RtlNtStatusToDosError (ret)); __seterrno_from_nt_status (ret);
} }
else else
base = MapViewOfFileEx (h, access, 0, offset, size, address); base = MapViewOfFileEx (h, access, 0, offset, size, address);

View File

@ -931,7 +931,7 @@ create_token (cygsid &usersid, user_groups &new_groups, struct passwd *pw)
&auth_luid, &exp, &user, new_tok_gsids, privs, &owner, &auth_luid, &exp, &user, new_tok_gsids, privs, &owner,
&pgrp, &dacl, &source); &pgrp, &dacl, &source);
if (ret) if (ret)
__seterrno_from_win_error (RtlNtStatusToDosError (ret)); __seterrno_from_nt_status (ret);
else if (GetLastError () == ERROR_PROC_NOT_FOUND) else if (GetLastError () == ERROR_PROC_NOT_FOUND)
{ {
__seterrno (); __seterrno ();
@ -1153,7 +1153,7 @@ write_sd (HANDLE fh, const char *file, security_descriptor &sd)
if (fh == INVALID_HANDLE_VALUE) /* CreateFile failed */ if (fh == INVALID_HANDLE_VALUE) /* CreateFile failed */
__seterrno (); __seterrno ();
else if (ret != STATUS_SUCCESS) /* NtSetSecurityObject failed */ else if (ret != STATUS_SUCCESS) /* NtSetSecurityObject failed */
__seterrno_from_win_error (RtlNtStatusToDosError (ret)); __seterrno_from_nt_status (ret);
else /* Everything's fine. */ else /* Everything's fine. */
res = 0; res = 0;
return res; return res;
@ -1348,7 +1348,7 @@ get_nt_object_security (HANDLE handle, SE_OBJECT_TYPE object_type,
} }
if (ret != STATUS_SUCCESS) if (ret != STATUS_SUCCESS)
{ {
__seterrno_from_win_error (RtlNtStatusToDosError (ret)); __seterrno_from_nt_status (ret);
return -1; return -1;
} }
return 0; return 0;

View File

@ -79,9 +79,9 @@ sysconf (int in)
sizeof sbi, NULL)) sizeof sbi, NULL))
!= STATUS_SUCCESS) != STATUS_SUCCESS)
{ {
__seterrno_from_win_error (RtlNtStatusToDosError (ret)); __seterrno_from_nt_status (ret);
debug_printf ("NtQuerySystemInformation: ret %d, Dos(ret) %d", debug_printf ("NtQuerySystemInformation: ret %d, Dos(ret) %E",
ret, RtlNtStatusToDosError (ret)); ret);
return -1; return -1;
} }
switch (in) switch (in)
@ -112,9 +112,9 @@ sysconf (int in)
sizeof spi, NULL)) sizeof spi, NULL))
!= STATUS_SUCCESS) != STATUS_SUCCESS)
{ {
__seterrno_from_win_error (RtlNtStatusToDosError (ret)); __seterrno_from_nt_status (ret);
debug_printf ("NtQuerySystemInformation: ret %d, Dos(ret) %d", debug_printf ("NtQuerySystemInformation: ret %d, Dos(ret) %E",
ret, RtlNtStatusToDosError (ret)); ret);
return -1; return -1;
} }
return spi.AvailablePages; return spi.AvailablePages;