summaryrefslogtreecommitdiff
path: root/hurd/stddef.h
blob: 824f60d7b925deaa9890c8e2df4a33f3f557c02e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* hurd/stddef.h - Standard definitions for the GNU Hurd.
   Copyright (C) 2007, 2008 Free Software Foundation, Inc.
   Written by Neal H. Walfield <neal@gnu.org>

   This file is part of the GNU Hurd.

   GNU Hurd is free software: you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   GNU Hurd is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with GNU Hurd.  If not, see
   <http://www.gnu.org/licenses/>.  */

#ifndef _HURD_STDDEF_H
#define _HURD_STDDEF_H	1

#ifndef ASM

#include <l4/types.h>
#include <assert.h>

/* Safe printf and putchar routines.  In particular, they don't call malloc and
   work in place.  This makes it appropriate for situations in which
   malloc is not yet working and when the state is suspected to be
   compromised (e.g., assert or panic).  */
#ifndef S_PRINTF
# if defined(RM_INTERN) || defined(_L4_TEST_ENVIRONMENT) || defined(_ENABLE_TESTS)
#  define S_PRINTF printf
# else
#  define S_PRINTF s_printf
# endif
#endif
extern int S_PRINTF (const char *fmt, ...);
#ifndef S_PUTCHAR
# if defined(RM_INTERN) || defined(_L4_TEST_ENVIRONMENT) || defined(_ENABLE_TESTS)
#  define S_PUTCHAR putchar
# else
#  define S_PUTCHAR s_putchar
# endif
#endif
extern int S_PUTCHAR (int chr);

/* Convenient debugging macros.  */
#define DEBUG_BOLD(text) "\033[01;31m" text "\033[00m"

#if defined(DEBUG_ELIDE)
# if DEBUG_ELIDE + 0 == 0
#  define do_debug(level) if (0)
# endif
#endif

#ifndef do_debug
# ifndef DEBUG_COND
extern int output_debug;
#  ifdef DEBUG_ELIDE
/* We elide some code at compile time.  */
#   define DEBUG_COND(level) \
  ((level) <= output_debug && (level) < DEBUG_ELIDE)
#  else
/* The default DEBUG_COND is LEVEL <= output_debug.  */
#   define DEBUG_COND(level) ((level) <= output_debug)
#  endif /* DEBUG_ELIDE.  */
# endif /* DEBUG_COND.  */

# define do_debug(level) if (DEBUG_COND(level))

#endif /* do_debug.  */

#include <l4/thread.h>

/* Print a debug message if DEBUG_COND is true.  */
#define debug(level, fmt, ...)						\
  do									\
    {									\
      extern char *program_name;					\
      extern int S_PRINTF (const char *, ...);				\
      do_debug (level)							\
        S_PRINTF ("%s (%x):%s:%d: " fmt "\n",				\
		  program_name, l4_myself (), __func__, __LINE__,	\
		  ##__VA_ARGS__);					\
    }									\
  while (0)

/* Print an error message and fail.  This function must be provided by
   the run-time.  */
extern void __attribute__ ((__noreturn__, format (printf, 3, 4)))
  panic_ (const char *func, int line, const char *fmt, ...);

#define panic(fmt, args...)			\
  panic_(__func__, __LINE__, fmt, ##args)

#endif /* ! ASM  */

/* XXX: We define these here as they are useful macros, everyone uses
   them and everyone includes this header file.  We should put them
   somewhere else.  */
#ifdef i386
#define PAGESIZE 0x1000
#define PAGESIZE_LOG2 12
#else
#error Not ported to this architecture.
#endif

/* Linux compatible names.  */
#define PAGE_SIZE PAGESIZE
#define PAGE_SHIFT PAGESIZE_LOG2
#define PAGE_MASK (~(PAGE_SIZE-1))

#ifndef ASM
#define likely(expr) __builtin_expect ((expr), 1)
#define unlikely(expr) __builtin_expect ((expr), 0)
#endif

#endif	/* _HURD_STDDEF_H */