Have psa_sim_serialise.pl generate psa_sim_serialize_reset()

Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
This commit is contained in:
Tom Cosgrove 2024-06-18 12:32:57 +01:00
parent aaf7e859a4
commit 2468896857
3 changed files with 40 additions and 0 deletions

View File

@ -711,4 +711,6 @@ void psa_sim_serialize_reset(void)
{
memset(hash_operation_handles, 0, sizeof(hash_operation_handles));
memset(hash_operations, 0, sizeof(hash_operations));
memset(aead_operation_handles, 0, sizeof(aead_operation_handles));
memset(aead_operations, 0, sizeof(aead_operations));
}

View File

@ -54,6 +54,10 @@
* don't contain pointers.
*/
/** Reset all operation slots.
*
* Should be called when all clients have disconnected.
*/
void psa_sim_serialize_reset(void);
/** Return how much buffer space is needed by \c psasim_serialise_begin().

View File

@ -105,6 +105,7 @@ if ($which eq "h") {
}
}
print define_server_serialize_reset(@types);
} else {
die("internal error - shouldn't happen");
}
@ -329,6 +330,12 @@ sub h_header
* don't contain pointers.
*/
/** Reset all operation slots.
*
* Should be called when all clients have disconnected.
*/
void psa_sim_serialize_reset(void);
/** Return how much buffer space is needed by \c psasim_serialise_begin().
*
* \return The number of bytes needed in the buffer for
@ -907,6 +914,33 @@ int psasim_deserialise_begin(uint8_t **pos, size_t *remaining)
EOF
}
# Return the code for psa_sim_serialize_reset()
sub define_server_serialize_reset
{
my @types = @_;
my $code = <<EOF;
void psa_sim_serialize_reset(void)
{
EOF
for my $type (@types) {
next unless $type =~ /^psa_(\w+_operation)_t$/;
my $what = $1; # e.g. "hash_operation"
$code .= <<EOF;
memset(${what}_handles, 0, sizeof(${what}_handles));
memset(${what}s, 0, sizeof(${what}s));
EOF
}
$code .= <<EOF;
}
EOF
}
# Horrible way to align first, second and third lines of function signature to
# appease uncrustify (these are the 2nd-4th lines of code, indices 1, 2 and 3)
#