Skip to content

Commit

Permalink
patches: Disable use of mmap and replace with mmalloc and free.
Browse files Browse the repository at this point in the history
As of this commit, using mmap with a file descriptor is currently
unsupported in Unikraft.  To mitigate against ths, we use a simple
mmalloc in its place to return a buffer.

Signed-off-by: Alexander Jung <[email protected]>
  • Loading branch information
nderjung committed Jan 4, 2021
1 parent 77133c3 commit 4616a00
Showing 1 changed file with 80 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
From dd29dd858438f5589fe636573fc36fa3ced66fbf Mon Sep 17 00:00:00 2001
From: Alexander Jung <[email protected]>
Date: Mon, 4 Jan 2021 12:10:22 +0100
Subject: [PATCH] Disable use of mmap and replace with mmalloc and free.

As of this commit, using mmap with a file descriptor is currently
unsupported in Unikraft. To mitigate against ths, we use a simple
mmalloc in its place to return a buffer.

Signed-off-by: Alexander Jung <[email protected]>
---
src/iperf_api.c | 32 ++++++++++++++++++++++----------
1 file changed, 22 insertions(+), 10 deletions(-)

diff --git a/src/iperf_api.c b/src/iperf_api.c
index 88fed30..b1f19eb 100644
--- a/src/iperf_api.c
+++ b/src/iperf_api.c
@@ -3886,13 +3886,23 @@ iperf_new_stream(struct iperf_test *test, int s, int sender)
free(sp);
return NULL;
}
- sp->buffer = (char *) mmap(NULL, test->settings->blksize, PROT_READ|PROT_WRITE, MAP_PRIVATE, sp->buffer_fd, 0);
- if (sp->buffer == MAP_FAILED) {
- i_errno = IECREATESTREAM;
- free(sp->result);
+#pragma "WARNING: mmap has been replaced with malloc until it is available within Unikraft (see lib-iperf3/patches)."
+ sp->buffer = (char *) malloc(test->settings->blksize);
+ if (!sp->buffer) {
free(sp);
+ i_errno = IECREATESTREAM;
return NULL;
}
+
+ // sp->buffer
+ // sp->buffe
+ // sp->buffer = (char *) mmap(NULL, test->settings->blksize, PROT_READ|PROT_WRITE, MAP_PRIVATE, sp->buffer_fd, 0);
+ // if (sp->buffer == MAP_FAILED) {
+ // i_errno = IECREATESTREAM;
+ // free(sp->result);
+ // free(sp);
+ // return NULL;
+ // }

/* Set socket */
sp->socket = s;
@@ -3904,7 +3914,8 @@ iperf_new_stream(struct iperf_test *test, int s, int sender)
sp->diskfile_fd = open(test->diskfile_name, sender ? O_RDONLY : (O_WRONLY|O_CREAT|O_TRUNC), S_IRUSR|S_IWUSR);
if (sp->diskfile_fd == -1) {
i_errno = IEFILE;
- munmap(sp->buffer, sp->test->settings->blksize);
+ // munmap(sp->buffer, sp->test->settings->blksize);
+ free(sp->buffer);
free(sp->result);
free(sp);
return NULL;
@@ -3917,14 +3928,15 @@ iperf_new_stream(struct iperf_test *test, int s, int sender)
sp->diskfile_fd = -1;

/* Initialize stream */
- if (test->repeating_payload)
- fill_with_repeating_pattern(sp->buffer, test->settings->blksize);
- else
- ret = readentropy(sp->buffer, test->settings->blksize);
+ // if (test->repeating_payload)
+ fill_with_repeating_pattern(sp->buffer, test->settings->blksize);
+ // else
+ // ret = readentropy(sp->buffer, test->settings->blksize);

if ((ret < 0) || (iperf_init_stream(sp, test) < 0)) {
close(sp->buffer_fd);
- munmap(sp->buffer, sp->test->settings->blksize);
+ // munmap(sp->buffer, sp->test->settings->blksize);
+ free(sp->buffer);
free(sp->result);
free(sp);
return NULL;
--
2.20.1

0 comments on commit 4616a00

Please sign in to comment.