diff --git a/amd64/include/ape/_apetypes.h b/mips64/include/ape/_apetypes.h new file mode 100644 index 0000000..6d8b9af --- /dev/null +++ b/amd64/include/ape/_apetypes.h @@ -0,0 +1,3 @@ +#ifndef _BITS64 +#define _BITS64 +#endif diff --git a/mips64/include/ape/_apetypes.h b/mips64/include/ape/_apetypes.h new file mode 100644 index 0000000..6d8b9af --- /dev/null +++ b/mips64/include/ape/_apetypes.h @@ -0,0 +1,3 @@ +#ifndef _BITS64 +#define _BITS64 +#endif diff --git a/power64/include/ape/_apetypes.h b/power64/include/ape/_apetypes.h new file mode 100644 index 0000000..6d8b9af --- /dev/null +++ b/power64/include/ape/_apetypes.h @@ -0,0 +1,3 @@ +#ifndef _BITS64 +#define _BITS64 +#endif diff --git a/spim64/include/ape/_apetypes.h b/spim64/include/ape/_apetypes.h new file mode 100644 index 0000000..6d8b9af --- /dev/null +++ b/spim64/include/ape/_apetypes.h @@ -0,0 +1,3 @@ +#ifndef _BITS64 +#define _BITS64 +#endif diff --git a/sys/include/ape/inttypes.h b/sys/include/ape/inttypes.h index 55725d5..38cfcd0 100644 --- a/sys/include/ape/inttypes.h +++ b/sys/include/ape/inttypes.h @@ -5,9 +5,15 @@ #ifndef _INTTYPES_H_ #define _INTTYPES_H_ 1 +#include "_apetypes.h" + +#ifdef _BITS64 +typedef long long _intptr_t; +typedef unsigned long long _uintptr_t; +#else typedef int _intptr_t; typedef unsigned int _uintptr_t; - +#endif typedef char int8_t; typedef short int16_t; diff --git a/sys/include/ape/stddef.h b/sys/include/ape/stddef.h index 713f9fc..19b9a6d 100644 --- a/sys/include/ape/stddef.h +++ b/sys/include/ape/stddef.h @@ -12,14 +12,20 @@ #define offsetof(ty,mem) ((size_t) &(((ty *)0)->mem)) #endif +#include "_apetypes.h" + +#ifdef _BITS64 +typedef long long ptrdiff_t; +#else typedef long ptrdiff_t; +#endif #ifndef _SIZE_T #define _SIZE_T -typedef unsigned long size_t; +typedef unsigned long size_t; /* even on 64-bit systems; see read(2) */ #endif #ifndef _WCHAR_T #define _WCHAR_T -typedef unsigned short wchar_t; +typedef unsigned long wchar_t; #endif #endif /* __STDDEF_H */ diff --git a/sys/include/ape/unistd.h b/sys/include/ape/unistd.h index ae78fec..758213e 100644 --- a/sys/include/ape/unistd.h +++ b/sys/include/ape/unistd.h @@ -15,7 +15,7 @@ #ifndef _SIZE_T #define _SIZE_T -typedef unsigned long size_t; +typedef unsigned long size_t; /* even on 64-bit systems; see read(2) */ #endif #ifndef _SSIZE_T #define _SSIZE_T diff --git a/sys/src/ape/lib/ap/gen/memmove.c b/sys/src/ape/lib/ap/gen/memmove.c index 7eec93f..4ab5407 100644 --- a/sys/src/ape/lib/ap/gen/memmove.c +++ b/sys/src/ape/lib/ap/gen/memmove.c @@ -1,4 +1,5 @@ #include +#include void* memmove(void *a1, const void *a2, size_t n) @@ -6,7 +7,7 @@ memmove(void *a1, const void *a2, size_t n) char *s1, *s2; extern void abort(void); - if((long)n < 0) + if((intptr_t)n < 0) abort(); if(a1 > a2) goto back; diff --git a/sys/src/ape/lib/ap/gen/mkfile b/sys/src/ape/lib/ap/gen/mkfile index ad4c1d3..6bc2e60 100644 --- a/sys/src/ape/lib/ap/gen/mkfile +++ b/sys/src/ape/lib/ap/gen/mkfile @@ -61,4 +61,4 @@ OFILES= `{rc ./reduce $O $objtype $ALLOFILES} +#include #include #include #include @@ -58,7 +59,7 @@ _startbuf(int fd) if(mux == 0){ _RFORK(RFREND); mux = (Muxseg*)_SEGATTACH(0, "shared", MUXADDR, sizeof(Muxseg)); - if((long)mux == -1){ + if((intptr_t)mux == -1){ _syserrno(); return -1; } @@ -152,7 +153,7 @@ _copyproc(int fd, Muxbuf *b) /* sleep until there's room */ b->roomwait = 1; unlock(&mux->lock); - _RENDEZVOUS((unsigned long)&b->roomwait, 0); + _RENDEZVOUS((uintptr_t)&b->roomwait, 0); } } else unlock(&mux->lock); @@ -174,15 +175,15 @@ _copyproc(int fd, Muxbuf *b) if(mux->selwait && FD_ISSET(fd, &mux->ewant)) { mux->selwait = 0; unlock(&mux->lock); - _RENDEZVOUS((unsigned long)&mux->selwait, fd); + _RENDEZVOUS((uintptr_t)&mux->selwait, fd); } else if(b->datawait) { b->datawait = 0; unlock(&mux->lock); - _RENDEZVOUS((unsigned long)&b->datawait, 0); + _RENDEZVOUS((uintptr_t)&b->datawait, 0); } else if(mux->selwait && FD_ISSET(fd, &mux->rwant)) { mux->selwait = 0; unlock(&mux->lock); - _RENDEZVOUS((unsigned long)&mux->selwait, fd); + _RENDEZVOUS((uintptr_t)&mux->selwait, fd); } else unlock(&mux->lock); _exit(0); @@ -195,12 +196,12 @@ _copyproc(int fd, Muxbuf *b) b->datawait = 0; unlock(&mux->lock); /* wake up _bufreading process */ - _RENDEZVOUS((unsigned long)&b->datawait, 0); + _RENDEZVOUS((uintptr_t)&b->datawait, 0); } else if(mux->selwait && FD_ISSET(fd, &mux->rwant)) { mux->selwait = 0; unlock(&mux->lock); /* wake up selecting process */ - _RENDEZVOUS((unsigned long)&mux->selwait, fd); + _RENDEZVOUS((uintptr_t)&mux->selwait, fd); } else unlock(&mux->lock); } else @@ -237,7 +238,7 @@ goteof: /* sleep until there's data */ b->datawait = 1; unlock(&mux->lock); - _RENDEZVOUS((unsigned long)&b->datawait, 0); + _RENDEZVOUS((uintptr_t)&b->datawait, 0); lock(&mux->lock); ngot = b->putnext - b->getnext; } @@ -255,7 +256,7 @@ goteof: b->roomwait = 0; unlock(&mux->lock); /* wake up copy process */ - _RENDEZVOUS((unsigned long)&b->roomwait, 0); + _RENDEZVOUS((uintptr_t)&b->roomwait, 0); } else unlock(&mux->lock); return ngot; @@ -348,7 +349,7 @@ select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *timeo } mux->selwait = 1; unlock(&mux->lock); - fd = _RENDEZVOUS((unsigned long)&mux->selwait, 0); + fd = _RENDEZVOUS((uintptr_t)&mux->selwait, 0); if(fd >= 0) { b = _fdinfo[fd].buf; if(FD_ISSET(fd, &mux->rwant)) { @@ -405,7 +406,7 @@ _timerproc(void) mux->selwait = 0; mux->waittime = LONGWAIT; unlock(&mux->lock); - _RENDEZVOUS((unsigned long)&mux->selwait, -2); + _RENDEZVOUS((uintptr_t)&mux->selwait, -2); } else { mux->waittime = LONGWAIT; unlock(&mux->lock); diff --git a/sys/src/ape/lib/ap/plan9/acid.c b/sys/src/ape/lib/ap/plan9/acid.c index 5109a21..2bc1d44 100644 --- a/sys/src/ape/lib/ap/plan9/acid.c +++ b/sys/src/ape/lib/ap/plan9/acid.c @@ -3,6 +3,8 @@ vc -a t.c > acidlib */ #define _POSIX_SOURCE 1 +#define _SUSV2_SOURCE +#define _PLAN9_SOURCE #define _BSD_EXTENSION 1 #define _LOCK_EXTENSION #include @@ -28,4 +30,4 @@ /* #include "sys9.h" buf.c below */ #include "_buf.c" #include "dir.h" -#include "fcall.h" +/* #include "fcall.h" */ diff --git a/sys/src/ape/lib/ap/plan9/brk.c b/sys/src/ape/lib/ap/plan9/brk.c index 0b32403..736b70c 100644 --- a/sys/src/ape/lib/ap/plan9/brk.c +++ b/sys/src/ape/lib/ap/plan9/brk.c @@ -1,4 +1,5 @@ #include "lib.h" +#include #include #include "sys9.h" @@ -9,11 +10,11 @@ extern int _BRK_(void*); char * brk(char *p) { - unsigned long n; + uintptr_t n; - n = (unsigned long)p; - n += 3; - n &= ~3; + n = (uintptr_t)p; + n += sizeof(uintptr_t) - 1; + n &= ~(sizeof(uintptr_t) - 1); if(_BRK_((void*)n) < 0){ errno = ENOMEM; return (char *)-1; @@ -23,10 +24,10 @@ brk(char *p) } void * -sbrk(unsigned long n) +sbrk(uintptr_t n) { - n += 3; - n &= ~3; + n += sizeof(uintptr_t) - 1; + n &= ~(sizeof(uintptr_t) - 1); if(_BRK_((void *)(bloc+n)) < 0){ errno = ENOMEM; return (void *)-1; diff --git a/sys/src/ape/lib/ap/plan9/malloc.c b/sys/src/ape/lib/ap/plan9/malloc.c index d8dc8bd..d5013d3 100644 --- a/sys/src/ape/lib/ap/plan9/malloc.c +++ b/sys/src/ape/lib/ap/plan9/malloc.c @@ -31,12 +31,12 @@ static Arena arena; #define datoff ((int)((Bucket*)0)->data) #define nil ((void*)0) -extern void *sbrk(unsigned long); +extern void *sbrk(uintptr_t); void* malloc(size_t size) { - uint next; + uintptr_t next; int pow, n; Bucket *bp, *nbp; @@ -68,11 +68,11 @@ good: if((intptr_t)bp == -1) return nil; - next = (uint)bp+size; + next = (uintptr_t)bp+size; nbp = (Bucket*)next; arena.btab[pow] = nbp; for(n -= 2; n; n--) { - next = (uint)nbp+size; + next = (uintptr_t)nbp+size; nbp->next = (Bucket*)next; nbp->size = pow; nbp = nbp->next; @@ -100,7 +100,7 @@ free(void *ptr) return; /* Find the start of the structure */ - bp = (Bucket*)((uint)ptr - datoff); + bp = (Bucket*)((uintptr_t)ptr - datoff); if(bp->magic != MAGIC) abort(); @@ -115,14 +115,14 @@ void* realloc(void *ptr, size_t n) { void *new; - uint osize; + uintptr_t osize; Bucket *bp; if(ptr == nil) return malloc(n); /* Find the start of the structure */ - bp = (Bucket*)((uint)ptr - datoff); + bp = (Bucket*)((uintptr_t)ptr - datoff); if(bp->magic != MAGIC) abort(); diff --git a/sys/src/ape/lib/ap/plan9/profile.c b/sys/src/ape/lib/ap/plan9/profile.c index a69e65f..d3260b9 100644 --- a/sys/src/ape/lib/ap/plan9/profile.c +++ b/sys/src/ape/lib/ap/plan9/profile.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -21,7 +22,7 @@ typedef unsigned long long uvlong; #include "/sys/include/tos.h" -extern void* sbrk(ulong); +extern void* sbrk(uintptr_t); extern long _callpc(void**); extern long _savearg(void); extern void _cycles(uvlong*); /* 64-bit value of the cycle counter if there is one, 0 if there isn't */ diff --git a/sys/src/ape/lib/ap/plan9/qlock.c b/sys/src/ape/lib/ap/plan9/qlock.c index b0882f7..a9e7307 100644 --- a/sys/src/ape/lib/ap/plan9/qlock.c +++ b/sys/src/ape/lib/ap/plan9/qlock.c @@ -3,6 +3,7 @@ #define _RESEARCH_SOURCE #include #include +#include #include #include #include "sys9.h" @@ -73,7 +74,7 @@ qlock(QLock *q) unlock(&q->lock); /* wait */ - while((*_rendezvousp)((ulong)mp, 1) == ~0) + while((*_rendezvousp)((uintptr_t)mp, 1) == ~0) ; mp->inuse = 0; } @@ -91,7 +92,7 @@ qunlock(QLock *q) if(q->head == nil) q->tail = nil; unlock(&q->lock); - while((*_rendezvousp)((ulong)p, 0x12345) == ~0) + while((*_rendezvousp)((uintptr_t)p, 0x12345) == ~0) ; return; } diff --git a/sys/src/ape/lib/ap/stdio/iolib.h b/sys/src/ape/lib/ap/stdio/iolib.h index 19b27df..a5fca5d 100644 --- a/sys/src/ape/lib/ap/stdio/iolib.h +++ b/sys/src/ape/lib/ap/stdio/iolib.h @@ -14,9 +14,6 @@ * fseek fsetpos ftell rewind clearerr * feof ferror perror */ -#ifndef _SUSV2_SOURCE -#define _SUSV2_SOURCE /* for *intptr_t types */ -#endif #include #include diff --git a/sys/src/ape/lib/ap/stdio/mkfile b/sys/src/ape/lib/ap/stdio/mkfile index dc7cea7..75f1ba2 100644 --- a/sys/src/ape/lib/ap/stdio/mkfile +++ b/sys/src/ape/lib/ap/stdio/mkfile @@ -65,4 +65,4 @@ OFILES=\ #include +#include #include "utf.h" #include "fmt.h" #include "fmtdef.h" @@ -348,7 +349,7 @@ __ifmt(Fmt *f) break; } if(f->r == 'p'){ - u = (ulong)va_arg(f->args, void*); + u = (uintptr_t)va_arg(f->args, void*); f->r = 'x'; fl |= FmtUnsigned; }else if(fl & FmtVLong){ diff --git a/sys/src/ape/lib/fmt/fmtfdflush.c b/sys/src/ape/lib/fmt/fmtfdflush.c index 796feab..026ccdf 100644 --- a/sys/src/ape/lib/fmt/fmtfdflush.c +++ b/sys/src/ape/lib/fmt/fmtfdflush.c @@ -12,6 +12,7 @@ * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. */ #include +#include #include #include "fmt.h" #include "fmtdef.h" @@ -26,7 +27,7 @@ __fmtFdFlush(Fmt *f) int n; n = (char*)f->to - (char*)f->start; - if(n && write((int)f->farg, f->start, n) != n) + if(n && write((int)(uintptr_t)f->farg, f->start, n) != n) return 0; f->to = f->start; return 1; diff --git a/sys/src/ape/lib/fmt/fmtstr.c b/sys/src/ape/lib/fmt/fmtstr.c index 7af1fa2..6b3f714 100644 --- a/sys/src/ape/lib/fmt/fmtstr.c +++ b/sys/src/ape/lib/fmt/fmtstr.c @@ -14,6 +14,7 @@ #include #include #include +#include #include "utf.h" #include "fmt.h" #include "fmtdef.h" @@ -22,9 +23,9 @@ static int fmtStrFlush(Fmt *f) { char *s; - int n; + uintptr_t n; - n = (int)f->farg; + n = (uintptr_t)f->farg; n += 256; f->farg = (void*)n; s = (char*)f->start; diff --git a/sys/src/ape/lib/fmt/mkfile b/sys/src/ape/lib/fmt/mkfile index 466df18..15ae76a 100644 --- a/sys/src/ape/lib/fmt/mkfile +++ b/sys/src/ape/lib/fmt/mkfile @@ -56,4 +56,4 @@ test: $LIB test.$O $CC -o test test.$O $LIB -L$PLAN9/lib -lutf -CFLAGS=$CFLAGS -c -D_POSIX_SOURCE -D_PLAN9_SOURCE -D_BSD_EXTENSION +CFLAGS=$CFLAGS -c -D_POSIX_SOURCE -D_PLAN9_SOURCE -D_BSD_EXTENSION -D_SUSV2_SOURCE diff --git a/sys/src/ape/lib/fmt/runefmtstr.c b/sys/src/ape/lib/fmt/runefmtstr.c index a2ec6cb..9515a8a 100644 --- a/sys/src/ape/lib/fmt/runefmtstr.c +++ b/sys/src/ape/lib/fmt/runefmtstr.c @@ -14,6 +14,7 @@ #include #include #include +#include #include "utf.h" #include "fmt.h" #include "fmtdef.h" @@ -22,9 +23,9 @@ static int runeFmtStrFlush(Fmt *f) { Rune *s; - int n; + uintptr_t n; - n = (int)f->farg; + n = (uintptr_t)f->farg; n += 256; f->farg = (void*)n; s = (Rune*)f->start;