make vfs & filesystems use failable copying
[minix3.git] / include / minix / sysutil.h
blobcc9eeebd1ab77165ff0e26e5f7b8d488dc74abe3
1 #ifndef _MINIX_SYSUTIL_H
2 #define _MINIX_SYSUTIL_H 1
4 #include <minix/ipc.h>
5 #include <sys/cdefs.h>
7 /* Extra system library definitions to support device drivers and servers.
9 * Created:
10 * Mar 15, 2004 by Jorrit N. Herder
12 * Changes:
13 * May 31, 2005: added printf, kputc (relocated from syslib)
14 * May 31, 2005: added getuptime
15 * Mar 18, 2005: added tickdelay
16 * Oct 01, 2004: added env_parse, env_prefix, env_panic
17 * Jul 13, 2004: added fkey_ctl
18 * Apr 28, 2004: added report, panic
19 * Mar 31, 2004: setup like other libraries, such as syslib
22 /*==========================================================================*
23 * Miscellaneous helper functions.
24 *==========================================================================*/
26 /* Environment parsing return values. */
27 #define EP_BUF_SIZE 128 /* local buffer for env value */
28 #define EP_UNSET 0 /* variable not set */
29 #define EP_OFF 1 /* var = off */
30 #define EP_ON 2 /* var = on (or field left blank) */
31 #define EP_SET 3 /* var = 1:2:3 (nonblank field) */
32 #define EP_EGETKENV 4 /* sys_getkenv() failed ... */
34 extern int env_argc;
35 extern char **env_argv;
37 void env_setargs(int argc, char *argv[]);
38 int env_get_param(const char *key, char *value, int max_size);
39 int env_prefix(char *env, char *prefix);
40 void env_panic(const char *key);
41 int env_parse(const char *env, const char *fmt, int field,
42 long *param, long min, long max);
44 #define fkey_map(fkeys, sfkeys) fkey_ctl(FKEY_MAP, (fkeys), (sfkeys))
45 #define fkey_unmap(fkeys, sfkeys) fkey_ctl(FKEY_UNMAP, (fkeys), (sfkeys))
46 #define fkey_events(fkeys, sfkeys) fkey_ctl(FKEY_EVENTS, (fkeys), (sfkeys))
47 int fkey_ctl(int req, int *fkeys, int *sfkeys);
49 int printf(const char *fmt, ...);
50 void kputc(int c);
51 __dead void panic(const char *fmt, ...)
52 __attribute__((__format__(__printf__,1,2)));
53 int getuptime(clock_t *ticks, clock_t *realtime, time_t *boottime);
54 int getticks(clock_t *ticks);
55 int tickdelay(clock_t ticks);
56 int tsc_calibrate(void);
57 u32_t sys_hz(void);
58 double getidle(void);
59 void util_stacktrace(void);
60 int micro_delay(u32_t micros);
61 u32_t tsc_64_to_micros(u64_t tsc);
62 u32_t tsc_to_micros(u32_t low, u32_t high);
63 u32_t tsc_get_khz(void);
64 u32_t micros_to_ticks(u32_t micros);
65 #if defined(__arm__)
66 void read_frclock(u32_t *frclk);
67 u32_t delta_frclock(u32_t base, u32_t cur);
68 #endif
69 void read_frclock_64(u64_t *frclk);
70 u64_t delta_frclock_64(u64_t base, u64_t cur);
71 u32_t frclock_64_to_micros(u64_t tsc);
72 void ser_putc(char c);
73 void get_randomness(struct k_randomness *, int);
74 u32_t sqrt_approx(u32_t);
76 int stime(time_t *_top);
78 #define asynsend(ep, msg) asynsend3(ep, msg, 0)
79 int asynsend3(endpoint_t ep, message *msg, int flags);
80 int asyn_geterror(endpoint_t *dst, message *msg, int *err);
82 #define ASSERT(c) if(!(c)) { panic("%s:%d: assert %s failed", __FILE__, __LINE__, #c); }
84 /* timing library */
85 #define TIMING_CATEGORIES 20
87 #define TIMING_POINTS 20 /* timing resolution */
88 #define TIMING_CATEGORIES 20
89 #define TIMING_NAME 10
91 struct util_timingdata {
92 char names[TIMING_NAME];
93 unsigned long lock_timings[TIMING_POINTS];
94 unsigned long lock_timings_range[2];
95 unsigned long binsize, resets, misses, measurements;
96 unsigned long starttimes[2]; /* nonzero if running */
99 typedef struct util_timingdata util_timingdata_t;
101 #endif /* _MINIX_SYSUTIL_H */