]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/page_decrypt.c
34d66afb9b66eb580b296d7d3ba501c477f024b6
[apple/xnu.git] / osfmk / kern / page_decrypt.c
1 /*
2 * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23
24 #include <kern/page_decrypt.h>
25 #include <kern/task.h>
26 #include <machine/commpage.h>
27
28 /*#include <sys/kernel.h> */
29 extern int hz; /* system clock's frequency */
30 extern void* dsmos_blobs[];
31 extern int dsmos_blob_count;
32
33 /* #include <sys/proc.h> */
34 extern int tsleep(void *chan, int pri, const char *wmesg, int timo);
35
36 /* #include <sys/param.h> */
37 #define PZERO 22 /* No longer magic, shouldn't be here. XXX */
38
39 static int _dsmos_wait_for_callback(const void*,void*);
40
41 static dsmos_page_transform_hook_t dsmos_hook = _dsmos_wait_for_callback;
42
43 int
44 _dsmos_wait_for_callback(const void* from, void *to)
45 {
46 /* printf("%s\n", __FUNCTION__); */
47 while (dsmos_hook == NULL)
48 tsleep(&dsmos_hook, PZERO, "dsmos", hz / 10);
49
50 return (*dsmos_hook) (from, to);
51 }
52
53 void
54 dsmos_page_transform_hook(dsmos_page_transform_hook_t hook,
55 void (*commpage_setup_dsmos_blob)(void**, int))
56 {
57 #ifdef i386
58 /* finish initializing the commpage here */
59 (*commpage_setup_dsmos_blob)(dsmos_blobs, dsmos_blob_count);
60 #endif
61
62 /* set the hook now - new callers will run with it */
63 dsmos_hook = hook;
64 }
65
66 int
67 dsmos_page_transform(const void* from, void* to)
68 {
69 /* printf("%s\n", __FUNCTION__); */
70 if (dsmos_hook == NULL)
71 return KERN_FAILURE;
72 return (*dsmos_hook) (from, to);
73 }
74