1 /* Filter driver - utility functions */
7 static clock_t next_alarm
;
9 /*===========================================================================*
11 *===========================================================================*/
12 char *flt_malloc(size_t size
, char *sbuf
, size_t ssize
)
14 /* Allocate a buffer for 'size' bytes. If 'size' is equal to or less
15 * than 'ssize', return the static buffer 'sbuf', otherwise, use
16 * malloc() to allocate memory dynamically.
23 p
= mmap(NULL
, size
, PROT_READ
| PROT_WRITE
,
24 MAP_PREALLOC
| MAP_CONTIG
| MAP_ANON
, -1, 0);
26 panic(__FILE__
, "out of memory", size
);
31 /*===========================================================================*
33 *===========================================================================*/
34 void flt_free(char *buf
, size_t size
, char *sbuf
)
36 /* Free a buffer previously allocated with flt_malloc().
43 /*===========================================================================*
45 *===========================================================================*/
46 char *print64(u64_t p
)
50 static char buf
[NB
][100];
51 u32_t lo
= ex64lo(p
), hi
= ex64hi(p
);
53 if(!hi
) sprintf(buf
[n
], "%lx", lo
);
54 else sprintf(buf
[n
], "%lx%08lx", hi
, lo
);
58 /*===========================================================================*
60 *===========================================================================*/
61 clock_t flt_alarm(clock_t dt
)
68 r
= sys_setalarm(dt
, 0);
71 panic(__FILE__
, "sys_setalarm failed", r
);
75 panic(__FILE__
, "clearing unset alarm", r
);
79 panic(__FILE__
, "overwriting alarm", r
);
80 if ((r
= getuptime(&next_alarm
)) != OK
)
81 panic(__FILE__
, "getuptime failed", r
);
88 /*===========================================================================*
90 *===========================================================================*/
91 static void got_alarm(int sig
)
96 /*===========================================================================*
98 *===========================================================================*/
99 void flt_sleep(int secs
)
101 /* Sleep for the given number of seconds. Don't use sleep(), as that
102 * will end up calling select() to VFS. This implementation could be
106 signal(SIGALRM
, got_alarm
);