4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-01-19 12:59:21 +08:00
newlib-cygwin/winsup/cygwin/posix_timer.h
Corinna Vinschen 83c51fffe6 Cygwin: posix timers: allocate timer_tracker on system heap.
Allocating on the cygheap would copy information of the tracker into
the child process.  A forked child knows the timer id and could simply
still access the (free'd but still valid) timer_tracker on the heap,
which is dangerous and very certainly doesn't reflect POSIX semantics.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-22 16:38:14 +01:00

56 lines
1.5 KiB
C++

/* timer.h: Define class timer_tracker, base class for posix timers
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. */
#ifndef __TIMER_H__
#define __TIMER_H__
#define TT_MAGIC 0x513e4a1c
class timer_tracker
{
unsigned magic;
SRWLOCK srwlock;
clockid_t clock_id;
sigevent evp;
struct itimerspec time_spec;
HANDLE timer;
HANDLE cancel_evt;
HANDLE sync_thr;
LONG64 interval;
LONG64 exp_ts;
LONG overrun_event_running;
LONG overrun_count_curr;
LONG64 overrun_count;
bool cancel ();
public:
void *operator new (size_t, void *p) __attribute__ ((nothrow)) {return p;}
void operator delete (void *p) { HeapFree (GetProcessHeap (), 0, p); }
timer_tracker (clockid_t, const sigevent *);
~timer_tracker ();
inline bool is_timer_tracker () const { return magic == TT_MAGIC; }
inline sigevent_t *sigevt () { return &evp; }
inline int getoverrun () const { return overrun_count_curr; }
LONG64 get_clock_now () const { return get_clock (clock_id)->n100secs (); }
LONG64 get_exp_ts () const { return exp_ts; }
LONG64 get_interval () const { return interval; }
void set_exp_ts (LONG64 ts) { exp_ts = ts; }
LONG arm_overrun_event ();
LONG disarm_overrun_event ();
int gettime (itimerspec *, bool);
int settime (int, const itimerspec *, itimerspec *);
DWORD thread_func ();
static void fixup_after_fork ();
};
#endif /* __TIMER_H__ */