2004-11-27 15:03:48 +03:00
|
|
|
/*
|
2007-07-27 05:34:14 +04:00
|
|
|
* Copyright 2002-2007, Axel Dörfler, axeld@pinc-software.de.
|
2004-11-27 15:03:48 +03:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Copyright 2001, Mark-Jan Bastian. All rights reserved.
|
|
|
|
* Distributed under the terms of the NewOS License.
|
|
|
|
*/
|
|
|
|
|
2007-10-11 12:30:18 +04:00
|
|
|
/*! Ports for IPC */
|
2004-02-23 07:02:24 +03:00
|
|
|
|
axeld + bonefish:
* Implemented automatic syscall restarts:
- A syscall can indicate that it has been interrupted and can be
restarted by setting a respective bit in thread::flags. It can
store parameters it wants to be preserved for the restart in
thread::syscall_restart::parameters. Another thread::flags bit
indicates whether it has been restarted.
- handle_signals() clears the restart flag, if the handled signal
has a handler function installed and SA_RESTART is not set. Another
thread flag (THREAD_FLAGS_DONT_RESTART_SYSCALL) can prevent syscalls
from being restarted, even if they could be (not used yet, but we
might want to use it in resume_thread(), so that we stay
behaviorally compatible with BeOS).
- The architecture specific syscall handler restarts the syscall, if
the restart flag is set. Implemented for x86 only.
- Added some support functions in the private <syscall_restart.h> to
simplify the syscall restart code in the syscalls.
- Adjusted all syscalls that can potentially be restarted accordingly.
- _user_ioctl() sets new thread flag THREAD_FLAGS_IOCTL_SYSCALL while
calling the underlying FS's/driver's hook, so that syscall restarts
can also be supported there.
* thread_at_kernel_exit() invokes handle_signals() in a loop now, as
long as the latter indicates that the thread shall be suspended, so
that after waking up signals received in the meantime will be handled
before the thread returns to userland. Adjusted handle_signals()
accordingly -- when encountering a suspending signal we don't check
for further signals.
* Fixed sigsuspend(): Suspending the thread and rescheduling doesn't
result in the correct behavior. Instead we employ a temporary
condition variable and interruptably wait on it. The POSIX test
suite test passes, now.
* Made the switch_sem[_etc]() behavior on interruption consistent.
Depending on when the signal arrived (before the call or when already
waiting) the first semaphore would or wouldn't be released. Now we
consistently release it.
* Refactored _user_{read,write}[v]() syscalls. Use a common function for
either pair. The iovec version doesn't fail anymore, if anything could
be read/written at all. It also checks whether a complete vector
could be read/written, so that we won't skip data, if the underlying
FS/driver couldn't read/write more ATM.
* Some refactoring in the x86 syscall handler: The int 99 and sysenter
handlers use a common subroutine to avoid code duplication.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23983 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-02-17 18:48:30 +03:00
|
|
|
#include <port.h>
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <iovec.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
#include <OS.h>
|
2004-03-16 05:53:41 +03:00
|
|
|
|
axeld + bonefish:
* Implemented automatic syscall restarts:
- A syscall can indicate that it has been interrupted and can be
restarted by setting a respective bit in thread::flags. It can
store parameters it wants to be preserved for the restart in
thread::syscall_restart::parameters. Another thread::flags bit
indicates whether it has been restarted.
- handle_signals() clears the restart flag, if the handled signal
has a handler function installed and SA_RESTART is not set. Another
thread flag (THREAD_FLAGS_DONT_RESTART_SYSCALL) can prevent syscalls
from being restarted, even if they could be (not used yet, but we
might want to use it in resume_thread(), so that we stay
behaviorally compatible with BeOS).
- The architecture specific syscall handler restarts the syscall, if
the restart flag is set. Implemented for x86 only.
- Added some support functions in the private <syscall_restart.h> to
simplify the syscall restart code in the syscalls.
- Adjusted all syscalls that can potentially be restarted accordingly.
- _user_ioctl() sets new thread flag THREAD_FLAGS_IOCTL_SYSCALL while
calling the underlying FS's/driver's hook, so that syscall restarts
can also be supported there.
* thread_at_kernel_exit() invokes handle_signals() in a loop now, as
long as the latter indicates that the thread shall be suspended, so
that after waking up signals received in the meantime will be handled
before the thread returns to userland. Adjusted handle_signals()
accordingly -- when encountering a suspending signal we don't check
for further signals.
* Fixed sigsuspend(): Suspending the thread and rescheduling doesn't
result in the correct behavior. Instead we employ a temporary
condition variable and interruptably wait on it. The POSIX test
suite test passes, now.
* Made the switch_sem[_etc]() behavior on interruption consistent.
Depending on when the signal arrived (before the call or when already
waiting) the first semaphore would or wouldn't be released. Now we
consistently release it.
* Refactored _user_{read,write}[v]() syscalls. Use a common function for
either pair. The iovec version doesn't fail anymore, if anything could
be read/written at all. It also checks whether a complete vector
could be read/written, so that we won't skip data, if the underlying
FS/driver couldn't read/write more ATM.
* Some refactoring in the x86 syscall handler: The int 99 and sysenter
handlers use a common subroutine to avoid code duplication.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23983 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-02-17 18:48:30 +03:00
|
|
|
#include <arch/int.h>
|
|
|
|
#include <cbuf.h>
|
2004-12-14 02:02:18 +03:00
|
|
|
#include <kernel.h>
|
2002-10-05 05:20:39 +04:00
|
|
|
#include <sem.h>
|
axeld + bonefish:
* Implemented automatic syscall restarts:
- A syscall can indicate that it has been interrupted and can be
restarted by setting a respective bit in thread::flags. It can
store parameters it wants to be preserved for the restart in
thread::syscall_restart::parameters. Another thread::flags bit
indicates whether it has been restarted.
- handle_signals() clears the restart flag, if the handled signal
has a handler function installed and SA_RESTART is not set. Another
thread flag (THREAD_FLAGS_DONT_RESTART_SYSCALL) can prevent syscalls
from being restarted, even if they could be (not used yet, but we
might want to use it in resume_thread(), so that we stay
behaviorally compatible with BeOS).
- The architecture specific syscall handler restarts the syscall, if
the restart flag is set. Implemented for x86 only.
- Added some support functions in the private <syscall_restart.h> to
simplify the syscall restart code in the syscalls.
- Adjusted all syscalls that can potentially be restarted accordingly.
- _user_ioctl() sets new thread flag THREAD_FLAGS_IOCTL_SYSCALL while
calling the underlying FS's/driver's hook, so that syscall restarts
can also be supported there.
* thread_at_kernel_exit() invokes handle_signals() in a loop now, as
long as the latter indicates that the thread shall be suspended, so
that after waking up signals received in the meantime will be handled
before the thread returns to userland. Adjusted handle_signals()
accordingly -- when encountering a suspending signal we don't check
for further signals.
* Fixed sigsuspend(): Suspending the thread and rescheduling doesn't
result in the correct behavior. Instead we employ a temporary
condition variable and interruptably wait on it. The POSIX test
suite test passes, now.
* Made the switch_sem[_etc]() behavior on interruption consistent.
Depending on when the signal arrived (before the call or when already
waiting) the first semaphore would or wouldn't be released. Now we
consistently release it.
* Refactored _user_{read,write}[v]() syscalls. Use a common function for
either pair. The iovec version doesn't fail anymore, if anything could
be read/written at all. It also checks whether a complete vector
could be read/written, so that we won't skip data, if the underlying
FS/driver couldn't read/write more ATM.
* Some refactoring in the x86 syscall handler: The int 99 and sysenter
handlers use a common subroutine to avoid code duplication.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23983 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-02-17 18:48:30 +03:00
|
|
|
#include <syscall_restart.h>
|
2004-03-16 05:53:41 +03:00
|
|
|
#include <team.h>
|
2004-03-12 07:57:38 +03:00
|
|
|
#include <util/list.h>
|
2007-10-02 23:47:31 +04:00
|
|
|
#include <wait_for_objects.h>
|
2004-03-12 07:57:38 +03:00
|
|
|
|
2002-10-05 05:20:39 +04:00
|
|
|
|
2004-03-05 04:23:43 +03:00
|
|
|
//#define TRACE_PORTS
|
|
|
|
#ifdef TRACE_PORTS
|
|
|
|
# define TRACE(x) dprintf x
|
|
|
|
#else
|
|
|
|
# define TRACE(x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2004-03-12 07:57:38 +03:00
|
|
|
typedef struct port_msg {
|
|
|
|
list_link link;
|
|
|
|
int32 code;
|
|
|
|
cbuf *buffer_chain;
|
|
|
|
size_t size;
|
|
|
|
} port_msg;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
struct port_entry {
|
2004-03-12 07:57:38 +03:00
|
|
|
port_id id;
|
|
|
|
team_id owner;
|
|
|
|
int32 capacity;
|
|
|
|
spinlock lock;
|
|
|
|
const char *name;
|
|
|
|
sem_id read_sem;
|
|
|
|
sem_id write_sem;
|
2005-01-14 23:45:18 +03:00
|
|
|
int32 total_count; // messages read from port since creation
|
2007-10-02 23:47:31 +04:00
|
|
|
select_info *select_infos;
|
2004-03-12 07:57:38 +03:00
|
|
|
struct list msg_queue;
|
2002-07-09 16:24:59 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-10-11 12:30:18 +04:00
|
|
|
#define MAX_QUEUE_LENGTH 4096
|
|
|
|
#define PORT_MAX_MESSAGE_SIZE 65536
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-04-22 02:57:39 +04:00
|
|
|
// sMaxPorts must be power of 2
|
|
|
|
static int32 sMaxPorts = 4096;
|
2004-05-13 23:35:49 +04:00
|
|
|
static int32 sUsedPorts = 0;
|
2004-03-12 08:09:29 +03:00
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
static struct port_entry *sPorts = NULL;
|
|
|
|
static area_id sPortArea = 0;
|
|
|
|
static bool sPortsActive = false;
|
2004-11-27 15:03:48 +03:00
|
|
|
static port_id sNextPort = 1;
|
|
|
|
static int32 sFirstFreeSlot = 1;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
static spinlock sPortSpinlock = 0;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
#define GRAB_PORT_LIST_LOCK() acquire_spinlock(&sPortSpinlock)
|
|
|
|
#define RELEASE_PORT_LIST_LOCK() release_spinlock(&sPortSpinlock)
|
2002-07-09 16:24:59 +04:00
|
|
|
#define GRAB_PORT_LOCK(s) acquire_spinlock(&(s).lock)
|
|
|
|
#define RELEASE_PORT_LOCK(s) release_spinlock(&(s).lock)
|
|
|
|
|
2002-08-05 09:25:26 +04:00
|
|
|
|
2007-10-11 12:30:18 +04:00
|
|
|
static int
|
2002-08-05 09:25:26 +04:00
|
|
|
dump_port_list(int argc, char **argv)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2006-03-24 15:59:23 +03:00
|
|
|
const char *name = NULL;
|
|
|
|
team_id owner = -1;
|
|
|
|
int32 i;
|
|
|
|
|
|
|
|
if (argc > 2) {
|
|
|
|
if (!strcmp(argv[1], "team") || !strcmp(argv[1], "owner"))
|
|
|
|
owner = strtoul(argv[2], NULL, 0);
|
|
|
|
else if (!strcmp(argv[1], "name"))
|
|
|
|
name = argv[2];
|
|
|
|
} else if (argc > 1)
|
|
|
|
owner = strtoul(argv[1], NULL, 0);
|
|
|
|
|
|
|
|
kprintf("port id cap r-sem w-sem team name\n");
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-04-22 02:57:39 +04:00
|
|
|
for (i = 0; i < sMaxPorts; i++) {
|
2006-03-24 15:59:23 +03:00
|
|
|
struct port_entry *port = &sPorts[i];
|
|
|
|
if (port->id < 0
|
|
|
|
|| (owner != -1 && port->owner != owner)
|
|
|
|
|| (name != NULL && strstr(port->name, name) == NULL))
|
|
|
|
continue;
|
|
|
|
|
2007-10-11 12:30:18 +04:00
|
|
|
kprintf("%p %6ld %4ld %6ld %6ld %6ld %s\n", port, port->id,
|
|
|
|
port->capacity, port->read_sem, port->write_sem, port->owner,
|
|
|
|
port->name);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2002-07-18 02:07:37 +04:00
|
|
|
return 0;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2002-08-05 09:25:26 +04:00
|
|
|
|
|
|
|
static void
|
|
|
|
_dump_port_info(struct port_entry *port)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2005-01-14 23:45:18 +03:00
|
|
|
int32 count;
|
|
|
|
|
2005-08-02 20:28:20 +04:00
|
|
|
kprintf("PORT: %p\n", port);
|
2008-01-29 02:19:54 +03:00
|
|
|
kprintf(" id: %ld\n", port->id);
|
2005-08-02 20:28:20 +04:00
|
|
|
kprintf(" name: \"%s\"\n", port->name);
|
2008-01-29 02:19:54 +03:00
|
|
|
kprintf(" owner: %ld\n", port->owner);
|
2005-08-02 20:28:20 +04:00
|
|
|
kprintf(" capacity: %ld\n", port->capacity);
|
2008-01-29 02:19:54 +03:00
|
|
|
kprintf(" read_sem: %ld\n", port->read_sem);
|
|
|
|
kprintf(" write_sem: %ld\n", port->write_sem);
|
2005-01-14 23:45:18 +03:00
|
|
|
get_sem_count(port->read_sem, &count);
|
2005-11-04 20:10:50 +03:00
|
|
|
kprintf(" read_sem count: %ld\n", count);
|
2005-01-14 23:45:18 +03:00
|
|
|
get_sem_count(port->write_sem, &count);
|
2005-11-04 20:10:50 +03:00
|
|
|
kprintf(" write_sem count: %ld\n", count);
|
2005-08-02 20:28:20 +04:00
|
|
|
kprintf(" total count: %ld\n", port->total_count);
|
2008-01-18 02:07:59 +03:00
|
|
|
|
|
|
|
set_debug_variable("_port", (addr_t)port);
|
|
|
|
set_debug_variable("_portID", port->id);
|
|
|
|
set_debug_variable("_owner", port->owner);
|
|
|
|
set_debug_variable("_readSem", port->read_sem);
|
|
|
|
set_debug_variable("_writeSem", port->write_sem);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2002-08-05 09:25:26 +04:00
|
|
|
|
|
|
|
static int
|
|
|
|
dump_port_info(int argc, char **argv)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2006-03-24 15:59:23 +03:00
|
|
|
const char *name = NULL;
|
|
|
|
sem_id sem = -1;
|
2002-07-09 16:24:59 +04:00
|
|
|
int i;
|
|
|
|
|
2002-08-05 09:25:26 +04:00
|
|
|
if (argc < 2) {
|
2008-01-17 17:40:07 +03:00
|
|
|
print_debugger_command_usage(argv[0]);
|
2002-07-18 02:07:37 +04:00
|
|
|
return 0;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2006-03-24 15:59:23 +03:00
|
|
|
if (argc > 2) {
|
|
|
|
if (!strcmp(argv[1], "address")) {
|
|
|
|
_dump_port_info((struct port_entry *)strtoul(argv[2], NULL, 0));
|
2002-07-18 02:07:37 +04:00
|
|
|
return 0;
|
2006-03-24 15:59:23 +03:00
|
|
|
} else if (!strcmp(argv[1], "sem"))
|
|
|
|
sem = strtoul(argv[2], NULL, 0);
|
|
|
|
else if (!strcmp(argv[1], "name"))
|
|
|
|
name = argv[2];
|
|
|
|
} else if (isdigit(argv[1][0])) {
|
|
|
|
// if the argument looks like a number, treat it as such
|
|
|
|
uint32 num = strtoul(argv[1], NULL, 0);
|
|
|
|
uint32 slot = num % sMaxPorts;
|
|
|
|
if (sPorts[slot].id != (int)num) {
|
2007-10-11 12:30:18 +04:00
|
|
|
kprintf("port %ld (%#lx) doesn't exist!\n", num, num);
|
2002-07-18 02:07:37 +04:00
|
|
|
return 0;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2006-03-24 15:59:23 +03:00
|
|
|
_dump_port_info(&sPorts[slot]);
|
|
|
|
return 0;
|
|
|
|
} else
|
|
|
|
name = argv[1];
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
// walk through the ports list, trying to match name
|
2004-04-22 02:57:39 +04:00
|
|
|
for (i = 0; i < sMaxPorts; i++) {
|
2007-10-11 12:30:18 +04:00
|
|
|
if ((name != NULL && sPorts[i].name != NULL
|
|
|
|
&& !strcmp(name, sPorts[i].name))
|
|
|
|
|| (sem != -1 && (sPorts[i].read_sem == sem
|
|
|
|
|| sPorts[i].write_sem == sem))) {
|
2004-03-12 08:06:13 +03:00
|
|
|
_dump_port_info(&sPorts[i]);
|
2002-08-05 09:25:26 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2006-03-24 15:59:23 +03:00
|
|
|
|
2002-08-05 09:25:26 +04:00
|
|
|
return 0;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2002-08-05 09:25:26 +04:00
|
|
|
|
2007-10-02 23:47:31 +04:00
|
|
|
static void
|
|
|
|
notify_port_select_events(int slot, uint16 events)
|
|
|
|
{
|
|
|
|
if (sPorts[slot].select_infos)
|
|
|
|
notify_select_events_list(sPorts[slot].select_infos, events);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 12:30:18 +04:00
|
|
|
static void
|
|
|
|
put_port_msg(port_msg *msg)
|
|
|
|
{
|
|
|
|
cbuf_free_chain(msg->buffer_chain);
|
|
|
|
free(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static port_msg *
|
|
|
|
get_port_msg(int32 code, size_t bufferSize)
|
|
|
|
{
|
|
|
|
// ToDo: investigate preallocation of port_msgs (or use a slab allocator)
|
|
|
|
cbuf *bufferChain = NULL;
|
2004-03-05 05:28:37 +03:00
|
|
|
|
2007-10-11 12:30:18 +04:00
|
|
|
port_msg *msg = (port_msg *)malloc(sizeof(port_msg));
|
|
|
|
if (msg == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (bufferSize > 0) {
|
|
|
|
bufferChain = cbuf_get_chain(bufferSize);
|
|
|
|
if (bufferChain == NULL) {
|
|
|
|
free(msg);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
msg->code = code;
|
|
|
|
msg->buffer_chain = bufferChain;
|
|
|
|
msg->size = bufferSize;
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*! You need to own the port's lock when calling this function */
|
|
|
|
static bool
|
|
|
|
is_port_closed(int32 slot)
|
|
|
|
{
|
|
|
|
return sPorts[slot].capacity == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*! Fills the port_info structure with information from the specified
|
|
|
|
port.
|
|
|
|
The port lock must be held when called.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
fill_port_info(struct port_entry *port, port_info *info, size_t size)
|
|
|
|
{
|
|
|
|
int32 count;
|
|
|
|
|
|
|
|
info->port = port->id;
|
|
|
|
info->team = port->owner;
|
|
|
|
info->capacity = port->capacity;
|
|
|
|
|
|
|
|
get_sem_count(port->read_sem, &count);
|
|
|
|
if (count < 0)
|
|
|
|
count = 0;
|
|
|
|
|
|
|
|
info->queue_count = count;
|
|
|
|
info->total_count = port->total_count;
|
|
|
|
|
|
|
|
strlcpy(info->name, port->name, B_OS_NAME_LENGTH);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// #pragma mark - private kernel API
|
|
|
|
|
|
|
|
|
|
|
|
/*! This function cycles through the ports table, deleting all
|
|
|
|
the ports that are owned by the passed team_id
|
|
|
|
*/
|
2004-03-05 05:28:37 +03:00
|
|
|
int
|
|
|
|
delete_owned_ports(team_id owner)
|
|
|
|
{
|
|
|
|
// ToDo: investigate maintaining a list of ports in the team
|
|
|
|
// to make this simpler and more efficient.
|
2004-03-12 08:06:13 +03:00
|
|
|
cpu_status state;
|
2004-03-05 05:28:37 +03:00
|
|
|
int i;
|
|
|
|
int count = 0;
|
|
|
|
|
2004-11-27 15:03:48 +03:00
|
|
|
TRACE(("delete_owned_ports(owner = %ld)\n", owner));
|
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
if (!sPortsActive)
|
2004-03-05 05:28:37 +03:00
|
|
|
return B_BAD_PORT_ID;
|
|
|
|
|
|
|
|
state = disable_interrupts();
|
|
|
|
GRAB_PORT_LIST_LOCK();
|
|
|
|
|
2004-04-22 02:57:39 +04:00
|
|
|
for (i = 0; i < sMaxPorts; i++) {
|
2004-03-12 08:06:13 +03:00
|
|
|
if (sPorts[i].id != -1 && sPorts[i].owner == owner) {
|
|
|
|
port_id id = sPorts[i].id;
|
2004-03-05 05:28:37 +03:00
|
|
|
|
|
|
|
RELEASE_PORT_LIST_LOCK();
|
|
|
|
restore_interrupts(state);
|
|
|
|
|
|
|
|
delete_port(id);
|
|
|
|
count++;
|
|
|
|
|
|
|
|
state = disable_interrupts();
|
|
|
|
GRAB_PORT_LIST_LOCK();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RELEASE_PORT_LIST_LOCK();
|
|
|
|
restore_interrupts(state);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 12:30:18 +04:00
|
|
|
int32
|
|
|
|
port_max_ports(void)
|
2004-03-12 07:57:38 +03:00
|
|
|
{
|
2007-10-11 12:30:18 +04:00
|
|
|
return sMaxPorts;
|
2004-03-12 07:57:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 12:30:18 +04:00
|
|
|
int32
|
|
|
|
port_used_ports(void)
|
2004-03-12 07:57:38 +03:00
|
|
|
{
|
2007-10-11 12:30:18 +04:00
|
|
|
return sUsedPorts;
|
2004-03-12 07:57:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 12:30:18 +04:00
|
|
|
status_t
|
|
|
|
port_init(kernel_args *args)
|
2006-03-08 18:08:48 +03:00
|
|
|
{
|
2007-10-11 12:30:18 +04:00
|
|
|
size_t size = sizeof(struct port_entry) * sMaxPorts;
|
|
|
|
int32 i;
|
2006-03-08 18:08:48 +03:00
|
|
|
|
2007-10-11 12:30:18 +04:00
|
|
|
// create and initialize ports table
|
|
|
|
sPortArea = create_area("port_table", (void **)&sPorts, B_ANY_KERNEL_ADDRESS,
|
|
|
|
size, B_FULL_LOCK, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA);
|
|
|
|
if (sPortArea < 0) {
|
|
|
|
panic("unable to allocate kernel port table!\n");
|
|
|
|
return sPortArea;
|
|
|
|
}
|
2006-03-08 18:08:48 +03:00
|
|
|
|
2007-10-11 12:30:18 +04:00
|
|
|
// ToDo: investigate preallocating a list of port_msgs to
|
|
|
|
// speed up actual message sending/receiving, a slab allocator
|
|
|
|
// might do it as well, though :-)
|
2004-04-22 02:57:39 +04:00
|
|
|
|
2007-10-11 12:30:18 +04:00
|
|
|
memset(sPorts, 0, size);
|
|
|
|
for (i = 0; i < sMaxPorts; i++)
|
|
|
|
sPorts[i].id = -1;
|
2004-04-22 02:57:39 +04:00
|
|
|
|
2007-10-11 12:30:18 +04:00
|
|
|
// add debugger commands
|
2008-01-17 17:40:07 +03:00
|
|
|
add_debugger_command_etc("ports", &dump_port_list,
|
|
|
|
"Dump a list of all active ports (for team, with name, etc.)",
|
|
|
|
"[ ([ \"team\" | \"owner\" ] <team>) | (\"name\" <name>) ]\n"
|
|
|
|
"Prints a list of all active ports meeting the given\n"
|
|
|
|
"requirement. If no argument is given, all ports are listed.\n"
|
|
|
|
" <team> - The team owning the ports.\n"
|
|
|
|
" <name> - Part of the name of the ports.\n", 0);
|
|
|
|
add_debugger_command_etc("port", &dump_port_info,
|
|
|
|
"Dump info about a particular port",
|
|
|
|
"([ \"address\" ] <address>) | ([ \"name\" ] <name>) "
|
|
|
|
"| (\"sem\" <sem>)\n"
|
|
|
|
"Prints info about the specified port.\n"
|
|
|
|
" <address> - Pointer to the port structure.\n"
|
|
|
|
" <name> - Name of the port.\n"
|
|
|
|
" <sem> - ID of the port's read or write semaphore.\n", 0);
|
2007-10-11 12:30:18 +04:00
|
|
|
|
|
|
|
sPortsActive = true;
|
|
|
|
return B_OK;
|
2004-04-22 02:57:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-08 20:09:20 +03:00
|
|
|
// #pragma mark - public kernel API
|
2004-03-05 05:28:37 +03:00
|
|
|
|
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
port_id
|
2004-03-12 07:57:38 +03:00
|
|
|
create_port(int32 queueLength, const char *name)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2004-03-12 07:57:38 +03:00
|
|
|
cpu_status state;
|
|
|
|
char nameBuffer[B_OS_NAME_LENGTH];
|
|
|
|
sem_id readSem, writeSem;
|
2004-11-27 15:03:48 +03:00
|
|
|
status_t status;
|
2002-08-03 04:41:27 +04:00
|
|
|
team_id owner;
|
2004-11-27 15:03:48 +03:00
|
|
|
int32 slot;
|
|
|
|
|
|
|
|
TRACE(("create_port(queueLength = %ld, name = \"%s\")\n", queueLength, name));
|
2004-03-12 07:57:38 +03:00
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
if (!sPortsActive)
|
2002-07-09 16:24:59 +04:00
|
|
|
return B_BAD_PORT_ID;
|
|
|
|
|
2002-09-11 16:25:47 +04:00
|
|
|
// check queue length
|
2004-03-12 07:57:38 +03:00
|
|
|
if (queueLength < 1
|
|
|
|
|| queueLength > MAX_QUEUE_LENGTH)
|
|
|
|
return B_BAD_VALUE;
|
2002-09-11 16:25:47 +04:00
|
|
|
|
2004-05-13 23:35:49 +04:00
|
|
|
// check early on if there are any free port slots to use
|
|
|
|
if (atomic_add(&sUsedPorts, 1) >= sMaxPorts) {
|
2004-11-27 15:03:48 +03:00
|
|
|
status = B_NO_MORE_PORTS;
|
|
|
|
goto err1;
|
2004-05-13 23:35:49 +04:00
|
|
|
}
|
|
|
|
|
2002-09-11 16:25:47 +04:00
|
|
|
// check & dup name
|
|
|
|
if (name == NULL)
|
|
|
|
name = "unnamed port";
|
|
|
|
|
2004-03-12 07:57:38 +03:00
|
|
|
// ToDo: we could save the memory and use the semaphore name only instead
|
|
|
|
strlcpy(nameBuffer, name, B_OS_NAME_LENGTH);
|
|
|
|
name = strdup(nameBuffer);
|
2004-05-13 23:35:49 +04:00
|
|
|
if (name == NULL) {
|
2004-11-27 15:03:48 +03:00
|
|
|
status = B_NO_MEMORY;
|
|
|
|
goto err1;
|
2004-05-13 23:35:49 +04:00
|
|
|
}
|
2002-09-11 16:25:47 +04:00
|
|
|
|
2004-03-12 07:57:38 +03:00
|
|
|
// create read sem with owner set to -1
|
|
|
|
// ToDo: should be B_SYSTEM_TEAM
|
|
|
|
readSem = create_sem_etc(0, name, -1);
|
|
|
|
if (readSem < B_OK) {
|
2004-11-27 15:03:48 +03:00
|
|
|
status = readSem;
|
|
|
|
goto err2;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2004-03-12 07:57:38 +03:00
|
|
|
// create write sem
|
|
|
|
writeSem = create_sem_etc(queueLength, name, -1);
|
2004-11-27 15:03:48 +03:00
|
|
|
if (writeSem < B_OK) {
|
|
|
|
status = writeSem;
|
|
|
|
goto err3;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2004-03-12 07:57:38 +03:00
|
|
|
|
2002-08-03 04:41:27 +04:00
|
|
|
owner = team_get_current_team_id();
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2002-07-25 05:05:51 +04:00
|
|
|
state = disable_interrupts();
|
2002-07-09 16:24:59 +04:00
|
|
|
GRAB_PORT_LIST_LOCK();
|
|
|
|
|
|
|
|
// find the first empty spot
|
2004-11-27 15:03:48 +03:00
|
|
|
for (slot = 0; slot < sMaxPorts; slot++) {
|
|
|
|
int32 i = (slot + sFirstFreeSlot) % sMaxPorts;
|
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
if (sPorts[i].id == -1) {
|
2004-11-27 15:03:48 +03:00
|
|
|
port_id id;
|
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
// make the port_id be a multiple of the slot it's in
|
2004-04-22 02:57:39 +04:00
|
|
|
if (i >= sNextPort % sMaxPorts)
|
|
|
|
sNextPort += i - sNextPort % sMaxPorts;
|
2004-03-04 23:43:13 +03:00
|
|
|
else
|
2004-04-22 02:57:39 +04:00
|
|
|
sNextPort += sMaxPorts - (sNextPort % sMaxPorts - i);
|
2004-11-27 15:03:48 +03:00
|
|
|
sFirstFreeSlot = slot + 1;
|
2004-03-04 23:43:13 +03:00
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
GRAB_PORT_LOCK(sPorts[i]);
|
|
|
|
sPorts[i].id = sNextPort++;
|
2002-07-09 16:24:59 +04:00
|
|
|
RELEASE_PORT_LIST_LOCK();
|
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
sPorts[i].capacity = queueLength;
|
|
|
|
sPorts[i].owner = owner;
|
|
|
|
sPorts[i].name = name;
|
2004-03-12 07:57:38 +03:00
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
sPorts[i].read_sem = readSem;
|
|
|
|
sPorts[i].write_sem = writeSem;
|
2004-03-12 07:57:38 +03:00
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
list_init(&sPorts[i].msg_queue);
|
|
|
|
sPorts[i].total_count = 0;
|
2007-10-02 23:47:31 +04:00
|
|
|
sPorts[i].select_infos = NULL;
|
2004-11-27 15:03:48 +03:00
|
|
|
id = sPorts[i].id;
|
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
RELEASE_PORT_LOCK(sPorts[i]);
|
2004-11-27 15:03:48 +03:00
|
|
|
restore_interrupts(state);
|
|
|
|
|
2005-03-25 21:22:27 +03:00
|
|
|
TRACE(("create_port() done: port created %ld\n", id));
|
|
|
|
|
2004-11-27 15:03:48 +03:00
|
|
|
return id;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
}
|
2004-03-12 07:57:38 +03:00
|
|
|
|
2004-11-27 15:03:48 +03:00
|
|
|
// not enough ports...
|
|
|
|
|
2004-05-13 23:35:49 +04:00
|
|
|
// ToDo: due to sUsedPorts, this cannot happen anymore - as
|
|
|
|
// long as sMaxPorts stays constant over the kernel run
|
|
|
|
// time (which it should be). IOW we could simply panic()
|
|
|
|
// here.
|
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
RELEASE_PORT_LIST_LOCK();
|
2004-11-27 15:03:48 +03:00
|
|
|
restore_interrupts(state);
|
|
|
|
|
|
|
|
status = B_NO_MORE_PORTS;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-03-12 07:57:38 +03:00
|
|
|
delete_sem(writeSem);
|
2004-11-27 15:03:48 +03:00
|
|
|
err3:
|
2004-03-12 07:57:38 +03:00
|
|
|
delete_sem(readSem);
|
2004-11-27 15:03:48 +03:00
|
|
|
err2:
|
2004-03-12 07:57:38 +03:00
|
|
|
free((char *)name);
|
2004-11-27 15:03:48 +03:00
|
|
|
err1:
|
2004-05-13 23:35:49 +04:00
|
|
|
atomic_add(&sUsedPorts, -1);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-11-27 15:03:48 +03:00
|
|
|
return status;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2002-10-05 05:20:39 +04:00
|
|
|
|
2002-09-11 16:25:47 +04:00
|
|
|
status_t
|
2002-07-09 16:24:59 +04:00
|
|
|
close_port(port_id id)
|
|
|
|
{
|
2006-03-08 20:09:20 +03:00
|
|
|
sem_id readSem, writeSem;
|
2004-03-12 08:06:13 +03:00
|
|
|
cpu_status state;
|
2006-03-08 20:09:20 +03:00
|
|
|
int32 slot;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-11-27 15:03:48 +03:00
|
|
|
TRACE(("close_port(id = %ld)\n", id));
|
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
if (!sPortsActive || id < 0)
|
2002-07-09 16:24:59 +04:00
|
|
|
return B_BAD_PORT_ID;
|
2004-03-12 08:06:13 +03:00
|
|
|
|
2004-04-22 02:57:39 +04:00
|
|
|
slot = id % sMaxPorts;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
// walk through the sem list, trying to match name
|
2002-07-25 05:05:51 +04:00
|
|
|
state = disable_interrupts();
|
2004-03-12 08:06:13 +03:00
|
|
|
GRAB_PORT_LOCK(sPorts[slot]);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
if (sPorts[slot].id != id) {
|
|
|
|
RELEASE_PORT_LOCK(sPorts[slot]);
|
2002-07-25 05:05:51 +04:00
|
|
|
restore_interrupts(state);
|
2005-04-12 13:02:32 +04:00
|
|
|
TRACE(("close_port: invalid port_id %ld\n", id));
|
2002-07-09 16:24:59 +04:00
|
|
|
return B_BAD_PORT_ID;
|
|
|
|
}
|
|
|
|
|
2006-03-08 20:09:20 +03:00
|
|
|
// mark port to disable writing - deleting the semaphores will
|
|
|
|
// wake up waiting read/writes
|
2004-03-12 08:28:50 +03:00
|
|
|
sPorts[slot].capacity = 0;
|
2006-03-08 20:09:20 +03:00
|
|
|
readSem = sPorts[slot].read_sem;
|
|
|
|
writeSem = sPorts[slot].write_sem;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2007-10-02 23:47:31 +04:00
|
|
|
notify_port_select_events(slot, B_EVENT_INVALID);
|
|
|
|
sPorts[slot].select_infos = NULL;
|
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
RELEASE_PORT_LOCK(sPorts[slot]);
|
2002-07-25 05:05:51 +04:00
|
|
|
restore_interrupts(state);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2006-03-08 20:09:20 +03:00
|
|
|
delete_sem(readSem);
|
|
|
|
delete_sem(writeSem);
|
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
return B_NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:20:39 +04:00
|
|
|
|
2002-09-03 06:09:48 +04:00
|
|
|
status_t
|
2002-07-09 16:24:59 +04:00
|
|
|
delete_port(port_id id)
|
|
|
|
{
|
2004-03-12 07:57:38 +03:00
|
|
|
cpu_status state;
|
|
|
|
sem_id readSem, writeSem;
|
|
|
|
const char *name;
|
|
|
|
struct list list;
|
|
|
|
port_msg *msg;
|
2006-03-08 20:09:20 +03:00
|
|
|
int32 slot;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-11-27 15:03:48 +03:00
|
|
|
TRACE(("delete_port(id = %ld)\n", id));
|
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
if (!sPortsActive || id < 0)
|
2002-07-09 16:24:59 +04:00
|
|
|
return B_BAD_PORT_ID;
|
|
|
|
|
2004-04-22 02:57:39 +04:00
|
|
|
slot = id % sMaxPorts;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2002-07-25 05:05:51 +04:00
|
|
|
state = disable_interrupts();
|
2004-03-12 08:06:13 +03:00
|
|
|
GRAB_PORT_LOCK(sPorts[slot]);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
if (sPorts[slot].id != id) {
|
|
|
|
RELEASE_PORT_LOCK(sPorts[slot]);
|
2002-07-25 05:05:51 +04:00
|
|
|
restore_interrupts(state);
|
2004-11-27 15:03:48 +03:00
|
|
|
|
|
|
|
TRACE(("delete_port: invalid port_id %ld\n", id));
|
2002-07-09 16:24:59 +04:00
|
|
|
return B_BAD_PORT_ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* mark port as invalid */
|
2004-03-13 00:36:02 +03:00
|
|
|
sPorts[slot].id = -1;
|
2004-03-12 08:06:13 +03:00
|
|
|
name = sPorts[slot].name;
|
|
|
|
readSem = sPorts[slot].read_sem;
|
|
|
|
writeSem = sPorts[slot].write_sem;
|
|
|
|
sPorts[slot].name = NULL;
|
2004-03-13 00:36:02 +03:00
|
|
|
list_move_to_list(&sPorts[slot].msg_queue, &list);
|
2004-03-12 08:06:13 +03:00
|
|
|
|
2007-10-02 23:47:31 +04:00
|
|
|
notify_port_select_events(slot, B_EVENT_INVALID);
|
|
|
|
sPorts[slot].select_infos = NULL;
|
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
RELEASE_PORT_LOCK(sPorts[slot]);
|
2004-11-27 15:03:48 +03:00
|
|
|
|
|
|
|
// update the first free slot hint in the array
|
|
|
|
GRAB_PORT_LIST_LOCK();
|
|
|
|
if (slot < sFirstFreeSlot)
|
|
|
|
sFirstFreeSlot = slot;
|
|
|
|
RELEASE_PORT_LIST_LOCK();
|
|
|
|
|
2002-07-25 05:05:51 +04:00
|
|
|
restore_interrupts(state);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-05-13 23:35:49 +04:00
|
|
|
atomic_add(&sUsedPorts, -1);
|
|
|
|
|
2004-03-12 07:57:38 +03:00
|
|
|
// free the queue
|
|
|
|
while ((msg = (port_msg *)list_remove_head_item(&list)) != NULL) {
|
|
|
|
put_port_msg(msg);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2004-03-12 07:57:38 +03:00
|
|
|
free((char *)name);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
// release the threads that were blocking on this port by deleting the sem
|
2002-07-14 14:10:22 +04:00
|
|
|
// read_port() will see the B_BAD_SEM_ID acq_sem() return value, and act accordingly
|
2004-03-12 07:57:38 +03:00
|
|
|
delete_sem(readSem);
|
|
|
|
delete_sem(writeSem);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-03-12 07:57:38 +03:00
|
|
|
return B_OK;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2002-10-05 05:20:39 +04:00
|
|
|
|
2007-10-02 23:47:31 +04:00
|
|
|
status_t
|
|
|
|
select_port(int32 id, struct select_info *info, bool kernel)
|
|
|
|
{
|
|
|
|
cpu_status state;
|
|
|
|
int32 slot;
|
|
|
|
status_t error = B_OK;
|
|
|
|
|
|
|
|
if (id < 0)
|
|
|
|
return B_BAD_PORT_ID;
|
|
|
|
|
|
|
|
slot = id % sMaxPorts;
|
|
|
|
|
|
|
|
state = disable_interrupts();
|
|
|
|
GRAB_PORT_LOCK(sPorts[slot]);
|
|
|
|
|
|
|
|
if (sPorts[slot].id != id || is_port_closed(slot)) {
|
|
|
|
// bad port ID
|
|
|
|
error = B_BAD_SEM_ID;
|
|
|
|
} else if (!kernel && sPorts[slot].owner == team_get_kernel_team_id()) {
|
|
|
|
// kernel port, but call from userland
|
|
|
|
error = B_NOT_ALLOWED;
|
|
|
|
} else {
|
|
|
|
info->selected_events &= B_EVENT_READ | B_EVENT_WRITE | B_EVENT_INVALID;
|
|
|
|
|
|
|
|
if (info->selected_events != 0) {
|
|
|
|
uint16 events = 0;
|
|
|
|
int32 writeCount = 0;
|
|
|
|
|
|
|
|
info->next = sPorts[slot].select_infos;
|
|
|
|
sPorts[slot].select_infos = info;
|
|
|
|
|
|
|
|
// check for events
|
|
|
|
if ((info->selected_events & B_EVENT_READ) != 0
|
|
|
|
&& !list_is_empty(&sPorts[slot].msg_queue)) {
|
|
|
|
events |= B_EVENT_READ;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (get_sem_count(sPorts[slot].write_sem, &writeCount) == B_OK
|
|
|
|
&& writeCount > 0) {
|
|
|
|
events |= B_EVENT_WRITE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (events != 0)
|
|
|
|
notify_select_events(info, events);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RELEASE_PORT_LOCK(sPorts[slot]);
|
|
|
|
restore_interrupts(state);
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
deselect_port(int32 id, struct select_info *info, bool kernel)
|
|
|
|
{
|
|
|
|
cpu_status state;
|
|
|
|
int32 slot;
|
|
|
|
|
|
|
|
if (id < 0)
|
|
|
|
return B_BAD_PORT_ID;
|
|
|
|
|
|
|
|
if (info->selected_events == 0)
|
|
|
|
return B_OK;
|
|
|
|
|
|
|
|
slot = id % sMaxPorts;
|
|
|
|
|
|
|
|
state = disable_interrupts();
|
|
|
|
GRAB_PORT_LOCK(sPorts[slot]);
|
|
|
|
|
|
|
|
if (sPorts[slot].id == id) {
|
|
|
|
select_info** infoLocation = &sPorts[slot].select_infos;
|
|
|
|
while (*infoLocation != NULL && *infoLocation != info)
|
|
|
|
infoLocation = &(*infoLocation)->next;
|
|
|
|
|
|
|
|
if (*infoLocation == info)
|
|
|
|
*infoLocation = info->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
RELEASE_PORT_LOCK(sPorts[slot]);
|
|
|
|
restore_interrupts(state);
|
|
|
|
|
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
port_id
|
2004-03-04 23:43:13 +03:00
|
|
|
find_port(const char *name)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2004-03-05 04:23:43 +03:00
|
|
|
port_id portFound = B_NAME_NOT_FOUND;
|
2004-03-04 23:43:13 +03:00
|
|
|
cpu_status state;
|
2006-03-08 20:09:20 +03:00
|
|
|
int32 i;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-11-27 15:03:48 +03:00
|
|
|
TRACE(("find_port(name = \"%s\")\n", name));
|
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
if (!sPortsActive)
|
2004-03-05 04:23:43 +03:00
|
|
|
return B_NAME_NOT_FOUND;
|
2004-03-04 23:43:13 +03:00
|
|
|
if (name == NULL)
|
2004-03-05 04:23:43 +03:00
|
|
|
return B_BAD_VALUE;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-03-04 23:43:13 +03:00
|
|
|
// Since we have to check every single port, and we don't
|
|
|
|
// care if it goes away at any point, we're only grabbing
|
|
|
|
// the port lock in question, not the port list lock
|
2002-10-05 05:20:39 +04:00
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
// loop over list
|
2004-04-22 02:57:39 +04:00
|
|
|
for (i = 0; i < sMaxPorts && portFound < B_OK; i++) {
|
2002-07-09 16:24:59 +04:00
|
|
|
// lock every individual port before comparing
|
2004-03-04 23:43:13 +03:00
|
|
|
state = disable_interrupts();
|
2004-03-12 08:06:13 +03:00
|
|
|
GRAB_PORT_LOCK(sPorts[i]);
|
2004-03-04 23:43:13 +03:00
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
if (sPorts[i].id >= 0 && !strcmp(name, sPorts[i].name))
|
|
|
|
portFound = sPorts[i].id;
|
2004-03-04 23:43:13 +03:00
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
RELEASE_PORT_LOCK(sPorts[i]);
|
2004-03-04 23:43:13 +03:00
|
|
|
restore_interrupts(state);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2004-03-04 23:43:13 +03:00
|
|
|
return portFound;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2002-10-05 05:20:39 +04:00
|
|
|
|
2002-09-03 06:09:48 +04:00
|
|
|
status_t
|
2002-07-09 16:24:59 +04:00
|
|
|
_get_port_info(port_id id, port_info *info, size_t size)
|
|
|
|
{
|
2004-03-12 08:06:13 +03:00
|
|
|
cpu_status state;
|
2002-07-09 16:24:59 +04:00
|
|
|
int slot;
|
|
|
|
|
2004-11-27 15:03:48 +03:00
|
|
|
TRACE(("get_port_info(id = %ld)\n", id));
|
|
|
|
|
2004-02-23 07:02:24 +03:00
|
|
|
if (info == NULL || size != sizeof(port_info))
|
|
|
|
return B_BAD_VALUE;
|
2004-03-12 08:06:13 +03:00
|
|
|
if (!sPortsActive || id < 0)
|
2002-07-09 16:24:59 +04:00
|
|
|
return B_BAD_PORT_ID;
|
|
|
|
|
2004-04-22 02:57:39 +04:00
|
|
|
slot = id % sMaxPorts;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2002-07-25 05:05:51 +04:00
|
|
|
state = disable_interrupts();
|
2004-03-12 08:06:13 +03:00
|
|
|
GRAB_PORT_LOCK(sPorts[slot]);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-03-12 08:28:50 +03:00
|
|
|
if (sPorts[slot].id != id || sPorts[slot].capacity == 0) {
|
2004-03-12 08:06:13 +03:00
|
|
|
RELEASE_PORT_LOCK(sPorts[slot]);
|
2002-07-25 05:05:51 +04:00
|
|
|
restore_interrupts(state);
|
2004-03-12 08:28:50 +03:00
|
|
|
TRACE(("get_port_info: invalid port_id %ld\n", id));
|
2002-07-09 16:24:59 +04:00
|
|
|
return B_BAD_PORT_ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
// fill a port_info struct with info
|
2004-03-12 08:06:13 +03:00
|
|
|
fill_port_info(&sPorts[slot], info, size);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
RELEASE_PORT_LOCK(sPorts[slot]);
|
2002-07-25 05:05:51 +04:00
|
|
|
restore_interrupts(state);
|
2004-02-23 07:02:24 +03:00
|
|
|
|
|
|
|
return B_OK;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2002-10-05 05:20:39 +04:00
|
|
|
|
2002-09-03 06:09:48 +04:00
|
|
|
status_t
|
2004-02-23 07:02:24 +03:00
|
|
|
_get_next_port_info(team_id team, int32 *_cookie, struct port_info *info, size_t size)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2004-03-12 08:06:13 +03:00
|
|
|
cpu_status state;
|
2002-07-09 16:24:59 +04:00
|
|
|
int slot;
|
2004-02-23 07:02:24 +03:00
|
|
|
|
2004-11-27 15:03:48 +03:00
|
|
|
TRACE(("get_next_port_info(team = %ld)\n", team));
|
|
|
|
|
2004-02-23 07:02:24 +03:00
|
|
|
if (info == NULL || size != sizeof(port_info) || _cookie == NULL || team < B_OK)
|
2002-10-05 05:20:39 +04:00
|
|
|
return B_BAD_VALUE;
|
2004-03-12 08:06:13 +03:00
|
|
|
if (!sPortsActive)
|
2004-02-23 07:02:24 +03:00
|
|
|
return B_BAD_PORT_ID;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-02-23 07:02:24 +03:00
|
|
|
slot = *_cookie;
|
2004-04-22 02:57:39 +04:00
|
|
|
if (slot >= sMaxPorts)
|
2004-02-23 07:02:24 +03:00
|
|
|
return B_BAD_PORT_ID;
|
|
|
|
|
|
|
|
if (team == B_CURRENT_TEAM)
|
|
|
|
team = team_get_current_team_id();
|
|
|
|
|
|
|
|
info->port = -1; // used as found flag
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
// spinlock
|
2002-07-25 05:05:51 +04:00
|
|
|
state = disable_interrupts();
|
2002-07-09 16:24:59 +04:00
|
|
|
GRAB_PORT_LIST_LOCK();
|
2004-02-23 07:02:24 +03:00
|
|
|
|
2004-04-22 02:57:39 +04:00
|
|
|
while (slot < sMaxPorts) {
|
2004-03-12 08:06:13 +03:00
|
|
|
GRAB_PORT_LOCK(sPorts[slot]);
|
2004-03-12 08:28:50 +03:00
|
|
|
if (sPorts[slot].id != -1 && sPorts[slot].capacity != 0 && sPorts[slot].owner == team) {
|
2004-02-23 07:02:24 +03:00
|
|
|
// found one!
|
2004-03-12 08:06:13 +03:00
|
|
|
fill_port_info(&sPorts[slot], info, size);
|
2004-02-23 07:02:24 +03:00
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
RELEASE_PORT_LOCK(sPorts[slot]);
|
2004-02-23 07:02:24 +03:00
|
|
|
slot++;
|
|
|
|
break;
|
|
|
|
}
|
2004-03-12 08:06:13 +03:00
|
|
|
RELEASE_PORT_LOCK(sPorts[slot]);
|
2002-07-09 16:24:59 +04:00
|
|
|
slot++;
|
|
|
|
}
|
|
|
|
RELEASE_PORT_LIST_LOCK();
|
2002-07-25 05:05:51 +04:00
|
|
|
restore_interrupts(state);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
if (info->port == -1)
|
|
|
|
return B_BAD_PORT_ID;
|
2004-02-23 07:02:24 +03:00
|
|
|
|
|
|
|
*_cookie = slot;
|
2002-07-09 16:24:59 +04:00
|
|
|
return B_NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:20:39 +04:00
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
ssize_t
|
|
|
|
port_buffer_size(port_id id)
|
|
|
|
{
|
|
|
|
return port_buffer_size_etc(id, 0, 0);
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:20:39 +04:00
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
ssize_t
|
2002-10-05 05:20:39 +04:00
|
|
|
port_buffer_size_etc(port_id id, uint32 flags, bigtime_t timeout)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2004-03-05 04:23:43 +03:00
|
|
|
cpu_status state;
|
|
|
|
sem_id cachedSem;
|
|
|
|
status_t status;
|
2004-03-12 07:57:38 +03:00
|
|
|
port_msg *msg;
|
2004-03-05 04:23:43 +03:00
|
|
|
ssize_t size;
|
2006-03-08 20:09:20 +03:00
|
|
|
int32 slot;
|
2004-03-05 04:23:43 +03:00
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
if (!sPortsActive || id < 0)
|
2002-07-09 16:24:59 +04:00
|
|
|
return B_BAD_PORT_ID;
|
|
|
|
|
2004-04-22 02:57:39 +04:00
|
|
|
slot = id % sMaxPorts;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2002-07-25 05:05:51 +04:00
|
|
|
state = disable_interrupts();
|
2004-03-12 08:06:13 +03:00
|
|
|
GRAB_PORT_LOCK(sPorts[slot]);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2006-03-08 18:08:48 +03:00
|
|
|
if (sPorts[slot].id != id
|
|
|
|
|| (is_port_closed(slot) && list_is_empty(&sPorts[slot].msg_queue))) {
|
2004-03-12 08:06:13 +03:00
|
|
|
RELEASE_PORT_LOCK(sPorts[slot]);
|
2002-07-25 05:05:51 +04:00
|
|
|
restore_interrupts(state);
|
2006-03-08 18:08:48 +03:00
|
|
|
TRACE(("port_buffer_size_etc(): %s port %ld\n",
|
|
|
|
sPorts[slot].id == id ? "closed" : "invalid", id));
|
2002-07-09 16:24:59 +04:00
|
|
|
return B_BAD_PORT_ID;
|
|
|
|
}
|
2006-03-08 18:08:48 +03:00
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
cachedSem = sPorts[slot].read_sem;
|
2004-03-05 04:23:43 +03:00
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
RELEASE_PORT_LOCK(sPorts[slot]);
|
2002-07-25 05:05:51 +04:00
|
|
|
restore_interrupts(state);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-03-12 07:57:38 +03:00
|
|
|
// block if no message, or, if B_TIMEOUT flag set, block with timeout
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-03-05 04:23:43 +03:00
|
|
|
status = acquire_sem_etc(cachedSem, 1, flags, timeout);
|
2006-03-08 20:09:20 +03:00
|
|
|
if (status != B_OK && status != B_BAD_SEM_ID)
|
2004-03-05 04:23:43 +03:00
|
|
|
return status;
|
|
|
|
|
2006-03-08 20:09:20 +03:00
|
|
|
// in case of B_BAD_SEM_ID, the port might have been closed but not yet
|
|
|
|
// deleted, ie. there could still be messages waiting for us
|
|
|
|
|
2004-03-05 04:23:43 +03:00
|
|
|
state = disable_interrupts();
|
2004-03-12 08:06:13 +03:00
|
|
|
GRAB_PORT_LOCK(sPorts[slot]);
|
2004-03-05 04:23:43 +03:00
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
if (sPorts[slot].id != id) {
|
2004-03-05 04:23:43 +03:00
|
|
|
// the port is no longer there
|
2004-03-12 08:06:13 +03:00
|
|
|
RELEASE_PORT_LOCK(sPorts[slot]);
|
2004-03-05 04:23:43 +03:00
|
|
|
restore_interrupts(state);
|
|
|
|
return B_BAD_PORT_ID;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2004-03-05 04:23:43 +03:00
|
|
|
// determine tail & get the length of the message
|
2008-01-17 17:04:06 +03:00
|
|
|
msg = (port_msg*)list_get_first_item(&sPorts[slot].msg_queue);
|
2006-03-08 20:09:20 +03:00
|
|
|
if (msg == NULL) {
|
|
|
|
if (status == B_OK)
|
|
|
|
panic("port %ld: no messages found\n", sPorts[slot].id);
|
2004-03-12 07:57:38 +03:00
|
|
|
|
2006-03-08 20:09:20 +03:00
|
|
|
size = B_BAD_PORT_ID;
|
|
|
|
} else
|
|
|
|
size = msg->size;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
RELEASE_PORT_LOCK(sPorts[slot]);
|
2004-03-05 04:23:43 +03:00
|
|
|
restore_interrupts(state);
|
|
|
|
|
|
|
|
// restore read_sem, as we haven't read from the port
|
|
|
|
release_sem(cachedSem);
|
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
// return length of item at end of queue
|
2004-03-05 04:23:43 +03:00
|
|
|
return size;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2002-10-05 05:20:39 +04:00
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
ssize_t
|
|
|
|
port_count(port_id id)
|
|
|
|
{
|
2004-03-12 08:06:13 +03:00
|
|
|
cpu_status state;
|
2006-03-08 20:09:20 +03:00
|
|
|
int32 count = 0;
|
|
|
|
int32 slot;
|
2002-10-05 05:20:39 +04:00
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
if (!sPortsActive || id < 0)
|
2002-07-09 16:24:59 +04:00
|
|
|
return B_BAD_PORT_ID;
|
|
|
|
|
2004-04-22 02:57:39 +04:00
|
|
|
slot = id % sMaxPorts;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2002-07-25 05:05:51 +04:00
|
|
|
state = disable_interrupts();
|
2004-03-12 08:06:13 +03:00
|
|
|
GRAB_PORT_LOCK(sPorts[slot]);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
if (sPorts[slot].id != id) {
|
|
|
|
RELEASE_PORT_LOCK(sPorts[slot]);
|
2002-07-25 05:05:51 +04:00
|
|
|
restore_interrupts(state);
|
2004-03-05 04:23:43 +03:00
|
|
|
TRACE(("port_count: invalid port_id %ld\n", id));
|
2002-07-09 16:24:59 +04:00
|
|
|
return B_BAD_PORT_ID;
|
|
|
|
}
|
2004-03-05 04:23:43 +03:00
|
|
|
|
2006-03-08 20:09:20 +03:00
|
|
|
if (get_sem_count(sPorts[slot].read_sem, &count) == B_OK) {
|
|
|
|
// do not return negative numbers
|
|
|
|
if (count < 0)
|
|
|
|
count = 0;
|
|
|
|
} else {
|
|
|
|
// the port might have been closed - we need to actually count the messages
|
|
|
|
void *message = NULL;
|
|
|
|
while ((message = list_get_next_item(&sPorts[slot].msg_queue, message)) != NULL) {
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
RELEASE_PORT_LOCK(sPorts[slot]);
|
2002-07-25 05:05:51 +04:00
|
|
|
restore_interrupts(state);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2006-03-08 20:09:20 +03:00
|
|
|
// return count of messages
|
2002-07-09 16:24:59 +04:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:20:39 +04:00
|
|
|
|
2005-01-16 00:43:07 +03:00
|
|
|
ssize_t
|
2003-06-28 20:46:07 +04:00
|
|
|
read_port(port_id port, int32 *msgCode, void *msgBuffer, size_t bufferSize)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-28 20:46:07 +04:00
|
|
|
return read_port_etc(port, msgCode, msgBuffer, bufferSize, 0, 0);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2002-10-05 05:20:39 +04:00
|
|
|
|
2005-01-16 00:43:07 +03:00
|
|
|
ssize_t
|
2004-03-12 07:57:38 +03:00
|
|
|
read_port_etc(port_id id, int32 *_msgCode, void *msgBuffer, size_t bufferSize,
|
2002-10-05 05:20:39 +04:00
|
|
|
uint32 flags, bigtime_t timeout)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2004-03-05 04:23:43 +03:00
|
|
|
cpu_status state;
|
|
|
|
sem_id cachedSem;
|
2003-06-28 20:46:07 +04:00
|
|
|
status_t status;
|
|
|
|
bool userCopy = (flags & PORT_FLAG_USE_USER_MEMCPY) > 0;
|
2004-03-12 07:57:38 +03:00
|
|
|
port_msg *msg;
|
|
|
|
size_t size;
|
2004-03-05 04:23:43 +03:00
|
|
|
int slot;
|
2002-10-05 05:20:39 +04:00
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
if (!sPortsActive || id < 0)
|
2002-07-09 16:24:59 +04:00
|
|
|
return B_BAD_PORT_ID;
|
|
|
|
|
2007-07-27 05:34:14 +04:00
|
|
|
if ((msgBuffer == NULL && bufferSize > 0)
|
2003-06-28 20:46:07 +04:00
|
|
|
|| timeout < 0)
|
|
|
|
return B_BAD_VALUE;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2005-02-27 19:18:07 +03:00
|
|
|
flags = flags & (B_CAN_INTERRUPT | B_KILL_CAN_INTERRUPT
|
|
|
|
| B_RELATIVE_TIMEOUT | B_ABSOLUTE_TIMEOUT);
|
2004-04-22 02:57:39 +04:00
|
|
|
slot = id % sMaxPorts;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2002-07-25 05:05:51 +04:00
|
|
|
state = disable_interrupts();
|
2004-03-12 08:06:13 +03:00
|
|
|
GRAB_PORT_LOCK(sPorts[slot]);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2006-03-08 18:08:48 +03:00
|
|
|
if (sPorts[slot].id != id
|
|
|
|
|| (is_port_closed(slot) && list_is_empty(&sPorts[slot].msg_queue))) {
|
2004-03-12 08:06:13 +03:00
|
|
|
RELEASE_PORT_LOCK(sPorts[slot]);
|
2002-07-25 05:05:51 +04:00
|
|
|
restore_interrupts(state);
|
2006-03-08 18:08:48 +03:00
|
|
|
TRACE(("read_port_etc(): %s port %ld\n",
|
|
|
|
sPorts[slot].id == id ? "closed" : "invalid", id));
|
2002-07-09 16:24:59 +04:00
|
|
|
return B_BAD_PORT_ID;
|
|
|
|
}
|
|
|
|
// store sem_id in local variable
|
2004-03-12 08:06:13 +03:00
|
|
|
cachedSem = sPorts[slot].read_sem;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
// unlock port && enable ints/
|
2004-03-12 08:06:13 +03:00
|
|
|
RELEASE_PORT_LOCK(sPorts[slot]);
|
2002-07-25 05:05:51 +04:00
|
|
|
restore_interrupts(state);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-03-05 04:23:43 +03:00
|
|
|
status = acquire_sem_etc(cachedSem, 1, flags, timeout);
|
2003-06-28 20:46:07 +04:00
|
|
|
// get 1 entry from the queue, block if needed
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2006-03-08 20:09:20 +03:00
|
|
|
if (status != B_OK && status != B_BAD_SEM_ID)
|
2004-03-05 04:23:43 +03:00
|
|
|
return status;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2006-03-08 20:09:20 +03:00
|
|
|
// in case of B_BAD_SEM_ID, the port might have been closed but not yet
|
|
|
|
// deleted, ie. there could still be messages waiting for us
|
|
|
|
|
2002-07-25 05:05:51 +04:00
|
|
|
state = disable_interrupts();
|
2004-03-12 08:06:13 +03:00
|
|
|
GRAB_PORT_LOCK(sPorts[slot]);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-03-12 07:57:38 +03:00
|
|
|
// first, let's check if the port is still alive
|
2004-03-12 08:06:13 +03:00
|
|
|
if (sPorts[slot].id == -1) {
|
2004-03-12 07:57:38 +03:00
|
|
|
// the port has been deleted in the meantime
|
2004-03-12 08:06:13 +03:00
|
|
|
RELEASE_PORT_LOCK(sPorts[slot]);
|
2004-03-12 07:57:38 +03:00
|
|
|
restore_interrupts(state);
|
|
|
|
return B_BAD_PORT_ID;
|
|
|
|
}
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2008-01-17 17:04:06 +03:00
|
|
|
msg = (port_msg*)list_get_first_item(&sPorts[slot].msg_queue);
|
2006-03-08 20:09:20 +03:00
|
|
|
if (msg == NULL) {
|
|
|
|
if (status == B_OK)
|
|
|
|
panic("port %ld: no messages found", sPorts[slot].id);
|
|
|
|
|
|
|
|
// the port has obviously been closed, but no messages are left anymore
|
|
|
|
RELEASE_PORT_LOCK(sPorts[slot]);
|
|
|
|
restore_interrupts(state);
|
|
|
|
return B_BAD_PORT_ID;
|
|
|
|
}
|
2003-06-28 20:46:07 +04:00
|
|
|
|
2004-03-12 07:57:38 +03:00
|
|
|
list_remove_link(msg);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
sPorts[slot].total_count++;
|
2003-06-28 20:46:07 +04:00
|
|
|
|
2007-10-02 23:47:31 +04:00
|
|
|
notify_port_select_events(slot, B_EVENT_WRITE);
|
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
cachedSem = sPorts[slot].write_sem;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
RELEASE_PORT_LOCK(sPorts[slot]);
|
2002-07-25 05:05:51 +04:00
|
|
|
restore_interrupts(state);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-03-12 07:57:38 +03:00
|
|
|
// check output buffer size
|
2008-01-17 17:04:06 +03:00
|
|
|
size = min_c(bufferSize, msg->size);
|
2004-03-12 07:57:38 +03:00
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
// copy message
|
2007-07-27 05:34:14 +04:00
|
|
|
if (_msgCode != NULL)
|
|
|
|
*_msgCode = msg->code;
|
2003-06-28 20:46:07 +04:00
|
|
|
if (size > 0) {
|
|
|
|
if (userCopy) {
|
2004-03-12 07:57:38 +03:00
|
|
|
if ((status = cbuf_user_memcpy_from_chain(msgBuffer, msg->buffer_chain, 0, size) < B_OK)) {
|
2002-07-09 16:24:59 +04:00
|
|
|
// leave the port intact, for other threads that might not crash
|
2004-03-12 07:57:38 +03:00
|
|
|
put_port_msg(msg);
|
2004-03-05 04:23:43 +03:00
|
|
|
release_sem(cachedSem);
|
2003-06-28 20:46:07 +04:00
|
|
|
return status;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
} else
|
2004-03-12 07:57:38 +03:00
|
|
|
cbuf_memcpy_from_chain(msgBuffer, msg->buffer_chain, 0, size);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2004-03-12 07:57:38 +03:00
|
|
|
put_port_msg(msg);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
// make one spot in queue available again for write
|
2004-03-05 04:23:43 +03:00
|
|
|
release_sem(cachedSem);
|
2004-03-12 07:57:38 +03:00
|
|
|
// ToDo: we might think about setting B_NO_RESCHEDULE here
|
|
|
|
// from time to time (always?)
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-28 20:46:07 +04:00
|
|
|
return size;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2002-10-05 05:20:39 +04:00
|
|
|
|
2002-09-03 06:09:48 +04:00
|
|
|
status_t
|
2003-06-28 20:46:07 +04:00
|
|
|
write_port(port_id id, int32 msgCode, const void *msgBuffer, size_t bufferSize)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2005-07-14 03:55:15 +04:00
|
|
|
iovec vec = { (void *)msgBuffer, bufferSize };
|
|
|
|
|
|
|
|
return writev_port_etc(id, msgCode, &vec, 1, bufferSize, 0, 0);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2002-10-05 05:20:39 +04:00
|
|
|
|
2002-09-03 06:09:48 +04:00
|
|
|
status_t
|
2003-06-28 20:46:07 +04:00
|
|
|
write_port_etc(port_id id, int32 msgCode, const void *msgBuffer,
|
|
|
|
size_t bufferSize, uint32 flags, bigtime_t timeout)
|
2005-07-14 03:55:15 +04:00
|
|
|
{
|
|
|
|
iovec vec = { (void *)msgBuffer, bufferSize };
|
|
|
|
|
|
|
|
return writev_port_etc(id, msgCode, &vec, 1, bufferSize, flags, timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
writev_port_etc(port_id id, int32 msgCode, const iovec *msgVecs,
|
|
|
|
size_t vecCount, size_t bufferSize, uint32 flags,
|
|
|
|
bigtime_t timeout)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2004-03-05 04:23:43 +03:00
|
|
|
cpu_status state;
|
|
|
|
sem_id cachedSem;
|
2004-03-12 07:57:38 +03:00
|
|
|
status_t status;
|
|
|
|
port_msg *msg;
|
2003-06-28 20:46:07 +04:00
|
|
|
bool userCopy = (flags & PORT_FLAG_USE_USER_MEMCPY) > 0;
|
2004-03-12 07:57:38 +03:00
|
|
|
int slot;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
if (!sPortsActive || id < 0)
|
2003-06-28 20:46:07 +04:00
|
|
|
return B_BAD_PORT_ID;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-28 20:46:07 +04:00
|
|
|
// mask irrelevant flags (for acquire_sem() usage)
|
2005-02-27 19:18:07 +03:00
|
|
|
flags = flags & (B_CAN_INTERRUPT | B_KILL_CAN_INTERRUPT
|
|
|
|
| B_RELATIVE_TIMEOUT | B_ABSOLUTE_TIMEOUT);
|
2004-04-22 02:57:39 +04:00
|
|
|
slot = id % sMaxPorts;
|
2003-06-28 20:46:07 +04:00
|
|
|
|
|
|
|
if (bufferSize > PORT_MAX_MESSAGE_SIZE)
|
2005-07-14 03:55:15 +04:00
|
|
|
return B_BAD_VALUE;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2002-07-25 05:05:51 +04:00
|
|
|
state = disable_interrupts();
|
2004-03-12 08:06:13 +03:00
|
|
|
GRAB_PORT_LOCK(sPorts[slot]);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
if (sPorts[slot].id != id) {
|
|
|
|
RELEASE_PORT_LOCK(sPorts[slot]);
|
2002-07-25 05:05:51 +04:00
|
|
|
restore_interrupts(state);
|
2004-03-05 04:23:43 +03:00
|
|
|
TRACE(("write_port_etc: invalid port_id %ld\n", id));
|
2002-07-09 16:24:59 +04:00
|
|
|
return B_BAD_PORT_ID;
|
|
|
|
}
|
|
|
|
|
2006-03-08 18:08:48 +03:00
|
|
|
if (is_port_closed(slot)) {
|
2004-03-12 08:06:13 +03:00
|
|
|
RELEASE_PORT_LOCK(sPorts[slot]);
|
2002-07-25 05:05:51 +04:00
|
|
|
restore_interrupts(state);
|
2004-03-05 04:23:43 +03:00
|
|
|
TRACE(("write_port_etc: port %ld closed\n", id));
|
2002-07-09 16:24:59 +04:00
|
|
|
return B_BAD_PORT_ID;
|
|
|
|
}
|
2004-03-05 04:23:43 +03:00
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
// store sem_id in local variable
|
2004-03-12 08:06:13 +03:00
|
|
|
cachedSem = sPorts[slot].write_sem;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
RELEASE_PORT_LOCK(sPorts[slot]);
|
2002-07-25 05:05:51 +04:00
|
|
|
restore_interrupts(state);
|
2004-03-05 04:23:43 +03:00
|
|
|
|
|
|
|
status = acquire_sem_etc(cachedSem, 1, flags, timeout);
|
2003-06-28 20:46:07 +04:00
|
|
|
// get 1 entry from the queue, block if needed
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2005-02-10 04:08:55 +03:00
|
|
|
if (status == B_BAD_SEM_ID) {
|
2006-03-08 20:09:20 +03:00
|
|
|
// somebody deleted or closed the port
|
2002-07-09 16:24:59 +04:00
|
|
|
return B_BAD_PORT_ID;
|
|
|
|
}
|
2005-01-14 23:21:58 +03:00
|
|
|
if (status != B_OK)
|
2004-03-05 04:23:43 +03:00
|
|
|
return status;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-03-12 07:57:38 +03:00
|
|
|
msg = get_port_msg(msgCode, bufferSize);
|
|
|
|
if (msg == NULL)
|
|
|
|
return B_NO_MEMORY;
|
2003-06-28 20:46:07 +04:00
|
|
|
|
2004-03-12 07:57:38 +03:00
|
|
|
if (bufferSize > 0) {
|
2005-07-14 03:55:15 +04:00
|
|
|
uint32 i;
|
2003-06-28 20:46:07 +04:00
|
|
|
if (userCopy) {
|
2002-07-09 16:24:59 +04:00
|
|
|
// copy from user memory
|
2005-07-14 03:55:15 +04:00
|
|
|
for (i = 0; i < vecCount; i++) {
|
|
|
|
size_t bytes = msgVecs[i].iov_len;
|
|
|
|
if (bytes > bufferSize)
|
|
|
|
bytes = bufferSize;
|
|
|
|
|
|
|
|
if ((status = cbuf_user_memcpy_to_chain(msg->buffer_chain,
|
|
|
|
0, msgVecs[i].iov_base, bytes)) < B_OK)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
bufferSize -= bytes;
|
|
|
|
if (bufferSize == 0)
|
|
|
|
break;
|
|
|
|
}
|
2003-06-28 20:46:07 +04:00
|
|
|
} else {
|
2002-07-09 16:24:59 +04:00
|
|
|
// copy from kernel memory
|
2005-07-14 03:55:15 +04:00
|
|
|
for (i = 0; i < vecCount; i++) {
|
|
|
|
size_t bytes = msgVecs[i].iov_len;
|
|
|
|
if (bytes > bufferSize)
|
|
|
|
bytes = bufferSize;
|
|
|
|
|
|
|
|
if ((status = cbuf_memcpy_to_chain(msg->buffer_chain,
|
|
|
|
0, msgVecs[i].iov_base, bytes)) < 0)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
bufferSize -= bytes;
|
|
|
|
if (bufferSize == 0)
|
|
|
|
break;
|
|
|
|
}
|
2003-06-28 20:46:07 +04:00
|
|
|
}
|
2004-03-12 07:57:38 +03:00
|
|
|
}
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-03-12 07:57:38 +03:00
|
|
|
// attach message to queue
|
2002-07-25 05:05:51 +04:00
|
|
|
state = disable_interrupts();
|
2004-03-12 08:06:13 +03:00
|
|
|
GRAB_PORT_LOCK(sPorts[slot]);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-03-12 07:57:38 +03:00
|
|
|
// first, let's check if the port is still alive
|
2004-03-12 08:06:13 +03:00
|
|
|
if (sPorts[slot].id == -1) {
|
2004-03-12 07:57:38 +03:00
|
|
|
// the port has been deleted in the meantime
|
2004-03-12 08:06:13 +03:00
|
|
|
RELEASE_PORT_LOCK(sPorts[slot]);
|
2004-03-12 07:57:38 +03:00
|
|
|
restore_interrupts(state);
|
2003-06-28 20:46:07 +04:00
|
|
|
|
2004-03-12 07:57:38 +03:00
|
|
|
put_port_msg(msg);
|
|
|
|
return B_BAD_PORT_ID;
|
|
|
|
}
|
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
list_add_item(&sPorts[slot].msg_queue, msg);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2007-10-02 23:47:31 +04:00
|
|
|
notify_port_select_events(slot, B_EVENT_READ);
|
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
// store sem_id in local variable
|
2004-03-12 08:06:13 +03:00
|
|
|
cachedSem = sPorts[slot].read_sem;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
RELEASE_PORT_LOCK(sPorts[slot]);
|
2002-07-25 05:05:51 +04:00
|
|
|
restore_interrupts(state);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
// release sem, allowing read (might reschedule)
|
2004-03-05 04:23:43 +03:00
|
|
|
release_sem(cachedSem);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
return B_NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:20:39 +04:00
|
|
|
|
2003-06-28 20:53:36 +04:00
|
|
|
status_t
|
|
|
|
set_port_owner(port_id id, team_id team)
|
|
|
|
{
|
2004-03-12 08:06:13 +03:00
|
|
|
cpu_status state;
|
2003-06-28 20:53:36 +04:00
|
|
|
int slot;
|
2005-03-25 21:22:27 +03:00
|
|
|
// ToDo: Shouldn't we at least check, whether the team exists?
|
2003-06-28 20:53:36 +04:00
|
|
|
|
2004-11-27 15:03:48 +03:00
|
|
|
TRACE(("set_port_owner(id = %ld, team = %ld)\n", id, team));
|
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
if (!sPortsActive || id < 0)
|
2003-06-28 20:53:36 +04:00
|
|
|
return B_BAD_PORT_ID;
|
|
|
|
|
2004-04-22 02:57:39 +04:00
|
|
|
slot = id % sMaxPorts;
|
2003-06-28 20:53:36 +04:00
|
|
|
|
|
|
|
state = disable_interrupts();
|
2004-03-12 08:06:13 +03:00
|
|
|
GRAB_PORT_LOCK(sPorts[slot]);
|
2003-06-28 20:53:36 +04:00
|
|
|
|
2004-03-12 08:06:13 +03:00
|
|
|
if (sPorts[slot].id != id) {
|
|
|
|
RELEASE_PORT_LOCK(sPorts[slot]);
|
2003-06-28 20:53:36 +04:00
|
|
|
restore_interrupts(state);
|
2004-03-12 07:57:38 +03:00
|
|
|
TRACE(("set_port_owner: invalid port_id %ld\n", id));
|
2003-06-28 20:53:36 +04:00
|
|
|
return B_BAD_PORT_ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
// transfer ownership to other team
|
2004-03-12 08:06:13 +03:00
|
|
|
sPorts[slot].owner = team;
|
2003-06-28 20:53:36 +04:00
|
|
|
|
|
|
|
// unlock port
|
2004-03-12 08:06:13 +03:00
|
|
|
RELEASE_PORT_LOCK(sPorts[slot]);
|
2003-06-28 20:53:36 +04:00
|
|
|
restore_interrupts(state);
|
|
|
|
|
|
|
|
return B_NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-08 20:09:20 +03:00
|
|
|
// #pragma mark - syscalls
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-01-27 06:02:24 +03:00
|
|
|
|
2002-10-05 05:20:39 +04:00
|
|
|
port_id
|
2004-08-29 00:51:47 +04:00
|
|
|
_user_create_port(int32 queueLength, const char *userName)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2004-02-23 07:02:24 +03:00
|
|
|
char name[B_OS_NAME_LENGTH];
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-02-23 07:02:24 +03:00
|
|
|
if (userName == NULL)
|
|
|
|
return create_port(queueLength, NULL);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-02-23 07:02:24 +03:00
|
|
|
if (!IS_USER_ADDRESS(userName)
|
|
|
|
|| user_strlcpy(name, userName, B_OS_NAME_LENGTH) < B_OK)
|
|
|
|
return B_BAD_ADDRESS;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-02-23 07:02:24 +03:00
|
|
|
return create_port(queueLength, name);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2002-10-05 05:20:39 +04:00
|
|
|
|
|
|
|
status_t
|
2004-08-29 00:51:47 +04:00
|
|
|
_user_close_port(port_id id)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
|
|
|
return close_port(id);
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:20:39 +04:00
|
|
|
|
|
|
|
status_t
|
2004-08-29 00:51:47 +04:00
|
|
|
_user_delete_port(port_id id)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
|
|
|
return delete_port(id);
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:20:39 +04:00
|
|
|
|
|
|
|
port_id
|
2004-08-29 00:51:47 +04:00
|
|
|
_user_find_port(const char *userName)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2004-02-23 07:02:24 +03:00
|
|
|
char name[B_OS_NAME_LENGTH];
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-02-23 07:02:24 +03:00
|
|
|
if (userName == NULL)
|
|
|
|
return B_BAD_VALUE;
|
|
|
|
if (!IS_USER_ADDRESS(userName)
|
|
|
|
|| user_strlcpy(name, userName, B_OS_NAME_LENGTH) < B_OK)
|
|
|
|
return B_BAD_ADDRESS;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-02-23 07:02:24 +03:00
|
|
|
return find_port(name);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2002-10-05 05:20:39 +04:00
|
|
|
|
|
|
|
status_t
|
2004-08-29 00:51:47 +04:00
|
|
|
_user_get_port_info(port_id id, struct port_info *userInfo)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2004-02-23 07:02:24 +03:00
|
|
|
struct port_info info;
|
|
|
|
status_t status;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-02-23 07:02:24 +03:00
|
|
|
if (userInfo == NULL)
|
|
|
|
return B_BAD_VALUE;
|
|
|
|
if (!IS_USER_ADDRESS(userInfo))
|
|
|
|
return B_BAD_ADDRESS;
|
|
|
|
|
|
|
|
status = get_port_info(id, &info);
|
|
|
|
|
|
|
|
// copy back to user space
|
axeld + bonefish:
* Implemented automatic syscall restarts:
- A syscall can indicate that it has been interrupted and can be
restarted by setting a respective bit in thread::flags. It can
store parameters it wants to be preserved for the restart in
thread::syscall_restart::parameters. Another thread::flags bit
indicates whether it has been restarted.
- handle_signals() clears the restart flag, if the handled signal
has a handler function installed and SA_RESTART is not set. Another
thread flag (THREAD_FLAGS_DONT_RESTART_SYSCALL) can prevent syscalls
from being restarted, even if they could be (not used yet, but we
might want to use it in resume_thread(), so that we stay
behaviorally compatible with BeOS).
- The architecture specific syscall handler restarts the syscall, if
the restart flag is set. Implemented for x86 only.
- Added some support functions in the private <syscall_restart.h> to
simplify the syscall restart code in the syscalls.
- Adjusted all syscalls that can potentially be restarted accordingly.
- _user_ioctl() sets new thread flag THREAD_FLAGS_IOCTL_SYSCALL while
calling the underlying FS's/driver's hook, so that syscall restarts
can also be supported there.
* thread_at_kernel_exit() invokes handle_signals() in a loop now, as
long as the latter indicates that the thread shall be suspended, so
that after waking up signals received in the meantime will be handled
before the thread returns to userland. Adjusted handle_signals()
accordingly -- when encountering a suspending signal we don't check
for further signals.
* Fixed sigsuspend(): Suspending the thread and rescheduling doesn't
result in the correct behavior. Instead we employ a temporary
condition variable and interruptably wait on it. The POSIX test
suite test passes, now.
* Made the switch_sem[_etc]() behavior on interruption consistent.
Depending on when the signal arrived (before the call or when already
waiting) the first semaphore would or wouldn't be released. Now we
consistently release it.
* Refactored _user_{read,write}[v]() syscalls. Use a common function for
either pair. The iovec version doesn't fail anymore, if anything could
be read/written at all. It also checks whether a complete vector
could be read/written, so that we won't skip data, if the underlying
FS/driver couldn't read/write more ATM.
* Some refactoring in the x86 syscall handler: The int 99 and sysenter
handlers use a common subroutine to avoid code duplication.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23983 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-02-17 18:48:30 +03:00
|
|
|
if (status == B_OK
|
|
|
|
&& user_memcpy(userInfo, &info, sizeof(struct port_info)) < B_OK)
|
2004-02-23 07:02:24 +03:00
|
|
|
return B_BAD_ADDRESS;
|
|
|
|
|
|
|
|
return status;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2002-10-05 05:20:39 +04:00
|
|
|
|
|
|
|
status_t
|
axeld + bonefish:
* Implemented automatic syscall restarts:
- A syscall can indicate that it has been interrupted and can be
restarted by setting a respective bit in thread::flags. It can
store parameters it wants to be preserved for the restart in
thread::syscall_restart::parameters. Another thread::flags bit
indicates whether it has been restarted.
- handle_signals() clears the restart flag, if the handled signal
has a handler function installed and SA_RESTART is not set. Another
thread flag (THREAD_FLAGS_DONT_RESTART_SYSCALL) can prevent syscalls
from being restarted, even if they could be (not used yet, but we
might want to use it in resume_thread(), so that we stay
behaviorally compatible with BeOS).
- The architecture specific syscall handler restarts the syscall, if
the restart flag is set. Implemented for x86 only.
- Added some support functions in the private <syscall_restart.h> to
simplify the syscall restart code in the syscalls.
- Adjusted all syscalls that can potentially be restarted accordingly.
- _user_ioctl() sets new thread flag THREAD_FLAGS_IOCTL_SYSCALL while
calling the underlying FS's/driver's hook, so that syscall restarts
can also be supported there.
* thread_at_kernel_exit() invokes handle_signals() in a loop now, as
long as the latter indicates that the thread shall be suspended, so
that after waking up signals received in the meantime will be handled
before the thread returns to userland. Adjusted handle_signals()
accordingly -- when encountering a suspending signal we don't check
for further signals.
* Fixed sigsuspend(): Suspending the thread and rescheduling doesn't
result in the correct behavior. Instead we employ a temporary
condition variable and interruptably wait on it. The POSIX test
suite test passes, now.
* Made the switch_sem[_etc]() behavior on interruption consistent.
Depending on when the signal arrived (before the call or when already
waiting) the first semaphore would or wouldn't be released. Now we
consistently release it.
* Refactored _user_{read,write}[v]() syscalls. Use a common function for
either pair. The iovec version doesn't fail anymore, if anything could
be read/written at all. It also checks whether a complete vector
could be read/written, so that we won't skip data, if the underlying
FS/driver couldn't read/write more ATM.
* Some refactoring in the x86 syscall handler: The int 99 and sysenter
handlers use a common subroutine to avoid code duplication.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23983 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-02-17 18:48:30 +03:00
|
|
|
_user_get_next_port_info(team_id team, int32 *userCookie,
|
|
|
|
struct port_info *userInfo)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2004-02-23 07:02:24 +03:00
|
|
|
struct port_info info;
|
|
|
|
status_t status;
|
|
|
|
int32 cookie;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-02-23 07:02:24 +03:00
|
|
|
if (userCookie == NULL || userInfo == NULL)
|
|
|
|
return B_BAD_VALUE;
|
|
|
|
if (!IS_USER_ADDRESS(userCookie) || !IS_USER_ADDRESS(userInfo)
|
|
|
|
|| user_memcpy(&cookie, userCookie, sizeof(int32)) < B_OK)
|
|
|
|
return B_BAD_ADDRESS;
|
|
|
|
|
|
|
|
status = get_next_port_info(team, &cookie, &info);
|
|
|
|
|
|
|
|
// copy back to user space
|
|
|
|
if (user_memcpy(userCookie, &cookie, sizeof(int32)) < B_OK
|
axeld + bonefish:
* Implemented automatic syscall restarts:
- A syscall can indicate that it has been interrupted and can be
restarted by setting a respective bit in thread::flags. It can
store parameters it wants to be preserved for the restart in
thread::syscall_restart::parameters. Another thread::flags bit
indicates whether it has been restarted.
- handle_signals() clears the restart flag, if the handled signal
has a handler function installed and SA_RESTART is not set. Another
thread flag (THREAD_FLAGS_DONT_RESTART_SYSCALL) can prevent syscalls
from being restarted, even if they could be (not used yet, but we
might want to use it in resume_thread(), so that we stay
behaviorally compatible with BeOS).
- The architecture specific syscall handler restarts the syscall, if
the restart flag is set. Implemented for x86 only.
- Added some support functions in the private <syscall_restart.h> to
simplify the syscall restart code in the syscalls.
- Adjusted all syscalls that can potentially be restarted accordingly.
- _user_ioctl() sets new thread flag THREAD_FLAGS_IOCTL_SYSCALL while
calling the underlying FS's/driver's hook, so that syscall restarts
can also be supported there.
* thread_at_kernel_exit() invokes handle_signals() in a loop now, as
long as the latter indicates that the thread shall be suspended, so
that after waking up signals received in the meantime will be handled
before the thread returns to userland. Adjusted handle_signals()
accordingly -- when encountering a suspending signal we don't check
for further signals.
* Fixed sigsuspend(): Suspending the thread and rescheduling doesn't
result in the correct behavior. Instead we employ a temporary
condition variable and interruptably wait on it. The POSIX test
suite test passes, now.
* Made the switch_sem[_etc]() behavior on interruption consistent.
Depending on when the signal arrived (before the call or when already
waiting) the first semaphore would or wouldn't be released. Now we
consistently release it.
* Refactored _user_{read,write}[v]() syscalls. Use a common function for
either pair. The iovec version doesn't fail anymore, if anything could
be read/written at all. It also checks whether a complete vector
could be read/written, so that we won't skip data, if the underlying
FS/driver couldn't read/write more ATM.
* Some refactoring in the x86 syscall handler: The int 99 and sysenter
handlers use a common subroutine to avoid code duplication.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23983 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-02-17 18:48:30 +03:00
|
|
|
|| (status == B_OK && user_memcpy(userInfo, &info,
|
|
|
|
sizeof(struct port_info)) < B_OK))
|
2004-02-23 07:02:24 +03:00
|
|
|
return B_BAD_ADDRESS;
|
|
|
|
|
|
|
|
return status;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2002-10-05 05:20:39 +04:00
|
|
|
|
|
|
|
ssize_t
|
2004-08-29 00:51:47 +04:00
|
|
|
_user_port_buffer_size_etc(port_id port, uint32 flags, bigtime_t timeout)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
axeld + bonefish:
* Implemented automatic syscall restarts:
- A syscall can indicate that it has been interrupted and can be
restarted by setting a respective bit in thread::flags. It can
store parameters it wants to be preserved for the restart in
thread::syscall_restart::parameters. Another thread::flags bit
indicates whether it has been restarted.
- handle_signals() clears the restart flag, if the handled signal
has a handler function installed and SA_RESTART is not set. Another
thread flag (THREAD_FLAGS_DONT_RESTART_SYSCALL) can prevent syscalls
from being restarted, even if they could be (not used yet, but we
might want to use it in resume_thread(), so that we stay
behaviorally compatible with BeOS).
- The architecture specific syscall handler restarts the syscall, if
the restart flag is set. Implemented for x86 only.
- Added some support functions in the private <syscall_restart.h> to
simplify the syscall restart code in the syscalls.
- Adjusted all syscalls that can potentially be restarted accordingly.
- _user_ioctl() sets new thread flag THREAD_FLAGS_IOCTL_SYSCALL while
calling the underlying FS's/driver's hook, so that syscall restarts
can also be supported there.
* thread_at_kernel_exit() invokes handle_signals() in a loop now, as
long as the latter indicates that the thread shall be suspended, so
that after waking up signals received in the meantime will be handled
before the thread returns to userland. Adjusted handle_signals()
accordingly -- when encountering a suspending signal we don't check
for further signals.
* Fixed sigsuspend(): Suspending the thread and rescheduling doesn't
result in the correct behavior. Instead we employ a temporary
condition variable and interruptably wait on it. The POSIX test
suite test passes, now.
* Made the switch_sem[_etc]() behavior on interruption consistent.
Depending on when the signal arrived (before the call or when already
waiting) the first semaphore would or wouldn't be released. Now we
consistently release it.
* Refactored _user_{read,write}[v]() syscalls. Use a common function for
either pair. The iovec version doesn't fail anymore, if anything could
be read/written at all. It also checks whether a complete vector
could be read/written, so that we won't skip data, if the underlying
FS/driver couldn't read/write more ATM.
* Some refactoring in the x86 syscall handler: The int 99 and sysenter
handlers use a common subroutine to avoid code duplication.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23983 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-02-17 18:48:30 +03:00
|
|
|
syscall_restart_handle_timeout_pre(flags, timeout);
|
|
|
|
|
|
|
|
status_t status = port_buffer_size_etc(port, flags | B_CAN_INTERRUPT,
|
|
|
|
timeout);
|
|
|
|
|
|
|
|
return syscall_restart_handle_timeout_post(status, timeout);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2002-10-05 05:20:39 +04:00
|
|
|
|
|
|
|
ssize_t
|
2004-08-29 00:51:47 +04:00
|
|
|
_user_port_count(port_id port)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
|
|
|
return port_count(port);
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:20:39 +04:00
|
|
|
|
2005-01-27 10:08:17 +03:00
|
|
|
status_t
|
|
|
|
_user_set_port_owner(port_id port, team_id team)
|
|
|
|
{
|
|
|
|
return set_port_owner(port, team);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-16 00:43:07 +03:00
|
|
|
ssize_t
|
2004-08-29 00:51:47 +04:00
|
|
|
_user_read_port_etc(port_id port, int32 *userCode, void *userBuffer,
|
2004-02-23 07:02:24 +03:00
|
|
|
size_t bufferSize, uint32 flags, bigtime_t timeout)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2004-02-23 07:02:24 +03:00
|
|
|
int32 messageCode;
|
2007-07-27 05:34:14 +04:00
|
|
|
ssize_t bytesRead;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
axeld + bonefish:
* Implemented automatic syscall restarts:
- A syscall can indicate that it has been interrupted and can be
restarted by setting a respective bit in thread::flags. It can
store parameters it wants to be preserved for the restart in
thread::syscall_restart::parameters. Another thread::flags bit
indicates whether it has been restarted.
- handle_signals() clears the restart flag, if the handled signal
has a handler function installed and SA_RESTART is not set. Another
thread flag (THREAD_FLAGS_DONT_RESTART_SYSCALL) can prevent syscalls
from being restarted, even if they could be (not used yet, but we
might want to use it in resume_thread(), so that we stay
behaviorally compatible with BeOS).
- The architecture specific syscall handler restarts the syscall, if
the restart flag is set. Implemented for x86 only.
- Added some support functions in the private <syscall_restart.h> to
simplify the syscall restart code in the syscalls.
- Adjusted all syscalls that can potentially be restarted accordingly.
- _user_ioctl() sets new thread flag THREAD_FLAGS_IOCTL_SYSCALL while
calling the underlying FS's/driver's hook, so that syscall restarts
can also be supported there.
* thread_at_kernel_exit() invokes handle_signals() in a loop now, as
long as the latter indicates that the thread shall be suspended, so
that after waking up signals received in the meantime will be handled
before the thread returns to userland. Adjusted handle_signals()
accordingly -- when encountering a suspending signal we don't check
for further signals.
* Fixed sigsuspend(): Suspending the thread and rescheduling doesn't
result in the correct behavior. Instead we employ a temporary
condition variable and interruptably wait on it. The POSIX test
suite test passes, now.
* Made the switch_sem[_etc]() behavior on interruption consistent.
Depending on when the signal arrived (before the call or when already
waiting) the first semaphore would or wouldn't be released. Now we
consistently release it.
* Refactored _user_{read,write}[v]() syscalls. Use a common function for
either pair. The iovec version doesn't fail anymore, if anything could
be read/written at all. It also checks whether a complete vector
could be read/written, so that we won't skip data, if the underlying
FS/driver couldn't read/write more ATM.
* Some refactoring in the x86 syscall handler: The int 99 and sysenter
handlers use a common subroutine to avoid code duplication.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23983 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-02-17 18:48:30 +03:00
|
|
|
syscall_restart_handle_timeout_pre(flags, timeout);
|
|
|
|
|
2007-07-27 05:34:14 +04:00
|
|
|
if (userBuffer == NULL && bufferSize != 0)
|
2004-02-23 07:02:24 +03:00
|
|
|
return B_BAD_VALUE;
|
2007-07-27 05:34:14 +04:00
|
|
|
if ((userCode != NULL && !IS_USER_ADDRESS(userCode))
|
|
|
|
|| (userBuffer != NULL && !IS_USER_ADDRESS(userBuffer)))
|
2004-02-23 07:02:24 +03:00
|
|
|
return B_BAD_ADDRESS;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2007-07-27 05:34:14 +04:00
|
|
|
bytesRead = read_port_etc(port, &messageCode, userBuffer, bufferSize,
|
|
|
|
flags | PORT_FLAG_USE_USER_MEMCPY | B_CAN_INTERRUPT, timeout);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2007-07-27 05:34:14 +04:00
|
|
|
if (bytesRead >= 0 && userCode != NULL
|
|
|
|
&& user_memcpy(userCode, &messageCode, sizeof(int32)) < B_OK)
|
2004-02-23 07:02:24 +03:00
|
|
|
return B_BAD_ADDRESS;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
axeld + bonefish:
* Implemented automatic syscall restarts:
- A syscall can indicate that it has been interrupted and can be
restarted by setting a respective bit in thread::flags. It can
store parameters it wants to be preserved for the restart in
thread::syscall_restart::parameters. Another thread::flags bit
indicates whether it has been restarted.
- handle_signals() clears the restart flag, if the handled signal
has a handler function installed and SA_RESTART is not set. Another
thread flag (THREAD_FLAGS_DONT_RESTART_SYSCALL) can prevent syscalls
from being restarted, even if they could be (not used yet, but we
might want to use it in resume_thread(), so that we stay
behaviorally compatible with BeOS).
- The architecture specific syscall handler restarts the syscall, if
the restart flag is set. Implemented for x86 only.
- Added some support functions in the private <syscall_restart.h> to
simplify the syscall restart code in the syscalls.
- Adjusted all syscalls that can potentially be restarted accordingly.
- _user_ioctl() sets new thread flag THREAD_FLAGS_IOCTL_SYSCALL while
calling the underlying FS's/driver's hook, so that syscall restarts
can also be supported there.
* thread_at_kernel_exit() invokes handle_signals() in a loop now, as
long as the latter indicates that the thread shall be suspended, so
that after waking up signals received in the meantime will be handled
before the thread returns to userland. Adjusted handle_signals()
accordingly -- when encountering a suspending signal we don't check
for further signals.
* Fixed sigsuspend(): Suspending the thread and rescheduling doesn't
result in the correct behavior. Instead we employ a temporary
condition variable and interruptably wait on it. The POSIX test
suite test passes, now.
* Made the switch_sem[_etc]() behavior on interruption consistent.
Depending on when the signal arrived (before the call or when already
waiting) the first semaphore would or wouldn't be released. Now we
consistently release it.
* Refactored _user_{read,write}[v]() syscalls. Use a common function for
either pair. The iovec version doesn't fail anymore, if anything could
be read/written at all. It also checks whether a complete vector
could be read/written, so that we won't skip data, if the underlying
FS/driver couldn't read/write more ATM.
* Some refactoring in the x86 syscall handler: The int 99 and sysenter
handlers use a common subroutine to avoid code duplication.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23983 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-02-17 18:48:30 +03:00
|
|
|
return syscall_restart_handle_timeout_post(bytesRead, timeout);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2002-10-05 05:20:39 +04:00
|
|
|
|
|
|
|
status_t
|
2004-08-29 00:51:47 +04:00
|
|
|
_user_write_port_etc(port_id port, int32 messageCode, const void *userBuffer,
|
2004-02-23 07:02:24 +03:00
|
|
|
size_t bufferSize, uint32 flags, bigtime_t timeout)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2005-07-14 03:55:15 +04:00
|
|
|
iovec vec = { (void *)userBuffer, bufferSize };
|
|
|
|
|
axeld + bonefish:
* Implemented automatic syscall restarts:
- A syscall can indicate that it has been interrupted and can be
restarted by setting a respective bit in thread::flags. It can
store parameters it wants to be preserved for the restart in
thread::syscall_restart::parameters. Another thread::flags bit
indicates whether it has been restarted.
- handle_signals() clears the restart flag, if the handled signal
has a handler function installed and SA_RESTART is not set. Another
thread flag (THREAD_FLAGS_DONT_RESTART_SYSCALL) can prevent syscalls
from being restarted, even if they could be (not used yet, but we
might want to use it in resume_thread(), so that we stay
behaviorally compatible with BeOS).
- The architecture specific syscall handler restarts the syscall, if
the restart flag is set. Implemented for x86 only.
- Added some support functions in the private <syscall_restart.h> to
simplify the syscall restart code in the syscalls.
- Adjusted all syscalls that can potentially be restarted accordingly.
- _user_ioctl() sets new thread flag THREAD_FLAGS_IOCTL_SYSCALL while
calling the underlying FS's/driver's hook, so that syscall restarts
can also be supported there.
* thread_at_kernel_exit() invokes handle_signals() in a loop now, as
long as the latter indicates that the thread shall be suspended, so
that after waking up signals received in the meantime will be handled
before the thread returns to userland. Adjusted handle_signals()
accordingly -- when encountering a suspending signal we don't check
for further signals.
* Fixed sigsuspend(): Suspending the thread and rescheduling doesn't
result in the correct behavior. Instead we employ a temporary
condition variable and interruptably wait on it. The POSIX test
suite test passes, now.
* Made the switch_sem[_etc]() behavior on interruption consistent.
Depending on when the signal arrived (before the call or when already
waiting) the first semaphore would or wouldn't be released. Now we
consistently release it.
* Refactored _user_{read,write}[v]() syscalls. Use a common function for
either pair. The iovec version doesn't fail anymore, if anything could
be read/written at all. It also checks whether a complete vector
could be read/written, so that we won't skip data, if the underlying
FS/driver couldn't read/write more ATM.
* Some refactoring in the x86 syscall handler: The int 99 and sysenter
handlers use a common subroutine to avoid code duplication.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23983 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-02-17 18:48:30 +03:00
|
|
|
syscall_restart_handle_timeout_pre(flags, timeout);
|
|
|
|
|
2005-01-27 10:08:17 +03:00
|
|
|
if (userBuffer == NULL && bufferSize != 0)
|
2004-02-23 07:02:24 +03:00
|
|
|
return B_BAD_VALUE;
|
2005-01-27 10:08:17 +03:00
|
|
|
if (userBuffer != NULL && !IS_USER_ADDRESS(userBuffer))
|
2004-02-23 07:02:24 +03:00
|
|
|
return B_BAD_ADDRESS;
|
|
|
|
|
axeld + bonefish:
* Implemented automatic syscall restarts:
- A syscall can indicate that it has been interrupted and can be
restarted by setting a respective bit in thread::flags. It can
store parameters it wants to be preserved for the restart in
thread::syscall_restart::parameters. Another thread::flags bit
indicates whether it has been restarted.
- handle_signals() clears the restart flag, if the handled signal
has a handler function installed and SA_RESTART is not set. Another
thread flag (THREAD_FLAGS_DONT_RESTART_SYSCALL) can prevent syscalls
from being restarted, even if they could be (not used yet, but we
might want to use it in resume_thread(), so that we stay
behaviorally compatible with BeOS).
- The architecture specific syscall handler restarts the syscall, if
the restart flag is set. Implemented for x86 only.
- Added some support functions in the private <syscall_restart.h> to
simplify the syscall restart code in the syscalls.
- Adjusted all syscalls that can potentially be restarted accordingly.
- _user_ioctl() sets new thread flag THREAD_FLAGS_IOCTL_SYSCALL while
calling the underlying FS's/driver's hook, so that syscall restarts
can also be supported there.
* thread_at_kernel_exit() invokes handle_signals() in a loop now, as
long as the latter indicates that the thread shall be suspended, so
that after waking up signals received in the meantime will be handled
before the thread returns to userland. Adjusted handle_signals()
accordingly -- when encountering a suspending signal we don't check
for further signals.
* Fixed sigsuspend(): Suspending the thread and rescheduling doesn't
result in the correct behavior. Instead we employ a temporary
condition variable and interruptably wait on it. The POSIX test
suite test passes, now.
* Made the switch_sem[_etc]() behavior on interruption consistent.
Depending on when the signal arrived (before the call or when already
waiting) the first semaphore would or wouldn't be released. Now we
consistently release it.
* Refactored _user_{read,write}[v]() syscalls. Use a common function for
either pair. The iovec version doesn't fail anymore, if anything could
be read/written at all. It also checks whether a complete vector
could be read/written, so that we won't skip data, if the underlying
FS/driver couldn't read/write more ATM.
* Some refactoring in the x86 syscall handler: The int 99 and sysenter
handlers use a common subroutine to avoid code duplication.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23983 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-02-17 18:48:30 +03:00
|
|
|
status_t status = writev_port_etc(port, messageCode, &vec, 1, bufferSize,
|
|
|
|
flags | PORT_FLAG_USE_USER_MEMCPY | B_CAN_INTERRUPT, timeout);
|
|
|
|
|
|
|
|
return syscall_restart_handle_timeout_post(status, timeout);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2005-07-14 03:55:15 +04:00
|
|
|
|
|
|
|
status_t
|
|
|
|
_user_writev_port_etc(port_id port, int32 messageCode, const iovec *userVecs,
|
|
|
|
size_t vecCount, size_t bufferSize, uint32 flags, bigtime_t timeout)
|
|
|
|
{
|
axeld + bonefish:
* Implemented automatic syscall restarts:
- A syscall can indicate that it has been interrupted and can be
restarted by setting a respective bit in thread::flags. It can
store parameters it wants to be preserved for the restart in
thread::syscall_restart::parameters. Another thread::flags bit
indicates whether it has been restarted.
- handle_signals() clears the restart flag, if the handled signal
has a handler function installed and SA_RESTART is not set. Another
thread flag (THREAD_FLAGS_DONT_RESTART_SYSCALL) can prevent syscalls
from being restarted, even if they could be (not used yet, but we
might want to use it in resume_thread(), so that we stay
behaviorally compatible with BeOS).
- The architecture specific syscall handler restarts the syscall, if
the restart flag is set. Implemented for x86 only.
- Added some support functions in the private <syscall_restart.h> to
simplify the syscall restart code in the syscalls.
- Adjusted all syscalls that can potentially be restarted accordingly.
- _user_ioctl() sets new thread flag THREAD_FLAGS_IOCTL_SYSCALL while
calling the underlying FS's/driver's hook, so that syscall restarts
can also be supported there.
* thread_at_kernel_exit() invokes handle_signals() in a loop now, as
long as the latter indicates that the thread shall be suspended, so
that after waking up signals received in the meantime will be handled
before the thread returns to userland. Adjusted handle_signals()
accordingly -- when encountering a suspending signal we don't check
for further signals.
* Fixed sigsuspend(): Suspending the thread and rescheduling doesn't
result in the correct behavior. Instead we employ a temporary
condition variable and interruptably wait on it. The POSIX test
suite test passes, now.
* Made the switch_sem[_etc]() behavior on interruption consistent.
Depending on when the signal arrived (before the call or when already
waiting) the first semaphore would or wouldn't be released. Now we
consistently release it.
* Refactored _user_{read,write}[v]() syscalls. Use a common function for
either pair. The iovec version doesn't fail anymore, if anything could
be read/written at all. It also checks whether a complete vector
could be read/written, so that we won't skip data, if the underlying
FS/driver couldn't read/write more ATM.
* Some refactoring in the x86 syscall handler: The int 99 and sysenter
handlers use a common subroutine to avoid code duplication.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23983 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-02-17 18:48:30 +03:00
|
|
|
syscall_restart_handle_timeout_pre(flags, timeout);
|
2005-07-14 03:55:15 +04:00
|
|
|
|
|
|
|
if (userVecs == NULL && bufferSize != 0)
|
|
|
|
return B_BAD_VALUE;
|
|
|
|
if (userVecs != NULL && !IS_USER_ADDRESS(userVecs))
|
|
|
|
return B_BAD_ADDRESS;
|
|
|
|
|
axeld + bonefish:
* Implemented automatic syscall restarts:
- A syscall can indicate that it has been interrupted and can be
restarted by setting a respective bit in thread::flags. It can
store parameters it wants to be preserved for the restart in
thread::syscall_restart::parameters. Another thread::flags bit
indicates whether it has been restarted.
- handle_signals() clears the restart flag, if the handled signal
has a handler function installed and SA_RESTART is not set. Another
thread flag (THREAD_FLAGS_DONT_RESTART_SYSCALL) can prevent syscalls
from being restarted, even if they could be (not used yet, but we
might want to use it in resume_thread(), so that we stay
behaviorally compatible with BeOS).
- The architecture specific syscall handler restarts the syscall, if
the restart flag is set. Implemented for x86 only.
- Added some support functions in the private <syscall_restart.h> to
simplify the syscall restart code in the syscalls.
- Adjusted all syscalls that can potentially be restarted accordingly.
- _user_ioctl() sets new thread flag THREAD_FLAGS_IOCTL_SYSCALL while
calling the underlying FS's/driver's hook, so that syscall restarts
can also be supported there.
* thread_at_kernel_exit() invokes handle_signals() in a loop now, as
long as the latter indicates that the thread shall be suspended, so
that after waking up signals received in the meantime will be handled
before the thread returns to userland. Adjusted handle_signals()
accordingly -- when encountering a suspending signal we don't check
for further signals.
* Fixed sigsuspend(): Suspending the thread and rescheduling doesn't
result in the correct behavior. Instead we employ a temporary
condition variable and interruptably wait on it. The POSIX test
suite test passes, now.
* Made the switch_sem[_etc]() behavior on interruption consistent.
Depending on when the signal arrived (before the call or when already
waiting) the first semaphore would or wouldn't be released. Now we
consistently release it.
* Refactored _user_{read,write}[v]() syscalls. Use a common function for
either pair. The iovec version doesn't fail anymore, if anything could
be read/written at all. It also checks whether a complete vector
could be read/written, so that we won't skip data, if the underlying
FS/driver couldn't read/write more ATM.
* Some refactoring in the x86 syscall handler: The int 99 and sysenter
handlers use a common subroutine to avoid code duplication.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23983 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-02-17 18:48:30 +03:00
|
|
|
iovec *vecs = NULL;
|
2005-07-14 03:55:15 +04:00
|
|
|
if (userVecs && vecCount != 0) {
|
2008-01-17 17:04:06 +03:00
|
|
|
vecs = (iovec*)malloc(sizeof(iovec) * vecCount);
|
2005-07-14 03:55:15 +04:00
|
|
|
if (vecs == NULL)
|
|
|
|
return B_NO_MEMORY;
|
|
|
|
|
|
|
|
if (user_memcpy(vecs, userVecs, sizeof(iovec) * vecCount) < B_OK) {
|
|
|
|
free(vecs);
|
|
|
|
return B_BAD_ADDRESS;
|
|
|
|
}
|
|
|
|
}
|
axeld + bonefish:
* Implemented automatic syscall restarts:
- A syscall can indicate that it has been interrupted and can be
restarted by setting a respective bit in thread::flags. It can
store parameters it wants to be preserved for the restart in
thread::syscall_restart::parameters. Another thread::flags bit
indicates whether it has been restarted.
- handle_signals() clears the restart flag, if the handled signal
has a handler function installed and SA_RESTART is not set. Another
thread flag (THREAD_FLAGS_DONT_RESTART_SYSCALL) can prevent syscalls
from being restarted, even if they could be (not used yet, but we
might want to use it in resume_thread(), so that we stay
behaviorally compatible with BeOS).
- The architecture specific syscall handler restarts the syscall, if
the restart flag is set. Implemented for x86 only.
- Added some support functions in the private <syscall_restart.h> to
simplify the syscall restart code in the syscalls.
- Adjusted all syscalls that can potentially be restarted accordingly.
- _user_ioctl() sets new thread flag THREAD_FLAGS_IOCTL_SYSCALL while
calling the underlying FS's/driver's hook, so that syscall restarts
can also be supported there.
* thread_at_kernel_exit() invokes handle_signals() in a loop now, as
long as the latter indicates that the thread shall be suspended, so
that after waking up signals received in the meantime will be handled
before the thread returns to userland. Adjusted handle_signals()
accordingly -- when encountering a suspending signal we don't check
for further signals.
* Fixed sigsuspend(): Suspending the thread and rescheduling doesn't
result in the correct behavior. Instead we employ a temporary
condition variable and interruptably wait on it. The POSIX test
suite test passes, now.
* Made the switch_sem[_etc]() behavior on interruption consistent.
Depending on when the signal arrived (before the call or when already
waiting) the first semaphore would or wouldn't be released. Now we
consistently release it.
* Refactored _user_{read,write}[v]() syscalls. Use a common function for
either pair. The iovec version doesn't fail anymore, if anything could
be read/written at all. It also checks whether a complete vector
could be read/written, so that we won't skip data, if the underlying
FS/driver couldn't read/write more ATM.
* Some refactoring in the x86 syscall handler: The int 99 and sysenter
handlers use a common subroutine to avoid code duplication.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23983 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-02-17 18:48:30 +03:00
|
|
|
|
|
|
|
status_t status = writev_port_etc(port, messageCode, vecs, vecCount,
|
|
|
|
bufferSize, flags | PORT_FLAG_USE_USER_MEMCPY | B_CAN_INTERRUPT,
|
|
|
|
timeout);
|
2005-07-14 03:55:15 +04:00
|
|
|
|
|
|
|
free(vecs);
|
axeld + bonefish:
* Implemented automatic syscall restarts:
- A syscall can indicate that it has been interrupted and can be
restarted by setting a respective bit in thread::flags. It can
store parameters it wants to be preserved for the restart in
thread::syscall_restart::parameters. Another thread::flags bit
indicates whether it has been restarted.
- handle_signals() clears the restart flag, if the handled signal
has a handler function installed and SA_RESTART is not set. Another
thread flag (THREAD_FLAGS_DONT_RESTART_SYSCALL) can prevent syscalls
from being restarted, even if they could be (not used yet, but we
might want to use it in resume_thread(), so that we stay
behaviorally compatible with BeOS).
- The architecture specific syscall handler restarts the syscall, if
the restart flag is set. Implemented for x86 only.
- Added some support functions in the private <syscall_restart.h> to
simplify the syscall restart code in the syscalls.
- Adjusted all syscalls that can potentially be restarted accordingly.
- _user_ioctl() sets new thread flag THREAD_FLAGS_IOCTL_SYSCALL while
calling the underlying FS's/driver's hook, so that syscall restarts
can also be supported there.
* thread_at_kernel_exit() invokes handle_signals() in a loop now, as
long as the latter indicates that the thread shall be suspended, so
that after waking up signals received in the meantime will be handled
before the thread returns to userland. Adjusted handle_signals()
accordingly -- when encountering a suspending signal we don't check
for further signals.
* Fixed sigsuspend(): Suspending the thread and rescheduling doesn't
result in the correct behavior. Instead we employ a temporary
condition variable and interruptably wait on it. The POSIX test
suite test passes, now.
* Made the switch_sem[_etc]() behavior on interruption consistent.
Depending on when the signal arrived (before the call or when already
waiting) the first semaphore would or wouldn't be released. Now we
consistently release it.
* Refactored _user_{read,write}[v]() syscalls. Use a common function for
either pair. The iovec version doesn't fail anymore, if anything could
be read/written at all. It also checks whether a complete vector
could be read/written, so that we won't skip data, if the underlying
FS/driver couldn't read/write more ATM.
* Some refactoring in the x86 syscall handler: The int 99 and sysenter
handlers use a common subroutine to avoid code duplication.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23983 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-02-17 18:48:30 +03:00
|
|
|
return syscall_restart_handle_timeout_post(status, timeout);
|
2005-07-14 03:55:15 +04:00
|
|
|
}
|