<commit_before>//SPDX-License-Identifier: BSD-2-Clause
/*
 * Copyright (C) 2017 - 2018, ARM Limited
 */

#include <kernel/misc.h>
#include <kernel/pseudo_ta.h>
#include <mm/core_memprot.h>
#include <mm/tee_mmu.h>
#include <sdp_pta.h>

#define PTA_NAME "sdp.pta"

static TEE_Result sdp_pa_cmd_virt_to_phys(uint32_t types,
					  TEE_Param params[TEE_NUM_PARAMS])
{
	char *va = params[0].memref.buffer;
	size_t len = params[0].memref.size;
	struct tee_ta_session *s;
	struct user_ta_ctx *utc;
	TEE_Result res;

	if (types != TEE_PARAM_TYPES(TEE_PARAM_TYPE_MEMREF_INPUT,
				     TEE_PARAM_TYPE_VALUE_OUTPUT,
				     TEE_PARAM_TYPE_NONE,
				     TEE_PARAM_TYPE_NONE)) {
		EMSG("bad parameters types: 0x%" PRIx32, types);
		return TEE_ERROR_BAD_PARAMETERS;
	}

	s = tee_ta_get_calling_session();
	if (!s)
		return TEE_ERROR_ACCESS_DENIED;

	utc = to_user_ta_ctx(s->ctx);
	res = tee_mmu_check_access_rights(utc, TEE_MEMORY_ACCESS_READ |
					  TEE_MEMORY_ACCESS_WRITE |
					  TEE_MEMORY_ACCESS_ANY_OWNER,
					  (uaddr_t)va, len);
	if (res != TEE_SUCCESS)
		return TEE_ERROR_ACCESS_DENIED;

	if (!core_vbuf_is(CORE_MEM_SDP_MEM, va, len)) {
		DMSG("bad memref secure attribute");
		return TEE_ERROR_BAD_PARAMETERS;
	}

	reg_pair_from_64(virt_to_phys(va), &params[1].value.a,
			 &params[1].value.b);

	return TEE_SUCCESS;
}

/*
 * Trusted Application Entry Points
 */
static TEE_Result open_session(uint32_t nParamTypes __unused,
			       TEE_Param pParams[TEE_NUM_PARAMS] __unused,
			       void **ppSessionContext __unused)
{
	struct tee_ta_session *s = tee_ta_get_calling_session();

	if (s && (s->ctx->flags & TA_FLAG_SECURE_DATA_PATH)) {
		DMSG("open entry point for pseudo-TA \"%s\"", PTA_NAME);
		return TEE_SUCCESS;
	}

	DMSG("TA %pUl is unauthorised access to pseudo-TA \"%s\"",
	     s->ctx->uuid, PTA_NAME);<commit_msg>core/arch/arm/pta/sdp_pta.c: Fix compile error<commit_after>//SPDX-License-Identifier: BSD-2-Clause
/*
 * Copyright (C) 2017 - 2018, ARM Limited
 */

#include <kernel/misc.h>
#include <kernel/pseudo_ta.h>
#include <mm/core_memprot.h>
#include <mm/tee_mmu.h>
#include <sdp_pta.h>

#define PTA_NAME "sdp.pta"

static TEE_Result sdp_pa_cmd_virt_to_phys(uint32_t types,
					  TEE_Param params[TEE_NUM_PARAMS])
{
	char *va = params[0].memref.buffer;
	size_t len = params[0].memref.size;
	struct tee_ta_session *s;
	struct user_ta_ctx *utc;
	TEE_Result res;

	if (types != TEE_PARAM_TYPES(TEE_PARAM_TYPE_MEMREF_INPUT,
				     TEE_PARAM_TYPE_VALUE_OUTPUT,
				     TEE_PARAM_TYPE_NONE,
				     TEE_PARAM_TYPE_NONE)) {
		EMSG("bad parameters types: 0x%" PRIx32, types);
		return TEE_ERROR_BAD_PARAMETERS;
	}

	s = tee_ta_get_calling_session();
	if (!s)
		return TEE_ERROR_ACCESS_DENIED;

	utc = to_user_ta_ctx(s->ctx);
	res = tee_mmu_check_access_rights(utc, TEE_MEMORY_ACCESS_READ |
					  TEE_MEMORY_ACCESS_WRITE |
					  TEE_MEMORY_ACCESS_ANY_OWNER,
					  (uaddr_t)va, len);
	if (res != TEE_SUCCESS)
		return TEE_ERROR_ACCESS_DENIED;

	if (!core_vbuf_is(CORE_MEM_SDP_MEM, va, len)) {
		DMSG("bad memref secure attribute");
		return TEE_ERROR_BAD_PARAMETERS;
	}

	reg_pair_from_64(virt_to_phys(va), &params[1].value.a,
			 &params[1].value.b);

	return TEE_SUCCESS;
}

/*
 * Trusted Application Entry Points
 */
static TEE_Result open_session(uint32_t nParamTypes __unused,
			       TEE_Param pParams[TEE_NUM_PARAMS] __unused,
			       void **ppSessionContext __unused)
{
	struct tee_ta_session *s = tee_ta_get_calling_session();

	if (s && (s->ctx->flags & TA_FLAG_SECURE_DATA_PATH)) {
		DMSG("open entry point for pseudo-TA \"%s\"", PTA_NAME);
		return TEE_SUCCESS;
	}

	DMSG("TA %pUl is unauthorised access to pseudo-TA \"%s\"",
	     (void *)&s->ctx->uuid, PTA_NAME);
{'fraction_non_alphanumeric': 0.12054054054054054, 'fraction_numerical': 0.011891891891891892, 'mean_word_length': 4.426686217008798, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5295170', 'n_tokens_mistral': 1673, 'n_tokens_neox': 1507, 'n_words': 267}