summaryrefslogtreecommitdiff
path: root/debian/patches/notify-fix-receiver-lookups.patch
blob: 1632be397a0f8d8b22f595926bac05bd54496e79 (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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
commit e9687ec4ff525ae4a88314ba4ae97da770bd012f
Author: Justus Winter <4winter@informatik.uni-hamburg.de>
Date:   Sat Apr 5 17:40:24 2014 +0200

    libports: fix notify_port_t receiver lookups
    
    * libports/Makefile (MIGSFLAGS): Include mig-mutate.h.
    * libports/mig-decls.h: New file.
    * libports/mig-mutate.h: Likewise.
    * libports/notify-dead-name.c: Fix receiver lookups.
    * libports/notify-no-senders.c: Likewise.
    * libports/notify-msg-accepted.c: Adjust function declaration.
    * libports/notify-port-deleted.c: Likewise.
    * libports/notify-port-destroyed.c: Likewise.
    * libports/notify-send-once.c: Likewise.
    * libports/ports.h: Likewise.
    * proc/Makefile (MIGSFLAGS): Include mig-mutate.h, move PROCESS mutators...
    * proc/mig-mutate.h: ... into a new file, add NOTIFY mutators.
    * proc/notify.c: Fix receiver lookups, adjust function declarations.
    * term/devio.c (ports_do_mach_notify_send_once): Adjust accordingly.

diff --git a/libports/Makefile b/libports/Makefile
index 767ee73..30da1c1 100644
--- a/libports/Makefile
+++ b/libports/Makefile
@@ -45,5 +45,6 @@ LDLIBS += -lpthread
 OBJS = $(SRCS:.c=.o) notifyServer.o interruptServer.o
 
 MIGCOMSFLAGS = -prefix ports_
+MIGSFLAGS = -imacros $(srcdir)/mig-mutate.h
 
 include ../Makeconf
diff --git a/libports/mig-decls.h b/libports/mig-decls.h
new file mode 100644
index 0000000..f8c4f15
--- /dev/null
+++ b/libports/mig-decls.h
@@ -0,0 +1,40 @@
+/*
+   Copyright (C) 2014 Free Software Foundation, Inc.
+   Written by Justus Winter.
+
+   This file is part of the GNU Hurd.
+
+   The 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 2, or (at
+   your option) any later version.
+
+   The 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 the GNU Hurd.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef __LIBPORTS_MIG_DECLS_H__
+#define __LIBPORTS_MIG_DECLS_H__
+
+#include "ports.h"
+
+/* Called by server stub functions.  */
+
+static inline struct port_info * __attribute__ ((unused))
+begin_using_port_info_port (mach_port_t port)
+{
+  return ports_lookup_port (0, port, 0);
+}
+
+static inline void __attribute__ ((unused))
+end_using_port_info (struct port_info *p)
+{
+  if (p)
+    ports_port_deref (p);
+}
+
+#endif /* __LIBPORTS_MIG_DECLS_H__ */
diff --git a/libports/mig-mutate.h b/libports/mig-mutate.h
new file mode 100644
index 0000000..f692236
--- /dev/null
+++ b/libports/mig-mutate.h
@@ -0,0 +1,25 @@
+/*
+   Copyright (C) 2014 Free Software Foundation, Inc.
+   Written by Justus Winter.
+
+   This file is part of the GNU Hurd.
+
+   The 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 2, or (at
+   your option) any later version.
+
+   The 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 the GNU Hurd.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#define NOTIFY_INTRAN						\
+  port_info_t begin_using_port_info_port (mach_port_t)
+#define NOTIFY_DESTRUCTOR					\
+  end_using_port_info (port_info_t)
+#define NOTIFY_IMPORTS						\
+  import "libports/mig-decls.h";
diff --git a/libports/notify-dead-name.c b/libports/notify-dead-name.c
index c67145d..f974e33 100644
--- a/libports/notify-dead-name.c
+++ b/libports/notify-dead-name.c
@@ -22,13 +22,12 @@
 #include "notify_S.h"
 
 error_t
-ports_do_mach_notify_dead_name (mach_port_t notify, mach_port_t dead_name)
+ports_do_mach_notify_dead_name (struct port_info *pi,
+				mach_port_t dead_name)
 {
-  void *pi = ports_lookup_port (0, notify, 0);
   if (!pi)
     return EOPNOTSUPP;
   ports_dead_name (pi, dead_name);
-  ports_port_deref (pi);
 
   /* Drop gratuitous extra reference that the notification creates. */
   mach_port_deallocate (mach_task_self (), dead_name);
diff --git a/libports/notify-msg-accepted.c b/libports/notify-msg-accepted.c
index c975083..0e49715 100644
--- a/libports/notify-msg-accepted.c
+++ b/libports/notify-msg-accepted.c
@@ -22,7 +22,8 @@
 #include "notify_S.h"
 
 error_t
-ports_do_mach_notify_msg_accepted (mach_port_t notify, mach_port_t name)
+ports_do_mach_notify_msg_accepted (struct port_info *pi,
+				   mach_port_t name)
 {
   return 0;
 }
diff --git a/libports/notify-no-senders.c b/libports/notify-no-senders.c
index dc9b316..55aa853 100644
--- a/libports/notify-no-senders.c
+++ b/libports/notify-no-senders.c
@@ -22,12 +22,11 @@
 #include "notify_S.h"
 
 error_t
-ports_do_mach_notify_no_senders (mach_port_t port, mach_port_mscount_t count)
+ports_do_mach_notify_no_senders (struct port_info *pi,
+				 mach_port_mscount_t count)
 {
-  void *pi = ports_lookup_port (0, port, 0);
   if (!pi)
     return EOPNOTSUPP;
   ports_no_senders (pi, count);
-  ports_port_deref (pi);
   return 0;
 }
diff --git a/libports/notify-port-deleted.c b/libports/notify-port-deleted.c
index 85012af..cfd3379 100644
--- a/libports/notify-port-deleted.c
+++ b/libports/notify-port-deleted.c
@@ -22,7 +22,8 @@
 #include "notify_S.h"
 
 error_t
-ports_do_mach_notify_port_deleted (mach_port_t notify, mach_port_t name)
+ports_do_mach_notify_port_deleted (struct port_info *pi,
+				   mach_port_t name)
 {
   return 0;
 }
diff --git a/libports/notify-port-destroyed.c b/libports/notify-port-destroyed.c
index 78eaf21..b8ece2a 100644
--- a/libports/notify-port-destroyed.c
+++ b/libports/notify-port-destroyed.c
@@ -22,7 +22,8 @@
 #include "notify_S.h"
 
 error_t
-ports_do_mach_notify_port_destroyed (mach_port_t notify, mach_port_t name)
+ports_do_mach_notify_port_destroyed (struct port_info *pi,
+				     mach_port_t name)
 {
   return 0;
 }
diff --git a/libports/notify-send-once.c b/libports/notify-send-once.c
index 09ffcf2..ad0ba33 100644
--- a/libports/notify-send-once.c
+++ b/libports/notify-send-once.c
@@ -22,7 +22,7 @@
 #include "notify_S.h"
 
 error_t
-ports_do_mach_notify_send_once (mach_port_t notify)
+ports_do_mach_notify_send_once (struct port_info *pi)
 {
   return 0;
 }
diff --git a/libports/ports.h b/libports/ports.h
index 0791841..47d4607 100644
--- a/libports/ports.h
+++ b/libports/ports.h
@@ -50,6 +50,8 @@ struct port_info
   hurd_ihash_locp_t hentry;
   struct port_info *next, **prevp; /* links on port_class list */
 };
+typedef struct port_info *port_info_t;
+
 /* FLAGS above are the following: */
 #define PORT_HAS_SENDRIGHTS	0x0001 /* send rights extant */
 #define PORT_INHIBITED		PORTS_INHIBITED
@@ -383,13 +385,19 @@ void ports_interrupt_notified_rpcs (void *object, mach_port_t port,
 int ports_notify_server (mach_msg_header_t *, mach_msg_header_t *);
 
 /* Notification server routines called by ports_notify_server.  */
-extern kern_return_t ports_do_mach_notify_dead_name (mach_port_t notify, mach_port_t deadport);
-extern kern_return_t ports_do_mach_notify_msg_accepted (mach_port_t notify, mach_port_t name);
-extern kern_return_t ports_do_mach_notify_no_senders (mach_port_t port, mach_port_mscount_t count);
-extern kern_return_t ports_do_mach_notify_port_deleted (mach_port_t notify, mach_port_t name);
-extern kern_return_t ports_do_mach_notify_port_destroyed (mach_port_t notify, mach_port_t name);
 extern kern_return_t
- ports_do_mach_notify_send_once (mach_port_t notify);
+ ports_do_mach_notify_dead_name (struct port_info *pi, mach_port_t deadport);
+extern kern_return_t
+ ports_do_mach_notify_msg_accepted (struct port_info *pi, mach_port_t name);
+extern kern_return_t
+ ports_do_mach_notify_no_senders (struct port_info *pi,
+				  mach_port_mscount_t count);
+extern kern_return_t
+ ports_do_mach_notify_port_deleted (struct port_info *pi, mach_port_t name);
+extern kern_return_t
+ ports_do_mach_notify_port_destroyed (struct port_info *pi, mach_port_t name);
+extern kern_return_t
+ ports_do_mach_notify_send_once (struct port_info *pi);
 
 /* A default interrupt server */
 int ports_interrupt_server (mach_msg_header_t *, mach_msg_header_t *);
diff --git a/proc/Makefile b/proc/Makefile
index 2eed13c..aa31ffb 100644
--- a/proc/Makefile
+++ b/proc/Makefile
@@ -24,9 +24,7 @@ target = proc
 SRCS = wait.c hash.c host.c info.c main.c mgt.c	notify.c pgrp.c msg.c \
        cpu-types.c stubs.c
 
-MIGSFLAGS="-DPROCESS_INTRAN=pstruct_t reqport_find (process_t)" \
-	"-DPROCESS_DESTRUCTOR=process_drop (pstruct_t)" \
-	"-DPROCESS_IMPORTS=import \"proc.h\";"
+MIGSFLAGS = -imacros $(srcdir)/mig-mutate.h
 
 MIGSTUBS = processServer.o notifyServer.o \
 	ourmsgUser.o proc_excUser.o proc_excServer.o
diff --git a/proc/mig-mutate.h b/proc/mig-mutate.h
new file mode 100644
index 0000000..ad6eb32
--- /dev/null
+++ b/proc/mig-mutate.h
@@ -0,0 +1,33 @@
+/*
+   Copyright (C) 2014 Free Software Foundation, Inc.
+   Written by Justus Winter.
+
+   This file is part of the GNU Hurd.
+
+   The 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 2, or (at
+   your option) any later version.
+
+   The 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 the GNU Hurd.  If not, see <http://www.gnu.org/licenses/>.  */
+
+
+#define PROCESS_INTRAN						\
+  pstruct_t reqport_find (process_t)
+#define PROCESS_DESTRUCTOR					\
+  process_drop (pstruct_t)
+#define PROCESS_IMPORTS						\
+  import "proc.h";
+
+#define NOTIFY_INTRAN						\
+  port_info_t begin_using_port_info_port (mach_port_t)
+#define NOTIFY_DESTRUCTOR					\
+  end_using_port_info (port_info_t)
+#define NOTIFY_IMPORTS						\
+  import "libports/mig-decls.h";
diff --git a/proc/notify.c b/proc/notify.c
index 5a112b0..b6731ae 100644
--- a/proc/notify.c
+++ b/proc/notify.c
@@ -36,33 +36,33 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
    message ports die.  Both notifications get sent to the process
    port.   */
 kern_return_t
-do_mach_notify_dead_name (mach_port_t notify,
+do_mach_notify_dead_name (struct port_info *pi,
 			  mach_port_t deadport)
 {
   struct proc *p;
 
-  if (notify == generic_port)
+  if (pi->port_right == generic_port)
     {
       check_dead_execdata_notify (deadport);
       mach_port_deallocate (mach_task_self (), deadport);
       return 0;
     }
 
-  p = ports_lookup_port (proc_bucket, notify, proc_class);
+  p = (struct proc *) pi;
 
-  if (!p)
+  if (!p
+      || p->p_pi.bucket != proc_bucket
+      || p->p_pi.class != proc_class)
     return EOPNOTSUPP;
 
   if (p->p_task == deadport)
     {
       process_has_exited (p);
-      ports_port_deref (p);
       mach_port_deallocate (mach_task_self (), deadport);
       return 0;
     }
   else
     {
-      ports_port_deref (p);
       return EINVAL;
     }
 }
@@ -70,35 +70,35 @@ do_mach_notify_dead_name (mach_port_t notify,
 /* We get no-senders notifications on exception ports that we
    handle through proc_handle_exceptions. */
 kern_return_t
-do_mach_notify_no_senders (mach_port_t notify,
+do_mach_notify_no_senders (struct port_info *pi,
 			   mach_port_mscount_t mscount)
 {
-  return ports_do_mach_notify_no_senders (notify, mscount);
+  return ports_do_mach_notify_no_senders (pi, mscount);
 }
 
 kern_return_t
-do_mach_notify_port_deleted (mach_port_t notify,
+do_mach_notify_port_deleted (struct port_info *pi,
 			     mach_port_t name)
 {
   return 0;
 }
 
 kern_return_t
-do_mach_notify_msg_accepted (mach_port_t notify,
+do_mach_notify_msg_accepted (struct port_info *pi,
 			     mach_port_t name)
 {
   return 0;
 }
 
 kern_return_t
-do_mach_notify_port_destroyed (mach_port_t notify,
+do_mach_notify_port_destroyed (struct port_info *pi,
 			       mach_port_t name)
 {
   return 0;
 }
 
 kern_return_t
-do_mach_notify_send_once (mach_port_t notify)
+do_mach_notify_send_once (struct port_info *pi)
 {
   return 0;
 }
diff --git a/term/devio.c b/term/devio.c
index 7c7d8fd..eedd7b8 100644
--- a/term/devio.c
+++ b/term/devio.c
@@ -731,18 +731,18 @@ device_write_reply (mach_port_t replyport,
 }
 
 error_t
-ports_do_mach_notify_send_once (mach_port_t notify)
+ports_do_mach_notify_send_once (struct port_info *pi)
 {
   error_t err;
 
   pthread_mutex_lock (&global_lock);
 
-  if (notify == phys_reply_writes)
+  if (pi->port_right == phys_reply_writes)
     {
       err = 0;
       devio_start_output ();
     }
-  else if (notify == phys_reply)
+  else if (pi->port_right == phys_reply)
     {
       if (input_pending)
 	{