xref: /f-stack/lib/ff_host_interface.h (revision 8d76b62e)
1 /*
2  * Copyright (c) 2013 Patrick Kelsey. All rights reserved.
3  * Copyright (C) 2017 THL A29 Limited, a Tencent company.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice, this
10  *   list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  *   this list of conditions and the following disclaimer in the documentation
13  *   and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
19  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * Derived in part from libuinet's uinet_host_interface.h.
27  */
28 
29 #ifndef _FSTACK_HOST_INTERFACE_H_
30 #define _FSTACK_HOST_INTERFACE_H_
31 
32 #define ff_PROT_NONE     0x00
33 #define ff_PROT_READ     0x01
34 #define ff_PROT_WRITE    0x02
35 
36 #define ff_MAP_SHARED    0x0001
37 #define ff_MAP_PRIVATE   0x0002
38 #define ff_MAP_ANON      0x1000
39 #define ff_MAP_NOCORE    0x00020000
40 
41 #define ff_MAP_FAILED    ((void *)-1)
42 
43 void *ff_mmap(void *addr, uint64_t len, int prot, int flags, int fd, uint64_t offset);
44 int ff_munmap(void *addr, uint64_t len);
45 
46 void *ff_malloc(uint64_t size);
47 void *ff_calloc(uint64_t number, uint64_t size);
48 void *ff_realloc(void *p, uint64_t size);
49 void ff_free(void *p);
50 
51 #define ff_CLOCK_REALTIME        0
52 #define ff_CLOCK_MONOTONIC        4
53 #define ff_CLOCK_MONOTONIC_FAST       12
54 
55 #define ff_NSEC_PER_SEC    (1000ULL * 1000ULL * 1000ULL)
56 
57 void ff_clock_gettime(int id, int64_t *sec, long *nsec);
58 uint64_t ff_clock_gettime_ns(int id);
59 uint64_t ff_get_tsc_ns(void);
60 
61 void ff_get_current_time(int64_t *sec, long *nsec);
62 void ff_update_current_ts(void);
63 
64 typedef void * ff_mutex_t;
65 typedef void * ff_cond_t;
66 typedef void * ff_rwlock_t;
67 
68 void ff_arc4rand(void *ptr, unsigned int len, int reseed);
69 uint32_t ff_arc4random(void);
70 
71 int ff_setenv(const char *name, const char *value);
72 char *ff_getenv(const char *name);
73 
74 void ff_os_errno(int error);
75 
76 int ff_in_pcbladdr(uint16_t family, void *faddr, uint16_t fport, void *laddr);
77 
78 int ff_rss_check(void *softc, uint32_t saddr, uint32_t daddr,
79     uint16_t sport, uint16_t dport);
80 
81 #endif
82 
83