1/*
2 * Copyright 2017, Data61, CSIRO (ABN 41 687 119 230)
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#include <camkes.h>
8#include <stdio.h>
9#include <stdlib.h>
10
11int run() {
12    const char *shello = "hello world";
13    const char *smore = "a longer string that will overflow the message registers on ARM";
14    char *s;
15    int i = 42, j;
16    int p, p1, p2;
17    float f = 273421.4274, g;
18    double d = 273421.4274, e;
19
20    printf("Starting the client\n");
21    printf("-------------------\n");
22
23    j = a_echo_int(i);
24    printf("echo_int: %d -> %d\n",i, j);
25
26    g = a_echo_float(f);
27    printf("echo_float: %f -> %f\n",f, g);
28
29    e = a_echo_double(d);
30    printf("echo_double: %f -> %f\n",d, e);
31
32    j = a_echo_mix(d);
33    printf("echo_mix: %f -> %d\n",d, j);
34
35    s = a_echo_string(shello);
36    printf("echo_string: \"%s\" -> \"%s\"\n", shello, s);
37    /* Ordinarily we would now free s, but it is a pointer from the other
38     * component's heap and freeing will pass it back to our heap, corrupting
39     * it. Instead we just leak memory in this example.
40     */
41    // free(s);
42
43    s = a_echo_string(smore);
44    printf("echo_string: \"%s\" -> \"%s\"\n", smore, s);
45    // free(s);
46
47    p = 123;
48    p2 = a_echo_parameter(p, &p1);
49    printf("echo_parameter: %d -> %d (returned = %d)\n", p, p1, p2);
50
51    p = 100;
52    a_increment_parameter(&p);
53    printf("increment_parameter: 100 -> %d\n", p);
54
55    printf("After the client\n");
56    return 0;
57}
58