Changeset View
Changeset View
Standalone View
Standalone View
include/secure/security.h
- This file was added.
/*- | |||||
* Copyright (c) 2015 Olivér Pintér | |||||
* All rights reserved. | |||||
ngie: Olivér Pintér's name has accents here, but not elsewhere. Also, I thought convention was to… | |||||
* | |||||
* Redistribution and use in source and binary forms, with or without | |||||
* modification, are permitted provided that the following conditions | |||||
* are met: | |||||
* 1. Redistributions of source code must retain the above copyright | |||||
* notice, this list of conditions and the following disclaimer. | |||||
* 2. Redistributions in binary form must reproduce the above copyright | |||||
* notice, this list of conditions and the following disclaimer in the | |||||
* documentation and/or other materials provided with the distribution. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | |||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
* SUCH DAMAGE. | |||||
* | |||||
* $FreeBSD$ | |||||
*/ | |||||
#ifndef _SECURE_SECURITY_ | |||||
#define _SECURE_SECURITY_ | |||||
#include <sys/cdefs.h> | |||||
#include <sys/types.h> | |||||
#ifndef __clang__ | |||||
#define __errordecl(name, msg) extern void name(void) __error_attr(msg) | |||||
#else | |||||
Not Done Inline ActionsBetter: pfg: Better:
#if !defined(__clang__) && `__GNUC_PREREQ(4, 3)` | |||||
Not Done Inline ActionsBah.. not so easy.. but there is something wrong there :( pfg: Bah.. not so easy.. but there is something wrong there :( | |||||
Done Inline Actions#if __GNUC_PREREQ__(4, 3) works here. pfg: #if `__GNUC_PREREQ__(4, 3)`
works here. | |||||
#define __errordecl(name, msg) | |||||
#endif | |||||
#define __RENAME(x) __asm__(#x) | |||||
#if __has_builtin(__builtin_umul_overflow) || __GNUC__ >= 5 | |||||
pfgUnsubmitted Done Inline ActionsThis should be __GNUC_PREREQ__(5, 0) for consistency. pfg: This should be `__GNUC_PREREQ__(5, 0)` for consistency.
But maybe we should have it in cdefs.h ? | |||||
#if __LP64__ | |||||
#define __size_mul_overflow(a, b, result) __builtin_umull_overflow(a, b, result) | |||||
#else | |||||
#define __size_mul_overflow(a, b, result) __builtin_umul_overflow(a, b, result) | |||||
#endif | |||||
#else | |||||
static __inline__ __always_inline int | |||||
__size_mul_overflow(__SIZE_TYPE__ a, __SIZE_TYPE__ b, __SIZE_TYPE__ *result) | |||||
{ | |||||
static const __SIZE_TYPE__ mul_no_overflow = 1UL << (sizeof(__SIZE_TYPE__) * 4); | |||||
*result = a * b; | |||||
return (a >= mul_no_overflow || b >= mul_no_overflow) && a > 0 && (__SIZE_TYPE__)-1 / a < b; | |||||
} | |||||
#endif | |||||
__BEGIN_DECLS | |||||
/* Common fail function. */ | |||||
void __secure_fail(const char *msg) __dead2 __nonnull(1); | |||||
/* SSP related fail functions. */ | |||||
void __chk_fail(void) __dead2; | |||||
void __stack_chk_fail(void) __dead2; | |||||
/* FORTIFY_SOURCE related fail function. */ | |||||
void __fortify_chk_fail(const char* msg) __dead2 __nonnull(1); | |||||
int __fortify_chk_overlap(const void *a, const void *b, size_t len); | |||||
__END_DECLS | |||||
#endif /* !_SECURE_SECURITY_ */ |
Olivér Pintér's name has accents here, but not elsewhere. Also, I thought convention was to omit email addresses.