* Makefile.am: Use -ffreestanding and remove -nostdinc since we are including stdint.h. * i386/i386/xen.h: Use uint64_t. * i386/include/mach/i386/machine_types.defs: Use uint32_t and int32_t. * i386/include/mach/i386/vm_types.h: Remove definitions of int*, uint*, unsigned* and signed* types. * i386/xen/xen.c: Use uint64_t. * include/device/device_types.defs: Use uint32_t. * include/mach/std_types.defs: Use POSIX types. * include/mach/std_types.h: Include stdint.h. * include/sys/types.h: Include stdint.h. * ipc/ipc_kmsg.c: Use uint64_t. * kern/exception.c: Use uint32_t. * xen/block.c: Use uint64_t. * xen/net.c: Do not use removed unsigned*_t types. * xen/ring.h: Use uint32_t instead. * xen/store.c: Use uint32_t. * xen/store.h: Use uint32_t. * xen/time.c: Use POSIX types only. * xen/time.h: Use uint64_t. ---
On Sun, Mar 20, 2016 at 11:55:10AM +0100, Thomas Schwinge wrote: > Hi! > > On Sun, 20 Mar 2016 00:30:30 +0100, Samuel Thibault <samuel.thiba...@gnu.org> > wrote: > > Flávio Cruz, on Sat 19 Mar 2016 14:20:34 +0100, wrote: > > > We already include mach/std_types.h in the stubs which provides uint32_t. > > > Should gnumach perhaps just rely on stdint.h? > > Relying on existing, standard header files generally makes sense. As I > understand it, <stdint.h> is part of the freestanding C implementation > (see <https://gcc.gnu.org/PR448>, for example). (I'm aware that we > currently don't built GNU Mach with -ffreestanding; but we should -- at > least conceptually.) I guess that makes sense since intN_t and uintN_t are part of the C99 standard. I've tried to compile GNU Mach using stdint.h and -ffreestanding and so far so good, however I'm not sure if removing -nostdinc is a good idea since we may include some files from /usr/include that should not included (things like sys/types.h and sys/time.h which are implemented in gnumach/include). I'm attaching the patch below. diff --git a/Makefile.am b/Makefile.am index 1c1bfff..e9c8fec 100644 --- a/Makefile.am +++ b/Makefile.am @@ -42,7 +42,7 @@ AM_LDFLAGS = # AM_CPPFLAGS += \ - -nostdinc -imacros config.h + -ffreestanding -imacros config.h AM_CPPFLAGS += \ -I$(systype) \ diff --git a/i386/i386/xen.h b/i386/i386/xen.h index c681187..49b0d52 100644 --- a/i386/i386/xen.h +++ b/i386/i386/xen.h @@ -356,8 +356,8 @@ _hypcall2(int, set_debugreg, int, reg, unsigned long, value); _hypcall1(unsigned long, get_debugreg, int, reg); /* x86-specific */ -MACH_INLINE unsigned64_t hyp_cpu_clock(void) { - unsigned64_t tsc; +MACH_INLINE uint64_t hyp_cpu_clock(void) { + uint64_t tsc; asm volatile("rdtsc":"=A"(tsc)); return tsc; } diff --git a/i386/include/mach/i386/machine_types.defs b/i386/include/mach/i386/machine_types.defs index 6ac17cf..6ff93db 100755 --- a/i386/include/mach/i386/machine_types.defs +++ b/i386/include/mach/i386/machine_types.defs @@ -47,7 +47,7 @@ * a port in user space as an integer and * in kernel space as a pointer. */ -type natural_t = unsigned32; +type natural_t = uint32_t; /* * An integer_t is the signed counterpart @@ -56,6 +56,6 @@ type natural_t = unsigned32; * other types in a machine-independent * way. */ -type integer_t = int32; +type integer_t = int32_t; #endif /* _MACHINE_MACHINE_TYPES_DEFS_ */ diff --git a/i386/include/mach/i386/vm_types.h b/i386/include/mach/i386/vm_types.h index 4a58b1c..4e259f9 100644 --- a/i386/include/mach/i386/vm_types.h +++ b/i386/include/mach/i386/vm_types.h @@ -59,16 +59,6 @@ typedef unsigned int natural_t; */ typedef int integer_t; -#ifndef _POSIX_SOURCE - -/* - * An int32 is an integer that is at least 32 bits wide - */ -typedef int int32; -typedef unsigned int uint32; - -#endif /* _POSIX_SOURCE */ - /* * A vm_offset_t is a type-neutral pointer, * e.g. an offset into a virtual memory space. @@ -92,20 +82,6 @@ typedef unsigned long phys_addr_t; */ typedef natural_t vm_size_t; -/* - * These types are _exactly_ as wide as indicated in their names. - */ -typedef signed char signed8_t; -typedef signed short signed16_t; -typedef signed int signed32_t; -typedef signed long long signed64_t; -typedef unsigned char unsigned8_t; -typedef unsigned short unsigned16_t; -typedef unsigned int unsigned32_t; -typedef unsigned long long unsigned64_t; -typedef float float32_t; -typedef double float64_t; - #endif /* __ASSEMBLER__ */ /* diff --git a/i386/xen/xen.c b/i386/xen/xen.c index a46ee2c..44d37e6 100644 --- a/i386/xen/xen.c +++ b/i386/xen/xen.c @@ -46,7 +46,7 @@ void hyp_failsafe_c_callback(struct failsafe_callback_regs *regs) { extern void return_to_iret; -void hypclock_machine_intr(int old_ipl, void *ret_addr, struct i386_interrupt_state *regs, unsigned64_t delta) { +void hypclock_machine_intr(int old_ipl, void *ret_addr, struct i386_interrupt_state *regs, uint64_t delta) { if (ret_addr == &return_to_iret) { clock_interrupt(delta/1000, /* usec per tick */ (regs->efl & EFL_VM) || /* user mode */ diff --git a/include/device/device_types.defs b/include/device/device_types.defs index 49cc271..e97d89c 100644 --- a/include/device/device_types.defs +++ b/include/device/device_types.defs @@ -43,9 +43,9 @@ DEVICE_IMPORTS #endif -type recnum_t = unsigned32; -type dev_mode_t = unsigned32; -type dev_flavor_t = unsigned32; +type recnum_t = uint32_t; +type dev_mode_t = uint32_t; +type dev_flavor_t = uint32_t; type dev_name_t = (MACH_MSG_TYPE_STRING_C, 8*128); type dev_status_t = array[*:1024] of int; type io_buf_ptr_t = ^array[] of MACH_MSG_TYPE_INTEGER_8; diff --git a/include/mach/std_types.defs b/include/mach/std_types.defs index a1f156d..5d95ab4 100644 --- a/include/mach/std_types.defs +++ b/include/mach/std_types.defs @@ -33,12 +33,12 @@ type char = MACH_MSG_TYPE_CHAR; type short = MACH_MSG_TYPE_INTEGER_16; type int = MACH_MSG_TYPE_INTEGER_32; -type int32 = MACH_MSG_TYPE_INTEGER_32; -type int64 = MACH_MSG_TYPE_INTEGER_64; +type int32_t = MACH_MSG_TYPE_INTEGER_32; +type int64_t = MACH_MSG_TYPE_INTEGER_64; type boolean_t = MACH_MSG_TYPE_BOOLEAN; type unsigned = MACH_MSG_TYPE_INTEGER_32; -type unsigned32 = MACH_MSG_TYPE_INTEGER_32; -type unsigned64 = MACH_MSG_TYPE_INTEGER_64; +type uint32_t = MACH_MSG_TYPE_INTEGER_32; +type uint64_t = MACH_MSG_TYPE_INTEGER_64; /* Get the definitions for natural_t and integer_t */ #include <mach/machine/machine_types.defs> diff --git a/include/mach/std_types.h b/include/mach/std_types.h index f78e236..553bd61 100644 --- a/include/mach/std_types.h +++ b/include/mach/std_types.h @@ -37,6 +37,7 @@ #include <mach/kern_return.h> #include <mach/port.h> #include <mach/machine/vm_types.h> +#include <stdint.h> typedef vm_offset_t pointer_t; typedef vm_offset_t vm_address_t; diff --git a/include/sys/types.h b/include/sys/types.h index 19e7b24..d576cc2 100644 --- a/include/sys/types.h +++ b/include/sys/types.h @@ -27,6 +27,7 @@ #define _MACH_SA_SYS_TYPES_H_ #include <mach/machine/vm_types.h> +#include <stdint.h> #ifndef _SIZE_T #define _SIZE_T @@ -58,20 +59,6 @@ typedef unsigned int time_t; #define RAND_MAX 0x7fffffff -/* Posix types */ -typedef signed8_t int8_t; -typedef unsigned8_t uint8_t; -typedef unsigned8_t u_int8_t; -typedef signed16_t int16_t; -typedef unsigned16_t uint16_t; -typedef unsigned16_t u_int16_t; -typedef signed32_t int32_t; -typedef unsigned32_t uint32_t; -typedef unsigned32_t u_int32_t; -typedef signed64_t int64_t; -typedef unsigned64_t uint64_t; -typedef unsigned64_t u_int64_t; - /* Symbols not allowed by POSIX */ #ifndef _POSIX_SOURCE diff --git a/ipc/ipc_kmsg.c b/ipc/ipc_kmsg.c index 5076809..21667ca 100644 --- a/ipc/ipc_kmsg.c +++ b/ipc/ipc_kmsg.c @@ -1307,7 +1307,7 @@ ipc_kmsg_copyin_body( mach_msg_type_number_t number; boolean_t is_inline, longform, dealloc, is_port; vm_offset_t data; - unsigned64_t length; + uint64_t length; kern_return_t kr; type = (mach_msg_type_long_t *) saddr; @@ -1358,7 +1358,7 @@ ipc_kmsg_copyin_body( /* calculate length of data in bytes, rounding up */ - length = (((unsigned64_t) number * size) + 7) >> 3; + length = (((uint64_t) number * size) + 7) >> 3; if (is_inline) { vm_size_t amount; @@ -2351,7 +2351,7 @@ ipc_kmsg_copyout_body( mach_msg_type_size_t size; mach_msg_type_number_t number; boolean_t is_inline, longform, is_port; - unsigned64_t length; + uint64_t length; vm_offset_t addr; type = (mach_msg_type_long_t *) saddr; @@ -2382,7 +2382,7 @@ ipc_kmsg_copyout_body( /* calculate length of data in bytes, rounding up */ - length = (((unsigned64_t) number * size) + 7) >> 3; + length = (((uint64_t) number * size) + 7) >> 3; is_port = MACH_MSG_TYPE_PORT_ANY(name); diff --git a/kern/exception.c b/kern/exception.c index 63a63d6..246c141 100644 --- a/kern/exception.c +++ b/kern/exception.c @@ -757,7 +757,7 @@ exception_raise( /* Macro used by MIG to cleanly check the type. */ #define BAD_TYPECHECK(type, check) unlikely (({\ - union { mach_msg_type_t t; unsigned32_t w; } _t, _c;\ + union { mach_msg_type_t t; uint32_t w; } _t, _c;\ _t.t = *(type); _c.t = *(check);_t.w != _c.w; })) /* Type descriptor for the return code. */ diff --git a/xen/block.c b/xen/block.c index d98b31e..46df358 100644 --- a/xen/block.c +++ b/xen/block.c @@ -489,7 +489,7 @@ device_read (void *d, ipc_port_t reply_port, req->operation = BLKIF_OP_READ; req->nr_segments = nbpages; req->handle = bd->handle; - req->id = (unsigned64_t) (unsigned long) &err; /* pointer on the stack */ + req->id = (uint64_t) (unsigned long) &err; /* pointer on the stack */ req->sector_number = bn + offset / 512; for (i = 0; i < nbpages; i++) { req->seg[i].gref = gref[i] = hyp_grant_give(bd->domid, atop(pages[i]->phys_addr), 0); @@ -641,7 +641,7 @@ device_write(void *d, ipc_port_t reply_port, req->operation = BLKIF_OP_WRITE; req->nr_segments = nbpages; req->handle = bd->handle; - req->id = (unsigned64_t) (unsigned long) &err; /* pointer on the stack */ + req->id = (uint64_t) (unsigned long) &err; /* pointer on the stack */ req->sector_number = bn + i*PAGE_SIZE / 512; for (j = 0; j < nbpages; j++) { diff --git a/xen/net.c b/xen/net.c index 5564365..a5db456 100644 --- a/xen/net.c +++ b/xen/net.c @@ -119,10 +119,10 @@ static void enqueue_rx_buf(struct net_data *nd, int number) { } static int recompute_checksum(void *data, int len) { - unsigned16_t *header16 = data; - unsigned8_t *header8 = data; + uint16_t *header16 = data; + uint8_t *header8 = data; unsigned length, i; - unsigned32_t checksum = 0; + uint32_t checksum = 0; /* IPv4 header length */ length = (header8[0] & 0xf) * 4; diff --git a/xen/public/elfstructs.h b/xen/public/elfstructs.h index 77362f3..65d5345 100644 --- a/xen/public/elfstructs.h +++ b/xen/public/elfstructs.h @@ -353,7 +353,7 @@ typedef struct { #define ELF64_R_SYM(info) ((info) >> 32) #define ELF64_R_TYPE(info) ((info) & 0xFFFFFFFF) -#define ELF64_R_INFO(s,t) (((s) << 32) + (u_int32_t)(t)) +#define ELF64_R_INFO(s,t) (((s) << 32) + (uint32_t)(t)) /* Program Header */ typedef struct { diff --git a/xen/ring.h b/xen/ring.h index c5c2fe3..1ac8b37 100644 --- a/xen/ring.h +++ b/xen/ring.h @@ -19,7 +19,7 @@ #ifndef XEN_RING_H #define XEN_RING_H -typedef unsigned32_t hyp_ring_pos_t; +typedef uint32_t hyp_ring_pos_t; #define hyp_ring_idx(ring, pos) (((unsigned)(pos)) & (sizeof(ring)-1)) #define hyp_ring_cell(ring, pos) (ring)[hyp_ring_idx((ring), (pos))] diff --git a/xen/store.c b/xen/store.c index 739dc36..659a70c 100644 --- a/xen/store.c +++ b/xen/store.c @@ -46,7 +46,7 @@ struct store_req { }; /* Send a request */ -static void store_put(hyp_store_transaction_t t, unsigned32_t type, struct store_req *req, unsigned nr_reqs) { +static void store_put(hyp_store_transaction_t t, uint32_t type, struct store_req *req, unsigned nr_reqs) { struct xsd_sockmsg head = { .type = type, .req_id = 0, @@ -105,7 +105,7 @@ static const char *errors[] = { static struct xsd_sockmsg head; const char *hyp_store_error; -static void *store_put_wait(hyp_store_transaction_t t, unsigned32_t type, struct store_req *req, unsigned nr_reqs) { +static void *store_put_wait(hyp_store_transaction_t t, uint32_t type, struct store_req *req, unsigned nr_reqs) { unsigned len; const char **error; void *data; diff --git a/xen/store.h b/xen/store.h index ae236eb..6bb78ea 100644 --- a/xen/store.h +++ b/xen/store.h @@ -21,7 +21,7 @@ #include <machine/xen.h> #include <xen/public/io/xenbus.h> -typedef unsigned32_t hyp_store_transaction_t; +typedef uint32_t hyp_store_transaction_t; #define hyp_store_state_unknown "0" #define hyp_store_state_initializing "1" diff --git a/xen/time.c b/xen/time.c index 4ebe91f..3ad73e2 100644 --- a/xen/time.c +++ b/xen/time.c @@ -28,14 +28,14 @@ #include "time.h" #include "store.h" -static unsigned64_t lastnsec; +static uint64_t lastnsec; /* 2^64 nanoseconds ~= 500 years */ -static unsigned64_t hyp_get_stime(void) { - unsigned32_t version; - unsigned64_t cpu_clock, last_cpu_clock, delta, system_time; - unsigned64_t delta_high, delta_low; - unsigned32_t mul; +static uint64_t hyp_get_stime(void) { + uint32_t version; + uint64_t cpu_clock, last_cpu_clock, delta, system_time; + uint64_t delta_high, delta_low; + uint32_t mul; signed8_t shift; volatile struct vcpu_time_info *time = &hyp_shared_info.vcpu_info[0].time; @@ -56,14 +56,14 @@ static unsigned64_t hyp_get_stime(void) { else delta <<= shift; delta_high = delta >> 32; - delta_low = (unsigned32_t) delta; - return system_time + ((delta_low * (unsigned64_t) mul) >> 32) - + (delta_high * (unsigned64_t) mul); + delta_low = (uint32_t) delta; + return system_time + ((delta_low * (uint64_t) mul) >> 32) + + (delta_high * (uint64_t) mul); } -unsigned64_t hyp_get_time(void) { - unsigned32_t version; - unsigned32_t sec, nsec; +uint64_t hyp_get_time(void) { + uint32_t version; + uint32_t sec, nsec; do { version = hyp_shared_info.wc_version; @@ -77,7 +77,7 @@ unsigned64_t hyp_get_time(void) { } static void hypclock_intr(int unit, int old_ipl, void *ret_addr, struct i386_interrupt_state *regs) { - unsigned64_t nsec, delta; + uint64_t nsec, delta; if (!lastnsec) return; @@ -116,7 +116,7 @@ int readtodc(tp) u_int *tp; { - unsigned64_t t = hyp_get_time(); + uint64_t t = hyp_get_time(); u_int n = t / 1000000000; *tp = n; diff --git a/xen/time.h b/xen/time.h index 8c8bc53..cf28720 100644 --- a/xen/time.h +++ b/xen/time.h @@ -20,6 +20,6 @@ #define XEN_TIME_H #include <mach/mach_types.h> -unsigned64_t hyp_get_time(void); +uint64_t hyp_get_time(void); #endif /* XEN_TIME_H */ -- 2.7.0