fix the stupid symbol attribute mess, pt. 1
This commit is contained in:
parent
af8210da4a
commit
298433e15f
10 changed files with 65 additions and 59 deletions
|
@ -5,7 +5,7 @@
|
|||
|
||||
#include <ardix/types.h>
|
||||
|
||||
int memcmp(const void *s1, const void *s2, size_t n);
|
||||
#include <toolchain.h>
|
||||
|
||||
/**
|
||||
* Copy `n` bytes from `src` to `dest`.
|
||||
|
@ -15,7 +15,7 @@ int memcmp(const void *s1, const void *s2, size_t n);
|
|||
* @param n: The amount of bytes to copy.
|
||||
* @returns A pointer to `dest`.
|
||||
*/
|
||||
void *memcpy(void *dest, const void *src, size_t n);
|
||||
__shared void *memcpy(void *dest, const void *src, size_t n);
|
||||
|
||||
/**
|
||||
* Starting from `ptr`, fill `n` bytes with the constant byte `c`.
|
||||
|
@ -25,7 +25,7 @@ void *memcpy(void *dest, const void *src, size_t n);
|
|||
* @param n: The amount of bytes to write.
|
||||
* @returns A pointer to `ptr`.
|
||||
*/
|
||||
void *memset(void *ptr, int c, size_t n);
|
||||
__shared void *memset(void *ptr, int c, size_t n);
|
||||
|
||||
/**
|
||||
* Copy a memory area.
|
||||
|
@ -37,7 +37,7 @@ void *memset(void *ptr, int c, size_t n);
|
|||
* @param n: The amount of bytes to copy.
|
||||
* @return a pointer to dest.
|
||||
*/
|
||||
void *memmove(void *dest, const void *src, size_t n);
|
||||
__shared void *memmove(void *dest, const void *src, size_t n);
|
||||
|
||||
/**
|
||||
* Compare the two strings `s1` and `s2`.
|
||||
|
@ -47,7 +47,7 @@ void *memmove(void *dest, const void *src, size_t n);
|
|||
* @returns `0` if both strings are equal, a positive value f `s1` is greater
|
||||
* than `s2`, and a negative value if `s1` is less than `s2`.
|
||||
*/
|
||||
int strcmp(const char *s1, const char *s2);
|
||||
__shared int strcmp(const char *s1, const char *s2);
|
||||
|
||||
/**
|
||||
* Copy a `NUL` terminated string from `src` to `dest`.
|
||||
|
@ -57,7 +57,7 @@ int strcmp(const char *s1, const char *s2);
|
|||
* @param src: The original string to copy from.
|
||||
* @returns A pointer to the destination string.
|
||||
*/
|
||||
char *strcpy(char *dest, const char *src);
|
||||
__shared char *strcpy(char *dest, const char *src);
|
||||
|
||||
/**
|
||||
* Copy a `NUL` terminated string from `src` to `dest`, but at most `n`
|
||||
|
@ -69,7 +69,7 @@ char *strcpy(char *dest, const char *src);
|
|||
* @param n: The amount of characters to copy at most.
|
||||
* @returns A pointer to the destination string.
|
||||
*/
|
||||
char *strncpy(char *dest, const char *src, size_t n);
|
||||
__shared char *strncpy(char *dest, const char *src, size_t n);
|
||||
|
||||
/**
|
||||
* Compute the length of the `NUL` terminated string `s`.
|
||||
|
@ -77,7 +77,7 @@ char *strncpy(char *dest, const char *src, size_t n);
|
|||
* @param s: The string.
|
||||
* @returns The length of `s` without the `NUL` terminator.
|
||||
*/
|
||||
size_t strlen(const char *s);
|
||||
__shared size_t strlen(const char *s);
|
||||
|
||||
/*
|
||||
* This file is part of Ardix.
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#if CONFIG_SCHED_MAXPROC < 128
|
||||
#define _PID_TYPE_ int8_t
|
||||
#elif CONFIG_SCHED_MAXPROC < 32767
|
||||
#elif CONFIG_SCHED_MAXPROC < 32768
|
||||
#define _PID_TYPE_ int16_t
|
||||
#else
|
||||
#define _PID_TYPE_ int32_t
|
||||
|
@ -16,10 +16,6 @@
|
|||
/** Process identifier. */
|
||||
typedef _PID_TYPE_ pid_t;
|
||||
|
||||
#ifndef __SIG_ATOMIC_TYPE__
|
||||
#define __SIG_ATOMIC_TYPE__ int
|
||||
#endif /* __SIG_ATOMIC_TYPE__ */
|
||||
|
||||
/** Simple atomic reference counter */
|
||||
typedef struct {
|
||||
int count;
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
* @param c: The character, cast to an `int`.
|
||||
* @returns A nonzero value if `c` is an alphabetic character, zero if not.
|
||||
*/
|
||||
int isalpha(int c);
|
||||
__const __shared int isalpha(int c);
|
||||
|
||||
/**
|
||||
* Return whether `c` is a control character.
|
||||
|
@ -19,7 +19,7 @@ int isalpha(int c);
|
|||
* @param c: The character, cast to an `int`.
|
||||
* @returns A nonzero value if `c` is a control character, zero if not.
|
||||
*/
|
||||
int iscntrl(int c);
|
||||
__const __shared int iscntrl(int c);
|
||||
|
||||
/**
|
||||
* Return whether `c` is a digit.
|
||||
|
@ -27,7 +27,7 @@ int iscntrl(int c);
|
|||
* @param c: The character, cast to an `int`.
|
||||
* @returns A nonzero value if `c` is a digit, zero if not.
|
||||
*/
|
||||
int isdigit(int c);
|
||||
__const __shared int isdigit(int c);
|
||||
|
||||
/**
|
||||
* Return whether `c` is a printable character except space.
|
||||
|
@ -36,7 +36,7 @@ int isdigit(int c);
|
|||
* @returns A nonzero value if `c` is a printable character and not space,
|
||||
* zero if not.
|
||||
*/
|
||||
int isgraph(int c);
|
||||
__const __shared int isgraph(int c);
|
||||
|
||||
/**
|
||||
* Return whether `c` is a lowercase letter.
|
||||
|
@ -44,7 +44,7 @@ int isgraph(int c);
|
|||
* @param c: The character, cast to an `int`.
|
||||
* @returns A nonzero value if `c` is lowercase, zero if not.
|
||||
*/
|
||||
int islower(int c);
|
||||
__const __shared int islower(int c);
|
||||
|
||||
/**
|
||||
* Return whether `c` is a printable character including space.
|
||||
|
@ -52,7 +52,7 @@ int islower(int c);
|
|||
* @param c: The character, cast to an `int`.
|
||||
* @returns A nonzero value if `c` is a printable character, zero if not.
|
||||
*/
|
||||
int isprint(int c);
|
||||
__const __shared int isprint(int c);
|
||||
|
||||
/**
|
||||
* Return whether `c` is a printable character
|
||||
|
@ -61,7 +61,7 @@ int isprint(int c);
|
|||
* @param c: The character, cast to an `int`.
|
||||
* @returns A nonzero value if `c` is a punctuation character, zero if not.
|
||||
*/
|
||||
int ispunct(int c);
|
||||
__const __shared int ispunct(int c);
|
||||
|
||||
/**
|
||||
* Return whether `c` is a white-space character.
|
||||
|
@ -71,7 +71,7 @@ int ispunct(int c);
|
|||
* @param c: The character, cast to an `int`.
|
||||
* @returns A nonzero value if `c` is a white-space character, zero if not.
|
||||
*/
|
||||
int isspace(int c);
|
||||
__const __shared int isspace(int c);
|
||||
|
||||
/**
|
||||
* Return whether `c` is an uppercase letter.
|
||||
|
@ -79,7 +79,7 @@ int isspace(int c);
|
|||
* @param c: The character, cast to an `int`.
|
||||
* @returns A nonzero value if `c` is uppercase, zero if not.
|
||||
*/
|
||||
int isupper(int c);
|
||||
__const __shared int isupper(int c);
|
||||
|
||||
/**
|
||||
* Return whether `c` is a hexadecimal digit.
|
||||
|
@ -88,7 +88,7 @@ int isupper(int c);
|
|||
* @param c: The character, cast to an `int`.
|
||||
* @returns A nonzero value if `c` is a blaank character, zero if not.
|
||||
*/
|
||||
int isxdigit(int c);
|
||||
__const __shared int isxdigit(int c);
|
||||
|
||||
/**
|
||||
* Return whether `c` is a 7-bit unsigned char.
|
||||
|
@ -96,7 +96,7 @@ int isxdigit(int c);
|
|||
* @param c: The character, cast to an `int`.
|
||||
* @returns A nonzero value if `c` is an ASCII character, zero if not.
|
||||
*/
|
||||
int isascii(int c);
|
||||
__const __shared int isascii(int c);
|
||||
|
||||
/**
|
||||
* Return whether `c` is a space or a tab character.
|
||||
|
@ -104,7 +104,7 @@ int isascii(int c);
|
|||
* @param c: The character, cast to an `int`.
|
||||
* @returns A nonzero value if `c` is a blank character, zero if not.
|
||||
*/
|
||||
int isblank(int c);
|
||||
__const __shared int isblank(int c);
|
||||
|
||||
/**
|
||||
* Check whether `c` is an alphanumeric character.
|
||||
|
@ -113,10 +113,7 @@ int isblank(int c);
|
|||
* @param c: The character, cast to an `int`.
|
||||
* @returns A nonzero value if the character is alphanumeric, zero if not.
|
||||
*/
|
||||
__always_inline int isalnum(int c)
|
||||
{
|
||||
return isalpha(c) || isdigit(c);
|
||||
}
|
||||
__const __shared int isalnum(int c);
|
||||
|
||||
/*
|
||||
* This file is part of Ardix.
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <toolchain.h>
|
||||
|
||||
#define EPERM 1
|
||||
#define ENOENT 2
|
||||
#define ESRCH 3
|
||||
|
@ -145,7 +147,7 @@
|
|||
* @param errnum: POSIX error number
|
||||
* @returns an immutable human-readable string briefly describing the error
|
||||
*/
|
||||
char *strerror(int errnum);
|
||||
__shared char *strerror(int errnum);
|
||||
|
||||
/* TODO: actually define errno */
|
||||
|
||||
|
|
|
@ -51,6 +51,16 @@
|
|||
#define __rodata __section(.rodata#)
|
||||
#endif
|
||||
|
||||
#ifndef __pure
|
||||
/** Declare a function is pure so gcc can do some common subexpression elimination. */
|
||||
#define __pure __attribute__((pure))
|
||||
#endif
|
||||
|
||||
#ifndef __const
|
||||
/** Like `__pure`, and the fuction does not access any memory except its stack. */
|
||||
#define __const __attribute__((const))
|
||||
#endif
|
||||
|
||||
#ifndef __user
|
||||
/** Denote a pointer to user space (this will be used for static code checks later) */
|
||||
#define __user
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
ssize_t read(int fildes, void *buf, size_t nbyte);
|
||||
ssize_t write(int fildes, const void *buf, size_t nbyte);
|
||||
__shared ssize_t read(int fildes, void *buf, size_t nbyte);
|
||||
__shared ssize_t write(int fildes, const void *buf, size_t nbyte);
|
||||
|
||||
/*
|
||||
* This file is part of Ardix.
|
||||
|
|
30
lib/ctype.c
30
lib/ctype.c
|
@ -2,72 +2,76 @@
|
|||
/* See the end of this file for copyright, license, and warranty information. */
|
||||
|
||||
#include <ctype.h>
|
||||
#include <toolchain.h>
|
||||
|
||||
__shared int isalpha(int c)
|
||||
int isalpha(int c)
|
||||
{
|
||||
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
|
||||
}
|
||||
|
||||
__shared int isblank(int c)
|
||||
int isblank(int c)
|
||||
{
|
||||
return c == ' ' || c == '\t';
|
||||
}
|
||||
|
||||
__shared int iscntrl(int c)
|
||||
int iscntrl(int c)
|
||||
{
|
||||
return c == 0x7F || (c >= 0 && c <= 0x1F);
|
||||
}
|
||||
|
||||
__shared int isdigit(int c)
|
||||
int isdigit(int c)
|
||||
{
|
||||
return c >= '0' && c <= '9';
|
||||
}
|
||||
|
||||
__shared int isgraph(int c)
|
||||
int isgraph(int c)
|
||||
{
|
||||
/* space *not* included */
|
||||
return c > 0x20 && c <= 0x7E;
|
||||
}
|
||||
|
||||
__shared int islower(int c)
|
||||
int islower(int c)
|
||||
{
|
||||
return c >= 'a' && c <= 'z';
|
||||
}
|
||||
|
||||
__shared int isprint(int c)
|
||||
int isprint(int c)
|
||||
{
|
||||
/* space *is* included */
|
||||
return c >= 0x20 && c <= 0x7E;
|
||||
}
|
||||
|
||||
__shared int ispunct(int c)
|
||||
int ispunct(int c)
|
||||
{
|
||||
return isprint(c) && !isalnum(c);
|
||||
}
|
||||
|
||||
__shared int isspace(int c)
|
||||
int isspace(int c)
|
||||
{
|
||||
return c == ' ' || (c >= '\n' && c <= '\r');
|
||||
}
|
||||
|
||||
__shared int isupper(int c)
|
||||
int isupper(int c)
|
||||
{
|
||||
return c >= 'A' && c <= 'Z';
|
||||
}
|
||||
|
||||
__shared int isxdigit(int c)
|
||||
int isxdigit(int c)
|
||||
{
|
||||
return (c >= '0' && c <= '9')
|
||||
|| (c >= 'A' && c <= 'F')
|
||||
|| (c >= 'a' && c <= 'f');
|
||||
}
|
||||
|
||||
__shared int isascii(int c)
|
||||
int isascii(int c)
|
||||
{
|
||||
return c & 0x7F;
|
||||
}
|
||||
|
||||
int isalnum(int c)
|
||||
{
|
||||
return isalpha(c) || isdigit(c);
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of Ardix.
|
||||
* Copyright (c) 2020, 2021 Felix Kopp <owo@fef.moe>.
|
||||
|
|
|
@ -103,7 +103,7 @@ __rodata static const char *error_messages[] = {
|
|||
[ESOCKTNOSUPPORT] "Socket type not supported",
|
||||
};
|
||||
|
||||
__shared char *strerror(int errnum)
|
||||
char *strerror(int errnum)
|
||||
{
|
||||
if (errnum < 0)
|
||||
errnum = -errnum;
|
||||
|
|
16
lib/string.c
16
lib/string.c
|
@ -8,7 +8,7 @@
|
|||
#include <stdbool.h>
|
||||
|
||||
#ifndef __HAVE_ASM_MEMCMP
|
||||
__shared int memcmp(const void *s1, const void *s2, size_t n)
|
||||
int memcmp(const void *s1, const void *s2, size_t n)
|
||||
{
|
||||
int delta = 0;
|
||||
|
||||
|
@ -23,7 +23,7 @@ __shared int memcmp(const void *s1, const void *s2, size_t n)
|
|||
#endif /* __HAVE_ASM_MEMCMP */
|
||||
|
||||
#ifndef __HAVE_ASM_MEMCPY
|
||||
__shared void *memcpy(void *dest, const void *src, size_t n)
|
||||
void *memcpy(void *dest, const void *src, size_t n)
|
||||
{
|
||||
uint8_t *tmp = (uint8_t *)dest;
|
||||
|
||||
|
@ -35,7 +35,7 @@ __shared void *memcpy(void *dest, const void *src, size_t n)
|
|||
#endif /* __HAVE_ASM_MEMCPY */
|
||||
|
||||
#ifndef __HAVE_ASM_MEMSET
|
||||
__shared void *memset(void *ptr, int c, size_t n)
|
||||
void *memset(void *ptr, int c, size_t n)
|
||||
{
|
||||
char *tmp = (char *)ptr;
|
||||
|
||||
|
@ -47,7 +47,7 @@ __shared void *memset(void *ptr, int c, size_t n)
|
|||
#endif /* __HAVE_ASM_MEMSET */
|
||||
|
||||
#ifndef __HAVE_ASM_MEMMOVE
|
||||
__shared void *memmove(void *dest, const void *src, size_t n)
|
||||
void *memmove(void *dest, const void *src, size_t n)
|
||||
{
|
||||
char *tmp = (char *)dest;
|
||||
const char *s = (const char *)src;
|
||||
|
@ -70,7 +70,7 @@ __shared void *memmove(void *dest, const void *src, size_t n)
|
|||
#endif /* __HAVE_ASM_MEMMOVE */
|
||||
|
||||
#ifndef __HAVE_ASM_STRCMP
|
||||
__shared int strcmp(const char *s1, const char *s2)
|
||||
int strcmp(const char *s1, const char *s2)
|
||||
{
|
||||
while (*s1++ == *s2++) {
|
||||
if (*s1 == '\0' || *s2 == '\0')
|
||||
|
@ -82,7 +82,7 @@ __shared int strcmp(const char *s1, const char *s2)
|
|||
#endif /* __HAVE_ASM_STRCMP */
|
||||
|
||||
#ifndef __HAVE_ASM_STRCPY
|
||||
__shared char *strcpy(char *dest, const char *src)
|
||||
char *strcpy(char *dest, const char *src)
|
||||
{
|
||||
char *tmp = dest;
|
||||
|
||||
|
@ -94,7 +94,7 @@ __shared char *strcpy(char *dest, const char *src)
|
|||
#endif /* __HAVE_ASM_STRCPY */
|
||||
|
||||
#ifndef __HAVE_ASM_STRNCPY
|
||||
__shared char *strncpy(char *dest, const char *src, size_t n)
|
||||
char *strncpy(char *dest, const char *src, size_t n)
|
||||
{
|
||||
char *tmp = dest;
|
||||
|
||||
|
@ -108,7 +108,7 @@ __shared char *strncpy(char *dest, const char *src, size_t n)
|
|||
#endif /* __HAVE_ASM_STRNCPY */
|
||||
|
||||
#ifndef __HAVE_ASM_STRLEN
|
||||
__shared size_t strlen(const char *s)
|
||||
size_t strlen(const char *s)
|
||||
{
|
||||
const char *tmp = s;
|
||||
|
||||
|
|
|
@ -1,19 +1,16 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* See the end of this file for copyright, license, and warranty information. */
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <ardix/syscall.h>
|
||||
|
||||
#include <toolchain.h>
|
||||
#include <unistd.h>
|
||||
|
||||
__shared ssize_t read(int fildes, void *buf, size_t nbyte)
|
||||
ssize_t read(int fildes, void *buf, size_t nbyte)
|
||||
{
|
||||
return syscall(SYSCALL_READ, (sysarg_t)fildes, (sysarg_t)buf, (sysarg_t)nbyte);
|
||||
}
|
||||
|
||||
__shared ssize_t write(int fildes, const void *buf, size_t nbyte)
|
||||
ssize_t write(int fildes, const void *buf, size_t nbyte)
|
||||
{
|
||||
return syscall(SYSCALL_WRITE, (sysarg_t)fildes, (sysarg_t)buf, (sysarg_t)nbyte);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue