Russ Cox | 133a158 | 2009-10-03 10:37:12 -0700 | [diff] [blame] | 1 | // 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 | |
| 5 | #include <pthread.h> |
| 6 | #include "libcgo.h" |
| 7 | |
| 8 | static void* threadentry(void*); |
| 9 | |
| 10 | void |
| 11 | initcgo(void) |
| 12 | { |
| 13 | } |
| 14 | |
| 15 | void |
| 16 | libcgo_sys_thread_start(ThreadStart *ts) |
| 17 | { |
| 18 | pthread_attr_t attr; |
| 19 | pthread_t p; |
| 20 | size_t size; |
| 21 | |
| 22 | pthread_attr_init(&attr); |
| 23 | pthread_attr_getstacksize(&attr, &size); |
| 24 | ts->g->stackguard = size; |
| 25 | pthread_create(&p, &attr, threadentry, ts); |
| 26 | } |
| 27 | |
| 28 | static void* |
| 29 | threadentry(void *v) |
| 30 | { |
| 31 | ThreadStart ts; |
| 32 | |
| 33 | ts = *(ThreadStart*)v; |
| 34 | free(v); |
| 35 | |
| 36 | ts.g->stackbase = (uintptr)&ts; |
| 37 | |
| 38 | /* |
| 39 | * libcgo_sys_thread_start set stackguard to stack size; |
| 40 | * change to actual guard pointer. |
| 41 | */ |
| 42 | ts.g->stackguard = (uintptr)&ts - ts.g->stackguard + 4096; |
| 43 | |
| 44 | crosscall_amd64(ts.m, ts.g, ts.fn); |
| 45 | return nil; |
| 46 | } |