mirror of
https://github.com/darlinghq/darlingserver.git
synced 2024-11-26 22:00:26 +00:00
db65a1b009
This new tool (`dserverdbg`) runs on the host but connects to darlingserver and makes unmanaged calls to retrieve debugging information. The initial set of subcommands available in this tool are `ps`, `lsport`, `lspset`, and `lsmsg`: * `ps` lists processes currently registered with the server and how many Mach ports they have * `lsport` lists the ports of a given process (via PID) and their rights and messages counts (for receive rights) * `lspset` lists the members of a given portset (via PID and port name) and provides the same information about each port as `lsport` * `lsmsg` lists the messages of a given port (via PID and port name), providing sender PID (if available) and size This tool may be expanded later to allow e.g. modifying logging settings while darlingserver is running or perhaps searching through and filtering the logs.
113 lines
3.4 KiB
C
113 lines
3.4 KiB
C
#pragma once
|
|
|
|
#include <sys/socket.h>
|
|
#include <sys/un.h>
|
|
#include <unistd.h>
|
|
#include <sys/syscall.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
#include <stdio.h>
|
|
#include <signal.h>
|
|
|
|
#include <darlingserver/rpc-supplement.h>
|
|
|
|
#include <rtsig.h>
|
|
|
|
#define dserver_rpc_hooks_msghdr_t struct msghdr
|
|
#define dserver_rpc_hooks_iovec_t struct iovec
|
|
#define dserver_rpc_hooks_cmsghdr_t struct cmsghdr
|
|
#define DSERVER_RPC_HOOKS_CMSG_SPACE CMSG_SPACE
|
|
#define DSERVER_RPC_HOOKS_CMSG_FIRSTHDR CMSG_FIRSTHDR
|
|
#define DSERVER_RPC_HOOKS_SOL_SOCKET SOL_SOCKET
|
|
#define DSERVER_RPC_HOOKS_SCM_RIGHTS SCM_RIGHTS
|
|
#define DSERVER_RPC_HOOKS_CMSG_LEN CMSG_LEN
|
|
#define DSERVER_RPC_HOOKS_CMSG_DATA CMSG_DATA
|
|
#define DSERVER_RPC_HOOKS_ATTRIBUTE static
|
|
|
|
#define dserver_rpc_hooks_get_pid getpid
|
|
|
|
#define dserver_rpc_hooks_get_tid() ((pid_t)syscall(SYS_gettid))
|
|
|
|
#if __x86_64__
|
|
#define dserver_rpc_hooks_get_architecture() dserver_rpc_architecture_x86_64
|
|
#elif __i386__
|
|
#define dserver_rpc_hooks_get_architecture() dserver_rpc_architecture_i386
|
|
#elif __aarch64__
|
|
#define dserver_rpc_hooks_get_architecture() dserver_rpc_architecture_arm64
|
|
#elif __arm__
|
|
#define dserver_rpc_hooks_get_architecture() dserver_rpc_architecture_arm32
|
|
#else
|
|
#define dserver_rpc_hooks_get_architecture() dserver_rpc_architecture_invalid
|
|
#endif
|
|
|
|
extern struct sockaddr_un __dserver_socket_address_data;
|
|
|
|
#define dserver_rpc_hooks_get_server_address() ((void*)&__dserver_socket_address_data)
|
|
|
|
#define dserver_rpc_hooks_get_server_address_length() sizeof(__dserver_socket_address_data)
|
|
|
|
#define dserver_rpc_hooks_memcpy memcpy
|
|
|
|
static long int dserver_rpc_hooks_send_message(int socket, const dserver_rpc_hooks_msghdr_t* message) {
|
|
ssize_t ret = sendmsg(socket, message, 0);
|
|
if (ret < 0) {
|
|
return -errno;
|
|
}
|
|
return ret;
|
|
};
|
|
|
|
static long int dserver_rpc_hooks_receive_message(int socket, dserver_rpc_hooks_msghdr_t* out_message) {
|
|
ssize_t ret = recvmsg(socket, out_message, 0);
|
|
if (ret < 0) {
|
|
return -errno;
|
|
}
|
|
|
|
if (ret >= sizeof(dserver_s2c_callhdr_t)) {
|
|
dserver_s2c_callhdr_t* callhdr = out_message->msg_iov->iov_base;
|
|
if (callhdr->call_number == 0x52cca11) {
|
|
// this is an S2C call
|
|
// dserverdbg shouldn't need to be doing S2C calls
|
|
fprintf(stderr, "dserverdbg darlingserver RPC hooks received S2C call\n");
|
|
abort();
|
|
}
|
|
}
|
|
|
|
return ret;
|
|
};
|
|
|
|
#define dserver_rpc_hooks_get_bad_message_status() (-EBADMSG)
|
|
|
|
#define dserver_rpc_hooks_get_communication_error_status() (-ECOMM)
|
|
|
|
#define dserver_rpc_hooks_get_broken_pipe_status() (-EPIPE)
|
|
|
|
#define dserver_rpc_hooks_close_fd close
|
|
|
|
extern int __dserver_main_thread_socket_fd;
|
|
|
|
#define dserver_rpc_hooks_get_socket() __dserver_main_thread_socket_fd
|
|
|
|
#define dserver_rpc_hooks_printf(...) fprintf(stderr, ## __VA_ARGS__)
|
|
|
|
#define dserver_rpc_hooks_atomic_save_t sigset_t
|
|
|
|
static void dserver_rpc_hooks_atomic_begin(dserver_rpc_hooks_atomic_save_t* atomic_save) {
|
|
sigset_t set;
|
|
sigfillset(&set);
|
|
sigdelset(&set, LINUX_SIGRTMIN);
|
|
sigdelset(&set, LINUX_SIGRTMIN + 1);
|
|
pthread_sigmask(SIG_BLOCK, &set, atomic_save);
|
|
};
|
|
|
|
static void dserver_rpc_hooks_atomic_end(dserver_rpc_hooks_atomic_save_t* atomic_save) {
|
|
pthread_sigmask(SIG_SETMASK, atomic_save, NULL);
|
|
};
|
|
|
|
#define dserver_rpc_hooks_get_interrupt_status() (-EINTR)
|
|
|
|
static void dserver_rpc_hooks_push_reply(int socket, const dserver_rpc_hooks_msghdr_t* reply, size_t size) {
|
|
// we shouldn't need to push any replies in dserverdbg
|
|
abort();
|
|
};
|