Compile vppinfra on macOS
Add missing calls to clib_mem_init to vppinfra test codes.
Change-Id: I53ffc6fc287d1a378065bb86c18b6e995ecdb775
Signed-off-by: Damjan Marion <damarion@cisco.com>
Signed-off-by: Dave Barach <dave@barachs.net>
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 11f2be9..53cb185 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -61,7 +61,6 @@
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
-find_package(OpenSSL REQUIRED)
include(cmake/memfd.cmake)
include(cmake/api.cmake)
@@ -72,11 +71,18 @@
##############################################################################
# subdirs - order matters
##############################################################################
-foreach(
- DIR
- vppinfra svm vlib vlibmemory vlibapi vnet vpp vat vcl plugins
- vpp-api tools/vppapigen tools/g2 tools/elftool tools/perftool
-)
+if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
+ find_package(OpenSSL REQUIRED)
+ set(SUBDIRS
+ vppinfra svm vlib vlibmemory vlibapi vnet vpp vat vcl plugins
+ vpp-api tools/vppapigen tools/g2 tools/elftool tools/perftool)
+elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
+ set(SUBDIRS vppinfra)
+else()
+ message(FATAL_ERROR "Unsupported system: ${CMAKE_SYSTEM_NAME}")
+endif()
+
+foreach(DIR ${SUBDIRS})
add_subdirectory(${DIR})
endforeach()
diff --git a/src/vppinfra/CMakeLists.txt b/src/vppinfra/CMakeLists.txt
index d5242e8..1e73335 100644
--- a/src/vppinfra/CMakeLists.txt
+++ b/src/vppinfra/CMakeLists.txt
@@ -44,7 +44,6 @@
cpu.c
cuckoo_template.c
elf.c
- elf_clib.c
elog.c
error.c
fheap.c
@@ -84,8 +83,6 @@
vec.c
vector.c
zvec.c
- linux/mem.c
- linux/sysfs.c
)
set(VPPINFRA_HEADERS
@@ -181,6 +178,14 @@
linux/sysfs.h
)
+if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
+ list(APPEND VPPINFRA_SRCS
+ elf_clib.c
+ linux/mem.c
+ linux/sysfs.c
+ )
+endif()
+
if(VPP_USE_DLMALLOC)
list(APPEND VPPINFRA_SRCS
diff --git a/src/vppinfra/elog.c b/src/vppinfra/elog.c
index 182ca12..036dce9 100644
--- a/src/vppinfra/elog.c
+++ b/src/vppinfra/elog.c
@@ -413,7 +413,11 @@
#ifdef CLIB_UNIX
{
#include <sys/syscall.h>
+#ifdef __APPLE__
+ clock_gettime (CLOCK_REALTIME, &ts);
+#else
syscall (SYS_clock_gettime, CLOCK_REALTIME, &ts);
+#endif
cpu_time_now = clib_cpu_time_now ();
/* Subtract 3/30/2017's worth of seconds to retain precision */
os_time_now_nsec = 1e9 * (ts.tv_sec - 1490885108) + ts.tv_nsec;
diff --git a/src/vppinfra/longjmp.S b/src/vppinfra/longjmp.S
index 6468dba..0b7449f 100644
--- a/src/vppinfra/longjmp.S
+++ b/src/vppinfra/longjmp.S
@@ -34,12 +34,21 @@
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-
+
+#if defined(__APPLE__)
+# define cdecl(s) _##s
+#else
+# define cdecl(s) s
+#endif
+
#if defined(__x86_64__)
- .global clib_setjmp
+ .global cdecl(clib_setjmp)
.align 4
- .type clib_setjmp, @function
-clib_setjmp:
+#ifndef __APPLE__
+ .type cdecl(clib_setjmp), @function
+#endif
+
+cdecl(clib_setjmp):
movq %rbx, 8*0(%rdi)
movq %rbp, 8*1(%rdi)
movq %r12, 8*2(%rdi)
@@ -59,10 +68,12 @@
movq %rsi, %rax
ret
- .global clib_longjmp
+ .global cdecl(clib_longjmp)
.align 4
- .type clib_longjmp, @function
-clib_longjmp:
+#ifndef __APPLE__
+ .type cdecl(clib_longjmp), @function
+#endif
+cdecl(clib_longjmp):
/* Restore regs. */
movq 8*0(%rdi), %rbx
movq 8*1(%rdi), %rbp
@@ -79,10 +90,12 @@
/* Away we go. */
jmpq *%rdx
- .global clib_calljmp
+ .global cdecl(clib_calljmp)
.align 4
- .type clib_calljmp, @function
-clib_calljmp:
+#ifndef __APPLE__
+ .type cdecl(clib_calljmp), @function
+#endif
+cdecl(clib_calljmp):
/* Make sure stack is 16-byte aligned. */
movq %rdx, %rax
andq $0xf, %rax
@@ -118,10 +131,10 @@
jmpq *%rdx
#elif defined(i386)
- .global clib_setjmp
+ .global cdecl(clib_setjmp)
.align 4
- .type clib_setjmp, @function
-clib_setjmp:
+ .type cdecl(clib_setjmp), @function
+cdecl(clib_setjmp):
movl 4(%esp), %ecx
movl %ebp, 4*0(%ecx)
@@ -141,10 +154,10 @@
movl 8(%esp), %eax
ret
- .global clib_longjmp
+ .global cdecl(clib_longjmp)
.align 4
- .type clib_longjmp, @function
-clib_longjmp:
+ .type cdecl(clib_longjmp), @function
+cdecl(clib_longjmp):
movl 4(%esp), %ecx
/* Give back user's return value. */
@@ -161,10 +174,10 @@
/* Away we go. */
jmp *%edx
- .global clib_calljmp
+ .global cdecl(clib_calljmp)
.align 4
- .type clib_calljmp, @function
-clib_calljmp:
+ .type cdecl(clib_calljmp), @function
+cdecl(clib_calljmp):
/* Get new stack pointer. */
movl 12(%esp), %edx
@@ -224,7 +237,7 @@
#define CLIB_POWERPC_ALTIVEC_N_REGS 0
#endif
-_prologue (clib_setjmp)
+_prologue (cdecl(clib_setjmp))
mflr 0
std 0, 8*0(3)
std 1, 8*1(3)
@@ -257,7 +270,7 @@
blr
-_prologue (clib_longjmp)
+_prologue (cdecl(clib_longjmp))
ld 0, 8*0(3)
mtlr 0
ld 1, 8*1(3)
@@ -290,14 +303,14 @@
blr
- .globl clib_calljmp
+ .globl cdecl(clib_calljmp)
.section ".opd","aw"
.align 3
-clib_calljmp:
- .quad .L.clib_calljmp,.TOC.@tocbase,0
+cdecl(clib_calljmp):
+ .quad .L.cdecl(clib_calljmp),.TOC.@tocbase,0
.previous
- .type clib_calljmp, @function
-.L.clib_calljmp:
+ .type cdecl(clib_calljmp), @function
+.L.cdecl(clib_calljmp):
mflr 0
mr 9,3
std 0,16(1)
@@ -325,7 +338,7 @@
blr
.long 0
.byte 0,0,0,1,128,0,0,0
- .size clib_calljmp,.-.L.clib_calljmp
+ .size cdecl(clib_calljmp),.-.L.cdecl(clib_calljmp)
#elif defined(__powerpc__)
@@ -344,10 +357,10 @@
#define CLIB_POWERPC_ALTIVEC_N_REGS 0
#endif
- .global clib_setjmp
+ .global cdecl(clib_setjmp)
.align 4
- .type clib_setjmp, @function
-clib_setjmp:
+ .type cdecl(clib_setjmp), @function
+cdecl(clib_setjmp):
mflr 0
stw 0, 4*0(3)
stw 1, 4*1(3)
@@ -380,10 +393,10 @@
blr
- .global clib_longjmp
+ .global cdecl(clib_longjmp)
.align 4
- .type clib_longjmp, @function
-clib_longjmp:
+ .type cdecl(clib_longjmp), @function
+cdecl(clib_longjmp):
lwz 0, 4*0(3)
mtlr 0
@@ -417,10 +430,10 @@
blr
- .global clib_calljmp
+ .global cdecl(clib_calljmp)
.align 4
- .type clib_calljmp, @function
-clib_calljmp:
+ .type cdecl(clib_calljmp), @function
+cdecl(clib_calljmp):
/* Make sure stack is 16 byte aligned. */
andi. 0, 5, 0xf
sub 5, 5, 0
@@ -458,10 +471,10 @@
#elif defined(__arm__)
- .global clib_setjmp
+ .global cdecl(clib_setjmp)
.align 4
- .type clib_setjmp, %function
-clib_setjmp:
+ .type cdecl(clib_setjmp), %function
+cdecl(clib_setjmp):
mov ip, r0 /* jmp buffer */
/* Save integer registers */
@@ -481,10 +494,10 @@
mov r0, r1
bx lr
- .global clib_longjmp
+ .global cdecl(clib_longjmp)
.align 4
- .type clib_longjmp, %function
-clib_longjmp:
+ .type cdecl(clib_longjmp), %function
+cdecl(clib_longjmp):
mov ip, r0 /* jmp buffer */
/* Restore integer registers. */
@@ -504,10 +517,10 @@
mov r0, r1
bx lr
- .global clib_calljmp
+ .global cdecl(clib_calljmp)
.align 4
- .type clib_calljmp, %function
-clib_calljmp:
+ .type cdecl(clib_calljmp), %function
+cdecl(clib_calljmp):
/* Make sure stack is 8 byte aligned. */
bic r2, r2, #7
@@ -541,51 +554,51 @@
#elif defined(__xtensa__)
/* FIXME implement if needed. */
- .global clib_setjmp
+ .global cdecl(clib_setjmp)
.align 4
- .type clib_setjmp, %function
-clib_setjmp:
+ .type cdecl(clib_setjmp), %function
+cdecl(clib_setjmp):
1: j 1b
- .global clib_longjmp
+ .global cdecl(clib_longjmp)
.align 4
- .type clib_longjmp, @function
-clib_longjmp:
+ .type cdecl(clib_longjmp), @function
+cdecl(clib_longjmp):
1: j 1b
- .global clib_calljmp
+ .global cdecl(clib_calljmp)
.align 4
- .type clib_calljmp, %function
-clib_calljmp:
+ .type cdecl(clib_calljmp), %function
+cdecl(clib_calljmp):
1: j 1b
#elif defined(__TMS320C6X__)
/* FIXME implement if needed. */
- .global clib_setjmp
+ .global cdecl(clib_setjmp)
.align 4
- .type clib_setjmp, %function
-clib_setjmp:
+ .type cdecl(clib_setjmp), %function
+cdecl(clib_setjmp):
1: B .S1 1b
- .global clib_longjmp
+ .global cdecl(clib_longjmp)
.align 4
- .type clib_longjmp, @function
-clib_longjmp:
+ .type cdecl(clib_longjmp), @function
+cdecl(clib_longjmp):
1: B .S1 1b
- .global clib_calljmp
+ .global cdecl(clib_calljmp)
.align 4
- .type clib_calljmp, %function
-clib_calljmp:
+ .type cdecl(clib_calljmp), %function
+cdecl(clib_calljmp):
1: B .S1 1b
#elif defined(_mips) && __mips == 64
- .global clib_setjmp
+ .global cdecl(clib_setjmp)
.align 8
- .type clib_setjmp, %function
-clib_setjmp:
+ .type cdecl(clib_setjmp), %function
+cdecl(clib_setjmp):
sd $ra, 0($a0)
sd $sp, 8($a0)
sd $gp, 16($a0)
@@ -602,10 +615,10 @@
jr $ra
nop
- .global clib_longjmp
+ .global cdecl(clib_longjmp)
.align 8
- .type clib_longjmp, @function
-clib_longjmp:
+ .type cdecl(clib_longjmp), @function
+cdecl(clib_longjmp):
move $v0, $a1
bne $v0, $0, 1f
nop
@@ -626,10 +639,10 @@
jr $ra
nop
- .global clib_calljmp
+ .global cdecl(clib_calljmp)
.align 8
- .type clib_calljmp, %function
-clib_calljmp:
+ .type cdecl(clib_calljmp), %function
+cdecl(clib_calljmp):
/* Force 16 byte alignment of the new stack */
li $t1, -16
and $t0, $a2, $t1
@@ -693,10 +706,10 @@
REG_PAIR (d10, d11, 128); \
REG_PAIR (d12, d13, 144); \
REG_PAIR (d14, d15, 160);
-// int clib_setjmp (jmp_buf)
- .global clib_setjmp
- .type clib_setjmp, %function
-clib_setjmp:
+// int cdecl(clib_setjmp) (jmp_buf)
+ .global cdecl(clib_setjmp)
+ .type cdecl(clib_setjmp), %function
+cdecl(clib_setjmp):
mov x16, sp
#define REG_PAIR(REG1, REG2, OFFS) stp REG1, REG2, [x0, OFFS]
#define REG_ONE(REG1, OFFS) str REG1, [x0, OFFS]
@@ -706,11 +719,11 @@
#undef REG_ONE
mov x0, x1
ret
- .size clib_setjmp, .-clib_setjmp
-// void clib_longjmp (jmp_buf, int) __attribute__ ((noreturn))
- .global clib_longjmp
- .type clib_longjmp, %function
-clib_longjmp:
+ .size cdecl(clib_setjmp), .-cdecl(clib_setjmp)
+// void cdecl(clib_longjmp) (jmp_buf, int) __attribute__ ((noreturn))
+ .global cdecl(clib_longjmp)
+ .type cdecl(clib_longjmp), %function
+cdecl(clib_longjmp):
#define REG_PAIR(REG1, REG2, OFFS) ldp REG1, REG2, [x0, OFFS]
#define REG_ONE(REG1, OFFS) ldr REG1, [x0, OFFS]
GPR_LAYOUT
@@ -723,13 +736,13 @@
// cinc w0, w1, eq
// use br not ret, as ret is guaranteed to mispredict
br x30
- .size clib_longjmp, .-clib_longjmp
+ .size cdecl(clib_longjmp), .-cdecl(clib_longjmp)
-// void clib_calljmp (x0=function, x1=arg, x2=new_stack)
- .global clib_calljmp
- .type clib_calljmp, %function
-clib_calljmp:
+// void cdecl(clib_calljmp) (x0=function, x1=arg, x2=new_stack)
+ .global cdecl(clib_calljmp)
+ .type cdecl(clib_calljmp), %function
+cdecl(clib_calljmp):
// save fn ptr
mov x3, x0
// set up fn arg
@@ -756,9 +769,11 @@
ldr x30,[x4, #8]
mov sp, x3
ret
- .size clib_calljmp, .-clib_calljmp
+ .size cdecl(clib_calljmp), .-cdecl(clib_calljmp)
#else
#error "unknown machine"
#endif
+#ifndef __APPLE__
.section .note.GNU-stack,"",%progbits
+#endif
diff --git a/src/vppinfra/mem_dlmalloc.c b/src/vppinfra/mem_dlmalloc.c
index 4a0d032..8afb050 100644
--- a/src/vppinfra/mem_dlmalloc.c
+++ b/src/vppinfra/mem_dlmalloc.c
@@ -354,7 +354,7 @@
{
if (i > 0)
s = format (s, "%U", format_white_space, indent);
-#ifdef CLIB_UNIX
+#if defined(CLIB_UNIX) && !defined(__APPLE__)
/* $$$$ does this actually work? */
s =
format (s, " %U\n", format_clib_elf_symbol_with_address,
diff --git a/src/vppinfra/socket.c b/src/vppinfra/socket.c
index 87a9333..29b2a94 100644
--- a/src/vppinfra/socket.c
+++ b/src/vppinfra/socket.c
@@ -309,12 +309,16 @@
default_socket_recvmsg (clib_socket_t * s, void *msg, int msglen,
int fds[], int num_fds)
{
+#ifdef __linux__
char ctl[CMSG_SPACE (sizeof (int) * num_fds) +
CMSG_SPACE (sizeof (struct ucred))];
+ struct ucred *cr = 0;
+#else
+ char ctl[CMSG_SPACE (sizeof (int) * num_fds)];
+#endif
struct msghdr mh = { 0 };
struct iovec iov[1];
ssize_t size;
- struct ucred *cr = 0;
struct cmsghdr *cmsg;
iov[0].iov_base = msg;
@@ -340,6 +344,7 @@
{
if (cmsg->cmsg_level == SOL_SOCKET)
{
+#ifdef __linux__
if (cmsg->cmsg_type == SCM_CREDENTIALS)
{
cr = (struct ucred *) CMSG_DATA (cmsg);
@@ -347,7 +352,9 @@
s->gid = cr->gid;
s->pid = cr->pid;
}
- else if (cmsg->cmsg_type == SCM_RIGHTS)
+ else
+#endif
+ if (cmsg->cmsg_type == SCM_RIGHTS)
{
clib_memcpy (fds, CMSG_DATA (cmsg), num_fds * sizeof (int));
}
@@ -436,6 +443,7 @@
clib_unix_warning ("setsockopt SO_REUSEADDR fails");
}
+#if __linux__
if (addr.sa.sa_family == PF_LOCAL && s->flags & CLIB_SOCKET_F_PASSCRED)
{
int x = 1;
@@ -447,6 +455,7 @@
goto done;
}
}
+#endif
if (need_bind && bind (s->fd, &addr.sa, addr_len) < 0)
{
diff --git a/src/vppinfra/test_format.c b/src/vppinfra/test_format.c
index cc95a00..8370be7 100644
--- a/src/vppinfra/test_format.c
+++ b/src/vppinfra/test_format.c
@@ -180,6 +180,8 @@
{
unformat_input_t i;
+ clib_mem_init (0, 3ULL << 30);
+
verbose = (argc > 1);
unformat_init_command_line (&i, argv);
diff --git a/src/vppinfra/test_hash.c b/src/vppinfra/test_hash.c
index 94110ab..7f047d9 100644
--- a/src/vppinfra/test_hash.c
+++ b/src/vppinfra/test_hash.c
@@ -440,6 +440,8 @@
unformat_input_t i;
int ret;
+ clib_mem_init (0, 3ULL << 30);
+
verbose = (argc > 1);
unformat_init_command_line (&i, argv);
ret = test_hash_main (&i);
diff --git a/src/vppinfra/test_longjmp.c b/src/vppinfra/test_longjmp.c
index 2415c4f..01debe2 100644
--- a/src/vppinfra/test_longjmp.c
+++ b/src/vppinfra/test_longjmp.c
@@ -112,6 +112,8 @@
unformat_input_t i;
int res;
+ clib_mem_init (0, 64 << 20);
+
verbose = (argc > 1);
unformat_init_command_line (&i, argv);
res = test_longjmp_main (&i);
diff --git a/src/vppinfra/test_macros.c b/src/vppinfra/test_macros.c
index 05299b3..cf6172a 100644
--- a/src/vppinfra/test_macros.c
+++ b/src/vppinfra/test_macros.c
@@ -47,6 +47,8 @@
unformat_input_t i;
int ret;
+ clib_mem_init (0, 64ULL << 20);
+
unformat_init_command_line (&i, argv);
ret = test_macros_main (&i);
unformat_free (&i);
diff --git a/src/vppinfra/test_maplog.c b/src/vppinfra/test_maplog.c
index 7ae70c5..f3ff662 100644
--- a/src/vppinfra/test_maplog.c
+++ b/src/vppinfra/test_maplog.c
@@ -123,6 +123,8 @@
unformat_input_t i;
int ret;
+ clib_mem_init (0, 64ULL << 20);
+
unformat_init_command_line (&i, argv);
ret = test_maplog_main (&i);
unformat_free (&i);
diff --git a/src/vppinfra/test_phash.c b/src/vppinfra/test_phash.c
index 9ed2ac7..47711c2 100644
--- a/src/vppinfra/test_phash.c
+++ b/src/vppinfra/test_phash.c
@@ -132,6 +132,8 @@
unformat_input_t i;
int res;
+ clib_mem_init (0, 64ULL << 20);
+
verbose = (argc > 1);
unformat_init_command_line (&i, argv);
res = test_phash_main (&i);
diff --git a/src/vppinfra/test_pool_iterate.c b/src/vppinfra/test_pool_iterate.c
index 406a2a5..4e8e2df 100644
--- a/src/vppinfra/test_pool_iterate.c
+++ b/src/vppinfra/test_pool_iterate.c
@@ -32,6 +32,8 @@
u32 *tp = 0;
u32 *junk;
+ clib_mem_init (0, 64ULL << 20);
+
for (i = 0; i < 70; i++)
{
pool_get (tp, junk);
diff --git a/src/vppinfra/test_qhash.c b/src/vppinfra/test_qhash.c
index fdbf0bb..68e8cbc 100644
--- a/src/vppinfra/test_qhash.c
+++ b/src/vppinfra/test_qhash.c
@@ -311,6 +311,8 @@
unformat_input_t i;
clib_error_t *error;
+ clib_mem_init (0, 64ULL << 20);
+
unformat_init_command_line (&i, argv);
error = test_qhash_main (&i);
unformat_free (&i);
diff --git a/src/vppinfra/test_random_isaac.c b/src/vppinfra/test_random_isaac.c
index 337d30d..bed8673 100644
--- a/src/vppinfra/test_random_isaac.c
+++ b/src/vppinfra/test_random_isaac.c
@@ -123,6 +123,8 @@
unformat_input_t i;
int ret;
+ clib_mem_init (0, 64ULL << 20);
+
verbose = (argc > 1);
unformat_init_command_line (&i, argv);
ret = test_isaac_main (&i);
diff --git a/src/vppinfra/test_serialize.c b/src/vppinfra/test_serialize.c
index 6351b05..09f3808 100644
--- a/src/vppinfra/test_serialize.c
+++ b/src/vppinfra/test_serialize.c
@@ -258,6 +258,8 @@
unformat_input_t i;
int r;
+ clib_mem_init (0, 64ULL << 20);
+
unformat_init_command_line (&i, argv);
r = test_serialize_main (&i);
unformat_free (&i);
diff --git a/src/vppinfra/test_socket.c b/src/vppinfra/test_socket.c
index 2f25ecc..ea0ae65 100644
--- a/src/vppinfra/test_socket.c
+++ b/src/vppinfra/test_socket.c
@@ -117,6 +117,8 @@
unformat_input_t i;
int r;
+ clib_mem_init (0, 64ULL << 20);
+
verbose = (argc > 1);
unformat_init_command_line (&i, argv);
r = test_socket_main (&i);
diff --git a/src/vppinfra/test_time.c b/src/vppinfra/test_time.c
index 63cfeac..80c0e3a 100644
--- a/src/vppinfra/test_time.c
+++ b/src/vppinfra/test_time.c
@@ -86,6 +86,8 @@
unformat_input_t i;
int ret;
+ clib_mem_init (0, 64ULL << 20);
+
verbose = (argc > 1);
unformat_init_command_line (&i, argv);
ret = test_time_main (&i);
diff --git a/src/vppinfra/test_time_range.c b/src/vppinfra/test_time_range.c
index ccb63b2..2ec6e13 100644
--- a/src/vppinfra/test_time_range.c
+++ b/src/vppinfra/test_time_range.c
@@ -162,6 +162,8 @@
unformat_input_t i;
int ret;
+ clib_mem_init (0, 64ULL << 20);
+
unformat_init_command_line (&i, argv);
ret = test_time_range_main (&i);
unformat_free (&i);
diff --git a/src/vppinfra/test_timing_wheel.c b/src/vppinfra/test_timing_wheel.c
index 0ce15ad..7cf6e0c 100644
--- a/src/vppinfra/test_timing_wheel.c
+++ b/src/vppinfra/test_timing_wheel.c
@@ -367,6 +367,8 @@
unformat_input_t i;
clib_error_t *error;
+ clib_mem_init (0, 64ULL << 20);
+
unformat_init_command_line (&i, argv);
error = test_timing_wheel_main (&i);
unformat_free (&i);
diff --git a/src/vppinfra/test_vec.c b/src/vppinfra/test_vec.c
index d60d27b..d02d71c 100644
--- a/src/vppinfra/test_vec.c
+++ b/src/vppinfra/test_vec.c
@@ -1173,8 +1173,6 @@
clib_mem_init (0, 3ULL << 30);
- // mheap_alloc (0, (uword) 10ULL << 30);
-
verbose = (argc > 1);
unformat_init_command_line (&i, argv);
ret = test_vec_main (&i);
diff --git a/src/vppinfra/test_vhash.c b/src/vppinfra/test_vhash.c
index 7293fdd..f5aa5e2 100644
--- a/src/vppinfra/test_vhash.c
+++ b/src/vppinfra/test_vhash.c
@@ -741,6 +741,8 @@
unformat_input_t i;
int r;
+ clib_mem_init (0, 64ULL << 20);
+
unformat_init_command_line (&i, argv);
r = test_vhash_main (&i);
unformat_free (&i);
diff --git a/src/vppinfra/test_zvec.c b/src/vppinfra/test_zvec.c
index 874fdef..7d777fa 100644
--- a/src/vppinfra/test_zvec.c
+++ b/src/vppinfra/test_zvec.c
@@ -98,6 +98,8 @@
unformat_input_t i;
int ret;
+ clib_mem_init (0, 64ULL << 20);
+
verbose = (argc > 1);
unformat_init_command_line (&i, argv);
ret = test_zvec_main (&i);
diff --git a/src/vppinfra/time.h b/src/vppinfra/time.h
index ced9677..64370d5 100644
--- a/src/vppinfra/time.h
+++ b/src/vppinfra/time.h
@@ -237,10 +237,14 @@
always_inline f64
unix_time_now (void)
{
+ struct timespec ts;
+#ifdef __MACH__
+ clock_gettime (CLOCK_REALTIME, &ts);
+#else
/* clock_gettime without indirect syscall uses GLIBC wrappers which
we don't want. Just the bare metal, please. */
- struct timespec ts;
syscall (SYS_clock_gettime, CLOCK_REALTIME, &ts);
+#endif
return ts.tv_sec + 1e-9 * ts.tv_nsec;
}
@@ -249,7 +253,11 @@
unix_time_now_nsec (void)
{
struct timespec ts;
+#ifdef __MACH__
+ clock_gettime (CLOCK_REALTIME, &ts);
+#else
syscall (SYS_clock_gettime, CLOCK_REALTIME, &ts);
+#endif
return 1e9 * ts.tv_sec + ts.tv_nsec;
}
@@ -257,7 +265,11 @@
unix_time_now_nsec_fraction (u32 * sec, u32 * nsec)
{
struct timespec ts;
+#ifdef __MACH__
+ clock_gettime (CLOCK_REALTIME, &ts);
+#else
syscall (SYS_clock_gettime, CLOCK_REALTIME, &ts);
+#endif
*sec = ts.tv_sec;
*nsec = ts.tv_nsec;
}
diff --git a/src/vppinfra/timer.c b/src/vppinfra/timer.c
index 85149dc..8bbab65 100644
--- a/src/vppinfra/timer.c
+++ b/src/vppinfra/timer.c
@@ -46,6 +46,10 @@
#include <vppinfra/timer.h>
#include <vppinfra/error.h>
+#ifndef HZ
+#define HZ 1000
+#endif
+
typedef struct
{
f64 time;
@@ -112,14 +116,14 @@
vector of pending timers. */
t = vec_end (timers) - 1;
- ASSERT (now >= 0 && finite (now));
+ ASSERT (now >= 0 && isfinite (now));
/* Time difference between when timer goes off and now. */
dt = t->time - now;
/* If timer is within threshold of going off
call user's callback. */
- if (dt <= time_resolution && finite (dt))
+ if (dt <= time_resolution && isfinite (dt))
{
_vec_len (timers) -= 1;
(*t->func) (t->arg, -dt);
diff --git a/src/vppinfra/unix-formats.c b/src/vppinfra/unix-formats.c
index b3b8c89..c447329 100644
--- a/src/vppinfra/unix-formats.c
+++ b/src/vppinfra/unix-formats.c
@@ -37,11 +37,17 @@
#ifdef __KERNEL__
+#if __linux__
# include <linux/unistd.h>
# include <linux/signal.h>
+#endif
#else /* ! __KERNEL__ */
+#ifdef __APPLE__
+#define _XOPEN_SOURCE
+#endif
+
#define _GNU_SOURCE /* to get REG_* in ucontext.h */
#include <ucontext.h>
#undef _GNU_SOURCE
@@ -57,12 +63,14 @@
#include <math.h>
#include <vppinfra/time.h>
+#if __linux__
#include <vppinfra/linux/syscall.h>
#ifdef AF_NETLINK
#include <linux/types.h>
#include <linux/netlink.h>
#endif
+#endif
#endif /* ! __KERNEL__ */
@@ -277,6 +285,7 @@
return s;
}
+#ifndef __APPLE__
u8 * format_tcp4_packet (u8 * s, va_list * args)
{
u8 * p = va_arg (*args, u8 *);
@@ -832,6 +841,7 @@
return s;
}
+#endif
u8 * format_time_float (u8 * s, va_list * args)
{