diff options
Diffstat (limited to 'contrib/ntp/include')
-rw-r--r-- | contrib/ntp/include/Makefile.am | 1 | ||||
-rw-r--r-- | contrib/ntp/include/Makefile.in | 1 | ||||
-rw-r--r-- | contrib/ntp/include/ntp_refclock.h | 2 | ||||
-rw-r--r-- | contrib/ntp/include/ntp_stdlib.h | 8 | ||||
-rw-r--r-- | contrib/ntp/include/ntp_worker.h | 66 | ||||
-rw-r--r-- | contrib/ntp/include/ntpd.h | 3 | ||||
-rw-r--r-- | contrib/ntp/include/safecast.h | 34 |
7 files changed, 88 insertions, 27 deletions
diff --git a/contrib/ntp/include/Makefile.am b/contrib/ntp/include/Makefile.am index f032c97..d8b4dd2 100644 --- a/contrib/ntp/include/Makefile.am +++ b/contrib/ntp/include/Makefile.am @@ -66,6 +66,7 @@ noinst_HEADERS = \ recvbuff.h \ refclock_atom.h \ refidsmear.h \ + safecast.h \ ssl_applink.c \ timepps-SCO.h \ timepps-Solaris.h \ diff --git a/contrib/ntp/include/Makefile.in b/contrib/ntp/include/Makefile.in index 8f0968b..6e45e93 100644 --- a/contrib/ntp/include/Makefile.in +++ b/contrib/ntp/include/Makefile.in @@ -551,6 +551,7 @@ noinst_HEADERS = \ recvbuff.h \ refclock_atom.h \ refidsmear.h \ + safecast.h \ ssl_applink.c \ timepps-SCO.h \ timepps-Solaris.h \ diff --git a/contrib/ntp/include/ntp_refclock.h b/contrib/ntp/include/ntp_refclock.h index f92d14c..b264dfa 100644 --- a/contrib/ntp/include/ntp_refclock.h +++ b/contrib/ntp/include/ntp_refclock.h @@ -220,7 +220,7 @@ extern void refclock_buginfo(sockaddr_u *, extern void refclock_control(sockaddr_u *, const struct refclockstat *, struct refclockstat *); -extern int refclock_open (char *, u_int, u_int); +extern int refclock_open (const char *, u_int, u_int); extern int refclock_setup (int, u_int, u_int); extern void refclock_timer (struct peer *); extern void refclock_transmit(struct peer *); diff --git a/contrib/ntp/include/ntp_stdlib.h b/contrib/ntp/include/ntp_stdlib.h index a2e62da..d735b41 100644 --- a/contrib/ntp/include/ntp_stdlib.h +++ b/contrib/ntp/include/ntp_stdlib.h @@ -65,8 +65,8 @@ typedef void (*ctrl_c_fn)(void); /* authkeys.c */ extern void auth_delkeys (void); extern int auth_havekey (keyid_t); -extern int authdecrypt (keyid_t, u_int32 *, int, int); -extern int authencrypt (keyid_t, u_int32 *, int); +extern int authdecrypt (keyid_t, u_int32 *, size_t, size_t); +extern size_t authencrypt (keyid_t, u_int32 *, size_t); extern int authhavekey (keyid_t); extern int authistrusted (keyid_t); extern int authreadkeys (const char *); @@ -95,8 +95,8 @@ extern void auth_prealloc_symkeys(int); extern int ymd2yd (int, int, int); /* a_md5encrypt.c */ -extern int MD5authdecrypt (int, u_char *, u_int32 *, int, int); -extern int MD5authencrypt (int, u_char *, u_int32 *, int); +extern int MD5authdecrypt (int, const u_char *, u_int32 *, size_t, size_t); +extern size_t MD5authencrypt (int, const u_char *, u_int32 *, size_t); extern void MD5auth_setkey (keyid_t, int, const u_char *, size_t); extern u_int32 addr2refid (sockaddr_u *); diff --git a/contrib/ntp/include/ntp_worker.h b/contrib/ntp/include/ntp_worker.h index f7e8d5b..50616b3 100644 --- a/contrib/ntp/include/ntp_worker.h +++ b/contrib/ntp/include/ntp_worker.h @@ -43,19 +43,22 @@ typedef struct blocking_pipe_header_tag { } blocking_pipe_header; # ifdef WORK_THREAD -# ifdef WORK_PIPE -typedef pthread_t * thr_ref; -typedef sem_t * sem_ref; +# ifdef SYS_WINNT +typedef struct { HANDLE thnd; } thread_type; +typedef struct { HANDLE shnd; } sema_type; # else -typedef HANDLE thr_ref; -typedef HANDLE sem_ref; +typedef pthread_t thread_type; +typedef sem_t sema_type; # endif +typedef thread_type *thr_ref; +typedef sema_type *sem_ref; # endif /* * */ -#ifdef WORK_FORK +#if defined(WORK_FORK) + typedef struct blocking_child_tag { int reusable; int pid; @@ -66,38 +69,59 @@ typedef struct blocking_child_tag { int resp_write_pipe; int ispipe; } blocking_child; + #elif defined(WORK_THREAD) + typedef struct blocking_child_tag { /* * blocking workitems and blocking_responses are dynamically-sized * one-dimensional arrays of pointers to blocking worker requests and * responses. + * + * IMPORTANT: This structure is shared between threads, and all access + * that is not atomic (especially queue operations) must hold the + * 'accesslock' semaphore to avoid data races. + * + * The resource management (thread/semaphore creation/destruction) + * functions and functions just testing a handle are safe because these + * are only changed by the main thread when no worker is running on the + * same data structure. */ int reusable; - thr_ref thread_ref; - u_int thread_id; - blocking_pipe_header * volatile * volatile + sem_ref accesslock; /* shared access lock */ + thr_ref thread_ref; /* thread 'handle' */ + + /* the reuest queue */ + blocking_pipe_header ** volatile workitems; volatile size_t workitems_alloc; - size_t next_workitem; /* parent */ - size_t next_workeritem; /* child */ - blocking_pipe_header * volatile * volatile + size_t head_workitem; /* parent */ + size_t tail_workitem; /* child */ + sem_ref workitems_pending; /* signalling */ + + /* the response queue */ + blocking_pipe_header ** volatile responses; volatile size_t responses_alloc; - size_t next_response; /* child */ - size_t next_workresp; /* parent */ + size_t head_response; /* child */ + size_t tail_response; /* parent */ + /* event handles / sem_t pointers */ - /* sem_ref child_is_blocking; */ - sem_ref blocking_req_ready; sem_ref wake_scheduled_sleep; + + /* some systems use a pipe for notification, others a semaphore. + * Both employ the queue above for the actual data transfer. + */ #ifdef WORK_PIPE - int resp_read_pipe; /* parent */ - int resp_write_pipe;/* child */ + int resp_read_pipe; /* parent */ + int resp_write_pipe; /* child */ int ispipe; - void * resp_read_ctx; /* child */ + void * resp_read_ctx; /* child */ #else - sem_ref blocking_response_ready; + sem_ref responses_pending; /* signalling */ #endif + sema_type sem_table[4]; + thread_type thr_table[1]; } blocking_child; #endif /* WORK_THREAD */ @@ -111,7 +135,7 @@ extern u_int available_blocking_child_slot(void); extern int queue_blocking_request(blocking_work_req, void *, size_t, blocking_work_callback, void *); -extern int queue_blocking_response(blocking_child *, +extern int queue_blocking_response(blocking_child *, blocking_pipe_header *, size_t, const blocking_pipe_header *); extern void process_blocking_resp(blocking_child *); diff --git a/contrib/ntp/include/ntpd.h b/contrib/ntp/include/ntpd.h index be3cd3e..362068c 100644 --- a/contrib/ntp/include/ntpd.h +++ b/contrib/ntp/include/ntpd.h @@ -156,7 +156,7 @@ extern u_int sys_tai; extern int freq_cnt; /* ntp_monitor.c */ -#define MON_HASH_SIZE (1U << mon_hash_bits) +#define MON_HASH_SIZE ((size_t)1U << mon_hash_bits) #define MON_HASH_MASK (MON_HASH_SIZE - 1) #define MON_HASH(addr) (sock_hash(addr) & MON_HASH_MASK) extern void init_mon (void); @@ -408,6 +408,7 @@ extern int hardpps_enable; /* kernel PPS discipline enabled */ extern int ext_enable; /* external clock enabled */ extern int cal_enable; /* refclock calibrate enable */ extern int allow_panic; /* allow panic correction (-g) */ +extern int enable_panic_check; /* Can we check allow_panic's state? */ extern int force_step_once; /* always step time once at startup (-G) */ extern int mode_ntpdate; /* exit on first clock set (-q) */ extern int peer_ntpdate; /* count of ntpdate peers */ diff --git a/contrib/ntp/include/safecast.h b/contrib/ntp/include/safecast.h new file mode 100644 index 0000000..9300463 --- /dev/null +++ b/contrib/ntp/include/safecast.h @@ -0,0 +1,34 @@ +#ifndef SAFECAST_H +#define SAFECAST_H + +#include <limits.h> +static inline int size2int_chk(size_t v) +{ + if (v > INT_MAX) + abort(); + return (int)(v); +} + +static inline int size2int_sat(size_t v) +{ + return (v > INT_MAX) ? INT_MAX : (int)v; +} + +/* Compilers can emit warning about increased alignment requirements + * when casting pointers. The impact is tricky: on machines where + * alignment is just a performance issue (x86,x64,...) this might just + * cause a performance penalty. On others, an address error can occur + * and the process dies... + * + * Still, there are many cases where the pointer arithmetic and the + * buffer alignment make sure this does not happen. OTOH, the compiler + * doesn't know this and still emits warnings. + * + * The following cast macros are going through void pointers to tell + * the compiler that there is no alignment requirement to watch. + */ +#define UA_PTR(ptype,pval) ((ptype *)(void*)(pval)) +#define UAC_PTR(ptype,pval) ((const ptype *)(const void*)(pval)) +#define UAV_PTR(ptype,pval) ((volatile ptype *)(volatile void*)(pval)) + +#endif |