VirtualBox

source: vbox/trunk/include/VBox/Graphics/VBoxVideoErr.h@ 107854

Last change on this file since 107854 was 107605, checked in by vboxsync, 7 weeks ago

Additions: Linux: vboxvideo: Additional fix for UBSAN warnings, bugref:10585.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.4 KB
Line 
1/* $Id: VBoxVideoErr.h 107605 2025-01-09 17:32:38Z vboxsync $ */
2/** @file
3 * VirtualBox Video driver, common code - iprt and VirtualBox macros and
4 * definitions.
5 */
6
7/*
8 * Copyright (C) 2017-2024 Oracle and/or its affiliates.
9 *
10 * Permission is hereby granted, free of charge, to any person
11 * obtaining a copy of this software and associated documentation
12 * files (the "Software"), to deal in the Software without
13 * restriction, including without limitation the rights to use,
14 * copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following
17 * conditions:
18 *
19 * The above copyright notice and this permission notice shall be
20 * included in all copies or substantial portions of the Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 * OTHER DEALINGS IN THE SOFTWARE.
30 */
31
32#ifndef VBOX_INCLUDED_Graphics_VBoxVideoErr_h
33#define VBOX_INCLUDED_Graphics_VBoxVideoErr_h
34#ifndef RT_WITHOUT_PRAGMA_ONCE
35# pragma once
36#endif
37
38/** @name VirtualBox error macros
39 * @{ */
40
41#define VINF_SUCCESS 0
42#define VERR_INVALID_PARAMETER (-2)
43#define VERR_INVALID_POINTER (-6)
44#define VERR_NO_MEMORY (-8)
45#define VERR_NOT_IMPLEMENTED (-12)
46#define VERR_INVALID_FUNCTION (-36)
47#define VERR_NOT_SUPPORTED (-37)
48#define VERR_TOO_MUCH_DATA (-42)
49#define VERR_NOT_FOUND (-78)
50#define VERR_INVALID_STATE (-79)
51#define VERR_OUT_OF_RESOURCES (-80)
52#define VERR_ALREADY_EXISTS (-105)
53#define VERR_INTERNAL_ERROR (-225)
54
55#define RT_SUCCESS_NP(rc) ( (int)(rc) >= VINF_SUCCESS )
56#define RT_SUCCESS(rc) ( likely(RT_SUCCESS_NP(rc)) )
57#define RT_FAILURE(rc) ( unlikely(!RT_SUCCESS_NP(rc)) )
58
59/** @} */
60
61/** @name VirtualBox assertions
62 * @{ */
63
64/* Unlike BUILD_BUG_ON(), these can be used outside of functions. */
65extern int vbox_assert_var[1];
66#define assert_compile(expr) \
67 extern int vbox_assert_var[1] __attribute__((__unused__)), \
68 vbox_assert_var[(expr) ? 1 : 0] __attribute__((__unused__))
69#define assert_compile_size(type, size) \
70 assert_compile(sizeof(type) == (size))
71#define assert_ptr_return(ptr,ret) \
72 do { if (unlikely(!(ptr))) { WARN_ON_ONCE(!(ptr)); return ret; } } while (0)
73
74/** @} */
75
76/** @def RT_BCOPY_UNFORTIFIED
77 * For copying a number of bytes from/to variable length structures.
78 *
79 * This is for working around false positives ("field-spanning writes") in the
80 * linux kernel's fortified memcpy (v5.18+) when copying from/to
81 * RT_FLEXIBLE_ARRAY fields and similar tricks going beyond the strict
82 * definition of a target or source structure.
83 *
84 * @param a_pDst Pointer to the destination buffer.
85 * @param a_pSrc Pointer to the source buffer.
86 * @param a_cbToCopy Number of bytes to copy.
87 * @see @bugref{10209}, @ticketref{21410}
88 */
89#if defined(RT_OS_LINUX) && defined(__KERNEL__)
90/* The definition of RT_BCOPY_UNFORTIFIED macro originally comes from IPRT
91 * header file. However, due to vboxvideo (Linux/DRM module) implementation,
92 * those header files cannot be used directly. Therefore, let's duplicate this
93 * definition here. Following vbox_drv.h header file is a part of
94 * vboxvideo sources, so this code block is only intended to be used from there. */
95# include "vbox_drv.h"
96# if (RTLNX_VER_MIN(5,18,0) || RTLNX_RHEL_RANGE(9,3, 9,99)) \
97 && !defined(__NO_FORTIFY) \
98 && defined(__OPTIMIZE__) \
99 && defined(CONFIG_FORTIFY_SOURCE)
100# define RT_BCOPY_UNFORTIFIED(a_pDst, a_pSrc, a_cbToCopy) __underlying_memcpy((a_pDst), (a_pSrc), (a_cbToCopy))
101# else
102# define RT_BCOPY_UNFORTIFIED(a_pDst, a_pSrc, a_cbToCopy) memcpy((a_pDst), (a_pSrc), (a_cbToCopy))
103# endif
104#else /* !RT_OS_LINUX && !__KERNEL__ */
105# define RT_BCOPY_UNFORTIFIED(a_pDst, a_pSrc, a_cbToCopy) memcpy((a_pDst), (a_pSrc), (a_cbToCopy))
106#endif /* !RT_OS_LINUX && !__KERNEL__ */
107
108#endif /* !VBOX_INCLUDED_Graphics_VBoxVideoErr_h */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette