~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/pkg/runtime/cgo/gcc_netbsd_amd64.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 <sys/types.h>
 
6
#include <pthread.h>
 
7
#include <signal.h>
 
8
#include <string.h>
 
9
#include "libcgo.h"
 
10
 
 
11
static void* threadentry(void*);
 
12
static void (*setmg_gcc)(void*, void*);
 
13
 
 
14
void
 
15
x_cgo_init(G *g, void (*setmg)(void*, void*))
 
16
{
 
17
        pthread_attr_t attr;
 
18
        size_t size;
 
19
 
 
20
        setmg_gcc = setmg;
 
21
        pthread_attr_init(&attr);
 
22
        pthread_attr_getstacksize(&attr, &size);
 
23
        g->stackguard = (uintptr)&attr - size + 4096;
 
24
        pthread_attr_destroy(&attr);
 
25
}
 
26
 
 
27
 
 
28
void
 
29
_cgo_sys_thread_start(ThreadStart *ts)
 
30
{
 
31
        pthread_attr_t attr;
 
32
        sigset_t ign, oset;
 
33
        pthread_t p;
 
34
        size_t size;
 
35
        int err;
 
36
 
 
37
        sigfillset(&ign);
 
38
        sigprocmask(SIG_SETMASK, &ign, &oset);
 
39
 
 
40
        pthread_attr_init(&attr);
 
41
        pthread_attr_getstacksize(&attr, &size);
 
42
 
 
43
        ts->g->stackguard = size;
 
44
        err = pthread_create(&p, &attr, threadentry, ts);
 
45
 
 
46
        sigprocmask(SIG_SETMASK, &oset, nil);
 
47
 
 
48
        if (err != 0) {
 
49
                fprintf(stderr, "runtime/cgo: pthread_create failed: %s\n", strerror(err));
 
50
                abort();
 
51
        }
 
52
}
 
53
 
 
54
static void*
 
55
threadentry(void *v)
 
56
{
 
57
        ThreadStart ts;
 
58
 
 
59
        ts = *(ThreadStart*)v;
 
60
        free(v);
 
61
 
 
62
        ts.g->stackbase = (uintptr)&ts;
 
63
 
 
64
        /*
 
65
         * _cgo_sys_thread_start set stackguard to stack size;
 
66
         * change to actual guard pointer.
 
67
         */
 
68
        ts.g->stackguard = (uintptr)&ts - ts.g->stackguard + 4096;
 
69
 
 
70
        /*
 
71
         * Set specific keys.
 
72
         */
 
73
        setmg_gcc((void*)ts.m, (void*)ts.g);
 
74
 
 
75
        crosscall_amd64(ts.fn);
 
76
        return nil;
 
77
}