Changeset 7433 in vbox for trunk/src/VBox/Additions/linux/module
- Timestamp:
- Mar 12, 2008 10:41:14 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/linux/module/vboxmod.c
r7233 r7433 20 20 21 21 /* #define IRQ_DEBUG */ 22 // #define IOCTL_DEBUG 23 #ifdef IOCTL_DEBUG 24 # define IOCTL_ENTRY(name, arg) \ 25 do { \ 26 Log(("IOCTL_ENTRY: %s, 0x%x\n", (name), (arg))); \ 27 } while(0) 28 # define IOCTL_EXIT(name, arg) \ 29 do { \ 30 Log(("IOCTL_EXIT: %s, 0x%x\n", (name), (arg))); \ 31 } while(0) 32 #else 33 # define IOCTL_ENTRY(name, arg) do { } while(0) 34 # define IOCTL_EXIT(name, arg) do { } while(0) 35 #endif 36 #ifdef IOCTL_LOG_DEBUG 37 # define IOCTL_LOG_ENTRY(arg) \ 38 do { \ 39 Log(("IOCTL_ENTRY: Log, 0x%x\n", (arg))); \ 40 } while(0) 41 # define IOCTL_LOG_EXIT(arg) \ 42 do { \ 43 Log(("IOCTL_EXIT: Log, 0x%x\n", (arg))); \ 44 } while(0) 45 #else 46 # define IOCTL_LOG_ENTRY(arg) do { } while(0) 47 # define IOCTL_LOG_EXIT(arg) do { } while(0) 48 #endif 49 #ifdef IOCTL_VMM_DEBUG 50 # define IOCTL_VMM_ENTRY(arg) \ 51 do { \ 52 Log(("IOCTL_ENTRY: VMMDevReq, 0x%x\n", (arg))); \ 53 } while(0) 54 # define IOCTL_VMM_EXIT(arg) \ 55 do { \ 56 Log(("IOCTL_EXIT: VMMDevReq, 0x%x\n", (arg))); \ 57 } while(0) 58 #else 59 # define IOCTL_VMM_ENTRY(arg) do { } while(0) 60 # define IOCTL_VMM_EXIT(arg) do { } while(0) 61 #endif 22 62 23 63 #include "vboxmod.h" … … 342 382 if ( VBOXGUEST_IOCTL_STRIP_SIZE(VBOXGUEST_IOCTL_LOG(0)) 343 383 == VBOXGUEST_IOCTL_STRIP_SIZE(cmd)) { 344 char *pszMessage = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL); 384 char *pszMessage; 385 386 IOCTL_LOG_ENTRY(arg); 387 pszMessage = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL); 345 388 if (NULL == pszMessage) { 346 389 LogRelFunc(("VBOXGUEST_IOCTL_LOG: cannot allocate %d bytes of memory!\n", … … 359 402 kfree(pszMessage); 360 403 } 361 return rc; 362 } 363 364 if ( VBOXGUEST_IOCTL_STRIP_SIZE(VBOXGUEST_IOCTL_VMMREQUEST(0)) 404 IOCTL_LOG_EXIT(arg); 405 } 406 else if ( VBOXGUEST_IOCTL_STRIP_SIZE(VBOXGUEST_IOCTL_VMMREQUEST(0)) 365 407 == VBOXGUEST_IOCTL_STRIP_SIZE(cmd)) { 366 408 VMMDevRequestHeader reqHeader; … … 368 410 size_t cbRequestSize; 369 411 size_t cbVanillaRequestSize; 370 int rc; 371 412 413 IOCTL_VMM_ENTRY(arg); 372 414 if (copy_from_user(&reqHeader, (void*)arg, sizeof(reqHeader))) 373 415 { 374 416 LogRelFunc(("IOCTL_VBOXGUEST_VMMREQUEST: copy_from_user failed for vmm request!\n")); 375 return -EFAULT; 376 } 377 /* get the request size */ 378 cbVanillaRequestSize = vmmdevGetRequestSize(reqHeader.requestType); 379 if (!cbVanillaRequestSize) 417 rc = -EFAULT; 418 } 419 if (0 == rc) 380 420 { 381 LogRelFunc(("IOCTL_VBOXGUEST_VMMREQUEST: invalid request type: %d\n", 382 reqHeader.requestType)); 383 return -EINVAL; 384 } 385 386 cbRequestSize = reqHeader.size; 387 if (cbRequestSize < cbVanillaRequestSize) 421 /* get the request size */ 422 cbVanillaRequestSize = vmmdevGetRequestSize(reqHeader.requestType); 423 if (!cbVanillaRequestSize) 424 { 425 LogRelFunc(("IOCTL_VBOXGUEST_VMMREQUEST: invalid request type: %d\n", 426 reqHeader.requestType)); 427 rc = -EINVAL; 428 } 429 } 430 if (0 == rc) 388 431 { 389 LogRelFunc(("IOCTL_VBOXGUEST_VMMREQUEST: invalid request size: %d min: %d type: %d\n", 390 cbRequestSize, 391 cbVanillaRequestSize, 392 reqHeader.requestType)); 393 return -EINVAL; 394 } 395 /* request storage for the full request */ 396 rc = VbglGRAlloc(&reqFull, cbRequestSize, reqHeader.requestType); 397 if (VBOX_FAILURE(rc)) 432 cbRequestSize = reqHeader.size; 433 if (cbRequestSize < cbVanillaRequestSize) 434 { 435 LogRelFunc(("IOCTL_VBOXGUEST_VMMREQUEST: invalid request size: %d min: %d type: %d\n", 436 cbRequestSize, 437 cbVanillaRequestSize, 438 reqHeader.requestType)); 439 rc = -EINVAL; 440 } 441 } 442 if (0 == rc) 398 443 { 399 LogRelFunc(("IOCTL_VBOXGUEST_VMMREQUEST: could not allocate request structure! rc = %d\n", rc)); 400 return -EFAULT; 401 } 402 /* now get the full request */ 403 if (copy_from_user(reqFull, (void*)arg, cbRequestSize)) 444 /* request storage for the full request */ 445 rc = VbglGRAlloc(&reqFull, cbRequestSize, reqHeader.requestType); 446 if (VBOX_FAILURE(rc)) 447 { 448 LogRelFunc(("IOCTL_VBOXGUEST_VMMREQUEST: could not allocate request structure! rc = %d\n", rc)); 449 rc = -EFAULT; 450 } 451 } 452 if (0 == rc) 404 453 { 405 LogRelFunc(("IOCTL_VBOXGUEST_VMMREQUEST: failed to fetch full request from user space!\n")); 454 /* now get the full request */ 455 if (copy_from_user(reqFull, (void*)arg, cbRequestSize)) 456 { 457 LogRelFunc(("IOCTL_VBOXGUEST_VMMREQUEST: failed to fetch full request from user space!\n")); 458 rc = -EFAULT; 459 } 460 } 461 462 /* now issue the request */ 463 if (0 == rc) 464 { 465 int rrc = VbglGRPerform(reqFull); 466 467 /* asynchronous processing? */ 468 if (rrc == VINF_HGCM_ASYNC_EXECUTE) 469 { 470 VMMDevHGCMRequestHeader *reqHGCM = (VMMDevHGCMRequestHeader*)reqFull; 471 wait_event_interruptible (vboxDev->eventq, reqHGCM->fu32Flags & VBOX_HGCM_REQ_DONE); 472 rrc = reqFull->rc; 473 } 474 475 /* failed? */ 476 if (VBOX_FAILURE(rrc) || VBOX_FAILURE(reqFull->rc)) 477 { 478 LogRelFunc(("IOCTL_VBOXGUEST_VMMREQUEST: request execution failed!\n")); 479 rc = VBOX_FAILURE(rrc) ? -RTErrConvertToErrno(rrc) 480 : -RTErrConvertToErrno(reqFull->rc); 481 } 482 else 483 { 484 /* success, copy the result data to user space */ 485 if (copy_to_user((void*)arg, (void*)reqFull, cbRequestSize)) 486 { 487 LogRelFunc(("IOCTL_VBOXGUEST_VMMREQUEST: error copying request result to user space!\n")); 488 rc = -EFAULT; 489 } 490 } 491 } 492 if (NULL != reqFull) 406 493 VbglGRFree(reqFull); 407 return -EFAULT; 408 } 409 410 /* now issue the request */ 411 rc = VbglGRPerform(reqFull); 412 413 /* asynchronous processing? */ 414 if (rc == VINF_HGCM_ASYNC_EXECUTE) 415 { 416 VMMDevHGCMRequestHeader *reqHGCM = (VMMDevHGCMRequestHeader*)reqFull; 417 wait_event_interruptible (vboxDev->eventq, reqHGCM->fu32Flags & VBOX_HGCM_REQ_DONE); 418 rc = reqFull->rc; 419 } 420 421 /* failed? */ 422 if (VBOX_FAILURE(rc) || VBOX_FAILURE(reqFull->rc)) 423 { 424 LogRelFunc(("IOCTL_VBOXGUEST_VMMREQUEST: request execution failed!\n")); 425 VbglGRFree(reqFull); 426 return VBOX_FAILURE(rc) ? -RTErrConvertToErrno(rc) 427 : -RTErrConvertToErrno(reqFull->rc); 428 } 429 else 430 { 431 /* success, copy the result data to user space */ 432 if (copy_to_user((void*)arg, (void*)reqFull, cbRequestSize)) 433 { 434 LogRelFunc(("IOCTL_VBOXGUEST_VMMREQUEST: error copying request result to user space!\n")); 435 VbglGRFree(reqFull); 436 return -EFAULT; 437 } 438 } 439 VbglGRFree(reqFull); 440 return rc; 441 } 442 443 if ( VBOXGUEST_IOCTL_STRIP_SIZE(VBOXGUEST_IOCTL_HGCM_CALL(0)) 444 == VBOXGUEST_IOCTL_STRIP_SIZE(cmd)) { 494 IOCTL_VMM_EXIT(arg); 495 } 496 else if ( ( VBOXGUEST_IOCTL_STRIP_SIZE(VBOXGUEST_IOCTL_HGCM_CALL(0)) 497 == VBOXGUEST_IOCTL_STRIP_SIZE(cmd)) 498 || (cmd == IOCTL_VBOXGUEST_HGCM_CALL)) 499 { 445 500 /* This IOCTL allows the guest to make an HGCM call from user space. The 446 501 OS-independant part of the Guest Additions already contain code for making an … … 450 505 passed to the call (which include pointers to other memory) inside the kernel's 451 506 address space. */ 452 return vbox_ioctl_hgcm_call(arg, vboxDev); 453 } 454 455 switch (cmd) { 456 case IOCTL_VBOXGUEST_WAITEVENT: 457 rc = vboxadd_wait_event((void *) arg); 458 break; 459 460 case VBOXGUEST_IOCTL_CANCEL_ALL_WAITEVENTS: 461 ++vboxDev->u32GuestInterruptions; 462 break; 463 464 case IOCTL_VBOXGUEST_HGCM_CALL: 465 /* This IOCTL allows the guest to make an HGCM call from user space. The 466 OS-independant part of the Guest Additions already contain code for making an 467 HGCM call from the guest, but this code assumes that the call is made from the 468 kernel's address space. So before calling it, we have to copy all parameters 469 to the HGCM call from user space to kernel space and reconstruct the structures 470 passed to the call (which include pointers to other memory) inside the kernel's 471 address space. */ 507 IOCTL_ENTRY("VBOXGUEST_IOCTL_HGCM_CALL", arg); 472 508 rc = vbox_ioctl_hgcm_call(arg, vboxDev); 473 break; 474 475 case IOCTL_VBOXGUEST_HGCM_CONNECT: 476 rc = vboxadd_hgcm_connect(filp, arg); 477 break; 478 479 case VBOXGUEST_IOCTL_CTL_FILTER_MASK: 509 IOCTL_EXIT("VBOXGUEST_IOCTL_HGCM_CALL", arg); 510 } 511 else 480 512 { 481 VBoxGuestFilterMaskInfo info;482 if (copy_from_user((void*)&info, (void*)arg, sizeof(info)))483 {484 LogRelFunc(("VBOXGUEST_IOCTL_CTL_FILTER_MASK: error getting parameters from user space!\n"));485 rc = -EFAULT;513 switch (cmd) { 514 case IOCTL_VBOXGUEST_WAITEVENT: 515 IOCTL_ENTRY("IOCTL_VBOXGUEST_WAITEVENT", arg); 516 rc = vboxadd_wait_event((void *) arg); 517 IOCTL_EXIT("IOCTL_VBOXGUEST_WAITEVENT", arg); 486 518 break; 487 } 488 rc = -RTErrConvertToErrno(vboxadd_control_filter_mask(&info)); 489 break; 490 } 491 default: 492 LogRelFunc(("unknown command: %x\n", cmd)); 493 rc = -EINVAL; 494 break; 519 case VBOXGUEST_IOCTL_CANCEL_ALL_WAITEVENTS: 520 IOCTL_ENTRY("VBOXGUEST_IOCTL_CANCEL_ALL_WAITEVENTS", arg); 521 ++vboxDev->u32GuestInterruptions; 522 IOCTL_EXIT("VBOXGUEST_IOCTL_CANCEL_ALL_WAITEVENTS", arg); 523 break; 524 case IOCTL_VBOXGUEST_HGCM_CONNECT: 525 IOCTL_ENTRY("IOCTL_VBOXGUEST_HGCM_CONNECT", arg); 526 rc = vboxadd_hgcm_connect(filp, arg); 527 IOCTL_EXIT("IOCTL_VBOXGUEST_HGCM_CONNECT", arg); 528 break; 529 case VBOXGUEST_IOCTL_CTL_FILTER_MASK: 530 { 531 VBoxGuestFilterMaskInfo info; 532 IOCTL_ENTRY("VBOXGUEST_IOCTL_CTL_FILTER_MASK", arg); 533 if (copy_from_user((void*)&info, (void*)arg, sizeof(info))) 534 { 535 LogRelFunc(("VBOXGUEST_IOCTL_CTL_FILTER_MASK: error getting parameters from user space!\n")); 536 rc = -EFAULT; 537 break; 538 } 539 rc = -RTErrConvertToErrno(vboxadd_control_filter_mask(&info)); 540 IOCTL_EXIT("VBOXGUEST_IOCTL_CTL_FILTER_MASK", arg); 541 break; 542 } 543 default: 544 LogRelFunc(("unknown command: %x\n", cmd)); 545 rc = -EINVAL; 546 break; 547 } 495 548 } 496 549 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.