VirtualBox

source: vbox/trunk/include/iprt/shmem.h@ 76327

Last change on this file since 76327 was 75883, checked in by vboxsync, 6 years ago

IPRT/shmem: Make doxygen and scm happy.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.5 KB
Line 
1/** @file
2 * IPRT - Named shared memory.
3 */
4
5/*
6 * Copyright (C) 2018 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef ___iprt_shmem_h
27#define ___iprt_shmem_h
28
29#include <iprt/types.h>
30
31RT_C_DECLS_BEGIN
32
33/** @defgroup grp_rt_shmem RTShMem - Shared memory.
34 * @ingroup grp_rt
35 */
36
37/** @name Open flags for RTShMemOpen().
38 * @{
39 */
40/** Creates a new shared memory object or opens an already existing one. */
41#define RTSHMEM_O_F_CREATE RT_BIT_32(0)
42/** Creates a new shared memory object failing if one with the same name exists already. */
43#define RTSHMEM_O_F_CREATE_EXCL (RTSHMEM_O_F_CREATE | RT_BIT_32(1))
44/** Opens the shared memory object for read access. */
45#define RTSHMEM_O_F_READ RT_BIT_32(2)
46/** Opens the shared memory object for write access. */
47#define RTSHMEM_O_F_WRITE RT_BIT_32(3)
48/** Opens the shared memory object for read and write access. */
49#define RTSHMEM_O_F_READWRITE (RTSHMEM_O_F_READ | RTSHMEM_O_F_WRITE)
50/** Truncates the shared memory object to 0 bytes on open. */
51#define RTSHMEM_O_F_TRUNCATE RT_BIT_32(4)
52/** Mappings may be created with executable access right (required to be known on Windows beforehand). */
53#define RTSHMEM_O_F_MAYBE_EXEC RT_BIT_32(5)
54/** Mask of all valid flags. */
55#define RTSHMEM_O_F_VALID_MASK UINT32_C(0x0000003f)
56/** @} */
57
58/**
59 * Creates or opens a new shared memory object with the given name.
60 *
61 * @returns IPRT status code.
62 * @retval VERR_OUT_OF_RANGE if the mapping hint count is too big.
63 * @param phShMem Where to store the handle to the shared memory object on success.
64 * @param pszName Name of the shared memory object to open or create.
65 * @param fFlags Combination of RTSHMEM_O_F_* flags.
66 * @param cbMax Maximum number of bytes to reserve for the shared memory object.
67 * On some platforms this can be 0 and set to another value using RTShMemSetSize() afterwards.
68 * Giving 0 on Windows results in an error as shared memory objects there do not support
69 * changing the size afterwards.
70 * @param cMappingsHint Hint about the possible number of mappings created later on, set to 0 for a default value.
71 */
72RTDECL(int) RTShMemOpen(PRTSHMEM phShMem, const char *pszName, uint32_t fFlags, size_t cbMax, uint32_t cMappingsHint);
73
74/**
75 * Closes the given shared memory object.
76 *
77 * @returns IPRT status code.
78 * @retval VERR_INVALID_STATE if there is still a mapping active for the given shared memory object.
79 * @param hShMem The shared memory object handle.
80 *
81 * @note The shared memory object will be deleted if the creator closes it.
82 */
83RTDECL(int) RTShMemClose(RTSHMEM hShMem);
84
85/**
86 * Returns the number of references (i.e. mappings) held for the given shared memory object.
87 *
88 * @returns Reference count or 0 on invalid handle.
89 * @param hShMem The shared memory object handle.
90 */
91RTDECL(uint32_t) RTShMemRefCount(RTSHMEM hShMem);
92
93/**
94 * Sets the size of the given shared memory object.
95 *
96 * @returns IPRT status code.
97 * @retval VERR_INVALID_STATE if there are mappings active for the given shared memory object.
98 * @retval VERR_NOT_SUPPORTED on some hosts which do not support changing the size after creation.
99 * @param hShMem The shared memory object handle.
100 * @param cbMem Size of the memory object handle in bytes.
101 */
102RTDECL(int) RTShMemSetSize(RTSHMEM hShMem, size_t cbMem);
103
104/**
105 * Queries the current size of the shared memory object.
106 *
107 * @returns IPRT status code.
108 * @param hShMem The shared memory object handle.
109 * @param pcbMem Where to store the size of the shared memory object on success.
110 */
111RTDECL(int) RTShMemQuerySize(RTSHMEM hShMem, size_t *pcbMem);
112
113/** @name Region mapping flags for RTShMemMapRegion().
114 * @{
115 */
116/** Read access. */
117#define RTSHMEM_MAP_F_READ RT_BIT_32(0)
118/** Write access. */
119#define RTSHMEM_MAP_F_WRITE RT_BIT_32(1)
120/** Execute access. */
121#define RTSHMEM_MAP_F_EXEC RT_BIT_32(2)
122/** Copy on write, any write creates a new page private to the callers address space and changes
123 * in that area are not shared with other processes using the hsared memory object. */
124#define RTSHMEM_MAP_F_COW RT_BIT_32(3)
125/** Mask of all valid flags. */
126#define RTSHMEM_MAP_F_VALID_MASK UINT32_C(0x0000000f)
127/** @} */
128
129/**
130 * Maps a region of the given shared memory object into the callers address space.
131 *
132 * @returns IPRT status code.
133 * @retval VERR_SHMEM_MAXIMUM_MAPPINGS_REACHED if the maximum number of mappings was reached (host dependent).
134 * @retval VERR_ACCESS_DENIED if the requested memory access rights do not line up with the flags given when opening
135 * the memory object (requesting write access for a readonly shared memory object for example).
136 * @param hShMem The shared memory object handle.
137 * @param offRegion Offset into the shared memory object to start mapping at.
138 * @param cbRegion Size of the region to map.
139 * @param fFlags Desired properties of the mapped region, combination of RTSHMEM_MAP_F_* defines.
140 * @param ppv Where to store the start address of the mapped region on success.
141 */
142RTDECL(int) RTShMemMapRegion(RTSHMEM hShMem, size_t offRegion, size_t cbRegion, uint32_t fFlags, void **ppv);
143
144/**
145 * Unmaps the given region of the shared memory object.
146 *
147 * @returns IPRT status code.
148 * @param hShMem The shared memory object handle.
149 * @param pv Pointer to the mapped region obtained with RTShMemMapRegion() earlier on.
150 */
151RTDECL(int) RTShMemUnmapRegion(RTSHMEM hShMem, void *pv);
152
153/** @} */
154RT_C_DECLS_END
155
156#endif
157
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