/*
 * =====================================================================================
 *
 *       Filename:  mcStackProtection.c
 *
 *    Description:  Stack protection in Tbase.
 *
 *        Version:  1.0
 *        Created:  12/05/2017 03:51:07 PM
 *       Compiler:  armcc
 *
 *         Author:  Dongwook Shim (), dw.shim@samsung.com
 *        Company:  Samsung Electronics
 *
 *        Copyright (c) 2017 by Samsung Electronics, All rights reserved.
 *
 * =====================================================================================
 */

#include <stdint.h>
#include <stdlib.h>

#include "tlStd.h"
#include "TlApi/TlApi.h"
#include "mcStackProtection.h"

#ifdef ARM64
uint64_t __stack_chk_guard = 0;
#else //ARM32
uint32_t __stack_chk_guard = 0;
#endif

void initStackProtection(void)
{
	size_t length = sizeof(__stack_chk_guard);
	tlApiRandomGenerateData(TLAPI_ALG_SECURE_RANDOM, (uint8_t *)&__stack_chk_guard, &length);
}

void __attribute__((weak)) __stack_chk_fail(void)
{
	abort();
}
