1/*#
2 *# Copyright 2017, Data61
3 *# Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4 *# ABN 41 687 119 230.
5 *#
6 *# This software may be distributed and modified according to the terms of
7 *# the BSD 2-Clause license. Note that NO WARRANTY is provided.
8 *# See "LICENSE_BSD2.txt" for details.
9 *#
10 *# @TAG(DATA61_BSD)
11 #*/
12
13/*? macros.show_includes(me.instance.type.includes) ?*/
14/*? macros.show_includes(me.interface.type.includes, '../static/components/%s/' % me.instance.type.name) ?*/
15
16
17/*- set mem_ep = alloc("mem_fault", seL4_EndpointObject, read=True, write=True, grantreply=True) -*/
18
19#include <assert.h>
20#include <limits.h>
21#include <stddef.h>
22#include <stdint.h>
23#include <stdlib.h>
24#include <string.h>
25#include <sel4/sel4.h>
26#include <sel4debug/debug.h>
27#include <utils/util.h>
28#include <camkes.h>
29#include <stdarg.h>
30
31int /*? me.interface.name ?*/__run(void) {
32    // Make connection to gdb
33    seL4_Word delegate_tcb;
34    seL4_UserContext regs;
35    while (1) {
36        seL4_Recv(/*? mem_ep ?*/, &delegate_tcb);
37        seL4_TCB_ReadRegisters(delegate_tcb, false, 0,
38                               sizeof(seL4_UserContext) / sizeof(seL4_Word),
39                               &regs);
40        // Check eax is 0 so that we know they were checking memory
41        // TODO Add a check on pc to see if they were in the mem check function
42        if (regs.eax == 0) {
43            // Signal to the delegate the memory is invalid
44            regs.eax = 1;
45               // Increment past the faulting instruction
46            regs.eip += 2;
47            // Write registers back
48            seL4_TCB_WriteRegisters(delegate_tcb, false, 0,
49                                    sizeof(seL4_UserContext) / sizeof(seL4_Word),
50                                    &regs);
51            // Resume the caller
52            seL4_MessageInfo_t info = seL4_MessageInfo_new(0, 0, 0, 1);
53            seL4_SetMR(0, regs.eip);
54            seL4_Reply(info);
55        }
56    }
57}
58