debuggers.hg

annotate tools/libxc/xc_misc.c @ 20945:3c3759296796

libxc: Reorder functions in xc_misc.c to avoid weak symbol problem

Using a function, and then declaring it weak later, has undefined
behaviour:
cc1: warnings being treated as errors
xc_misc.c:388: error: weak declaration of 'xc_map_foreign_bulk'
after first use results in unspecified behavior

So swap the functions xc_map_foreign_pages and xc_map_foreign_bulk.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Feb 04 13:16:39 2010 +0000 (2010-02-04)
parents a7546e45ca83
children 28e5409e3fb3
rev   line source
mjw@1661 1 /******************************************************************************
mjw@1661 2 * xc_misc.c
kaf24@9698 3 *
mjw@1661 4 * Miscellaneous control interface functions.
mjw@1661 5 */
mjw@1661 6
mjw@1661 7 #include "xc_private.h"
kfraser@12313 8 #include <xen/hvm/hvm_op.h>
mjw@1661 9
mjw@1661 10 int xc_readconsolering(int xc_handle,
kaf24@5365 11 char **pbuffer,
kaf24@9698 12 unsigned int *pnr_chars,
keir@16294 13 int clear, int incremental, uint32_t *pindex)
mjw@1661 14 {
mjw@1661 15 int ret;
kfraser@11295 16 DECLARE_SYSCTL;
kaf24@5365 17 char *buffer = *pbuffer;
kaf24@5365 18 unsigned int nr_chars = *pnr_chars;
mjw@1661 19
kfraser@11295 20 sysctl.cmd = XEN_SYSCTL_readconsole;
kfraser@11295 21 set_xen_guest_handle(sysctl.u.readconsole.buffer, buffer);
keir@16294 22 sysctl.u.readconsole.count = nr_chars;
keir@16294 23 sysctl.u.readconsole.clear = clear;
keir@16294 24 sysctl.u.readconsole.incremental = 0;
keir@16294 25 if ( pindex )
keir@16294 26 {
keir@16294 27 sysctl.u.readconsole.index = *pindex;
keir@16294 28 sysctl.u.readconsole.incremental = incremental;
keir@16294 29 }
mjw@1661 30
kfraser@11895 31 if ( (ret = lock_pages(buffer, nr_chars)) != 0 )
mjw@1661 32 return ret;
mjw@1661 33
kfraser@11295 34 if ( (ret = do_sysctl(xc_handle, &sysctl)) == 0 )
keir@16294 35 {
kfraser@11295 36 *pnr_chars = sysctl.u.readconsole.count;
keir@16294 37 if ( pindex )
keir@16294 38 *pindex = sysctl.u.readconsole.index;
keir@16294 39 }
mjw@1661 40
kfraser@11895 41 unlock_pages(buffer, nr_chars);
mjw@1661 42
mjw@1661 43 return ret;
kaf24@9698 44 }
mjw@1661 45
kfraser@14347 46 int xc_send_debug_keys(int xc_handle, char *keys)
kfraser@14347 47 {
kfraser@14347 48 int ret, len = strlen(keys);
kfraser@14347 49 DECLARE_SYSCTL;
kfraser@14347 50
kfraser@14347 51 sysctl.cmd = XEN_SYSCTL_debug_keys;
kfraser@14347 52 set_xen_guest_handle(sysctl.u.debug_keys.keys, keys);
kfraser@14347 53 sysctl.u.debug_keys.nr_keys = len;
kfraser@14347 54
kfraser@14347 55 if ( (ret = lock_pages(keys, len)) != 0 )
kfraser@14347 56 return ret;
kfraser@14347 57
kfraser@14347 58 ret = do_sysctl(xc_handle, &sysctl);
kfraser@14347 59
kfraser@14347 60 unlock_pages(keys, len);
kfraser@14347 61
kfraser@14347 62 return ret;
kfraser@14347 63 }
kfraser@14347 64
mjw@1661 65 int xc_physinfo(int xc_handle,
mjw@1661 66 xc_physinfo_t *put_info)
mjw@1661 67 {
mjw@1661 68 int ret;
kfraser@11295 69 DECLARE_SYSCTL;
kaf24@9698 70
kfraser@11295 71 sysctl.cmd = XEN_SYSCTL_physinfo;
mjw@1661 72
kfraser@15520 73 memcpy(&sysctl.u.physinfo, put_info, sizeof(*put_info));
kfraser@15520 74
kfraser@11295 75 if ( (ret = do_sysctl(xc_handle, &sysctl)) != 0 )
kaf24@2825 76 return ret;
mjw@1661 77
kfraser@11295 78 memcpy(put_info, &sysctl.u.physinfo, sizeof(*put_info));
mjw@1661 79
mjw@1661 80 return 0;
mjw@1661 81 }
mjw@1661 82
mjw@1661 83 int xc_sched_id(int xc_handle,
mjw@1661 84 int *sched_id)
mjw@1661 85 {
mjw@1661 86 int ret;
kfraser@11295 87 DECLARE_SYSCTL;
kaf24@9698 88
kfraser@11295 89 sysctl.cmd = XEN_SYSCTL_sched_id;
kaf24@9698 90
kfraser@11295 91 if ( (ret = do_sysctl(xc_handle, &sysctl)) != 0 )
kaf24@3269 92 return ret;
kaf24@9698 93
kfraser@11295 94 *sched_id = sysctl.u.sched_id.sched_id;
kaf24@9698 95
mjw@1661 96 return 0;
mjw@1661 97 }
mjw@1661 98
keir@20929 99 #if defined(__i386__) || defined(__x86_64__)
keir@20929 100 int xc_mca_op(int xc_handle, struct xen_mc *mc)
keir@20929 101 {
keir@20929 102 int ret = 0;
keir@20929 103 DECLARE_HYPERCALL;
keir@20929 104
keir@20929 105 mc->interface_version = XEN_MCA_INTERFACE_VERSION;
keir@20929 106 if ( lock_pages(mc, sizeof(mc)) )
keir@20929 107 {
keir@20929 108 PERROR("Could not lock xen_mc memory\n");
keir@20929 109 return -EINVAL;
keir@20929 110 }
keir@20929 111
keir@20929 112 hypercall.op = __HYPERVISOR_mca;
keir@20929 113 hypercall.arg[0] = (unsigned long)mc;
keir@20929 114 ret = do_xen_hypercall(xc_handle, &hypercall);
keir@20929 115 unlock_pages(mc, sizeof(mc));
keir@20929 116 return ret;
keir@20929 117 }
keir@20929 118 #endif
keir@20929 119
kaf24@3269 120 int xc_perfc_control(int xc_handle,
emellor@8007 121 uint32_t opcode,
kaf24@10991 122 xc_perfc_desc_t *desc,
kaf24@10991 123 xc_perfc_val_t *val,
kaf24@10991 124 int *nbr_desc,
kaf24@10991 125 int *nbr_val)
kaf24@3269 126 {
kaf24@3269 127 int rc;
kfraser@11295 128 DECLARE_SYSCTL;
kaf24@3269 129
kfraser@11295 130 sysctl.cmd = XEN_SYSCTL_perfc_op;
kfraser@11295 131 sysctl.u.perfc_op.cmd = opcode;
kfraser@11295 132 set_xen_guest_handle(sysctl.u.perfc_op.desc, desc);
kfraser@11295 133 set_xen_guest_handle(sysctl.u.perfc_op.val, val);
kaf24@3269 134
kfraser@11295 135 rc = do_sysctl(xc_handle, &sysctl);
kaf24@3269 136
keir@15469 137 if ( nbr_desc )
kfraser@11295 138 *nbr_desc = sysctl.u.perfc_op.nr_counters;
keir@15469 139 if ( nbr_val )
kfraser@11295 140 *nbr_val = sysctl.u.perfc_op.nr_vals;
kaf24@10991 141
kaf24@10991 142 return rc;
kaf24@3269 143 }
rneugeba@4001 144
keir@20350 145 int xc_lockprof_control(int xc_handle,
keir@20350 146 uint32_t opcode,
keir@20350 147 uint32_t *n_elems,
keir@20350 148 uint64_t *time,
keir@20350 149 xc_lockprof_data_t *data)
keir@20350 150 {
keir@20350 151 int rc;
keir@20350 152 DECLARE_SYSCTL;
keir@20350 153
keir@20350 154 sysctl.cmd = XEN_SYSCTL_lockprof_op;
keir@20350 155 sysctl.u.lockprof_op.cmd = opcode;
keir@20350 156 sysctl.u.lockprof_op.max_elem = n_elems ? *n_elems : 0;
keir@20350 157 set_xen_guest_handle(sysctl.u.lockprof_op.data, data);
keir@20350 158
keir@20350 159 rc = do_sysctl(xc_handle, &sysctl);
keir@20350 160
keir@20350 161 if (n_elems)
keir@20350 162 *n_elems = sysctl.u.lockprof_op.nr_elem;
keir@20350 163 if (time)
keir@20350 164 *time = sysctl.u.lockprof_op.time;
keir@20350 165
keir@20350 166 return rc;
keir@20350 167 }
keir@20350 168
keir@15469 169 int xc_getcpuinfo(int xc_handle, int max_cpus,
keir@15469 170 xc_cpuinfo_t *info, int *nr_cpus)
steven@15465 171 {
keir@15469 172 int rc;
steven@15465 173 DECLARE_SYSCTL;
steven@15465 174
keir@15469 175 sysctl.cmd = XEN_SYSCTL_getcpuinfo;
keir@15469 176 sysctl.u.getcpuinfo.max_cpus = max_cpus;
keir@15469 177 set_xen_guest_handle(sysctl.u.getcpuinfo.info, info);
keir@15469 178
keir@15469 179 if ( (rc = lock_pages(info, max_cpus*sizeof(*info))) != 0 )
keir@15469 180 return rc;
steven@15465 181
keir@15469 182 rc = do_sysctl(xc_handle, &sysctl);
keir@15469 183
keir@15469 184 unlock_pages(info, max_cpus*sizeof(*info));
steven@15465 185
keir@15469 186 if ( nr_cpus )
keir@15469 187 *nr_cpus = sysctl.u.getcpuinfo.nr_cpus;
steven@15465 188
keir@15469 189 return rc;
steven@15465 190 }
steven@15465 191
steven@15465 192
kfraser@12542 193 int xc_hvm_set_pci_intx_level(
kfraser@12542 194 int xc_handle, domid_t dom,
kfraser@12542 195 uint8_t domain, uint8_t bus, uint8_t device, uint8_t intx,
kfraser@12542 196 unsigned int level)
kfraser@12313 197 {
kfraser@12313 198 DECLARE_HYPERCALL;
keir@20887 199 struct xen_hvm_set_pci_intx_level _arg, *arg = &_arg;
kfraser@12313 200 int rc;
kfraser@12313 201
keir@20887 202 if ( (rc = hcall_buf_prep((void **)&arg, sizeof(*arg))) != 0 )
kfraser@12542 203 {
kfraser@12542 204 PERROR("Could not lock memory");
kaf24@13669 205 return rc;
kfraser@12542 206 }
kfraser@12542 207
keir@20887 208 hypercall.op = __HYPERVISOR_hvm_op;
keir@20887 209 hypercall.arg[0] = HVMOP_set_pci_intx_level;
keir@20887 210 hypercall.arg[1] = (unsigned long)arg;
keir@20887 211
keir@20887 212 arg->domid = dom;
keir@20887 213 arg->domain = domain;
keir@20887 214 arg->bus = bus;
keir@20887 215 arg->device = device;
keir@20887 216 arg->intx = intx;
keir@20887 217 arg->level = level;
keir@20887 218
kfraser@12542 219 rc = do_xen_hypercall(xc_handle, &hypercall);
kfraser@12542 220
keir@20887 221 hcall_buf_release((void **)&arg, sizeof(*arg));
kfraser@12542 222
kfraser@12542 223 return rc;
kfraser@12542 224 }
kfraser@12542 225
kfraser@12542 226 int xc_hvm_set_isa_irq_level(
kfraser@12542 227 int xc_handle, domid_t dom,
kfraser@12542 228 uint8_t isa_irq,
kfraser@12542 229 unsigned int level)
kfraser@12542 230 {
kfraser@12542 231 DECLARE_HYPERCALL;
keir@20887 232 struct xen_hvm_set_isa_irq_level _arg, *arg = &_arg;
kfraser@12542 233 int rc;
kfraser@12542 234
keir@20887 235 if ( (rc = hcall_buf_prep((void **)&arg, sizeof(*arg))) != 0 )
kfraser@12542 236 {
kfraser@12542 237 PERROR("Could not lock memory");
kaf24@13669 238 return rc;
kfraser@12542 239 }
kfraser@12542 240
keir@20887 241 hypercall.op = __HYPERVISOR_hvm_op;
keir@20887 242 hypercall.arg[0] = HVMOP_set_isa_irq_level;
keir@20887 243 hypercall.arg[1] = (unsigned long)arg;
keir@20887 244
keir@20887 245 arg->domid = dom;
keir@20887 246 arg->isa_irq = isa_irq;
keir@20887 247 arg->level = level;
keir@20887 248
kfraser@12542 249 rc = do_xen_hypercall(xc_handle, &hypercall);
kfraser@12542 250
keir@20887 251 hcall_buf_release((void **)&arg, sizeof(*arg));
kfraser@12542 252
kfraser@12542 253 return rc;
kfraser@12542 254 }
kfraser@12542 255
kfraser@12542 256 int xc_hvm_set_pci_link_route(
kfraser@12542 257 int xc_handle, domid_t dom, uint8_t link, uint8_t isa_irq)
kfraser@12542 258 {
kfraser@12542 259 DECLARE_HYPERCALL;
kfraser@12542 260 struct xen_hvm_set_pci_link_route arg;
kfraser@12542 261 int rc;
kfraser@12542 262
kfraser@12542 263 hypercall.op = __HYPERVISOR_hvm_op;
kfraser@12542 264 hypercall.arg[0] = HVMOP_set_pci_link_route;
kfraser@12542 265 hypercall.arg[1] = (unsigned long)&arg;
kfraser@12542 266
kfraser@12542 267 arg.domid = dom;
kfraser@12542 268 arg.link = link;
kfraser@12542 269 arg.isa_irq = isa_irq;
kfraser@12313 270
kaf24@13669 271 if ( (rc = lock_pages(&arg, sizeof(arg))) != 0 )
kfraser@12313 272 {
kfraser@12313 273 PERROR("Could not lock memory");
kaf24@13669 274 return rc;
kfraser@12313 275 }
kfraser@12313 276
kfraser@12313 277 rc = do_xen_hypercall(xc_handle, &hypercall);
kfraser@12313 278
kaf24@13669 279 unlock_pages(&arg, sizeof(arg));
kfraser@12313 280
kfraser@12313 281 return rc;
kfraser@12313 282 }
kfraser@12313 283
keir@17602 284 int xc_hvm_track_dirty_vram(
keir@17602 285 int xc_handle, domid_t dom,
keir@17602 286 uint64_t first_pfn, uint64_t nr,
keir@17602 287 unsigned long *dirty_bitmap)
keir@17602 288 {
keir@17602 289 DECLARE_HYPERCALL;
keir@17602 290 struct xen_hvm_track_dirty_vram arg;
keir@17602 291 int rc;
keir@17602 292
keir@17602 293 hypercall.op = __HYPERVISOR_hvm_op;
keir@17602 294 hypercall.arg[0] = HVMOP_track_dirty_vram;
keir@17602 295 hypercall.arg[1] = (unsigned long)&arg;
keir@17602 296
keir@17602 297 arg.domid = dom;
keir@17602 298 arg.first_pfn = first_pfn;
keir@17602 299 arg.nr = nr;
keir@17602 300 set_xen_guest_handle(arg.dirty_bitmap, (uint8_t *)dirty_bitmap);
keir@17602 301
keir@17602 302 if ( (rc = lock_pages(&arg, sizeof(arg))) != 0 )
keir@17602 303 {
keir@17602 304 PERROR("Could not lock memory");
keir@17602 305 return rc;
keir@17602 306 }
keir@17602 307
keir@17602 308 rc = do_xen_hypercall(xc_handle, &hypercall);
keir@17602 309
keir@17602 310 unlock_pages(&arg, sizeof(arg));
keir@17602 311
keir@17602 312 return rc;
keir@17602 313 }
keir@17602 314
keir@17949 315 int xc_hvm_modified_memory(
keir@17949 316 int xc_handle, domid_t dom, uint64_t first_pfn, uint64_t nr)
keir@17949 317 {
keir@17949 318 DECLARE_HYPERCALL;
keir@17949 319 struct xen_hvm_modified_memory arg;
keir@17949 320 int rc;
keir@17949 321
keir@17949 322 hypercall.op = __HYPERVISOR_hvm_op;
keir@17949 323 hypercall.arg[0] = HVMOP_modified_memory;
keir@17949 324 hypercall.arg[1] = (unsigned long)&arg;
keir@17949 325
keir@17949 326 arg.domid = dom;
keir@17949 327 arg.first_pfn = first_pfn;
keir@17949 328 arg.nr = nr;
keir@17949 329
keir@17949 330 if ( (rc = lock_pages(&arg, sizeof(arg))) != 0 )
keir@17949 331 {
keir@17949 332 PERROR("Could not lock memory");
keir@17949 333 return rc;
keir@17949 334 }
keir@17949 335
keir@17949 336 rc = do_xen_hypercall(xc_handle, &hypercall);
keir@17949 337
keir@17949 338 unlock_pages(&arg, sizeof(arg));
keir@17949 339
keir@17949 340 return rc;
keir@17949 341 }
keir@17949 342
keir@18059 343 int xc_hvm_set_mem_type(
keir@18059 344 int xc_handle, domid_t dom, hvmmem_type_t mem_type, uint64_t first_pfn, uint64_t nr)
keir@18059 345 {
keir@18059 346 DECLARE_HYPERCALL;
keir@18059 347 struct xen_hvm_set_mem_type arg;
keir@18059 348 int rc;
keir@18059 349
keir@18059 350 hypercall.op = __HYPERVISOR_hvm_op;
keir@18059 351 hypercall.arg[0] = HVMOP_set_mem_type;
keir@18059 352 hypercall.arg[1] = (unsigned long)&arg;
keir@18059 353
keir@18059 354 arg.domid = dom;
keir@18059 355 arg.hvmmem_type = mem_type;
keir@18059 356 arg.first_pfn = first_pfn;
keir@18059 357 arg.nr = nr;
keir@18059 358
keir@18059 359 if ( (rc = lock_pages(&arg, sizeof(arg))) != 0 )
keir@18059 360 {
keir@18059 361 PERROR("Could not lock memory");
keir@18059 362 return rc;
keir@18059 363 }
keir@18059 364
keir@18059 365 rc = do_xen_hypercall(xc_handle, &hypercall);
keir@18059 366
keir@18059 367 unlock_pages(&arg, sizeof(arg));
keir@18059 368
keir@18059 369 return rc;
keir@18059 370 }
keir@18059 371
keir@18059 372
keir@20837 373 /* stub for all not yet converted OSes */
keir@20837 374 void *
keir@20837 375 #ifdef __GNUC__
keir@20837 376 __attribute__((__weak__))
keir@20837 377 #endif
keir@20837 378 xc_map_foreign_bulk(int xc_handle, uint32_t dom, int prot,
keir@20837 379 const xen_pfn_t *arr, int *err, unsigned int num)
keir@20837 380 {
keir@20837 381 xen_pfn_t *pfn;
keir@20837 382 unsigned int i;
keir@20837 383 void *ret;
keir@20837 384
keir@20837 385 if ((int)num <= 0) {
keir@20837 386 errno = EINVAL;
keir@20837 387 return NULL;
keir@20837 388 }
keir@20837 389
keir@20888 390 pfn = malloc(num * sizeof(*pfn));
keir@20837 391 if (!pfn) {
keir@20837 392 errno = ENOMEM;
keir@20837 393 return NULL;
keir@20837 394 }
keir@20837 395
keir@20837 396 memcpy(pfn, arr, num * sizeof(*arr));
keir@20837 397 ret = xc_map_foreign_batch(xc_handle, dom, prot, pfn, num);
keir@20837 398
keir@20837 399 if (ret) {
keir@20837 400 for (i = 0; i < num; ++i)
keir@20837 401 switch (pfn[i] ^ arr[i]) {
keir@20837 402 case 0:
keir@20837 403 err[i] = 0;
keir@20837 404 break;
keir@20837 405 default:
keir@20837 406 err[i] = -EINVAL;
keir@20837 407 break;
keir@20837 408 }
keir@20888 409 } else
keir@20888 410 memset(err, 0, num * sizeof(*err));
keir@20837 411
kfraser@15875 412 free(pfn);
keir@20837 413
keir@20837 414 return ret;
kfraser@15875 415 }
kfraser@15875 416
keir@20945 417 void *xc_map_foreign_pages(int xc_handle, uint32_t dom, int prot,
keir@20945 418 const xen_pfn_t *arr, int num)
keir@20945 419 {
keir@20945 420 void *res;
keir@20945 421 int i, *err;
keir@20945 422
keir@20945 423 if (num < 0) {
keir@20945 424 errno = -EINVAL;
keir@20945 425 return NULL;
keir@20945 426 }
keir@20945 427
keir@20945 428 err = malloc(num * sizeof(*err));
keir@20945 429 if (!err)
keir@20945 430 return NULL;
keir@20945 431
keir@20945 432 res = xc_map_foreign_bulk(xc_handle, dom, prot, arr, err, num);
keir@20945 433 if (res) {
keir@20945 434 for (i = 0; i < num; i++) {
keir@20945 435 if (err[i]) {
keir@20945 436 errno = -err[i];
keir@20945 437 munmap(res, num * PAGE_SIZE);
keir@20945 438 res = NULL;
keir@20945 439 break;
keir@20945 440 }
keir@20945 441 }
keir@20945 442 }
keir@20945 443
keir@20945 444 free(err);
keir@20945 445 return res;
keir@20945 446 }
keir@20945 447
kaf24@6944 448 /*
kaf24@6944 449 * Local variables:
kaf24@6944 450 * mode: C
kaf24@6944 451 * c-set-style: "BSD"
kaf24@6944 452 * c-basic-offset: 4
kaf24@6944 453 * tab-width: 4
kaf24@6944 454 * indent-tabs-mode: nil
kaf24@6944 455 * End:
kaf24@6944 456 */