libc/winsup/cygwin/times.cc

774 lines
17 KiB
C++
Raw Normal View History

2000-02-17 20:38:33 +01:00
/* times.cc
This file is part of Cygwin.
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#define __timezonefunc__
Remove unneeded header files from source files throughout. Update copyrights where appropriate. * globals.cc: New file for generic global variables. * mkglobals_h: New file to generate globals.h. * mkstatic: New Script used to build a (currently non-working) static libcygwin_s.a. * Makefile.in: Add unused rule to build a non-working libcygwin_s.a. (DLL_OFILES): Add globals.o. Make all objects rely on globals.h. (globals.h): New target. Generate globals.h. * cygtls.h: Honor new CYGTLS_HANDLE define to control when the HANDLE operator is allowed in _cygtls. * dcrt0.cc: Move most globals to globals.cc. * init.cc: Ditto. * environ.cc (strip_title_path): Remove now-unneeded extern. * fhandler_serial.cc (fhandler_serial::open): Ditto. * pinfo.cc: Ditto. (commune_process): Ditto. * shared.cc: Ditto. * glob.cc: Ditto. * strace.cc: Ditto. * exceptions.cc: Define CYGTLS_HANDLE before including winsup.h. * path.cc (stat_suffixes): Move here. * security.h: Add forward class path_conv declaration. * smallprint.cc (__small_vsprintf): Make a true c++ function. (__small_sprintf): Ditto. (small_printf): Ditto. (console_printf): Ditto. (__small_vswprintf): Ditto. (__small_swprintf): Ditto. * spawn.cc (spawn_guts): Remove _stdcall decoration in favor of regparm. (hExeced): Move to globals.cc * strfuncs.cc (current_codepage): Ditto. (active_codepage): Ditto. * sync.cc (lock_process::locker): Move here from dcrt0.cc. * syscalls.cc (stat_suffixes): Move to path.cc. * tty.cc (tty::create_master): Uncapitalize fatal warning for consistency. * winsup.h: Include globals.h to declare most of the grab bag list of globals which were previously defined here. * mount.h: Move USER_* defines back to shared_info.h. * speclib: Force temporary directory cleanup.
2009-01-03 06:12:22 +01:00
#include "winsup.h"
2000-02-17 20:38:33 +01:00
#include <sys/times.h>
#include <sys/timeb.h>
#include <sys/param.h>
2000-02-17 20:38:33 +01:00
#include <utime.h>
#include <stdlib.h>
#include <unistd.h>
#include "cygerrno.h"
#include "security.h"
#include "path.h"
* devices.cc: New file. * devices.gperf: New file. * devices.shilka: New file. * cygwin-gperf: New file. * cygwin-shilka: New file. * fhandler_fifo.cc: New file. * fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes fhandler.h throughout. Remove device argument and unit arguments from fhandler constructors throughout. Remove pc arguments to fhandler functions and use internal pc element instead, throughout. Use dev element in pc throughout. Use major/minor elements rather than units and device numbers previously in fhandler class. Use correct methods for fhandler file names rather than directly accessing file name variables, throughout. * Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o * dcrt0.cc (dll_crt0_1): Call device::init. * devices.h: Renumber devices based on more Linux-like major/minor numbers. Add more devices. Declare standard device storage. (device): Declare struct. * dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type. * dtable.cc (dtable::get_debugger_info): Ditto. (cygwin_attach_handle_to_fd): Ditto. (dtable::release): Remove special FH_SOCKET case in favor of generic "need_fixup_before" test. (dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name to build standard fhandler. (dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move out of dtable class. Don't accept a path_conv argument. Just build it here and pass it to: (build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class. Use intrinsic device type in path_conv to create new fhandler. (build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class. Simplify arguments to just take new 'device' type and a name. Just return pointer to fhandler rather than trying to insert into dtable. (dtable::dup_worker): Accommodate above build_fh name changes. (dtable::find_fifo): New (currently broken) function. (handle_to_fn): Use strechr for efficiency. * dtable.h: Reflect above build_fh name changes and argument differences. (fhandler_base *&operator []): Return self rather than copy of self. * fhandler.cc (fhandler_base::operator =): Use pc element to set normalized path. (fhandler_base::set_name): Ditto. (fhandler_base::raw_read): Use method to access name. (fhandler_base::write): Correctly use get_output_handle rather than get_handle. (handler_base::device_access_denied): New function. (fhandler_base::open): Eliminate pc argument and use pc element of fhandler_base throughout. (fhandler_base::fstat): Detect if device is based in filesystem and use fstat_fs to calculate stat, if so. (fhandler_base::fhandler_base): Eliminate handling of file names and, instead, just free appropriate component from pc. (fhandler_base::opendir): Remove path_conv parameter. * fhandler.h: Remove all device flags. (fhandler_base::pc): New element. (fhandler_base::set_name): Change argument to path_conv. (fhandler_base::error): New function. (fhandler_base::exists): New function. (fhandler_base::pc_binmode): New function. (fhandler_base::dev): New function. (fhandler_base::open_fs): New function. (fhandler_base::fstat_fs): New function. (fhandler_base::fstat_by_name): New function. (fhandler_base::fstat_by_handle): New function. (fhandler_base::isfifo): New function. (fhandler_base::is_slow): New function. (fhandler_base::is_auto_device): New function. (fhandler_base::is_fs_special): New function. (fhandler_base::device_access_denied): New function. (fhandler_base::operator DWORD&): New operator. (fhandler_base::get_name): Return normalized path from pc. (fhandler_base::get_win32_name): Return windows path from pc. (fhandler_base::isdevice): Renamed from is_device. (fhandler_base::get_native_name): Return device format. (fhandler_fifo): New class. (fhandler_nodevice): New class. (select_stuff::device_specific): Remove array. (select_stuff::device_specific_pipe): New class element. (select_stuff::device_specific_socket): New class element. (select_stuff::device_specific_serial): New class element. (select_stuff::select_stuff): Initialize new elements. * fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class from fhandler_disk_file. (fhandler_base::fstat_by_name): Ditto. (fhandler_base::fstat_by_name): Ditto. (fhandler_disk_file::open): Move most functionality into fhandler_base::open_fs. (fhandler_base::open_fs): New function. (fhandler_disk_file::close): Move most functionality into fhandler_base::close_fs. (fhandler_base::close_fs): New function. * fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging output. * fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard urandom device into appropriate place. (fhandler_socket::accept): Reflect change in fdsock return value. * fhandler_tty.cc: See "throughouts" above. * net.cc: Accommodate fdsock change throughout. (fdsock): Return success or failure, accept fd argument and device argument. * path.cc (symlink_info::major): New element. (symlink_info::minor): New element. (symlink_info::parse_device): Declare new function. (fs_info::update): Accommodate changes in path_conv class. (path_conv::fillin): Ditto. (path_conv::return_and_clear_normalized_path): Eliminate. (path_conv::set_normalized_path): New function. (path_conv::path_conv): Set info in dev element. Use path_conv methods Check for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff. where appropriate rather than direct access. Use set_normalized_path to set normalized path. (windows_device_names): Eliminate. (get_dev): Ditto. (get_raw_device_number): Ditto. (get_device_number): Ditto. (win32_device_name): Call new device name parser to do most of the heavy lifting. (mount_info::conv_to_win32_path): Fill in dev field as appropriate. (symlink_worker): Handle new device files. (symlink_info::check): Ditto. (symlink_info::parse_device): Define new function. * path.h (executable_states): Move here from fhandler.h. (fs_info): Rename variables to *_storage and create methods for accessing same. (path_conv): Add dev element, remove devn and unit and adjust inline methods to accommodate. (set_normalized_path): Declare new function. * pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos. (_pinfo::commune_send): Ditto. * pipe.cc (fhandler_pipe::close): check for existence of handle before closing it. (handler_pipe::create): Rename from make_pipe. Change arguments to accept fhandler_pipe array. Accommodate fifos. (pipe): Rework to deal with fhandler_pipe::create changes. (_pipe): Ditto. * select.cc: Use individual device_specific types throughout rather than indexing with obsolete device number. (set_bits): Use is_socket call rather than checking device number. * shared_info.h (CURR_MOUNT_MAGIC): Update. (conv_to_win32_path): Reflect addition of device argument. * syscalls.cc (mknod_worker): New function. (open): Use build_fh_name to build fhandler. (chown_worker): Detect if this is an 'auto' device rather than an on-filesystem device and handle appropriately. (chmod_device): New function. (chmod): Detect if this is an 'auto' device rather than an on-filesystem device and handle appropriately. Use chmod_device to set mode of in-filesystem devices. (stat_worker): Eliminate path_conv argument. Call build_fh_name to construct fhandler. Use fh->error() rather than pc->error to detect errors in fhandler construction. (access_worker): New function pulled from access. Accommodate in-filesystem devices. (access): Use access_worker. (fpathconf): Detect if this is an 'auto' device rather than an on-filesystem device and handle appropriately. (mknod_worker): New function. (mknod32): New function. (chroot): Free normalized path -- assuming it was actually cmalloced. * tty.cc (create_tty_master): Tweak for new device class. (tty::common_init): Ditto. * winsup.h (stat_worker): Remove. (symlink_worker): Declare. * exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't worry about pending_signals since sig_dispatch_pending should always do the right thing now. (sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3. * pinfo.h: Move __SIG enum to sigproc.h. (PICOM_FIFO): New enum element. (_pinfo): Remove 'thread2signal' stuff throughout class. (_pinfo::commune_send): Make varargs. (_pinfo::sigtodo): Eliminate. (_pinfo::thread2signal): Ditto. * signal.cc (kill_worker): Eliminate call to setthread2signal. * sigproc.cc (local_sigtodo): Eliminate. (getlocal_sigtodo): Ditto. (sigelem): New class. (pending_signals): New class. (sigqueue): New variable, start of sigqueue linked list. (sigcatch_nonmain): Eliminate. (sigcatch_main): Eliminate. (sigcatch_nosync): Eliminate. (sigcomplete_nonmain): Eliminate. (pending_signals): Eliminate. (sig_clear): Call signal thread to clear pending signals, unless already in signal thread. (sigpending): Call signal thread to get pending signals. (sig_dispatch_pending): Eliminate use of pending_signals and just check sigqueue. (sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close signal pipe handle. (sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send signals. (getevent): Eliminate. (pending_signals::add): New function. (pending_signals::del): New function. (pending_signals::next): New function. (wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to communicate and maintain a linked list of signals. * sigproc.h: Move __SIG defines here. Add __SIGPENDING. (sig_dispatch_pending): Remove "C" specifier. (sig_handle): Accept a mask argument. * thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
#include "fhandler.h"
#include "dtable.h"
#include "cygheap.h"
#include "pinfo.h"
#include "thread.h"
* exceptions.cc (set_signal_mask): Redefine to not pass by address. Report calculated mask in debugging output. * sigproc.h (set_signal_mask): Reflect above change in declaration. * path.cc (mount_item::build_win32): Take path apart before feeding it to fnmunge. Throughout, change use of _reent_winsup()-> to _my_tls.locals. instead. Throughout, remove obsolete MT_SAFE/_CYG_THREAD_FAILSAFE considerations. Througout, add cygtls.h include. * Makefile.in (DLL_OFILES): Add cygtls.o. Add some more objects to the -fomit-frame-pointer list. * acconfig.h: Remove obsolete settings. * config.h.in: Ditto. * bsdlib.cc: Add cygtls.h include. * configure.in: Remove --enable-extra-threadsafe-checking. * configure: Regenerate. * cygtls.h (_local_storage): New struct renamed from _winsup_t (sic). (_threadinfo:local_clib): Add new field. (_threadinfo::locals): Ditto. (_threadinfo::init_thread): Accept second _reent * argument. (_threadinfo::call): Define as regparm. (CYGTLS_PADSIZE): Remove unnecessary slop. (_getreent): Define as a macro. * thread.h: Remove _CYG_THREAD_FAILSAFE and MT_SAFE stuff. (_winsup_t): Move to cygtls.h. (ResourceLocks::ResourceLocks): Eliminate empty constructor. (MTinterface::reents): Eliminate. (MTinterface::thread_self_key): Eliminate. (MTinterface::MTinterface): Eliminate. * dcrt0.cc: Include stdio.h for _impure_ptr initialization. (do_global_ctors): Remove run_ctors_p (sic) considerations. Don't call atexit here. (__main): Initialize destructors for user here. (dll_crt0_1): Accept a dummy argument. Don't call init_thread here. Don't set _impure_ptr here. Call do_global_ctors after more things have been initialized. (_dll_crt0): Define zeros buffer as max of needed size of CYGTLS_PADSIZE so that it can be used for two purposes while minimizing stack usage. Initialize _impure_ptr specifically, for speed. Call dll_crt0_1 with buffer argument. (cygwin_dll_init): Call dll_crt0_1 with dummy argument. * dtable.cc (dtable::find_unused_handle): Remove call to AssertResourceOwner. * exceptions.cc: Move _threadinfo stuff to new file. * cygtls.cc: New file. * gentls_offsets: Accommodate increasing complexity of cygtls.h. * hires.h (hires_base::~hires_base): Remove. * init.cc (dll_entry): Remove setting of reents. * thread.cc: Remove syslog.h include. (__getreent): Simplify to use _my_tls. (_reent_winsup): Delete. (AssertResourceOwner): Delete. (MTinterface::Init): Remove setting of _clib and _winsup, with all that entails. (MTinterface::fixup_after_fork): Ditto. (pthread::thread_init_wrapper): Ditto. Also remove call to set_tls_self_pointer. (pthread::set_tls_self_pointer): Eliminate. (pthread::get_tls_self_pointer): Just return _my_tls.tid; (__reent_t::init_clib): Eliminate. * tlsoffsets.h: Regenerate.
2003-12-23 17:26:31 +01:00
#include "cygtls.h"
#include "ntdll.h"
hires_ms NO_COPY gtod;
hires_ns NO_COPY ntod;
static inline void __attribute__ ((always_inline))
get_system_time (PLARGE_INTEGER systime)
{
wincap.has_precise_system_time ()
? GetSystemTimePreciseAsFileTime ((LPFILETIME) systime)
: GetSystemTimeAsFileTime ((LPFILETIME) systime);
}
2000-02-17 20:38:33 +01:00
/* Cygwin internal */
Streamline time/times functionality. Remove last remains of former Windows 9x compatibility. * fhandler_disk_file.cc (fhandler_base::fstat_helper): Drop now unneeded casts in calls to_timestruc_t. (fhandler_base::utimens_fs): Ditto for timespec_to_filetime. * fhandler_proc.cc (format_proc_stat): Ditto for to_time_t. * hires.h (class hires_ms): Remove unused member initime_ns. Remove declarations for timeGetTime_ns and prime. (hires_ms::uptime): Remove. * posix_ipc.cc (ipc_cond_timedwait): Ditto for timespec_to_filetime. * fhandler_registry.cc (fhandler_registry::fstat): Add cast. * resource.cc (fill_rusage): Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. * times.cc: Simplify time handling. Throughout, use LARGE_INTEGER rather than FILETIME to simplify computations. Throughout use {u}int64_t rather than {unsigned} long long. Drop unneeded casts since NSPERSEC is 64 bit anyway. (systime_ns): Remove. (times): Call NtQuerySystemInformation to fetch boot time. Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. Call GetSystemTimeAsFileTime. (totimeval): Use constant 1000000 as in other functions. (time_t_to_filetime): Remove. (to_time_t): Change return type to time_t. (time_as_timestruc_t): Rename filetime to systime. (time): Ditto. Add cast. (hires_ns::nsecs): Fix return type cast. (hires_ms::timeGetTime_ns): Remove. (hires_ns::prime): Remove. (hires_ms::nsecs): Drop call to prime. Call GetSystemTimeAsFileTime directly. Subtract FACTOR here since it's the only function needing to do so. (minperiod): Cosmetically change to ULONG. (hires_ns::resolution): Fix return type cast. (hires_ms::resolution): Simplify, rely on NtQueryTimerResolution. * winsup.h: Align time related prototypes to above changes.
2013-06-14 11:09:41 +02:00
static uint64_t __stdcall
__to_clock_t (PLARGE_INTEGER src, int flag)
2000-02-17 20:38:33 +01:00
{
Streamline time/times functionality. Remove last remains of former Windows 9x compatibility. * fhandler_disk_file.cc (fhandler_base::fstat_helper): Drop now unneeded casts in calls to_timestruc_t. (fhandler_base::utimens_fs): Ditto for timespec_to_filetime. * fhandler_proc.cc (format_proc_stat): Ditto for to_time_t. * hires.h (class hires_ms): Remove unused member initime_ns. Remove declarations for timeGetTime_ns and prime. (hires_ms::uptime): Remove. * posix_ipc.cc (ipc_cond_timedwait): Ditto for timespec_to_filetime. * fhandler_registry.cc (fhandler_registry::fstat): Add cast. * resource.cc (fill_rusage): Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. * times.cc: Simplify time handling. Throughout, use LARGE_INTEGER rather than FILETIME to simplify computations. Throughout use {u}int64_t rather than {unsigned} long long. Drop unneeded casts since NSPERSEC is 64 bit anyway. (systime_ns): Remove. (times): Call NtQuerySystemInformation to fetch boot time. Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. Call GetSystemTimeAsFileTime. (totimeval): Use constant 1000000 as in other functions. (time_t_to_filetime): Remove. (to_time_t): Change return type to time_t. (time_as_timestruc_t): Rename filetime to systime. (time): Ditto. Add cast. (hires_ns::nsecs): Fix return type cast. (hires_ms::timeGetTime_ns): Remove. (hires_ns::prime): Remove. (hires_ms::nsecs): Drop call to prime. Call GetSystemTimeAsFileTime directly. Subtract FACTOR here since it's the only function needing to do so. (minperiod): Cosmetically change to ULONG. (hires_ns::resolution): Fix return type cast. (hires_ms::resolution): Simplify, rely on NtQueryTimerResolution. * winsup.h: Align time related prototypes to above changes.
2013-06-14 11:09:41 +02:00
uint64_t total = src->QuadPart;
2000-02-17 20:38:33 +01:00
/* Convert into clock ticks - the total is in 10ths of a usec. */
if (flag)
total -= FACTOR;
total /= NS100PERSEC / CLOCKS_PER_SEC;
2000-02-17 20:38:33 +01:00
return total;
}
/* times: POSIX 4.5.2.1 */
extern "C" clock_t
times (struct tms *buf)
2000-02-17 20:38:33 +01:00
{
Streamline time/times functionality. Remove last remains of former Windows 9x compatibility. * fhandler_disk_file.cc (fhandler_base::fstat_helper): Drop now unneeded casts in calls to_timestruc_t. (fhandler_base::utimens_fs): Ditto for timespec_to_filetime. * fhandler_proc.cc (format_proc_stat): Ditto for to_time_t. * hires.h (class hires_ms): Remove unused member initime_ns. Remove declarations for timeGetTime_ns and prime. (hires_ms::uptime): Remove. * posix_ipc.cc (ipc_cond_timedwait): Ditto for timespec_to_filetime. * fhandler_registry.cc (fhandler_registry::fstat): Add cast. * resource.cc (fill_rusage): Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. * times.cc: Simplify time handling. Throughout, use LARGE_INTEGER rather than FILETIME to simplify computations. Throughout use {u}int64_t rather than {unsigned} long long. Drop unneeded casts since NSPERSEC is 64 bit anyway. (systime_ns): Remove. (times): Call NtQuerySystemInformation to fetch boot time. Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. Call GetSystemTimeAsFileTime. (totimeval): Use constant 1000000 as in other functions. (time_t_to_filetime): Remove. (to_time_t): Change return type to time_t. (time_as_timestruc_t): Rename filetime to systime. (time): Ditto. Add cast. (hires_ns::nsecs): Fix return type cast. (hires_ms::timeGetTime_ns): Remove. (hires_ns::prime): Remove. (hires_ms::nsecs): Drop call to prime. Call GetSystemTimeAsFileTime directly. Subtract FACTOR here since it's the only function needing to do so. (minperiod): Cosmetically change to ULONG. (hires_ns::resolution): Fix return type cast. (hires_ms::resolution): Simplify, rely on NtQueryTimerResolution. * winsup.h: Align time related prototypes to above changes.
2013-06-14 11:09:41 +02:00
static SYSTEM_TIMEOFDAY_INFORMATION stodi;
KERNEL_USER_TIMES kut;
LARGE_INTEGER ticks;
* Throughout, use __try/__except/__endtry blocks, rather than myfault handler. * cygtls.cc (_cygtls::remove): Accommodate the fact that pathbufs has been moved from _local_storage to _cygtls. * cygtls.h (class tls_pathbuf): Add comment to hint to gendef usage of counters. Change type of counters to uint32_t for clarity. Remove _cygtls as friend class. (struct _local_storage): Move pathbufs from here... (struct _cygtls): ...to here, allowing to access it from _sigbe. (class san): Only define on 32 bit. Remove errno, _c_cnt and _w_cnt members. (san::setup): Drop parameter. Don't initialize removed members. (san::leave): Don't set removed members. (class myfault): Only define on 32 bit. (myfault::faulted): Only keep implementation not taking any parameter. Drop argument in call to sebastian.setup. (__try/__leave/__except/__endtry): Implement to support real SEH. For now stick to SJLJ on 32 bit. * dcrt0.cc (dll_crt0_0): Drop 64 bit call to exception::install_myfault_handler. * exception.h (exception_handler): Define with EXCEPTION_DISPOSITION as return type. (PDISPATCHER_CONTEXT): Define as void * on 32 bit. Define as pointer to _DISPATCHER_CONTEXT on 64 bit. (class exception): Define separately for 32 and 64 bit. (exception::myfault): Add handler for myfault SEH handling on 64 bit. (exception::exception): Fix mangled method name to account for change in type of last parameter. (exception::install_myfault_handler): Remove. * exceptions.cc (exception::myfault_handle): Remove. (exception::myfault): New SEH handler for 64 bit. * gendef (_sigbe): Set tls_pathbuf counters to 0 explicitely when returning to the caller. * ntdll.h: Move a comment to a better place. (struct _SCOPE_TABLE): Define on 64 bit. * thread.cc (verifyable_object_isvalid): Remove gcc 4.7 workaround. * tls_pbuf.cc (tls_pbuf): Fix to accommodate new place of pathbufs. (tls_pathbuf::destroy): Change type of loop variables to uint32_t. * tls_pbuf.h (class tmp_pathbuf): Change type of buffer counters to uint32_t. Accommodate new place of pathbufs. * tlsoffsets.h: Regenerate. * tlsoffsets64.h: Regenerate.
2014-08-22 11:21:33 +02:00
clock_t tc = (clock_t) -1;
* Throughout, use __try/__except/__endtry blocks, rather than myfault handler. * cygtls.cc (_cygtls::remove): Accommodate the fact that pathbufs has been moved from _local_storage to _cygtls. * cygtls.h (class tls_pathbuf): Add comment to hint to gendef usage of counters. Change type of counters to uint32_t for clarity. Remove _cygtls as friend class. (struct _local_storage): Move pathbufs from here... (struct _cygtls): ...to here, allowing to access it from _sigbe. (class san): Only define on 32 bit. Remove errno, _c_cnt and _w_cnt members. (san::setup): Drop parameter. Don't initialize removed members. (san::leave): Don't set removed members. (class myfault): Only define on 32 bit. (myfault::faulted): Only keep implementation not taking any parameter. Drop argument in call to sebastian.setup. (__try/__leave/__except/__endtry): Implement to support real SEH. For now stick to SJLJ on 32 bit. * dcrt0.cc (dll_crt0_0): Drop 64 bit call to exception::install_myfault_handler. * exception.h (exception_handler): Define with EXCEPTION_DISPOSITION as return type. (PDISPATCHER_CONTEXT): Define as void * on 32 bit. Define as pointer to _DISPATCHER_CONTEXT on 64 bit. (class exception): Define separately for 32 and 64 bit. (exception::myfault): Add handler for myfault SEH handling on 64 bit. (exception::exception): Fix mangled method name to account for change in type of last parameter. (exception::install_myfault_handler): Remove. * exceptions.cc (exception::myfault_handle): Remove. (exception::myfault): New SEH handler for 64 bit. * gendef (_sigbe): Set tls_pathbuf counters to 0 explicitely when returning to the caller. * ntdll.h: Move a comment to a better place. (struct _SCOPE_TABLE): Define on 64 bit. * thread.cc (verifyable_object_isvalid): Remove gcc 4.7 workaround. * tls_pbuf.cc (tls_pbuf): Fix to accommodate new place of pathbufs. (tls_pathbuf::destroy): Change type of loop variables to uint32_t. * tls_pbuf.h (class tmp_pathbuf): Change type of buffer counters to uint32_t. Accommodate new place of pathbufs. * tlsoffsets.h: Regenerate. * tlsoffsets64.h: Regenerate.
2014-08-22 11:21:33 +02:00
__try
{
/* Fetch boot time if we haven't already. */
if (!stodi.BootTime.QuadPart)
NtQuerySystemInformation (SystemTimeOfDayInformation,
&stodi, sizeof stodi, NULL);
NtQueryInformationProcess (NtCurrentProcess (), ProcessTimes,
&kut, sizeof kut, NULL);
get_system_time (&ticks);
/* uptime */
ticks.QuadPart -= stodi.BootTime.QuadPart;
/* ticks is in in 100ns, convert to clock ticks. */
tc = (clock_t) (ticks.QuadPart * CLOCKS_PER_SEC / NS100PERSEC);
* Throughout, use __try/__except/__endtry blocks, rather than myfault handler. * cygtls.cc (_cygtls::remove): Accommodate the fact that pathbufs has been moved from _local_storage to _cygtls. * cygtls.h (class tls_pathbuf): Add comment to hint to gendef usage of counters. Change type of counters to uint32_t for clarity. Remove _cygtls as friend class. (struct _local_storage): Move pathbufs from here... (struct _cygtls): ...to here, allowing to access it from _sigbe. (class san): Only define on 32 bit. Remove errno, _c_cnt and _w_cnt members. (san::setup): Drop parameter. Don't initialize removed members. (san::leave): Don't set removed members. (class myfault): Only define on 32 bit. (myfault::faulted): Only keep implementation not taking any parameter. Drop argument in call to sebastian.setup. (__try/__leave/__except/__endtry): Implement to support real SEH. For now stick to SJLJ on 32 bit. * dcrt0.cc (dll_crt0_0): Drop 64 bit call to exception::install_myfault_handler. * exception.h (exception_handler): Define with EXCEPTION_DISPOSITION as return type. (PDISPATCHER_CONTEXT): Define as void * on 32 bit. Define as pointer to _DISPATCHER_CONTEXT on 64 bit. (class exception): Define separately for 32 and 64 bit. (exception::myfault): Add handler for myfault SEH handling on 64 bit. (exception::exception): Fix mangled method name to account for change in type of last parameter. (exception::install_myfault_handler): Remove. * exceptions.cc (exception::myfault_handle): Remove. (exception::myfault): New SEH handler for 64 bit. * gendef (_sigbe): Set tls_pathbuf counters to 0 explicitely when returning to the caller. * ntdll.h: Move a comment to a better place. (struct _SCOPE_TABLE): Define on 64 bit. * thread.cc (verifyable_object_isvalid): Remove gcc 4.7 workaround. * tls_pbuf.cc (tls_pbuf): Fix to accommodate new place of pathbufs. (tls_pathbuf::destroy): Change type of loop variables to uint32_t. * tls_pbuf.h (class tmp_pathbuf): Change type of buffer counters to uint32_t. Accommodate new place of pathbufs. * tlsoffsets.h: Regenerate. * tlsoffsets64.h: Regenerate.
2014-08-22 11:21:33 +02:00
buf->tms_stime = __to_clock_t (&kut.KernelTime, 0);
buf->tms_utime = __to_clock_t (&kut.UserTime, 0);
timeval_to_filetime (&myself->rusage_children.ru_stime, &kut.KernelTime);
buf->tms_cstime = __to_clock_t (&kut.KernelTime, 1);
timeval_to_filetime (&myself->rusage_children.ru_utime, &kut.UserTime);
buf->tms_cutime = __to_clock_t (&kut.UserTime, 1);
}
__except (EFAULT)
{
tc = (clock_t) -1;
}
__endtry
syscall_printf ("%D = times(%p)", tc, buf);
return tc;
2000-02-17 20:38:33 +01:00
}
EXPORT_ALIAS (times, _times)
2000-02-17 20:38:33 +01:00
/* settimeofday: BSD */
extern "C" int
settimeofday (const struct timeval *tv, const struct timezone *tz)
2000-02-17 20:38:33 +01:00
{
SYSTEMTIME st;
struct tm *ptm;
* Throughout, use __try/__except/__endtry blocks, rather than myfault handler. * cygtls.cc (_cygtls::remove): Accommodate the fact that pathbufs has been moved from _local_storage to _cygtls. * cygtls.h (class tls_pathbuf): Add comment to hint to gendef usage of counters. Change type of counters to uint32_t for clarity. Remove _cygtls as friend class. (struct _local_storage): Move pathbufs from here... (struct _cygtls): ...to here, allowing to access it from _sigbe. (class san): Only define on 32 bit. Remove errno, _c_cnt and _w_cnt members. (san::setup): Drop parameter. Don't initialize removed members. (san::leave): Don't set removed members. (class myfault): Only define on 32 bit. (myfault::faulted): Only keep implementation not taking any parameter. Drop argument in call to sebastian.setup. (__try/__leave/__except/__endtry): Implement to support real SEH. For now stick to SJLJ on 32 bit. * dcrt0.cc (dll_crt0_0): Drop 64 bit call to exception::install_myfault_handler. * exception.h (exception_handler): Define with EXCEPTION_DISPOSITION as return type. (PDISPATCHER_CONTEXT): Define as void * on 32 bit. Define as pointer to _DISPATCHER_CONTEXT on 64 bit. (class exception): Define separately for 32 and 64 bit. (exception::myfault): Add handler for myfault SEH handling on 64 bit. (exception::exception): Fix mangled method name to account for change in type of last parameter. (exception::install_myfault_handler): Remove. * exceptions.cc (exception::myfault_handle): Remove. (exception::myfault): New SEH handler for 64 bit. * gendef (_sigbe): Set tls_pathbuf counters to 0 explicitely when returning to the caller. * ntdll.h: Move a comment to a better place. (struct _SCOPE_TABLE): Define on 64 bit. * thread.cc (verifyable_object_isvalid): Remove gcc 4.7 workaround. * tls_pbuf.cc (tls_pbuf): Fix to accommodate new place of pathbufs. (tls_pathbuf::destroy): Change type of loop variables to uint32_t. * tls_pbuf.h (class tmp_pathbuf): Change type of buffer counters to uint32_t. Accommodate new place of pathbufs. * tlsoffsets.h: Regenerate. * tlsoffsets64.h: Regenerate.
2014-08-22 11:21:33 +02:00
int res = -1;
* Throughout, use __try/__except/__endtry blocks, rather than myfault handler. * cygtls.cc (_cygtls::remove): Accommodate the fact that pathbufs has been moved from _local_storage to _cygtls. * cygtls.h (class tls_pathbuf): Add comment to hint to gendef usage of counters. Change type of counters to uint32_t for clarity. Remove _cygtls as friend class. (struct _local_storage): Move pathbufs from here... (struct _cygtls): ...to here, allowing to access it from _sigbe. (class san): Only define on 32 bit. Remove errno, _c_cnt and _w_cnt members. (san::setup): Drop parameter. Don't initialize removed members. (san::leave): Don't set removed members. (class myfault): Only define on 32 bit. (myfault::faulted): Only keep implementation not taking any parameter. Drop argument in call to sebastian.setup. (__try/__leave/__except/__endtry): Implement to support real SEH. For now stick to SJLJ on 32 bit. * dcrt0.cc (dll_crt0_0): Drop 64 bit call to exception::install_myfault_handler. * exception.h (exception_handler): Define with EXCEPTION_DISPOSITION as return type. (PDISPATCHER_CONTEXT): Define as void * on 32 bit. Define as pointer to _DISPATCHER_CONTEXT on 64 bit. (class exception): Define separately for 32 and 64 bit. (exception::myfault): Add handler for myfault SEH handling on 64 bit. (exception::exception): Fix mangled method name to account for change in type of last parameter. (exception::install_myfault_handler): Remove. * exceptions.cc (exception::myfault_handle): Remove. (exception::myfault): New SEH handler for 64 bit. * gendef (_sigbe): Set tls_pathbuf counters to 0 explicitely when returning to the caller. * ntdll.h: Move a comment to a better place. (struct _SCOPE_TABLE): Define on 64 bit. * thread.cc (verifyable_object_isvalid): Remove gcc 4.7 workaround. * tls_pbuf.cc (tls_pbuf): Fix to accommodate new place of pathbufs. (tls_pathbuf::destroy): Change type of loop variables to uint32_t. * tls_pbuf.h (class tmp_pathbuf): Change type of buffer counters to uint32_t. Accommodate new place of pathbufs. * tlsoffsets.h: Regenerate. * tlsoffsets64.h: Regenerate.
2014-08-22 11:21:33 +02:00
__try
{
if (tv->tv_usec < 0 || tv->tv_usec >= USPERSEC)
* Throughout, use __try/__except/__endtry blocks, rather than myfault handler. * cygtls.cc (_cygtls::remove): Accommodate the fact that pathbufs has been moved from _local_storage to _cygtls. * cygtls.h (class tls_pathbuf): Add comment to hint to gendef usage of counters. Change type of counters to uint32_t for clarity. Remove _cygtls as friend class. (struct _local_storage): Move pathbufs from here... (struct _cygtls): ...to here, allowing to access it from _sigbe. (class san): Only define on 32 bit. Remove errno, _c_cnt and _w_cnt members. (san::setup): Drop parameter. Don't initialize removed members. (san::leave): Don't set removed members. (class myfault): Only define on 32 bit. (myfault::faulted): Only keep implementation not taking any parameter. Drop argument in call to sebastian.setup. (__try/__leave/__except/__endtry): Implement to support real SEH. For now stick to SJLJ on 32 bit. * dcrt0.cc (dll_crt0_0): Drop 64 bit call to exception::install_myfault_handler. * exception.h (exception_handler): Define with EXCEPTION_DISPOSITION as return type. (PDISPATCHER_CONTEXT): Define as void * on 32 bit. Define as pointer to _DISPATCHER_CONTEXT on 64 bit. (class exception): Define separately for 32 and 64 bit. (exception::myfault): Add handler for myfault SEH handling on 64 bit. (exception::exception): Fix mangled method name to account for change in type of last parameter. (exception::install_myfault_handler): Remove. * exceptions.cc (exception::myfault_handle): Remove. (exception::myfault): New SEH handler for 64 bit. * gendef (_sigbe): Set tls_pathbuf counters to 0 explicitely when returning to the caller. * ntdll.h: Move a comment to a better place. (struct _SCOPE_TABLE): Define on 64 bit. * thread.cc (verifyable_object_isvalid): Remove gcc 4.7 workaround. * tls_pbuf.cc (tls_pbuf): Fix to accommodate new place of pathbufs. (tls_pathbuf::destroy): Change type of loop variables to uint32_t. * tls_pbuf.h (class tmp_pathbuf): Change type of buffer counters to uint32_t. Accommodate new place of pathbufs. * tlsoffsets.h: Regenerate. * tlsoffsets64.h: Regenerate.
2014-08-22 11:21:33 +02:00
{
set_errno (EINVAL);
return -1;
}
ptm = gmtime (&tv->tv_sec);
st.wYear = ptm->tm_year + 1900;
st.wMonth = ptm->tm_mon + 1;
st.wDayOfWeek = ptm->tm_wday;
st.wDay = ptm->tm_mday;
st.wHour = ptm->tm_hour;
st.wMinute = ptm->tm_min;
st.wSecond = ptm->tm_sec;
st.wMilliseconds = tv->tv_usec / (USPERSEC / MSPERSEC);
* Throughout, use __try/__except/__endtry blocks, rather than myfault handler. * cygtls.cc (_cygtls::remove): Accommodate the fact that pathbufs has been moved from _local_storage to _cygtls. * cygtls.h (class tls_pathbuf): Add comment to hint to gendef usage of counters. Change type of counters to uint32_t for clarity. Remove _cygtls as friend class. (struct _local_storage): Move pathbufs from here... (struct _cygtls): ...to here, allowing to access it from _sigbe. (class san): Only define on 32 bit. Remove errno, _c_cnt and _w_cnt members. (san::setup): Drop parameter. Don't initialize removed members. (san::leave): Don't set removed members. (class myfault): Only define on 32 bit. (myfault::faulted): Only keep implementation not taking any parameter. Drop argument in call to sebastian.setup. (__try/__leave/__except/__endtry): Implement to support real SEH. For now stick to SJLJ on 32 bit. * dcrt0.cc (dll_crt0_0): Drop 64 bit call to exception::install_myfault_handler. * exception.h (exception_handler): Define with EXCEPTION_DISPOSITION as return type. (PDISPATCHER_CONTEXT): Define as void * on 32 bit. Define as pointer to _DISPATCHER_CONTEXT on 64 bit. (class exception): Define separately for 32 and 64 bit. (exception::myfault): Add handler for myfault SEH handling on 64 bit. (exception::exception): Fix mangled method name to account for change in type of last parameter. (exception::install_myfault_handler): Remove. * exceptions.cc (exception::myfault_handle): Remove. (exception::myfault): New SEH handler for 64 bit. * gendef (_sigbe): Set tls_pathbuf counters to 0 explicitely when returning to the caller. * ntdll.h: Move a comment to a better place. (struct _SCOPE_TABLE): Define on 64 bit. * thread.cc (verifyable_object_isvalid): Remove gcc 4.7 workaround. * tls_pbuf.cc (tls_pbuf): Fix to accommodate new place of pathbufs. (tls_pathbuf::destroy): Change type of loop variables to uint32_t. * tls_pbuf.h (class tmp_pathbuf): Change type of buffer counters to uint32_t. Accommodate new place of pathbufs. * tlsoffsets.h: Regenerate. * tlsoffsets64.h: Regenerate.
2014-08-22 11:21:33 +02:00
res = -!SetSystemTime (&st);
gtod.reset ();
if (res)
set_errno (EPERM);
}
* Throughout, use __try/__except/__endtry blocks, rather than myfault handler. * cygtls.cc (_cygtls::remove): Accommodate the fact that pathbufs has been moved from _local_storage to _cygtls. * cygtls.h (class tls_pathbuf): Add comment to hint to gendef usage of counters. Change type of counters to uint32_t for clarity. Remove _cygtls as friend class. (struct _local_storage): Move pathbufs from here... (struct _cygtls): ...to here, allowing to access it from _sigbe. (class san): Only define on 32 bit. Remove errno, _c_cnt and _w_cnt members. (san::setup): Drop parameter. Don't initialize removed members. (san::leave): Don't set removed members. (class myfault): Only define on 32 bit. (myfault::faulted): Only keep implementation not taking any parameter. Drop argument in call to sebastian.setup. (__try/__leave/__except/__endtry): Implement to support real SEH. For now stick to SJLJ on 32 bit. * dcrt0.cc (dll_crt0_0): Drop 64 bit call to exception::install_myfault_handler. * exception.h (exception_handler): Define with EXCEPTION_DISPOSITION as return type. (PDISPATCHER_CONTEXT): Define as void * on 32 bit. Define as pointer to _DISPATCHER_CONTEXT on 64 bit. (class exception): Define separately for 32 and 64 bit. (exception::myfault): Add handler for myfault SEH handling on 64 bit. (exception::exception): Fix mangled method name to account for change in type of last parameter. (exception::install_myfault_handler): Remove. * exceptions.cc (exception::myfault_handle): Remove. (exception::myfault): New SEH handler for 64 bit. * gendef (_sigbe): Set tls_pathbuf counters to 0 explicitely when returning to the caller. * ntdll.h: Move a comment to a better place. (struct _SCOPE_TABLE): Define on 64 bit. * thread.cc (verifyable_object_isvalid): Remove gcc 4.7 workaround. * tls_pbuf.cc (tls_pbuf): Fix to accommodate new place of pathbufs. (tls_pathbuf::destroy): Change type of loop variables to uint32_t. * tls_pbuf.h (class tmp_pathbuf): Change type of buffer counters to uint32_t. Accommodate new place of pathbufs. * tlsoffsets.h: Regenerate. * tlsoffsets64.h: Regenerate.
2014-08-22 11:21:33 +02:00
__except (EFAULT)
{
res = -1;
}
__endtry
2013-04-23 11:44:36 +02:00
syscall_printf ("%R = settimeofday(%p, %p)", res, tv, tz);
return res;
2000-02-17 20:38:33 +01:00
}
/* stime: SVr4 */
extern "C" int
stime (const time_t *t)
{
struct timeval tv = { *t, 0 };
return settimeofday(&tv, NULL);
}
2000-02-17 20:38:33 +01:00
/* timezone: standards? */
extern "C" char *
timezone (void)
2000-02-17 20:38:33 +01:00
{
* exceptions.cc (set_signal_mask): Redefine to not pass by address. Report calculated mask in debugging output. * sigproc.h (set_signal_mask): Reflect above change in declaration. * path.cc (mount_item::build_win32): Take path apart before feeding it to fnmunge. Throughout, change use of _reent_winsup()-> to _my_tls.locals. instead. Throughout, remove obsolete MT_SAFE/_CYG_THREAD_FAILSAFE considerations. Througout, add cygtls.h include. * Makefile.in (DLL_OFILES): Add cygtls.o. Add some more objects to the -fomit-frame-pointer list. * acconfig.h: Remove obsolete settings. * config.h.in: Ditto. * bsdlib.cc: Add cygtls.h include. * configure.in: Remove --enable-extra-threadsafe-checking. * configure: Regenerate. * cygtls.h (_local_storage): New struct renamed from _winsup_t (sic). (_threadinfo:local_clib): Add new field. (_threadinfo::locals): Ditto. (_threadinfo::init_thread): Accept second _reent * argument. (_threadinfo::call): Define as regparm. (CYGTLS_PADSIZE): Remove unnecessary slop. (_getreent): Define as a macro. * thread.h: Remove _CYG_THREAD_FAILSAFE and MT_SAFE stuff. (_winsup_t): Move to cygtls.h. (ResourceLocks::ResourceLocks): Eliminate empty constructor. (MTinterface::reents): Eliminate. (MTinterface::thread_self_key): Eliminate. (MTinterface::MTinterface): Eliminate. * dcrt0.cc: Include stdio.h for _impure_ptr initialization. (do_global_ctors): Remove run_ctors_p (sic) considerations. Don't call atexit here. (__main): Initialize destructors for user here. (dll_crt0_1): Accept a dummy argument. Don't call init_thread here. Don't set _impure_ptr here. Call do_global_ctors after more things have been initialized. (_dll_crt0): Define zeros buffer as max of needed size of CYGTLS_PADSIZE so that it can be used for two purposes while minimizing stack usage. Initialize _impure_ptr specifically, for speed. Call dll_crt0_1 with buffer argument. (cygwin_dll_init): Call dll_crt0_1 with dummy argument. * dtable.cc (dtable::find_unused_handle): Remove call to AssertResourceOwner. * exceptions.cc: Move _threadinfo stuff to new file. * cygtls.cc: New file. * gentls_offsets: Accommodate increasing complexity of cygtls.h. * hires.h (hires_base::~hires_base): Remove. * init.cc (dll_entry): Remove setting of reents. * thread.cc: Remove syslog.h include. (__getreent): Simplify to use _my_tls. (_reent_winsup): Delete. (AssertResourceOwner): Delete. (MTinterface::Init): Remove setting of _clib and _winsup, with all that entails. (MTinterface::fixup_after_fork): Ditto. (pthread::thread_init_wrapper): Ditto. Also remove call to set_tls_self_pointer. (pthread::set_tls_self_pointer): Eliminate. (pthread::get_tls_self_pointer): Just return _my_tls.tid; (__reent_t::init_clib): Eliminate. * tlsoffsets.h: Regenerate.
2003-12-23 17:26:31 +01:00
char *b = _my_tls.locals.timezone_buf;
2000-02-17 20:38:33 +01:00
tzset ();
__small_sprintf (b,"GMT%+d:%02d", (int) (-_timezone / 3600), (int) (abs (_timezone / 60) % 60));
2000-02-17 20:38:33 +01:00
return b;
}
/* Cygwin internal */
void __stdcall
Streamline time/times functionality. Remove last remains of former Windows 9x compatibility. * fhandler_disk_file.cc (fhandler_base::fstat_helper): Drop now unneeded casts in calls to_timestruc_t. (fhandler_base::utimens_fs): Ditto for timespec_to_filetime. * fhandler_proc.cc (format_proc_stat): Ditto for to_time_t. * hires.h (class hires_ms): Remove unused member initime_ns. Remove declarations for timeGetTime_ns and prime. (hires_ms::uptime): Remove. * posix_ipc.cc (ipc_cond_timedwait): Ditto for timespec_to_filetime. * fhandler_registry.cc (fhandler_registry::fstat): Add cast. * resource.cc (fill_rusage): Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. * times.cc: Simplify time handling. Throughout, use LARGE_INTEGER rather than FILETIME to simplify computations. Throughout use {u}int64_t rather than {unsigned} long long. Drop unneeded casts since NSPERSEC is 64 bit anyway. (systime_ns): Remove. (times): Call NtQuerySystemInformation to fetch boot time. Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. Call GetSystemTimeAsFileTime. (totimeval): Use constant 1000000 as in other functions. (time_t_to_filetime): Remove. (to_time_t): Change return type to time_t. (time_as_timestruc_t): Rename filetime to systime. (time): Ditto. Add cast. (hires_ns::nsecs): Fix return type cast. (hires_ms::timeGetTime_ns): Remove. (hires_ns::prime): Remove. (hires_ms::nsecs): Drop call to prime. Call GetSystemTimeAsFileTime directly. Subtract FACTOR here since it's the only function needing to do so. (minperiod): Cosmetically change to ULONG. (hires_ns::resolution): Fix return type cast. (hires_ms::resolution): Simplify, rely on NtQueryTimerResolution. * winsup.h: Align time related prototypes to above changes.
2013-06-14 11:09:41 +02:00
totimeval (struct timeval *dst, PLARGE_INTEGER src, int sub, int flag)
2000-02-17 20:38:33 +01:00
{
Streamline time/times functionality. Remove last remains of former Windows 9x compatibility. * fhandler_disk_file.cc (fhandler_base::fstat_helper): Drop now unneeded casts in calls to_timestruc_t. (fhandler_base::utimens_fs): Ditto for timespec_to_filetime. * fhandler_proc.cc (format_proc_stat): Ditto for to_time_t. * hires.h (class hires_ms): Remove unused member initime_ns. Remove declarations for timeGetTime_ns and prime. (hires_ms::uptime): Remove. * posix_ipc.cc (ipc_cond_timedwait): Ditto for timespec_to_filetime. * fhandler_registry.cc (fhandler_registry::fstat): Add cast. * resource.cc (fill_rusage): Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. * times.cc: Simplify time handling. Throughout, use LARGE_INTEGER rather than FILETIME to simplify computations. Throughout use {u}int64_t rather than {unsigned} long long. Drop unneeded casts since NSPERSEC is 64 bit anyway. (systime_ns): Remove. (times): Call NtQuerySystemInformation to fetch boot time. Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. Call GetSystemTimeAsFileTime. (totimeval): Use constant 1000000 as in other functions. (time_t_to_filetime): Remove. (to_time_t): Change return type to time_t. (time_as_timestruc_t): Rename filetime to systime. (time): Ditto. Add cast. (hires_ns::nsecs): Fix return type cast. (hires_ms::timeGetTime_ns): Remove. (hires_ns::prime): Remove. (hires_ms::nsecs): Drop call to prime. Call GetSystemTimeAsFileTime directly. Subtract FACTOR here since it's the only function needing to do so. (minperiod): Cosmetically change to ULONG. (hires_ns::resolution): Fix return type cast. (hires_ms::resolution): Simplify, rely on NtQueryTimerResolution. * winsup.h: Align time related prototypes to above changes.
2013-06-14 11:09:41 +02:00
int64_t x = __to_clock_t (src, flag);
2000-02-17 20:38:33 +01:00
x *= (int64_t) USPERSEC / CLOCKS_PER_SEC; /* Turn x into usecs */
x -= (int64_t) sub * USPERSEC;
2000-02-17 20:38:33 +01:00
dst->tv_usec = x % USPERSEC; /* And split */
dst->tv_sec = x / USPERSEC;
2000-02-17 20:38:33 +01:00
}
/* FIXME: Make thread safe */
2000-02-17 20:38:33 +01:00
extern "C" int
gettimeofday (struct timeval *__restrict tv, void *__restrict tzvp)
2000-02-17 20:38:33 +01:00
{
struct timezone *tz = (struct timezone *) tzvp;
static bool tzflag;
LONGLONG now = gtod.usecs ();
if (now == (LONGLONG) -1)
return -1;
2000-02-17 20:38:33 +01:00
tv->tv_sec = now / USPERSEC;
tv->tv_usec = now % USPERSEC;
if (tz != NULL)
{
2002-05-12 03:50:38 +02:00
if (!tzflag)
{
tzset ();
2002-05-12 03:50:38 +02:00
tzflag = true;
}
tz->tz_minuteswest = _timezone / 60;
tz->tz_dsttime = _daylight;
}
return 0;
2000-02-17 20:38:33 +01:00
}
EXPORT_ALIAS (gettimeofday, _gettimeofday)
2000-02-17 20:38:33 +01:00
/* Cygwin internal */
void __stdcall
Streamline time/times functionality. Remove last remains of former Windows 9x compatibility. * fhandler_disk_file.cc (fhandler_base::fstat_helper): Drop now unneeded casts in calls to_timestruc_t. (fhandler_base::utimens_fs): Ditto for timespec_to_filetime. * fhandler_proc.cc (format_proc_stat): Ditto for to_time_t. * hires.h (class hires_ms): Remove unused member initime_ns. Remove declarations for timeGetTime_ns and prime. (hires_ms::uptime): Remove. * posix_ipc.cc (ipc_cond_timedwait): Ditto for timespec_to_filetime. * fhandler_registry.cc (fhandler_registry::fstat): Add cast. * resource.cc (fill_rusage): Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. * times.cc: Simplify time handling. Throughout, use LARGE_INTEGER rather than FILETIME to simplify computations. Throughout use {u}int64_t rather than {unsigned} long long. Drop unneeded casts since NSPERSEC is 64 bit anyway. (systime_ns): Remove. (times): Call NtQuerySystemInformation to fetch boot time. Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. Call GetSystemTimeAsFileTime. (totimeval): Use constant 1000000 as in other functions. (time_t_to_filetime): Remove. (to_time_t): Change return type to time_t. (time_as_timestruc_t): Rename filetime to systime. (time): Ditto. Add cast. (hires_ns::nsecs): Fix return type cast. (hires_ms::timeGetTime_ns): Remove. (hires_ns::prime): Remove. (hires_ms::nsecs): Drop call to prime. Call GetSystemTimeAsFileTime directly. Subtract FACTOR here since it's the only function needing to do so. (minperiod): Cosmetically change to ULONG. (hires_ns::resolution): Fix return type cast. (hires_ms::resolution): Simplify, rely on NtQueryTimerResolution. * winsup.h: Align time related prototypes to above changes.
2013-06-14 11:09:41 +02:00
timespec_to_filetime (const struct timespec *time_in, PLARGE_INTEGER out)
{
if (time_in->tv_nsec == UTIME_OMIT)
Streamline time/times functionality. Remove last remains of former Windows 9x compatibility. * fhandler_disk_file.cc (fhandler_base::fstat_helper): Drop now unneeded casts in calls to_timestruc_t. (fhandler_base::utimens_fs): Ditto for timespec_to_filetime. * fhandler_proc.cc (format_proc_stat): Ditto for to_time_t. * hires.h (class hires_ms): Remove unused member initime_ns. Remove declarations for timeGetTime_ns and prime. (hires_ms::uptime): Remove. * posix_ipc.cc (ipc_cond_timedwait): Ditto for timespec_to_filetime. * fhandler_registry.cc (fhandler_registry::fstat): Add cast. * resource.cc (fill_rusage): Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. * times.cc: Simplify time handling. Throughout, use LARGE_INTEGER rather than FILETIME to simplify computations. Throughout use {u}int64_t rather than {unsigned} long long. Drop unneeded casts since NSPERSEC is 64 bit anyway. (systime_ns): Remove. (times): Call NtQuerySystemInformation to fetch boot time. Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. Call GetSystemTimeAsFileTime. (totimeval): Use constant 1000000 as in other functions. (time_t_to_filetime): Remove. (to_time_t): Change return type to time_t. (time_as_timestruc_t): Rename filetime to systime. (time): Ditto. Add cast. (hires_ns::nsecs): Fix return type cast. (hires_ms::timeGetTime_ns): Remove. (hires_ns::prime): Remove. (hires_ms::nsecs): Drop call to prime. Call GetSystemTimeAsFileTime directly. Subtract FACTOR here since it's the only function needing to do so. (minperiod): Cosmetically change to ULONG. (hires_ns::resolution): Fix return type cast. (hires_ms::resolution): Simplify, rely on NtQueryTimerResolution. * winsup.h: Align time related prototypes to above changes.
2013-06-14 11:09:41 +02:00
out->QuadPart = 0;
else
out->QuadPart = time_in->tv_sec * NS100PERSEC
+ time_in->tv_nsec / (NSPERSEC/NS100PERSEC) + FACTOR;
}
2000-02-17 20:38:33 +01:00
/* Cygwin internal */
void __stdcall
Streamline time/times functionality. Remove last remains of former Windows 9x compatibility. * fhandler_disk_file.cc (fhandler_base::fstat_helper): Drop now unneeded casts in calls to_timestruc_t. (fhandler_base::utimens_fs): Ditto for timespec_to_filetime. * fhandler_proc.cc (format_proc_stat): Ditto for to_time_t. * hires.h (class hires_ms): Remove unused member initime_ns. Remove declarations for timeGetTime_ns and prime. (hires_ms::uptime): Remove. * posix_ipc.cc (ipc_cond_timedwait): Ditto for timespec_to_filetime. * fhandler_registry.cc (fhandler_registry::fstat): Add cast. * resource.cc (fill_rusage): Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. * times.cc: Simplify time handling. Throughout, use LARGE_INTEGER rather than FILETIME to simplify computations. Throughout use {u}int64_t rather than {unsigned} long long. Drop unneeded casts since NSPERSEC is 64 bit anyway. (systime_ns): Remove. (times): Call NtQuerySystemInformation to fetch boot time. Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. Call GetSystemTimeAsFileTime. (totimeval): Use constant 1000000 as in other functions. (time_t_to_filetime): Remove. (to_time_t): Change return type to time_t. (time_as_timestruc_t): Rename filetime to systime. (time): Ditto. Add cast. (hires_ns::nsecs): Fix return type cast. (hires_ms::timeGetTime_ns): Remove. (hires_ns::prime): Remove. (hires_ms::nsecs): Drop call to prime. Call GetSystemTimeAsFileTime directly. Subtract FACTOR here since it's the only function needing to do so. (minperiod): Cosmetically change to ULONG. (hires_ns::resolution): Fix return type cast. (hires_ms::resolution): Simplify, rely on NtQueryTimerResolution. * winsup.h: Align time related prototypes to above changes.
2013-06-14 11:09:41 +02:00
timeval_to_filetime (const struct timeval *time_in, PLARGE_INTEGER out)
2000-02-17 20:38:33 +01:00
{
out->QuadPart = time_in->tv_sec * NS100PERSEC
+ time_in->tv_usec * (NS100PERSEC/USPERSEC) + FACTOR;
2000-02-17 20:38:33 +01:00
}
/* Cygwin internal */
bool
timeval_to_ms (const struct timeval *time_in, DWORD &ms)
{
if (time_in->tv_sec < 0 || time_in->tv_usec < 0
|| time_in->tv_usec >= USPERSEC)
return false;
if ((time_in->tv_sec == 0 && time_in->tv_usec == 0)
|| time_in->tv_sec >= (time_t) (INFINITE / MSPERSEC))
ms = INFINITE;
else
ms = time_in->tv_sec * MSPERSEC
+ (time_in->tv_usec + (USPERSEC / MSPERSEC) - 1)
/ (USPERSEC / MSPERSEC);
return true;
}
2000-02-17 20:38:33 +01:00
/* Cygwin internal */
static timeval __stdcall
time_t_to_timeval (time_t in)
{
timeval res;
res.tv_sec = in;
res.tv_usec = 0;
return res;
}
/* Cygwin internal */
static const struct timespec *
timeval_to_timespec (const struct timeval *tvp, struct timespec *tmp)
{
if (!tvp)
return NULL;
tmp[0].tv_sec = tvp[0].tv_sec;
tmp[0].tv_nsec = tvp[0].tv_usec * (NSPERSEC/USPERSEC);
if (tmp[0].tv_nsec < 0)
tmp[0].tv_nsec = 0;
else if (tmp[0].tv_nsec >= NSPERSEC)
tmp[0].tv_nsec = NSPERSEC - 1;
tmp[1].tv_sec = tvp[1].tv_sec;
tmp[1].tv_nsec = tvp[1].tv_usec * (NSPERSEC/USPERSEC);
if (tmp[1].tv_nsec < 0)
tmp[1].tv_nsec = 0;
else if (tmp[1].tv_nsec >= NSPERSEC)
tmp[1].tv_nsec = NSPERSEC - 1;
return tmp;
}
2000-02-17 20:38:33 +01:00
/* Cygwin internal */
/* Convert a Win32 time to "UNIX" format. */
Streamline time/times functionality. Remove last remains of former Windows 9x compatibility. * fhandler_disk_file.cc (fhandler_base::fstat_helper): Drop now unneeded casts in calls to_timestruc_t. (fhandler_base::utimens_fs): Ditto for timespec_to_filetime. * fhandler_proc.cc (format_proc_stat): Ditto for to_time_t. * hires.h (class hires_ms): Remove unused member initime_ns. Remove declarations for timeGetTime_ns and prime. (hires_ms::uptime): Remove. * posix_ipc.cc (ipc_cond_timedwait): Ditto for timespec_to_filetime. * fhandler_registry.cc (fhandler_registry::fstat): Add cast. * resource.cc (fill_rusage): Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. * times.cc: Simplify time handling. Throughout, use LARGE_INTEGER rather than FILETIME to simplify computations. Throughout use {u}int64_t rather than {unsigned} long long. Drop unneeded casts since NSPERSEC is 64 bit anyway. (systime_ns): Remove. (times): Call NtQuerySystemInformation to fetch boot time. Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. Call GetSystemTimeAsFileTime. (totimeval): Use constant 1000000 as in other functions. (time_t_to_filetime): Remove. (to_time_t): Change return type to time_t. (time_as_timestruc_t): Rename filetime to systime. (time): Ditto. Add cast. (hires_ns::nsecs): Fix return type cast. (hires_ms::timeGetTime_ns): Remove. (hires_ns::prime): Remove. (hires_ms::nsecs): Drop call to prime. Call GetSystemTimeAsFileTime directly. Subtract FACTOR here since it's the only function needing to do so. (minperiod): Cosmetically change to ULONG. (hires_ns::resolution): Fix return type cast. (hires_ms::resolution): Simplify, rely on NtQueryTimerResolution. * winsup.h: Align time related prototypes to above changes.
2013-06-14 11:09:41 +02:00
time_t __stdcall
to_time_t (PLARGE_INTEGER ptr)
2000-02-17 20:38:33 +01:00
{
/* A file time is the number of 100ns since jan 1 1601
stuffed into two long words.
A time_t is the number of seconds since jan 1 1970. */
Streamline time/times functionality. Remove last remains of former Windows 9x compatibility. * fhandler_disk_file.cc (fhandler_base::fstat_helper): Drop now unneeded casts in calls to_timestruc_t. (fhandler_base::utimens_fs): Ditto for timespec_to_filetime. * fhandler_proc.cc (format_proc_stat): Ditto for to_time_t. * hires.h (class hires_ms): Remove unused member initime_ns. Remove declarations for timeGetTime_ns and prime. (hires_ms::uptime): Remove. * posix_ipc.cc (ipc_cond_timedwait): Ditto for timespec_to_filetime. * fhandler_registry.cc (fhandler_registry::fstat): Add cast. * resource.cc (fill_rusage): Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. * times.cc: Simplify time handling. Throughout, use LARGE_INTEGER rather than FILETIME to simplify computations. Throughout use {u}int64_t rather than {unsigned} long long. Drop unneeded casts since NSPERSEC is 64 bit anyway. (systime_ns): Remove. (times): Call NtQuerySystemInformation to fetch boot time. Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. Call GetSystemTimeAsFileTime. (totimeval): Use constant 1000000 as in other functions. (time_t_to_filetime): Remove. (to_time_t): Change return type to time_t. (time_as_timestruc_t): Rename filetime to systime. (time): Ditto. Add cast. (hires_ns::nsecs): Fix return type cast. (hires_ms::timeGetTime_ns): Remove. (hires_ns::prime): Remove. (hires_ms::nsecs): Drop call to prime. Call GetSystemTimeAsFileTime directly. Subtract FACTOR here since it's the only function needing to do so. (minperiod): Cosmetically change to ULONG. (hires_ns::resolution): Fix return type cast. (hires_ms::resolution): Simplify, rely on NtQueryTimerResolution. * winsup.h: Align time related prototypes to above changes.
2013-06-14 11:09:41 +02:00
int64_t x = ptr->QuadPart;
/* pass "no time" as epoch */
if (x == 0)
return 0;
2000-02-17 20:38:33 +01:00
x -= FACTOR; /* number of 100ns between 1601 and 1970 */
x /= NS100PERSEC; /* number of 100ns in a second */
2000-02-17 20:38:33 +01:00
return x;
}
/* Cygwin internal */
/* Convert a Win32 time to "UNIX" timestruc_t format. */
void __stdcall
Streamline time/times functionality. Remove last remains of former Windows 9x compatibility. * fhandler_disk_file.cc (fhandler_base::fstat_helper): Drop now unneeded casts in calls to_timestruc_t. (fhandler_base::utimens_fs): Ditto for timespec_to_filetime. * fhandler_proc.cc (format_proc_stat): Ditto for to_time_t. * hires.h (class hires_ms): Remove unused member initime_ns. Remove declarations for timeGetTime_ns and prime. (hires_ms::uptime): Remove. * posix_ipc.cc (ipc_cond_timedwait): Ditto for timespec_to_filetime. * fhandler_registry.cc (fhandler_registry::fstat): Add cast. * resource.cc (fill_rusage): Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. * times.cc: Simplify time handling. Throughout, use LARGE_INTEGER rather than FILETIME to simplify computations. Throughout use {u}int64_t rather than {unsigned} long long. Drop unneeded casts since NSPERSEC is 64 bit anyway. (systime_ns): Remove. (times): Call NtQuerySystemInformation to fetch boot time. Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. Call GetSystemTimeAsFileTime. (totimeval): Use constant 1000000 as in other functions. (time_t_to_filetime): Remove. (to_time_t): Change return type to time_t. (time_as_timestruc_t): Rename filetime to systime. (time): Ditto. Add cast. (hires_ns::nsecs): Fix return type cast. (hires_ms::timeGetTime_ns): Remove. (hires_ns::prime): Remove. (hires_ms::nsecs): Drop call to prime. Call GetSystemTimeAsFileTime directly. Subtract FACTOR here since it's the only function needing to do so. (minperiod): Cosmetically change to ULONG. (hires_ns::resolution): Fix return type cast. (hires_ms::resolution): Simplify, rely on NtQueryTimerResolution. * winsup.h: Align time related prototypes to above changes.
2013-06-14 11:09:41 +02:00
to_timestruc_t (PLARGE_INTEGER ptr, timestruc_t *out)
{
/* A file time is the number of 100ns since jan 1 1601
stuffed into two long words.
A timestruc_t is the number of seconds and microseconds since jan 1 1970
stuffed into a time_t and a long. */
Streamline time/times functionality. Remove last remains of former Windows 9x compatibility. * fhandler_disk_file.cc (fhandler_base::fstat_helper): Drop now unneeded casts in calls to_timestruc_t. (fhandler_base::utimens_fs): Ditto for timespec_to_filetime. * fhandler_proc.cc (format_proc_stat): Ditto for to_time_t. * hires.h (class hires_ms): Remove unused member initime_ns. Remove declarations for timeGetTime_ns and prime. (hires_ms::uptime): Remove. * posix_ipc.cc (ipc_cond_timedwait): Ditto for timespec_to_filetime. * fhandler_registry.cc (fhandler_registry::fstat): Add cast. * resource.cc (fill_rusage): Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. * times.cc: Simplify time handling. Throughout, use LARGE_INTEGER rather than FILETIME to simplify computations. Throughout use {u}int64_t rather than {unsigned} long long. Drop unneeded casts since NSPERSEC is 64 bit anyway. (systime_ns): Remove. (times): Call NtQuerySystemInformation to fetch boot time. Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. Call GetSystemTimeAsFileTime. (totimeval): Use constant 1000000 as in other functions. (time_t_to_filetime): Remove. (to_time_t): Change return type to time_t. (time_as_timestruc_t): Rename filetime to systime. (time): Ditto. Add cast. (hires_ns::nsecs): Fix return type cast. (hires_ms::timeGetTime_ns): Remove. (hires_ns::prime): Remove. (hires_ms::nsecs): Drop call to prime. Call GetSystemTimeAsFileTime directly. Subtract FACTOR here since it's the only function needing to do so. (minperiod): Cosmetically change to ULONG. (hires_ns::resolution): Fix return type cast. (hires_ms::resolution): Simplify, rely on NtQueryTimerResolution. * winsup.h: Align time related prototypes to above changes.
2013-06-14 11:09:41 +02:00
int64_t x = ptr->QuadPart;
/* pass "no time" as epoch */
if (x == 0)
{
out->tv_sec = 0;
out->tv_nsec = 0;
return;
}
x -= FACTOR; /* number of 100ns between 1601 and 1970 */
out->tv_sec = x / NS100PERSEC;
out->tv_nsec = (x % NS100PERSEC) * (NSPERSEC/NS100PERSEC);
}
/* Cygwin internal */
/* Get the current time as a "UNIX" timestruc_t format. */
void __stdcall
time_as_timestruc_t (timestruc_t * out)
{
Streamline time/times functionality. Remove last remains of former Windows 9x compatibility. * fhandler_disk_file.cc (fhandler_base::fstat_helper): Drop now unneeded casts in calls to_timestruc_t. (fhandler_base::utimens_fs): Ditto for timespec_to_filetime. * fhandler_proc.cc (format_proc_stat): Ditto for to_time_t. * hires.h (class hires_ms): Remove unused member initime_ns. Remove declarations for timeGetTime_ns and prime. (hires_ms::uptime): Remove. * posix_ipc.cc (ipc_cond_timedwait): Ditto for timespec_to_filetime. * fhandler_registry.cc (fhandler_registry::fstat): Add cast. * resource.cc (fill_rusage): Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. * times.cc: Simplify time handling. Throughout, use LARGE_INTEGER rather than FILETIME to simplify computations. Throughout use {u}int64_t rather than {unsigned} long long. Drop unneeded casts since NSPERSEC is 64 bit anyway. (systime_ns): Remove. (times): Call NtQuerySystemInformation to fetch boot time. Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. Call GetSystemTimeAsFileTime. (totimeval): Use constant 1000000 as in other functions. (time_t_to_filetime): Remove. (to_time_t): Change return type to time_t. (time_as_timestruc_t): Rename filetime to systime. (time): Ditto. Add cast. (hires_ns::nsecs): Fix return type cast. (hires_ms::timeGetTime_ns): Remove. (hires_ns::prime): Remove. (hires_ms::nsecs): Drop call to prime. Call GetSystemTimeAsFileTime directly. Subtract FACTOR here since it's the only function needing to do so. (minperiod): Cosmetically change to ULONG. (hires_ns::resolution): Fix return type cast. (hires_ms::resolution): Simplify, rely on NtQueryTimerResolution. * winsup.h: Align time related prototypes to above changes.
2013-06-14 11:09:41 +02:00
LARGE_INTEGER systime;
get_system_time (&systime);
Streamline time/times functionality. Remove last remains of former Windows 9x compatibility. * fhandler_disk_file.cc (fhandler_base::fstat_helper): Drop now unneeded casts in calls to_timestruc_t. (fhandler_base::utimens_fs): Ditto for timespec_to_filetime. * fhandler_proc.cc (format_proc_stat): Ditto for to_time_t. * hires.h (class hires_ms): Remove unused member initime_ns. Remove declarations for timeGetTime_ns and prime. (hires_ms::uptime): Remove. * posix_ipc.cc (ipc_cond_timedwait): Ditto for timespec_to_filetime. * fhandler_registry.cc (fhandler_registry::fstat): Add cast. * resource.cc (fill_rusage): Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. * times.cc: Simplify time handling. Throughout, use LARGE_INTEGER rather than FILETIME to simplify computations. Throughout use {u}int64_t rather than {unsigned} long long. Drop unneeded casts since NSPERSEC is 64 bit anyway. (systime_ns): Remove. (times): Call NtQuerySystemInformation to fetch boot time. Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. Call GetSystemTimeAsFileTime. (totimeval): Use constant 1000000 as in other functions. (time_t_to_filetime): Remove. (to_time_t): Change return type to time_t. (time_as_timestruc_t): Rename filetime to systime. (time): Ditto. Add cast. (hires_ns::nsecs): Fix return type cast. (hires_ms::timeGetTime_ns): Remove. (hires_ns::prime): Remove. (hires_ms::nsecs): Drop call to prime. Call GetSystemTimeAsFileTime directly. Subtract FACTOR here since it's the only function needing to do so. (minperiod): Cosmetically change to ULONG. (hires_ns::resolution): Fix return type cast. (hires_ms::resolution): Simplify, rely on NtQueryTimerResolution. * winsup.h: Align time related prototypes to above changes.
2013-06-14 11:09:41 +02:00
to_timestruc_t (&systime, out);
}
2000-02-17 20:38:33 +01:00
/* time: POSIX 4.5.1.1, C 4.12.2.4 */
/* Return number of seconds since 00:00 UTC on jan 1, 1970 */
extern "C" time_t
2000-02-17 20:38:33 +01:00
time (time_t * ptr)
{
time_t res;
Streamline time/times functionality. Remove last remains of former Windows 9x compatibility. * fhandler_disk_file.cc (fhandler_base::fstat_helper): Drop now unneeded casts in calls to_timestruc_t. (fhandler_base::utimens_fs): Ditto for timespec_to_filetime. * fhandler_proc.cc (format_proc_stat): Ditto for to_time_t. * hires.h (class hires_ms): Remove unused member initime_ns. Remove declarations for timeGetTime_ns and prime. (hires_ms::uptime): Remove. * posix_ipc.cc (ipc_cond_timedwait): Ditto for timespec_to_filetime. * fhandler_registry.cc (fhandler_registry::fstat): Add cast. * resource.cc (fill_rusage): Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. * times.cc: Simplify time handling. Throughout, use LARGE_INTEGER rather than FILETIME to simplify computations. Throughout use {u}int64_t rather than {unsigned} long long. Drop unneeded casts since NSPERSEC is 64 bit anyway. (systime_ns): Remove. (times): Call NtQuerySystemInformation to fetch boot time. Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. Call GetSystemTimeAsFileTime. (totimeval): Use constant 1000000 as in other functions. (time_t_to_filetime): Remove. (to_time_t): Change return type to time_t. (time_as_timestruc_t): Rename filetime to systime. (time): Ditto. Add cast. (hires_ns::nsecs): Fix return type cast. (hires_ms::timeGetTime_ns): Remove. (hires_ns::prime): Remove. (hires_ms::nsecs): Drop call to prime. Call GetSystemTimeAsFileTime directly. Subtract FACTOR here since it's the only function needing to do so. (minperiod): Cosmetically change to ULONG. (hires_ns::resolution): Fix return type cast. (hires_ms::resolution): Simplify, rely on NtQueryTimerResolution. * winsup.h: Align time related prototypes to above changes.
2013-06-14 11:09:41 +02:00
LARGE_INTEGER systime;
2000-02-17 20:38:33 +01:00
get_system_time (&systime);
Streamline time/times functionality. Remove last remains of former Windows 9x compatibility. * fhandler_disk_file.cc (fhandler_base::fstat_helper): Drop now unneeded casts in calls to_timestruc_t. (fhandler_base::utimens_fs): Ditto for timespec_to_filetime. * fhandler_proc.cc (format_proc_stat): Ditto for to_time_t. * hires.h (class hires_ms): Remove unused member initime_ns. Remove declarations for timeGetTime_ns and prime. (hires_ms::uptime): Remove. * posix_ipc.cc (ipc_cond_timedwait): Ditto for timespec_to_filetime. * fhandler_registry.cc (fhandler_registry::fstat): Add cast. * resource.cc (fill_rusage): Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. * times.cc: Simplify time handling. Throughout, use LARGE_INTEGER rather than FILETIME to simplify computations. Throughout use {u}int64_t rather than {unsigned} long long. Drop unneeded casts since NSPERSEC is 64 bit anyway. (systime_ns): Remove. (times): Call NtQuerySystemInformation to fetch boot time. Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. Call GetSystemTimeAsFileTime. (totimeval): Use constant 1000000 as in other functions. (time_t_to_filetime): Remove. (to_time_t): Change return type to time_t. (time_as_timestruc_t): Rename filetime to systime. (time): Ditto. Add cast. (hires_ns::nsecs): Fix return type cast. (hires_ms::timeGetTime_ns): Remove. (hires_ns::prime): Remove. (hires_ms::nsecs): Drop call to prime. Call GetSystemTimeAsFileTime directly. Subtract FACTOR here since it's the only function needing to do so. (minperiod): Cosmetically change to ULONG. (hires_ns::resolution): Fix return type cast. (hires_ms::resolution): Simplify, rely on NtQueryTimerResolution. * winsup.h: Align time related prototypes to above changes.
2013-06-14 11:09:41 +02:00
res = to_time_t (&systime);
2000-02-17 20:38:33 +01:00
if (ptr)
*ptr = res;
2013-04-23 11:44:36 +02:00
syscall_printf ("%d = time(%p)", res, ptr);
2000-02-17 20:38:33 +01:00
return res;
}
int
utimens_worker (path_conv &win32, const struct timespec *tvp)
2000-02-17 20:38:33 +01:00
{
int res = -1;
if (win32.error)
set_errno (win32.error);
else
2000-02-17 20:38:33 +01:00
{
fhandler_base *fh = NULL;
bool fromfd = false;
cygheap_fdenum cfd (true);
while (cfd.next () >= 0)
if (cfd->get_access () & (FILE_WRITE_ATTRIBUTES | GENERIC_WRITE)
&& RtlEqualUnicodeString (cfd->pc.get_nt_native_path (),
win32.get_nt_native_path (),
Add case-sensitivity. Unconditionally handle mount points case-sensitive. Unconditionally handle virtual paths case-sensitive. Unconditionally handle registry paths case-insensitive. Otherwise, accommodate case-sensitivity of given path throughout. * cygheap.cc (cygheap_root::set): Get additional caseinsensitive parameter and store it. * cygheap.h (struct cygheap_root_mount_info): Add member caseinsensitive. * dlfcn.cc (get_full_path_of_dll): Drop PC_NOFULL parameter from call to path_conv::check. * environ.cc (pcheck_case): Remove. (check_case_init): Remove. (known): Drop "check_case" option. * exceptions.cc (open_stackdumpfile): Add comment. * fhandler.cc (fhandler_base::get_default_fmode): Call pathmatch instead of strcasematch. * fhandler_disk_file.cc: Accommodate case-sensitivity of given path throughout. (__DIR_mounts::check_mount): Unconditionally check virtual paths case-sensitive. (fhandler_disk_file::link): Drop case clash handling. (fhandler_disk_file::open): Ditto. (fhandler_disk_file::readdir_helper): Drop managed mount code. * mount.cc: Remove managed mount code and datastructures. (struct opt): Remove "managed" option. Add "posix=0" and "posix=1" options. (fillout_mntent): Remove "managed" output. Add "posix" output. * path.cc (struct symlink_info): Remove case_clash member and case_check method. (pcheck_case): Remove. (path_prefix_p): Take additional bool parameter "caseinsensitive". (pathnmatch): Ditto. (pathmatch): Ditto. (mkrelpath): Ditto. (fs_info::update): Set caseinsensitive flag according to file system name and FILE_CASE_SENSITIVE_SEARCH flag. Add comment. (tfx_chars_managed): Remove. (transform_chars): Drop "managed" parameter. Always use tfx_chars. (get_nt_native_path): Drop "managed" parameter. Make sure drive letters are always upper case. (getfileattr): Change second parameter to denote caseinsensitivity. (path_conv::check): Initialize caseinsensitive to OBJ_CASE_INSENSITIVE. Set caseinsensitive according to global obcaseinsensitive flag, file system case sensitivity and MOUNT_NOPOSIX mount flag. Drop case_clash and all the related code. (symlink_worker): Drop case clash handling. (symlink_info::set): Drop setting case_clash. (symlink_info::case_check): Remove. (cwdstuff::set): Add comment. (etc::init): Take path_conv instead of PUNICODE_STRING as parameter to allow case sensitivity. * path.h (enum pathconv_arg): Drop PC_SYM_IGNORE. (enum case_checking): Remove. (enum path_types): Drop PATH_ENC, add PATH_NOPOSIX flag. (struct fs_info): Add caseinsensitive flag and accessor methods. (class path_conv): Add caseinsensitive member and define objcaseinsensitive method. Drop case_clash member and isencoded method. (pathmatch): Change prototype according to above change. (pathnmatch): Ditto. (path_prefix_p): Ditto. (get_nt_native_path): Ditto. (class etc): Ditto. (fnunmunge): Remove prototype. * shared.cc (shared_info::init_obcaseinsensitive): Initialize obcaseinsensitive flag from obcaseinsensitive registry value. (shared_info::initialize): Call init_obcaseinsensitive here by the first process creating the shared memory. * shared_info.h (mount_item::fnmunge): Remove. (shared_info::obcaseinsensitive): Rename from obcaseinsensitivity. (shared_info::init_obcaseinsensitive): Declare. * syscalls.cc (try_to_bin): Add comment. * include/sys/mount.h (MOUNT_ENC): Remove flag. (MOUNT_NOPOSIX): Add flag.
2008-07-16 22:20:45 +02:00
cfd->pc.objcaseinsensitive ()))
{
fh = cfd;
fromfd = true;
break;
}
if (!fh)
{
if (!(fh = build_fh_pc (win32)))
goto error;
if (fh->error ())
{
debug_printf ("got %d error from build_fh_pc", fh->error ());
set_errno (fh->error ());
}
}
res = fh->utimens (tvp);
if (!fromfd)
delete fh;
}
2000-02-17 20:38:33 +01:00
error:
syscall_printf ("%R = utimes(%S, %p)", res, win32.get_nt_native_path (), tvp);
2000-02-17 20:38:33 +01:00
return res;
}
/* utimes: POSIX/SUSv3 */
extern "C" int
utimes (const char *path, const struct timeval *tvp)
{
path_conv win32 (path, PC_POSIX | PC_SYM_FOLLOW, stat_suffixes);
struct timespec tmp[2];
return utimens_worker (win32, timeval_to_timespec (tvp, tmp));
}
/* BSD */
extern "C" int
lutimes (const char *path, const struct timeval *tvp)
{
path_conv win32 (path, PC_POSIX | PC_SYM_NOFOLLOW, stat_suffixes);
struct timespec tmp[2];
return utimens_worker (win32, timeval_to_timespec (tvp, tmp));
}
/* futimens: POSIX/SUSv4 */
extern "C" int
futimens (int fd, const struct timespec *tvp)
{
int res;
cygheap_fdget cfd (fd);
if (cfd < 0)
res = -1;
else if (cfd->get_access () & (FILE_WRITE_ATTRIBUTES | GENERIC_WRITE))
res = cfd->utimens (tvp);
else
res = utimens_worker (cfd->pc, tvp);
syscall_printf ("%d = futimens(%d, %p)", res, fd, tvp);
return res;
}
/* BSD */
extern "C" int
futimes (int fd, const struct timeval *tvp)
{
struct timespec tmp[2];
return futimens (fd, timeval_to_timespec (tvp, tmp));
}
2000-02-17 20:38:33 +01:00
/* utime: POSIX 5.6.6.1 */
extern "C" int
utime (const char *path, const struct utimbuf *buf)
2000-02-17 20:38:33 +01:00
{
struct timeval tmp[2];
if (buf == 0)
return utimes (path, 0);
2013-04-23 11:44:36 +02:00
debug_printf ("incoming utime act %lx", buf->actime);
2000-02-17 20:38:33 +01:00
tmp[0] = time_t_to_timeval (buf->actime);
tmp[1] = time_t_to_timeval (buf->modtime);
return utimes (path, tmp);
}
/* ftime: standards? */
extern "C" int
2000-02-17 20:38:33 +01:00
ftime (struct timeb *tp)
{
struct timeval tv;
struct timezone tz;
if (gettimeofday (&tv, &tz) < 0)
return -1;
tp->time = tv.tv_sec;
tp->millitm = tv.tv_usec / 1000;
tp->timezone = tz.tz_minuteswest;
tp->dstflag = tz.tz_dsttime;
return 0;
}
#define stupid_printf if (cygwin_finished_initializing) debug_printf
void
hires_ns::prime ()
{
LARGE_INTEGER ifreq;
if (!QueryPerformanceFrequency (&ifreq))
{
inited = -1;
return;
}
int priority = GetThreadPriority (GetCurrentThread ());
SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_TIME_CRITICAL);
if (!QueryPerformanceCounter (&primed_pc))
{
SetThreadPriority (GetCurrentThread (), priority);
inited = -1;
return;
}
freq = (double) ((double) NSPERSEC / (double) ifreq.QuadPart);
inited = true;
SetThreadPriority (GetCurrentThread (), priority);
}
LONGLONG
hires_ns::nsecs (bool monotonic)
{
if (!inited)
prime ();
if (inited < 0)
{
set_errno (ENOSYS);
Streamline time/times functionality. Remove last remains of former Windows 9x compatibility. * fhandler_disk_file.cc (fhandler_base::fstat_helper): Drop now unneeded casts in calls to_timestruc_t. (fhandler_base::utimens_fs): Ditto for timespec_to_filetime. * fhandler_proc.cc (format_proc_stat): Ditto for to_time_t. * hires.h (class hires_ms): Remove unused member initime_ns. Remove declarations for timeGetTime_ns and prime. (hires_ms::uptime): Remove. * posix_ipc.cc (ipc_cond_timedwait): Ditto for timespec_to_filetime. * fhandler_registry.cc (fhandler_registry::fstat): Add cast. * resource.cc (fill_rusage): Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. * times.cc: Simplify time handling. Throughout, use LARGE_INTEGER rather than FILETIME to simplify computations. Throughout use {u}int64_t rather than {unsigned} long long. Drop unneeded casts since NSPERSEC is 64 bit anyway. (systime_ns): Remove. (times): Call NtQuerySystemInformation to fetch boot time. Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. Call GetSystemTimeAsFileTime. (totimeval): Use constant 1000000 as in other functions. (time_t_to_filetime): Remove. (to_time_t): Change return type to time_t. (time_as_timestruc_t): Rename filetime to systime. (time): Ditto. Add cast. (hires_ns::nsecs): Fix return type cast. (hires_ms::timeGetTime_ns): Remove. (hires_ns::prime): Remove. (hires_ms::nsecs): Drop call to prime. Call GetSystemTimeAsFileTime directly. Subtract FACTOR here since it's the only function needing to do so. (minperiod): Cosmetically change to ULONG. (hires_ns::resolution): Fix return type cast. (hires_ms::resolution): Simplify, rely on NtQueryTimerResolution. * winsup.h: Align time related prototypes to above changes.
2013-06-14 11:09:41 +02:00
return (LONGLONG) -1;
}
LARGE_INTEGER now;
if (!QueryPerformanceCounter (&now))
{
set_errno (ENOSYS);
return -1;
}
// FIXME: Use round() here?
now.QuadPart = (LONGLONG) (freq * (double)
2013-04-23 11:44:36 +02:00
(now.QuadPart - (monotonic ? 0LL : primed_pc.QuadPart)));
return now.QuadPart;
}
LONGLONG
hires_ms::nsecs ()
{
Streamline time/times functionality. Remove last remains of former Windows 9x compatibility. * fhandler_disk_file.cc (fhandler_base::fstat_helper): Drop now unneeded casts in calls to_timestruc_t. (fhandler_base::utimens_fs): Ditto for timespec_to_filetime. * fhandler_proc.cc (format_proc_stat): Ditto for to_time_t. * hires.h (class hires_ms): Remove unused member initime_ns. Remove declarations for timeGetTime_ns and prime. (hires_ms::uptime): Remove. * posix_ipc.cc (ipc_cond_timedwait): Ditto for timespec_to_filetime. * fhandler_registry.cc (fhandler_registry::fstat): Add cast. * resource.cc (fill_rusage): Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. * times.cc: Simplify time handling. Throughout, use LARGE_INTEGER rather than FILETIME to simplify computations. Throughout use {u}int64_t rather than {unsigned} long long. Drop unneeded casts since NSPERSEC is 64 bit anyway. (systime_ns): Remove. (times): Call NtQuerySystemInformation to fetch boot time. Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. Call GetSystemTimeAsFileTime. (totimeval): Use constant 1000000 as in other functions. (time_t_to_filetime): Remove. (to_time_t): Change return type to time_t. (time_as_timestruc_t): Rename filetime to systime. (time): Ditto. Add cast. (hires_ns::nsecs): Fix return type cast. (hires_ms::timeGetTime_ns): Remove. (hires_ns::prime): Remove. (hires_ms::nsecs): Drop call to prime. Call GetSystemTimeAsFileTime directly. Subtract FACTOR here since it's the only function needing to do so. (minperiod): Cosmetically change to ULONG. (hires_ns::resolution): Fix return type cast. (hires_ms::resolution): Simplify, rely on NtQueryTimerResolution. * winsup.h: Align time related prototypes to above changes.
2013-06-14 11:09:41 +02:00
LARGE_INTEGER systime;
get_system_time (&systime);
Streamline time/times functionality. Remove last remains of former Windows 9x compatibility. * fhandler_disk_file.cc (fhandler_base::fstat_helper): Drop now unneeded casts in calls to_timestruc_t. (fhandler_base::utimens_fs): Ditto for timespec_to_filetime. * fhandler_proc.cc (format_proc_stat): Ditto for to_time_t. * hires.h (class hires_ms): Remove unused member initime_ns. Remove declarations for timeGetTime_ns and prime. (hires_ms::uptime): Remove. * posix_ipc.cc (ipc_cond_timedwait): Ditto for timespec_to_filetime. * fhandler_registry.cc (fhandler_registry::fstat): Add cast. * resource.cc (fill_rusage): Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. * times.cc: Simplify time handling. Throughout, use LARGE_INTEGER rather than FILETIME to simplify computations. Throughout use {u}int64_t rather than {unsigned} long long. Drop unneeded casts since NSPERSEC is 64 bit anyway. (systime_ns): Remove. (times): Call NtQuerySystemInformation to fetch boot time. Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. Call GetSystemTimeAsFileTime. (totimeval): Use constant 1000000 as in other functions. (time_t_to_filetime): Remove. (to_time_t): Change return type to time_t. (time_as_timestruc_t): Rename filetime to systime. (time): Ditto. Add cast. (hires_ns::nsecs): Fix return type cast. (hires_ms::timeGetTime_ns): Remove. (hires_ns::prime): Remove. (hires_ms::nsecs): Drop call to prime. Call GetSystemTimeAsFileTime directly. Subtract FACTOR here since it's the only function needing to do so. (minperiod): Cosmetically change to ULONG. (hires_ns::resolution): Fix return type cast. (hires_ms::resolution): Simplify, rely on NtQueryTimerResolution. * winsup.h: Align time related prototypes to above changes.
2013-06-14 11:09:41 +02:00
/* Add conversion factor for UNIX vs. Windows base time */
return systime.QuadPart - FACTOR;
}
* cygwin/include/signal.h: Add copyright notice. * cygwin.din: Make clock SIGFE. Add clock_gettime, sigwaitinfo, timer_create, timer_delete, timer_settime. * include/cygwin/version.h: Reflect above additions. * fork.cc (fork_child): Call fixup_timers_after_fork. * signal.cc (sigwait): Remove unused variable. * timer.cc: New file. (clock_gettime): Define new function. (timer_tracker): Define new struct used by timer functions. (timer_tracker::timer_tracker): New function. (to_us): New function. (timer_thread): New function. (timer_tracker::settime): New function. (timer_create): New function. (timer_settime): New function. (timer_delete): New function. (fixup_timers_after_fork): New function. * cygthread.cc: Bump thread count. * signal.cc (sigwaitinfo): Define new function. (sigwait): Redefine based on sigwaitinfo. * include/cygwin/signal.h (sigwaitinfo): Declare. (sigwait): Ditto. * dtable.cc (dtable::vfork_parent_restore): Avoid double close of ctty when ctty == ctty_on_hold. * cygtls.h (_threadinfo::threadkill): New element. (_threadinfo::set_threadkill): Declare new function. (_threadinfo::reset_threadkill): Declare new function. * dcrt0.cc (dcrt0_1): Call here so that it will be possible to attach to running process with #(*& Windows Me/9x. (initial_env): Try to initialize strace if uninitialized. * gendef: Don't zero signal if threadkill is set since that will happen in the called function. * signal.cc (sigwait): Ensure cleanup in error conditions. * sigproc.cc (sig_send): Clear packet mask storage. (wait_subproc): Fill in child exit code in siginfo_t structure. * thread.cc (pthread_kill): Set threadkill flag. * tlsoffsets.h: Regenerate. Throughout, use siginfo_t to fill out all signal information for "kernel" signals. * cygtls.h (_threadinfo::set_siginfo): Declare new function. * cygtls.cc (_threadinfo::set_siginfo): Define new function. * dcrt0.cc (do_exit): Accommodate siginfo_t considerations. * exceptions.cc (handle_exceptions): Ditto. (sig_handle_tty_stop): Ditto. (ctrl_c_handler): Use killsys() to send signal. (sigpacket::process): Rename from sig_handle. Use siginfo_t field from sigpacket for everything. (tty_min::kill_pgrp): Accommodate siginfo_t considerations. (fhandler_termios::bg_check): Ditto. * fhandler_tty.cc (fhandler_tty_slave::ioctl): Use killsys() to send signal. * signal.cc (kill_worker): Rewrite to use siginfo_t second argument. (kill_pgrp): Ditto. (kill0): Define new function pulled from kill(). (kill): Rewrite as frontend to kill0. (killsys): Define new function. * sigproc.cc (sigelem): Eliminate. (sigpacket): Move to sigproc.h. Subsume sigelem. (pending_signals): Use sigpacket rather than sigelem for everything. (sig_clear): Ditto. (wait_sig): Ditto. (sig_send): Rewrite to use siginfo_t argument. (sig_send): New function wratpper to sig_send with siginfo_t argument. (wait_subproc): Accommodate siginfo_t considerations. * thread.cc (pthread_kill): Ditto. * sigproc.h (sigpacket): Move here. (sigpacket::process): Declare "new" function. (sig_handle): Eliminate declaration. (sig_send): Declare with new paramaters. (killsys): Declare new function. (kill_pgrp): Declare. * winsup.h: Move some signal-specific stuff to sigproc.h. * include/cygwin/signal.h: Tweak some siginfo_t stuff.
2004-01-19 06:46:54 +01:00
extern "C" int
clock_gettime (clockid_t clk_id, struct timespec *tp)
{
if (CLOCKID_IS_PROCESS (clk_id))
{
pid_t pid = CLOCKID_TO_PID (clk_id);
HANDLE hProcess;
KERNEL_USER_TIMES kut;
Streamline time/times functionality. Remove last remains of former Windows 9x compatibility. * fhandler_disk_file.cc (fhandler_base::fstat_helper): Drop now unneeded casts in calls to_timestruc_t. (fhandler_base::utimens_fs): Ditto for timespec_to_filetime. * fhandler_proc.cc (format_proc_stat): Ditto for to_time_t. * hires.h (class hires_ms): Remove unused member initime_ns. Remove declarations for timeGetTime_ns and prime. (hires_ms::uptime): Remove. * posix_ipc.cc (ipc_cond_timedwait): Ditto for timespec_to_filetime. * fhandler_registry.cc (fhandler_registry::fstat): Add cast. * resource.cc (fill_rusage): Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. * times.cc: Simplify time handling. Throughout, use LARGE_INTEGER rather than FILETIME to simplify computations. Throughout use {u}int64_t rather than {unsigned} long long. Drop unneeded casts since NSPERSEC is 64 bit anyway. (systime_ns): Remove. (times): Call NtQuerySystemInformation to fetch boot time. Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. Call GetSystemTimeAsFileTime. (totimeval): Use constant 1000000 as in other functions. (time_t_to_filetime): Remove. (to_time_t): Change return type to time_t. (time_as_timestruc_t): Rename filetime to systime. (time): Ditto. Add cast. (hires_ns::nsecs): Fix return type cast. (hires_ms::timeGetTime_ns): Remove. (hires_ns::prime): Remove. (hires_ms::nsecs): Drop call to prime. Call GetSystemTimeAsFileTime directly. Subtract FACTOR here since it's the only function needing to do so. (minperiod): Cosmetically change to ULONG. (hires_ns::resolution): Fix return type cast. (hires_ms::resolution): Simplify, rely on NtQueryTimerResolution. * winsup.h: Align time related prototypes to above changes.
2013-06-14 11:09:41 +02:00
int64_t x;
if (pid == 0)
2011-06-06 07:02:13 +02:00
pid = getpid ();
pinfo p (pid);
if (!p || !p->exists ())
2011-06-06 07:02:13 +02:00
{
set_errno (EINVAL);
return -1;
}
hProcess = OpenProcess (PROCESS_QUERY_LIMITED_INFORMATION, 0,
p->dwProcessId);
Streamline time/times functionality. Remove last remains of former Windows 9x compatibility. * fhandler_disk_file.cc (fhandler_base::fstat_helper): Drop now unneeded casts in calls to_timestruc_t. (fhandler_base::utimens_fs): Ditto for timespec_to_filetime. * fhandler_proc.cc (format_proc_stat): Ditto for to_time_t. * hires.h (class hires_ms): Remove unused member initime_ns. Remove declarations for timeGetTime_ns and prime. (hires_ms::uptime): Remove. * posix_ipc.cc (ipc_cond_timedwait): Ditto for timespec_to_filetime. * fhandler_registry.cc (fhandler_registry::fstat): Add cast. * resource.cc (fill_rusage): Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. * times.cc: Simplify time handling. Throughout, use LARGE_INTEGER rather than FILETIME to simplify computations. Throughout use {u}int64_t rather than {unsigned} long long. Drop unneeded casts since NSPERSEC is 64 bit anyway. (systime_ns): Remove. (times): Call NtQuerySystemInformation to fetch boot time. Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. Call GetSystemTimeAsFileTime. (totimeval): Use constant 1000000 as in other functions. (time_t_to_filetime): Remove. (to_time_t): Change return type to time_t. (time_as_timestruc_t): Rename filetime to systime. (time): Ditto. Add cast. (hires_ns::nsecs): Fix return type cast. (hires_ms::timeGetTime_ns): Remove. (hires_ns::prime): Remove. (hires_ms::nsecs): Drop call to prime. Call GetSystemTimeAsFileTime directly. Subtract FACTOR here since it's the only function needing to do so. (minperiod): Cosmetically change to ULONG. (hires_ns::resolution): Fix return type cast. (hires_ms::resolution): Simplify, rely on NtQueryTimerResolution. * winsup.h: Align time related prototypes to above changes.
2013-06-14 11:09:41 +02:00
NtQueryInformationProcess (hProcess, ProcessTimes,
&kut, sizeof kut, NULL);
x = kut.KernelTime.QuadPart + kut.UserTime.QuadPart;
tp->tv_sec = x / NS100PERSEC;
tp->tv_nsec = (x % NS100PERSEC) * (NSPERSEC/NS100PERSEC);
CloseHandle (hProcess);
return 0;
}
if (CLOCKID_IS_THREAD (clk_id))
{
long thr_id = CLOCKID_TO_THREADID (clk_id);
HANDLE hThread;
KERNEL_USER_TIMES kut;
Streamline time/times functionality. Remove last remains of former Windows 9x compatibility. * fhandler_disk_file.cc (fhandler_base::fstat_helper): Drop now unneeded casts in calls to_timestruc_t. (fhandler_base::utimens_fs): Ditto for timespec_to_filetime. * fhandler_proc.cc (format_proc_stat): Ditto for to_time_t. * hires.h (class hires_ms): Remove unused member initime_ns. Remove declarations for timeGetTime_ns and prime. (hires_ms::uptime): Remove. * posix_ipc.cc (ipc_cond_timedwait): Ditto for timespec_to_filetime. * fhandler_registry.cc (fhandler_registry::fstat): Add cast. * resource.cc (fill_rusage): Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. * times.cc: Simplify time handling. Throughout, use LARGE_INTEGER rather than FILETIME to simplify computations. Throughout use {u}int64_t rather than {unsigned} long long. Drop unneeded casts since NSPERSEC is 64 bit anyway. (systime_ns): Remove. (times): Call NtQuerySystemInformation to fetch boot time. Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. Call GetSystemTimeAsFileTime. (totimeval): Use constant 1000000 as in other functions. (time_t_to_filetime): Remove. (to_time_t): Change return type to time_t. (time_as_timestruc_t): Rename filetime to systime. (time): Ditto. Add cast. (hires_ns::nsecs): Fix return type cast. (hires_ms::timeGetTime_ns): Remove. (hires_ns::prime): Remove. (hires_ms::nsecs): Drop call to prime. Call GetSystemTimeAsFileTime directly. Subtract FACTOR here since it's the only function needing to do so. (minperiod): Cosmetically change to ULONG. (hires_ns::resolution): Fix return type cast. (hires_ms::resolution): Simplify, rely on NtQueryTimerResolution. * winsup.h: Align time related prototypes to above changes.
2013-06-14 11:09:41 +02:00
int64_t x;
if (thr_id == 0)
2011-06-06 07:02:13 +02:00
thr_id = pthread::self ()->getsequence_np ();
hThread = OpenThread (THREAD_QUERY_LIMITED_INFORMATION, 0, thr_id);
if (!hThread)
2011-06-06 07:02:13 +02:00
{
set_errno (EINVAL);
return -1;
}
Streamline time/times functionality. Remove last remains of former Windows 9x compatibility. * fhandler_disk_file.cc (fhandler_base::fstat_helper): Drop now unneeded casts in calls to_timestruc_t. (fhandler_base::utimens_fs): Ditto for timespec_to_filetime. * fhandler_proc.cc (format_proc_stat): Ditto for to_time_t. * hires.h (class hires_ms): Remove unused member initime_ns. Remove declarations for timeGetTime_ns and prime. (hires_ms::uptime): Remove. * posix_ipc.cc (ipc_cond_timedwait): Ditto for timespec_to_filetime. * fhandler_registry.cc (fhandler_registry::fstat): Add cast. * resource.cc (fill_rusage): Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. * times.cc: Simplify time handling. Throughout, use LARGE_INTEGER rather than FILETIME to simplify computations. Throughout use {u}int64_t rather than {unsigned} long long. Drop unneeded casts since NSPERSEC is 64 bit anyway. (systime_ns): Remove. (times): Call NtQuerySystemInformation to fetch boot time. Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. Call GetSystemTimeAsFileTime. (totimeval): Use constant 1000000 as in other functions. (time_t_to_filetime): Remove. (to_time_t): Change return type to time_t. (time_as_timestruc_t): Rename filetime to systime. (time): Ditto. Add cast. (hires_ns::nsecs): Fix return type cast. (hires_ms::timeGetTime_ns): Remove. (hires_ns::prime): Remove. (hires_ms::nsecs): Drop call to prime. Call GetSystemTimeAsFileTime directly. Subtract FACTOR here since it's the only function needing to do so. (minperiod): Cosmetically change to ULONG. (hires_ns::resolution): Fix return type cast. (hires_ms::resolution): Simplify, rely on NtQueryTimerResolution. * winsup.h: Align time related prototypes to above changes.
2013-06-14 11:09:41 +02:00
NtQueryInformationThread (hThread, ThreadTimes,
&kut, sizeof kut, NULL);
x = kut.KernelTime.QuadPart + kut.UserTime.QuadPart;
tp->tv_sec = x / NS100PERSEC;
tp->tv_nsec = (x % NS100PERSEC) * (NSPERSEC/NS100PERSEC);
CloseHandle (hThread);
return 0;
}
switch (clk_id)
* cygwin/include/signal.h: Add copyright notice. * cygwin.din: Make clock SIGFE. Add clock_gettime, sigwaitinfo, timer_create, timer_delete, timer_settime. * include/cygwin/version.h: Reflect above additions. * fork.cc (fork_child): Call fixup_timers_after_fork. * signal.cc (sigwait): Remove unused variable. * timer.cc: New file. (clock_gettime): Define new function. (timer_tracker): Define new struct used by timer functions. (timer_tracker::timer_tracker): New function. (to_us): New function. (timer_thread): New function. (timer_tracker::settime): New function. (timer_create): New function. (timer_settime): New function. (timer_delete): New function. (fixup_timers_after_fork): New function. * cygthread.cc: Bump thread count. * signal.cc (sigwaitinfo): Define new function. (sigwait): Redefine based on sigwaitinfo. * include/cygwin/signal.h (sigwaitinfo): Declare. (sigwait): Ditto. * dtable.cc (dtable::vfork_parent_restore): Avoid double close of ctty when ctty == ctty_on_hold. * cygtls.h (_threadinfo::threadkill): New element. (_threadinfo::set_threadkill): Declare new function. (_threadinfo::reset_threadkill): Declare new function. * dcrt0.cc (dcrt0_1): Call here so that it will be possible to attach to running process with #(*& Windows Me/9x. (initial_env): Try to initialize strace if uninitialized. * gendef: Don't zero signal if threadkill is set since that will happen in the called function. * signal.cc (sigwait): Ensure cleanup in error conditions. * sigproc.cc (sig_send): Clear packet mask storage. (wait_subproc): Fill in child exit code in siginfo_t structure. * thread.cc (pthread_kill): Set threadkill flag. * tlsoffsets.h: Regenerate. Throughout, use siginfo_t to fill out all signal information for "kernel" signals. * cygtls.h (_threadinfo::set_siginfo): Declare new function. * cygtls.cc (_threadinfo::set_siginfo): Define new function. * dcrt0.cc (do_exit): Accommodate siginfo_t considerations. * exceptions.cc (handle_exceptions): Ditto. (sig_handle_tty_stop): Ditto. (ctrl_c_handler): Use killsys() to send signal. (sigpacket::process): Rename from sig_handle. Use siginfo_t field from sigpacket for everything. (tty_min::kill_pgrp): Accommodate siginfo_t considerations. (fhandler_termios::bg_check): Ditto. * fhandler_tty.cc (fhandler_tty_slave::ioctl): Use killsys() to send signal. * signal.cc (kill_worker): Rewrite to use siginfo_t second argument. (kill_pgrp): Ditto. (kill0): Define new function pulled from kill(). (kill): Rewrite as frontend to kill0. (killsys): Define new function. * sigproc.cc (sigelem): Eliminate. (sigpacket): Move to sigproc.h. Subsume sigelem. (pending_signals): Use sigpacket rather than sigelem for everything. (sig_clear): Ditto. (wait_sig): Ditto. (sig_send): Rewrite to use siginfo_t argument. (sig_send): New function wratpper to sig_send with siginfo_t argument. (wait_subproc): Accommodate siginfo_t considerations. * thread.cc (pthread_kill): Ditto. * sigproc.h (sigpacket): Move here. (sigpacket::process): Declare "new" function. (sig_handle): Eliminate declaration. (sig_send): Declare with new paramaters. (killsys): Declare new function. (kill_pgrp): Declare. * winsup.h: Move some signal-specific stuff to sigproc.h. * include/cygwin/signal.h: Tweak some siginfo_t stuff.
2004-01-19 06:46:54 +01:00
{
case CLOCK_REALTIME:
2011-06-06 07:02:13 +02:00
{
LONGLONG now = gtod.nsecs ();
if (now == (LONGLONG) -1)
return -1;
tp->tv_sec = now / NS100PERSEC;
tp->tv_nsec = (now % NS100PERSEC) * (NSPERSEC / NS100PERSEC);
2011-06-06 07:02:13 +02:00
break;
}
case CLOCK_MONOTONIC:
2011-06-06 07:02:13 +02:00
{
LONGLONG now = ntod.nsecs (true);
2011-06-06 07:02:13 +02:00
if (now == (LONGLONG) -1)
return -1;
tp->tv_sec = now / NSPERSEC;
tp->tv_nsec = (now % NSPERSEC);
2011-06-06 07:02:13 +02:00
break;
}
default:
2011-06-06 07:02:13 +02:00
set_errno (EINVAL);
return -1;
* cygwin/include/signal.h: Add copyright notice. * cygwin.din: Make clock SIGFE. Add clock_gettime, sigwaitinfo, timer_create, timer_delete, timer_settime. * include/cygwin/version.h: Reflect above additions. * fork.cc (fork_child): Call fixup_timers_after_fork. * signal.cc (sigwait): Remove unused variable. * timer.cc: New file. (clock_gettime): Define new function. (timer_tracker): Define new struct used by timer functions. (timer_tracker::timer_tracker): New function. (to_us): New function. (timer_thread): New function. (timer_tracker::settime): New function. (timer_create): New function. (timer_settime): New function. (timer_delete): New function. (fixup_timers_after_fork): New function. * cygthread.cc: Bump thread count. * signal.cc (sigwaitinfo): Define new function. (sigwait): Redefine based on sigwaitinfo. * include/cygwin/signal.h (sigwaitinfo): Declare. (sigwait): Ditto. * dtable.cc (dtable::vfork_parent_restore): Avoid double close of ctty when ctty == ctty_on_hold. * cygtls.h (_threadinfo::threadkill): New element. (_threadinfo::set_threadkill): Declare new function. (_threadinfo::reset_threadkill): Declare new function. * dcrt0.cc (dcrt0_1): Call here so that it will be possible to attach to running process with #(*& Windows Me/9x. (initial_env): Try to initialize strace if uninitialized. * gendef: Don't zero signal if threadkill is set since that will happen in the called function. * signal.cc (sigwait): Ensure cleanup in error conditions. * sigproc.cc (sig_send): Clear packet mask storage. (wait_subproc): Fill in child exit code in siginfo_t structure. * thread.cc (pthread_kill): Set threadkill flag. * tlsoffsets.h: Regenerate. Throughout, use siginfo_t to fill out all signal information for "kernel" signals. * cygtls.h (_threadinfo::set_siginfo): Declare new function. * cygtls.cc (_threadinfo::set_siginfo): Define new function. * dcrt0.cc (do_exit): Accommodate siginfo_t considerations. * exceptions.cc (handle_exceptions): Ditto. (sig_handle_tty_stop): Ditto. (ctrl_c_handler): Use killsys() to send signal. (sigpacket::process): Rename from sig_handle. Use siginfo_t field from sigpacket for everything. (tty_min::kill_pgrp): Accommodate siginfo_t considerations. (fhandler_termios::bg_check): Ditto. * fhandler_tty.cc (fhandler_tty_slave::ioctl): Use killsys() to send signal. * signal.cc (kill_worker): Rewrite to use siginfo_t second argument. (kill_pgrp): Ditto. (kill0): Define new function pulled from kill(). (kill): Rewrite as frontend to kill0. (killsys): Define new function. * sigproc.cc (sigelem): Eliminate. (sigpacket): Move to sigproc.h. Subsume sigelem. (pending_signals): Use sigpacket rather than sigelem for everything. (sig_clear): Ditto. (wait_sig): Ditto. (sig_send): Rewrite to use siginfo_t argument. (sig_send): New function wratpper to sig_send with siginfo_t argument. (wait_subproc): Accommodate siginfo_t considerations. * thread.cc (pthread_kill): Ditto. * sigproc.h (sigpacket): Move here. (sigpacket::process): Declare "new" function. (sig_handle): Eliminate declaration. (sig_send): Declare with new paramaters. (killsys): Declare new function. (kill_pgrp): Declare. * winsup.h: Move some signal-specific stuff to sigproc.h. * include/cygwin/signal.h: Tweak some siginfo_t stuff.
2004-01-19 06:46:54 +01:00
}
return 0;
}
extern "C" int
clock_settime (clockid_t clk_id, const struct timespec *tp)
{
struct timeval tv;
if (CLOCKID_IS_PROCESS (clk_id) || CLOCKID_IS_THREAD (clk_id))
/* According to POSIX, the privileges to set a particular clock
* are implementation-defined. On Linux, CPU-time clocks are not
* settable; do the same here.
*/
{
set_errno (EPERM);
return -1;
}
if (clk_id != CLOCK_REALTIME)
{
set_errno (EINVAL);
return -1;
}
tv.tv_sec = tp->tv_sec;
tv.tv_usec = tp->tv_nsec / 1000;
return settimeofday (&tv, NULL);
}
Streamline time/times functionality. Remove last remains of former Windows 9x compatibility. * fhandler_disk_file.cc (fhandler_base::fstat_helper): Drop now unneeded casts in calls to_timestruc_t. (fhandler_base::utimens_fs): Ditto for timespec_to_filetime. * fhandler_proc.cc (format_proc_stat): Ditto for to_time_t. * hires.h (class hires_ms): Remove unused member initime_ns. Remove declarations for timeGetTime_ns and prime. (hires_ms::uptime): Remove. * posix_ipc.cc (ipc_cond_timedwait): Ditto for timespec_to_filetime. * fhandler_registry.cc (fhandler_registry::fstat): Add cast. * resource.cc (fill_rusage): Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. * times.cc: Simplify time handling. Throughout, use LARGE_INTEGER rather than FILETIME to simplify computations. Throughout use {u}int64_t rather than {unsigned} long long. Drop unneeded casts since NSPERSEC is 64 bit anyway. (systime_ns): Remove. (times): Call NtQuerySystemInformation to fetch boot time. Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. Call GetSystemTimeAsFileTime. (totimeval): Use constant 1000000 as in other functions. (time_t_to_filetime): Remove. (to_time_t): Change return type to time_t. (time_as_timestruc_t): Rename filetime to systime. (time): Ditto. Add cast. (hires_ns::nsecs): Fix return type cast. (hires_ms::timeGetTime_ns): Remove. (hires_ns::prime): Remove. (hires_ms::nsecs): Drop call to prime. Call GetSystemTimeAsFileTime directly. Subtract FACTOR here since it's the only function needing to do so. (minperiod): Cosmetically change to ULONG. (hires_ns::resolution): Fix return type cast. (hires_ms::resolution): Simplify, rely on NtQueryTimerResolution. * winsup.h: Align time related prototypes to above changes.
2013-06-14 11:09:41 +02:00
static ULONG minperiod; // FIXME: Maintain period after a fork.
LONGLONG
hires_ns::resolution ()
{
if (!inited)
prime ();
if (inited < 0)
{
set_errno (ENOSYS);
Streamline time/times functionality. Remove last remains of former Windows 9x compatibility. * fhandler_disk_file.cc (fhandler_base::fstat_helper): Drop now unneeded casts in calls to_timestruc_t. (fhandler_base::utimens_fs): Ditto for timespec_to_filetime. * fhandler_proc.cc (format_proc_stat): Ditto for to_time_t. * hires.h (class hires_ms): Remove unused member initime_ns. Remove declarations for timeGetTime_ns and prime. (hires_ms::uptime): Remove. * posix_ipc.cc (ipc_cond_timedwait): Ditto for timespec_to_filetime. * fhandler_registry.cc (fhandler_registry::fstat): Add cast. * resource.cc (fill_rusage): Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. * times.cc: Simplify time handling. Throughout, use LARGE_INTEGER rather than FILETIME to simplify computations. Throughout use {u}int64_t rather than {unsigned} long long. Drop unneeded casts since NSPERSEC is 64 bit anyway. (systime_ns): Remove. (times): Call NtQuerySystemInformation to fetch boot time. Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. Call GetSystemTimeAsFileTime. (totimeval): Use constant 1000000 as in other functions. (time_t_to_filetime): Remove. (to_time_t): Change return type to time_t. (time_as_timestruc_t): Rename filetime to systime. (time): Ditto. Add cast. (hires_ns::nsecs): Fix return type cast. (hires_ms::timeGetTime_ns): Remove. (hires_ns::prime): Remove. (hires_ms::nsecs): Drop call to prime. Call GetSystemTimeAsFileTime directly. Subtract FACTOR here since it's the only function needing to do so. (minperiod): Cosmetically change to ULONG. (hires_ns::resolution): Fix return type cast. (hires_ms::resolution): Simplify, rely on NtQueryTimerResolution. * winsup.h: Align time related prototypes to above changes.
2013-06-14 11:09:41 +02:00
return (LONGLONG) -1;
}
return (freq <= 1.0) ? 1LL : (LONGLONG) freq;
}
UINT
hires_ms::resolution ()
{
if (!minperiod)
{
ULONG coarsest, finest, actual;
Streamline time/times functionality. Remove last remains of former Windows 9x compatibility. * fhandler_disk_file.cc (fhandler_base::fstat_helper): Drop now unneeded casts in calls to_timestruc_t. (fhandler_base::utimens_fs): Ditto for timespec_to_filetime. * fhandler_proc.cc (format_proc_stat): Ditto for to_time_t. * hires.h (class hires_ms): Remove unused member initime_ns. Remove declarations for timeGetTime_ns and prime. (hires_ms::uptime): Remove. * posix_ipc.cc (ipc_cond_timedwait): Ditto for timespec_to_filetime. * fhandler_registry.cc (fhandler_registry::fstat): Add cast. * resource.cc (fill_rusage): Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. * times.cc: Simplify time handling. Throughout, use LARGE_INTEGER rather than FILETIME to simplify computations. Throughout use {u}int64_t rather than {unsigned} long long. Drop unneeded casts since NSPERSEC is 64 bit anyway. (systime_ns): Remove. (times): Call NtQuerySystemInformation to fetch boot time. Call NtQueryInformationProcess rather than GetProcessTimes to deal with LARGE_INTEGER rather than FILETIME. Call GetSystemTimeAsFileTime. (totimeval): Use constant 1000000 as in other functions. (time_t_to_filetime): Remove. (to_time_t): Change return type to time_t. (time_as_timestruc_t): Rename filetime to systime. (time): Ditto. Add cast. (hires_ns::nsecs): Fix return type cast. (hires_ms::timeGetTime_ns): Remove. (hires_ns::prime): Remove. (hires_ms::nsecs): Drop call to prime. Call GetSystemTimeAsFileTime directly. Subtract FACTOR here since it's the only function needing to do so. (minperiod): Cosmetically change to ULONG. (hires_ns::resolution): Fix return type cast. (hires_ms::resolution): Simplify, rely on NtQueryTimerResolution. * winsup.h: Align time related prototypes to above changes.
2013-06-14 11:09:41 +02:00
NtQueryTimerResolution (&coarsest, &finest, &actual);
/* The actual resolution of the OS timer is a system-wide setting which
can be changed any time, by any process. The only fixed value we
can rely on is the coarsest value. */
minperiod = coarsest;
}
return minperiod;
}
extern "C" int
clock_getres (clockid_t clk_id, struct timespec *tp)
{
if (CLOCKID_IS_PROCESS (clk_id) || CLOCKID_IS_THREAD (clk_id))
{
ULONG coarsest, finest, actual;
NtQueryTimerResolution (&coarsest, &finest, &actual);
tp->tv_sec = coarsest / NS100PERSEC;
tp->tv_nsec = (coarsest % NS100PERSEC) * (NSPERSEC/NS100PERSEC);
return 0;
}
switch (clk_id)
{
case CLOCK_REALTIME:
2011-06-06 07:02:13 +02:00
{
DWORD period = gtod.resolution ();
tp->tv_sec = period / NS100PERSEC;
tp->tv_nsec = (period % NS100PERSEC) * (NSPERSEC/NS100PERSEC);
2011-06-06 07:02:13 +02:00
break;
}
case CLOCK_MONOTONIC:
2011-06-06 07:02:13 +02:00
{
LONGLONG period = ntod.resolution ();
tp->tv_sec = period / NSPERSEC;
tp->tv_nsec = period % NSPERSEC;
2011-06-06 07:02:13 +02:00
break;
}
default:
2011-06-06 07:02:13 +02:00
set_errno (EINVAL);
return -1;
}
return 0;
}
extern "C" int
clock_setres (clockid_t clk_id, struct timespec *tp)
{
static NO_COPY bool period_set;
int status;
if (clk_id != CLOCK_REALTIME)
{
set_errno (EINVAL);
return -1;
}
/* Convert to 100ns to match OS resolution. The OS uses ULONG values
to express resolution in 100ns units, so the coarsest timer resolution
is < 430 secs. Actually the coarsest timer resolution is only slightly
beyond 15ms, but this might change in future OS versions, so we play nice
here. */
ULONGLONG period = tp->tv_sec * NS100PERSEC
+ (tp->tv_nsec + (NSPERSEC/NS100PERSEC) - 1)
/ (NSPERSEC/NS100PERSEC);
/* clock_setres is non-POSIX/non-Linux. On QNX, the function always
rounds the incoming value to the nearest supported value. */
ULONG coarsest, finest, actual;
if (NT_SUCCESS (NtQueryTimerResolution (&coarsest, &finest, &actual)))
{
if (period > coarsest)
period = coarsest;
else if (finest > period)
period = finest;
}
if (period_set
* cygtls.h (struct _local_storage): Add cw_timer member. * cygtls.cc (_cygtls::init_thread): Initialize locals.cw_timer. (_cygtls::fixup_after_fork): Ditto. * tlsoffsets.h: Regenerate. * ntdll.h (enum _TIMER_INFORMATION_CLASS): Define. (struct _TIMER_BASIC_INFORMATION): Define. (NtQueryTimer): Declare function. * thread.h (cancelable_wait): Change timeout argument to PLARGE_INTEGER and provide NULL default. (fast_mutex::lock): Adjust accordingly. (pthread_cond::wait): Change timeout argument to PLARGE_INTEGER and default to NULL. * thread.cc (cancelable_wait): Change timeout argument to PLARGE_INTEGER. Initialize _cygtls.locals.cw_timer if needed. Use NT waitable timers for handling timeout. Return remaining time to timeout argument if timeout was relative. (pthread_cond::wait): Change timeout argument to PLARGE_INTEGER. Adjust to change in cancelable_wait. (pthread_mutex::lock): Adjust to change in cancelable_wait. (pthread_spinlock::lock): Ditto. (pthread::join): Ditto. (__pthread_cond_dowait): Change waitlength argument to PLARGE_INTEGER. Adjust to changes in cancelable_wait and pthread_cond::wait. (pthread_cond_timedwait): Adjust to change in __pthread_cond_dowait. (pthread_cond_wait): Ditto. (semaphore::_timedwait): Adjust to change in cancelable_wait. (semaphore::_wait): Ditto. * exceptions.cc (handle_sigsuspend): Ditto. * signal.cc (nanosleep): Ditto. * wait.cc (wait4): Ditto. Fix copyright dates. * times.cc (FACTOR, NSPERSEC): Move from here... * hires.h (FACTOR, NSPERSEC): ...to here.
2011-08-03 18:40:48 +02:00
&& NT_SUCCESS (NtSetTimerResolution (minperiod, FALSE, &actual)))
period_set = false;
status = NtSetTimerResolution (period, TRUE, &actual);
if (!NT_SUCCESS (status))
{
__seterrno_from_nt_status (status);
return -1;
}
minperiod = period;
period_set = true;
return 0;
}
extern "C" int
clock_getcpuclockid (pid_t pid, clockid_t *clk_id)
{
if (pid != 0)
{
pinfo p (pid);
if (!p || !p->exists ())
return (ESRCH);
}
*clk_id = (clockid_t) PID_TO_CLOCKID (pid);
return 0;
}