Skip to content

Commit eb784a5

Browse files
committed
freebsd portage proposal.
- getrandom is available since the 12 release but we re safe since 11 is EOL now.
1 parent 5543c09 commit eb784a5

5 files changed

Lines changed: 16 additions & 2 deletions

File tree

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@ ifeq ($(UNAME), Linux)
171171
STRIP = strip -s $(BUILD_DIR)/$(LIBNAME)
172172
endif
173173

174+
ifeq ($(UNAME), FreeBSD)
175+
STRIP = strip -s $(BUILD_DIR)/$(LIBNAME)
176+
## Using spinlocks to avoid recursive locks contentions with calloc
177+
USE_SPINLOCK = -DUSE_SPINLOCK=1
178+
endif
179+
174180
HOOKS = $(MALLOC_HOOK)
175181
OPTIMIZE = -O2 -fstrict-aliasing -Wstrict-aliasing
176182
COMMON_CFLAGS = -Wall -Iinclude/ $(THREAD_SUPPORT) $(PRE_POPULATE_PAGES) $(STARTUP_MEM_USAGE)

include/conf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
/* See PERFORMANCE.md for notes on huge page sizes.
6161
* If your system uses a non-default value for huge
6262
* page sizes you will need to adjust that here */
63-
#if (__linux__ && MAP_HUGETLB) || (__APPLE__ && VM_FLAGS_SUPERPAGE_SIZE_2MB) && HUGE_PAGES
63+
#if (__linux__ && MAP_HUGETLB) || (__APPLE__ && VM_FLAGS_SUPERPAGE_SIZE_2MB) || (__FreeBSD__ && MAP_HUGETLB) && HUGE_PAGES
6464
#define HUGE_PAGE_SZ 2097152
6565
#endif
6666

include/iso_alloc_internal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ using namespace std;
7979
#include <sched.h>
8080
#endif
8181

82+
#if defined(__FreeBSD__)
83+
#define MAP_HUGETLB MAP_ALIGNED_SUPER
84+
#endif
85+
8286
#if HEAP_PROFILER
8387
#include <fcntl.h>
8488
#endif

src/iso_alloc_random.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <sys/syscall.h>
1010
#elif __APPLE__
1111
#include <Security/SecRandom.h>
12+
#elif __FreeBSD__
13+
#include <sys/random.h>
1214
#else
1315
#error "unknown OS"
1416
#endif
@@ -27,6 +29,8 @@ INTERNAL_HIDDEN uint64_t rand_uint64(void) {
2729
ret = syscall(SYS_getrandom, &val, sizeof(val), GRND_NONBLOCK) != sizeof(val);
2830
#elif __APPLE__
2931
ret = SecRandomCopyBytes(kSecRandomDefault, sizeof(val), &val);
32+
#elif __FreeBSD__
33+
ret = getrandom(&val, sizeof(val), GRND_NONBLOCK) != sizeof(val);
3034
#endif
3135

3236
#if ABORT_NO_ENTROPY

utils/run_tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
# This script runs all debug tests including vulnerable
33
# examples of code that should crash
44
$(echo '' > test_output.txt)

0 commit comments

Comments
 (0)