IPC server: do not loop to find syscall handler

Instead of using a loop to find a matching ipc (inter process
communication) system call type, the offset in the call table can be
simply calculated in constant time.

Also, when the interprocess communication server receives an ipc
system call from a process, ipc should tell VM to watch the process
only once. This patch fixes that also.

(Patch and commit message slightly edited by committer.)
This commit is contained in:
Sbastien Boisvert 2012-09-08 17:46:06 +02:00 committed by David van Moolenbroek
parent df3975243b
commit 373cb6526c

View file

@ -38,7 +38,7 @@ int main(int argc, char *argv[])
while (TRUE) { while (TRUE) {
int r; int r;
int i; int ipc_number;
if ((r = sef_receive(ANY, &m)) != OK) if ((r = sef_receive(ANY, &m)) != OK)
printf("sef_receive failed %d.\n", r); printf("sef_receive failed %d.\n", r);
@ -62,8 +62,22 @@ int main(int argc, char *argv[])
continue; continue;
} }
/* dispatch messages */ /*
for (i = 0; i < SIZE(ipc_calls); i++) { * The ipc number in the table can be obtained
* with a simple equation because the values of
* IPC system calls are consecutive and begin
* at ( IPC_BASE + 1 )
*/
ipc_number = call_type - (IPC_BASE + 1);
/* dispatch message */
if (ipc_number >= 0 && ipc_number < SIZE(ipc_calls)) {
int result;
if (ipc_calls[ipc_number].type != call_type)
panic("IPC: call table order mismatch");
/* If any process does an IPC call, /* If any process does an IPC call,
* we have to know about it exiting. * we have to know about it exiting.
* Tell VM to watch it for us. * Tell VM to watch it for us.
@ -72,13 +86,13 @@ int main(int argc, char *argv[])
printf("IPC: watch failed on %d\n", m.m_source); printf("IPC: watch failed on %d\n", m.m_source);
} }
if (ipc_calls[i].type == call_type) { result = ipc_calls[ipc_number].func(&m);
int result;
result = ipc_calls[i].func(&m); /*
* The handler of the IPC call did not
if (ipc_calls[i].reply) * post a reply.
break; */
if (!ipc_calls[ipc_number].reply) {
m.m_type = result; m.m_type = result;
@ -88,11 +102,8 @@ int main(int argc, char *argv[])
if ((r = sendnb(who_e, &m)) != OK) if ((r = sendnb(who_e, &m)) != OK)
printf("IPC send error %d.\n", r); printf("IPC send error %d.\n", r);
break;
} }
} } else {
if (i == SIZE(ipc_calls)) {
/* warn and then ignore */ /* warn and then ignore */
printf("IPC unknown call type: %d from %d.\n", printf("IPC unknown call type: %d from %d.\n",
call_type, who_e); call_type, who_e);