summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mauderer <Christian.Mauderer@embedded-brains.de>2016-07-15 11:39:48 +0200
committerChristian Mauderer <Christian.Mauderer@embedded-brains.de>2016-08-02 10:21:38 +0200
commit3d9134086847bc755fd9dcc7f6149f8871d6a6ed (patch)
treee7b1f68cfd9f6448511aedf3eac31b45b24f82ed
parentfa43d6a7ea8f26e4f095b55bea74be8cdd5dd6dc (diff)
downloadrtems-libbsd-3d9134086847bc755fd9dcc7f6149f8871d6a6ed.tar.bz2
rtemsbsd: Add call to program with a data restore
This adds the rtems_bsd_program_call_main_width_data_restore function.
-rw-r--r--rtemsbsd/include/machine/rtems-bsd-program.h5
-rw-r--r--rtemsbsd/rtems/rtems-kernel-program.c23
-rw-r--r--testsuite/program01/test_main.c34
3 files changed, 62 insertions, 0 deletions
diff --git a/rtemsbsd/include/machine/rtems-bsd-program.h b/rtemsbsd/include/machine/rtems-bsd-program.h
index 82830f51..4605017f 100644
--- a/rtemsbsd/include/machine/rtems-bsd-program.h
+++ b/rtemsbsd/include/machine/rtems-bsd-program.h
@@ -53,6 +53,11 @@ int
rtems_bsd_program_call_main(const char *name, int (*main)(int, char **),
int argc, char **argv);
+int
+rtems_bsd_program_call_main_with_data_restore(const char *name,
+ int (*main)(int, char **), int argc, char **argv,
+ const void *data_buf, const size_t data_size);
+
void
rtems_bsd_program_exit(int exit_code) __dead2;
diff --git a/rtemsbsd/rtems/rtems-kernel-program.c b/rtemsbsd/rtems/rtems-kernel-program.c
index a71d5496..0355c585 100644
--- a/rtemsbsd/rtems/rtems-kernel-program.c
+++ b/rtemsbsd/rtems/rtems-kernel-program.c
@@ -200,6 +200,29 @@ rtems_bsd_program_call_main(const char *name, int (*main)(int, char **),
return exit_code;
}
+int
+rtems_bsd_program_call_main_with_data_restore(const char *name,
+ int (*main)(int, char **), int argc, char **argv,
+ const void *data_buf, const size_t data_size)
+{
+ int exit_code = EXIT_FAILURE;
+ void *savebuf;
+
+ savebuf = malloc(data_size, M_TEMP, 0);
+ if(savebuf == NULL) {
+ errno = ENOMEM;
+ exit_code = EXIT_FAILURE;
+ } else {
+ memcpy(savebuf, data_buf, data_size);
+ exit_code = rtems_bsd_program_call_main(name, main, argc,
+ argv);
+ memcpy(data_buf, savebuf, data_size);
+ free(savebuf, M_TEMP);
+ }
+
+ return exit_code;
+}
+
static struct mtx program_mtx;
MTX_SYSINIT(rtems_bsd_program, &program_mtx, "BSD program", MTX_DEF);
diff --git a/testsuite/program01/test_main.c b/testsuite/program01/test_main.c
index 398dd62c..ca14a36d 100644
--- a/testsuite/program01/test_main.c
+++ b/testsuite/program01/test_main.c
@@ -170,6 +170,23 @@ no_mem_bsd_program(int fd)
assert(rtems_bsd_program_get_context() == NULL);
}
+#define OVERWRITE_CONTENT "Some test pattern"
+#define OVERWRITE_AFTER_RESTORE "xxxxxtestxxxxxxxx"
+#define OVERWRITE_RESTORE_FIRST (5)
+#define OVERWRITE_RESTORE_SIZE (4)
+static const char overwrite_compare[] = OVERWRITE_AFTER_RESTORE;
+static char overwrite_me[] = OVERWRITE_CONTENT;
+
+static int
+overwrite_main(int argc, char **argv)
+{
+ size_t len = strlen(overwrite_me);
+ memset(overwrite_me, 'x', len);
+ assert(strcmp(overwrite_me, overwrite_compare) != 0);
+ errno = 0;
+ rtems_bsd_program_exit(1012);
+}
+
static void
test_bsd_program(void)
{
@@ -196,11 +213,15 @@ test_bsd_program(void)
no_mem_bsd_program(-1);
rtems_workspace_greedy_free(greedy);
+ assert(rtems_resource_snapshot_check(&snapshot));
+
errno = 0;
exit_code = rtems_bsd_program_call_main(prog_name, NULL, 1, invalid_argv);
assert(errno == EFAULT);
assert(exit_code == EXIT_FAILURE);
+ assert(rtems_resource_snapshot_check(&snapshot));
+
errno = EINVAL;
exit_code = rtems_bsd_program_call(prog_name, some_prog, some_context);
assert(errno == 0);
@@ -208,6 +229,8 @@ test_bsd_program(void)
assert(strcmp(rtems_bsd_program_get_name(), "?") == 0);
assert(rtems_bsd_program_get_context() == NULL);
+ assert(rtems_resource_snapshot_check(&snapshot));
+
errno = EINVAL;
exit_code = rtems_bsd_program_call_main(prog_name, some_main,
some_argc, some_argv);
@@ -217,6 +240,17 @@ test_bsd_program(void)
assert(rtems_bsd_program_get_context() == NULL);
assert(rtems_resource_snapshot_check(&snapshot));
+
+ exit_code = rtems_bsd_program_call_main_with_data_restore(prog_name,
+ overwrite_main, some_argc, some_argv,
+ overwrite_me + OVERWRITE_RESTORE_FIRST, OVERWRITE_RESTORE_SIZE);
+ assert(errno == 0);
+ assert(exit_code == 1012);
+ assert(strcmp(rtems_bsd_program_get_name(), "?") == 0);
+ assert(rtems_bsd_program_get_context() == NULL);
+ assert(strcmp(overwrite_me, overwrite_compare) == 0);
+
+ assert(rtems_resource_snapshot_check(&snapshot));
}
static void