hc
2024-11-01 2f529f9b558ca1c1bd74be7437a84e4711743404
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
/*
 * Copyright (C) 2013 Philippe Gerum <rpm@xenomai.org>.
 *
 * This program 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 of the
 * License, or (at your option) any later version.
 *
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
#ifndef _COBALT_POSIX_EXTENSION_H
#define _COBALT_POSIX_EXTENSION_H
 
#include <linux/time.h>
#include <linux/list.h>
 
#ifdef CONFIG_XENO_OPT_COBALT_EXTENSION
 
#include <cobalt/kernel/thread.h>
 
struct cobalt_timer;
struct cobalt_sigpending;
struct cobalt_extref;
struct siginfo;
struct xnsched_class;
union xnsched_policy_param;
 
struct cobalt_extension {
   struct xnthread_personality core;
   struct {
       struct cobalt_thread *
       (*timer_init)(struct cobalt_extref *reftimer, /* nklocked, IRQs off. */
                 const struct sigevent *__restrict__ evp);
       int (*timer_settime)(struct cobalt_extref *reftimer, /* nklocked, IRQs off. */
                    const struct itimerspec64 *__restrict__ value,
                    int flags);
       int (*timer_gettime)(struct cobalt_extref *reftimer, /* nklocked, IRQs off. */
                    struct itimerspec64 *__restrict__ value);
       int (*timer_delete)(struct cobalt_extref *reftimer); /* nklocked, IRQs off. */
       int (*timer_cleanup)(struct cobalt_extref *reftimer); /* nklocked, IRQs off. */
       int (*signal_deliver)(struct cobalt_extref *refthread,
                     struct siginfo *si,
                     struct cobalt_sigpending *sigp);
       int (*signal_queue)(struct cobalt_extref *refthread,
                   struct cobalt_sigpending *sigp);
       int (*signal_copyinfo)(struct cobalt_extref *refthread,
                      void __user *u_si,
                      const struct siginfo *si,
                      int overrun);
       int (*signal_copyinfo_compat)(struct cobalt_extref *refthread,
                         void __user *u_si,
                         const struct siginfo *si,
                         int overrun);
       int (*sched_yield)(struct cobalt_extref *curref);
       int (*thread_setsched)(struct cobalt_extref *refthread, /* nklocked, IRQs off. */
                      struct xnsched_class *sched_class,
                      union xnsched_policy_param *param);
   } ops;
};
 
struct cobalt_extref {
   struct cobalt_extension *extension;
   struct list_head next;
   void *private;
};
 
static inline void cobalt_set_extref(struct cobalt_extref *ref,
                    struct cobalt_extension *ext,
                    void *priv)
{
   ref->extension = ext;
   ref->private = priv;
}
 
/**
 * All macros return non-zero if some thread-level extension code was
 * called, leaving the output value into __ret. Otherwise, the __ret
 * value is undefined.
 */
#define cobalt_initcall_extension(__extfn, __extref, __owner, __ret, __args...) \
   ({                                    \
       int __val = 0;                            \
       if ((__owner) && (__owner)->extref.extension) {            \
           (__extref)->extension = (__owner)->extref.extension;    \
           if ((__extref)->extension->ops.__extfn) {        \
               (__ret) = (__extref)->extension->ops.        \
                   __extfn(__extref, ##__args );        \
               __val = 1;                    \
           }                            \
       } else                                \
           (__extref)->extension = NULL;                \
       __val;                                \
   })
       
#define cobalt_call_extension(__extfn, __extref, __ret, __args...)    \
   ({                                \
       int __val = 0;                        \
       if ((__extref)->extension &&                \
           (__extref)->extension->ops.__extfn) {        \
           (__ret) = (__extref)->extension->ops.        \
               __extfn(__extref, ##__args );        \
           __val = 1;                    \
       }                            \
       __val;                            \
   })
 
#else /* !CONFIG_XENO_OPT_COBALT_EXTENSION */
 
struct cobalt_extension;
 
struct cobalt_extref {
};
 
static inline void cobalt_set_extref(struct cobalt_extref *ref,
                    struct cobalt_extension *ext,
                    void *priv)
{
}
 
#define cobalt_initcall_extension(__extfn, __extref, __owner, __ret, __args...)    \
   ({ (void)(__owner); (void)(__ret); 0; })
 
#define cobalt_call_extension(__extfn, __extref, __ret, __args...)    \
   ({ (void)(__ret); 0; })
 
#endif /* !CONFIG_XENO_OPT_COBALT_EXTENSION */
 
#endif /* !_COBALT_POSIX_EXTENSION_H */