1 /* SPDX-License-Identifier: (GPL-2.0 OR CDDL-1.0) */
3 * vboxguest vmm-req and hgcm-call code, VBoxGuestR0LibHGCMInternal.cpp,
4 * VBoxGuestR0LibGenericRequest.cpp and RTErrConvertToErrno.cpp in vbox svn.
6 * Copyright (C) 2006-2016 Oracle Corporation
9 #include <linux/errno.h>
10 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/sizes.h>
14 #include <linux/slab.h>
15 #include <linux/uaccess.h>
16 #include <linux/vmalloc.h>
17 #include <linux/vbox_err.h>
18 #include <linux/vbox_utils.h>
19 #include "vboxguest_core.h"
21 /* Get the pointer to the first parameter of a HGCM call request. */
22 #define VMMDEV_HGCM_CALL_PARMS(a) \
23 ((struct vmmdev_hgcm_function_parameter *)( \
24 (u8 *)(a) + sizeof(struct vmmdev_hgcm_call)))
26 /* The max parameter buffer size for a user request. */
27 #define VBG_MAX_HGCM_USER_PARM (24 * SZ_1M)
28 /* The max parameter buffer size for a kernel request. */
29 #define VBG_MAX_HGCM_KERNEL_PARM (16 * SZ_1M)
31 #define VBG_DEBUG_PORT 0x504
33 /* This protects vbg_log_buf and serializes VBG_DEBUG_PORT accesses */
34 static DEFINE_SPINLOCK(vbg_log_lock
);
35 static char vbg_log_buf
[128];
37 #define VBG_LOG(name, pr_func) \
38 void name(const char *fmt, ...) \
40 unsigned long flags; \
44 va_start(args, fmt); \
45 spin_lock_irqsave(&vbg_log_lock, flags); \
47 count = vscnprintf(vbg_log_buf, sizeof(vbg_log_buf), fmt, args);\
48 for (i = 0; i < count; i++) \
49 outb(vbg_log_buf[i], VBG_DEBUG_PORT); \
51 pr_func("%s", vbg_log_buf); \
53 spin_unlock_irqrestore(&vbg_log_lock, flags); \
58 VBG_LOG(vbg_info
, pr_info
);
59 VBG_LOG(vbg_warn
, pr_warn
);
60 VBG_LOG(vbg_err
, pr_err
);
61 #if defined(DEBUG) && !defined(CONFIG_DYNAMIC_DEBUG)
62 VBG_LOG(vbg_debug
, pr_debug
);
65 void *vbg_req_alloc(size_t len
, enum vmmdev_request_type req_type
)
67 struct vmmdev_request_header
*req
;
68 int order
= get_order(PAGE_ALIGN(len
));
70 req
= (void *)__get_free_pages(GFP_KERNEL
| GFP_DMA32
, order
);
74 memset(req
, 0xaa, len
);
77 req
->version
= VMMDEV_REQUEST_HEADER_VERSION
;
78 req
->request_type
= req_type
;
79 req
->rc
= VERR_GENERAL_FAILURE
;
86 void vbg_req_free(void *req
, size_t len
)
91 free_pages((unsigned long)req
, get_order(PAGE_ALIGN(len
)));
94 /* Note this function returns a VBox status code, not a negative errno!! */
95 int vbg_req_perform(struct vbg_dev
*gdev
, void *req
)
97 unsigned long phys_req
= virt_to_phys(req
);
99 outl(phys_req
, gdev
->io_port
+ VMMDEV_PORT_OFF_REQUEST
);
101 * The host changes the request as a result of the outl, make sure
102 * the outl and any reads of the req happen in the correct order.
106 return ((struct vmmdev_request_header
*)req
)->rc
;
109 static bool hgcm_req_done(struct vbg_dev
*gdev
,
110 struct vmmdev_hgcmreq_header
*header
)
115 spin_lock_irqsave(&gdev
->event_spinlock
, flags
);
116 done
= header
->flags
& VMMDEV_HGCM_REQ_DONE
;
117 spin_unlock_irqrestore(&gdev
->event_spinlock
, flags
);
122 int vbg_hgcm_connect(struct vbg_dev
*gdev
,
123 struct vmmdev_hgcm_service_location
*loc
,
124 u32
*client_id
, int *vbox_status
)
126 struct vmmdev_hgcm_connect
*hgcm_connect
= NULL
;
129 hgcm_connect
= vbg_req_alloc(sizeof(*hgcm_connect
),
130 VMMDEVREQ_HGCM_CONNECT
);
134 hgcm_connect
->header
.flags
= 0;
135 memcpy(&hgcm_connect
->loc
, loc
, sizeof(*loc
));
136 hgcm_connect
->client_id
= 0;
138 rc
= vbg_req_perform(gdev
, hgcm_connect
);
140 if (rc
== VINF_HGCM_ASYNC_EXECUTE
)
141 wait_event(gdev
->hgcm_wq
,
142 hgcm_req_done(gdev
, &hgcm_connect
->header
));
145 *client_id
= hgcm_connect
->client_id
;
146 rc
= hgcm_connect
->header
.result
;
149 vbg_req_free(hgcm_connect
, sizeof(*hgcm_connect
));
154 EXPORT_SYMBOL(vbg_hgcm_connect
);
156 int vbg_hgcm_disconnect(struct vbg_dev
*gdev
, u32 client_id
, int *vbox_status
)
158 struct vmmdev_hgcm_disconnect
*hgcm_disconnect
= NULL
;
161 hgcm_disconnect
= vbg_req_alloc(sizeof(*hgcm_disconnect
),
162 VMMDEVREQ_HGCM_DISCONNECT
);
163 if (!hgcm_disconnect
)
166 hgcm_disconnect
->header
.flags
= 0;
167 hgcm_disconnect
->client_id
= client_id
;
169 rc
= vbg_req_perform(gdev
, hgcm_disconnect
);
171 if (rc
== VINF_HGCM_ASYNC_EXECUTE
)
172 wait_event(gdev
->hgcm_wq
,
173 hgcm_req_done(gdev
, &hgcm_disconnect
->header
));
176 rc
= hgcm_disconnect
->header
.result
;
178 vbg_req_free(hgcm_disconnect
, sizeof(*hgcm_disconnect
));
183 EXPORT_SYMBOL(vbg_hgcm_disconnect
);
185 static u32
hgcm_call_buf_size_in_pages(void *buf
, u32 len
)
187 u32 size
= PAGE_ALIGN(len
+ ((unsigned long)buf
& ~PAGE_MASK
));
189 return size
>> PAGE_SHIFT
;
192 static void hgcm_call_add_pagelist_size(void *buf
, u32 len
, size_t *extra
)
196 page_count
= hgcm_call_buf_size_in_pages(buf
, len
);
197 *extra
+= offsetof(struct vmmdev_hgcm_pagelist
, pages
[page_count
]);
200 static int hgcm_call_preprocess_linaddr(
201 const struct vmmdev_hgcm_function_parameter
*src_parm
,
202 void **bounce_buf_ret
, size_t *extra
)
204 void *buf
, *bounce_buf
;
209 buf
= (void *)src_parm
->u
.pointer
.u
.linear_addr
;
210 len
= src_parm
->u
.pointer
.size
;
211 copy_in
= src_parm
->type
!= VMMDEV_HGCM_PARM_TYPE_LINADDR_OUT
;
213 if (len
> VBG_MAX_HGCM_USER_PARM
)
216 bounce_buf
= kvmalloc(len
, GFP_KERNEL
);
221 ret
= copy_from_user(bounce_buf
, (void __user
*)buf
, len
);
225 memset(bounce_buf
, 0, len
);
228 *bounce_buf_ret
= bounce_buf
;
229 hgcm_call_add_pagelist_size(bounce_buf
, len
, extra
);
234 * Preprocesses the HGCM call, validate parameters, alloc bounce buffers and
235 * figure out how much extra storage we need for page lists.
236 * Return: 0 or negative errno value.
237 * @src_parm: Pointer to source function call parameters
238 * @parm_count: Number of function call parameters.
239 * @bounce_bufs_ret: Where to return the allocated bouncebuffer array
240 * @extra: Where to return the extra request space needed for
241 * physical page lists.
243 static int hgcm_call_preprocess(
244 const struct vmmdev_hgcm_function_parameter
*src_parm
,
245 u32 parm_count
, void ***bounce_bufs_ret
, size_t *extra
)
247 void *buf
, **bounce_bufs
= NULL
;
251 for (i
= 0; i
< parm_count
; i
++, src_parm
++) {
252 switch (src_parm
->type
) {
253 case VMMDEV_HGCM_PARM_TYPE_32BIT
:
254 case VMMDEV_HGCM_PARM_TYPE_64BIT
:
257 case VMMDEV_HGCM_PARM_TYPE_LINADDR
:
258 case VMMDEV_HGCM_PARM_TYPE_LINADDR_IN
:
259 case VMMDEV_HGCM_PARM_TYPE_LINADDR_OUT
:
261 bounce_bufs
= kcalloc(parm_count
,
267 *bounce_bufs_ret
= bounce_bufs
;
270 ret
= hgcm_call_preprocess_linaddr(src_parm
,
278 case VMMDEV_HGCM_PARM_TYPE_LINADDR_KERNEL
:
279 case VMMDEV_HGCM_PARM_TYPE_LINADDR_KERNEL_IN
:
280 case VMMDEV_HGCM_PARM_TYPE_LINADDR_KERNEL_OUT
:
281 buf
= (void *)src_parm
->u
.pointer
.u
.linear_addr
;
282 len
= src_parm
->u
.pointer
.size
;
283 if (WARN_ON(len
> VBG_MAX_HGCM_KERNEL_PARM
))
286 hgcm_call_add_pagelist_size(buf
, len
, extra
);
298 * Translates linear address types to page list direction flags.
300 * Return: page list flags.
303 static u32
hgcm_call_linear_addr_type_to_pagelist_flags(
304 enum vmmdev_hgcm_function_parameter_type type
)
310 case VMMDEV_HGCM_PARM_TYPE_LINADDR
:
311 case VMMDEV_HGCM_PARM_TYPE_LINADDR_KERNEL
:
312 return VMMDEV_HGCM_F_PARM_DIRECTION_BOTH
;
314 case VMMDEV_HGCM_PARM_TYPE_LINADDR_IN
:
315 case VMMDEV_HGCM_PARM_TYPE_LINADDR_KERNEL_IN
:
316 return VMMDEV_HGCM_F_PARM_DIRECTION_TO_HOST
;
318 case VMMDEV_HGCM_PARM_TYPE_LINADDR_OUT
:
319 case VMMDEV_HGCM_PARM_TYPE_LINADDR_KERNEL_OUT
:
320 return VMMDEV_HGCM_F_PARM_DIRECTION_FROM_HOST
;
324 static void hgcm_call_init_linaddr(struct vmmdev_hgcm_call
*call
,
325 struct vmmdev_hgcm_function_parameter
*dst_parm
, void *buf
, u32 len
,
326 enum vmmdev_hgcm_function_parameter_type type
, u32
*off_extra
)
328 struct vmmdev_hgcm_pagelist
*dst_pg_lst
;
333 dst_parm
->type
= type
;
336 dst_parm
->u
.pointer
.size
= 0;
337 dst_parm
->u
.pointer
.u
.linear_addr
= 0;
341 dst_pg_lst
= (void *)call
+ *off_extra
;
342 page_count
= hgcm_call_buf_size_in_pages(buf
, len
);
343 is_vmalloc
= is_vmalloc_addr(buf
);
345 dst_parm
->type
= VMMDEV_HGCM_PARM_TYPE_PAGELIST
;
346 dst_parm
->u
.page_list
.size
= len
;
347 dst_parm
->u
.page_list
.offset
= *off_extra
;
348 dst_pg_lst
->flags
= hgcm_call_linear_addr_type_to_pagelist_flags(type
);
349 dst_pg_lst
->offset_first_page
= (unsigned long)buf
& ~PAGE_MASK
;
350 dst_pg_lst
->page_count
= page_count
;
352 for (i
= 0; i
< page_count
; i
++) {
354 page
= vmalloc_to_page(buf
);
356 page
= virt_to_page(buf
);
358 dst_pg_lst
->pages
[i
] = page_to_phys(page
);
362 *off_extra
+= offsetof(struct vmmdev_hgcm_pagelist
, pages
[page_count
]);
366 * Initializes the call request that we're sending to the host.
367 * @call: The call to initialize.
368 * @client_id: The client ID of the caller.
369 * @function: The function number of the function to call.
370 * @src_parm: Pointer to source function call parameters.
371 * @parm_count: Number of function call parameters.
372 * @bounce_bufs: The bouncebuffer array.
374 static void hgcm_call_init_call(
375 struct vmmdev_hgcm_call
*call
, u32 client_id
, u32 function
,
376 const struct vmmdev_hgcm_function_parameter
*src_parm
,
377 u32 parm_count
, void **bounce_bufs
)
379 struct vmmdev_hgcm_function_parameter
*dst_parm
=
380 VMMDEV_HGCM_CALL_PARMS(call
);
381 u32 i
, off_extra
= (uintptr_t)(dst_parm
+ parm_count
) - (uintptr_t)call
;
384 call
->header
.flags
= 0;
385 call
->header
.result
= VINF_SUCCESS
;
386 call
->client_id
= client_id
;
387 call
->function
= function
;
388 call
->parm_count
= parm_count
;
390 for (i
= 0; i
< parm_count
; i
++, src_parm
++, dst_parm
++) {
391 switch (src_parm
->type
) {
392 case VMMDEV_HGCM_PARM_TYPE_32BIT
:
393 case VMMDEV_HGCM_PARM_TYPE_64BIT
:
394 *dst_parm
= *src_parm
;
397 case VMMDEV_HGCM_PARM_TYPE_LINADDR
:
398 case VMMDEV_HGCM_PARM_TYPE_LINADDR_IN
:
399 case VMMDEV_HGCM_PARM_TYPE_LINADDR_OUT
:
400 hgcm_call_init_linaddr(call
, dst_parm
, bounce_bufs
[i
],
401 src_parm
->u
.pointer
.size
,
402 src_parm
->type
, &off_extra
);
405 case VMMDEV_HGCM_PARM_TYPE_LINADDR_KERNEL
:
406 case VMMDEV_HGCM_PARM_TYPE_LINADDR_KERNEL_IN
:
407 case VMMDEV_HGCM_PARM_TYPE_LINADDR_KERNEL_OUT
:
408 buf
= (void *)src_parm
->u
.pointer
.u
.linear_addr
;
409 hgcm_call_init_linaddr(call
, dst_parm
, buf
,
410 src_parm
->u
.pointer
.size
,
411 src_parm
->type
, &off_extra
);
416 dst_parm
->type
= VMMDEV_HGCM_PARM_TYPE_INVALID
;
422 * Tries to cancel a pending HGCM call.
424 * Return: VBox status code
426 static int hgcm_cancel_call(struct vbg_dev
*gdev
, struct vmmdev_hgcm_call
*call
)
431 * We use a pre-allocated request for cancellations, which is
432 * protected by cancel_req_mutex. This means that all cancellations
433 * get serialized, this should be fine since they should be rare.
435 mutex_lock(&gdev
->cancel_req_mutex
);
436 gdev
->cancel_req
->phys_req_to_cancel
= virt_to_phys(call
);
437 rc
= vbg_req_perform(gdev
, gdev
->cancel_req
);
438 mutex_unlock(&gdev
->cancel_req_mutex
);
440 if (rc
== VERR_NOT_IMPLEMENTED
) {
441 call
->header
.flags
|= VMMDEV_HGCM_REQ_CANCELLED
;
442 call
->header
.header
.request_type
= VMMDEVREQ_HGCM_CANCEL
;
444 rc
= vbg_req_perform(gdev
, call
);
445 if (rc
== VERR_INVALID_PARAMETER
)
450 call
->header
.flags
|= VMMDEV_HGCM_REQ_CANCELLED
;
456 * Performs the call and completion wait.
457 * Return: 0 or negative errno value.
458 * @gdev: The VBoxGuest device extension.
459 * @call: The call to execute.
460 * @timeout_ms: Timeout in ms.
461 * @leak_it: Where to return the leak it / free it, indicator.
464 static int vbg_hgcm_do_call(struct vbg_dev
*gdev
, struct vmmdev_hgcm_call
*call
,
465 u32 timeout_ms
, bool *leak_it
)
467 int rc
, cancel_rc
, ret
;
472 rc
= vbg_req_perform(gdev
, call
);
475 * If the call failed, then pretend success. Upper layers will
476 * interpret the result code in the packet.
479 call
->header
.result
= rc
;
483 if (rc
!= VINF_HGCM_ASYNC_EXECUTE
)
486 /* Host decided to process the request asynchronously, wait for it */
487 if (timeout_ms
== U32_MAX
)
488 timeout
= MAX_SCHEDULE_TIMEOUT
;
490 timeout
= msecs_to_jiffies(timeout_ms
);
492 timeout
= wait_event_interruptible_timeout(
494 hgcm_req_done(gdev
, &call
->header
),
497 /* timeout > 0 means hgcm_req_done has returned true, so success */
506 /* Cancel the request */
507 cancel_rc
= hgcm_cancel_call(gdev
, call
);
512 * Failed to cancel, this should mean that the cancel has lost the
513 * race with normal completion, wait while the host completes it.
515 if (cancel_rc
== VERR_NOT_FOUND
|| cancel_rc
== VERR_SEM_DESTROYED
)
516 timeout
= msecs_to_jiffies(500);
518 timeout
= msecs_to_jiffies(2000);
520 timeout
= wait_event_timeout(gdev
->hgcm_wq
,
521 hgcm_req_done(gdev
, &call
->header
),
524 if (WARN_ON(timeout
== 0)) {
525 /* We really should never get here */
526 vbg_err("%s: Call timedout and cancellation failed, leaking the request\n",
532 /* The call has completed normally after all */
537 * Copies the result of the call back to the caller info structure and user
539 * Return: 0 or negative errno value.
540 * @call: HGCM call request.
541 * @dst_parm: Pointer to function call parameters destination.
542 * @parm_count: Number of function call parameters.
543 * @bounce_bufs: The bouncebuffer array.
545 static int hgcm_call_copy_back_result(
546 const struct vmmdev_hgcm_call
*call
,
547 struct vmmdev_hgcm_function_parameter
*dst_parm
,
548 u32 parm_count
, void **bounce_bufs
)
550 const struct vmmdev_hgcm_function_parameter
*src_parm
=
551 VMMDEV_HGCM_CALL_PARMS(call
);
556 /* Copy back parameters. */
557 for (i
= 0; i
< parm_count
; i
++, src_parm
++, dst_parm
++) {
558 switch (dst_parm
->type
) {
559 case VMMDEV_HGCM_PARM_TYPE_32BIT
:
560 case VMMDEV_HGCM_PARM_TYPE_64BIT
:
561 *dst_parm
= *src_parm
;
564 case VMMDEV_HGCM_PARM_TYPE_PAGELIST
:
565 dst_parm
->u
.page_list
.size
= src_parm
->u
.page_list
.size
;
568 case VMMDEV_HGCM_PARM_TYPE_LINADDR_IN
:
569 case VMMDEV_HGCM_PARM_TYPE_LINADDR_KERNEL
:
570 case VMMDEV_HGCM_PARM_TYPE_LINADDR_KERNEL_IN
:
571 case VMMDEV_HGCM_PARM_TYPE_LINADDR_KERNEL_OUT
:
572 dst_parm
->u
.pointer
.size
= src_parm
->u
.pointer
.size
;
575 case VMMDEV_HGCM_PARM_TYPE_LINADDR
:
576 case VMMDEV_HGCM_PARM_TYPE_LINADDR_OUT
:
577 dst_parm
->u
.pointer
.size
= src_parm
->u
.pointer
.size
;
579 p
= (void __user
*)dst_parm
->u
.pointer
.u
.linear_addr
;
580 ret
= copy_to_user(p
, bounce_bufs
[i
],
581 min(src_parm
->u
.pointer
.size
,
582 dst_parm
->u
.pointer
.size
));
596 int vbg_hgcm_call(struct vbg_dev
*gdev
, u32 client_id
, u32 function
,
597 u32 timeout_ms
, struct vmmdev_hgcm_function_parameter
*parms
,
598 u32 parm_count
, int *vbox_status
)
600 struct vmmdev_hgcm_call
*call
;
601 void **bounce_bufs
= NULL
;
606 size
= sizeof(struct vmmdev_hgcm_call
) +
607 parm_count
* sizeof(struct vmmdev_hgcm_function_parameter
);
609 * Validate and buffer the parameters for the call. This also increases
610 * call_size with the amount of extra space needed for page lists.
612 ret
= hgcm_call_preprocess(parms
, parm_count
, &bounce_bufs
, &size
);
614 /* Even on error bounce bufs may still have been allocated */
615 goto free_bounce_bufs
;
618 call
= vbg_req_alloc(size
, VMMDEVREQ_HGCM_CALL
);
621 goto free_bounce_bufs
;
624 hgcm_call_init_call(call
, client_id
, function
, parms
, parm_count
,
627 ret
= vbg_hgcm_do_call(gdev
, call
, timeout_ms
, &leak_it
);
629 *vbox_status
= call
->header
.result
;
630 ret
= hgcm_call_copy_back_result(call
, parms
, parm_count
,
635 vbg_req_free(call
, size
);
639 for (i
= 0; i
< parm_count
; i
++)
640 kvfree(bounce_bufs
[i
]);
646 EXPORT_SYMBOL(vbg_hgcm_call
);
650 struct vbg_dev
*gdev
, u32 client_id
, u32 function
, u32 timeout_ms
,
651 struct vmmdev_hgcm_function_parameter32
*parm32
, u32 parm_count
,
654 struct vmmdev_hgcm_function_parameter
*parm64
= NULL
;
658 /* KISS allocate a temporary request and convert the parameters. */
659 size
= parm_count
* sizeof(struct vmmdev_hgcm_function_parameter
);
660 parm64
= kzalloc(size
, GFP_KERNEL
);
664 for (i
= 0; i
< parm_count
; i
++) {
665 switch (parm32
[i
].type
) {
666 case VMMDEV_HGCM_PARM_TYPE_32BIT
:
667 parm64
[i
].type
= VMMDEV_HGCM_PARM_TYPE_32BIT
;
668 parm64
[i
].u
.value32
= parm32
[i
].u
.value32
;
671 case VMMDEV_HGCM_PARM_TYPE_64BIT
:
672 parm64
[i
].type
= VMMDEV_HGCM_PARM_TYPE_64BIT
;
673 parm64
[i
].u
.value64
= parm32
[i
].u
.value64
;
676 case VMMDEV_HGCM_PARM_TYPE_LINADDR_OUT
:
677 case VMMDEV_HGCM_PARM_TYPE_LINADDR
:
678 case VMMDEV_HGCM_PARM_TYPE_LINADDR_IN
:
679 parm64
[i
].type
= parm32
[i
].type
;
680 parm64
[i
].u
.pointer
.size
= parm32
[i
].u
.pointer
.size
;
681 parm64
[i
].u
.pointer
.u
.linear_addr
=
682 parm32
[i
].u
.pointer
.u
.linear_addr
;
692 ret
= vbg_hgcm_call(gdev
, client_id
, function
, timeout_ms
,
693 parm64
, parm_count
, vbox_status
);
698 for (i
= 0; i
< parm_count
; i
++, parm32
++, parm64
++) {
699 switch (parm64
[i
].type
) {
700 case VMMDEV_HGCM_PARM_TYPE_32BIT
:
701 parm32
[i
].u
.value32
= parm64
[i
].u
.value32
;
704 case VMMDEV_HGCM_PARM_TYPE_64BIT
:
705 parm32
[i
].u
.value64
= parm64
[i
].u
.value64
;
708 case VMMDEV_HGCM_PARM_TYPE_LINADDR_OUT
:
709 case VMMDEV_HGCM_PARM_TYPE_LINADDR
:
710 case VMMDEV_HGCM_PARM_TYPE_LINADDR_IN
:
711 parm32
[i
].u
.pointer
.size
= parm64
[i
].u
.pointer
.size
;
726 static const int vbg_status_code_to_errno_table
[] = {
727 [-VERR_ACCESS_DENIED
] = -EPERM
,
728 [-VERR_FILE_NOT_FOUND
] = -ENOENT
,
729 [-VERR_PROCESS_NOT_FOUND
] = -ESRCH
,
730 [-VERR_INTERRUPTED
] = -EINTR
,
731 [-VERR_DEV_IO_ERROR
] = -EIO
,
732 [-VERR_TOO_MUCH_DATA
] = -E2BIG
,
733 [-VERR_BAD_EXE_FORMAT
] = -ENOEXEC
,
734 [-VERR_INVALID_HANDLE
] = -EBADF
,
735 [-VERR_TRY_AGAIN
] = -EAGAIN
,
736 [-VERR_NO_MEMORY
] = -ENOMEM
,
737 [-VERR_INVALID_POINTER
] = -EFAULT
,
738 [-VERR_RESOURCE_BUSY
] = -EBUSY
,
739 [-VERR_ALREADY_EXISTS
] = -EEXIST
,
740 [-VERR_NOT_SAME_DEVICE
] = -EXDEV
,
741 [-VERR_NOT_A_DIRECTORY
] = -ENOTDIR
,
742 [-VERR_PATH_NOT_FOUND
] = -ENOTDIR
,
743 [-VERR_INVALID_NAME
] = -ENOENT
,
744 [-VERR_IS_A_DIRECTORY
] = -EISDIR
,
745 [-VERR_INVALID_PARAMETER
] = -EINVAL
,
746 [-VERR_TOO_MANY_OPEN_FILES
] = -ENFILE
,
747 [-VERR_INVALID_FUNCTION
] = -ENOTTY
,
748 [-VERR_SHARING_VIOLATION
] = -ETXTBSY
,
749 [-VERR_FILE_TOO_BIG
] = -EFBIG
,
750 [-VERR_DISK_FULL
] = -ENOSPC
,
751 [-VERR_SEEK_ON_DEVICE
] = -ESPIPE
,
752 [-VERR_WRITE_PROTECT
] = -EROFS
,
753 [-VERR_BROKEN_PIPE
] = -EPIPE
,
754 [-VERR_DEADLOCK
] = -EDEADLK
,
755 [-VERR_FILENAME_TOO_LONG
] = -ENAMETOOLONG
,
756 [-VERR_FILE_LOCK_FAILED
] = -ENOLCK
,
757 [-VERR_NOT_IMPLEMENTED
] = -ENOSYS
,
758 [-VERR_NOT_SUPPORTED
] = -ENOSYS
,
759 [-VERR_DIR_NOT_EMPTY
] = -ENOTEMPTY
,
760 [-VERR_TOO_MANY_SYMLINKS
] = -ELOOP
,
761 [-VERR_NO_MORE_FILES
] = -ENODATA
,
762 [-VERR_NO_DATA
] = -ENODATA
,
763 [-VERR_NET_NO_NETWORK
] = -ENONET
,
764 [-VERR_NET_NOT_UNIQUE_NAME
] = -ENOTUNIQ
,
765 [-VERR_NO_TRANSLATION
] = -EILSEQ
,
766 [-VERR_NET_NOT_SOCKET
] = -ENOTSOCK
,
767 [-VERR_NET_DEST_ADDRESS_REQUIRED
] = -EDESTADDRREQ
,
768 [-VERR_NET_MSG_SIZE
] = -EMSGSIZE
,
769 [-VERR_NET_PROTOCOL_TYPE
] = -EPROTOTYPE
,
770 [-VERR_NET_PROTOCOL_NOT_AVAILABLE
] = -ENOPROTOOPT
,
771 [-VERR_NET_PROTOCOL_NOT_SUPPORTED
] = -EPROTONOSUPPORT
,
772 [-VERR_NET_SOCKET_TYPE_NOT_SUPPORTED
] = -ESOCKTNOSUPPORT
,
773 [-VERR_NET_OPERATION_NOT_SUPPORTED
] = -EOPNOTSUPP
,
774 [-VERR_NET_PROTOCOL_FAMILY_NOT_SUPPORTED
] = -EPFNOSUPPORT
,
775 [-VERR_NET_ADDRESS_FAMILY_NOT_SUPPORTED
] = -EAFNOSUPPORT
,
776 [-VERR_NET_ADDRESS_IN_USE
] = -EADDRINUSE
,
777 [-VERR_NET_ADDRESS_NOT_AVAILABLE
] = -EADDRNOTAVAIL
,
778 [-VERR_NET_DOWN
] = -ENETDOWN
,
779 [-VERR_NET_UNREACHABLE
] = -ENETUNREACH
,
780 [-VERR_NET_CONNECTION_RESET
] = -ENETRESET
,
781 [-VERR_NET_CONNECTION_ABORTED
] = -ECONNABORTED
,
782 [-VERR_NET_CONNECTION_RESET_BY_PEER
] = -ECONNRESET
,
783 [-VERR_NET_NO_BUFFER_SPACE
] = -ENOBUFS
,
784 [-VERR_NET_ALREADY_CONNECTED
] = -EISCONN
,
785 [-VERR_NET_NOT_CONNECTED
] = -ENOTCONN
,
786 [-VERR_NET_SHUTDOWN
] = -ESHUTDOWN
,
787 [-VERR_NET_TOO_MANY_REFERENCES
] = -ETOOMANYREFS
,
788 [-VERR_TIMEOUT
] = -ETIMEDOUT
,
789 [-VERR_NET_CONNECTION_REFUSED
] = -ECONNREFUSED
,
790 [-VERR_NET_HOST_DOWN
] = -EHOSTDOWN
,
791 [-VERR_NET_HOST_UNREACHABLE
] = -EHOSTUNREACH
,
792 [-VERR_NET_ALREADY_IN_PROGRESS
] = -EALREADY
,
793 [-VERR_NET_IN_PROGRESS
] = -EINPROGRESS
,
794 [-VERR_MEDIA_NOT_PRESENT
] = -ENOMEDIUM
,
795 [-VERR_MEDIA_NOT_RECOGNIZED
] = -EMEDIUMTYPE
,
798 int vbg_status_code_to_errno(int rc
)
804 if (rc
>= ARRAY_SIZE(vbg_status_code_to_errno_table
) ||
805 vbg_status_code_to_errno_table
[rc
] == 0) {
806 vbg_warn("%s: Unhandled err %d\n", __func__
, -rc
);
810 return vbg_status_code_to_errno_table
[rc
];
812 EXPORT_SYMBOL(vbg_status_code_to_errno
);