aboutsummaryrefslogtreecommitdiffstats
path: root/tools/libxc/xenctrl_osdep_ENOSYS.c
blob: 4821342a484f0a1ed4f2e1412b0e1532c67a9ba8 (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
/* Dummy backend which just logs and returns ENOSYS. */

#include <errno.h>
#include <inttypes.h>
#include <stdlib.h>

#include "xenctrl.h"
#include "xenctrlosdep.h"

#define IPRINTF(_x, _f, _a...) xc_osdep_log(_x,XTL_INFO,0, _f , ## _a)

#define ERROR(_x, _m, _a...)  xc_osdep_log(_x,XTL_ERROR,XC_INTERNAL_ERROR,_m , ## _a )
#define PERROR(_x, _m, _a...) xc_osdep_log(_x,XTL_ERROR,XC_INTERNAL_ERROR,_m \
                  " (%d = %s)", ## _a , errno, xc_strerror(xch, errno))

static xc_osdep_handle ENOSYS_privcmd_open(xc_interface *xch)
{
    IPRINTF(xch, "ENOSYS_privcmd: opening handle %p\n", (void *)1);
    return (xc_osdep_handle)1; /*dummy*/
}

static int ENOSYS_privcmd_close(xc_interface *xch, xc_osdep_handle h)
{
    IPRINTF(xch, "ENOSYS_privcmd: closing handle %p\n", h);
    return 0;
}

static int ENOSYS_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall)
{
    IPRINTF(xch, "ENOSYS_privcmd %p: hypercall: %02lld(%#llx,%#llx,%#llx,%#llx,%#llx)\n",
            h, hypercall->op,
            hypercall->arg[0], hypercall->arg[1], hypercall->arg[2],
            hypercall->arg[3], hypercall->arg[4]);
    return -ENOSYS;
}

static void *ENOSYS_privcmd_map_foreign_batch(xc_interface *xch, xc_osdep_handle h, uint32_t dom, int prot,
                                      xen_pfn_t *arr, int num)
{
    IPRINTF(xch, "ENOSYS_privcmd %p: map_foreign_batch: dom%d prot %#x arr %p num %d\n", h, dom, prot, arr, num);
    return MAP_FAILED;
}

static void *ENOSYS_privcmd_map_foreign_bulk(xc_interface *xch, xc_osdep_handle h, uint32_t dom, int prot,
                                     const xen_pfn_t *arr, int *err, unsigned int num)
{
    IPRINTF(xch, "ENOSYS_privcmd %p: map_foreign_buld: dom%d prot %#x arr %p err %p num %d\n", h, dom, prot, arr, err, num);
    return MAP_FAILED;
}

static void *ENOSYS_privcmd_map_foreign_range(xc_interface *xch, xc_osdep_handle h, uint32_t dom, int size, int prot,
                                      unsigned long mfn)
{
    IPRINTF(xch, "ENOSYS_privcmd %p: map_foreign_range: dom%d size %#x prot %#x mfn %ld\n", h, dom, size, prot, mfn);
    return MAP_FAILED;
}

static void *ENOSYS_privcmd_map_foreign_ranges(xc_interface *xch, xc_osdep_handle h, uint32_t dom, size_t size, int prot,
                                       size_t chunksize, privcmd_mmap_entry_t entries[],
                                       int nentries)
{
    IPRINTF(xch, "ENOSYS_privcmd %p: map_foreign_ranges: dom%d size %zd prot %#x chunksize %zd entries %p num %d\n", h, dom, size, prot, chunksize, entries, nentries);
    return MAP_FAILED;
}

static struct xc_osdep_ops ENOSYS_privcmd_ops =
{
    .open      = &ENOSYS_privcmd_open,
    .close     = &ENOSYS_privcmd_close,
    .u.privcmd   = {
        .hypercall = &ENOSYS_privcmd_hypercall,

        .map_foreign_batch = &ENOSYS_privcmd_map_foreign_batch,
        .map_foreign_bulk = &ENOSYS_privcmd_map_foreign_bulk,
        .map_foreign_range = &ENOSYS_privcmd_map_foreign_range,
        .map_foreign_ranges = &ENOSYS_privcmd_map_foreign_ranges,
    }
};

static xc_osdep_handle ENOSYS_evtchn_open(xc_interface *xce)
{
    IPRINTF(xce, "ENOSYS_evtchn: opening handle %p\n", (void *)1);
    return (xc_osdep_handle)2; /*dummy*/
}

static int ENOSYS_evtchn_close(xc_interface *xce, xc_osdep_handle h)
{
    IPRINTF(xce, "ENOSYS_evtchn: closing handle %p\n", h);
    return 0;
}

static int ENOSYS_evtchn_fd(xc_interface *xce, xc_osdep_handle h)
{
    IPRINTF(xce, "ENOSYS_fd %p: fd\n", h);
    return (int)h;
}

static int ENOSYS_evtchn_notify(xc_interface *xce, xc_osdep_handle h, evtchn_port_t port)
{
    IPRINTF(xce, "ENOSYS_evtchn %p: notify: %d\n", h, port);
    return -ENOSYS;
}

static int ENOSYS_evtchn_bind_unbound_port(xc_interface *xce, xc_osdep_handle h, int domid)
{
    IPRINTF(xce, "ENOSYS_evtchn %p: bind_unbound_port: dom%d\n", h, domid);
    return -ENOSYS;
}


static int ENOSYS_evtchn_bind_interdomain(xc_interface *xce, xc_osdep_handle h, int domid, evtchn_port_t remote_port)
{
    IPRINTF(xce, "ENOSYS_evtchn %p: bind_interdomain: dmo%d %d\n", h, domid, remote_port);
    return -ENOSYS;
}


static int ENOSYS_evtchn_bind_virq(xc_interface *xce, xc_osdep_handle h, unsigned int virq)
{
    IPRINTF(xce, "ENOSYS_evtchn %p: bind_virq: %d\n", h, virq);
    return -ENOSYS;
}


static int ENOSYS_evtchn_unbind(xc_interface *xce, xc_osdep_handle h, evtchn_port_t port)
{
    IPRINTF(xce, "ENOSYS_evtchn %p: unbind: %d\n", h, port);
    return -ENOSYS;
}


static evtchn_port_or_error_t ENOSYS_evtchn_pending(xc_interface *xce, xc_osdep_handle h)
{
    IPRINTF(xce, "ENOSYS_evtchn %p: pending\n", h);
    return -ENOSYS;
}

static int ENOSYS_evtchn_unmask(xc_interface *xce, xc_osdep_handle h, evtchn_port_t port)
{
    IPRINTF(xce, "ENOSYS_evtchn %p: unmask: %d\n", h, port);
    return -ENOSYS;
}

static struct xc_osdep_ops ENOSYS_evtchn_ops = {
    .open = &ENOSYS_evtchn_open,
    .close = &ENOSYS_evtchn_close,

    .u.evtchn = {
        .fd = &ENOSYS_evtchn_fd,

        .notify = &ENOSYS_evtchn_notify,

        .bind_unbound_port = &ENOSYS_evtchn_bind_unbound_port,
        .bind_interdomain = &ENOSYS_evtchn_bind_interdomain,
        .bind_virq = &ENOSYS_evtchn_bind_virq,

        .unbind = &ENOSYS_evtchn_unbind,

        .pending = &ENOSYS_evtchn_pending,
        .unmask = &ENOSYS_evtchn_unmask,
    },
};

static struct xc_osdep_ops * ENOSYS_osdep_init(xc_interface *xch, enum xc_osdep_type type)
{
    struct xc_osdep_ops *ops;

    if (getenv("ENOSYS") == NULL)
    {
        PERROR(xch, "ENOSYS: not configured\n");
        return NULL;
    }

    switch ( type )
    {
    case XC_OSDEP_PRIVCMD:
        ops = &ENOSYS_privcmd_ops;
        break;
    case XC_OSDEP_EVTCHN:
        ops = &ENOSYS_evtchn_ops;
        break;
    default:
        ops = NULL;
        break;
    }

    IPRINTF(xch, "ENOSYS_osdep_init: initialising handle ops at %p\n", ops);

    return ops;
}

xc_osdep_info_t xc_osdep_info = {
    .name = "Pessimistic ENOSYS OS interface",
    .init = &ENOSYS_osdep_init,
    .fake = 1,
};

/*
 * Local variables:
 * mode: C
 * c-file-style: "BSD"
 * c-basic-offset: 4
 * tab-width: 4
 * indent-tabs-mode: nil
 * End:
 */