6 #define IN_DEPUTY_LIBRARY
8 // Use inline even when not optimizing for speed, since it prevents
9 // warnings that would occur due to unused static functions.
10 #ifdef DEPUTY_ALWAYS_STOP_ON_ERROR
11 #define INLINE inline __attribute__((always_inline))
16 #define __LOCATION__ __FILE__, __LINE__, __FUNCTION__
17 #define __LOCATION__FORMALS const char* file, int line, const char* func
18 #define __LOCATION__ACTUALS file, line, func
21 #define asmlinkage __attribute__((regparm(0)))
25 #define noreturn __attribute__((noreturn))
28 extern int __ivy_checking_on;
31 void deputy_fail_mayreturn(const char *check, const char *text,
32 __LOCATION__FORMALS) {
34 if (!__ivy_checking_on) return;
35 old = __ivy_checking_on;
36 __ivy_checking_on = 0;
37 cprintf("%s:%d: %s: Assertion failed in %s: %s\n",
38 __LOCATION__ACTUALS, check, text);
39 __ivy_checking_on = old;
46 void deputy_fail_noreturn_fast(void) {
47 __ivy_checking_on = 0;
48 panic("Deputy assertion failure\n");
49 __ivy_checking_on = 1;
52 int deputy_strlen(const char *str) {
56 char *deputy_strcpy(char *dest, const char *src) {
58 while ((*dest++ = *src++) != '\0') {
64 char *deputy_strncpy(char *dest, const char *src, size_t count) {
68 if ((*tmp = *src) != 0) src++;
75 /* Search for a NULL starting at e and return its index */
76 int deputy_findnull(const void *e, unsigned int bytes) {
77 #define NULLCHECK(type) \
79 type *p = (type*) e; \
83 length = (p - (type*) e); \
99 if (!__ivy_checking_on) return length;
100 __ivy_checking_on = 0;
101 cprintf("Invalid byte size for nullcheck.\n");
102 __ivy_checking_on = 1;
110 void *__deputy_memset(void *s, int c, unsigned int n) {
111 return memset(s, c, n);