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