^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #ifndef __MCONSOLE_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define __MCONSOLE_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #ifdef __UM_HOST__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <stdint.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #define u32 uint32_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <sysdep/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define MCONSOLE_MAGIC (0xcafebabe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define MCONSOLE_MAX_DATA (512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define MCONSOLE_VERSION 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) struct mconsole_request {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) u32 magic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) u32 version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) u32 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) char data[MCONSOLE_MAX_DATA];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct mconsole_reply {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) u32 err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) u32 more;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) u32 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) char data[MCONSOLE_MAX_DATA];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct mconsole_notify {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) u32 magic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) u32 version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) enum { MCONSOLE_SOCKET, MCONSOLE_PANIC, MCONSOLE_HANG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) MCONSOLE_USER_NOTIFY } type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) u32 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) char data[MCONSOLE_MAX_DATA];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct mc_request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) enum mc_context { MCONSOLE_INTR, MCONSOLE_PROC };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct mconsole_command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) char *command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) void (*handler)(struct mc_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) enum mc_context context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct mc_request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) int as_interrupt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) int originating_fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) unsigned int originlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) unsigned char origin[128]; /* sockaddr_un */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct mconsole_request request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct mconsole_command *cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct uml_pt_regs regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) extern char mconsole_socket_name[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) extern int mconsole_unlink_socket(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) extern int mconsole_reply_len(struct mc_request *req, const char *reply,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) int len, int err, int more);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) extern int mconsole_reply(struct mc_request *req, const char *str, int err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) int more);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) extern void mconsole_version(struct mc_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) extern void mconsole_help(struct mc_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) extern void mconsole_halt(struct mc_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) extern void mconsole_reboot(struct mc_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) extern void mconsole_config(struct mc_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) extern void mconsole_remove(struct mc_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) extern void mconsole_sysrq(struct mc_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) extern void mconsole_cad(struct mc_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) extern void mconsole_stop(struct mc_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) extern void mconsole_go(struct mc_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) extern void mconsole_log(struct mc_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) extern void mconsole_proc(struct mc_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) extern void mconsole_stack(struct mc_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) extern int mconsole_get_request(int fd, struct mc_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) extern int mconsole_notify(char *sock_name, int type, const void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) extern char *mconsole_notify_socket(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) extern void lock_notify(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) extern void unlock_notify(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) #endif