1 /* 2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. 3 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without modification, 6 * are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this list of 9 * conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 * of conditions and the following disclaimer in the documentation and/or other materials 13 * provided with the distribution. 14 * 15 * 3. Neither the name of the copyright holder nor the names of its contributors may be used 16 * to endorse or promote products derived from this software without specific prior written 17 * permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #include "los_typedef.h" 33 #pragma once 34 35 /* 36 * @brief Copy data from userspace into kernelspace 37 * 38 * This function validates that usermode has access to src before copying the 39 * data. 40 * 41 * @param dst The destination buffer. 42 * @param src The source buffer. 43 * @param len The number of bytes to copy. 44 * 45 * @return bytes not copied 46 */ 47 size_t LOS_ArchCopyFromUser(void *dst, const void *src, size_t len); 48 49 /* 50 * @brief Copy data from kernelspace into userspace 51 * 52 * This function validates that usermode has access to dst before copying the 53 * data. 54 * 55 * @param dst The destination buffer. 56 * @param src The source buffer. 57 * @param len The number of bytes to copy. 58 * 59 * @return bytes not copied 60 */ 61 size_t LOS_ArchCopyToUser(void *dst, const void *src, size_t len); 62 63 /* 64 * @brief Copy data from src to dst 65 * 66 * This function will use different copy methods to copy src data to dst, according to 67 * the different spaces (userspace or kernelspace) of dst data. 68 * 69 * @param dst The destination buffer, can be userspace address. 70 * @param max The maxsimum number of bytes to copy. 71 * @param src The source buffer. 72 * @param len The number of bytes to copy. 73 * 74 * @return zero on success; non-zero on failure. 75 */ 76 INT32 LOS_CopyFromKernel(VOID *dest, UINT32 max, const VOID *src, UINT32 count); 77 78 /* 79 * @brief Copy data from src to dst 80 * 81 * This function will use different copy methods to copy src data to dst, according to 82 * the different spaces (userspace or kernelspace) of src data. 83 * 84 * @param dst The destination buffer. 85 * @param max The maxsimum number of bytes to copy. 86 * @param src The source buffer, can be userspace address. 87 * @param len The number of bytes to copy. 88 * 89 * @return zero on success; non-zero on failure. 90 */ 91 INT32 LOS_CopyToKernel(VOID *dest, UINT32 max, const VOID *src, UINT32 count); 92 93 /* 94 * @brief Clear data in buf 95 * 96 * This function will clear buf from buf to buf + len. 97 * 98 * @param buf The destination buffer, can be userspace address. 99 * @param len The number of bytes to clear. 100 * 101 * @return zero on success; non-zero on failure. 102 */ 103 INT32 LOS_UserMemClear(unsigned char *buf, UINT32 len); 104