Ejemplo n.º 1
0
int
ipmi_kcs_ctx_io_init (ipmi_kcs_ctx_t ctx)
{
  if (!ctx || ctx->magic != IPMI_KCS_CTX_MAGIC)
    {
      ERR_TRACE (ipmi_kcs_ctx_errormsg (ctx), ipmi_kcs_ctx_errnum (ctx));
      return (-1);
    }

  if (ctx->io_init)
    goto out;

#ifdef __FreeBSD__
#ifdef USE_IOPERM
  /* i386_set_ioperm has known problems on FBSD 5.x (bus errors). */
  if (i386_set_ioperm (ctx->driver_address, 0x02, 0x01))
    {
      KCS_ERRNO_TO_KCS_ERRNUM (ctx, errno);
      return (-1);
    }
#else  /* !USE_IOPERM */
  /* Opening /dev/io raises IOPL bits for current process. */
  if ((ctx->dev_fd = open ("/dev/io", O_RDONLY)) < 0)
    {
      KCS_ERRNO_TO_KCS_ERRNUM (ctx, errno);
      return (-1);
    }
#endif /* !USE_IOPERM */
#else  /* !__FreeBSD__ */
#if HAVE_IOPL
  if (iopl (3) < 0)
    {
      KCS_ERRNO_TO_KCS_ERRNUM (ctx, errno);
      return (-1);
    }
#else /* !HAVE_IOPL */
  /* otherwise, we always return a system error */
  KCS_SET_ERRNUM (ctx, IPMI_KCS_ERR_SYSTEM_ERROR);
  return (-1);
#endif /* !HAVE_IOPL */
#endif /* !__FreeBSD__ */

  ctx->io_init = 1;
 out:
  ctx->errnum = IPMI_KCS_ERR_SUCCESS;
  return (0);
}
Ejemplo n.º 2
0
static int
take_permissions(ClipMachine * ClipMachineMemory, int port)
{
#ifdef OS_LINUX
   if (plevel > 2)
      return 0;
   if (port >= 0x400)
   {
      if (plevel < 3)
      {
       try_iopl:
	 if (iopl(3))
	 {
	    _clip_trap_printf(ClipMachineMemory, __FILE__, __LINE__, "Cannot take io permissons: %s", strerror(errno));
	    return _clip_call_errblock(ClipMachineMemory, -1);
	 }
	 plevel = 3;
	 return 0;
      }
   }
   else
   {
      if (ioperm(port, 1, 1))
	 goto try_iopl;
   }
#endif

#ifdef OS_FREEBSD
#ifdef ARCH_i386
   if (i386_set_ioperm(port, 1, 1))
   {
      _clip_trap_printf(ClipMachineMemory, __FILE__, __LINE__, "Cannot take io permissons: %s", strerror(errno));
      return _clip_call_errblock(ClipMachineMemory, -1);
   }
#endif
#endif

#ifdef OS_GYGWIN
#endif

   return 0;
}
Ejemplo n.º 3
0
int
sys_sysarch(struct proc *p, void *v, register_t *retval)
{
    struct sys_sysarch_args /* {
		syscallarg(int) op;
		syscallarg(void *) parms;
	} */ *uap = v;
    int error = 0;

    switch(SCARG(uap, op)) {
#ifdef	USER_LDT
    case I386_GET_LDT:
        error = i386_get_ldt(p, SCARG(uap, parms), retval);
        break;

    case I386_SET_LDT:
        error = i386_set_ldt(p, SCARG(uap, parms), retval);
        break;
#endif

    case I386_IOPL:
        error = i386_iopl(p, SCARG(uap, parms), retval);
        break;

    case I386_GET_IOPERM:
        error = i386_get_ioperm(p, SCARG(uap, parms), retval);
        break;

    case I386_SET_IOPERM:
        error = i386_set_ioperm(p, SCARG(uap, parms), retval);
        break;

#ifdef VM86
    case I386_VM86:
        error = i386_vm86(p, SCARG(uap, parms), retval);
        break;
#endif

    case I386_GET_FSBASE:
    {
        uint32_t base = i386_get_threadbase(p, TSEG_FS);

        error = copyout(&base, SCARG(uap, parms), sizeof(base));
        break;
    }

    case I386_SET_FSBASE:
    {
        uint32_t base;

        if ((error = copyin(SCARG(uap, parms), &base, sizeof(base))))
            break;
        error = i386_set_threadbase(p, base, TSEG_FS);
        break;
    }

    case I386_GET_GSBASE:
    {
        uint32_t base = i386_get_threadbase(p, TSEG_GS);

        error = copyout(&base, SCARG(uap, parms), sizeof(base));
        break;
    }

    case I386_SET_GSBASE:
    {
        uint32_t base;

        if ((error = copyin(SCARG(uap, parms), &base, sizeof(base))))
            break;
        error = i386_set_threadbase(p, base, TSEG_GS);
        break;
    }

    default:
        error = EINVAL;
        break;
    }
    return (error);
}