-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathinit_comms.c
44 lines (35 loc) · 1.13 KB
/
init_comms.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// SPDX-License-Identifier: MIT
// Copyright (c) 2023 Ulrich Hecht
// init comms
// Clears the inter-cell communication areas to prevent race conditions.
#include "libc_server.h"
#include "sdl_server.h"
#include "video_encoder.h"
#include "fixed_addr.h"
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
void clear_comms_buffer(int mem_fd, unsigned long addr, size_t size)
{
void *buffer = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, addr);
if (buffer == MAP_FAILED) {
perror("failed to map comms buffer");
exit(1);
}
memset(buffer, 0, size);
munmap(buffer, size);
}
int main(void)
{
int mem_fd = open("/dev/mem", O_RDWR);
if (mem_fd < 0) {
perror("failed to open memory device");
return 1;
}
clear_comms_buffer(mem_fd, LIBC_CALL_BUFFER_ADDR, sizeof(struct libc_call_buffer));
clear_comms_buffer(mem_fd, SDL_EVENT_BUFFER_ADDR, sizeof(struct sdl_event_buffer));
clear_comms_buffer(mem_fd, VIDEO_ENCODER_PORT_ADDR, sizeof(struct video_encoder_comm_buffer));
clear_comms_buffer(mem_fd, GDBSTUB_PORT_ADDR, 4);
close(mem_fd);
return 0;
}