1 
2 /*
3  * Copyright (C) NGINX, Inc.
4  */
5 
6 #ifndef _NXT_UNIT_SPTR_H_INCLUDED_
7 #define _NXT_UNIT_SPTR_H_INCLUDED_
8 
9 
10 #include <inttypes.h>
11 #include <stddef.h>
12 #include <string.h>
13 
14 #include "nxt_unit_typedefs.h"
15 
16 
17 /* Serialized pointer. */
18 union nxt_unit_sptr_u {
19     uint8_t   base[1];
20     uint32_t  offset;
21 };
22 
23 
24 static inline void
nxt_unit_sptr_set(nxt_unit_sptr_t * sptr,void * ptr)25 nxt_unit_sptr_set(nxt_unit_sptr_t *sptr, void *ptr)
26 {
27     sptr->offset = (uint8_t *) ptr - sptr->base;
28 }
29 
30 
31 static inline void *
nxt_unit_sptr_get(nxt_unit_sptr_t * sptr)32 nxt_unit_sptr_get(nxt_unit_sptr_t *sptr)
33 {
34     return sptr->base + sptr->offset;
35 }
36 
37 
38 #endif /* _NXT_UNIT_SPTR_H_INCLUDED_ */
39