LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 #include "runtime.h" | 5 #include "runtime.h" |
6 #include "stack.h" | 6 #include "stack.h" |
7 | 7 |
8 enum { | 8 enum { |
9 maxround = sizeof(uintptr), | 9 maxround = sizeof(uintptr), |
10 }; | 10 }; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 runtime·printf("throw: %s\n", s); | 112 runtime·printf("throw: %s\n", s); |
113 runtime·dopanic(0); | 113 runtime·dopanic(0); |
114 *(int32*)0 = 0; // not reached | 114 *(int32*)0 = 0; // not reached |
115 runtime·exit(1); // even more not reached | 115 runtime·exit(1); // even more not reached |
116 } | 116 } |
117 | 117 |
118 void | 118 void |
119 runtime·panicstring(int8 *s) | 119 runtime·panicstring(int8 *s) |
120 { | 120 { |
121 Eface err; | 121 Eface err; |
122 » | 122 |
123 if(m->gcing) { | 123 if(m->gcing) { |
124 runtime·printf("panic: %s\n", s); | 124 runtime·printf("panic: %s\n", s); |
125 runtime·throw("panic during gc"); | 125 runtime·throw("panic during gc"); |
126 } | 126 } |
127 runtime·newErrorString(runtime·gostringnocopy((byte*)s), &err); | 127 runtime·newErrorString(runtime·gostringnocopy((byte*)s), &err); |
128 runtime·panic(err); | 128 runtime·panic(err); |
129 } | 129 } |
130 | 130 |
131 int32 | 131 int32 |
132 runtime·mcmp(byte *s1, byte *s2, uint32 n) | 132 runtime·mcmp(byte *s1, byte *s2, uint32 n) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 } | 182 } |
183 | 183 |
184 int32 runtime·isplan9; | 184 int32 runtime·isplan9; |
185 int32 runtime·iswindows; | 185 int32 runtime·iswindows; |
186 | 186 |
187 void | 187 void |
188 runtime·goargs(void) | 188 runtime·goargs(void) |
189 { | 189 { |
190 String *s; | 190 String *s; |
191 int32 i; | 191 int32 i; |
192 » | 192 |
193 // for windows implementation see "os" package | 193 // for windows implementation see "os" package |
194 if(Windows) | 194 if(Windows) |
195 return; | 195 return; |
196 | 196 |
197 s = runtime·malloc(argc*sizeof s[0]); | 197 s = runtime·malloc(argc*sizeof s[0]); |
198 for(i=0; i<argc; i++) | 198 for(i=0; i<argc; i++) |
199 s[i] = runtime·gostringnocopy(argv[i]); | 199 s[i] = runtime·gostringnocopy(argv[i]); |
200 os·Args.array = (byte*)s; | 200 os·Args.array = (byte*)s; |
201 os·Args.len = argc; | 201 os·Args.len = argc; |
202 os·Args.cap = argc; | 202 os·Args.cap = argc; |
203 } | 203 } |
204 | 204 |
205 void | 205 void |
206 runtime·goenvs_unix(void) | 206 runtime·goenvs_unix(void) |
207 { | 207 { |
208 String *s; | 208 String *s; |
209 int32 i, n; | 209 int32 i, n; |
210 » | 210 |
211 for(n=0; argv[argc+1+n] != 0; n++) | 211 for(n=0; argv[argc+1+n] != 0; n++) |
212 ; | 212 ; |
213 | 213 |
214 s = runtime·malloc(n*sizeof s[0]); | 214 s = runtime·malloc(n*sizeof s[0]); |
215 for(i=0; i<n; i++) | 215 for(i=0; i<n; i++) |
216 s[i] = runtime·gostringnocopy(argv[argc+1+i]); | 216 s[i] = runtime·gostringnocopy(argv[argc+1+i]); |
217 syscall·envs.array = (byte*)s; | 217 syscall·envs.array = (byte*)s; |
218 syscall·envs.len = n; | 218 syscall·envs.len = n; |
219 syscall·envs.cap = n; | 219 syscall·envs.cap = n; |
220 } | 220 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 runtime·check(void) | 271 runtime·check(void) |
272 { | 272 { |
273 int8 a; | 273 int8 a; |
274 uint8 b; | 274 uint8 b; |
275 int16 c; | 275 int16 c; |
276 uint16 d; | 276 uint16 d; |
277 int32 e; | 277 int32 e; |
278 uint32 f; | 278 uint32 f; |
279 int64 g; | 279 int64 g; |
280 uint64 h; | 280 uint64 h; |
281 » float32 i; | 281 » float32 i, i1; |
282 » float64 j; | 282 » float64 j, j1; |
283 void* k; | 283 void* k; |
284 uint16* l; | 284 uint16* l; |
285 struct x1 { | 285 struct x1 { |
286 byte x; | 286 byte x; |
287 }; | 287 }; |
288 struct y1 { | 288 struct y1 { |
289 struct x1 x1; | 289 struct x1 x1; |
290 byte y; | 290 byte y; |
291 }; | 291 }; |
292 | 292 |
(...skipping 19 matching lines...) Expand all Loading... |
312 runtime·throw("cas1"); | 312 runtime·throw("cas1"); |
313 if(z != 2) | 313 if(z != 2) |
314 runtime·throw("cas2"); | 314 runtime·throw("cas2"); |
315 | 315 |
316 z = 4; | 316 z = 4; |
317 if(runtime·cas(&z, 5, 6)) | 317 if(runtime·cas(&z, 5, 6)) |
318 runtime·throw("cas3"); | 318 runtime·throw("cas3"); |
319 if(z != 4) | 319 if(z != 4) |
320 runtime·throw("cas4"); | 320 runtime·throw("cas4"); |
321 | 321 |
322 » runtime·initsig(0); | 322 » *(uint64*)&j = ~0ULL; |
323 } | 323 » if(j == j) |
324 | 324 » » runtime·throw("float64nan"); |
325 void | 325 » if(!(j != j)) |
326 runtime·CTestAtomic64(void) | 326 » » runtime·throw("float64nan1"); |
327 { | 327 |
328 » uint64 z64 = 42; | 328 » *(uint64*)&j1 = ~1ULL; |
329 » uint64 x64 = 0; | 329 » if(j == j1) |
330 »······· | 330 » » runtime·throw("float64nan2"); |
| 331 » if(!(j != j1)) |
| 332 » » runtime·throw("float64nan3"); |
| 333 |
| 334 » *(uint32*)&i = ~0UL; |
| 335 » if(i == i) |
| 336 » » runtime·throw("float32nan"); |
| 337 » if(!(i != i)) |
| 338 » » runtime·throw("float32nan1"); |
| 339 |
| 340 » *(uint32*)&i1 = ~1UL; |
| 341 » if(i == i1) |
| 342 » » runtime·throw("float32nan2"); |
| 343 » if(!(i != i1)) |
| 344 » » runtime·throw("float32nan3"); |
| 345 } |
| 346 |
| 347 void |
| 348 runtime·CTestAtomic64(bool isShort) |
| 349 { |
| 350 » uint64 z64, x64; |
| 351 |
| 352 » USED(isShort); |
| 353 |
331 z64 = 42; | 354 z64 = 42; |
332 x64 = 0; | 355 x64 = 0; |
333 if(runtime·cas64(&z64, &x64, 1)) | 356 if(runtime·cas64(&z64, &x64, 1)) |
334 runtime·panicstring("cas64 failed"); | 357 runtime·panicstring("cas64 failed"); |
335 if(x64 != 42) | 358 if(x64 != 42) |
336 runtime·panicstring("cas64 failed"); | 359 runtime·panicstring("cas64 failed"); |
337 if(!runtime·cas64(&z64, &x64, 1)) | 360 if(!runtime·cas64(&z64, &x64, 1)) |
338 runtime·panicstring("cas64 failed"); | 361 runtime·panicstring("cas64 failed"); |
339 if(x64 != 42 || z64 != 1) | 362 if(x64 != 42 || z64 != 1) |
340 runtime·panicstring("cas64 failed"); | 363 runtime·panicstring("cas64 failed"); |
341 if(runtime·atomicload64(&z64) != 1) | 364 if(runtime·atomicload64(&z64) != 1) |
342 runtime·panicstring("load64 failed"); | 365 runtime·panicstring("load64 failed"); |
343 runtime·atomicstore64(&z64, (1ull<<40)+1); | 366 runtime·atomicstore64(&z64, (1ull<<40)+1); |
344 if(runtime·atomicload64(&z64) != (1ull<<40)+1) | 367 if(runtime·atomicload64(&z64) != (1ull<<40)+1) |
345 runtime·panicstring("store64 failed"); | 368 runtime·panicstring("store64 failed"); |
346 if(runtime·xadd64(&z64, (1ull<<40)+1) != (2ull<<40)+2) | 369 if(runtime·xadd64(&z64, (1ull<<40)+1) != (2ull<<40)+2) |
347 runtime·panicstring("xadd64 failed"); | 370 runtime·panicstring("xadd64 failed"); |
348 if(runtime·atomicload64(&z64) != (2ull<<40)+2) | 371 if(runtime·atomicload64(&z64) != (2ull<<40)+2) |
349 runtime·panicstring("xadd64 failed"); | 372 runtime·panicstring("xadd64 failed"); |
350 } | 373 } |
351 | |
352 /* | |
353 * map and chan helpers for | |
354 * dealing with unknown types | |
355 */ | |
356 static uintptr | |
357 memhash(uint32 s, void *a) | |
358 { | |
359 byte *b; | |
360 uintptr hash; | |
361 | |
362 b = a; | |
363 if(sizeof(hash) == 4) | |
364 hash = 2860486313U; | |
365 else | |
366 hash = 33054211828000289ULL; | |
367 while(s > 0) { | |
368 if(sizeof(hash) == 4) | |
369 hash = (hash ^ *b) * 3267000013UL; | |
370 else | |
371 hash = (hash ^ *b) * 23344194077549503ULL; | |
372 b++; | |
373 s--; | |
374 } | |
375 return hash; | |
376 } | |
377 | |
378 static uint32 | |
379 memequal(uint32 s, void *a, void *b) | |
380 { | |
381 byte *ba, *bb, *aend; | |
382 | |
383 if(a == b) | |
384 return 1; | |
385 ba = a; | |
386 bb = b; | |
387 aend = ba+s; | |
388 while(ba != aend) { | |
389 if(*ba != *bb) | |
390 return 0; | |
391 ba++; | |
392 bb++; | |
393 } | |
394 return 1; | |
395 } | |
396 | |
397 static void | |
398 memprint(uint32 s, void *a) | |
399 { | |
400 uint64 v; | |
401 | |
402 v = 0xbadb00b; | |
403 switch(s) { | |
404 case 1: | |
405 v = *(uint8*)a; | |
406 break; | |
407 case 2: | |
408 v = *(uint16*)a; | |
409 break; | |
410 case 4: | |
411 v = *(uint32*)a; | |
412 break; | |
413 case 8: | |
414 v = *(uint64*)a; | |
415 break; | |
416 } | |
417 runtime·printint(v); | |
418 } | |
419 | |
420 static void | |
421 memcopy(uint32 s, void *a, void *b) | |
422 { | |
423 if(b == nil) { | |
424 runtime·memclr(a,s); | |
425 return; | |
426 } | |
427 runtime·memmove(a,b,s); | |
428 } | |
429 | |
430 static uint32 | |
431 memequal8(uint32 s, uint8 *a, uint8 *b) | |
432 { | |
433 USED(s); | |
434 return *a == *b; | |
435 } | |
436 | |
437 static void | |
438 memcopy8(uint32 s, uint8 *a, uint8 *b) | |
439 { | |
440 USED(s); | |
441 if(b == nil) { | |
442 *a = 0; | |
443 return; | |
444 } | |
445 *a = *b; | |
446 } | |
447 | |
448 static uint32 | |
449 memequal16(uint32 s, uint16 *a, uint16 *b) | |
450 { | |
451 USED(s); | |
452 return *a == *b; | |
453 } | |
454 | |
455 static void | |
456 memcopy16(uint32 s, uint16 *a, uint16 *b) | |
457 { | |
458 USED(s); | |
459 if(b == nil) { | |
460 *a = 0; | |
461 return; | |
462 } | |
463 *a = *b; | |
464 } | |
465 | |
466 static uint32 | |
467 memequal32(uint32 s, uint32 *a, uint32 *b) | |
468 { | |
469 USED(s); | |
470 return *a == *b; | |
471 } | |
472 | |
473 static void | |
474 memcopy32(uint32 s, uint32 *a, uint32 *b) | |
475 { | |
476 USED(s); | |
477 if(b == nil) { | |
478 *a = 0; | |
479 return; | |
480 } | |
481 *a = *b; | |
482 } | |
483 | |
484 static uint32 | |
485 memequal64(uint32 s, uint64 *a, uint64 *b) | |
486 { | |
487 USED(s); | |
488 return *a == *b; | |
489 } | |
490 | |
491 static void | |
492 memcopy64(uint32 s, uint64 *a, uint64 *b) | |
493 { | |
494 USED(s); | |
495 if(b == nil) { | |
496 *a = 0; | |
497 return; | |
498 } | |
499 *a = *b; | |
500 } | |
501 | |
502 static uint32 | |
503 memequal128(uint32 s, uint64 *a, uint64 *b) | |
504 { | |
505 USED(s); | |
506 return a[0] == b[0] && a[1] == b[1]; | |
507 } | |
508 | |
509 static void | |
510 memcopy128(uint32 s, uint64 *a, uint64 *b) | |
511 { | |
512 USED(s); | |
513 if(b == nil) { | |
514 a[0] = 0; | |
515 a[1] = 0; | |
516 return; | |
517 } | |
518 a[0] = b[0]; | |
519 a[1] = b[1]; | |
520 } | |
521 | |
522 static void | |
523 slicecopy(uint32 s, Slice *a, Slice *b) | |
524 { | |
525 USED(s); | |
526 if(b == nil) { | |
527 a->array = 0; | |
528 a->len = 0; | |
529 a->cap = 0; | |
530 return; | |
531 } | |
532 a->array = b->array; | |
533 a->len = b->len; | |
534 a->cap = b->cap; | |
535 } | |
536 | |
537 static uintptr | |
538 strhash(uint32 s, String *a) | |
539 { | |
540 USED(s); | |
541 return memhash((*a).len, (*a).str); | |
542 } | |
543 | |
544 static uint32 | |
545 strequal(uint32 s, String *a, String *b) | |
546 { | |
547 int32 alen; | |
548 | |
549 USED(s); | |
550 alen = a->len; | |
551 if(alen != b->len) | |
552 return false; | |
553 return memequal(alen, a->str, b->str); | |
554 } | |
555 | |
556 static void | |
557 strprint(uint32 s, String *a) | |
558 { | |
559 USED(s); | |
560 runtime·printstring(*a); | |
561 } | |
562 | |
563 static void | |
564 strcopy(uint32 s, String *a, String *b) | |
565 { | |
566 USED(s); | |
567 if(b == nil) { | |
568 a->str = 0; | |
569 a->len = 0; | |
570 return; | |
571 } | |
572 a->str = b->str; | |
573 a->len = b->len; | |
574 } | |
575 | |
576 static uintptr | |
577 interhash(uint32 s, Iface *a) | |
578 { | |
579 USED(s); | |
580 return runtime·ifacehash(*a); | |
581 } | |
582 | |
583 static void | |
584 interprint(uint32 s, Iface *a) | |
585 { | |
586 USED(s); | |
587 runtime·printiface(*a); | |
588 } | |
589 | |
590 static uint32 | |
591 interequal(uint32 s, Iface *a, Iface *b) | |
592 { | |
593 USED(s); | |
594 return runtime·ifaceeq_c(*a, *b); | |
595 } | |
596 | |
597 static void | |
598 intercopy(uint32 s, Iface *a, Iface *b) | |
599 { | |
600 USED(s); | |
601 if(b == nil) { | |
602 a->tab = 0; | |
603 a->data = 0; | |
604 return; | |
605 } | |
606 a->tab = b->tab; | |
607 a->data = b->data; | |
608 } | |
609 | |
610 static uintptr | |
611 nilinterhash(uint32 s, Eface *a) | |
612 { | |
613 USED(s); | |
614 return runtime·efacehash(*a); | |
615 } | |
616 | |
617 static void | |
618 nilinterprint(uint32 s, Eface *a) | |
619 { | |
620 USED(s); | |
621 runtime·printeface(*a); | |
622 } | |
623 | |
624 static uint32 | |
625 nilinterequal(uint32 s, Eface *a, Eface *b) | |
626 { | |
627 USED(s); | |
628 return runtime·efaceeq_c(*a, *b); | |
629 } | |
630 | |
631 static void | |
632 nilintercopy(uint32 s, Eface *a, Eface *b) | |
633 { | |
634 USED(s); | |
635 if(b == nil) { | |
636 a->type = 0; | |
637 a->data = 0; | |
638 return; | |
639 } | |
640 a->type = b->type; | |
641 a->data = b->data; | |
642 } | |
643 | |
644 uintptr | |
645 runtime·nohash(uint32 s, void *a) | |
646 { | |
647 USED(s); | |
648 USED(a); | |
649 runtime·panicstring("hash of unhashable type"); | |
650 return 0; | |
651 } | |
652 | |
653 uint32 | |
654 runtime·noequal(uint32 s, void *a, void *b) | |
655 { | |
656 USED(s); | |
657 USED(a); | |
658 USED(b); | |
659 runtime·panicstring("comparing uncomparable types"); | |
660 return 0; | |
661 } | |
662 | |
663 Alg | |
664 runtime·algarray[] = | |
665 { | |
666 [AMEM] { memhash, memequal, memprint, memcopy }, | |
667 [ANOEQ] { runtime·nohash, runtime·noequal, memprint, memcopy }, | |
668 [ASTRING] { (void*)strhash, (void*)strequal, (void*)strprint, (void*)strco
py }, | |
669 [AINTER] { (void*)interhash, (void*)interequal, (void*)interprint
, (void*)intercopy }, | |
670 [ANILINTER] { (void*)nilinterhash, (void*)nilinterequal, (void*)nilinterprin
t, (void*)nilintercopy }, | |
671 [ASLICE] { (void*)runtime·nohash, (void*)runtime·noequal, (void*)memprint
, (void*)slicecopy }, | |
672 [AMEM8] { memhash, (void*)memequal8, memprint, (void*)memcopy8 }, | |
673 [AMEM16] { memhash, (void*)memequal16, memprint, (void*)memcopy16 }, | |
674 [AMEM32] { memhash, (void*)memequal32, memprint, (void*)memcopy32 }, | |
675 [AMEM64] { memhash, (void*)memequal64, memprint, (void*)memcopy64 }, | |
676 [AMEM128] { memhash, (void*)memequal128, memprint, (void*)memcopy128 }, | |
677 [ANOEQ8] { runtime·nohash, runtime·noequal, memprint, (void*)memcopy8 }, | |
678 [ANOEQ16] { runtime·nohash, runtime·noequal, memprint, (void*)memcopy16 }, | |
679 [ANOEQ32] { runtime·nohash, runtime·noequal, memprint, (void*)memcopy32 }, | |
680 [ANOEQ64] { runtime·nohash, runtime·noequal, memprint, (void*)memcopy64 }, | |
681 [ANOEQ128] { runtime·nohash, runtime·noequal, memprint, (void*)memcopy128 }
, | |
682 }; | |
683 | 374 |
684 void | 375 void |
685 runtime·Caller(int32 skip, uintptr retpc, String retfile, int32 retline, bool re
tbool) | 376 runtime·Caller(int32 skip, uintptr retpc, String retfile, int32 retline, bool re
tbool) |
686 { | 377 { |
687 Func *f, *g; | 378 Func *f, *g; |
688 uintptr pc; | 379 uintptr pc; |
689 uintptr rpc[2]; | 380 uintptr rpc[2]; |
690 | 381 |
691 /* | 382 /* |
692 * Ask for two PCs: the one we were asked for | 383 * Ask for two PCs: the one we were asked for |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 { | 434 { |
744 uint32 x; | 435 uint32 x; |
745 | 436 |
746 x = m->fastrand; | 437 x = m->fastrand; |
747 x += x; | 438 x += x; |
748 if(x & 0x80000000L) | 439 if(x & 0x80000000L) |
749 x ^= 0x88888eefUL; | 440 x ^= 0x88888eefUL; |
750 m->fastrand = x; | 441 m->fastrand = x; |
751 return x; | 442 return x; |
752 } | 443 } |
LEFT | RIGHT |