Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust sytem headers #8

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
[submodule "libcxx"]
path = libcxx
url = https://github.com/CTSRD-CHERI/libcxx.git
[submodule "mbedtls"]
path = mbedtls
url = https://github.com/ARMmbed/mbedtls.git
1 change: 1 addition & 0 deletions boot/src/boot/boot_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "boot/boot_info.h"
#include "object.h"
#include "string.h"
#include "strings.h"
#include "uart.h"
#include "elf.h"
#include "utils.h"
Expand Down
1 change: 1 addition & 0 deletions cherios/core/memmgt/src/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "syscalls.h"
#include "stdio.h"
#include "string.h"
#include "strings.h"
#include "pmem.h"


Expand Down
1 change: 1 addition & 0 deletions cherios/core/memmgt/src/pmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "mmap.h"
#include "math.h"
#include "object.h"
#include "strings.h"

page_t* book;

Expand Down
1 change: 1 addition & 0 deletions cherios/core/namespace/src/namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "stdio.h"
#include "string.h"
#include "crt.h"
#include "strings.h"

typedef struct {
void * act_reference;
Expand Down
1 change: 1 addition & 0 deletions cherios/kernel/include/klib.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "math.h"
#include "sched.h"
#include "string.h"
#include "strings.h"
#include "kutils.h"
#include "syscalls.h"

Expand Down
1 change: 1 addition & 0 deletions cherios/system/dylink/src/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "misc.h"
#include "namespace.h"
#include "macroutils.h"
#include "strings.h"

// We batch symbol exchnage because otherwise there would be far too many domain crossings
#define SYMBOL_EXCHANGE_MAX 0x20
Expand Down
1 change: 1 addition & 0 deletions cherios/system/libsocket/src/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <queue.h>
#include "object.h"
#include "string.h"
#include "strings.h"
#include "nano/nanokernel.h"
#include "assert.h"
#include "cheric.h"
Expand Down
1 change: 1 addition & 0 deletions cherios/system/lwip/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "cheristd.h"
#include "cheric.h"
#include "stdlib.h"
#include "strings.h"
#include "assert.h"
#include "mman.h"
#include "misc.h"
Expand Down
1 change: 1 addition & 0 deletions cherios/system/lwip/src/virtio/virtio_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "lwip_driver.h"
#include "mman.h"
#include "malta_virtio_mmio.h"
#include "strings.h"

static void alloc_recv(net_session* session) {

Expand Down
1 change: 1 addition & 0 deletions cherios/system/type_manager/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "stdlib.h"
#include "lists.h"
#include "string.h"
#include "strings.h"
#include "type_manager.h"
#include "misc.h"
#include "namespace.h"
Expand Down
1 change: 1 addition & 0 deletions churn/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "cheric.h"
#include "mman.h"
#include "string.h"
#include "strings.h"
#include "assert.h"
#include "stdio.h"
#include "syscalls.h"
Expand Down
1 change: 1 addition & 0 deletions elf/src/cprogram.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "cprogram.h"
#include "queue.h"
#include "string.h"
#include "strings.h"
#include "syscalls.h"
#include "mman.h"
#include "assert.h"
Expand Down
1 change: 1 addition & 0 deletions elf/src/elf_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "cheric.h"
#include "math.h"
#include "string.h"
#include "strings.h"
#include "elf.h"
#include "nano/nanokernel.h"
#include "mman.h"
Expand Down
1 change: 1 addition & 0 deletions fs_test/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "assert.h"
#include "stdio.h"
#include "string.h"
#include "strings.h"
#include "aes.h"

#define BIG_SIZE 0x1000
Expand Down
2 changes: 1 addition & 1 deletion include/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ __asm__ __volatile__ ( \
SANE_ASM \
"1:" \
LOADL(type) " %[out], %[ptr] \n" \
ADD(type, val_type)" %[add], %[out], %[v] \n" \
ASM_ADD(type, val_type)" %[add], %[out], %[v] \n" \
STOREC(type) " %[tmp], %[add], %[ptr] \n" \
"beqz %[tmp], 1b \n" \
"nop \n" \
Expand Down
24 changes: 12 additions & 12 deletions include/cheric.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,17 @@ static inline precision_rounded_length round_cheri_length(size_t length) {
#define OUT_32i "i"
#define OUT_64i "i"

#define ADD_8_16i "daddiu"
#define ADD_16_16i "daddiu"
#define ADD_32_16i "daddiu"
#define ADD_64_16i "daddiu"
#define ADD_c_16i "cincoffset"

#define ADD_8_64 "daddu"
#define ADD_16_64 "daddu"
#define ADD_32_64 "daddu"
#define ADD_64_64 "daddu"
#define ADD_c_64 "cincoffset"
#define ASM_ADD_8_16i "daddiu"
#define ASM_ADD_16_16i "daddiu"
#define ASM_ADD_32_16i "daddiu"
#define ASM_ADD_64_16i "daddiu"
#define ASM_ADD_c_16i "cincoffset"

#define ASM_ADD_8_64 "daddu"
#define ASM_ADD_16_64 "daddu"
#define ASM_ADD_32_64 "daddu"
#define ASM_ADD_64_64 "daddu"
#define ASM_ADD_c_64 "cincoffset"

#define CTYPE_8 uint8_t
#define CTYPE_16 uint16_t
Expand All @@ -145,7 +145,7 @@ static inline precision_rounded_length round_cheri_length(size_t length) {

#define BNE(type, a, b, label,tmp) BNE_ ## type(a,b,label,tmp)

#define ADD(type, val_type) ADD_ ## type ## _ ## val_type
#define ASM_ADD(type, val_type) ASM_ADD_ ## type ## _ ## val_type

#define LOADL(type) "cll" SUF_ ## type
#define LOAD(type) "cl" SUF_ ## type
Expand Down
51 changes: 2 additions & 49 deletions include/mips.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@

#ifndef __ASSEMBLY__

#include <stdint.h>

/*
* Provide more convenient names for useful qualifiers from gcc/clang.
*/
Expand All @@ -97,55 +99,6 @@ typedef unsigned long size_t;

typedef long off_t;

/*
* Useful integer type names that we can't pick up from the compile-time
* environment.
*/
typedef char int8_t;
typedef unsigned char u_char;
typedef unsigned char uint8_t;
typedef short int16_t;
typedef unsigned short u_short;
typedef unsigned short uint16_t;
typedef int int32_t;
typedef unsigned int u_int;
typedef unsigned int uint32_t;
typedef long intmax_t;
typedef long quad_t;
typedef long ptrdiff_t;
typedef long int64_t;
typedef unsigned long u_long;
typedef unsigned long uint64_t;
typedef unsigned long uintmax_t;
typedef unsigned long u_quad_t;
typedef __uintcap_t uintptr_t;
//typedef unsigned long uintptr_t;
typedef __intcap_t intptr_t;
typedef unsigned long caddr_t;

typedef u_long ulong;
typedef u_char uchar;
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef uint16_t __u16;
typedef uint32_t __u32;
typedef uint8_t u_int8_t;
typedef uint16_t u_int16_t;
typedef uint32_t u_int32_t;
typedef uint64_t u_int64_t;

#define define_intypes(size) \
typedef int ## size ## _t int_least ## size ## _t; \
typedef uint ## size ## _t uint_least ## size ## _t; \
typedef int ## size ## _t int_fast ## size ## _t; \
typedef uint ## size ## _t uint_fast ## size ## _t;

#define INT_SIZES(ITEM) ITEM(8) ITEM(16) ITEM(32) ITEM(64)

INT_SIZES(define_intypes)

#define NBBY 8 /* Number of bits per byte. */
#ifdef __cplusplus
#define NULL nullptr
Expand Down
53 changes: 53 additions & 0 deletions include/stdint.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,59 @@
#ifndef _MACHINE__STDINT_H_
#define _MACHINE__STDINT_H_

/*
* Useful integer type names that we can't pick up from the compile-time
* environment.
*/
typedef char int8_t;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clang (and I believe modern GCC) defines all of these for you. You get macros like __UINT8_TYPE__, and even the __UINT_LEAST16_TYPE__, __UINT_FAST32_TYPE__ etc. Given this header is wrong for 32-bit systems I would suggest just using all those; CheriOS would conceivably be highly useful for RV32 CHERI-RISC-V given its utility in embedded systems, once the issue of type bits is addressed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this just works, seconded.

Copy link
Member

@arichardson arichardson Jun 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just do #include_next <stdint.h> to pick up the compiler-provided one? (https://github.com/CTSRD-CHERI/llvm-project/blob/master/clang/lib/Headers/stdint.h)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that works if we get rid of -nostdinc. Are we going to have -ibuiltininc soon on CTSRD-CHERI/llvm-project?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently it's Darwin-only upstream.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird for that to be OS-specific. Would it be easy to add to our frontend? I feel a little jittery about removing -nostdinc from cherios. It's probably fine for my segregated build environment where the cherios builds can't see the mainline/cheribsd builds and their sysroots, but...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our usual "hack" is --sysroot=/no/such/path...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And yeah, well, -nostdinc is already OS-specific, don't ask me why. There are some really bad decisions in the structuring of Clang's drivers. And no, no reason not to add it to the FreeBSD driver, though it's not strictly required and does diverge from upstream. But when Lawrence adds a CheriOS triple and driver, that driver can always support -ibuiltininc :)

typedef unsigned char u_char;
typedef unsigned char uint8_t;
typedef short int16_t;
typedef unsigned short u_short;
typedef unsigned short uint16_t;
typedef int int32_t;
typedef unsigned int u_int;
typedef unsigned int uint32_t;
typedef long intmax_t;
typedef long quad_t;
typedef long ptrdiff_t;
typedef long int64_t;
typedef unsigned long u_long;
typedef unsigned long uint64_t;
typedef unsigned long uintmax_t;
typedef unsigned long u_quad_t;
typedef __uintcap_t uintptr_t;
//typedef unsigned long uintptr_t;
typedef __intcap_t intptr_t;
typedef unsigned long caddr_t;

typedef u_long ulong;
typedef u_char uchar;
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef uint16_t __u16;
typedef uint32_t __u32;
typedef uint8_t u_int8_t;
typedef uint16_t u_int16_t;
typedef uint32_t u_int32_t;
typedef uint64_t u_int64_t;

#define define_intypes(size) \
typedef int ## size ## _t int_least ## size ## _t; \
typedef uint ## size ## _t uint_least ## size ## _t; \
typedef int ## size ## _t int_fast ## size ## _t; \
typedef uint ## size ## _t uint_fast ## size ## _t;

#define INT_SIZES(ITEM) ITEM(8) ITEM(16) ITEM(32) ITEM(64)

INT_SIZES(define_intypes)

#undef define_inttypes
#undef INT_SIZES


#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS)

#define INT8_C(c) (c)
Expand Down
3 changes: 3 additions & 0 deletions include/stdlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ static inline void * calloc_debug(size_t n, size_t s) {
void abort(void) __dead2;
void exit(int status) __dead2;

#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1

char * itoa ( int value, char * str, int base );
int atoi(const char* str);

Expand Down
3 changes: 1 addition & 2 deletions include/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include "locale.h"

__BEGIN_DECLS
void bzero(void *, size_t);
void * memcpy(void *dest, const void *src, size_t n);
void * memmove ( void * destination, const void * source, size_t num );
void * memset(void *, int, size_t);
Expand All @@ -56,7 +55,7 @@ char * strncpy(char * dest,const char *src,size_t count);
char * strstr(const char *s, const char *find);
char *strpbrk(const char *str1, const char *str2);

int memcmp ( const char * ptr1, const char * ptr2, size_t num );
int memcmp ( const void * ptr1, const void * ptr2, size_t num );

#define strcoll strcmp
#define strxfrm strncpy
Expand Down
42 changes: 42 additions & 0 deletions include/strings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*-
* Copyright (c) 2016 Robert N. M. Watson
* All rights reserved.
*
* This software was developed by SRI International and the University of
* Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
* ("CTSRD"), as part of the DARPA CRASH research programme.
*
* 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.
*/

#ifndef __STRINGS_H__
#define __STRINGS_H__

#include <cdefs.h>
#include "mips.h"

__BEGIN_DECLS
void bzero(void *, size_t);

__END_DECLS

#endif /* !__STRINGS_H__ */
1 change: 1 addition & 0 deletions libcrt/crtbeginC.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "mips.h"
#include "cheric.h"
#include "string.h"
#include "strings.h"
#include "dylink.h"
#include "crt.h"

Expand Down
1 change: 1 addition & 0 deletions libuser/src/dedup.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "nano/usernano.h"
#include "stdlib.h"
#include "crt.h"
#include "strings.h"

static act_kt dedup_service = NULL;

Expand Down
1 change: 1 addition & 0 deletions mbedtls
Submodule mbedtls added at a7f6d2
1 change: 1 addition & 0 deletions socket_test/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "assert.h"
#include "stdio.h"
#include "string.h"
#include "strings.h"
#include "capmalloc.h"

#define DATA_SIZE 0x800
Expand Down
1 change: 1 addition & 0 deletions unaligned_test/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "cheric.h"
#include "assert.h"
#include "string.h"
#include "strings.h"
#include "stdio.h"

int main(__unused register_t arg,__unused capability carg) {
Expand Down