Merge pull request #9191 from tom-cosgrove-arm/psa-sim-fixes

Some fixes to the PSA simulator
This commit is contained in:
Tom Cosgrove
2024-05-29 12:31:05 +00:00
committed by GitHub
3 changed files with 11 additions and 10 deletions
@@ -8,6 +8,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/ipc.h> #include <sys/ipc.h>
#include <sys/msg.h> #include <sys/msg.h>
#include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@@ -426,7 +427,7 @@ size_t psa_read(psa_handle_t msg_handle, uint32_t invec_idx,
assert(idx >= 0); assert(idx >= 0);
len = msgrcv(connections[idx].client_to_server_q, &msg, sizeof(struct message_text), 0, 0); len = msgrcv(connections[idx].client_to_server_q, &msg, sizeof(struct message_text), 0, 0);
len = (len - sizeof(msg.message_text.qid)); len = (len - offsetof(struct message_text, buf));
if (len < 0) { if (len < 0) {
FATAL("Internal error: failed to dispatch read request to the client"); FATAL("Internal error: failed to dispatch read request to the client");
@@ -454,7 +455,6 @@ size_t psa_read(psa_handle_t msg_handle, uint32_t invec_idx,
void psa_write(psa_handle_t msg_handle, uint32_t outvec_idx, void psa_write(psa_handle_t msg_handle, uint32_t outvec_idx,
const void *buffer, size_t num_bytes) const void *buffer, size_t num_bytes)
{ {
size_t sofar = 0; size_t sofar = 0;
struct message msg = { 0 }; struct message msg = { 0 };
int idx; int idx;
@@ -478,9 +478,9 @@ void psa_write(psa_handle_t msg_handle, uint32_t outvec_idx,
sending = MAX_FRAGMENT_SIZE - (sizeof(size_t) * 2); sending = MAX_FRAGMENT_SIZE - (sizeof(size_t) * 2);
} }
INFO("Server: sending %lu bytes to client", sending); INFO("Server: sending %lu bytes to client, sofar = %lu", sending, (long) sofar);
send_msg(msg_handle, WRITE_REQUEST, outvec_idx, sending, buffer, sending); send_msg(msg_handle, WRITE_REQUEST, outvec_idx, sending, buffer + sofar, sending);
idx = find_connection(message_client[msg_handle]); idx = find_connection(message_client[msg_handle]);
assert(idx >= 0); assert(idx >= 0);
@@ -489,7 +489,7 @@ void psa_write(psa_handle_t msg_handle, uint32_t outvec_idx,
if (len < 1) { if (len < 1) {
FATAL("Client didn't give me a full response"); FATAL("Client didn't give me a full response");
} }
sofar = sofar + len; sofar = sofar + sending;
} }
/* Update the seek count */ /* Update the seek count */
@@ -498,7 +498,6 @@ void psa_write(psa_handle_t msg_handle, uint32_t outvec_idx,
size_t psa_skip(psa_handle_t msg_handle, uint32_t invec_idx, size_t num_bytes) size_t psa_skip(psa_handle_t msg_handle, uint32_t invec_idx, size_t num_bytes)
{ {
is_valid_msg_handle(msg_handle); is_valid_msg_handle(msg_handle);
is_call_msg(msg_handle); is_call_msg(msg_handle);
@@ -511,7 +510,6 @@ size_t psa_skip(psa_handle_t msg_handle, uint32_t invec_idx, size_t num_bytes)
static void destroy_temporary_queue(int myqid) static void destroy_temporary_queue(int myqid)
{ {
if (msgctl(myqid, IPC_RMID, NULL) != 0) { if (msgctl(myqid, IPC_RMID, NULL) != 0) {
INFO("ERROR: Failed to delete msg queue %d", myqid); INFO("ERROR: Failed to delete msg queue %d", myqid);
} }
@@ -613,7 +611,6 @@ void __init_psasim(const char **array,
const uint32_t versions[32], const uint32_t versions[32],
const int strict_policy_array[32]) const int strict_policy_array[32])
{ {
static uint8_t library_initialised = 0; static uint8_t library_initialised = 0;
key_t key; key_t key;
int qid; int qid;
@@ -638,7 +635,7 @@ void __init_psasim(const char **array,
if (strncmp(array[i], "", 1) != 0) { if (strncmp(array[i], "", 1) != 0) {
INFO("Setting up %s", array[i]); INFO("Setting up %s", array[i]);
memset(queue_path, 0, sizeof(queue_path)); memset(queue_path, 0, sizeof(queue_path));
sprintf(queue_path, "%s%s", TMP_FILE_BASE_PATH, array[i]); snprintf(queue_path, sizeof(queue_path), "%s%s", TMP_FILE_BASE_PATH, array[i]);
/* Create file if doesn't exist */ /* Create file if doesn't exist */
fp = fopen(queue_path, "ab+"); fp = fopen(queue_path, "ab+");
@@ -19,8 +19,12 @@
#include "mbedtls/version.h" #include "mbedtls/version.h"
#include "psa/crypto.h" #include "psa/crypto.h"
#ifdef DEBUG
#define SERVER_PRINT(fmt, ...) \ #define SERVER_PRINT(fmt, ...) \
PRINT("Server: " fmt, ##__VA_ARGS__) PRINT("Server: " fmt, ##__VA_ARGS__)
#else
#define SERVER_PRINT(...)
#endif
#define BUF_SIZE 25 #define BUF_SIZE 25
@@ -17,7 +17,7 @@ function clean_run() {
rm -f psa_notify_* rm -f psa_notify_*
pkill psa_partition || true pkill psa_partition || true
pkill psa_client || true pkill psa_client || true
ipcs | grep q | awk '{ printf " -q " $$2 }' | xargs ipcrm > /dev/null 2>&1 || true ipcs | grep q | awk '{ printf " -q " $2 }' | xargs ipcrm > /dev/null 2>&1 || true
} }
# The server creates some local files when it starts up so we can wait for this # The server creates some local files when it starts up so we can wait for this