LCOV - code coverage report
Current view: top level - include - parasite.h (source / functions) Hit Total Coverage
Test: coverage3.info Lines: 6 6 100.0 %
Date: 2014-04-22 Functions: 0 0 -
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : #ifndef __CR_PARASITE_H__
       2                 :            : #define __CR_PARASITE_H__
       3                 :            : 
       4                 :            : #define PARASITE_STACK_SIZE     (16 << 10)
       5                 :            : #define PARASITE_ARG_SIZE_MIN   ( 1 << 12)
       6                 :            : 
       7                 :            : #define PARASITE_MAX_SIZE       (64 << 10)
       8                 :            : 
       9                 :            : #ifndef __ASSEMBLY__
      10                 :            : 
      11                 :            : #include <sys/un.h>
      12                 :            : #include <sys/time.h>
      13                 :            : #include <time.h>
      14                 :            : #include <signal.h>
      15                 :            : 
      16                 :            : #include "image.h"
      17                 :            : #include "util-pie.h"
      18                 :            : 
      19                 :            : #include "protobuf/vma.pb-c.h"
      20                 :            : 
      21                 :            : #define __head __used __section(.head.text)
      22                 :            : 
      23                 :            : enum {
      24                 :            :         PARASITE_CMD_IDLE               = 0,
      25                 :            :         PARASITE_CMD_ACK,
      26                 :            : 
      27                 :            :         PARASITE_CMD_INIT_DAEMON,
      28                 :            :         PARASITE_CMD_DUMP_THREAD,
      29                 :            :         PARASITE_CMD_UNMAP,
      30                 :            : 
      31                 :            :         /*
      32                 :            :          * These two must be greater than INITs.
      33                 :            :          */
      34                 :            :         PARASITE_CMD_DAEMONIZED,
      35                 :            : 
      36                 :            :         PARASITE_CMD_FINI,
      37                 :            : 
      38                 :            :         PARASITE_CMD_MPROTECT_VMAS,
      39                 :            :         PARASITE_CMD_DUMPPAGES,
      40                 :            : 
      41                 :            :         PARASITE_CMD_DUMP_SIGACTS,
      42                 :            :         PARASITE_CMD_DUMP_ITIMERS,
      43                 :            :         PARASITE_CMD_DUMP_POSIX_TIMERS,
      44                 :            :         PARASITE_CMD_DUMP_MISC,
      45                 :            :         PARASITE_CMD_DUMP_CREDS,
      46                 :            :         PARASITE_CMD_DRAIN_FDS,
      47                 :            :         PARASITE_CMD_GET_PROC_FD,
      48                 :            :         PARASITE_CMD_DUMP_TTY,
      49                 :            :         PARASITE_CMD_CHECK_VDSO_MARK,
      50                 :            : 
      51                 :            :         PARASITE_CMD_MAX,
      52                 :            : };
      53                 :            : 
      54                 :            : struct ctl_msg {
      55                 :            :         unsigned int    cmd;                    /* command itself */
      56                 :            :         unsigned int    ack;                    /* ack on command */
      57                 :            :         int             err;                    /* error code on reply */
      58                 :            : };
      59                 :            : 
      60                 :            : #define ctl_msg_cmd(_cmd)               \
      61                 :            :         (struct ctl_msg){.cmd = _cmd, }
      62                 :            : 
      63                 :            : #define ctl_msg_ack(_cmd, _err) \
      64                 :            :         (struct ctl_msg){.cmd = _cmd, .ack = _cmd, .err = _err, }
      65                 :            : 
      66                 :            : struct parasite_init_args {
      67                 :            :         int                     h_addr_len;
      68                 :            :         struct sockaddr_un      h_addr;
      69                 :            : 
      70                 :            :         int                     log_level;
      71                 :            : 
      72                 :            :         struct rt_sigframe      *sigframe;
      73                 :            : };
      74                 :            : 
      75                 :            : struct parasite_unmap_args {
      76                 :            :         void                    *parasite_start;
      77                 :            :         unsigned long           parasite_len;
      78                 :            : };
      79                 :            : 
      80                 :            : struct parasite_vma_entry
      81                 :            : {
      82                 :            :         unsigned long   start;
      83                 :            :         unsigned long   len;
      84                 :            :         int             prot;
      85                 :            : };
      86                 :            : 
      87                 :            : struct parasite_vdso_vma_entry {
      88                 :            :         unsigned long   start;
      89                 :            :         unsigned long   len;
      90                 :            :         unsigned long   proxy_addr;
      91                 :            :         int             is_marked;
      92                 :            : };
      93                 :            : 
      94                 :            : struct parasite_dump_pages_args {
      95                 :            :         unsigned int    nr_vmas;
      96                 :            :         unsigned int    add_prot;
      97                 :            :         unsigned int    off;
      98                 :            :         unsigned int    nr_segs;
      99                 :            :         unsigned int    nr_pages;
     100                 :            : };
     101                 :            : 
     102                 :            : static inline struct parasite_vma_entry *pargs_vmas(struct parasite_dump_pages_args *a)
     103                 :            : {
     104                 :            :         return (struct parasite_vma_entry *)(a + 1);
     105                 :            : }
     106                 :            : 
     107                 :            : static inline struct iovec *pargs_iovs(struct parasite_dump_pages_args *a)
     108                 :            : {
     109                 :       3664 :         return (struct iovec *)(pargs_vmas(a) + a->nr_vmas);
     110                 :            : }
     111                 :            : 
     112                 :            : struct parasite_dump_sa_args {
     113                 :            :         rt_sigaction_t sas[SIGMAX];
     114                 :            : };
     115                 :            : 
     116                 :            : struct parasite_dump_itimers_args {
     117                 :            :         struct itimerval real;
     118                 :            :         struct itimerval virt;
     119                 :            :         struct itimerval prof;
     120                 :            : };
     121                 :            : 
     122                 :            : struct posix_timer {
     123                 :            :         int it_id;
     124                 :            :         struct itimerspec val;
     125                 :            :         int overrun;
     126                 :            : };
     127                 :            : 
     128                 :            : struct parasite_dump_posix_timers_args {
     129                 :            :         int timer_n;
     130                 :            :         struct posix_timer timer[0];
     131                 :            : };
     132                 :            : 
     133                 :            : static inline int posix_timers_dump_size(int timer_n)
     134                 :            : {
     135                 :        923 :         return sizeof(int) + sizeof(struct posix_timer) * timer_n;
     136                 :            : }
     137                 :            : 
     138                 :            : struct parasite_dump_thread {
     139                 :            :         unsigned int            *tid_addr;
     140                 :            :         pid_t                   tid;
     141                 :            :         tls_t                   tls;
     142                 :            :         stack_t                 sas;
     143                 :            : };
     144                 :            : 
     145                 :            : /*
     146                 :            :  * Misc sfuff, that is too small for separate file, but cannot
     147                 :            :  * be read w/o using parasite
     148                 :            :  */
     149                 :            : 
     150                 :            : struct parasite_dump_misc {
     151                 :            :         unsigned long           brk;
     152                 :            : 
     153                 :            :         u32 pid;
     154                 :            :         u32 sid;
     155                 :            :         u32 pgid;
     156                 :            :         u32 umask;
     157                 :            : 
     158                 :            :         struct parasite_dump_thread     ti;
     159                 :            : };
     160                 :            : 
     161                 :            : #define PARASITE_MAX_GROUPS     (PAGE_SIZE / sizeof(unsigned int) - 2 * sizeof(unsigned))
     162                 :            : 
     163                 :            : struct parasite_dump_creds {
     164                 :            :         unsigned int            secbits;
     165                 :            :         unsigned int            ngroups;
     166                 :            :         unsigned int            groups[PARASITE_MAX_GROUPS];
     167                 :            : };
     168                 :            : 
     169                 :            : static inline void copy_sas(ThreadSasEntry *dst, const stack_t *src)
     170                 :            : {
     171                 :       2778 :         dst->ss_sp = encode_pointer(src->ss_sp);
     172                 :       1389 :         dst->ss_size = (u64)src->ss_size;
     173                 :       1389 :         dst->ss_flags = src->ss_flags;
     174                 :            : }
     175                 :            : 
     176                 :            : #define PARASITE_MAX_FDS        (PAGE_SIZE / sizeof(int))
     177                 :            : 
     178                 :            : struct parasite_drain_fd {
     179                 :            :         int     nr_fds;
     180                 :            :         int     fds[PARASITE_MAX_FDS];
     181                 :            : };
     182                 :            : 
     183                 :            : static inline int drain_fds_size(struct parasite_drain_fd *dfds)
     184                 :            : {
     185                 :       1826 :         return sizeof(dfds->nr_fds) + dfds->nr_fds * sizeof(dfds->fds[0]);
     186                 :            : }
     187                 :            : 
     188                 :            : struct parasite_tty_args {
     189                 :            :         int     fd;
     190                 :            : 
     191                 :            :         int     sid;
     192                 :            :         int     pgrp;
     193                 :            :         bool    hangup;
     194                 :            : 
     195                 :            :         int     st_pckt;
     196                 :            :         int     st_lock;
     197                 :            :         int     st_excl;
     198                 :            : };
     199                 :            : 
     200                 :            : /* the parasite prefix is added by gen_offsets.sh */
     201                 :            : #define parasite_sym(pblob, name) ((void *)(pblob) + parasite_blob_offset__##name)
     202                 :            : 
     203                 :            : #endif /* !__ASSEMBLY__ */
     204                 :            : 
     205                 :            : #endif /* __CR_PARASITE_H__ */

Generated by: LCOV version 1.9