summaryrefslogtreecommitdiff
path: root/src/libc/intr.c
blob: e751fa138919fb31ddb8456465e1656c09b59136 (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
#include <camellia/intr.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>

static void intr_null(struct intr_data *) { }

extern void (*volatile _intr)(struct intr_data *);
void intr_set(void (*fn)(struct intr_data *)) {
	_intr = fn ? fn : intr_null;
}

/* does haystack begin with needle? */
static
bool strprefix(const char *haystack, const char *needle)
{
	for (;; haystack++, needle++) {
		if (*needle == '\0') return true;
		/* note that *haystack == '\0' implies *needle != *haystack */
		if (*needle != *haystack) return false;
	}
}

__attribute__((visibility("hidden")))
extern char __executable_start[];

void intr_default(struct intr_data *d) {
	if (strprefix(d->msg, "sys: ")) {
		fprintf(stderr, "%s: %s (base %p)\n", getprogname(), d->msg, __executable_start);
	}
	exit(1);
}