chore(app/common): random service maps shared page if necessary

Previously, the random number service required its caller to map shared
page before invoking the service. This commit removes that requirement.

The service now automatically maps the shared page if it is not already
mapped by the caller, and unmaps it afterward. This change simplifies
the API and improves robustness by reducing dependency on the caller's
setup.

This commit also adds the optimization that the service passes the
caller app's shared page as target buffer for the random app's stub,
instead of a buffer allocated on the stack. This makes the extra memcpy
unnecessary.

Change-Id: I23f2b5c21dff4d2ec090a4bd6bf60ad0e25ad3f2
Signed-off-by: Mate Toth-Pal <mate.toth-pal@arm.com>
diff --git a/app/common/rmm_svc/src/app_services.c b/app/common/rmm_svc/src/app_services.c
index 97df885..37347e2 100644
--- a/app/common/rmm_svc/src/app_services.c
+++ b/app/common/rmm_svc/src/app_services.c
@@ -50,9 +50,8 @@
 			  unsigned long arg3)
 {
 	size_t len = arg0;
-	uint8_t buf[GRANULE_SIZE];
 	int ret;
-	void *shared_page;
+	bool unmap_shared_page = false;
 
 	(void)arg1;
 	(void)arg2;
@@ -69,15 +68,21 @@
 
 	struct app_data_cfg *random_app_data = random_app_get_data_cfg();
 
-	ret = random_app_prng_get_random(random_app_data, buf, len);
+	if (app_data->el2_shared_page == NULL) {
+		app_map_shared_page(app_data);
+		unmap_shared_page = true;
+	}
+
+	/* Pass the caller app's shared page as buf to the random app stub. */
+	ret = random_app_prng_get_random(random_app_data, app_data->el2_shared_page, len);
 	if (ret != 0) {
 		return (uint64_t)ret;
 	}
 
-	shared_page = app_data->el2_shared_page;
-	assert(shared_page != NULL);
-	/* coverity[misra_c_2012_rule_9_1_violation:SUPPRESS] */
-	(void)memcpy(shared_page, (void *)buf, len);
+	if (unmap_shared_page) {
+		app_unmap_shared_page(app_data);
+	}
+
 	return 0;
 }