blob: b44eb929ccc153cfb23fcbcb8a233310453d3e3c [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;
Russ Cox0d3a0432009-03-30 00:01:07 -070021#else
22typedef uint32 uintptr;
23#endif
Ken Thompsonbbb20732008-06-05 19:38:39 -070024
25/*
26 * get rid of C types
Russ Cox3aa063d2008-11-23 17:08:55 -080027 * the / / / forces a syntax error immediately,
28 * which will show "last name: XXunsigned".
Ken Thompsonbbb20732008-06-05 19:38:39 -070029 */
Russ Cox3aa063d2008-11-23 17:08:55 -080030#define unsigned XXunsigned / / /
31#define signed XXsigned / / /
32#define char XXchar / / /
33#define short XXshort / / /
34#define int XXint / / /
35#define long XXlong / / /
36#define float XXfloat / / /
37#define double XXdouble / / /
Ken Thompsonbbb20732008-06-05 19:38:39 -070038
39/*
40 * defined types
41 */
42typedef uint8 bool;
43typedef uint8 byte;
Ken Thompson594175d2008-07-13 14:29:46 -070044typedef struct Alg Alg;
Russ Cox3aa063d2008-11-23 17:08:55 -080045typedef struct Func Func;
46typedef struct G G;
47typedef struct Gobuf Gobuf;
Russ Coxd28acc42008-08-04 16:43:49 -070048typedef struct Lock Lock;
Russ Cox3aa063d2008-11-23 17:08:55 -080049typedef struct M M;
Russ Coxd28acc42008-08-04 16:43:49 -070050typedef struct Mem Mem;
Russ Cox3aa063d2008-11-23 17:08:55 -080051typedef union Note Note;
Rob Pike87f22082009-08-25 15:54:25 -070052typedef struct Slice Slice;
Russ Cox3aa063d2008-11-23 17:08:55 -080053typedef struct Stktop Stktop;
Ken Thompson36570612009-04-09 18:16:21 -070054typedef struct String String;
Russ Cox3aa063d2008-11-23 17:08:55 -080055typedef struct Usema Usema;
Russ Coxc3077f72008-12-19 17:11:54 -080056typedef struct SigTab SigTab;
57typedef struct MCache MCache;
58typedef struct Iface Iface;
Russ Coxc7513ea2009-07-07 11:02:54 -070059typedef struct Itab Itab;
Russ Cox2da50222009-05-20 14:57:55 -070060typedef struct Eface Eface;
Russ Coxc7513ea2009-07-07 11:02:54 -070061typedef struct Type Type;
Ken Thompson1e1cc4e2009-01-27 12:03:53 -080062typedef struct Defer Defer;
Russ Cox764b6ec2009-07-08 13:55:57 -070063typedef struct hash Hmap;
Russ Cox5ddaf9a2009-07-08 15:00:54 -070064typedef struct Hchan Hchan;
Ken Thompson594175d2008-07-13 14:29:46 -070065
66/*
Rob Piked08f0062009-08-11 13:30:35 -070067 * per-cpu declaration.
68 * "extern register" is a special storage class implemented by 6c, 8c, etc.
69 * on machines with lots of registers, it allocates a register that will not be
70 * used in generated code. on the x86, it allocates a slot indexed by a
71 * segment register.
72 *
73 * amd64: allocated downwards from R15
74 * x86: allocated upwards from 0(FS)
75 * arm: allocated upwards from R9
Russ Cox653cef12009-08-26 10:47:18 -070076 *
Rob Piked08f0062009-08-11 13:30:35 -070077 * every C file linked into a Go program must include runtime.h
78 * so that the C compiler knows to avoid other uses of these registers.
79 * the Go compilers know to avoid them.
Ken Thompson594175d2008-07-13 14:29:46 -070080 */
Rob Piked08f0062009-08-11 13:30:35 -070081extern register G* g;
82extern register M* m;
Ken Thompson594175d2008-07-13 14:29:46 -070083
84/*
85 * defined constants
86 */
87enum
88{
89 // G status
90 Gidle,
91 Grunnable,
Russ Coxd28acc42008-08-04 16:43:49 -070092 Grunning,
Russ Cox3f8aa662008-12-05 15:24:18 -080093 Gsyscall,
Ken Thompson52620032008-07-14 14:33:39 -070094 Gwaiting,
Russ Cox96824002008-08-05 14:18:47 -070095 Gmoribund,
Ken Thompson594175d2008-07-13 14:29:46 -070096 Gdead,
Russ Cox133a1582009-10-03 10:37:12 -070097 Gcgocall,
Ken Thompson594175d2008-07-13 14:29:46 -070098};
99enum
100{
101 true = 1,
102 false = 0,
103};
104
105/*
106 * structures
107 */
Russ Coxd28acc42008-08-04 16:43:49 -0700108struct Lock
109{
110 uint32 key;
Russ Cox376898c2008-09-09 11:50:14 -0700111 uint32 sema; // for OS X
Russ Coxd28acc42008-08-04 16:43:49 -0700112};
Russ Cox5ff12f82008-09-24 10:25:28 -0700113struct Usema
114{
115 uint32 u;
116 uint32 k;
117};
Russ Cox376898c2008-09-09 11:50:14 -0700118union Note
Russ Coxd28acc42008-08-04 16:43:49 -0700119{
Russ Cox376898c2008-09-09 11:50:14 -0700120 struct { // Linux
121 Lock lock;
122 };
123 struct { // OS X
124 int32 wakeup;
Russ Cox5ff12f82008-09-24 10:25:28 -0700125 Usema sema;
Russ Cox376898c2008-09-09 11:50:14 -0700126 };
Russ Coxd28acc42008-08-04 16:43:49 -0700127};
Ken Thompson594175d2008-07-13 14:29:46 -0700128struct String
Ken Thompsonbbb20732008-06-05 19:38:39 -0700129{
Ken Thompson36570612009-04-09 18:16:21 -0700130 byte* str;
Ken Thompsonbbb20732008-06-05 19:38:39 -0700131 int32 len;
Ken Thompson594175d2008-07-13 14:29:46 -0700132};
Russ Coxc3077f72008-12-19 17:11:54 -0800133struct Iface
134{
Russ Coxc7513ea2009-07-07 11:02:54 -0700135 Itab* tab;
Ken Thompson36570612009-04-09 18:16:21 -0700136 void* data;
Russ Coxc3077f72008-12-19 17:11:54 -0800137};
Russ Cox2da50222009-05-20 14:57:55 -0700138struct Eface
139{
Russ Coxc7513ea2009-07-07 11:02:54 -0700140 Type* type;
Russ Cox2da50222009-05-20 14:57:55 -0700141 void* data;
142};
Ken Thompson66a603c2008-08-27 17:28:30 -0700143
Rob Pike87f22082009-08-25 15:54:25 -0700144struct Slice
Ken Thompson66a603c2008-08-27 17:28:30 -0700145{ // must not move anything
146 byte* array; // actual data
Rob Pike87f22082009-08-25 15:54:25 -0700147 uint32 len; // number of elements
Russ Cox75647d22008-11-17 12:32:35 -0800148 uint32 cap; // allocated number of elements
Ken Thompson66a603c2008-08-27 17:28:30 -0700149};
Ken Thompson751ce3a2008-07-11 19:16:39 -0700150struct Gobuf
151{
Russ Cox38020092009-06-17 16:31:02 -0700152 // The offsets of these fields are known to (hard-coded in) libmach.
Russ Cox7343e032009-06-17 15:12:16 -0700153 byte* sp;
154 byte* pc;
155 G* g;
Kai Backman111005d2009-06-25 11:26:10 -0700156 uintptr r0; // used on arm
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};
178struct Mem
179{
180 uint8* hunk;
181 uint32 nhunk;
182 uint64 nmmap;
183 uint64 nmal;
Ken Thompson45288542008-07-08 17:19:17 -0700184};
Ken Thompson45288542008-07-08 17:19:17 -0700185struct M
186{
Russ Cox38020092009-06-17 16:31:02 -0700187 // The offsets of these fields are known to (hard-coded in) libmach.
Russ Cox7343e032009-06-17 15:12:16 -0700188 G* g0; // goroutine with scheduling stack
189 void (*morepc)(void);
Russ Coxbba278a2009-07-08 18:16:09 -0700190 void* morefp; // frame pointer for more stack
Russ Cox7343e032009-06-17 15:12:16 -0700191 Gobuf morebuf; // gobuf arg to morestack
192
Russ Cox38020092009-06-17 16:31:02 -0700193 // Fields not known to debuggers.
Russ Cox7343e032009-06-17 15:12:16 -0700194 uint32 moreframe; // size arguments to morestack
195 uint32 moreargs;
196 uintptr cret; // return value from C
197 uint64 procid; // for debuggers, but offset not hard-coded
198 G* gsignal; // signal-handling G
199 uint32 tls[8]; // thread-local storage (for 386 extern register)
200 Gobuf sched; // scheduling stack
201 G* curg; // current running goroutine
Russ Coxefc86a72008-11-25 16:48:10 -0800202 int32 id;
Russ Coxda0a7d72008-12-19 03:13:39 -0800203 int32 mallocing;
Russ Cox8c357ce2009-06-15 21:31:56 -0700204 int32 gcing;
Russ Cox1ce17912009-01-26 17:37:05 -0800205 int32 locks;
Russ Cox218c3932009-07-13 17:28:39 -0700206 int32 waitnextg;
Russ Cox96824002008-08-05 14:18:47 -0700207 Note havenextg;
208 G* nextg;
Russ Cox93689d82009-10-09 15:35:33 -0700209 M* alllink; // on allm
Russ Cox96824002008-08-05 14:18:47 -0700210 M* schedlink;
Russ Coxd28acc42008-08-04 16:43:49 -0700211 Mem mem;
Russ Cox376898c2008-09-09 11:50:14 -0700212 uint32 machport; // Return address for Mach IPC (OS X)
Russ Coxe29ce172008-12-18 15:42:28 -0800213 MCache *mcache;
Russ Cox218c3932009-07-13 17:28:39 -0700214 G* lockedg;
Ken Thompson751ce3a2008-07-11 19:16:39 -0700215};
Ken Thompson52620032008-07-14 14:33:39 -0700216struct Stktop
Ken Thompson594175d2008-07-13 14:29:46 -0700217{
Russ Cox38020092009-06-17 16:31:02 -0700218 // The offsets of these fields are known to (hard-coded in) libmach.
Russ Cox7343e032009-06-17 15:12:16 -0700219 uint8* stackguard;
220 uint8* stackbase;
221 Gobuf gobuf;
222 uint32 args;
Russ Coxbba278a2009-07-08 18:16:09 -0700223
224 // Frame pointer: where args start in old frame.
225 // fp == gobuf.sp except in the case of a reflected
226 // function call, which uses an off-stack argument frame.
227 uint8* fp;
Ken Thompson45288542008-07-08 17:19:17 -0700228};
Ken Thompson594175d2008-07-13 14:29:46 -0700229struct Alg
Ken Thompson751ce3a2008-07-11 19:16:39 -0700230{
Russ Coxa52fb812009-06-04 21:09:06 -0700231 uintptr (*hash)(uint32, void*);
Ken Thompson594175d2008-07-13 14:29:46 -0700232 uint32 (*equal)(uint32, void*, void*);
233 void (*print)(uint32, void*);
234 void (*copy)(uint32, void*, void*);
Ken Thompson751ce3a2008-07-11 19:16:39 -0700235};
Ken Thompson594175d2008-07-13 14:29:46 -0700236struct SigTab
Ken Thompsonbbb20732008-06-05 19:38:39 -0700237{
Russ Coxdfa58932008-12-03 14:21:28 -0800238 int32 flags;
Ken Thompson594175d2008-07-13 14:29:46 -0700239 int8 *name;
Ken Thompsonbbb20732008-06-05 19:38:39 -0700240};
Russ Coxdfa58932008-12-03 14:21:28 -0800241enum
242{
243 SigCatch = 1<<0,
244 SigIgnore = 1<<1,
245 SigRestart = 1<<2,
246};
Ken Thompsonbbb20732008-06-05 19:38:39 -0700247
Russ Cox3aa063d2008-11-23 17:08:55 -0800248// (will be) shared with go; edit ../cmd/6g/sys.go too.
249// should move out of sys.go eventually.
250// also eventually, the loaded symbol table should
251// be closer to this form.
252struct Func
253{
Ken Thompson36570612009-04-09 18:16:21 -0700254 String name;
255 String type; // go type string
256 String src; // src file name
Russ Coxa5433362008-11-25 09:23:36 -0800257 uint64 entry; // entry pc
258 int64 frame; // stack frame size
Rob Pike87f22082009-08-25 15:54:25 -0700259 Slice pcln; // pc/ln tab for this func
Russ Coxa5433362008-11-25 09:23:36 -0800260 int64 pc0; // starting pc, ln for table
261 int32 ln0;
Russ Coxefc86a72008-11-25 16:48:10 -0800262 int32 args; // number of 32-bit in/out args
263 int32 locals; // number of 32-bit locals
Russ Cox3aa063d2008-11-23 17:08:55 -0800264};
265
Ken Thompsonbbb20732008-06-05 19:38:39 -0700266/*
267 * defined macros
268 * you need super-goru privilege
269 * to add this list.
270 */
271#define nelem(x) (sizeof(x)/sizeof((x)[0]))
272#define nil ((void*)0)
273
274/*
Russ Coxeee50ae2008-12-19 12:05:22 -0800275 * known to compiler
276 */
277enum
278{
Russ Coxa7f6d402009-01-26 09:56:42 -0800279 AMEM,
280 ANOEQ,
Russ Coxeee50ae2008-12-19 12:05:22 -0800281 ASTRING,
Russ Coxeee50ae2008-12-19 12:05:22 -0800282 AINTER,
Russ Cox2da50222009-05-20 14:57:55 -0700283 ANILINTER,
Russ Cox9b6d3852009-01-26 12:36:21 -0800284 AFAKE,
Russ Coxa7f6d402009-01-26 09:56:42 -0800285 Amax
Russ Coxeee50ae2008-12-19 12:05:22 -0800286};
287
Russ Cox29aa3ff2009-07-02 21:25:46 -0700288
289enum {
290 Structrnd = sizeof(uintptr)
291};
292
Russ Coxeee50ae2008-12-19 12:05:22 -0800293/*
Ken Thompson47ab1c12009-01-27 13:23:28 -0800294 * deferred subroutine calls
Ken Thompson1e1cc4e2009-01-27 12:03:53 -0800295 */
296struct Defer
297{
298 int32 siz;
299 byte* sp;
300 byte* fn;
301 Defer* link;
302 byte args[8]; // padded to actual size
303};
304
305/*
Ken Thompson594175d2008-07-13 14:29:46 -0700306 * external data
307 */
Russ Coxa7f6d402009-01-26 09:56:42 -0800308extern Alg algarray[Amax];
Ken Thompson36570612009-04-09 18:16:21 -0700309extern String emptystring;
Ken Thompson594175d2008-07-13 14:29:46 -0700310G* allg;
Russ Cox93689d82009-10-09 15:35:33 -0700311M* allm;
Ken Thompson594175d2008-07-13 14:29:46 -0700312int32 goidgen;
Russ Coxd28acc42008-08-04 16:43:49 -0700313extern int32 gomaxprocs;
Rob Pike6e8dbc22008-09-12 09:44:41 -0700314extern int32 panicking;
Ken Thompson79fbbe32008-11-05 21:50:28 -0800315extern int32 maxround;
Russ Cox1b14bdb2009-09-22 16:28:32 -0700316int8* goos;
Ken Thompson594175d2008-07-13 14:29:46 -0700317
318/*
Rob Pike8e82a672008-06-30 11:50:36 -0700319 * common functions and data
320 */
Ken Thompson751ce3a2008-07-11 19:16:39 -0700321int32 strcmp(byte*, byte*);
Russ Cox3aa063d2008-11-23 17:08:55 -0800322int32 findnull(byte*);
Rob Pike8e82a672008-06-30 11:50:36 -0700323void dump(byte*, int32);
Ken Thompson751ce3a2008-07-11 19:16:39 -0700324int32 runetochar(byte*, int32);
Rob Pike54ec7192009-04-12 17:01:17 -0700325int32 charntorune(int32*, uint8*, int32);
Rob Pike8e82a672008-06-30 11:50:36 -0700326
Rob Pike8e82a672008-06-30 11:50:36 -0700327/*
Ken Thompson4e8142c2008-06-16 22:34:50 -0700328 * very low level c-called
Ken Thompsonbbb20732008-06-05 19:38:39 -0700329 */
Russ Cox7343e032009-06-17 15:12:16 -0700330void gogo(Gobuf*, uintptr);
331void gogocall(Gobuf*, void(*)(void));
332uintptr gosave(Gobuf*);
333void sys·lessstack(void);
Russ Cox36096242009-01-16 14:58:14 -0800334void goargs(void);
Ken Thompsonbbb20732008-06-05 19:38:39 -0700335void FLUSH(void*);
Rob Piked3204ef2008-06-30 14:39:47 -0700336void* getu(void);
Ken Thompson4e8142c2008-06-16 22:34:50 -0700337void throw(int8*);
Ken Thompson594175d2008-07-13 14:29:46 -0700338uint32 rnd(uint32, uint32);
Ken Thompsonbbb20732008-06-05 19:38:39 -0700339void prints(int8*);
Russ Coxefc86a72008-11-25 16:48:10 -0800340void printf(int8*, ...);
Russ Cox3aa063d2008-11-23 17:08:55 -0800341byte* mchr(byte*, byte, byte*);
Ken Thompsone1a06cc2008-06-15 20:24:30 -0700342void mcpy(byte*, byte*, uint32);
Russ Cox9b6d3852009-01-26 12:36:21 -0800343int32 mcmp(byte*, byte*, uint32);
Ken Thompsonbc0b4f02008-11-13 10:35:44 -0800344void mmov(byte*, byte*, uint32);
Ken Thompsone1a06cc2008-06-15 20:24:30 -0700345void* mal(uint32);
Ken Thompson36570612009-04-09 18:16:21 -0700346uint32 cmpstring(String, String);
347String gostring(byte*);
Rob Pikeaeb43982008-06-21 15:36:23 -0700348void initsig(void);
Russ Coxfb40f882008-09-22 13:47:53 -0700349int32 gotraceback(void);
Ken Thompson751ce3a2008-07-11 19:16:39 -0700350void traceback(uint8 *pc, uint8 *sp, G* gp);
Rob Pike3835e012008-07-28 11:29:41 -0700351void tracebackothers(G*);
Rob Pikec870ac22008-07-14 20:54:55 -0700352int32 open(byte*, int32, ...);
Rob Pikec870ac22008-07-14 20:54:55 -0700353int32 write(int32, void*, int32);
Russ Coxd28acc42008-08-04 16:43:49 -0700354bool cas(uint32*, uint32, uint32);
Russ Coxaa3222d82009-06-02 23:02:12 -0700355void jmpdefer(byte*, void*);
Russ Coxd28acc42008-08-04 16:43:49 -0700356void exit1(int32);
357void ready(G*);
358byte* getenv(int8*);
359int32 atoi(byte*);
Russ Cox96824002008-08-05 14:18:47 -0700360void newosproc(M *m, G *g, void *stk, void (*fn)(void));
Russ Coxa67258f2008-09-18 15:56:46 -0700361void signalstack(byte*, int32);
362G* malg(int32);
363void minit(void);
Russ Cox0d3a0432009-03-30 00:01:07 -0700364Func* findfunc(uintptr);
Russ Coxa5433362008-11-25 09:23:36 -0800365int32 funcline(Func*, uint64);
Russ Cox79e1db22008-12-04 08:30:54 -0800366void* stackalloc(uint32);
367void stackfree(void*);
Russ Coxe29ce172008-12-18 15:42:28 -0800368MCache* allocmcache(void);
369void mallocinit(void);
Russ Coxa7f6d402009-01-26 09:56:42 -0800370bool ifaceeq(Iface, Iface);
Russ Cox2da50222009-05-20 14:57:55 -0700371bool efaceeq(Eface, Eface);
Russ Coxa52fb812009-06-04 21:09:06 -0700372uintptr ifacehash(Iface);
373uintptr efacehash(Eface);
374uintptr nohash(uint32, void*);
Russ Coxa7f6d402009-01-26 09:56:42 -0800375uint32 noequal(uint32, void*, void*);
Russ Cox1ce17912009-01-26 17:37:05 -0800376void* malloc(uintptr size);
377void* mallocgc(uintptr size);
378void free(void *v);
Russ Cox918afd942009-05-08 15:21:41 -0700379void exit(int32);
380void breakpoint(void);
381void gosched(void);
382void goexit(void);
Russ Cox133a1582009-10-03 10:37:12 -0700383void runcgo(void (*fn)(void*), void*);
Russ Coxd28acc42008-08-04 16:43:49 -0700384
Russ Cox5bb0c4f2008-12-15 10:50:33 -0800385#pragma varargck argpos printf 1
386
387#pragma varargck type "d" int32
388#pragma varargck type "d" uint32
389#pragma varargck type "D" int64
390#pragma varargck type "D" uint64
391#pragma varargck type "x" int32
392#pragma varargck type "x" uint32
393#pragma varargck type "X" int64
394#pragma varargck type "X" uint64
395#pragma varargck type "p" void*
Russ Cox0d3a0432009-03-30 00:01:07 -0700396#pragma varargck type "p" uintptr
Russ Cox5bb0c4f2008-12-15 10:50:33 -0800397#pragma varargck type "s" int8*
398#pragma varargck type "s" uint8*
Ken Thompson36570612009-04-09 18:16:21 -0700399#pragma varargck type "S" String
Russ Cox5bb0c4f2008-12-15 10:50:33 -0800400
Russ Cox3f8aa662008-12-05 15:24:18 -0800401// TODO(rsc): Remove. These are only temporary,
402// for the mark and sweep collector.
403void stoptheworld(void);
404void starttheworld(void);
405
Russ Coxd28acc42008-08-04 16:43:49 -0700406/*
407 * mutual exclusion locks. in the uncontended case,
408 * as fast as spin locks (just a few user-level instructions),
409 * but on the contention path they sleep in the kernel.
Russ Cox96824002008-08-05 14:18:47 -0700410 * a zeroed Lock is unlocked (no need to initialize each lock).
Russ Coxd28acc42008-08-04 16:43:49 -0700411 */
412void lock(Lock*);
413void unlock(Lock*);
Russ Coxd28acc42008-08-04 16:43:49 -0700414
415/*
Russ Cox96824002008-08-05 14:18:47 -0700416 * sleep and wakeup on one-time events.
Russ Coxf7f63292008-08-05 14:21:42 -0700417 * before any calls to notesleep or notewakeup,
Russ Cox96824002008-08-05 14:18:47 -0700418 * must call noteclear to initialize the Note.
419 * then, any number of threads can call notesleep
420 * and exactly one thread can call notewakeup (once).
421 * once notewakeup has been called, all the notesleeps
422 * will return. future notesleeps will return immediately.
Russ Coxd28acc42008-08-04 16:43:49 -0700423 */
Russ Cox96824002008-08-05 14:18:47 -0700424void noteclear(Note*);
425void notesleep(Note*);
426void notewakeup(Note*);
Ken Thompson4e8142c2008-06-16 22:34:50 -0700427
428/*
Ian Lance Taylor9b8da822009-01-13 09:55:24 -0800429 * Redefine methods for the benefit of gcc, which does not support
430 * UTF-8 characters in identifiers.
431 */
432#ifndef __GNUC__
Ian Lance Taylor9b8da822009-01-13 09:55:24 -0800433#define sys_memclr sys·memclr
Ian Lance Taylor9b8da822009-01-13 09:55:24 -0800434#define sys_getcallerpc sys·getcallerpc
Ian Lance Taylor9b8da822009-01-13 09:55:24 -0800435#define sys_mmap sys·mmap
Rob Pike87f22082009-08-25 15:54:25 -0700436#define sys_printslice sys·printslice
Ian Lance Taylor9b8da822009-01-13 09:55:24 -0800437#define sys_printbool sys·printbool
438#define sys_printfloat sys·printfloat
439#define sys_printhex sys·printhex
440#define sys_printint sys·printint
Russ Cox2da50222009-05-20 14:57:55 -0700441#define sys_printiface sys·printiface
442#define sys_printeface sys·printeface
Ian Lance Taylor9b8da822009-01-13 09:55:24 -0800443#define sys_printpc sys·printpc
444#define sys_printpointer sys·printpointer
445#define sys_printstring sys·printstring
446#define sys_printuint sys·printuint
Ian Lance Taylor9b8da822009-01-13 09:55:24 -0800447#define sys_setcallerpc sys·setcallerpc
Ian Lance Taylor9b8da822009-01-13 09:55:24 -0800448#endif
449
450/*
Russ Cox1f8a40d2009-01-22 16:23:44 -0800451 * low level go-called
Ken Thompson4e8142c2008-06-16 22:34:50 -0700452 */
Ian Lance Taylor9b8da822009-01-13 09:55:24 -0800453uint8* sys_mmap(byte*, uint32, int32, int32, int32, uint32);
454void sys_memclr(byte*, uint32);
455void sys_setcallerpc(void*, void*);
456void* sys_getcallerpc(void*);
Ken Thompsonbbb20732008-06-05 19:38:39 -0700457
458/*
Ken Thompson4e8142c2008-06-16 22:34:50 -0700459 * runtime go-called
Ken Thompsonbbb20732008-06-05 19:38:39 -0700460 */
Ian Lance Taylor9b8da822009-01-13 09:55:24 -0800461void sys_printbool(bool);
462void sys_printfloat(float64);
463void sys_printint(int64);
Russ Cox2da50222009-05-20 14:57:55 -0700464void sys_printiface(Iface);
465void sys_printeface(Eface);
Ken Thompson36570612009-04-09 18:16:21 -0700466void sys_printstring(String);
Ian Lance Taylor9b8da822009-01-13 09:55:24 -0800467void sys_printpc(void*);
468void sys_printpointer(void*);
469void sys_printuint(uint64);
470void sys_printhex(uint64);
Rob Pike87f22082009-08-25 15:54:25 -0700471void sys_printslice(Slice);
Rob Pike6db99de2008-07-08 10:36:43 -0700472
473/*
Russ Cox1f8a40d2009-01-22 16:23:44 -0800474 * wrapped for go users
Rob Pike6db99de2008-07-08 10:36:43 -0700475 */
Russ Cox1f8a40d2009-01-22 16:23:44 -0800476float64 Inf(int32 sign);
477float64 NaN(void);
478float32 float32frombits(uint32 i);
479uint32 float32tobits(float32 f);
480float64 float64frombits(uint64 i);
481uint64 float64tobits(float64 f);
482float64 frexp(float64 d, int32 *ep);
483bool isInf(float64 f, int32 sign);
484bool isNaN(float64 f);
485float64 ldexp(float64 d, int32 e);
486float64 modf(float64 d, float64 *ip);
487void semacquire(uint32*);
488void semrelease(uint32*);
Russ Cox5ddaf9a2009-07-08 15:00:54 -0700489
Russ Cox764b6ec2009-07-08 13:55:57 -0700490void mapassign(Hmap*, byte*, byte*);
491void mapaccess(Hmap*, byte*, byte*, bool*);
492struct hash_iter* mapiterinit(Hmap*);
493void mapiternext(struct hash_iter*);
494bool mapiterkey(struct hash_iter*, void*);
495void mapiterkeyvalue(struct hash_iter*, void*, void*);
Russ Cox7a0f4ca2009-09-08 13:46:54 -0700496Hmap* makemap(Type*, Type*, uint32);
Russ Cox5ddaf9a2009-07-08 15:00:54 -0700497
Russ Cox7a0f4ca2009-09-08 13:46:54 -0700498Hchan* makechan(Type*, uint32);
Russ Cox5ddaf9a2009-07-08 15:00:54 -0700499void chansend(Hchan*, void*, bool*);
500void chanrecv(Hchan*, void*, bool*);
Russ Cox653cef12009-08-26 10:47:18 -0700501void chanclose(Hchan*);
502bool chanclosed(Hchan*);
Russ Coxde7920e2009-08-26 12:42:22 -0700503int32 chanlen(Hchan*);
504int32 chancap(Hchan*);
Russ Cox92e92572009-07-10 16:32:26 -0700505
506void ifaceE2I(struct InterfaceType*, Eface, Iface*);