summaryrefslogtreecommitdiff
path: root/libs/notify-wrapper.c
blob: d2cf7221dd7e1f26229c0dbccef36e6ec05b43c3 (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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174

#ifndef _GNU_SOURCE
#define _GNU_SOURCE 1
#endif

#include <mach/boolean.h>
#include <mach/kern_return.h>
#include <mach/message.h>
#include <mach/mig_errors.h>
#include <mach/mig_support.h>

#include <mach/std_types.h>
#include <mach/mach_types.h>
#include <device/device_types.h>
#include <device/net_status.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/statfs.h>
#include <sys/resource.h>
#include <sys/utsname.h>
#include <hurd/hurd_types.h>

#include <stdio.h>
#include <assert.h>

#include "notify-wrapper.h"

/* this is NULL initialized */
static void* routines[_NUMBER_OF_ROUTINES];

/* function wrappers follows... */

/* do mach notify port deleted */

typedef kern_return_t (*do_mach_notify_port_deleted_type)(mach_port_t,
		mach_port_t name);

kern_return_t
lisp_S_do_mach_notify_port_deleted(mach_port_t notify,
		mach_port_t name)
{
	//fprintf(stderr, "notify: port deleted\n");
	if(routines[DO_MACH_NOTIFY_PORT_DELETED] == NULL) {
		return 0;
	}

	do_mach_notify_port_deleted_type do_mach_notify_port_deleted_routine =
		routines[DO_MACH_NOTIFY_PORT_DELETED];

	return do_mach_notify_port_deleted_routine(notify, name);
}

/* do mach notify msg accepted */

typedef kern_return_t (*do_mach_notify_msg_accepted_type)(mach_port_t,
		mach_port_t);

kern_return_t
lisp_S_do_mach_notify_msg_accepted(mach_port_t notify,
		mach_port_t name)
{
	//fprintf(stderr, "notify: msg accepted\n");
	if(routines[DO_MACH_NOTIFY_MSG_ACCEPTED] == NULL) {
		return 0;
	}

	do_mach_notify_msg_accepted_type do_mach_notify_msg_accepted_routine =
		routines[DO_MACH_NOTIFY_MSG_ACCEPTED];

	return do_mach_notify_msg_accepted_routine(notify, name);
}

/* do mach notify port destroyed */

typedef kern_return_t (*do_mach_notify_port_destroyed_type)(mach_port_t,
		mach_port_t);

kern_return_t
lisp_S_do_mach_notify_port_destroyed(mach_port_t notify,
		mach_port_t rights)
{
	//fprintf(stderr, "notify: port-destroyed\n");

	if(routines[DO_MACH_NOTIFY_PORT_DESTROYED] == NULL) {
		return 0;
	}

	do_mach_notify_port_destroyed_type
		do_mach_port_notify_port_destroyed_routine =
			routines[DO_MACH_NOTIFY_PORT_DESTROYED];

	return do_mach_port_notify_port_destroyed_routine(notify, rights);
}

/* do mach notify no senders */

typedef kern_return_t (*do_mach_notify_no_senders_type)(mach_port_t,
		mach_port_mscount_t);

kern_return_t
lisp_S_do_mach_notify_no_senders(mach_port_t notify,
		mach_port_mscount_t mscount)
{
	//fprintf(stderr, "notify: no senders\n");
	if(routines[DO_MACH_NOTIFY_NO_SENDERS] == NULL) {
		return EOPNOTSUPP;
	}

	do_mach_notify_no_senders_type do_mach_notify_no_senders_routine =
		routines[DO_MACH_NOTIFY_NO_SENDERS];

	return do_mach_notify_no_senders_routine(notify, mscount);
}

/* do mach notify send once */

typedef kern_return_t (*do_mach_notify_send_once_type)(mach_port_t);

kern_return_t
lisp_S_do_mach_notify_send_once(mach_port_t notify)
{
	//fprintf(stderr, "notify: send once\n");
	if(routines[DO_MACH_NOTIFY_SEND_ONCE] == NULL) {
		return 0;
	}

	do_mach_notify_send_once_type do_mach_notify_send_once_routine =
		routines[DO_MACH_NOTIFY_SEND_ONCE];

	return do_mach_notify_send_once_routine(notify);
}

/* do mach notify dead name */

typedef kern_return_t (*do_mach_notify_dead_name_type)(mach_port_t,
		mach_port_t);

kern_return_t
lisp_S_do_mach_notify_dead_name(mach_port_t notify,
		mach_port_t name)
{
	//fprintf(stderr, "notify: dead name\n");
	if(routines[DO_MACH_NOTIFY_DEAD_NAME] == NULL) {
		return EOPNOTSUPP;
	}

	do_mach_notify_dead_name_type do_mach_notify_dead_name_routine =
		routines[DO_MACH_NOTIFY_DEAD_NAME];

	return do_mach_notify_dead_name_routine(notify, name);
}

static const char*
routine_to_str(const NotifyRoutine rot)
{
#define RET(val) case val: return #val ;
	switch(rot) {
		RET(DO_MACH_NOTIFY_PORT_DELETED)
		RET(DO_MACH_NOTIFY_MSG_ACCEPTED)
		RET(DO_MACH_NOTIFY_PORT_DESTROYED)
		RET(DO_MACH_NOTIFY_NO_SENDERS)
		RET(DO_MACH_NOTIFY_SEND_ONCE)
		RET(DO_MACH_NOTIFY_DEAD_NAME)
		case _NUMBER_OF_ROUTINES:
		default:
			return "";
	}

#undef RET
}

#include "common.c"

COMMON_FUNCTIONS(notify);