+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>
* fhandler.h (fhandler_base::utimes_fs): New method.
#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); \
+ })
#ifndef DEBUGGING
-#define set_errno(val) (errno = (val), _impure_ptr->_errno = (val))
+#define set_errno(val) (errno = _impure_ptr->_errno = (val))
#else
int __stdcall __set_errno (const char *ln, int ln, int val) __attribute ((regparm(3)));
#define set_errno(val) __set_errno (__PRETTY_FUNCTION__, __LINE__, (val))
create_disposition, create_options, NULL, 0);
if (!NT_SUCCESS (status))
{
- __seterrno_from_win_error (RtlNtStatusToDosError (status));
+ __seterrno_from_nt_status (status);
if (!nohandle ())
goto done;
}
pfai->InternalInformation.IndexNumber.LowPart,
pfai->StandardInformation.NumberOfLinks);
- debug_printf ("%u = NtQuerynformationFile)",
+ debug_printf ("%u = NtQueryInformationFile)",
RtlNtStatusToDosError (status));
}
if ((ret = NtQuerySystemInformation (SystemBasicInformation, (PVOID) &sbi,
sizeof sbi, NULL)) != STATUS_SUCCESS)
{
- __seterrno_from_win_error (RtlNtStatusToDosError (ret));
- debug_printf("NtQuerySystemInformation: ret %d, Dos(ret) %d",
- ret, RtlNtStatusToDosError (ret));
+ __seterrno_from_nt_status (ret);
+ debug_printf("NtQuerySystemInformation: ret %d, Dos(ret) %E", ret);
mem_size = 0;
}
else
NTSTATUS ret = NtOpenSection (&mem, section_access, &attr);
if (!NT_SUCCESS (ret))
{
- __seterrno_from_win_error (RtlNtStatusToDosError (ret));
+ __seterrno_from_nt_status (ret);
set_io_handle (NULL);
return 0;
}
0,
PAGE_READONLY)) != STATUS_SUCCESS)
{
- __seterrno_from_win_error (RtlNtStatusToDosError (ret));
+ __seterrno_from_nt_status (ret);
return -1;
}
if (!NT_SUCCESS (ret = NtUnmapViewOfSection (INVALID_HANDLE_VALUE, viewmem)))
{
- __seterrno_from_win_error (RtlNtStatusToDosError (ret));
+ __seterrno_from_nt_status (ret);
return -1;
}
0,
PAGE_READONLY)) != STATUS_SUCCESS)
{
- __seterrno_from_win_error (RtlNtStatusToDosError (ret));
+ __seterrno_from_nt_status (ret);
ulen = (size_t) -1;
return;
}
if (!NT_SUCCESS (ret = NtUnmapViewOfSection (INVALID_HANDLE_VALUE, viewmem)))
{
- __seterrno_from_win_error (RtlNtStatusToDosError (ret));
+ __seterrno_from_nt_status (ret);
ulen = (size_t) -1;
return;
}
NTSTATUS ret = NtOpenSection (&h, section_access, &attr);
if (!NT_SUCCESS (ret))
{
- __seterrno_from_win_error (RtlNtStatusToDosError (ret));
+ __seterrno_from_nt_status (ret);
syscall_printf ("-1 = mmap(): NtOpenSection failed with %E");
return INVALID_HANDLE_VALUE;
}
0,
protect)) != STATUS_SUCCESS)
{
- __seterrno_from_win_error (RtlNtStatusToDosError (ret));
+ __seterrno_from_nt_status (ret);
syscall_printf ("-1 = mmap(): NtMapViewOfSection failed with %E");
return INVALID_HANDLE_VALUE;
}
NTSTATUS ret;
if (!NT_SUCCESS (ret = NtUnmapViewOfSection (INVALID_HANDLE_VALUE, addr)))
{
- __seterrno_from_win_error (RtlNtStatusToDosError (ret));
+ __seterrno_from_nt_status (ret);
return -1;
}
CloseHandle (h);
0,
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");
return false;
}
}
else if (ret != STATUS_SUCCESS)
{
- __seterrno_from_win_error (RtlNtStatusToDosError (ret));
- debug_printf("NtQuerySystemInformation: ret %d, Dos(ret) %d",
- ret, RtlNtStatusToDosError (ret));
+ __seterrno_from_nt_status (ret);
+ debug_printf("NtQuerySystemInformation: ret %d, Dos(ret) %E", ret);
return 0;
}
}
(PVOID) &sbi, sizeof sbi, NULL))
!= STATUS_SUCCESS)
{
- __seterrno_from_win_error (RtlNtStatusToDosError (ret));
- debug_printf ("NtQuerySystemInformation: ret %d, Dos(ret) %d",
- ret, RtlNtStatusToDosError (ret));
+ __seterrno_from_nt_status (ret);
+ debug_printf ("NtQuerySystemInformation: ret %d, Dos(ret) %E", ret);
sbi.NumberProcessors = 1;
}
sizeof stodi, NULL);
if (ret != STATUS_SUCCESS)
{
- __seterrno_from_win_error (RtlNtStatusToDosError (ret));
- debug_printf("NtQuerySystemInformation: ret %d, Dos(ret) %d",
- ret, RtlNtStatusToDosError (ret));
+ __seterrno_from_nt_status (ret);
+ debug_printf("NtQuerySystemInformation: ret %d, Dos(ret) %E", ret);
return 0;
}
pages_in = spi.PagesRead;
sizeof spt, NULL);
if (ret != STATUS_SUCCESS)
{
- __seterrno_from_win_error (RtlNtStatusToDosError (ret));
- debug_printf ("NtQueryInformationProcess: ret %d, Dos(ret) %d",
- ret, RtlNtStatusToDosError (ret));
+ __seterrno_from_nt_status (ret);
+ debug_printf ("NtQueryInformationProcess: ret %d, Dos(ret) %E", ret);
return 0;
}
fault_count = vmc.PageFaultCount;
base ? AT_ROUND_TO_PAGE : 0, protect);
if (ret != STATUS_SUCCESS)
{
- __seterrno_from_win_error (RtlNtStatusToDosError (ret));
+ __seterrno_from_nt_status (ret);
base = NULL;
}
else
ulen, &phys, &ulen, ViewShare,
AT_ROUND_TO_PAGE, protect);
if (ret != STATUS_SUCCESS)
- __seterrno_from_win_error (RtlNtStatusToDosError (ret));
+ __seterrno_from_nt_status (ret);
}
else
base = MapViewOfFileEx (h, access, 0, offset, size, address);
&auth_luid, &exp, &user, new_tok_gsids, privs, &owner,
&pgrp, &dacl, &source);
if (ret)
- __seterrno_from_win_error (RtlNtStatusToDosError (ret));
+ __seterrno_from_nt_status (ret);
else if (GetLastError () == ERROR_PROC_NOT_FOUND)
{
__seterrno ();
if (fh == INVALID_HANDLE_VALUE) /* CreateFile failed */
__seterrno ();
else if (ret != STATUS_SUCCESS) /* NtSetSecurityObject failed */
- __seterrno_from_win_error (RtlNtStatusToDosError (ret));
+ __seterrno_from_nt_status (ret);
else /* Everything's fine. */
res = 0;
return res;
}
if (ret != STATUS_SUCCESS)
{
- __seterrno_from_win_error (RtlNtStatusToDosError (ret));
+ __seterrno_from_nt_status (ret);
return -1;
}
return 0;
sizeof sbi, NULL))
!= STATUS_SUCCESS)
{
- __seterrno_from_win_error (RtlNtStatusToDosError (ret));
- debug_printf ("NtQuerySystemInformation: ret %d, Dos(ret) %d",
- ret, RtlNtStatusToDosError (ret));
+ __seterrno_from_nt_status (ret);
+ debug_printf ("NtQuerySystemInformation: ret %d, Dos(ret) %E",
+ ret);
return -1;
}
switch (in)
sizeof spi, NULL))
!= STATUS_SUCCESS)
{
- __seterrno_from_win_error (RtlNtStatusToDosError (ret));
- debug_printf ("NtQuerySystemInformation: ret %d, Dos(ret) %d",
- ret, RtlNtStatusToDosError (ret));
+ __seterrno_from_nt_status (ret);
+ debug_printf ("NtQuerySystemInformation: ret %d, Dos(ret) %E",
+ ret);
return -1;
}
return spi.AvailablePages;