GDBserver
Loading...
Searching...
No Matches
Classes | Macros | Enumerations | Functions | Variables
linux-namespaces.c File Reference
#include "gdbsupport/common-defs.h"
#include "nat/linux-namespaces.h"
#include "gdbsupport/filestuff.h"
#include <fcntl.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include "gdbsupport/gdb_wait.h"
#include <signal.h>
#include <sched.h>
#include "gdbsupport/scope-exit.h"

Go to the source code of this file.

Classes

struct  linux_ns
 
struct  linux_mnsh
 

Macros

#define MSG_CMSG_CLOEXEC   0
 
#define mnsh_return_int(sock, result, error)    mnsh_send_message (sock, MNSH_RET_INT, -1, result, error, NULL, 0)
 
#define mnsh_return_fd(sock, fd, error)
 
#define mnsh_return_intstr(sock, result, buf, bufsiz, error)
 
#define mnsh_send_setns(helper, fd, nstype)
 
#define mnsh_send_open(helper, filename, flags, mode)
 
#define mnsh_send_unlink(helper, filename)
 
#define mnsh_send_readlink(helper, filename)
 

Enumerations

enum  mnsh_msg_type {
  MNSH_MSG_ERROR , MNSH_REQ_SETNS , MNSH_REQ_OPEN , MNSH_REQ_UNLINK ,
  MNSH_REQ_READLINK , MNSH_RET_INT , MNSH_RET_FD , MNSH_RET_INTSTR
}
 
enum  mnsh_fs_code { MNSH_FS_ERROR = -1 , MNSH_FS_DIRECT , MNSH_FS_HELPER }
 

Functions

static pid_t do_fork (void)
 
static int do_setns (int fd, int nstype)
 
static const char * linux_ns_filename (struct linux_ns *ns, int pid)
 
static struct linux_nslinux_ns_get_namespace (enum linux_ns_type type)
 
int linux_ns_same (pid_t pid, enum linux_ns_type type)
 
static void mnsh_debug_print_message (enum mnsh_msg_type type, int fd, int int1, int int2, const void *buf, int bufsiz)
 
static void mnsh_maybe_mourn_peer (void)
 
static ssize_t mnsh_send_message (int sock, enum mnsh_msg_type type, int fd, int int1, int int2, const void *buf, int bufsiz)
 
static ssize_t mnsh_recv_message (int sock, enum mnsh_msg_type *type, int *fd, int *int1, int *int2, void *buf, int bufsiz)
 
static ssize_t mnsh_handle_setns (int sock, int fd, int nstype)
 
static ssize_t mnsh_handle_open (int sock, const char *filename, int flags, mode_t mode)
 
static ssize_t mnsh_handle_unlink (int sock, const char *filename)
 
static ssize_t mnsh_handle_readlink (int sock, const char *filename)
 
static void mnsh_main (int sock) ATTRIBUTE_NORETURN
 
static struct linux_mnshlinux_mntns_get_helper (void)
 
static int mnsh_recv_int (struct linux_mnsh *helper, int *result, int *error)
 
static int mnsh_recv_fd (struct linux_mnsh *helper, int *fd, int *error)
 
static ssize_t mnsh_recv_intstr (struct linux_mnsh *helper, int *result, int *error, void *buf, int bufsiz)
 
static enum mnsh_fs_code linux_mntns_access_fs (pid_t pid)
 
int linux_mntns_open_cloexec (pid_t pid, const char *filename, int flags, mode_t mode)
 
int linux_mntns_unlink (pid_t pid, const char *filename)
 
ssize_t linux_mntns_readlink (pid_t pid, const char *filename, char *buf, size_t bufsiz)
 

Variables

bool debug_linux_namespaces
 
static int mnsh_creator_pid = 0
 

Macro Definition Documentation

◆ mnsh_return_fd

#define mnsh_return_fd ( sock,
fd,
error )
Value:
(fd) < 0 ? -1 : (fd), \
(fd) < 0 ? (fd) : 0, \
error, NULL, 0)
@ MNSH_RET_FD
static ssize_t mnsh_send_message(int sock, enum mnsh_msg_type type, int fd, int int1, int int2, const void *buf, int bufsiz)

Definition at line 497 of file linux-namespaces.c.

Referenced by mnsh_handle_open().

◆ mnsh_return_int

#define mnsh_return_int ( sock,
result,
error )    mnsh_send_message (sock, MNSH_RET_INT, -1, result, error, NULL, 0)

Definition at line 494 of file linux-namespaces.c.

Referenced by mnsh_handle_setns(), and mnsh_handle_unlink().

◆ mnsh_return_intstr

#define mnsh_return_intstr ( sock,
result,
buf,
bufsiz,
error )
Value:
mnsh_send_message (sock, MNSH_RET_INTSTR, -1, result, error, \
buf, bufsiz)
@ MNSH_RET_INTSTR

Definition at line 503 of file linux-namespaces.c.

Referenced by mnsh_handle_readlink().

◆ mnsh_send_open

#define mnsh_send_open ( helper,
filename,
flags,
mode )
Value:
mnsh_send_message (helper->sock, MNSH_REQ_OPEN, -1, flags, mode, \
filename, strlen (filename) + 1)
@ MNSH_REQ_OPEN

Definition at line 764 of file linux-namespaces.c.

Referenced by linux_mntns_open_cloexec().

◆ mnsh_send_readlink

#define mnsh_send_readlink ( helper,
filename )
Value:
mnsh_send_message (helper->sock, MNSH_REQ_READLINK, -1, 0, 0, \
filename, strlen (filename) + 1)
@ MNSH_REQ_READLINK

Definition at line 772 of file linux-namespaces.c.

Referenced by linux_mntns_readlink().

◆ mnsh_send_setns

#define mnsh_send_setns ( helper,
fd,
nstype )
Value:
mnsh_send_message (helper->sock, MNSH_REQ_SETNS, fd, nstype, 0, \
NULL, 0)
@ MNSH_REQ_SETNS

Definition at line 760 of file linux-namespaces.c.

Referenced by linux_mntns_access_fs().

◆ mnsh_send_unlink

#define mnsh_send_unlink ( helper,
filename )
Value:
mnsh_send_message (helper->sock, MNSH_REQ_UNLINK, -1, 0, 0, \
filename, strlen (filename) + 1)
@ MNSH_REQ_UNLINK

Definition at line 768 of file linux-namespaces.c.

Referenced by linux_mntns_unlink().

◆ MSG_CMSG_CLOEXEC

#define MSG_CMSG_CLOEXEC   0

Definition at line 67 of file linux-namespaces.c.

Referenced by mnsh_recv_message().

Enumeration Type Documentation

◆ mnsh_fs_code

Enumerator
MNSH_FS_ERROR 
MNSH_FS_DIRECT 
MNSH_FS_HELPER 

Definition at line 863 of file linux-namespaces.c.

◆ mnsh_msg_type

Enumerator
MNSH_MSG_ERROR 
MNSH_REQ_SETNS 
MNSH_REQ_OPEN 
MNSH_REQ_UNLINK 
MNSH_REQ_READLINK 
MNSH_RET_INT 
MNSH_RET_FD 
MNSH_RET_INTSTR 

Definition at line 222 of file linux-namespaces.c.

Function Documentation

◆ do_fork()

static pid_t do_fork ( void )
inlinestatic

Definition at line 39 of file linux-namespaces.c.

Referenced by linux_mntns_get_helper().

◆ do_setns()

static int do_setns ( int fd,
int nstype )
inlinestatic

Definition at line 52 of file linux-namespaces.c.

Referenced by mnsh_handle_setns().

◆ linux_mntns_access_fs()

static enum mnsh_fs_code linux_mntns_access_fs ( pid_t pid)
static

◆ linux_mntns_get_helper()

static struct linux_mnsh * linux_mntns_get_helper ( void )
static

◆ linux_mntns_open_cloexec()

int linux_mntns_open_cloexec ( pid_t pid,
const char * filename,
int flags,
mode_t mode )

◆ linux_mntns_readlink()

ssize_t linux_mntns_readlink ( pid_t pid,
const char * filename,
char * buf,
size_t bufsiz )

◆ linux_mntns_unlink()

int linux_mntns_unlink ( pid_t pid,
const char * filename )

◆ linux_ns_filename()

static const char * linux_ns_filename ( struct linux_ns * ns,
int pid )
static

Definition at line 95 of file linux-namespaces.c.

References linux_ns::filename.

Referenced by linux_mntns_access_fs(), linux_ns_get_namespace(), and linux_ns_same().

◆ linux_ns_get_namespace()

static struct linux_ns * linux_ns_get_namespace ( enum linux_ns_type type)
static

◆ linux_ns_same()

int linux_ns_same ( pid_t pid,
enum linux_ns_type type )

◆ mnsh_debug_print_message()

static void mnsh_debug_print_message ( enum mnsh_msg_type type,
int fd,
int int1,
int int2,
const void * buf,
int bufsiz )
static

◆ mnsh_handle_open()

static ssize_t mnsh_handle_open ( int sock,
const char * filename,
int flags,
mode_t mode )
static

Definition at line 520 of file linux-namespaces.c.

References mnsh_return_fd.

Referenced by mnsh_main().

◆ mnsh_handle_readlink()

static ssize_t mnsh_handle_readlink ( int sock,
const char * filename )
static

Definition at line 540 of file linux-namespaces.c.

References mnsh_return_intstr.

Referenced by mnsh_main().

◆ mnsh_handle_setns()

static ssize_t mnsh_handle_setns ( int sock,
int fd,
int nstype )
static

Definition at line 510 of file linux-namespaces.c.

References do_setns(), and mnsh_return_int.

Referenced by mnsh_main().

◆ mnsh_handle_unlink()

static ssize_t mnsh_handle_unlink ( int sock,
const char * filename )
static

Definition at line 530 of file linux-namespaces.c.

References mnsh_return_int.

Referenced by mnsh_main().

◆ mnsh_main()

static void mnsh_main ( int sock)
static

◆ mnsh_maybe_mourn_peer()

static void mnsh_maybe_mourn_peer ( void )
static

◆ mnsh_recv_fd()

static int mnsh_recv_fd ( struct linux_mnsh * helper,
int * fd,
int * error )
static

Definition at line 808 of file linux-namespaces.c.

References mnsh_recv_message(), MNSH_RET_FD, and linux_mnsh::sock.

Referenced by linux_mntns_open_cloexec().

◆ mnsh_recv_int()

static int mnsh_recv_int ( struct linux_mnsh * helper,
int * result,
int * error )
static

Definition at line 782 of file linux-namespaces.c.

References mnsh_recv_message(), MNSH_RET_INT, and linux_mnsh::sock.

Referenced by linux_mntns_access_fs(), and linux_mntns_unlink().

◆ mnsh_recv_intstr()

static ssize_t mnsh_recv_intstr ( struct linux_mnsh * helper,
int * result,
int * error,
void * buf,
int bufsiz )
static

Definition at line 840 of file linux-namespaces.c.

References mnsh_recv_message(), MNSH_RET_INTSTR, and linux_mnsh::sock.

Referenced by linux_mntns_readlink().

◆ mnsh_recv_message()

static ssize_t mnsh_recv_message ( int sock,
enum mnsh_msg_type * type,
int * fd,
int * int1,
int * int2,
void * buf,
int bufsiz )
static

◆ mnsh_send_message()

static ssize_t mnsh_send_message ( int sock,
enum mnsh_msg_type type,
int fd,
int int1,
int int2,
const void * buf,
int bufsiz )
static

Variable Documentation

◆ debug_linux_namespaces

bool debug_linux_namespaces

Definition at line 34 of file linux-namespaces.c.

Referenced by linux_mntns_get_helper(), mnsh_recv_message(), and mnsh_send_message().

◆ mnsh_creator_pid

int mnsh_creator_pid = 0
static

Definition at line 630 of file linux-namespaces.c.

Referenced by linux_mntns_get_helper(), and mnsh_maybe_mourn_peer().