summaryrefslogtreecommitdiff
path: root/src/pal/src/include/pal/shm.hpp
blob: de1d09e63644136610520206e175e56ddec1e1d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

/*++



Module Name:

    include/pal/shm.hpp

Abstract:
    C++ typesafe accessors for shared memory routines



--*/

#ifndef _SHM_HPP_
#define _SHM_HPP_

#include "shmemory.h"

//
// Some compilers (e.g., HPUX/IA64) warn about using NULL to initialize
// something of type SHMPTR, since SHMPTR is defined as DWORD_PTR, which
// isn't considered a pointer type...
//

#define SHMNULL 0

#ifndef _DEBUG

inline
void *
ShmPtrToPtrFast(SHMPTR shmptr)
{
    void *pv = NULL;
    
    if (SHMNULL != shmptr)
    {
        int segment = shmptr >> 24;

        if (segment < shm_numsegments)
        {
            pv = reinterpret_cast<void*>(
                reinterpret_cast<DWORD_PTR>(shm_segment_bases[(uint)segment].Load())
                + (shmptr & 0x00FFFFFF)
                );
        }
        else
        {
            pv = SHMPtrToPtr(shmptr);
        }
    }

    return pv;
}

//
// We could use a function template here to avoid the cast / macro
//

#define SHMPTR_TO_TYPED_PTR(type, shmptr) reinterpret_cast<type*>(ShmPtrToPtrFast((shmptr)))

#else

#define SHMPTR_TO_TYPED_PTR(type, shmptr) reinterpret_cast<type*>(SHMPtrToPtr((shmptr)))

#endif

/* Set ptr to NULL if shmPtr == 0, else set ptr to SHMPTR_TO_TYPED_PTR(type, shmptr) 
   return FALSE if SHMPTR_TO_TYPED_PTR returns NULL ptr from non null shmptr, 
   TRUE otherwise */
#define SHMPTR_TO_TYPED_PTR_BOOL(type, ptr, shmptr) \
    ((shmptr != 0) ? ((ptr = SHMPTR_TO_TYPED_PTR(type, shmptr)) != NULL) : ((ptr = NULL) == NULL))




#endif // _SHM_HPP_