blob: 46df412b399c19c71922dfd875047bdffe576bf7 [file] [log] [blame]
Ken Thompsonbbb20732008-06-05 19:38:39 -07001// Copyright 2009 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
Ken Thompsonbbb20732008-06-05 19:38:39 -07005/*
6 * basic types
7 */
8typedef signed char int8;
9typedef unsigned char uint8;
10typedef signed short int16;
11typedef unsigned short uint16;
12typedef signed int int32;
13typedef unsigned int uint32;
14typedef signed long long int int64;
15typedef unsigned long long int uint64;
16typedef float float32;
17typedef double float64;
Russ Cox0d3a0432009-03-30 00:01:07 -070018
19#ifdef _64BIT
Russ Cox75647d22008-11-17 12:32:35 -080020typedef uint64 uintptr;
Devon H. O'Dell659780b2009-11-18 09:11:39 -080021typedef int64 intptr;
Russ Cox0d3a0432009-03-30 00:01:07 -070022#else
23typedef uint32 uintptr;
Devon H. O'Dell659780b2009-11-18 09:11:39 -080024typedef int32 intptr;
Russ Cox0d3a0432009-03-30 00:01:07 -070025#endif
Ken Thompsonbbb20732008-06-05 19:38:39 -070026
27/*
28 * get rid of C types
Russ Cox3aa063d2008-11-23 17:08:55 -080029 * the / / / forces a syntax error immediately,
30 * which will show "last name: XXunsigned".
Ken Thompsonbbb20732008-06-05 19:38:39 -070031 */
Russ Cox3aa063d2008-11-23 17:08:55 -080032#define unsigned XXunsigned / / /
33#define signed XXsigned / / /
34#define char XXchar / / /
35#define short XXshort / / /
36#define int XXint / / /
37#define long XXlong / / /
38#define float XXfloat / / /
39#define double XXdouble / / /
Ken Thompsonbbb20732008-06-05 19:38:39 -070040
41/*
42 * defined types
43 */
44typedef uint8 bool;
45typedef uint8 byte;
Ken Thompson594175d2008-07-13 14:29:46 -070046typedef struct Alg Alg;
Russ Cox3aa063d2008-11-23 17:08:55 -080047typedef struct Func Func;
48typedef struct G G;
49typedef struct Gobuf Gobuf;
Russ Coxd28acc42008-08-04 16:43:49 -070050typedef struct Lock Lock;
Russ Cox3aa063d2008-11-23 17:08:55 -080051typedef struct M M;
Russ Coxd28acc42008-08-04 16:43:49 -070052typedef struct Mem Mem;
Russ Cox3aa063d2008-11-23 17:08:55 -080053typedef union Note Note;
Rob Pike87f22082009-08-25 15:54:25 -070054typedef struct Slice Slice;
Russ Cox3aa063d2008-11-23 17:08:55 -080055typedef struct Stktop Stktop;
Ken Thompson36570612009-04-09 18:16:21 -070056typedef struct String String;
Russ Cox3aa063d2008-11-23 17:08:55 -080057typedef struct Usema Usema;
Russ Coxc3077f72008-12-19 17:11:54 -080058typedef struct SigTab SigTab;
59typedef struct MCache MCache;
60typedef struct Iface Iface;
Russ Coxc7513ea2009-07-07 11:02:54 -070061typedef struct Itab Itab;
Russ Cox2da50222009-05-20 14:57:55 -070062typedef struct Eface Eface;
Russ Coxc7513ea2009-07-07 11:02:54 -070063typedef struct Type Type;
Ken Thompson1e1cc4e2009-01-27 12:03:53 -080064typedef struct Defer Defer;
Russ Cox764b6ec2009-07-08 13:55:57 -070065typedef struct hash Hmap;
Russ Cox5ddaf9a2009-07-08 15:00:54 -070066typedef struct Hchan Hchan;
Ken Thompson594175d2008-07-13 14:29:46 -070067
68/*
Rob Piked08f0062009-08-11 13:30:35 -070069 * per-cpu declaration.
70 * "extern register" is a special storage class implemented by 6c, 8c, etc.
71 * on machines with lots of registers, it allocates a register that will not be
72 * used in generated code. on the x86, it allocates a slot indexed by a
73 * segment register.
74 *
75 * amd64: allocated downwards from R15
76 * x86: allocated upwards from 0(FS)
77 * arm: allocated upwards from R9
Russ Cox653cef12009-08-26 10:47:18 -070078 *
Rob Piked08f0062009-08-11 13:30:35 -070079 * every C file linked into a Go program must include runtime.h
80 * so that the C compiler knows to avoid other uses of these registers.
81 * the Go compilers know to avoid them.
Ken Thompson594175d2008-07-13 14:29:46 -070082 */
Rob Piked08f0062009-08-11 13:30:35 -070083extern register G* g;
84extern register M* m;
Ken Thompson594175d2008-07-13 14:29:46 -070085
86/*
87 * defined constants
88 */
89enum
90{
91 // G status
92 Gidle,
93 Grunnable,
Russ Coxd28acc42008-08-04 16:43:49 -070094 Grunning,
Russ Cox3f8aa662008-12-05 15:24:18 -080095 Gsyscall,
Ken Thompson52620032008-07-14 14:33:39 -070096 Gwaiting,
Russ Cox96824002008-08-05 14:18:47 -070097 Gmoribund,
Ken Thompson594175d2008-07-13 14:29:46 -070098 Gdead,
99};
100enum
101{
102 true = 1,
103 false = 0,
104};
105
106/*
107 * structures
108 */
Russ Coxd28acc42008-08-04 16:43:49 -0700109struct Lock
110{
111 uint32 key;
Russ Cox376898c2008-09-09 11:50:14 -0700112 uint32 sema; // for OS X
Russ Coxd28acc42008-08-04 16:43:49 -0700113};
Russ Cox5ff12f82008-09-24 10:25:28 -0700114struct Usema
115{
116 uint32 u;
117 uint32 k;
118};
Russ Cox376898c2008-09-09 11:50:14 -0700119union Note
Russ Coxd28acc42008-08-04 16:43:49 -0700120{
Russ Cox376898c2008-09-09 11:50:14 -0700121 struct { // Linux
122 Lock lock;
123 };
124 struct { // OS X
125 int32 wakeup;
Russ Cox5ff12f82008-09-24 10:25:28 -0700126 Usema sema;
Russ Cox376898c2008-09-09 11:50:14 -0700127 };
Russ Coxd28acc42008-08-04 16:43:49 -0700128};
Ken Thompson594175d2008-07-13 14:29:46 -0700129struct String
Ken Thompsonbbb20732008-06-05 19:38:39 -0700130{
Ken Thompson36570612009-04-09 18:16:21 -0700131 byte* str;
Ken Thompsonbbb20732008-06-05 19:38:39 -0700132 int32 len;
Ken Thompson594175d2008-07-13 14:29:46 -0700133};
Russ Coxc3077f72008-12-19 17:11:54 -0800134struct Iface
135{
Russ Coxc7513ea2009-07-07 11:02:54 -0700136 Itab* tab;
Ken Thompson36570612009-04-09 18:16:21 -0700137 void* data;
Russ Coxc3077f72008-12-19 17:11:54 -0800138};
Russ Cox2da50222009-05-20 14:57:55 -0700139struct Eface
140{
Russ Coxc7513ea2009-07-07 11:02:54 -0700141 Type* type;
Russ Cox2da50222009-05-20 14:57:55 -0700142 void* data;
143};
Ken Thompson66a603c2008-08-27 17:28:30 -0700144
Rob Pike87f22082009-08-25 15:54:25 -0700145struct Slice
Ken Thompson66a603c2008-08-27 17:28:30 -0700146{ // must not move anything
147 byte* array; // actual data
Rob Pike87f22082009-08-25 15:54:25 -0700148 uint32 len; // number of elements
Russ Cox75647d22008-11-17 12:32:35 -0800149 uint32 cap; // allocated number of elements
Ken Thompson66a603c2008-08-27 17:28:30 -0700150};
Ken Thompson751ce3a2008-07-11 19:16:39 -0700151struct Gobuf
152{
Russ Cox38020092009-06-17 16:31:02 -0700153 // The offsets of these fields are known to (hard-coded in) libmach.
Russ Cox7343e032009-06-17 15:12:16 -0700154 byte* sp;
155 byte* pc;
156 G* g;
Ken Thompson751ce3a2008-07-11 19:16:39 -0700157};
Ken Thompson7b454bb2008-07-09 11:35:26 -0700158struct G
Ken Thompson45288542008-07-08 17:19:17 -0700159{
Russ Cox133a1582009-10-03 10:37:12 -0700160 byte* stackguard; // cannot move - also known to linker, libmach, libcgo
161 byte* stackbase; // cannot move - also known to libmach, libcgo
Russ Cox7343e032009-06-17 15:12:16 -0700162 Defer* defer;
Russ Cox38020092009-06-17 16:31:02 -0700163 Gobuf sched; // cannot move - also known to libmach
Russ Cox133a1582009-10-03 10:37:12 -0700164 byte* stack0;
Russ Cox7343e032009-06-17 15:12:16 -0700165 byte* entry; // initial function
Rob Pike3835e012008-07-28 11:29:41 -0700166 G* alllink; // on allg
Ken Thompsone963cba2008-07-25 15:55:12 -0700167 void* param; // passed parameter on wakeup
168 int16 status;
Ken Thompson751ce3a2008-07-11 19:16:39 -0700169 int32 goid;
Ken Thompsone963cba2008-07-25 15:55:12 -0700170 int32 selgen; // valid sudog pointer
Russ Cox96824002008-08-05 14:18:47 -0700171 G* schedlink;
Ken Thompson1e1cc4e2009-01-27 12:03:53 -0800172 bool readyonstop;
Russ Cox7343e032009-06-17 15:12:16 -0700173 M* m; // for debuggers, but offset not hard-coded
Russ Cox218c3932009-07-13 17:28:39 -0700174 M* lockedm;
Russ Cox133a1582009-10-03 10:37:12 -0700175 void (*cgofn)(void*); // for cgo/ffi
176 void *cgoarg;
Russ Coxd28acc42008-08-04 16:43:49 -0700177};
Ken Thompson45288542008-07-08 17:19:17 -0700178struct M
179{
Russ Cox38020092009-06-17 16:31:02 -0700180 // The offsets of these fields are known to (hard-coded in) libmach.
Russ Cox7343e032009-06-17 15:12:16 -0700181 G* g0; // goroutine with scheduling stack
182 void (*morepc)(void);
Russ Coxbba278a2009-07-08 18:16:09 -0700183 void* morefp; // frame pointer for more stack
Russ Cox7343e032009-06-17 15:12:16 -0700184 Gobuf morebuf; // gobuf arg to morestack
185
Russ Cox38020092009-06-17 16:31:02 -0700186 // Fields not known to debuggers.
Russ Cox7343e032009-06-17 15:12:16 -0700187 uint32 moreframe; // size arguments to morestack
188 uint32 moreargs;
189 uintptr cret; // return value from C
190 uint64 procid; // for debuggers, but offset not hard-coded
191 G* gsignal; // signal-handling G
192 uint32 tls[8]; // thread-local storage (for 386 extern register)
193 Gobuf sched; // scheduling stack
194 G* curg; // current running goroutine
Russ Coxefc86a72008-11-25 16:48:10 -0800195 int32 id;
Russ Coxda0a7d72008-12-19 03:13:39 -0800196 int32 mallocing;
Russ Cox8c357ce2009-06-15 21:31:56 -0700197 int32 gcing;
Russ Cox1ce17912009-01-26 17:37:05 -0800198 int32 locks;
Russ Cox218c3932009-07-13 17:28:39 -0700199 int32 waitnextg;
Russ Cox96824002008-08-05 14:18:47 -0700200 Note havenextg;
201 G* nextg;
Russ Cox93689d82009-10-09 15:35:33 -0700202 M* alllink; // on allm
Russ Cox96824002008-08-05 14:18:47 -0700203 M* schedlink;
Russ Cox376898c2008-09-09 11:50:14 -0700204 uint32 machport; // Return address for Mach IPC (OS X)
Russ Coxe29ce172008-12-18 15:42:28 -0800205 MCache *mcache;
Russ Cox218c3932009-07-13 17:28:39 -0700206 G* lockedg;
Ken Thompson751ce3a2008-07-11 19:16:39 -0700207};
Ken Thompson52620032008-07-14 14:33:39 -0700208struct Stktop
Ken Thompson594175d2008-07-13 14:29:46 -0700209{
Russ Cox38020092009-06-17 16:31:02 -0700210 // The offsets of these fields are known to (hard-coded in) libmach.
Russ Cox7343e032009-06-17 15:12:16 -0700211 uint8* stackguard;
212 uint8* stackbase;
213 Gobuf gobuf;
214 uint32 args;
Russ Coxbba278a2009-07-08 18:16:09 -0700215
216 // Frame pointer: where args start in old frame.
217 // fp == gobuf.sp except in the case of a reflected
218 // function call, which uses an off-stack argument frame.
219 uint8* fp;
Ken Thompson45288542008-07-08 17:19:17 -0700220};
Ken Thompson594175d2008-07-13 14:29:46 -0700221struct Alg
Ken Thompson751ce3a2008-07-11 19:16:39 -0700222{
Russ Coxa52fb812009-06-04 21:09:06 -0700223 uintptr (*hash)(uint32, void*);
Ken Thompson594175d2008-07-13 14:29:46 -0700224 uint32 (*equal)(uint32, void*, void*);
225 void (*print)(uint32, void*);
226 void (*copy)(uint32, void*, void*);
Ken Thompson751ce3a2008-07-11 19:16:39 -0700227};
Ken Thompson594175d2008-07-13 14:29:46 -0700228struct SigTab
Ken Thompsonbbb20732008-06-05 19:38:39 -0700229{
Russ Coxdfa58932008-12-03 14:21:28 -0800230 int32 flags;
Ken Thompson594175d2008-07-13 14:29:46 -0700231 int8 *name;
Ken Thompsonbbb20732008-06-05 19:38:39 -0700232};
Russ Coxdfa58932008-12-03 14:21:28 -0800233enum
234{
235 SigCatch = 1<<0,
236 SigIgnore = 1<<1,
237 SigRestart = 1<<2,
David Symondsb5866492009-12-15 18:21:29 -0800238 SigQueue = 1<<3,
Russ Coxdfa58932008-12-03 14:21:28 -0800239};
Ken Thompsonbbb20732008-06-05 19:38:39 -0700240
Russ Cox3aa063d2008-11-23 17:08:55 -0800241// (will be) shared with go; edit ../cmd/6g/sys.go too.
242// should move out of sys.go eventually.
243// also eventually, the loaded symbol table should
244// be closer to this form.
245struct Func
246{
Ken Thompson36570612009-04-09 18:16:21 -0700247 String name;
248 String type; // go type string
249 String src; // src file name
Russ Coxa5433362008-11-25 09:23:36 -0800250 uint64 entry; // entry pc
251 int64 frame; // stack frame size
Rob Pike87f22082009-08-25 15:54:25 -0700252 Slice pcln; // pc/ln tab for this func
Russ Coxa5433362008-11-25 09:23:36 -0800253 int64 pc0; // starting pc, ln for table
254 int32 ln0;
Russ Coxefc86a72008-11-25 16:48:10 -0800255 int32 args; // number of 32-bit in/out args
256 int32 locals; // number of 32-bit locals
Russ Cox3aa063d2008-11-23 17:08:55 -0800257};
258
Ken Thompsonbbb20732008-06-05 19:38:39 -0700259/*
260 * defined macros
261 * you need super-goru privilege
262 * to add this list.
263 */
264#define nelem(x) (sizeof(x)/sizeof((x)[0]))
265#define nil ((void*)0)
266
267/*
Russ Coxeee50ae2008-12-19 12:05:22 -0800268 * known to compiler
269 */
270enum
271{
Russ Coxa7f6d402009-01-26 09:56:42 -0800272 AMEM,
273 ANOEQ,
Russ Coxeee50ae2008-12-19 12:05:22 -0800274 ASTRING,
Russ Coxeee50ae2008-12-19 12:05:22 -0800275 AINTER,
Russ Cox2da50222009-05-20 14:57:55 -0700276 ANILINTER,
Russ Cox9b6d3852009-01-26 12:36:21 -0800277 AFAKE,
Russ Coxa7f6d402009-01-26 09:56:42 -0800278 Amax
Russ Coxeee50ae2008-12-19 12:05:22 -0800279};
280
Russ Cox29aa3ff2009-07-02 21:25:46 -0700281
282enum {
283 Structrnd = sizeof(uintptr)
284};
285
Russ Coxeee50ae2008-12-19 12:05:22 -0800286/*
Ken Thompson47ab1c12009-01-27 13:23:28 -0800287 * deferred subroutine calls
Ken Thompson1e1cc4e2009-01-27 12:03:53 -0800288 */
289struct Defer
290{
291 int32 siz;
292 byte* sp;
293 byte* fn;
294 Defer* link;
295 byte args[8]; // padded to actual size
296};
297
298/*
Ken Thompson594175d2008-07-13 14:29:46 -0700299 * external data
300 */
Russ Coxa7f6d402009-01-26 09:56:42 -0800301extern Alg algarray[Amax];
Ken Thompson36570612009-04-09 18:16:21 -0700302extern String emptystring;
Ken Thompson594175d2008-07-13 14:29:46 -0700303G* allg;
Russ Cox93689d82009-10-09 15:35:33 -0700304M* allm;
Ken Thompson594175d2008-07-13 14:29:46 -0700305int32 goidgen;
Russ Coxd28acc42008-08-04 16:43:49 -0700306extern int32 gomaxprocs;
Rob Pike6e8dbc22008-09-12 09:44:41 -0700307extern int32 panicking;
Ken Thompson79fbbe32008-11-05 21:50:28 -0800308extern int32 maxround;
Rob Pikef6d67c92009-10-13 22:48:03 -0700309extern int32 fd; // usually 1; set to 2 when panicking
Russ Cox1b14bdb2009-09-22 16:28:32 -0700310int8* goos;
Ken Thompson594175d2008-07-13 14:29:46 -0700311
312/*
Rob Pike8e82a672008-06-30 11:50:36 -0700313 * common functions and data
314 */
Ken Thompson751ce3a2008-07-11 19:16:39 -0700315int32 strcmp(byte*, byte*);
Russ Cox3aa063d2008-11-23 17:08:55 -0800316int32 findnull(byte*);
Rob Pike8e82a672008-06-30 11:50:36 -0700317void dump(byte*, int32);
Ken Thompson751ce3a2008-07-11 19:16:39 -0700318int32 runetochar(byte*, int32);
Rob Pike54ec7192009-04-12 17:01:17 -0700319int32 charntorune(int32*, uint8*, int32);
Rob Pike8e82a672008-06-30 11:50:36 -0700320
Rob Pike8e82a672008-06-30 11:50:36 -0700321/*
Ken Thompson4e8142c2008-06-16 22:34:50 -0700322 * very low level c-called
Ken Thompsonbbb20732008-06-05 19:38:39 -0700323 */
Russ Cox7343e032009-06-17 15:12:16 -0700324void gogo(Gobuf*, uintptr);
325void gogocall(Gobuf*, void(*)(void));
326uintptr gosave(Gobuf*);
Russ Cox22a5c782009-10-15 23:10:49 -0700327void runtime·lessstack(void);
Russ Cox36096242009-01-16 14:58:14 -0800328void goargs(void);
Ken Thompsonbbb20732008-06-05 19:38:39 -0700329void FLUSH(void*);
Rob Piked3204ef2008-06-30 14:39:47 -0700330void* getu(void);
Ken Thompson4e8142c2008-06-16 22:34:50 -0700331void throw(int8*);
Ken Thompson594175d2008-07-13 14:29:46 -0700332uint32 rnd(uint32, uint32);
Ken Thompsonbbb20732008-06-05 19:38:39 -0700333void prints(int8*);
Russ Coxefc86a72008-11-25 16:48:10 -0800334void printf(int8*, ...);
Russ Cox3aa063d2008-11-23 17:08:55 -0800335byte* mchr(byte*, byte, byte*);
Ken Thompsone1a06cc2008-06-15 20:24:30 -0700336void mcpy(byte*, byte*, uint32);
Russ Cox9b6d3852009-01-26 12:36:21 -0800337int32 mcmp(byte*, byte*, uint32);
Russ Cox652f5562009-11-20 09:11:46 -0800338void memmove(void*, void*, uint32);
Ken Thompsone1a06cc2008-06-15 20:24:30 -0700339void* mal(uint32);
Ken Thompson36570612009-04-09 18:16:21 -0700340uint32 cmpstring(String, String);
341String gostring(byte*);
Rob Pikeaeb43982008-06-21 15:36:23 -0700342void initsig(void);
Russ Coxfb40f882008-09-22 13:47:53 -0700343int32 gotraceback(void);
Ken Thompson751ce3a2008-07-11 19:16:39 -0700344void traceback(uint8 *pc, uint8 *sp, G* gp);
Rob Pike3835e012008-07-28 11:29:41 -0700345void tracebackothers(G*);
Rob Pikec870ac22008-07-14 20:54:55 -0700346int32 open(byte*, int32, ...);
Rob Pikec870ac22008-07-14 20:54:55 -0700347int32 write(int32, void*, int32);
Russ Coxd28acc42008-08-04 16:43:49 -0700348bool cas(uint32*, uint32, uint32);
Russ Coxaa3222d82009-06-02 23:02:12 -0700349void jmpdefer(byte*, void*);
Russ Coxd28acc42008-08-04 16:43:49 -0700350void exit1(int32);
351void ready(G*);
352byte* getenv(int8*);
353int32 atoi(byte*);
Russ Cox96824002008-08-05 14:18:47 -0700354void newosproc(M *m, G *g, void *stk, void (*fn)(void));
Russ Coxa67258f2008-09-18 15:56:46 -0700355void signalstack(byte*, int32);
356G* malg(int32);
357void minit(void);
Russ Cox0d3a0432009-03-30 00:01:07 -0700358Func* findfunc(uintptr);
Russ Coxa5433362008-11-25 09:23:36 -0800359int32 funcline(Func*, uint64);
Russ Cox79e1db22008-12-04 08:30:54 -0800360void* stackalloc(uint32);
361void stackfree(void*);
Russ Coxe29ce172008-12-18 15:42:28 -0800362MCache* allocmcache(void);
363void mallocinit(void);
Russ Coxa7f6d402009-01-26 09:56:42 -0800364bool ifaceeq(Iface, Iface);
Russ Cox2da50222009-05-20 14:57:55 -0700365bool efaceeq(Eface, Eface);
Russ Coxa52fb812009-06-04 21:09:06 -0700366uintptr ifacehash(Iface);
367uintptr efacehash(Eface);
368uintptr nohash(uint32, void*);
Russ Coxa7f6d402009-01-26 09:56:42 -0800369uint32 noequal(uint32, void*, void*);
Russ Cox1ce17912009-01-26 17:37:05 -0800370void* malloc(uintptr size);
Russ Cox1ce17912009-01-26 17:37:05 -0800371void free(void *v);
Russ Cox918afd942009-05-08 15:21:41 -0700372void exit(int32);
373void breakpoint(void);
374void gosched(void);
375void goexit(void);
Russ Cox133a1582009-10-03 10:37:12 -0700376void runcgo(void (*fn)(void*), void*);
David Symondsb5866492009-12-15 18:21:29 -0800377void entersyscall(void);
378void exitsyscall(void);
379void siginit(void);
380void sigsend(int32 sig);
Russ Coxd28acc42008-08-04 16:43:49 -0700381
Russ Cox5bb0c4f2008-12-15 10:50:33 -0800382#pragma varargck argpos printf 1
383
384#pragma varargck type "d" int32
385#pragma varargck type "d" uint32
386#pragma varargck type "D" int64
387#pragma varargck type "D" uint64
388#pragma varargck type "x" int32
389#pragma varargck type "x" uint32
390#pragma varargck type "X" int64
391#pragma varargck type "X" uint64
392#pragma varargck type "p" void*
Russ Cox0d3a0432009-03-30 00:01:07 -0700393#pragma varargck type "p" uintptr
Russ Cox5bb0c4f2008-12-15 10:50:33 -0800394#pragma varargck type "s" int8*
395#pragma varargck type "s" uint8*
Ken Thompson36570612009-04-09 18:16:21 -0700396#pragma varargck type "S" String
Russ Cox5bb0c4f2008-12-15 10:50:33 -0800397
Russ Cox3f8aa662008-12-05 15:24:18 -0800398// TODO(rsc): Remove. These are only temporary,
399// for the mark and sweep collector.
400void stoptheworld(void);
401void starttheworld(void);
402
Russ Coxd28acc42008-08-04 16:43:49 -0700403/*
404 * mutual exclusion locks. in the uncontended case,
405 * as fast as spin locks (just a few user-level instructions),
406 * but on the contention path they sleep in the kernel.
Russ Cox96824002008-08-05 14:18:47 -0700407 * a zeroed Lock is unlocked (no need to initialize each lock).
Russ Coxd28acc42008-08-04 16:43:49 -0700408 */
409void lock(Lock*);
410void unlock(Lock*);
Russ Coxd28acc42008-08-04 16:43:49 -0700411
412/*
Russ Coxa68592a2009-10-14 13:02:05 -0700413 * sleep and wakeup on one-time events.
Russ Coxf7f63292008-08-05 14:21:42 -0700414 * before any calls to notesleep or notewakeup,
Russ Cox96824002008-08-05 14:18:47 -0700415 * must call noteclear to initialize the Note.
416 * then, any number of threads can call notesleep
417 * and exactly one thread can call notewakeup (once).
418 * once notewakeup has been called, all the notesleeps
419 * will return. future notesleeps will return immediately.
Russ Coxd28acc42008-08-04 16:43:49 -0700420 */
Russ Cox96824002008-08-05 14:18:47 -0700421void noteclear(Note*);
422void notesleep(Note*);
423void notewakeup(Note*);
Ken Thompson4e8142c2008-06-16 22:34:50 -0700424
425/*
Ian Lance Taylor9b8da822009-01-13 09:55:24 -0800426 * Redefine methods for the benefit of gcc, which does not support
427 * UTF-8 characters in identifiers.
428 */
429#ifndef __GNUC__
Russ Cox22a5c782009-10-15 23:10:49 -0700430#define runtime_memclr runtime·memclr
431#define runtime_getcallerpc runtime·getcallerpc
432#define runtime_mmap runtime·mmap
433#define runtime_printslice runtime·printslice
434#define runtime_printbool runtime·printbool
435#define runtime_printfloat runtime·printfloat
436#define runtime_printhex runtime·printhex
437#define runtime_printint runtime·printint
438#define runtime_printiface runtime·printiface
439#define runtime_printeface runtime·printeface
440#define runtime_printpc runtime·printpc
441#define runtime_printpointer runtime·printpointer
442#define runtime_printstring runtime·printstring
443#define runtime_printuint runtime·printuint
444#define runtime_setcallerpc runtime·setcallerpc
Ian Lance Taylor9b8da822009-01-13 09:55:24 -0800445#endif
446
447/*
Adam Langley3f7a3242009-11-13 10:08:51 -0800448 * This is consistent across Linux and BSD.
449 * If a new OS is added that is different, move this to
450 * $GOOS/$GOARCH/defs.h.
451 */
452#define EACCES 13
453
454/*
Russ Cox1f8a40d2009-01-22 16:23:44 -0800455 * low level go-called
Ken Thompson4e8142c2008-06-16 22:34:50 -0700456 */
Russ Cox22a5c782009-10-15 23:10:49 -0700457uint8* runtime_mmap(byte*, uint32, int32, int32, int32, uint32);
458void runtime_memclr(byte*, uint32);
459void runtime_setcallerpc(void*, void*);
460void* runtime_getcallerpc(void*);
Ken Thompsonbbb20732008-06-05 19:38:39 -0700461
462/*
Ken Thompson4e8142c2008-06-16 22:34:50 -0700463 * runtime go-called
Ken Thompsonbbb20732008-06-05 19:38:39 -0700464 */
Russ Cox22a5c782009-10-15 23:10:49 -0700465void runtime_printbool(bool);
466void runtime_printfloat(float64);
467void runtime_printint(int64);
468void runtime_printiface(Iface);
469void runtime_printeface(Eface);
470void runtime_printstring(String);
471void runtime_printpc(void*);
472void runtime_printpointer(void*);
473void runtime_printuint(uint64);
474void runtime_printhex(uint64);
475void runtime_printslice(Slice);
Rob Pike6db99de2008-07-08 10:36:43 -0700476
477/*
Russ Cox1f8a40d2009-01-22 16:23:44 -0800478 * wrapped for go users
Rob Pike6db99de2008-07-08 10:36:43 -0700479 */
Russ Cox1f8a40d2009-01-22 16:23:44 -0800480float64 Inf(int32 sign);
481float64 NaN(void);
482float32 float32frombits(uint32 i);
483uint32 float32tobits(float32 f);
484float64 float64frombits(uint64 i);
485uint64 float64tobits(float64 f);
486float64 frexp(float64 d, int32 *ep);
487bool isInf(float64 f, int32 sign);
488bool isNaN(float64 f);
489float64 ldexp(float64 d, int32 e);
490float64 modf(float64 d, float64 *ip);
491void semacquire(uint32*);
492void semrelease(uint32*);
David Symondsb5866492009-12-15 18:21:29 -0800493String signame(int32 sig);
494
Russ Cox5ddaf9a2009-07-08 15:00:54 -0700495
Russ Cox764b6ec2009-07-08 13:55:57 -0700496void mapassign(Hmap*, byte*, byte*);
497void mapaccess(Hmap*, byte*, byte*, bool*);
498struct hash_iter* mapiterinit(Hmap*);
499void mapiternext(struct hash_iter*);
500bool mapiterkey(struct hash_iter*, void*);
501void mapiterkeyvalue(struct hash_iter*, void*, void*);
Russ Cox7a0f4ca2009-09-08 13:46:54 -0700502Hmap* makemap(Type*, Type*, uint32);
Russ Cox5ddaf9a2009-07-08 15:00:54 -0700503
Russ Cox7a0f4ca2009-09-08 13:46:54 -0700504Hchan* makechan(Type*, uint32);
Russ Cox5ddaf9a2009-07-08 15:00:54 -0700505void chansend(Hchan*, void*, bool*);
506void chanrecv(Hchan*, void*, bool*);
Russ Cox653cef12009-08-26 10:47:18 -0700507void chanclose(Hchan*);
508bool chanclosed(Hchan*);
Russ Coxde7920e2009-08-26 12:42:22 -0700509int32 chanlen(Hchan*);
510int32 chancap(Hchan*);
Russ Cox92e92572009-07-10 16:32:26 -0700511
512void ifaceE2I(struct InterfaceType*, Eface, Iface*);