Remove some really old portability hacks that should no longer be needed.
[dragonfly.git] / test / sysmsg / syscall.h
blobbac09b9e9ccca205c4a51e7f583b19e09eed2b50
1 /*
2 * Copyright (c) 2004 Eirik Nygaard. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. Neither the name of The DragonFly Project nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific, prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
22 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
30 #define __syscall_args nosys_args
32 #include <sys/types.h>
33 #include <sys/msgport.h>
34 #include <sys/syscall.h>
35 #include <sys/sysproto.h>
37 #include <stdlib.h>
38 #include <errno.h>
40 #define INITMSGSYSCALL(name, flags) do { \
41 bzero(&__CONCAT(name, msg), sizeof(__CONCAT(name, msg))); \
42 (__CONCAT(name, msg)).usrmsg.umsg.ms_cmd.cm_op = \
43 (__CONCAT(SYS_,name)); \
44 (__CONCAT(name, msg)).usrmsg.umsg.ms_flags = (flags); \
45 } while (0)
47 #define DOMSGSYSCALL(name) do { \
48 error = sendsys(NULL, &__CONCAT(name,msg).usrmsg, \
49 sizeof(__CONCAT(name,msg))); \
50 } while (0)
52 #define FINISHMSGSYSCALL(name, error) do { \
53 if (__CONCAT(name,msg).usrmsg.umsg.ms_error == EASYNC) { \
54 for (;;) { \
55 int rmsg; \
56 rmsg = waitsys(NULL, (void *)error, 0); \
57 if (error == rmsg) \
58 break; \
59 else if (rmsg != 0) { \
60 errno = rmsg; \
61 return(-1); \
62 } \
63 } \
64 } \
65 if (__CONCAT(name,msg).usrmsg.umsg.ms_error) { \
66 errno = __CONCAT(name,msg).usrmsg.umsg.ms_error; \
67 return(-1); \
68 } \
69 else \
70 return(__CONCAT(name,msg).usrmsg.umsg.u.ms_result); \
71 } while(0)
73 static __inline int
74 sendsys(void *port, void *msg, int msgsize)
76 int error;
78 __asm __volatile("int $0x81" : "=a"(error), "=c"(msg), "=d"(msgsize) :
79 "0"(port), "1"(msg), "2"(msgsize) : "memory");
80 return(error);
83 static __inline int
84 waitsys(void *port, void *msg, int msgsize)
86 int error;
88 __asm __volatile("int $0x82" : "=a"(error), "=c"(msg),
89 "=d"(msgsize) : "0"(port), "1"(msg), "2"(msgsize) :
90 "memory");
91 return(error);