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

« back to all changes in this revision

Viewing changes to src/pkg/runtime/os_solaris.c

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2014-11-18 15:12:26 UTC
  • mfrom: (14.2.12 vivid-proposed)
  • Revision ID: package-import@ubuntu.com-20141118151226-zug7vn93mn3dtiz3
Tags: 2:1.3.2-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - Support co-installability with gccgo-go tool:
    - d/rules,golang-go.install: Rename bin/go -> bin/golang-go
    - d/golang-go.{postinst,prerm}: Install/remove /usr/bin/go using
      alternatives.
  - d/copyright: Amendments for full compiliance with copyright format.
  - d/control: Demote golang-go.tools to Suggests to support Ubuntu MIR.
  - dropped patches (now upstream):
    - d/p/issue27650045_40001_50001.diff
    - d/p/issue28050043_60001_70001.diff
    - d/p/issue54790044_100001_110001.diff

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2011 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 "runtime.h"
 
6
#include "defs_GOOS_GOARCH.h"
 
7
#include "os_GOOS.h"
 
8
#include "signal_unix.h"
 
9
#include "stack.h"
 
10
#include "../../cmd/ld/textflag.h"
 
11
 
 
12
#pragma dynexport end _end
 
13
#pragma dynexport etext _etext
 
14
#pragma dynexport edata _edata
 
15
 
 
16
#pragma dynimport libc·___errno ___errno "libc.so"
 
17
#pragma dynimport libc·clock_gettime clock_gettime "libc.so"
 
18
#pragma dynimport libc·close close "libc.so"
 
19
#pragma dynimport libc·exit exit "libc.so"
 
20
#pragma dynimport libc·fstat fstat "libc.so"
 
21
#pragma dynimport libc·getcontext getcontext "libc.so"
 
22
#pragma dynimport libc·getrlimit getrlimit "libc.so"
 
23
#pragma dynimport libc·malloc malloc "libc.so"
 
24
#pragma dynimport libc·mmap mmap "libc.so"
 
25
#pragma dynimport libc·munmap munmap "libc.so"
 
26
#pragma dynimport libc·open open "libc.so"
 
27
#pragma dynimport libc·pthread_attr_destroy pthread_attr_destroy "libc.so"
 
28
#pragma dynimport libc·pthread_attr_getstack pthread_attr_getstack "libc.so"
 
29
#pragma dynimport libc·pthread_attr_init pthread_attr_init "libc.so"
 
30
#pragma dynimport libc·pthread_attr_setdetachstate pthread_attr_setdetachstate "libc.so"
 
31
#pragma dynimport libc·pthread_attr_setstack pthread_attr_setstack "libc.so"
 
32
#pragma dynimport libc·pthread_create pthread_create "libc.so"
 
33
#pragma dynimport libc·raise raise "libc.so"
 
34
#pragma dynimport libc·read read "libc.so"
 
35
#pragma dynimport libc·select select "libc.so"
 
36
#pragma dynimport libc·sched_yield sched_yield "libc.so"
 
37
#pragma dynimport libc·sem_init sem_init "libc.so"
 
38
#pragma dynimport libc·sem_post sem_post "libc.so"
 
39
#pragma dynimport libc·sem_reltimedwait_np sem_reltimedwait_np "libc.so"
 
40
#pragma dynimport libc·sem_wait sem_wait "libc.so"
 
41
#pragma dynimport libc·setitimer setitimer "libc.so"
 
42
#pragma dynimport libc·sigaction sigaction "libc.so"
 
43
#pragma dynimport libc·sigaltstack sigaltstack "libc.so"
 
44
#pragma dynimport libc·sigprocmask sigprocmask "libc.so"
 
45
#pragma dynimport libc·sysconf sysconf "libc.so"
 
46
#pragma dynimport libc·usleep usleep "libc.so"
 
47
#pragma dynimport libc·write write "libc.so"
 
48
 
 
49
extern uintptr libc·___errno;
 
50
extern uintptr libc·clock_gettime;
 
51
extern uintptr libc·close;
 
52
extern uintptr libc·exit;
 
53
extern uintptr libc·fstat;
 
54
extern uintptr libc·getcontext;
 
55
extern uintptr libc·getrlimit;
 
56
extern uintptr libc·malloc;
 
57
extern uintptr libc·mmap;
 
58
extern uintptr libc·munmap;
 
59
extern uintptr libc·open;
 
60
extern uintptr libc·pthread_attr_destroy;
 
61
extern uintptr libc·pthread_attr_getstack;
 
62
extern uintptr libc·pthread_attr_init;
 
63
extern uintptr libc·pthread_attr_setdetachstate;
 
64
extern uintptr libc·pthread_attr_setstack;
 
65
extern uintptr libc·pthread_create;
 
66
extern uintptr libc·raise;
 
67
extern uintptr libc·read;
 
68
extern uintptr libc·sched_yield;
 
69
extern uintptr libc·select;
 
70
extern uintptr libc·sem_init;
 
71
extern uintptr libc·sem_post;
 
72
extern uintptr libc·sem_reltimedwait_np;
 
73
extern uintptr libc·sem_wait;
 
74
extern uintptr libc·setitimer;
 
75
extern uintptr libc·sigaction;
 
76
extern uintptr libc·sigaltstack;
 
77
extern uintptr libc·sigprocmask;
 
78
extern uintptr libc·sysconf;
 
79
extern uintptr libc·usleep;
 
80
extern uintptr libc·write;
 
81
 
 
82
void    runtime·getcontext(Ucontext *context);
 
83
int32   runtime·pthread_attr_destroy(PthreadAttr* attr);
 
84
int32   runtime·pthread_attr_init(PthreadAttr* attr);
 
85
int32   runtime·pthread_attr_getstack(PthreadAttr* attr, void** addr, uint64* size);
 
86
int32   runtime·pthread_attr_setdetachstate(PthreadAttr* attr, int32 state);
 
87
int32   runtime·pthread_attr_setstack(PthreadAttr* attr, void* addr, uint64 size);
 
88
int32   runtime·pthread_create(Pthread* thread, PthreadAttr* attr, void(*fn)(void), void *arg);
 
89
uint32  runtime·tstart_sysvicall(M *newm);
 
90
int32   runtime·sem_init(SemT* sem, int32 pshared, uint32 value);
 
91
int32   runtime·sem_post(SemT* sem);
 
92
int32   runtime·sem_reltimedwait_np(SemT* sem, Timespec* timeout);
 
93
int32   runtime·sem_wait(SemT* sem);
 
94
int64   runtime·sysconf(int32 name);
 
95
 
 
96
extern SigTab runtime·sigtab[];
 
97
static Sigset sigset_none;
 
98
static Sigset sigset_all = { ~(uint32)0, ~(uint32)0, ~(uint32)0, ~(uint32)0, };
 
99
 
 
100
// Calling sysvcall on os stack.
 
101
#pragma textflag NOSPLIT
 
102
uintptr
 
103
runtime·sysvicall6(uintptr fn, int32 count, ...)
 
104
{
 
105
        runtime·memclr((byte*)&m->scratch, sizeof(m->scratch));
 
106
        m->libcall.fn = (void*)fn;
 
107
        m->libcall.n = (uintptr)count;
 
108
        for(;count; count--)
 
109
                m->scratch.v[count - 1] = *((uintptr*)&count + count);
 
110
        m->libcall.args = (uintptr*)&m->scratch.v[0];
 
111
        runtime·asmcgocall(runtime·asmsysvicall6, &m->libcall);
 
112
        return m->libcall.r1;
 
113
}
 
114
 
 
115
static int32
 
116
getncpu(void) 
 
117
{
 
118
        int32 n;
 
119
        
 
120
        n = (int32)runtime·sysconf(_SC_NPROCESSORS_ONLN);
 
121
        if(n < 1)
 
122
                return 1;
 
123
        return n;
 
124
}
 
125
 
 
126
void
 
127
runtime·osinit(void)
 
128
{
 
129
        runtime·ncpu = getncpu(); 
 
130
}
 
131
 
 
132
void
 
133
runtime·newosproc(M *mp, void *stk)
 
134
{
 
135
        PthreadAttr attr;
 
136
        Sigset oset;
 
137
        Pthread tid;
 
138
        int32 ret;
 
139
 
 
140
        USED(stk);
 
141
        if(runtime·pthread_attr_init(&attr) != 0)
 
142
                runtime·throw("pthread_attr_init");
 
143
        if(runtime·pthread_attr_setstack(&attr, 0, 0x200000) != 0)
 
144
                runtime·throw("pthread_attr_setstack");
 
145
        if(runtime·pthread_attr_getstack(&attr, (void**)&mp->g0->stackbase, &mp->g0->stacksize) != 0)
 
146
                runtime·throw("pthread_attr_getstack"); 
 
147
        if(runtime·pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) != 0)
 
148
                runtime·throw("pthread_attr_setdetachstate");
 
149
 
 
150
        // Disable signals during create, so that the new thread starts
 
151
        // with signals disabled.  It will enable them in minit.
 
152
        runtime·sigprocmask(SIG_SETMASK, &sigset_all, &oset);
 
153
        ret = runtime·pthread_create(&tid, &attr, (void (*)(void))runtime·tstart_sysvicall, mp);
 
154
        runtime·sigprocmask(SIG_SETMASK, &oset, nil);
 
155
        if(ret != 0) {
 
156
                runtime·printf("runtime: failed to create new OS thread (have %d already; errno=%d)\n", runtime·mcount(), ret);
 
157
                runtime·throw("runtime.newosproc");
 
158
        }
 
159
}
 
160
 
 
161
void
 
162
runtime·get_random_data(byte **rnd, int32 *rnd_len)
 
163
{
 
164
        #pragma dataflag NOPTR
 
165
        static byte urandom_data[HashRandomBytes];
 
166
        int32 fd;
 
167
        fd = runtime·open("/dev/urandom", 0 /* O_RDONLY */, 0);
 
168
        if(runtime·read(fd, urandom_data, HashRandomBytes) == HashRandomBytes) {
 
169
                *rnd = urandom_data;
 
170
                *rnd_len = HashRandomBytes;
 
171
        } else {
 
172
                *rnd = nil;
 
173
                *rnd_len = 0;
 
174
        }
 
175
        runtime·close(fd);
 
176
}
 
177
 
 
178
void
 
179
runtime·goenvs(void)
 
180
{
 
181
        runtime·goenvs_unix();
 
182
}
 
183
 
 
184
// Called to initialize a new m (including the bootstrap m).
 
185
// Called on the parent thread (main thread in case of bootstrap), can allocate memory.
 
186
void
 
187
runtime·mpreinit(M *mp)
 
188
{
 
189
        mp->gsignal = runtime·malg(32*1024);
 
190
}
 
191
 
 
192
// Called to initialize a new m (including the bootstrap m).
 
193
// Called on the new thread, can not allocate memory.
 
194
void
 
195
runtime·minit(void)
 
196
{
 
197
        runtime·asmcgocall(runtime·miniterrno, (void *)libc·___errno);
 
198
        // Initialize signal handling
 
199
        runtime·signalstack((byte*)m->gsignal->stackguard - StackGuard, 32*1024);
 
200
        runtime·sigprocmask(SIG_SETMASK, &sigset_none, nil);
 
201
}
 
202
 
 
203
// Called from dropm to undo the effect of an minit.
 
204
void
 
205
runtime·unminit(void)
 
206
{
 
207
        runtime·signalstack(nil, 0);
 
208
}
 
209
 
 
210
void
 
211
runtime·sigpanic(void)
 
212
{
 
213
        if(!runtime·canpanic(g))
 
214
                runtime·throw("unexpected signal during runtime execution");
 
215
 
 
216
        switch(g->sig) {
 
217
        case SIGBUS:
 
218
                if(g->sigcode0 == BUS_ADRERR && g->sigcode1 < 0x1000 || g->paniconfault) {
 
219
                        if(g->sigpc == 0)
 
220
                                runtime·panicstring("call of nil func value");
 
221
                        runtime·panicstring("invalid memory address or nil pointer dereference");
 
222
                }
 
223
                runtime·printf("unexpected fault address %p\n", g->sigcode1);
 
224
                runtime·throw("fault");
 
225
        case SIGSEGV:
 
226
                if((g->sigcode0 == 0 || g->sigcode0 == SEGV_MAPERR || g->sigcode0 == SEGV_ACCERR) && g->sigcode1 < 0x1000 || g->paniconfault) {
 
227
                        if(g->sigpc == 0)
 
228
                                runtime·panicstring("call of nil func value");
 
229
                        runtime·panicstring("invalid memory address or nil pointer dereference");
 
230
                }
 
231
                runtime·printf("unexpected fault address %p\n", g->sigcode1);
 
232
                runtime·throw("fault");
 
233
        case SIGFPE:
 
234
                switch(g->sigcode0) {
 
235
                case FPE_INTDIV:
 
236
                        runtime·panicstring("integer divide by zero");
 
237
                case FPE_INTOVF:
 
238
                        runtime·panicstring("integer overflow");
 
239
                }
 
240
                runtime·panicstring("floating point error");
 
241
        }
 
242
        runtime·panicstring(runtime·sigtab[g->sig].name);
 
243
}
 
244
 
 
245
uintptr
 
246
runtime·memlimit(void)
 
247
{
 
248
        Rlimit rl;
 
249
        extern byte text[], end[];
 
250
        uintptr used;
 
251
        
 
252
        if(runtime·getrlimit(RLIMIT_AS, &rl) != 0)
 
253
                return 0;
 
254
        if(rl.rlim_cur >= 0x7fffffff)
 
255
                return 0;
 
256
 
 
257
        // Estimate our VM footprint excluding the heap.
 
258
        // Not an exact science: use size of binary plus
 
259
        // some room for thread stacks.
 
260
        used = end - text + (64<<20);
 
261
        if(used >= rl.rlim_cur)
 
262
                return 0;
 
263
 
 
264
        // If there's not at least 16 MB left, we're probably
 
265
        // not going to be able to do much.  Treat as no limit.
 
266
        rl.rlim_cur -= used;
 
267
        if(rl.rlim_cur < (16<<20))
 
268
                return 0;
 
269
 
 
270
        return rl.rlim_cur - used;
 
271
}
 
272
 
 
273
void
 
274
runtime·setprof(bool on)
 
275
{
 
276
        USED(on);
 
277
}
 
278
 
 
279
extern void runtime·sigtramp(void);
 
280
 
 
281
void
 
282
runtime·setsig(int32 i, GoSighandler *fn, bool restart)
 
283
{
 
284
        Sigaction sa;
 
285
 
 
286
        runtime·memclr((byte*)&sa, sizeof sa);
 
287
        sa.sa_flags = SA_SIGINFO|SA_ONSTACK;
 
288
        if(restart)
 
289
                sa.sa_flags |= SA_RESTART;
 
290
        sa.sa_mask.__sigbits[0] = ~(uint32)0;
 
291
        sa.sa_mask.__sigbits[1] = ~(uint32)0;
 
292
        sa.sa_mask.__sigbits[2] = ~(uint32)0;
 
293
        sa.sa_mask.__sigbits[3] = ~(uint32)0;
 
294
        if(fn == runtime·sighandler)
 
295
                fn = (void*)runtime·sigtramp;
 
296
        *((void**)&sa._funcptr[0]) = (void*)fn;
 
297
        runtime·sigaction(i, &sa, nil);
 
298
}
 
299
 
 
300
GoSighandler*
 
301
runtime·getsig(int32 i)
 
302
{
 
303
        Sigaction sa;
 
304
 
 
305
        runtime·memclr((byte*)&sa, sizeof sa);
 
306
        runtime·sigaction(i, nil, &sa);
 
307
        if(*((void**)&sa._funcptr[0]) == runtime·sigtramp)
 
308
                return runtime·sighandler;
 
309
        return *((void**)&sa._funcptr[0]);
 
310
}
 
311
 
 
312
void
 
313
runtime·signalstack(byte *p, int32 n)
 
314
{
 
315
        StackT st;
 
316
 
 
317
        st.ss_sp = (void*)p;
 
318
        st.ss_size = n;
 
319
        st.ss_flags = 0;
 
320
        if(p == nil)
 
321
                st.ss_flags = SS_DISABLE;
 
322
        runtime·sigaltstack(&st, nil);
 
323
}
 
324
 
 
325
void
 
326
runtime·unblocksignals(void)
 
327
{
 
328
        runtime·sigprocmask(SIG_SETMASK, &sigset_none, nil);
 
329
}
 
330
 
 
331
#pragma textflag NOSPLIT
 
332
uintptr
 
333
runtime·semacreate(void)
 
334
{
 
335
        SemT* sem;
 
336
 
 
337
        // Call libc's malloc rather than runtime·malloc.  This will
 
338
        // allocate space on the C heap.  We can't call runtime·malloc
 
339
        // here because it could cause a deadlock.
 
340
        m->libcall.fn = (void*)libc·malloc;
 
341
        m->libcall.n = 1;
 
342
        runtime·memclr((byte*)&m->scratch, sizeof(m->scratch));
 
343
        m->scratch.v[0] = (uintptr)sizeof(*sem);
 
344
        m->libcall.args = (uintptr*)&m->scratch;
 
345
        runtime·asmcgocall(runtime·asmsysvicall6, &m->libcall);
 
346
        sem = (void*)m->libcall.r1;
 
347
        if(runtime·sem_init(sem, 0, 0) != 0)
 
348
                runtime·throw("sem_init");
 
349
        return (uintptr)sem;
 
350
}
 
351
 
 
352
#pragma textflag NOSPLIT
 
353
int32
 
354
runtime·semasleep(int64 ns)
 
355
{
 
356
        if(ns >= 0) {
 
357
                m->ts.tv_sec = ns / 1000000000LL;
 
358
                m->ts.tv_nsec = ns % 1000000000LL;
 
359
 
 
360
                m->libcall.fn = (void*)libc·sem_reltimedwait_np;
 
361
                m->libcall.n = 2;
 
362
                runtime·memclr((byte*)&m->scratch, sizeof(m->scratch));
 
363
                m->scratch.v[0] = m->waitsema;
 
364
                m->scratch.v[1] = (uintptr)&m->ts;
 
365
                m->libcall.args = (uintptr*)&m->scratch;
 
366
                runtime·asmcgocall(runtime·asmsysvicall6, &m->libcall);
 
367
                if(*m->perrno != 0) {
 
368
                        if(*m->perrno == ETIMEDOUT || *m->perrno == EAGAIN || *m->perrno == EINTR)
 
369
                                return -1;
 
370
                        runtime·throw("sem_reltimedwait_np");
 
371
                }
 
372
                return 0;
 
373
        }
 
374
        for(;;) {
 
375
                m->libcall.fn = (void*)libc·sem_wait;
 
376
                m->libcall.n = 1;
 
377
                runtime·memclr((byte*)&m->scratch, sizeof(m->scratch));
 
378
                m->scratch.v[0] = m->waitsema;
 
379
                m->libcall.args = (uintptr*)&m->scratch;
 
380
                runtime·asmcgocall(runtime·asmsysvicall6, &m->libcall);
 
381
                if(m->libcall.r1 == 0)
 
382
                        break;
 
383
                if(*m->perrno == EINTR) 
 
384
                        continue;
 
385
                runtime·throw("sem_wait");
 
386
        }
 
387
        return 0;
 
388
}
 
389
 
 
390
#pragma textflag NOSPLIT
 
391
void
 
392
runtime·semawakeup(M *mp)
 
393
{
 
394
        SemT* sem = (SemT*)mp->waitsema;
 
395
        if(runtime·sem_post(sem) != 0)
 
396
                runtime·throw("sem_post");
 
397
}
 
398
 
 
399
int32
 
400
runtime·close(int32 fd)
 
401
{
 
402
        return runtime·sysvicall6(libc·close, 1, (uintptr)fd);
 
403
}
 
404
 
 
405
void
 
406
runtime·exit(int32 r)
 
407
{
 
408
        runtime·sysvicall6(libc·exit, 1, (uintptr)r);
 
409
}
 
410
 
 
411
/* int32 */ void
 
412
runtime·getcontext(Ucontext* context)
 
413
{
 
414
        runtime·sysvicall6(libc·getcontext, 1, (uintptr)context);
 
415
}
 
416
 
 
417
int32
 
418
runtime·getrlimit(int32 res, Rlimit* rlp)
 
419
{
 
420
        return runtime·sysvicall6(libc·getrlimit, 2, (uintptr)res, (uintptr)rlp);
 
421
}
 
422
 
 
423
uint8*
 
424
runtime·mmap(byte* addr, uintptr len, int32 prot, int32 flags, int32 fildes, uint32 off)
 
425
{
 
426
        return (uint8*)runtime·sysvicall6(libc·mmap, 6, (uintptr)addr, (uintptr)len, (uintptr)prot, (uintptr)flags, (uintptr)fildes, (uintptr)off);
 
427
}
 
428
 
 
429
void
 
430
runtime·munmap(byte* addr, uintptr len)
 
431
{
 
432
        runtime·sysvicall6(libc·munmap, 2, (uintptr)addr, (uintptr)len);
 
433
}
 
434
 
 
435
extern int64 runtime·nanotime1(void);
 
436
#pragma textflag NOSPLIT
 
437
int64
 
438
runtime·nanotime(void)
 
439
{
 
440
        return runtime·sysvicall6((uintptr)runtime·nanotime1, 0);
 
441
}
 
442
 
 
443
void
 
444
time·now(int64 sec, int32 usec)
 
445
{
 
446
        int64 ns;
 
447
 
 
448
        ns = runtime·nanotime();
 
449
        sec = ns / 1000000000LL;
 
450
        usec = ns - sec * 1000000000LL;
 
451
        FLUSH(&sec);
 
452
        FLUSH(&usec);
 
453
}
 
454
 
 
455
int32
 
456
runtime·open(int8* path, int32 oflag, int32 mode)
 
457
{
 
458
        return runtime·sysvicall6(libc·open, 3, (uintptr)path, (uintptr)oflag, (uintptr)mode);
 
459
}
 
460
 
 
461
int32
 
462
runtime·pthread_attr_destroy(PthreadAttr* attr)
 
463
{
 
464
        return runtime·sysvicall6(libc·pthread_attr_destroy, 1, (uintptr)attr);
 
465
}
 
466
 
 
467
int32
 
468
runtime·pthread_attr_getstack(PthreadAttr* attr, void** addr, uint64* size)
 
469
{
 
470
        return runtime·sysvicall6(libc·pthread_attr_getstack, 3, (uintptr)attr, (uintptr)addr, (uintptr)size);
 
471
}
 
472
 
 
473
int32
 
474
runtime·pthread_attr_init(PthreadAttr* attr)
 
475
{
 
476
        return runtime·sysvicall6(libc·pthread_attr_init, 1, (uintptr)attr);
 
477
}
 
478
 
 
479
int32
 
480
runtime·pthread_attr_setdetachstate(PthreadAttr* attr, int32 state)
 
481
{
 
482
        return runtime·sysvicall6(libc·pthread_attr_setdetachstate, 2, (uintptr)attr, (uintptr)state);
 
483
}
 
484
 
 
485
int32
 
486
runtime·pthread_attr_setstack(PthreadAttr* attr, void* addr, uint64 size)
 
487
{
 
488
        return runtime·sysvicall6(libc·pthread_attr_setstack, 3, (uintptr)attr, (uintptr)addr, (uintptr)size);
 
489
}
 
490
 
 
491
int32
 
492
runtime·pthread_create(Pthread* thread, PthreadAttr* attr, void(*fn)(void), void *arg)
 
493
{
 
494
        return runtime·sysvicall6(libc·pthread_create, 4, (uintptr)thread, (uintptr)attr, (uintptr)fn, (uintptr)arg);
 
495
}
 
496
 
 
497
/* int32 */ void
 
498
runtime·raise(int32 sig)
 
499
{
 
500
        runtime·sysvicall6(libc·raise, 1, (uintptr)sig);
 
501
}
 
502
 
 
503
int32
 
504
runtime·read(int32 fd, void* buf, int32 nbyte)
 
505
{
 
506
        return runtime·sysvicall6(libc·read, 3, (uintptr)fd, (uintptr)buf, (uintptr)nbyte);
 
507
}
 
508
 
 
509
#pragma textflag NOSPLIT
 
510
int32
 
511
runtime·sem_init(SemT* sem, int32 pshared, uint32 value)
 
512
{
 
513
        return runtime·sysvicall6(libc·sem_init, 3, (uintptr)sem, (uintptr)pshared, (uintptr)value);
 
514
}
 
515
 
 
516
#pragma textflag NOSPLIT
 
517
int32
 
518
runtime·sem_post(SemT* sem)
 
519
{
 
520
        return runtime·sysvicall6(libc·sem_post, 1, (uintptr)sem);
 
521
}
 
522
 
 
523
#pragma textflag NOSPLIT
 
524
int32
 
525
runtime·sem_reltimedwait_np(SemT* sem, Timespec* timeout)
 
526
{
 
527
        return runtime·sysvicall6(libc·sem_reltimedwait_np, 2, (uintptr)sem, (uintptr)timeout);
 
528
}
 
529
 
 
530
#pragma textflag NOSPLIT
 
531
int32
 
532
runtime·sem_wait(SemT* sem)
 
533
{
 
534
        return runtime·sysvicall6(libc·sem_wait, 1, (uintptr)sem);
 
535
}
 
536
 
 
537
/* int32 */ void
 
538
runtime·setitimer(int32 which, Itimerval* value, Itimerval* ovalue)
 
539
{
 
540
        runtime·sysvicall6(libc·setitimer, 3, (uintptr)which, (uintptr)value, (uintptr)ovalue);
 
541
}
 
542
 
 
543
/* int32 */ void
 
544
runtime·sigaction(int32 sig, struct Sigaction* act, struct Sigaction* oact)
 
545
{
 
546
        runtime·sysvicall6(libc·sigaction, 3, (uintptr)sig, (uintptr)act, (uintptr)oact);
 
547
}
 
548
 
 
549
/* int32 */ void
 
550
runtime·sigaltstack(Sigaltstack* ss, Sigaltstack* oss)
 
551
{
 
552
        runtime·sysvicall6(libc·sigaltstack, 2, (uintptr)ss, (uintptr)oss);
 
553
}
 
554
 
 
555
/* int32 */ void
 
556
runtime·sigprocmask(int32 how, Sigset* set, Sigset* oset)
 
557
{
 
558
        runtime·sysvicall6(libc·sigprocmask, 3, (uintptr)how, (uintptr)set, (uintptr)oset);
 
559
}
 
560
 
 
561
int64
 
562
runtime·sysconf(int32 name)
 
563
{
 
564
        return runtime·sysvicall6(libc·sysconf, 1, (uintptr)name);
 
565
}
 
566
 
 
567
void
 
568
runtime·usleep(uint32 us)
 
569
{
 
570
        runtime·sysvicall6(libc·usleep, 1, (uintptr)us);
 
571
}
 
572
 
 
573
int32
 
574
runtime·write(uintptr fd, void* buf, int32 nbyte)
 
575
{
 
576
        return runtime·sysvicall6(libc·write, 3, (uintptr)fd, (uintptr)buf, (uintptr)nbyte);
 
577
}
 
578
 
 
579
void
 
580
runtime·osyield(void)
 
581
{
 
582
        runtime·sysvicall6(libc·sched_yield, 0);
 
583
}