1// Copyright 2016 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <stdio.h>
6#include <stdlib.h>
7#include <string.h>
8
9#include <zircon/syscalls.h>
10#include <zircon/syscalls-ddk.h>
11
12static int val = 5;
13
14void bad_kernel_access_read(void) {
15    char cmd[50];
16    snprintf(cmd, sizeof(cmd), "db %p 1", &val);
17    zx_debug_send_command(cmd, strlen(cmd));
18}
19
20void bad_kernel_access_write(void) {
21    char cmd[50];
22    snprintf(cmd, sizeof(cmd), "mb %p 1 1", &val);
23    zx_debug_send_command(cmd, strlen(cmd));
24}
25
26int main(int argc, char **argv) {
27    if (argc < 2) {
28        printf("Usage: %s [read|write]\n", argv[0]);
29        return 1;
30    }
31
32    if (!strcmp(argv[1], "read")) {
33        bad_kernel_access_read();
34    } else if (!strcmp(argv[1], "write")) {
35        bad_kernel_access_write();
36    }
37    return 0;
38}
39