Commit 0b08c948 authored by Russ Cox's avatar Russ Cox

runtime: prepare for 64-bit ints

This CL makes the runtime understand that the type of
the len or cap of a map, slice, or string is 'int', not 'int32',
and it is also careful to distinguish between function arguments
and results of type 'int' vs type 'int32'.

In the runtime, the new typedefs 'intgo' and 'uintgo' refer
to Go int and uint. The C types int and uint continue to be
unavailable (cause intentional compile errors).

This CL does not change the meaning of int, but it should make
the eventual change of the meaning of int on amd64 a bit
smoother.

Update #2188.

R=iant, r, dave, remyoudompheng
CC=golang-dev
https://golang.org/cl/6551067
parent 5e3fb887
...@@ -26,6 +26,11 @@ static char *input; ...@@ -26,6 +26,11 @@ static char *input;
static Buf *output; static Buf *output;
#define EOF -1 #define EOF -1
enum
{
use64bitint = 0,
};
static int static int
xgetchar(void) xgetchar(void)
{ {
...@@ -86,13 +91,16 @@ static struct { ...@@ -86,13 +91,16 @@ static struct {
char *name; char *name;
int size; int size;
} type_table[] = { } type_table[] = {
/* variable sized first, for easy replacement */ /*
/* order matches enum above */ * variable sized first, for easy replacement.
/* default is 32-bit architecture sizes */ * order matches enum above.
{"bool", 1}, * default is 32-bit architecture sizes.
* spelling as in package runtime, so intgo/uintgo not int/uint.
*/
{"bool", 1},
{"float", 4}, {"float", 4},
{"int", 4}, {"intgo", 4},
{"uint", 4}, {"uintgo", 4},
{"uintptr", 4}, {"uintptr", 4},
{"String", 8}, {"String", 8},
{"Slice", 12}, {"Slice", 12},
...@@ -101,12 +109,13 @@ static struct { ...@@ -101,12 +109,13 @@ static struct {
/* fixed size */ /* fixed size */
{"float32", 4}, {"float32", 4},
{"float64", 8}, {"float64", 8},
{"byte", 1}, {"byte", 1},
{"int8", 1}, {"int8", 1},
{"uint8", 1}, {"uint8", 1},
{"int16", 2}, {"int16", 2},
{"uint16", 2}, {"uint16", 2},
{"int32", 4}, {"int32", 4},
{"rune", 4},
{"uint32", 4}, {"uint32", 4},
{"int64", 8}, {"int64", 8},
{"uint64", 8}, {"uint64", 8},
...@@ -328,7 +337,7 @@ read_type(void) ...@@ -328,7 +337,7 @@ read_type(void)
unsigned int len; unsigned int len;
p = read_token_no_eof(); p = read_token_no_eof();
if (*p != '*') if (*p != '*' && !streq(p, "int") && !streq(p, "uint"))
return p; return p;
op = p; op = p;
pointer_count = 0; pointer_count = 0;
...@@ -337,13 +346,18 @@ read_type(void) ...@@ -337,13 +346,18 @@ read_type(void)
++p; ++p;
} }
len = xstrlen(p); len = xstrlen(p);
q = xmalloc(len + pointer_count + 1); q = xmalloc(len + 2 + pointer_count + 1);
xmemmove(q, p, len); xmemmove(q, p, len);
while (pointer_count > 0) {
q[len] = '*'; // Turn int/uint into intgo/uintgo.
++len; if((len == 3 && xmemcmp(q, "int", 3) == 0) || (len == 4 && xmemcmp(q, "uint", 4) == 0)) {
--pointer_count; q[len++] = 'g';
q[len++] = 'o';
} }
while (pointer_count-- > 0)
q[len++] = '*';
q[len] = '\0'; q[len] = '\0';
xfree(op); xfree(op);
return q; return q;
...@@ -713,15 +727,25 @@ goc2c(char *goc, char *c) ...@@ -713,15 +727,25 @@ goc2c(char *goc, char *c)
if(!gcc) { if(!gcc) {
if(streq(goarch, "amd64")) { if(streq(goarch, "amd64")) {
type_table[Uintptr].size = 8; type_table[Uintptr].size = 8;
type_table[String].size = 16;
type_table[Slice].size = 8+4+4;
type_table[Eface].size = 8+8; type_table[Eface].size = 8+8;
type_table[String].size = 16;
if(use64bitint) {
type_table[Int].size = 8;
type_table[Uint].size = 8;
}
type_table[Slice].size = 8+2*type_table[Int].size;
structround = 8; structround = 8;
} else { } else {
// NOTE: These are set in the initializer,
// but they might have been changed by a
// previous invocation of goc2c, so we have
// to restore them.
type_table[Uintptr].size = 4; type_table[Uintptr].size = 4;
type_table[String].size = 8; type_table[String].size = 8;
type_table[Slice].size = 16; type_table[Slice].size = 16;
type_table[Eface].size = 4+4; type_table[Eface].size = 4+4;
type_table[Int].size = 4;
type_table[Uint].size = 4;
structround = 4; structround = 4;
} }
} }
......
...@@ -930,9 +930,9 @@ func (v Value) Len() int { ...@@ -930,9 +930,9 @@ func (v Value) Len() int {
tt := (*arrayType)(unsafe.Pointer(v.typ)) tt := (*arrayType)(unsafe.Pointer(v.typ))
return int(tt.len) return int(tt.len)
case Chan: case Chan:
return int(chanlen(v.iword())) return chanlen(v.iword())
case Map: case Map:
return int(maplen(v.iword())) return maplen(v.iword())
case Slice: case Slice:
// Slice is bigger than a word; assume flagIndir. // Slice is bigger than a word; assume flagIndir.
return (*SliceHeader)(v.val).Len return (*SliceHeader)(v.val).Len
...@@ -989,7 +989,7 @@ func (v Value) MapKeys() []Value { ...@@ -989,7 +989,7 @@ func (v Value) MapKeys() []Value {
} }
m := v.iword() m := v.iword()
mlen := int32(0) mlen := int(0)
if m != nil { if m != nil {
mlen = maplen(m) mlen = maplen(m)
} }
...@@ -1821,7 +1821,7 @@ func MakeChan(typ Type, buffer int) Value { ...@@ -1821,7 +1821,7 @@ func MakeChan(typ Type, buffer int) Value {
if typ.ChanDir() != BothDir { if typ.ChanDir() != BothDir {
panic("reflect.MakeChan: unidirectional channel type") panic("reflect.MakeChan: unidirectional channel type")
} }
ch := makechan(typ.runtimeType(), uint32(buffer)) ch := makechan(typ.runtimeType(), uint64(buffer))
return Value{typ.common(), unsafe.Pointer(ch), flag(Chan) << flagKindShift} return Value{typ.common(), unsafe.Pointer(ch), flag(Chan) << flagKindShift}
} }
...@@ -2235,20 +2235,20 @@ func cvtI2I(v Value, typ Type) Value { ...@@ -2235,20 +2235,20 @@ func cvtI2I(v Value, typ Type) Value {
} }
// implemented in ../pkg/runtime // implemented in ../pkg/runtime
func chancap(ch iword) int32 func chancap(ch iword) int
func chanclose(ch iword) func chanclose(ch iword)
func chanlen(ch iword) int32 func chanlen(ch iword) int
func chanrecv(t *runtimeType, ch iword, nb bool) (val iword, selected, received bool) func chanrecv(t *runtimeType, ch iword, nb bool) (val iword, selected, received bool)
func chansend(t *runtimeType, ch iword, val iword, nb bool) bool func chansend(t *runtimeType, ch iword, val iword, nb bool) bool
func makechan(typ *runtimeType, size uint32) (ch iword) func makechan(typ *runtimeType, size uint64) (ch iword)
func makemap(t *runtimeType) (m iword) func makemap(t *runtimeType) (m iword)
func mapaccess(t *runtimeType, m iword, key iword) (val iword, ok bool) func mapaccess(t *runtimeType, m iword, key iword) (val iword, ok bool)
func mapassign(t *runtimeType, m iword, key, val iword, ok bool) func mapassign(t *runtimeType, m iword, key, val iword, ok bool)
func mapiterinit(t *runtimeType, m iword) *byte func mapiterinit(t *runtimeType, m iword) *byte
func mapiterkey(it *byte) (key iword, ok bool) func mapiterkey(it *byte) (key iword, ok bool)
func mapiternext(it *byte) func mapiternext(it *byte)
func maplen(m iword) int32 func maplen(m iword) int
func call(fn, arg unsafe.Pointer, n uint32) func call(fn, arg unsafe.Pointer, n uint32)
func ifaceE2I(t *runtimeType, src interface{}, dst unsafe.Pointer) func ifaceE2I(t *runtimeType, src interface{}, dst unsafe.Pointer)
......
...@@ -316,7 +316,7 @@ runtime·strhash(uintptr *h, uintptr s, void *a) ...@@ -316,7 +316,7 @@ runtime·strhash(uintptr *h, uintptr s, void *a)
void void
runtime·strequal(bool *eq, uintptr s, void *a, void *b) runtime·strequal(bool *eq, uintptr s, void *a, void *b)
{ {
int32 alen; intgo alen;
USED(s); USED(s);
alen = ((String*)a)->len; alen = ((String*)a)->len;
......
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
#include "runtime.h" #include "runtime.h"
#include "arch_GOARCH.h"
#include "type.h" #include "type.h"
#include "malloc.h"
#define MAXALIGN 7 #define MAXALIGN 7
#define NOSELGEN 1 #define NOSELGEN 1
...@@ -31,14 +33,14 @@ struct WaitQ ...@@ -31,14 +33,14 @@ struct WaitQ
struct Hchan struct Hchan
{ {
uint32 qcount; // total data in the q uintgo qcount; // total data in the q
uint32 dataqsiz; // size of the circular q uintgo dataqsiz; // size of the circular q
uint16 elemsize; uint16 elemsize;
bool closed; bool closed;
uint8 elemalign; uint8 elemalign;
Alg* elemalg; // interface for element type Alg* elemalg; // interface for element type
uint32 sendx; // send index uintgo sendx; // send index
uint32 recvx; // receive index uintgo recvx; // receive index
WaitQ recvq; // list of recv waiters WaitQ recvq; // list of recv waiters
WaitQ sendq; // list of send waiters WaitQ sendq; // list of send waiters
Lock; Lock;
...@@ -84,12 +86,16 @@ Hchan* ...@@ -84,12 +86,16 @@ Hchan*
runtime·makechan_c(ChanType *t, int64 hint) runtime·makechan_c(ChanType *t, int64 hint)
{ {
Hchan *c; Hchan *c;
int32 n; uintptr n;
Type *elem; Type *elem;
elem = t->elem; elem = t->elem;
if(hint < 0 || (int32)hint != hint || (elem->size > 0 && hint > ((uintptr)-1) / elem->size)) // compiler checks this but be safe.
if(elem->size >= (1<<16))
runtime·throw("makechan: invalid channel element type");
if(hint < 0 || (intgo)hint != hint || (elem->size > 0 && hint > MaxMem / elem->size))
runtime·panicstring("makechan: size out of range"); runtime·panicstring("makechan: size out of range");
// calculate rounded size of Hchan // calculate rounded size of Hchan
...@@ -105,16 +111,16 @@ runtime·makechan_c(ChanType *t, int64 hint) ...@@ -105,16 +111,16 @@ runtime·makechan_c(ChanType *t, int64 hint)
c->dataqsiz = hint; c->dataqsiz = hint;
if(debug) if(debug)
runtime·printf("makechan: chan=%p; elemsize=%D; elemalg=%p; elemalign=%d; dataqsiz=%d\n", runtime·printf("makechan: chan=%p; elemsize=%D; elemalg=%p; elemalign=%d; dataqsiz=%D\n",
c, (int64)elem->size, elem->alg, elem->align, c->dataqsiz); c, (int64)elem->size, elem->alg, elem->align, (int64)c->dataqsiz);
return c; return c;
} }
// For reflect // For reflect
// func makechan(typ *ChanType, size uint32) (chan) // func makechan(typ *ChanType, size uint64) (chan)
void void
reflect·makechan(ChanType *t, uint32 size, Hchan *c) reflect·makechan(ChanType *t, uint64 size, Hchan *c)
{ {
c = runtime·makechan_c(t, size); c = runtime·makechan_c(t, size);
FLUSH(&c); FLUSH(&c);
...@@ -1038,7 +1044,7 @@ enum SelectDir { ...@@ -1038,7 +1044,7 @@ enum SelectDir {
// func rselect(cases []runtimeSelect) (chosen int, word uintptr, recvOK bool) // func rselect(cases []runtimeSelect) (chosen int, word uintptr, recvOK bool)
void void
reflect·rselect(Slice cases, int32 chosen, uintptr word, bool recvOK) reflect·rselect(Slice cases, intgo chosen, uintptr word, bool recvOK)
{ {
int32 i; int32 i;
Select *sel; Select *sel;
...@@ -1091,7 +1097,7 @@ reflect·rselect(Slice cases, int32 chosen, uintptr word, bool recvOK) ...@@ -1091,7 +1097,7 @@ reflect·rselect(Slice cases, int32 chosen, uintptr word, bool recvOK)
} }
} }
chosen = (int32)(uintptr)selectgo(&sel); chosen = (intgo)(uintptr)selectgo(&sel);
if(rcase[chosen].dir == SelectRecv && rcase[chosen].typ->elem->size > sizeof(void*)) if(rcase[chosen].dir == SelectRecv && rcase[chosen].typ->elem->size > sizeof(void*))
word = (uintptr)recvptr; word = (uintptr)recvptr;
...@@ -1153,9 +1159,9 @@ reflect·chanclose(Hchan *c) ...@@ -1153,9 +1159,9 @@ reflect·chanclose(Hchan *c)
} }
// For reflect // For reflect
// func chanlen(c chan) (len int32) // func chanlen(c chan) (len int)
void void
reflect·chanlen(Hchan *c, int32 len) reflect·chanlen(Hchan *c, intgo len)
{ {
if(c == nil) if(c == nil)
len = 0; len = 0;
...@@ -1165,9 +1171,9 @@ reflect·chanlen(Hchan *c, int32 len) ...@@ -1165,9 +1171,9 @@ reflect·chanlen(Hchan *c, int32 len)
} }
// For reflect // For reflect
// func chancap(c chan) (cap int32) // func chancap(c chan) int
void void
reflect·chancap(Hchan *c, int32 cap) reflect·chancap(Hchan *c, intgo cap)
{ {
if(c == nil) if(c == nil)
cap = 0; cap = 0;
......
...@@ -121,7 +121,7 @@ static void LostProfileData(void) { ...@@ -121,7 +121,7 @@ static void LostProfileData(void) {
// SetCPUProfileRate sets the CPU profiling rate. // SetCPUProfileRate sets the CPU profiling rate.
// The user documentation is in debug.go. // The user documentation is in debug.go.
void void
runtime·SetCPUProfileRate(int32 hz) runtime·SetCPUProfileRate(intgo hz)
{ {
uintptr *p; uintptr *p;
uintptr n; uintptr n;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#define CanFreeKey (1<<3) /* okay to free pointers to keys */ #define CanFreeKey (1<<3) /* okay to free pointers to keys */
struct Hmap { /* a hash table; initialize with hash_init() */ struct Hmap { /* a hash table; initialize with hash_init() */
uint32 count; /* elements in table - must be first */ uintgo count; /* elements in table - must be first */
uint8 datasize; /* amount of data to store in entry */ uint8 datasize; /* amount of data to store in entry */
uint8 flag; uint8 flag;
uint8 valoff; /* offset of value in key+value data block */ uint8 valoff; /* offset of value in key+value data block */
...@@ -728,7 +728,6 @@ hash_keyptr(Hmap *h, void *p) ...@@ -728,7 +728,6 @@ hash_keyptr(Hmap *h, void *p)
static int32 debug = 0; static int32 debug = 0;
// makemap(typ *Type, hint uint32) (hmap *map[any]any);
Hmap* Hmap*
runtime·makemap_c(MapType *typ, int64 hint) runtime·makemap_c(MapType *typ, int64 hint)
{ {
...@@ -1152,10 +1151,10 @@ reflect·mapiterkey(struct hash_iter *it, uintptr key, bool ok) ...@@ -1152,10 +1151,10 @@ reflect·mapiterkey(struct hash_iter *it, uintptr key, bool ok)
} }
// For reflect: // For reflect:
// func maplen(h map) (len int32) // func maplen(h map) (len int)
// Like len(m) in the actual language, we treat the nil map as length 0. // Like len(m) in the actual language, we treat the nil map as length 0.
void void
reflect·maplen(Hmap *h, int32 len) reflect·maplen(Hmap *h, intgo len)
{ {
if(h == nil) if(h == nil)
len = 0; len = 0;
......
...@@ -703,7 +703,7 @@ reflect·unsafe_New(Eface typ, void *ret) ...@@ -703,7 +703,7 @@ reflect·unsafe_New(Eface typ, void *ret)
} }
void void
reflect·unsafe_NewArray(Eface typ, uint32 n, void *ret) reflect·unsafe_NewArray(Eface typ, intgo n, void *ret)
{ {
uint64 size; uint64 size;
Type *t; Type *t;
......
...@@ -20,7 +20,7 @@ MHeap runtime·mheap; ...@@ -20,7 +20,7 @@ MHeap runtime·mheap;
extern MStats mstats; // defined in extern.go extern MStats mstats; // defined in extern.go
extern volatile int32 runtime·MemProfileRate; extern volatile intgo runtime·MemProfileRate;
// Allocate an object of at least size bytes. // Allocate an object of at least size bytes.
// Small objects are allocated from the per-thread cache's free lists. // Small objects are allocated from the per-thread cache's free lists.
...@@ -28,7 +28,8 @@ extern volatile int32 runtime·MemProfileRate; ...@@ -28,7 +28,8 @@ extern volatile int32 runtime·MemProfileRate;
void* void*
runtime·mallocgc(uintptr size, uint32 flag, int32 dogc, int32 zeroed) runtime·mallocgc(uintptr size, uint32 flag, int32 dogc, int32 zeroed)
{ {
int32 sizeclass, rate; int32 sizeclass;
intgo rate;
MCache *c; MCache *c;
uintptr npages; uintptr npages;
MSpan *s; MSpan *s;
...@@ -226,7 +227,7 @@ runtime·mlookup(void *v, byte **base, uintptr *size, MSpan **sp) ...@@ -226,7 +227,7 @@ runtime·mlookup(void *v, byte **base, uintptr *size, MSpan **sp)
MCache* MCache*
runtime·allocmcache(void) runtime·allocmcache(void)
{ {
int32 rate; intgo rate;
MCache *c; MCache *c;
runtime·lock(&runtime·mheap); runtime·lock(&runtime·mheap);
...@@ -507,7 +508,8 @@ func SetFinalizer(obj Eface, finalizer Eface) { ...@@ -507,7 +508,8 @@ func SetFinalizer(obj Eface, finalizer Eface) {
byte *base; byte *base;
uintptr size; uintptr size;
FuncType *ft; FuncType *ft;
int32 i, nret; int32 i;
uintptr nret;
Type *t; Type *t;
if(obj.type == nil) { if(obj.type == nil) {
......
...@@ -128,6 +128,15 @@ enum ...@@ -128,6 +128,15 @@ enum
MaxGcproc = 8, MaxGcproc = 8,
}; };
// Maximum memory allocation size, a hint for callers.
// This must be a #define instead of an enum because it
// is so large.
#ifdef _64BIT
#define MaxMem (16ULL<<30) /* 16 GB */
#else
#define MaxMem ((uintptr)-1)
#endif
// A generic linked list of blocks. (Typically the block is bigger than sizeof(MLink).) // A generic linked list of blocks. (Typically the block is bigger than sizeof(MLink).)
struct MLink struct MLink
{ {
...@@ -418,5 +427,5 @@ int32 runtime·gcprocs(void); ...@@ -418,5 +427,5 @@ int32 runtime·gcprocs(void);
void runtime·helpgc(int32 nproc); void runtime·helpgc(int32 nproc);
void runtime·gchelper(void); void runtime·gchelper(void);
bool runtime·getfinalizer(void *p, bool del, void (**fn)(void*), int32 *nret); bool runtime·getfinalizer(void *p, bool del, void (**fn)(void*), uintptr *nret);
void runtime·walkfintab(void (*fn)(void*)); void runtime·walkfintab(void (*fn)(void*));
...@@ -12,7 +12,7 @@ typedef struct Fin Fin; ...@@ -12,7 +12,7 @@ typedef struct Fin Fin;
struct Fin struct Fin
{ {
void (*fn)(void*); void (*fn)(void*);
int32 nret; uintptr nret;
}; };
// Finalizer hash table. Direct hash, linear scan, at most 3/4 full. // Finalizer hash table. Direct hash, linear scan, at most 3/4 full.
...@@ -42,7 +42,7 @@ static struct { ...@@ -42,7 +42,7 @@ static struct {
} fintab[TABSZ]; } fintab[TABSZ];
static void static void
addfintab(Fintab *t, void *k, void (*fn)(void*), int32 nret) addfintab(Fintab *t, void *k, void (*fn)(void*), uintptr nret)
{ {
int32 i, j; int32 i, j;
...@@ -137,7 +137,7 @@ resizefintab(Fintab *tab) ...@@ -137,7 +137,7 @@ resizefintab(Fintab *tab)
} }
bool bool
runtime·addfinalizer(void *p, void (*f)(void*), int32 nret) runtime·addfinalizer(void *p, void (*f)(void*), uintptr nret)
{ {
Fintab *tab; Fintab *tab;
byte *base; byte *base;
...@@ -175,7 +175,7 @@ runtime·addfinalizer(void *p, void (*f)(void*), int32 nret) ...@@ -175,7 +175,7 @@ runtime·addfinalizer(void *p, void (*f)(void*), int32 nret)
// get finalizer; if del, delete finalizer. // get finalizer; if del, delete finalizer.
// caller is responsible for updating RefHasFinalizer (special) bit. // caller is responsible for updating RefHasFinalizer (special) bit.
bool bool
runtime·getfinalizer(void *p, bool del, void (**fn)(void*), int32 *nret) runtime·getfinalizer(void *p, bool del, void (**fn)(void*), uintptr *nret)
{ {
Fintab *tab; Fintab *tab;
bool res; bool res;
......
...@@ -82,7 +82,7 @@ struct Finalizer ...@@ -82,7 +82,7 @@ struct Finalizer
{ {
void (*fn)(void*); void (*fn)(void*);
void *arg; void *arg;
int32 nret; uintptr nret;
}; };
typedef struct FinBlock FinBlock; typedef struct FinBlock FinBlock;
...@@ -633,7 +633,7 @@ static bool ...@@ -633,7 +633,7 @@ static bool
handlespecial(byte *p, uintptr size) handlespecial(byte *p, uintptr size)
{ {
void (*fn)(void*); void (*fn)(void*);
int32 nret; uintptr nret;
FinBlock *block; FinBlock *block;
Finalizer *f; Finalizer *f;
......
...@@ -284,7 +284,7 @@ record(Record *r, Bucket *b) ...@@ -284,7 +284,7 @@ record(Record *r, Bucket *b)
r->stk[i] = 0; r->stk[i] = 0;
} }
func MemProfile(p Slice, include_inuse_zero bool) (n int32, ok bool) { func MemProfile(p Slice, include_inuse_zero bool) (n int, ok bool) {
Bucket *b; Bucket *b;
Record *r; Record *r;
...@@ -310,7 +310,7 @@ struct TRecord { ...@@ -310,7 +310,7 @@ struct TRecord {
uintptr stk[32]; uintptr stk[32];
}; };
func ThreadCreateProfile(p Slice) (n int32, ok bool) { func ThreadCreateProfile(p Slice) (n int, ok bool) {
TRecord *r; TRecord *r;
M *first, *m; M *first, *m;
...@@ -329,7 +329,7 @@ func ThreadCreateProfile(p Slice) (n int32, ok bool) { ...@@ -329,7 +329,7 @@ func ThreadCreateProfile(p Slice) (n int32, ok bool) {
} }
} }
func Stack(b Slice, all bool) (n int32) { func Stack(b Slice, all bool) (n int) {
byte *pc, *sp; byte *pc, *sp;
sp = runtime·getcallersp(&b); sp = runtime·getcallersp(&b);
...@@ -372,7 +372,7 @@ saveg(byte *pc, byte *sp, G *g, TRecord *r) ...@@ -372,7 +372,7 @@ saveg(byte *pc, byte *sp, G *g, TRecord *r)
r->stk[n] = 0; r->stk[n] = 0;
} }
func GoroutineProfile(b Slice) (n int32, ok bool) { func GoroutineProfile(b Slice) (n int, ok bool) {
byte *pc, *sp; byte *pc, *sp;
TRecord *r; TRecord *r;
G *gp; G *gp;
......
...@@ -343,7 +343,7 @@ runtime·printstring(String v) ...@@ -343,7 +343,7 @@ runtime·printstring(String v)
extern uint32 runtime·maxstring; extern uint32 runtime·maxstring;
if(v.len > runtime·maxstring) { if(v.len > runtime·maxstring) {
gwrite("[invalid string]", 16); gwrite("[string too long]", 17);
return; return;
} }
if(v.len > 0) if(v.len > 0)
......
...@@ -1451,7 +1451,7 @@ runtime·mid(uint32 ret) ...@@ -1451,7 +1451,7 @@ runtime·mid(uint32 ret)
} }
void void
runtime·NumGoroutine(int32 ret) runtime·NumGoroutine(intgo ret)
{ {
ret = runtime·sched.gcount; ret = runtime·sched.gcount;
FLUSH(&ret); FLUSH(&ret);
......
...@@ -290,7 +290,7 @@ runtime·check(void) ...@@ -290,7 +290,7 @@ runtime·check(void)
} }
void void
runtime·Caller(int32 skip, uintptr retpc, String retfile, int32 retline, bool retbool) runtime·Caller(intgo skip, uintptr retpc, String retfile, intgo retline, bool retbool)
{ {
Func *f, *g; Func *f, *g;
uintptr pc; uintptr pc;
...@@ -327,7 +327,7 @@ runtime·Caller(int32 skip, uintptr retpc, String retfile, int32 retline, bool r ...@@ -327,7 +327,7 @@ runtime·Caller(int32 skip, uintptr retpc, String retfile, int32 retline, bool r
} }
void void
runtime·Callers(int32 skip, Slice pc, int32 retn) runtime·Callers(intgo skip, Slice pc, intgo retn)
{ {
// runtime.callers uses pc.array==nil as a signal // runtime.callers uses pc.array==nil as a signal
// to print a stack trace. Pick off 0-length pc here // to print a stack trace. Pick off 0-length pc here
......
...@@ -19,9 +19,13 @@ typedef double float64; ...@@ -19,9 +19,13 @@ typedef double float64;
#ifdef _64BIT #ifdef _64BIT
typedef uint64 uintptr; typedef uint64 uintptr;
typedef int64 intptr; typedef int64 intptr;
typedef int32 intgo; // Go's int
typedef uint32 uintgo; // Go's uint
#else #else
typedef uint32 uintptr; typedef uint32 uintptr;
typedef int32 intptr; typedef int32 intptr;
typedef int32 intgo; // Go's int
typedef uint32 uintgo; // Go's uint
#endif #endif
/* /*
...@@ -139,7 +143,7 @@ union Note ...@@ -139,7 +143,7 @@ union Note
struct String struct String
{ {
byte* str; byte* str;
int32 len; intgo len;
}; };
struct Iface struct Iface
{ {
...@@ -165,8 +169,8 @@ struct Complex128 ...@@ -165,8 +169,8 @@ struct Complex128
struct Slice struct Slice
{ // must not move anything { // must not move anything
byte* array; // actual data byte* array; // actual data
uint32 len; // number of elements uintgo len; // number of elements
uint32 cap; // allocated number of elements uintgo cap; // allocated number of elements
}; };
struct Gobuf struct Gobuf
{ {
...@@ -518,7 +522,8 @@ extern int32 runtime·gcwaiting; // gc is waiting to run ...@@ -518,7 +522,8 @@ extern int32 runtime·gcwaiting; // gc is waiting to run
int8* runtime·goos; int8* runtime·goos;
int32 runtime·ncpu; int32 runtime·ncpu;
extern bool runtime·iscgo; extern bool runtime·iscgo;
extern void (*runtime·sysargs)(int32, uint8**); extern void (*runtime·sysargs)(int32, uint8**);
extern uint32 runtime·maxstring;
/* /*
* common functions and data * common functions and data
...@@ -554,8 +559,8 @@ void runtime·memmove(void*, void*, uint32); ...@@ -554,8 +559,8 @@ void runtime·memmove(void*, void*, uint32);
void* runtime·mal(uintptr); void* runtime·mal(uintptr);
String runtime·catstring(String, String); String runtime·catstring(String, String);
String runtime·gostring(byte*); String runtime·gostring(byte*);
String runtime·gostringn(byte*, int32); String runtime·gostringn(byte*, intgo);
Slice runtime·gobytes(byte*, int32); Slice runtime·gobytes(byte*, intgo);
String runtime·gostringnocopy(byte*); String runtime·gostringnocopy(byte*);
String runtime·gostringw(uint16*); String runtime·gostringw(uint16*);
void runtime·initsig(void); void runtime·initsig(void);
...@@ -603,7 +608,7 @@ uintptr runtime·ifacehash(Iface); ...@@ -603,7 +608,7 @@ uintptr runtime·ifacehash(Iface);
uintptr runtime·efacehash(Eface); uintptr runtime·efacehash(Eface);
void* runtime·malloc(uintptr size); void* runtime·malloc(uintptr size);
void runtime·free(void *v); void runtime·free(void *v);
bool runtime·addfinalizer(void*, void(*fn)(void*), int32); bool runtime·addfinalizer(void*, void(*fn)(void*), uintptr);
void runtime·runpanic(Panic*); void runtime·runpanic(Panic*);
void* runtime·getcallersp(void*); void* runtime·getcallersp(void*);
int32 runtime·mcount(void); int32 runtime·mcount(void);
...@@ -807,8 +812,6 @@ Hmap* runtime·makemap_c(MapType*, int64); ...@@ -807,8 +812,6 @@ Hmap* runtime·makemap_c(MapType*, int64);
Hchan* runtime·makechan_c(ChanType*, int64); Hchan* runtime·makechan_c(ChanType*, int64);
void runtime·chansend(ChanType*, Hchan*, byte*, bool*); void runtime·chansend(ChanType*, Hchan*, byte*, bool*);
void runtime·chanrecv(ChanType*, Hchan*, byte*, bool*, bool*); void runtime·chanrecv(ChanType*, Hchan*, byte*, bool*, bool*);
int32 runtime·chanlen(Hchan*);
int32 runtime·chancap(Hchan*);
bool runtime·showframe(Func*); bool runtime·showframe(Func*);
void runtime·ifaceE2I(struct InterfaceType*, Eface, Iface*); void runtime·ifaceE2I(struct InterfaceType*, Eface, Iface*);
......
...@@ -5,10 +5,10 @@ ...@@ -5,10 +5,10 @@
package runtime package runtime
#include "runtime.h" #include "runtime.h"
func GOMAXPROCS(n int32) (ret int32) { func GOMAXPROCS(n int) (ret int) {
ret = runtime·gomaxprocsfunc(n); ret = runtime·gomaxprocsfunc(n);
} }
func NumCPU() (ret int32) { func NumCPU() (ret int) {
ret = runtime·ncpu; ret = runtime·ncpu;
} }
...@@ -8,20 +8,21 @@ ...@@ -8,20 +8,21 @@
#include "typekind.h" #include "typekind.h"
#include "malloc.h" #include "malloc.h"
static int32 debug = 0; static bool debug = 0;
static void makeslice1(SliceType*, int32, int32, Slice*); static void makeslice1(SliceType*, intgo, intgo, Slice*);
static void growslice1(SliceType*, Slice, int32, Slice *); static void growslice1(SliceType*, Slice, intgo, Slice *);
void runtime·copy(Slice to, Slice fm, uintptr width, int32 ret); void runtime·copy(Slice to, Slice fm, uintptr width, intgo ret);
// see also unsafe·NewArray // see also unsafe·NewArray
// makeslice(typ *Type, len, cap int64) (ary []any); // makeslice(typ *Type, len, cap int64) (ary []any);
void void
runtime·makeslice(SliceType *t, int64 len, int64 cap, Slice ret) runtime·makeslice(SliceType *t, int64 len, int64 cap, Slice ret)
{ {
if(len < 0 || (int32)len != len) if(len < 0 || (intgo)len != len)
runtime·panicstring("makeslice: len out of range"); runtime·panicstring("makeslice: len out of range");
if(cap < len || (int32)cap != cap || t->elem->size > 0 && cap > ((uintptr)-1) / t->elem->size)
if(cap < len || (intgo)cap != cap || t->elem->size > 0 && cap > MaxMem / t->elem->size)
runtime·panicstring("makeslice: cap out of range"); runtime·panicstring("makeslice: cap out of range");
makeslice1(t, len, cap, &ret); makeslice1(t, len, cap, &ret);
...@@ -39,7 +40,7 @@ runtime·makeslice(SliceType *t, int64 len, int64 cap, Slice ret) ...@@ -39,7 +40,7 @@ runtime·makeslice(SliceType *t, int64 len, int64 cap, Slice ret)
static uintptr zerobase; static uintptr zerobase;
static void static void
makeslice1(SliceType *t, int32 len, int32 cap, Slice *ret) makeslice1(SliceType *t, intgo len, intgo cap, Slice *ret)
{ {
uintptr size; uintptr size;
...@@ -60,7 +61,7 @@ makeslice1(SliceType *t, int32 len, int32 cap, Slice *ret) ...@@ -60,7 +61,7 @@ makeslice1(SliceType *t, int32 len, int32 cap, Slice *ret)
void void
runtime·appendslice(SliceType *t, Slice x, Slice y, Slice ret) runtime·appendslice(SliceType *t, Slice x, Slice y, Slice ret)
{ {
int32 m; intgo m;
uintptr w; uintptr w;
m = x.len+y.len; m = x.len+y.len;
...@@ -84,7 +85,7 @@ runtime·appendslice(SliceType *t, Slice x, Slice y, Slice ret) ...@@ -84,7 +85,7 @@ runtime·appendslice(SliceType *t, Slice x, Slice y, Slice ret)
void void
runtime·appendstr(SliceType *t, Slice x, String y, Slice ret) runtime·appendstr(SliceType *t, Slice x, String y, Slice ret)
{ {
int32 m; intgo m;
m = x.len+y.len; m = x.len+y.len;
...@@ -113,7 +114,7 @@ runtime·growslice(SliceType *t, Slice old, int64 n, Slice ret) ...@@ -113,7 +114,7 @@ runtime·growslice(SliceType *t, Slice old, int64 n, Slice ret)
cap = old.cap + n; cap = old.cap + n;
if((int32)cap != cap || cap > ((uintptr)-1) / t->elem->size) if((intgo)cap != cap || cap < old.cap || cap > MaxMem / t->elem->size)
runtime·panicstring("growslice: cap out of range"); runtime·panicstring("growslice: cap out of range");
growslice1(t, old, cap, &ret); growslice1(t, old, cap, &ret);
...@@ -129,12 +130,17 @@ runtime·growslice(SliceType *t, Slice old, int64 n, Slice ret) ...@@ -129,12 +130,17 @@ runtime·growslice(SliceType *t, Slice old, int64 n, Slice ret)
} }
static void static void
growslice1(SliceType *t, Slice x, int32 newcap, Slice *ret) growslice1(SliceType *t, Slice x, intgo newcap, Slice *ret)
{ {
int32 m; intgo m;
m = x.cap; m = x.cap;
if(m == 0)
// Using newcap directly for m+m < newcap handles
// both the case where m == 0 and also the case where
// m+m/4 wraps around, in which case the loop
// below might never terminate.
if(m+m < newcap)
m = newcap; m = newcap;
else { else {
do { do {
...@@ -148,9 +154,9 @@ growslice1(SliceType *t, Slice x, int32 newcap, Slice *ret) ...@@ -148,9 +154,9 @@ growslice1(SliceType *t, Slice x, int32 newcap, Slice *ret)
runtime·memmove(ret->array, x.array, ret->len * t->elem->size); runtime·memmove(ret->array, x.array, ret->len * t->elem->size);
} }
// copy(to any, fr any, wid uint32) int // copy(to any, fr any, wid uintptr) int
void void
runtime·copy(Slice to, Slice fm, uintptr width, int32 ret) runtime·copy(Slice to, Slice fm, uintptr width, intgo ret)
{ {
if(fm.len == 0 || to.len == 0 || width == 0) { if(fm.len == 0 || to.len == 0 || width == 0) {
ret = 0; ret = 0;
...@@ -184,7 +190,7 @@ out: ...@@ -184,7 +190,7 @@ out:
} }
void void
runtime·slicestringcopy(Slice to, String fm, int32 ret) runtime·slicestringcopy(Slice to, String fm, intgo ret)
{ {
if(fm.len == 0 || to.len == 0) { if(fm.len == 0 || to.len == 0) {
ret = 0; ret = 0;
......
...@@ -33,10 +33,10 @@ runtime·findnullw(uint16 *s) ...@@ -33,10 +33,10 @@ runtime·findnullw(uint16 *s)
return l; return l;
} }
uint32 runtime·maxstring = 256; uint32 runtime·maxstring = 256; // a hint for print
static String static String
gostringsize(int32 l) gostringsize(intgo l)
{ {
String s; String s;
uint32 ms; uint32 ms;
...@@ -58,7 +58,7 @@ gostringsize(int32 l) ...@@ -58,7 +58,7 @@ gostringsize(int32 l)
String String
runtime·gostring(byte *str) runtime·gostring(byte *str)
{ {
int32 l; intgo l;
String s; String s;
l = runtime·findnull(str); l = runtime·findnull(str);
...@@ -68,7 +68,7 @@ runtime·gostring(byte *str) ...@@ -68,7 +68,7 @@ runtime·gostring(byte *str)
} }
String String
runtime·gostringn(byte *str, int32 l) runtime·gostringn(byte *str, intgo l)
{ {
String s; String s;
...@@ -78,7 +78,7 @@ runtime·gostringn(byte *str, int32 l) ...@@ -78,7 +78,7 @@ runtime·gostringn(byte *str, int32 l)
} }
Slice Slice
runtime·gobytes(byte *p, int32 n) runtime·gobytes(byte *p, intgo n)
{ {
Slice sl; Slice sl;
...@@ -102,7 +102,7 @@ runtime·gostringnocopy(byte *str) ...@@ -102,7 +102,7 @@ runtime·gostringnocopy(byte *str)
String String
runtime·gostringw(uint16 *str) runtime·gostringw(uint16 *str)
{ {
int32 n1, n2, i; intgo n1, n2, i;
byte buf[8]; byte buf[8];
String s; String s;
...@@ -139,9 +139,9 @@ runtime·catstring(String s1, String s2) ...@@ -139,9 +139,9 @@ runtime·catstring(String s1, String s2)
} }
static String static String
concatstring(int32 n, String *s) concatstring(intgo n, String *s)
{ {
int32 i, l, count; intgo i, l, count;
String out; String out;
l = 0; l = 0;
...@@ -172,14 +172,14 @@ concatstring(int32 n, String *s) ...@@ -172,14 +172,14 @@ concatstring(int32 n, String *s)
#pragma textflag 7 #pragma textflag 7
// s1 is the first of n strings. // s1 is the first of n strings.
// the output string follows. // the output string follows.
func concatstring(n int32, s1 String) { func concatstring(n int, s1 String) {
(&s1)[n] = concatstring(n, &s1); (&s1)[n] = concatstring(n, &s1);
} }
static int32 static int32
cmpstring(String s1, String s2) cmpstring(String s1, String s2)
{ {
uint32 i, l; uintgo i, l;
byte c1, c2; byte c1, c2;
l = s1.len; l = s1.len;
...@@ -200,12 +200,12 @@ cmpstring(String s1, String s2) ...@@ -200,12 +200,12 @@ cmpstring(String s1, String s2)
return 0; return 0;
} }
func cmpstring(s1 String, s2 String) (v int32) { func cmpstring(s1 String, s2 String) (v int) {
v = cmpstring(s1, s2); v = cmpstring(s1, s2);
} }
func eqstring(s1 String, s2 String) (v bool) { func eqstring(s1 String, s2 String) (v bool) {
uint32 i, l; uintgo i, l;
if(s1.len != s2.len) { if(s1.len != s2.len) {
v = false; v = false;
...@@ -227,7 +227,7 @@ func eqstring(s1 String, s2 String) (v bool) { ...@@ -227,7 +227,7 @@ func eqstring(s1 String, s2 String) (v bool) {
int32 int32
runtime·strcmp(byte *s1, byte *s2) runtime·strcmp(byte *s1, byte *s2)
{ {
uint32 i; uintptr i;
byte c1, c2; byte c1, c2;
for(i=0;; i++) { for(i=0;; i++) {
...@@ -283,7 +283,7 @@ func stringtoslicebyte(s String) (b Slice) { ...@@ -283,7 +283,7 @@ func stringtoslicebyte(s String) (b Slice) {
} }
func slicerunetostring(b Slice) (s String) { func slicerunetostring(b Slice) (s String) {
int32 siz1, siz2, i; intgo siz1, siz2, i;
int32 *a; int32 *a;
byte dum[8]; byte dum[8];
...@@ -306,7 +306,7 @@ func slicerunetostring(b Slice) (s String) { ...@@ -306,7 +306,7 @@ func slicerunetostring(b Slice) (s String) {
} }
func stringtoslicerune(s String) (b Slice) { func stringtoslicerune(s String) (b Slice) {
int32 n; intgo n;
int32 dum, *r; int32 dum, *r;
uint8 *p, *ep; uint8 *p, *ep;
...@@ -334,7 +334,7 @@ enum ...@@ -334,7 +334,7 @@ enum
Runeself = 0x80, Runeself = 0x80,
}; };
func stringiter(s String, k int32) (retk int32) { func stringiter(s String, k int) (retk int) {
int32 l; int32 l;
if(k >= s.len) { if(k >= s.len) {
...@@ -355,7 +355,7 @@ func stringiter(s String, k int32) (retk int32) { ...@@ -355,7 +355,7 @@ func stringiter(s String, k int32) (retk int32) {
out: out:
} }
func stringiter2(s String, k int32) (retk int32, retv int32) { func stringiter2(s String, k int) (retk int, retv int32) {
if(k >= s.len) { if(k >= s.len) {
// retk=0 is end of iteration // retk=0 is end of iteration
retk = 0; retk = 0;
......
...@@ -411,7 +411,7 @@ runtime·funcline(Func *f, uintptr targetpc) ...@@ -411,7 +411,7 @@ runtime·funcline(Func *f, uintptr targetpc)
} }
void void
runtime·funcline_go(Func *f, uintptr targetpc, String retfile, int32 retline) runtime·funcline_go(Func *f, uintptr targetpc, String retfile, intgo retline)
{ {
retfile = f->src; retfile = f->src;
retline = runtime·funcline(f, targetpc); retline = runtime·funcline(f, targetpc);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment