[072607b] | 1 | /*
|
---|
| 2 | * Copyright (c) 2016 Jakub Jermar
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup genericipc
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | */
|
---|
| 34 |
|
---|
| 35 | #include <ipc/sysipc_ops.h>
|
---|
| 36 | #include <ipc/ipc.h>
|
---|
| 37 | #include <mm/as.h>
|
---|
| 38 | #include <mm/page.h>
|
---|
| 39 | #include <genarch/mm/page_pt.h>
|
---|
| 40 | #include <genarch/mm/page_ht.h>
|
---|
| 41 | #include <mm/frame.h>
|
---|
| 42 | #include <proc/task.h>
|
---|
| 43 | #include <abi/errno.h>
|
---|
| 44 | #include <arch.h>
|
---|
| 45 |
|
---|
| 46 | static int answer_preprocess(call_t *answer, ipc_data_t *olddata)
|
---|
| 47 | {
|
---|
[ae66564] | 48 | /*
|
---|
| 49 | * We only do the special handling below if the call was initiated by
|
---|
| 50 | * the kernel. Otherwise a malicious task could use this mechanism to
|
---|
| 51 | * hold memory frames forever.
|
---|
| 52 | */
|
---|
| 53 | if (!answer->priv)
|
---|
| 54 | return EOK;
|
---|
| 55 |
|
---|
[072607b] | 56 | if (!IPC_GET_RETVAL(answer->data)) {
|
---|
[ae66564] | 57 |
|
---|
[2a2fbc8] | 58 | pte_t pte;
|
---|
[072607b] | 59 | uintptr_t frame;
|
---|
| 60 |
|
---|
| 61 | page_table_lock(AS, true);
|
---|
[2a2fbc8] | 62 | bool found = page_mapping_find(AS, IPC_GET_ARG1(answer->data),
|
---|
| 63 | false, &pte);
|
---|
[560b81c] | 64 | if (found & PTE_PRESENT(&pte)) {
|
---|
[2a2fbc8] | 65 | frame = PTE_GET_FRAME(&pte);
|
---|
[9befb0d] | 66 | pfn_t pfn = ADDR2PFN(frame);
|
---|
| 67 | if (find_zone(pfn, 1, 0) != (size_t) -1) {
|
---|
| 68 | /*
|
---|
| 69 | * The frame is in physical memory managed by
|
---|
| 70 | * the frame allocator.
|
---|
| 71 | */
|
---|
| 72 | frame_reference_add(ADDR2PFN(frame));
|
---|
| 73 | }
|
---|
[072607b] | 74 | IPC_SET_ARG1(answer->data, frame);
|
---|
| 75 | } else {
|
---|
| 76 | IPC_SET_RETVAL(answer->data, ENOENT);
|
---|
| 77 | }
|
---|
| 78 | page_table_unlock(AS, true);
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | return EOK;
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | sysipc_ops_t ipc_m_page_in_ops = {
|
---|
| 85 | .request_preprocess = null_request_preprocess,
|
---|
| 86 | .request_forget = null_request_forget,
|
---|
| 87 | .request_process = null_request_process,
|
---|
| 88 | .answer_cleanup = null_answer_cleanup,
|
---|
| 89 | .answer_preprocess = answer_preprocess,
|
---|
| 90 | .answer_process = null_answer_process,
|
---|
| 91 | };
|
---|
| 92 |
|
---|
| 93 | /** @}
|
---|
| 94 | */
|
---|