Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/firecracker
Path: blob/main/resources/tests/init.c
1956 views
1
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
// SPDX-License-Identifier: Apache-2.0
3
4
// Init wrapper for boot timing. Alpine-specific because it points at /sbin/openrc-init.
5
6
#include <sys/types.h>
7
#include <fcntl.h>
8
#include <sys/mman.h>
9
#include <unistd.h>
10
11
// Base address values are defined in arch/src/lib.rs as arch::MMIO_MEM_START.
12
// Values are computed in arch/src/<arch>/mod.rs from the architecture layouts.
13
// Position on the bus is defined by MMIO_LEN increments, where MMIO_LEN is
14
// defined as 0x1000 in vmm/src/device_manager/mmio.rs.
15
#ifdef __x86_64__
16
#define MAGIC_MMIO_SIGNAL_GUEST_BOOT_COMPLETE 0xd0000000
17
#endif
18
#ifdef __aarch64__
19
#define MAGIC_MMIO_SIGNAL_GUEST_BOOT_COMPLETE 0x40000000
20
#endif
21
22
#define MAGIC_VALUE_SIGNAL_GUEST_BOOT_COMPLETE 123
23
24
int main () {
25
int fd = open("/dev/mem", (O_RDWR | O_SYNC | O_CLOEXEC));
26
int mapped_size = getpagesize();
27
28
char *map_base = mmap(NULL,
29
mapped_size,
30
PROT_WRITE,
31
MAP_SHARED,
32
fd,
33
MAGIC_MMIO_SIGNAL_GUEST_BOOT_COMPLETE);
34
35
*map_base = MAGIC_VALUE_SIGNAL_GUEST_BOOT_COMPLETE;
36
msync(map_base, mapped_size, MS_ASYNC);
37
38
const char *init = "/sbin/openrc-init";
39
40
char *const argv[] = { "/sbin/init", NULL };
41
char *const envp[] = { };
42
43
execve(init, argv, envp);
44
}
45
46