aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2018-09-03 12:30:36 +0200
committerDamjan Marion <dmarion@me.com>2018-09-03 16:51:40 +0000
commit4dffd1c9988020619caff9b8d3b350e7f79e0398 (patch)
tree58d6b48f3925e815b68dfe04d3946c80ad1c24a1 /src
parentea5b5be4eeb0f4cd80cb466bd6e31cad33c57960 (diff)
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>
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt18
-rw-r--r--src/vppinfra/CMakeLists.txt11
-rw-r--r--src/vppinfra/elog.c4
-rw-r--r--src/vppinfra/longjmp.S189
-rw-r--r--src/vppinfra/mem_dlmalloc.c2
-rw-r--r--src/vppinfra/socket.c13
-rw-r--r--src/vppinfra/test_format.c2
-rw-r--r--src/vppinfra/test_hash.c2
-rw-r--r--src/vppinfra/test_longjmp.c2
-rw-r--r--src/vppinfra/test_macros.c2
-rw-r--r--src/vppinfra/test_maplog.c2
-rw-r--r--src/vppinfra/test_phash.c2
-rw-r--r--src/vppinfra/test_pool_iterate.c2
-rw-r--r--src/vppinfra/test_qhash.c2
-rw-r--r--src/vppinfra/test_random_isaac.c2
-rw-r--r--src/vppinfra/test_serialize.c2
-rw-r--r--src/vppinfra/test_socket.c2
-rw-r--r--src/vppinfra/test_time.c2
-rw-r--r--src/vppinfra/test_time_range.c2
-rw-r--r--src/vppinfra/test_timing_wheel.c2
-rw-r--r--src/vppinfra/test_vec.c2
-rw-r--r--src/vppinfra/test_vhash.c2
-rw-r--r--src/vppinfra/test_zvec.c2
-rw-r--r--src/vppinfra/time.h14
-rw-r--r--src/vppinfra/timer.c8
-rw-r--r--src/vppinfra/unix-formats.c10
26 files changed, 199 insertions, 104 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 11f2be90d9f..53cb185f1ae 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -61,7 +61,6 @@ set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "vpp")
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 @@ include(cmake/plugin.cmake)
##############################################################################
# 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 d5242e88066..1e73335275e 100644
--- a/src/vppinfra/CMakeLists.txt
+++ b/src/vppinfra/CMakeLists.txt
@@ -44,7 +44,6 @@ set(VPPINFRA_SRCS
cpu.c
cuckoo_template.c
elf.c
- elf_clib.c
elog.c
error.c
fheap.c
@@ -84,8 +83,6 @@ set(VPPINFRA_SRCS
vec.c
vector.c
zvec.c
- linux/mem.c
- linux/sysfs.c
)
set(VPPINFRA_HEADERS
@@ -181,6 +178,14 @@ set(VPPINFRA_HEADERS
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 182ca127b12..036dce98f32 100644
--- a/src/vppinfra/elog.c
+++ b/src/vppinfra/elog.c
@@ -413,7 +413,11 @@ elog_time_now (elog_time_stamp_t * et)
#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 6468dba45bf..0b7449f8669 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 @@ clib_setjmp:
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 @@ clib_longjmp:
/* 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 @@ clib_calljmp:
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 @@ clib_setjmp:
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 @@ clib_longjmp:
/* 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 @@ _ (26, 6) _ (27, 7) _ (28, 8) _ (29, 9) _ (30, 10) _ (31, 11)
#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 @@ _prologue (clib_setjmp)
blr
-_prologue (clib_longjmp)
+_prologue (cdecl(clib_longjmp))
ld 0, 8*0(3)
mtlr 0
ld 1, 8*1(3)
@@ -290,14 +303,14 @@ _prologue (clib_longjmp)
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 @@ clib_calljmp:
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 @@ _ (26, 6) _ (27, 7) _ (28, 8) _ (29, 9) _ (30, 10) _ (31, 11)
#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 @@ clib_setjmp:
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 @@ clib_longjmp:
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 @@ clib_calljmp:
#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 @@ clib_setjmp:
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 @@ clib_longjmp:
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 @@ clib_calljmp:
#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 @@ clib_setjmp:
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 @@ clib_longjmp:
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 @@ clib_calljmp:
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 @@ clib_setjmp:
#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 @@ clib_longjmp:
// 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 @@ clib_calljmp:
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 4a0d032785e..8afb0507092 100644
--- a/src/vppinfra/mem_dlmalloc.c
+++ b/src/vppinfra/mem_dlmalloc.c
@@ -354,7 +354,7 @@ format_mheap_trace (u8 * s, va_list * va)
{
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 87a9333f904..29b2a945cb9 100644
--- a/src/vppinfra/socket.c
+++ b/src/vppinfra/socket.c
@@ -309,12 +309,16 @@ static clib_error_t *
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 @@ default_socket_recvmsg (clib_socket_t * s, void *msg, int msglen,
{
if (cmsg->cmsg_level == SOL_SOCKET)
{
+#ifdef __linux__
if (cmsg->cmsg_type == SCM_CREDENTIALS)
{
cr = (struct ucred *) CMSG_DATA (cmsg);
@@ -347,7 +352,9 @@ default_socket_recvmsg (clib_socket_t * s, void *msg, int msglen,
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_socket_init (clib_socket_t * s)
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 @@ clib_socket_init (clib_socket_t * s)
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 cc95a00ef48..8370be7a460 100644
--- a/src/vppinfra/test_format.c
+++ b/src/vppinfra/test_format.c
@@ -180,6 +180,8 @@ main (int argc, char *argv[])
{
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 94110ab68ad..7f047d9ec78 100644
--- a/src/vppinfra/test_hash.c
+++ b/src/vppinfra/test_hash.c
@@ -440,6 +440,8 @@ main (int argc, char *argv[])
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 2415c4f061c..01debe2ac37 100644
--- a/src/vppinfra/test_longjmp.c
+++ b/src/vppinfra/test_longjmp.c
@@ -112,6 +112,8 @@ main (int argc, char *argv[])
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 05299b38e3f..cf6172ab1f1 100644
--- a/src/vppinfra/test_macros.c
+++ b/src/vppinfra/test_macros.c
@@ -47,6 +47,8 @@ main (int argc, char *argv[])
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 7ae70c52f51..f3ff6623a3e 100644
--- a/src/vppinfra/test_maplog.c
+++ b/src/vppinfra/test_maplog.c
@@ -123,6 +123,8 @@ main (int argc, char *argv[])
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 9ed2ac7b950..47711c28dbc 100644
--- a/src/vppinfra/test_phash.c
+++ b/src/vppinfra/test_phash.c
@@ -132,6 +132,8 @@ main (int argc, char *argv[])
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 406a2a577c2..4e8e2dfa15f 100644
--- a/src/vppinfra/test_pool_iterate.c
+++ b/src/vppinfra/test_pool_iterate.c
@@ -32,6 +32,8 @@ main (int argc, char *argv[])
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 fdbf0bbebb0..68e8cbc2bde 100644
--- a/src/vppinfra/test_qhash.c
+++ b/src/vppinfra/test_qhash.c
@@ -311,6 +311,8 @@ main (int argc, char *argv[])
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 337d30ddea0..bed8673e710 100644
--- a/src/vppinfra/test_random_isaac.c
+++ b/src/vppinfra/test_random_isaac.c
@@ -123,6 +123,8 @@ main (int argc, char *argv[])
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 6351b050c6c..09f38082313 100644
--- a/src/vppinfra/test_serialize.c
+++ b/src/vppinfra/test_serialize.c
@@ -258,6 +258,8 @@ main (int argc, char *argv[])
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 2f25eccd91f..ea0ae658943 100644
--- a/src/vppinfra/test_socket.c
+++ b/src/vppinfra/test_socket.c
@@ -117,6 +117,8 @@ main (int argc, char *argv[])
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 63cfeac5b0a..80c0e3a24b1 100644
--- a/src/vppinfra/test_time.c
+++ b/src/vppinfra/test_time.c
@@ -86,6 +86,8 @@ main (int argc, char *argv[])
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 ccb63b20873..2ec6e13a9d5 100644
--- a/src/vppinfra/test_time_range.c
+++ b/src/vppinfra/test_time_range.c
@@ -162,6 +162,8 @@ main (int argc, char *argv[])
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 0ce15ad88cb..7cf6e0c33f4 100644
--- a/src/vppinfra/test_timing_wheel.c
+++ b/src/vppinfra/test_timing_wheel.c
@@ -367,6 +367,8 @@ main (int argc, char *argv[])
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 d60d27b2ad2..d02d71c4a2a 100644
--- a/src/vppinfra/test_vec.c
+++ b/src/vppinfra/test_vec.c
@@ -1173,8 +1173,6 @@ main (int argc, char *argv[])
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 7293fdde86e..f5aa5e21aec 100644
--- a/src/vppinfra/test_vhash.c
+++ b/src/vppinfra/test_vhash.c
@@ -741,6 +741,8 @@ main (int argc, char *argv[])
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 874fdefa4ad..7d777fabf83 100644
--- a/src/vppinfra/test_zvec.c
+++ b/src/vppinfra/test_zvec.c
@@ -98,6 +98,8 @@ main (int argc, char *argv[])
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 ced9677d1e2..64370d523bb 100644
--- a/src/vppinfra/time.h
+++ b/src/vppinfra/time.h
@@ -237,10 +237,14 @@ void clib_time_init (clib_time_t * c);
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 @@ always_inline u64
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 @@ always_inline void
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 85149dc6b00..8bbab653ec0 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 @@ timer_interrupt (int signum)
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 b3b8c899d70..c4473299563 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 @@ u8 * format_sockaddr (u8 * s, va_list * args)
return s;
}
+#ifndef __APPLE__
u8 * format_tcp4_packet (u8 * s, va_list * args)
{
u8 * p = va_arg (*args, u8 *);
@@ -832,6 +841,7 @@ u8 * format_timeval (u8 * s, va_list * args)
return s;
}
+#endif
u8 * format_time_float (u8 * s, va_list * args)
{