/**
 * @file       task_access.h
 * @brief      Read/write particular data from REE user space tasks
 * @author     Ivan Vorobiov (i.vorobiov@samsung.com)
 * @version    1.0
 * @date       Created Jul 13, 2016
 * @copyright  In Samsung Ukraine R&D Center (SURC) under a contract between
 * @copyright  LLC "Samsung Electronics Ukraine Company" (Kiev, Ukraine) and
 * @copyright  "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
 * @copyright  Copyright: (c) Samsung Electronics Co, Ltd 2016. All rights reserved.
**/

#ifndef PA_TZ_DRV_SRC_TASK_ACCESS_H_
#define PA_TZ_DRV_SRC_TASK_ACCESS_H_

#include "memory.h"
#include "task.h"

/**
 * @brief Read task memory by task_struct
 * @param [in] task task_struct
 * @param [in] user_address User space virtual address inside the task
 * @param [in] size Count of bytes needed to read
 * @param [out] out Pointer to output buffer with size at least "size" bytes
 * @return ::PA_TZ_SUCCESS in case of success, ::PA_TZ_GENERAL_ERROR,
 *         ::PA_TZ_MEMORY_PERM_ERROR
 */
PaTzResult TaskAccessGetBytes(const TaskInfo *task,
                              ProcessAddress address, size_t size, void *out);

/**
 * @brief Write memory to REE task by task_struct
 * @param [in] task task_struct
 * @param [in] in Pointer to source buffer
 * @param [in] size Count of bytes needed to write
 * @param [in] user_address User space virtual address inside the task
 * @return ::PA_TZ_SUCCESS in case of success, ::PA_TZ_GENERAL_ERROR,
 *         ::PA_TZ_MEMORY_PERM_ERROR
 */
PaTzResult TaskAccessPutBytes(const TaskInfo *task,
                              const void *in, size_t size, ProcessAddress address);

/**
 * @brief Check that user memory is readable
 * @param [in] task Task info
 * @param [in] address User space process address
 * @return 1 if memory is readable, 0 if memory is not readable,
 * -1 if error is occurred
 */
int32_t IsProcessAddressReadable(const TaskInfo *task, ProcessAddress address);

/**
 * @brief Check that user memory is writable
 * @param [in] task Task info
 * @param [in] address User space process address
 * @return 1 if memory is writable, 0 if memory is not writable,
 * -1 if error is occurred
 */
int32_t IsProcessAddressWritable(const TaskInfo *task, ProcessAddress address);

#endif // PA_TZ_DRV_SRC_TASK_ACCESS_H_
