#ifndef _VX_INLINE_H #define _VX_INLINE_H // #define VX_DEBUG #include #include #if defined(VX_DEBUG) #define vxdprintk(x...) printk("vxd: " x) #else #define vxdprintk(x...) #endif void free_vx_info(struct vx_info *); extern int proc_pid_vinfo(struct task_struct *, char *); #define get_vx_info(i) __get_vx_info(i,__FILE__,__LINE__) static __inline__ struct vx_info *__get_vx_info(struct vx_info *vxi, const char *_file, int _line) { /* for now we allow vxi to be null */ if (!vxi) return NULL; vxdprintk("get_vx_info(%p[#%d.%d])\t%s:%d\n", vxi, vxi->vx_id, atomic_read(&vxi->vx_refcount), _file, _line); atomic_inc(&vxi->vx_refcount); return vxi; } #define put_vx_info(i) __put_vx_info(i,__FILE__,__LINE__) static __inline__ void __put_vx_info(struct vx_info *vxi, const char *_file, int _line) { /* for now we allow vxi to be null */ if (!vxi) return; vxdprintk("put_vx_info(%p[#%d.%d])\t%s:%d\n", vxi, vxi->vx_id, atomic_read(&vxi->vx_refcount), _file, _line); if (atomic_dec_and_lock(&vxi->vx_refcount, &vxlist_lock)) { list_del(&vxi->vx_list); spin_unlock(&vxlist_lock); free_vx_info(vxi); } } #define task_get_vx_info(i) __task_get_vx_info(i,__FILE__,__LINE__) static __inline__ struct vx_info *__task_get_vx_info(struct task_struct *p, const char *_file, int _line) { struct vx_info *vxi; task_lock(p); vxi = __get_vx_info(p->vx_info, _file, _line); task_unlock(p); return vxi; } #define vx_verify_info(p,i) \ __vx_verify_info((p)->vx_info,i,__FILE__,__LINE__) static __inline__ void __vx_verify_info( struct vx_info *vxa, struct vx_info *vxb, const char *_file, int _line) { if (vxa == vxb) return; printk(KERN_ERR "vx bad assumption (%p==%p) at %s:%d\n", vxa, vxb, _file, _line); } #define vx_task_id(t) ((t)->vx_id) #define vx_current_id() vx_task_id(current) #define vx_check(c,m) __vx_check(vx_current_id(),c,m) /* * check current context for ADMIN/WATCH and * optionally agains supplied argument */ static __inline__ int __vx_check(xid_t cid, xid_t id, unsigned int mode) { if (mode & VX_ARG_MASK) { if ((mode & VX_IDENT) && (id == cid)) return 1; } if (mode & VX_ATR_MASK) { if ((mode & VX_DYNAMIC) && (id >= MIN_D_CONTEXT) && (id <= MAX_S_CONTEXT)) return 1; if ((mode & VX_STATIC) && (id > 1) && (id < MIN_D_CONTEXT)) return 1; } return (((mode & VX_ADMIN) && (cid == 0)) || ((mode & VX_WATCH) && (cid == 1))); } void free_ip_info(struct ip_info *); #define get_ip_info(i) __get_ip_info(i,__FILE__,__LINE__) static __inline__ struct ip_info *__get_ip_info(struct ip_info *ipi, const char *_file, int _line) { /* for now we allow vxi to be null */ if (!ipi) return NULL; vxdprintk("get_ip_info(%p[%d])\t%s:%d\n", ipi, atomic_read(&ipi->ip_refcount), _file, _line); atomic_inc(&ipi->ip_refcount); return ipi; } #define put_ip_info(i) __put_ip_info(i,__FILE__,__LINE__) static __inline__ void __put_ip_info(struct ip_info *ipi, const char *_file, int _line) { /* for now we allow vxi to be null */ if (!ipi) return; vxdprintk("put_ip_info(%p[%d])\t%s:%d\n", ipi, atomic_read(&ipi->ip_refcount), _file, _line); if (atomic_dec_and_lock(&ipi->ip_refcount, &iplist_lock)) { list_del(&ipi->ip_list); spin_unlock(&iplist_lock); free_ip_info(ipi); } } #define task_get_ip_info(i) __task_get_ip_info(i,__FILE__,__LINE__) static __inline__ struct ip_info *__task_get_ip_info(struct task_struct *p, const char *_file, int _line) { struct ip_info *ipi; task_lock(p); ipi = __get_ip_info(p->ip_info, _file, _line); task_unlock(p); return ipi; } #define ip_verify_info(p,i) \ __ip_verify_info((p)->ip_info,i,__FILE__,__LINE__) static __inline__ void __ip_verify_info( struct ip_info *ipa, struct ip_info *ipb, const char *_file, int _line) { if (ipa == ipb) return; printk(KERN_ERR "ip bad assumption (%p==%p) at %s:%d\n", ipa, ipb, _file, _line); } #endif