From eceef16b5c5963ed27aa16b2ead4654b5a7dd391 Mon Sep 17 00:00:00 2001 From: Tom Jones Date: Wed, 31 Jan 2024 10:44:14 +0000 Subject: svm: Use ftruncate to expand svm on FreeBSD Linux doesn't support the Linux idiom of using lseek and a write to set the size of a file, instead use ftruncate to accomplish the same effect. This change is taken from the Nanoteq VPP port commit: https://github.com/ftk-ntq/vpp/commit/04a1b19b37e791accc61b91f3f413d8bc8b1ff8f Type: improvement Change-Id: Ie0b83e751b8b8f20b6814e5c9f760035747dfad9 Signed-off-by: Tom Jones --- src/svm/svm.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/svm/svm.c b/src/svm/svm.c index 0a910558f6e..5580808909a 100644 --- a/src/svm/svm.c +++ b/src/svm/svm.c @@ -551,7 +551,6 @@ svm_map_region (svm_map_region_args_t * a) int svm_fd; svm_region_t *rp; int deadman = 0; - u8 junk = 0; void *oldheap; int rv; int pid_holding_region_lock; @@ -582,6 +581,15 @@ svm_map_region (svm_map_region_args_t * a) vec_free (shm_name); +#ifdef __FreeBSD__ + if (ftruncate (svm_fd, a->size) < 0) + { + clib_warning ("ftruncate region size"); + close (svm_fd); + return (0); + } +#else + u8 junk = 0; if (lseek (svm_fd, a->size, SEEK_SET) == (off_t) - 1) { clib_warning ("seek region size"); @@ -594,6 +602,7 @@ svm_map_region (svm_map_region_args_t * a) close (svm_fd); return (0); } +#endif /* __FreeBSD__ */ rp = mmap (uword_to_pointer (a->baseva, void *), a->size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, svm_fd, 0); -- cgit 1.2.3-korg