From 68687d61630314a79c2d87db2e041e7560824e10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sat, 5 Oct 2002 01:20:39 +0000 Subject: [PATCH] Now includes sem.h (since it needs the private create_sem_etc() call). Cleaned up the source a bit. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1378 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/core/port.c | 203 +++++++++++++++++++++++------------------ 1 file changed, 114 insertions(+), 89 deletions(-) diff --git a/src/kernel/core/port.c b/src/kernel/core/port.c index 1c83bb10bb..2147e89e03 100644 --- a/src/kernel/core/port.c +++ b/src/kernel/core/port.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -17,6 +18,7 @@ #include #include + struct port_msg { int msg_code; cbuf* data_cbuf; @@ -203,7 +205,7 @@ create_port(int32 queue_length, const char *name) } // init cbuf list of the queue - for (i=0; i= next_port % MAX_PORTS) { @@ -276,15 +278,16 @@ out: return retval; } + status_t close_port(port_id id) { int state; int slot; - if(ports_active == false) + if (ports_active == false) return B_BAD_PORT_ID; - if(id < 0) + if (id < 0) return B_BAD_PORT_ID; slot = id % MAX_PORTS; @@ -308,6 +311,7 @@ close_port(port_id id) return B_NO_ERROR; } + status_t delete_port(port_id id) { @@ -320,9 +324,9 @@ delete_port(port_id id) char *old_name; struct port_msg *q; - if(ports_active == false) + if (ports_active == false) return B_BAD_PORT_ID; - if(id < 0) + if (id < 0) return B_BAD_PORT_ID; slot = id % MAX_PORTS; @@ -366,6 +370,7 @@ delete_port(port_id id) return B_NO_ERROR; } + port_id find_port(const char *port_name) { @@ -373,17 +378,17 @@ find_port(const char *port_name) int state; int ret_val = B_BAD_PORT_ID; - if(ports_active == false) + if (ports_active == false) return B_BAD_PORT_ID; - if(port_name == NULL) + if (port_name == NULL) return B_BAD_PORT_ID; // lock list of ports state = disable_interrupts(); GRAB_PORT_LIST_LOCK(); - + // loop over list - for(i=0; i 0)) + if ((msg_buffer == NULL) && (buffer_size > 0)) return EINVAL; if (timeout < 0) return EINVAL; @@ -651,7 +653,7 @@ read_port_etc(port_id id, state = disable_interrupts(); GRAB_PORT_LOCK(ports[slot]); - if(ports[slot].id != id) { + if (ports[slot].id != id) { RELEASE_PORT_LOCK(ports[slot]); restore_interrupts(state); dprintf("read_port_etc: invalid port_id %ld\n", id); @@ -736,15 +738,16 @@ read_port_etc(port_id id, return siz; } + status_t set_port_owner(port_id id, team_id team) { int slot; int state; - if(ports_active == false) + if (ports_active == false) return B_BAD_PORT_ID; - if(id < 0) + if (id < 0) return B_BAD_PORT_ID; slot = id % MAX_PORTS; @@ -752,7 +755,7 @@ set_port_owner(port_id id, team_id team) state = disable_interrupts(); GRAB_PORT_LOCK(ports[slot]); - if(ports[slot].id != id) { + if (ports[slot].id != id) { RELEASE_PORT_LOCK(ports[slot]); restore_interrupts(state); dprintf("set_port_owner: invalid port_id %ld\n", id); @@ -769,22 +772,17 @@ set_port_owner(port_id id, team_id team) return B_NO_ERROR; } + status_t -write_port(port_id id, - int32 msg_code, - const void *msg_buffer, - size_t buffer_size) +write_port(port_id id, int32 msg_code, const void *msg_buffer, size_t buffer_size) { return write_port_etc(id, msg_code, msg_buffer, buffer_size, 0, 0); } + status_t -write_port_etc(port_id id, - int32 msg_code, - const void *msg_buffer, - size_t buffer_size, - uint32 flags, - bigtime_t timeout) +write_port_etc(port_id id, int32 msg_code, const void *msg_buffer, + size_t buffer_size, uint32 flags, bigtime_t timeout) { int slot; int state; @@ -795,9 +793,9 @@ write_port_etc(port_id id, int32 c1, c2; int err; - if(ports_active == false) + if (ports_active == false) return B_BAD_PORT_ID; - if(id < 0) + if (id < 0) return B_BAD_PORT_ID; // mask irrelevant flags @@ -812,7 +810,7 @@ write_port_etc(port_id id, state = disable_interrupts(); GRAB_PORT_LOCK(ports[slot]); - if(ports[slot].id != id) { + if (ports[slot].id != id) { RELEASE_PORT_LOCK(ports[slot]); restore_interrupts(state); dprintf("write_port_etc: invalid port_id %ld\n", id); @@ -905,21 +903,24 @@ write_port_etc(port_id id, return B_NO_ERROR; } + /* this function cycles through the ports table, deleting all the ports that are owned by the passed team_id */ -int delete_owned_ports(team_id owner) + +int +delete_owned_ports(team_id owner) { int state; int i; int count = 0; - - if(ports_active == false) + + if (ports_active == false) return B_BAD_PORT_ID; state = disable_interrupts(); GRAB_PORT_LIST_LOCK(); - for(i=0; i= KERNEL_BASE && (addr)uinfo <= KERNEL_TOP) + if ((addr)uinfo >= KERNEL_BASE && (addr)uinfo <= KERNEL_TOP) return ERR_VM_BAD_USER_MEMORY; res = get_port_info(id, &info); // copy to userspace rc = user_memcpy(uinfo, &info, sizeof(struct port_info)); - if(rc < 0) + if (rc < 0) return rc; return res; } -status_t user_get_next_port_info(team_id uteam, - int32 *ucookie, - struct port_info *uinfo) + +status_t +user_get_next_port_info(team_id uteam, int32 *ucookie, struct port_info *uinfo) { status_t res; struct port_info info; @@ -1122,39 +1137,45 @@ status_t user_get_next_port_info(team_id uteam, return EINVAL; if (uinfo == NULL) return EINVAL; - if((addr)ucookie >= KERNEL_BASE && (addr)ucookie <= KERNEL_TOP) + if ((addr)ucookie >= KERNEL_BASE && (addr)ucookie <= KERNEL_TOP) return ERR_VM_BAD_USER_MEMORY; - if((addr)uinfo >= KERNEL_BASE && (addr)uinfo <= KERNEL_TOP) + if ((addr)uinfo >= KERNEL_BASE && (addr)uinfo <= KERNEL_TOP) return ERR_VM_BAD_USER_MEMORY; // copy from userspace rc = user_memcpy(&cookie, ucookie, sizeof(int32)); - if(rc < 0) + if (rc < 0) return rc; res = get_next_port_info(uteam, &cookie, &info); // copy to userspace rc = user_memcpy(ucookie, &info, sizeof(int32)); - if(rc < 0) + if (rc < 0) return rc; rc = user_memcpy(uinfo, &info, sizeof(struct port_info)); - if(rc < 0) + if (rc < 0) return rc; return res; } -ssize_t user_port_buffer_size_etc(port_id port, uint32 flags, bigtime_t timeout) + +ssize_t +user_port_buffer_size_etc(port_id port, uint32 flags, bigtime_t timeout) { return port_buffer_size_etc(port, flags | B_CAN_INTERRUPT, timeout); } -ssize_t user_port_count(port_id port) + +ssize_t +user_port_count(port_id port) { return port_count(port); } -status_t user_read_port_etc(port_id uport, int32 *umsg_code, void *umsg_buffer, - size_t ubuffer_size, uint32 uflags, bigtime_t utimeout) + +status_t +user_read_port_etc(port_id uport, int32 *umsg_code, void *umsg_buffer, + size_t ubuffer_size, uint32 uflags, bigtime_t utimeout) { ssize_t res; int32 msg_code; @@ -1180,13 +1201,17 @@ status_t user_read_port_etc(port_id uport, int32 *umsg_code, void *umsg_buffer, return res; } -status_t user_set_port_owner(port_id port, team_id team) + +status_t +user_set_port_owner(port_id port, team_id team) { return set_port_owner(port, team); } -status_t user_write_port_etc(port_id uport, int32 umsg_code, void *umsg_buffer, - size_t ubuffer_size, uint32 uflags, bigtime_t utimeout) + +status_t +user_write_port_etc(port_id uport, int32 umsg_code, void *umsg_buffer, + size_t ubuffer_size, uint32 uflags, bigtime_t utimeout) { if (umsg_buffer == NULL) return EINVAL;