1 /*
2  * Copyright 2019 The Hafnium Authors.
3  *
4  * Use of this source code is governed by a BSD-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/BSD-3-Clause.
7  */
8 
9 #include "vmapi/hf/call.h"
10 
11 #include "primary_with_secondary.h"
12 #include "test/hftest.h"
13 #include "test/vmapi/exception_handler.h"
14 #include "test/vmapi/ffa.h"
15 
TEAR_DOWN(unmapped)16 TEAR_DOWN(unmapped)
17 {
18 	EXPECT_FFA_ERROR(ffa_rx_release(), FFA_DENIED);
19 }
20 
21 /**
22  * Accessing unmapped memory traps the VM.
23  */
TEST(unmapped,data_unmapped)24 TEST(unmapped, data_unmapped)
25 {
26 	struct ffa_value run_res;
27 	struct mailbox_buffers mb = set_up_mailbox();
28 
29 	SERVICE_SELECT(SERVICE_VM1, "data_unmapped", mb.send);
30 
31 	run_res = ffa_run(SERVICE_VM1, 0);
32 	EXPECT_EQ(exception_handler_receive_exception_count(&run_res, mb.recv),
33 		  1);
34 }
35 
36 /**
37  * Accessing partially unmapped memory traps the VM.
38  */
TEST(unmapped,straddling_data_unmapped)39 TEST(unmapped, straddling_data_unmapped)
40 {
41 	struct ffa_value run_res;
42 	struct mailbox_buffers mb = set_up_mailbox();
43 
44 	SERVICE_SELECT(SERVICE_VM1, "straddling_data_unmapped", mb.send);
45 
46 	run_res = ffa_run(SERVICE_VM1, 0);
47 	EXPECT_EQ(exception_handler_receive_exception_count(&run_res, mb.recv),
48 		  1);
49 }
50 
51 /**
52  * Executing unmapped memory traps the VM.
53  */
TEST(unmapped,instruction_unmapped)54 TEST(unmapped, instruction_unmapped)
55 {
56 	struct ffa_value run_res;
57 	struct mailbox_buffers mb = set_up_mailbox();
58 
59 	SERVICE_SELECT(SERVICE_VM1, "instruction_unmapped", mb.send);
60 
61 	run_res = ffa_run(SERVICE_VM1, 0);
62 	EXPECT_EQ(exception_handler_receive_exception_count(&run_res, mb.recv),
63 		  1);
64 }
65