summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_unit_sptr.h
blob: 6d867a5e5b28a661c8620b8713d4db4476f6c050 (plain) (blame)
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

/*
 * Copyright (C) NGINX, Inc.
 */

#ifndef _NXT_UNIT_SPTR_H_INCLUDED_
#define _NXT_UNIT_SPTR_H_INCLUDED_


#include <inttypes.h>
#include <stddef.h>
#include <string.h>

#include "nxt_unit_typedefs.h"


/* Serialized pointer. */
union nxt_unit_sptr_u {
    uint8_t   base[1];
    uint32_t  offset;
};


static inline void
nxt_unit_sptr_set(nxt_unit_sptr_t *sptr, void *ptr)
{
    const uint8_t  *base;

    base = sptr->base;
    sptr->offset = (uint8_t *) ptr - base;
}


static inline void *
nxt_unit_sptr_get(nxt_unit_sptr_t *sptr)
{
    return sptr->base + sptr->offset;
}


#endif /* _NXT_UNIT_SPTR_H_INCLUDED_ */