summaryrefslogtreecommitdiff
path: root/kern
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2023-10-01 15:39:49 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2023-10-01 15:59:22 +0200
commite64697e4abda6c7ef512f4a2948c0d777d668be9 (patch)
treec9307d06b177dbf6da5e8acb92eeab4bd86118ed /kern
parent922e514ad93bf21985659ad10a96019a20ad4c10 (diff)
Add and use ikm_cache_alloc/free/_try
Diffstat (limited to 'kern')
-rw-r--r--kern/exception.c30
-rw-r--r--kern/ipc_kobject.c6
2 files changed, 13 insertions, 23 deletions
diff --git a/kern/exception.c b/kern/exception.c
index d3fa50e1..15f29705 100644
--- a/kern/exception.c
+++ b/kern/exception.c
@@ -366,16 +366,9 @@ exception_raise(
* and it will give the buffer back with its reply.
*/
- kmsg = ikm_cache();
- if (kmsg != IKM_NULL) {
- ikm_cache() = IKM_NULL;
- ikm_check_initialized(kmsg, IKM_SAVED_KMSG_SIZE);
- } else {
- kmsg = ikm_alloc(IKM_SAVED_MSG_SIZE);
- if (kmsg == IKM_NULL)
- panic("exception_raise");
- ikm_init(kmsg, IKM_SAVED_MSG_SIZE);
- }
+ kmsg = ikm_cache_alloc();
+ if (kmsg == IKM_NULL)
+ panic("exception_raise");
/*
* We need a reply port for the RPC.
@@ -695,15 +688,20 @@ exception_raise(
assert(kmsg->ikm_size == IKM_SAVED_KMSG_SIZE);
if (copyoutmsg(&kmsg->ikm_header, receiver->ith_msg,
- sizeof(struct mach_exception)) ||
- (ikm_cache() != IKM_NULL)) {
+ sizeof(struct mach_exception))) {
+ mr = ipc_kmsg_put(receiver->ith_msg, kmsg,
+ kmsg->ikm_header.msgh_size);
+ thread_syscall_return(mr);
+ /*NOTREACHED*/
+ }
+
+ if (!ikm_cache_free_try(kmsg)) {
mr = ipc_kmsg_put(receiver->ith_msg, kmsg,
kmsg->ikm_header.msgh_size);
thread_syscall_return(mr);
/*NOTREACHED*/
}
- ikm_cache() = kmsg;
thread_syscall_return(MACH_MSG_SUCCESS);
/*NOTREACHED*/
#ifndef __GNUC__
@@ -823,11 +821,7 @@ exception_parse_reply(ipc_kmsg_t kmsg)
kr = msg->RetCode;
- if ((kmsg->ikm_size == IKM_SAVED_KMSG_SIZE) &&
- (ikm_cache() == IKM_NULL))
- ikm_cache() = kmsg;
- else
- ikm_free(kmsg);
+ ikm_cache_free(kmsg);
return kr;
}
diff --git a/kern/ipc_kobject.c b/kern/ipc_kobject.c
index 960ef892..0a815953 100644
--- a/kern/ipc_kobject.c
+++ b/kern/ipc_kobject.c
@@ -238,11 +238,7 @@ ipc_kobject_server(ipc_kmsg_t request)
/* like ipc_kmsg_put, but without the copyout */
ikm_check_initialized(request, request->ikm_size);
- if ((request->ikm_size == IKM_SAVED_KMSG_SIZE) &&
- (ikm_cache() == IKM_NULL))
- ikm_cache() = request;
- else
- ikm_free(request);
+ ikm_cache_free(request);
} else {
/*
* The message contents of the request are intact.