Exemplo n.º 1
0
int
ipc_port_allocate_reserved(ipc_port_t port, ipc_port_flags_t flags)
{
	struct ipc_port *ipcp, *old;
	int error;

	if (port == IPC_PORT_UNKNOWN || port >= IPC_PORT_UNRESERVED_START)
		return (ERROR_INVALID);

	IPC_PORTS_LOCK();
	old = ipc_port_lookup(port);
	if (old != NULL) {
		IPC_PORT_UNLOCK(old);
		IPC_PORTS_UNLOCK();
		return (ERROR_NOT_FREE);
	}
	IPC_PORTS_UNLOCK();

	ipcp = ipc_port_alloc();
	if (ipcp == NULL)
		return (ERROR_EXHAUSTED);

	IPC_PORTS_LOCK();
	IPC_PORT_LOCK(ipcp);
	error = ipc_port_register(ipcp, port, flags);
	if (error != 0)
		panic("%s: ipc_port_register failed: %m", __func__, error);
	IPC_PORT_UNLOCK(ipcp);
	IPC_PORTS_UNLOCK();

	return (0);
}
Exemplo n.º 2
0
mach_port_name_t
mach_reply_port(
	__unused struct mach_reply_port_args *args)
{
	ipc_port_t port;
	mach_port_name_t name;
	kern_return_t kr;

	kr = ipc_port_alloc(current_task()->itk_space, &name, &port);
	if (kr == KERN_SUCCESS)
		ip_unlock(port);
	else
		name = MACH_PORT_NULL;
	return name;
}
IOReturn com_enkript_driver_Service::hello(task_t target)
{
  EKDebugLog("hello task 0x%x", target);
  kern_return_t ret = KERN_SUCCESS;
  /* allocate receive port
   */
  ret = ipc_port_alloc(get_task_ipcspace(current_task()), &exception_port_name, &exception_port);
  EKDebugLog("ipc_port_alloc() ret=%d", ret);
  if (ret) return kIOReturnError;  
  /* set task exception port
   */
  ret = task_set_exception_ports(target, EXC_MASK_ALL, ipc_port_make_send(exception_port), EXCEPTION_DEFAULT, THREAD_STATE_NONE);
  EKDebugLog("task_set_exception_ports() ret=%d", ret);
  if (ret) return kIOReturnError;  
  /* create exception handler thread
   */
  (void) kernel_thread(kernel_task, exception_handler);

  return kIOReturnSuccess;
}
Exemplo n.º 4
0
int
ipc_port_allocate(ipc_port_t *portp, ipc_port_flags_t flags)
{
	struct ipc_port *ipcp, *old;
	ipc_port_t port;
	int error;

	ipcp = ipc_port_alloc();
	if (ipcp == NULL)
		return (ERROR_EXHAUSTED);

	IPC_PORTS_LOCK();
	for (;;) {
		if (ipc_port_next < IPC_PORT_UNRESERVED_START) {
			ipc_port_next = IPC_PORT_UNRESERVED_START;
			continue;
		}
		port = ipc_port_next++;

		old = ipc_port_lookup(port);
		if (old != NULL) {
			IPC_PORT_UNLOCK(old);
			continue;
		}

		IPC_PORT_LOCK(ipcp);
		error = ipc_port_register(ipcp, port, flags);
		if (error != 0)
			panic("%s: ipc_port_register failed: %m", __func__,
			      error);
		IPC_PORT_UNLOCK(ipcp);

		IPC_PORTS_UNLOCK();

		*portp = port;

		return (0);
	}
}
Exemplo n.º 5
0
kern_return_t
mach_port_allocate_full(
	ipc_space_t		space,
	mach_port_right_t	right,
	mach_port_t		proto,
	mach_port_qos_t		*qosp,
	mach_port_name_t	*namep)
{
	ipc_kmsg_t		kmsg;
	kern_return_t		kr;

	if (space == IS_NULL)
		return (KERN_INVALID_TASK);

	if (proto != MACH_PORT_NULL)
		return (KERN_INVALID_VALUE);

	if (qosp->name) {
		if (!MACH_PORT_VALID (*namep))
			return (KERN_INVALID_VALUE);
		if (is_fast_space (space))
			return (KERN_FAILURE);
	}

	if (qosp->prealloc) {
		mach_msg_size_t size = qosp->len + MAX_TRAILER_SIZE;
		if (right != MACH_PORT_RIGHT_RECEIVE)
			return (KERN_INVALID_VALUE);
		kmsg = (ipc_kmsg_t)kalloc(ikm_plus_overhead(size));
		if (kmsg == IKM_NULL)
			return (KERN_RESOURCE_SHORTAGE);
		ikm_init(kmsg, size);
	}

	switch (right) {
	    case MACH_PORT_RIGHT_RECEIVE:
	    {
		ipc_port_t	port;

		if (qosp->name)
			kr = ipc_port_alloc_name(space, *namep, &port);
		else
			kr = ipc_port_alloc(space, namep, &port);
		if (kr == KERN_SUCCESS) {
			if (qosp->prealloc) 
				ipc_kmsg_set_prealloc(kmsg, port);

			ip_unlock(port);

		} else if (qosp->prealloc)
			ipc_kmsg_free(kmsg);
		break;
	    }

	    case MACH_PORT_RIGHT_PORT_SET:
	    {
		ipc_pset_t	pset;

		if (qosp->name)
			kr = ipc_pset_alloc_name(space, *namep, &pset);
		else
			kr = ipc_pset_alloc(space, namep, &pset);
		if (kr == KERN_SUCCESS)
			ips_unlock(pset);
		break;
	    }

	    case MACH_PORT_RIGHT_DEAD_NAME:
		kr = ipc_object_alloc_dead(space, namep);
		break;

	    default:
		kr = KERN_INVALID_VALUE;
		break;
	}

	return (kr);
}