9 * These routines do their printing without using stdio. Stdio can't
10 * be used because it calls malloc(). Internal routines of a malloc()
11 * debugger should not re-enter malloc(), so stdio is out.
15 * NUMBER_BUFFER_SIZE is the longest character string that could be needed
16 * to represent an unsigned integer, assuming we might print in base 2.
18 #define NUMBER_BUFFER_SIZE (sizeof(ef_number) * NBBY)
21 printNumber(ef_number number, ef_number base)
23 char buffer[NUMBER_BUFFER_SIZE];
24 char * s = &buffer[NUMBER_BUFFER_SIZE];
31 EF_Abort("Internal error printing number.");
33 digit = number % base;
38 *s = 'a' + digit - 10;
40 } while ( (number /= base) > 0 );
42 size = &buffer[NUMBER_BUFFER_SIZE] - s;
49 vprint(const char * pattern, va_list args)
51 static const char bad_pattern[] =
52 "\nBad pattern specifier %%%c in EF_Print().\n";
53 const char * s = pattern;
56 while ( (c = *s++) != '\0' ) {
61 (void) write(2, &c, 1);
65 * Print an address passed as a void pointer.
66 * The type of ef_number must be set so that
67 * it is large enough to contain all of the
68 * bits of a void pointer.
71 (ef_number)va_arg(args, void *)
79 string = va_arg(args, char *);
80 length = strlen(string);
82 (void) write(2, string, length);
87 int n = va_arg(args, int);
98 printNumber(va_arg(args, u_int), 0x10);
102 char c = va_arg(args, char);
104 (void) write(2, &c, 1);
109 EF_Print(bad_pattern, c);
115 (void) write(2, &c, 1);
120 EF_Abort(const char * pattern, ...)
124 va_start(args, pattern);
126 EF_Print("\nElectricFence Aborting: ");
127 vprint(pattern, args);
133 * I use kill(getpid(), SIGILL) instead of abort() because some
134 * mis-guided implementations of abort() flush stdio, which can
135 * cause malloc() or free() to be called.
137 kill(getpid(), SIGILL);
138 /* Just in case something handles SIGILL and returns, exit here. */
143 EF_Exit(const char * pattern, ...)
147 va_start(args, pattern);
149 EF_Print("\nElectricFence Exiting: ");
150 vprint(pattern, args);
156 * I use _exit() because the regular exit() flushes stdio,
157 * which may cause malloc() or free() to be called.
163 EF_Print(const char * pattern, ...)
167 va_start(args, pattern);
168 vprint(pattern, args);