rem: int state;
add: cpu_status state;
context: send_data(thread_id tid, int32 code, const void *buffer, size_t buffer_size){	struct thread *target;	sem_id cached_sem;	int state;	status_t rv;	cbuf *data;	state = disable_interrupts();	GRAB_THREAD_LOCK();	target = thread_get_thread_struct_locked(tid);	if (!target) {		RELEASE_THREAD_LOCK();		restore_interrupts(state);		return B_BAD_THREAD_ID;	}	cached_sem = target->msg.write_sem;	RELEASE_THREAD_LOCK();	restore_interrupts(state);	if (buffer_size > THREAD_MAX_MESSAGE_SIZE)		return B_NO_MEMORY;	rv = acquire_sem_etc(cached_sem, 1, B_CAN_INTERRUPT, 0);	if (rv == B_INTERRUPTED)		// We got interrupted by a signal		return rv;	if (rv != B_OK)		// Any other acquisition problems may be due to thread deletion		return B_BAD_THREAD_ID;	if (buffer_size > 0) {		data = cbuf_get_chain(buffer_size);		if (!data)			return B_NO_MEMORY;		rv = cbuf_user_memcpy_to_chain(data, 0, buffer, buffer_size);		if (rv < 0) {			cbuf_free_chain(data);			return B_NO_MEMORY;		}	} else		data = NULL;	state = disable_interrupts();	GRAB_THREAD_LOCK();	// The target thread could have been deleted at this point	target = thread_get_thread_struct_locked(tid);	if (!target) {		RELEASE_THREAD_LOCK();		restore_interrupts(state);		cbuf_free_chain(data);		return B_BAD_THREAD_ID;	}	// Save message informations	target->msg.sender = thread_get_current_thread()->id;	target->msg.code = code;	target->msg.size = buffer_size;	target->msg.buffer = data;	cached_sem = target->msg.read_sem;	RELEASE_THREAD_LOCK();	restore_interrupts(state);	release_sem(cached_sem);	return B_OK;}