From a179a6a0a7b23ba5e4034a8fcfa04c6c6c1fb352 Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Wed, 8 Nov 2023 21:52:55 +0100 Subject: [PATCH] use access from gcc 11 --- core/klibc.c | 22 +++++++++++----------- core/klibc.h | 12 ++++++------ tests/test.c | 4 ++++ 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/core/klibc.c b/core/klibc.c index fbef3b5..364a4f6 100644 --- a/core/klibc.c +++ b/core/klibc.c @@ -27,19 +27,9 @@ int memcmp(const void *aptr, const void *bptr, size_t size) /* How many bytes are copied each iteration of the word copy loop. */ #define LITTLEBLOCKSIZE (sizeof (long)) -/* Threshhold for punting to the byte copier. */ +/* Threshold for punting to the byte copier. */ #define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE) -void *memmove(void *dst, const void *src, size_t n) -{ - char *dstChar = dst; - const char *srcChar = src; - for (size_t i = 0; i < n; i++) { - *(dstChar++) = *(srcChar++); - } - return dst; -} - void *memcpy(void *dst0, const void *src0, size_t len0) { #if 0 @@ -88,6 +78,16 @@ void *memcpy(void *dst0, const void *src0, size_t len0) #endif } +void *memmove(void *dst, const void *src, size_t n) +{ + char *dstChar = dst; + const char *srcChar = src; + for (size_t i = 0; i < n; i++) { + *(dstChar++) = *(srcChar++); + } + return dst; +} + void *memset(void *src, int c, size_t n) { for (char *ptr = (char *)src; n > 0; n--, ptr++) { diff --git a/core/klibc.h b/core/klibc.h index 435282e..d54b146 100644 --- a/core/klibc.h +++ b/core/klibc.h @@ -14,21 +14,21 @@ /** compares the first @param n bytes (each interpreted as * unsigned char) of the memory areas @param s1 and @param s2. */ -int memcmp(const void *s1, const void *s2, size_t n); +__attribute__ ((access (read_only, 1, 3), access (read_only, 2, 3))) int memcmp(const void *s1, const void *s2, size_t n); /** * copies n bytes from memory area src to memory area dest. The memory areas may overlap */ -void *memmove(void *dest, const void *src, size_t n); -void *memcpy(void *dest, const void *src, size_t n); -void *memset(void *s, int c, size_t n); +__attribute__ ((access (write_only, 1, 3), access (read_only, 2, 3))) void *memmove(void *dest, const void *src, size_t n); +__attribute__ ((access (write_only, 1, 3), access (read_only, 2, 3))) void *memcpy(void *dest, const void *src, size_t n); +__attribute__ ((access (write_only, 1, 3))) void *memset(void *s, int c, size_t n); char *itoa(long long int value, char *str, int base); int atoi(const char *str); void reverse(char s[]); int strlen(const char s[]); -unsigned int strnlen(const char *s, size_t count); +__attribute__ ((access (read_only, 1, 2))) unsigned int strnlen(const char *s, size_t count); int strcmp(const char s1[], const char s2[]); -char *strzcpy(char *dst, const char *src, int len); +__attribute__ ((access (read_only, 2), access (write_only, 1, 3))) char *strzcpy(char *dst, const char *src, int len); int puts(const char *str); int putc(const char str); int vsnprintf(char *str, size_t size, const char *format, va_list ap); diff --git a/tests/test.c b/tests/test.c index c12de53..7628a64 100644 --- a/tests/test.c +++ b/tests/test.c @@ -496,6 +496,10 @@ void testRingBuffer() void run_test(void) { + // Example of checking thx to access attributs + //int a[4] = {0}; + //int b[3] = {0}; + //memcpy(b, a, sizeof(a)); uint freemem, usedmem; uint afterFreemem, afterUsedmem;