port_subr.c revision 11dc39dd3ec06044a7e912a5e26b6d5c55ecd731
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* This file containts all the functions required for interactions of
* event sources with the event port file system.
*/
#include <sys/sysmacros.h>
#include <sys/poll_impl.h>
#include <sys/port_impl.h>
/*
* Maximum number of elements allowed to be passed in a single call of a
* port function (port_sendn(), port_getn(). We need to allocate kernel memory
* for all of them at once, so we can't let it scale without limit.
*/
/*
* Block other threads from using a port.
* We enter holding portq->portq_mutex but
* we may drop and reacquire this lock.
* Callers must deal with this fact.
*/
void
{
}
/*
* Undo port_block(portq).
*/
void
{
}
/*
* Called from pollwakeup(PORT_SOURCE_FD source) to determine
* if the port's fd needs to be notified of poll events. If yes,
* we mark the port indicating that pollwakeup() is referring
* it so that the port_t does not disappear. pollwakeup()
* calls port_pollwkdone() after notifying. In port_pollwkdone(),
* we clear the hold on the port_t (clear PORTQ_POLLWK_PEND).
*/
int
{
int events = 0;
/*
* Normally, we should not have a situation where PORTQ_POLLIN
* and PORTQ_POLLWK_PEND are set at the same time, but it is
* possible. So, in pollwakeup() we ensure that no new fd's get
* added to the pollhead between the time it notifies poll events
* and calls poll_wkupdone() where we clear the PORTQ_POLLWK_PEND flag.
*/
}
return (events);
}
void
{
}
/*
* The port_send_event() function is used by all event sources to submit
* trigerred events to a port. All the data required for the event management
* is already stored in the port_kevent_t structure.
* The event port internal data is stored in the port_kevent_t structure
* during the allocation time (see port_alloc_event()). The data related to
* the event itself and to the event source management is stored in the
* port_kevent_t structure between the allocation time and submit time
* (see port_init_event()).
*
* This function is often called from interrupt level.
*/
void
{
/* Event already in the port queue */
}
return;
}
/* put event in the port queue */
portq->portq_nent++;
/*
* Remove the PORTQ_WAIT_EVENTS flag to indicate
* that new events are available.
*/
}
/* Check if thread is in port_close() waiting for outstanding events */
/* Check if all outstanding events are already in port queue */
}
if (portq->portq_getn == 0) {
/*
* No thread retrieving events -> check if enough events are
* available to satify waiting threads.
*/
if (portq->portq_thread &&
}
/*
* If some thread is polling the port's fd, then notify it.
* For PORT_SOURCE_FD source, we don't need to call pollwakeup()
* here as it will result in a recursive call(PORT_SOURCE_FD source
* is pollwakeup()). Therefore pollwakeup() itself will notify the
* ports if being polled.
*/
} else {
}
}
/*
* The port_alloc_event() function has to be used by all event sources
* to request an slot for event notification.
* The slot reservation could be denied because of lack of resources.
* For that reason the event source should allocate an event slot as early
* as possible and be prepared to get an error code instead of the
* port event pointer.
* Al current event sources allocate an event slot during a system call
* entry. They return an error code to the application if an event slot
* could not be reserved.
* It is also recommended to associate the event source with the port
* before some other port function is used.
* The port argument is a file descriptor obtained by the application as
* a return value of port_create().
* Possible values of flags are:
* PORT_ALLOC_DEFAULT
* This is the standard type of port events. port_get(n) will free this
* type of event structures as soon as the events are delivered to the
* application.
* PORT_ALLOC_PRIVATE
* This type of event will be use for private use of the event source.
* The port_get(n) function will deliver events of such an structure to
* the application but it will not free the event structure itself.
* The event source must free this structure using port_free_event().
* PORT_ALLOC_CACHED
* This type of events is used when the event source helds an own
* cache.
* The port_get(n) function will deliver events of such an structure to
* the application but it will not free the event structure itself.
* The event source must free this structure using port_free_event().
*/
int
{
return (EBADF);
return (EBADFD);
}
return (ENOMEM);
}
/*
* port_max_events is controlled by the resource control
* process.port-max-events
*/
return (EAGAIN);
}
return (0);
}
/*
* This function is faster than the standard port_alloc_event() and
* can be used when the event source already allocated an event from
* a port.
*/
int
{
int error;
if (error == 0)
return (error);
}
/*
* port_alloc_event_local() is reserved for internal use only.
* It is doing the same job as port_alloc_event() but with the event port
* pointer as the first argument.
* The check of the validity of the port file descriptor is skipped here.
*/
int
{
return (ENOMEM);
return (EAGAIN);
}
return (0);
}
/*
* port_alloc_event_block() has the same functionality of port_alloc_event() +
* - it blocks if not enough event slots are available and
* - it blocks if not enough memory is available.
* Currently port_dispatch() is using this function to increase the
* reliability of event delivery for library event sources.
*/
int
{
/* signal detected */
return (EINTR);
}
}
return (0);
}
/*
* Take an event out of the port queue
*/
static void
{
portq->portq_nent--;
}
/*
* The port_remove_done_event() function takes a fired event out of the
* port queue.
* Currently this function is required to cancel a fired event because
* the application is delivering new association data (see port_associate_fd()).
*/
void
{
/* wait for port_get() or port_getn() */
/* event still in port queue */
if (portq->portq_getn) {
/*
* There could be still fired events in the temp queue;
* push those events back to the port queue and
* remove requested event afterwards.
*/
}
/* now remove event from the port queue */
}
}
/*
* Return port event back to the kmem_cache.
* If the event is currently in the port queue the event itself will only
* be set as invalid. The port_get(n) function will not deliver such events
* to the application and it will return them back to the kmem_cache.
*/
void
{
return;
return;
}
return;
}
return;
}
/*
* Another thread is closing the event port.
* That thread will sleep until all allocated event
* structures returned to the event port framework.
* The portq_mutex is used to synchronize the status
* of the allocated event structures (port_curr).
*/
}
}
/*
* This event port internal function is used by port_free_event() and
* other port internal functions to return event structures back to the
* kmem_cache.
*/
void
{
int wakeup;
pkevp->portkev_flags = 0;
if (counter == 0) {
}
/* Submit a POLLOUT event if requested */
if (wakeup)
}
/*
* port_init_event(port_event_t *pev, uintptr_t object, void *user,
* int (*port_callback)(void *, int *, pid_t, int, void *), void *sysarg);
* This function initializes most of the "wired" elements of the port
* event structure. This is normally being used just after the allocation
* of the port event structure.
* pkevp : pointer to the port event structure
* object : object associated with this event structure
* user : user defined pointer delivered with the association function
* port_callback:
* Address of the callback function which will be called
* - just before the event is delivered to the application.
* The callback function is called in user context and can be
* used for copyouts, e.g.
* - on close() or dissociation of the event. The sub-system
* must remove immediately every existing association of
* some object with this event.
* sysarg : event source propietary data
*/
void
int (*port_callback)(void *, int *, pid_t, int, void *),
void *sysarg)
{
}
/*
* This routine removes a portfd_t from the fd cache's hash table.
*/
void
{
if (--pcp->pc_fdcount == 0) {
/*
* signal the thread which may have blocked in
* port_close_sourcefd() on lastclose waiting
* for pc_fdcount to drop to 0.
*/
}
return;
}
/* polldat struct found */
if (--pcp->pc_fdcount == 0) {
/*
* signal the thread which may have blocked in
* port_close_sourcefd() on lastclose waiting
* for pc_fdcount to drop to 0.
*/
}
break;
}
}
}
/*
* The port_push_eventq() function is used to move all remaining events
* from the temporary queue used in port_get(n)() to the standard port
* queue.
*/
void
{
/*
* Append temporary portq_get_list to the port queue. On return
* the temporary portq_get_list is empty.
*/
portq->portq_tnent = 0;
}
/*
* The port_remove_fd_object() function frees all resources associated with
* delivered portfd_t structure.
*/
void
{
int error;
}
/*
* move events from the temporary "get" queue
* back to the port queue
*/
}
/* cleanup merged port queue */
}
if (pkevp->portkev_callback) {
pkevp);
}
/* remove polldat struct */
}
/*
* The port_close_fd() function dissociates a file descriptor from a port
* and removes all allocated resources.
* close(2) detects in the uf_entry_t structure that the fd is associated
* with a port (at least one port).
* The fd can be associated with several ports.
*/
void
{
/*
* the portfd_t passed in should be for this proc.
*/
}
/*
* The port_associate_ksource() function associates an event source with a port.
* On port_close() all associated sources are requested to free all local
* resources associated with the event port.
* The association of a source with a port can only be done one time. Further
* calls of this function will only increment the reference counter.
* The allocated port_source_t structure is removed from the port as soon as
* the reference counter becomes 0.
*/
/* ARGSUSED */
int
{
port_source_t **ps;
return (EBADF);
return (EBADFD);
}
break;
}
/* Create association of the event source with the port */
return (ENOMEM);
}
if (*ps)
} else {
/* entry already available, source is only requesting count */
pse->portsrc_cnt++;
}
if (portsrc)
return (0);
}
/*
* The port_dissociate_ksource() function dissociates an event source from
* a port.
*/
int
{
port_source_t **psh;
return (EINVAL);
return (EBADF);
return (EBADFD);
}
if (--ps->portsrc_cnt == 0) {
/* last association removed -> free source structure */
/* first entry */
if (ps->portsrc_next)
} else {
if (ps->portsrc_next)
}
}
return (0);
}