#include <sys/types.h>
#include <sys/mman.h>
#include <sys/signal.h>
+#include <sys/event.h>
#include <sys/time.h>
#include <sys/ucontext.h>
#include <sys/unistd.h>
import "C"
const (
+ EINTR = C.EINTR
+ EFAULT = C.EFAULT
+
PROT_NONE = C.PROT_NONE
PROT_READ = C.PROT_READ
PROT_WRITE = C.PROT_WRITE
SA_RESTART = C.SA_RESTART
SA_ONSTACK = C.SA_ONSTACK
- EINTR = C.EINTR
-
SIGHUP = C.SIGHUP
SIGINT = C.SIGINT
SIGQUIT = C.SIGQUIT
ITIMER_REAL = C.ITIMER_REAL
ITIMER_VIRTUAL = C.ITIMER_VIRTUAL
ITIMER_PROF = C.ITIMER_PROF
+
+ EV_ADD = C.EV_ADD
+ EV_DELETE = C.EV_DELETE
+ EV_CLEAR = C.EV_CLEAR
+ EV_RECEIPT = 0
+ EV_ERROR = C.EV_ERROR
+ EVFILT_READ = C.EVFILT_READ
+ EVFILT_WRITE = C.EVFILT_WRITE
)
type Sigaltstack C.struct_sigaltstack
type McontextT C.mcontext_t
type UcontextT C.ucontext_t
+
+type Kevent C.struct_kevent
enum {
+ EINTR = 0x4,
+ EFAULT = 0xe,
+
PROT_NONE = 0x0,
PROT_READ = 0x1,
PROT_WRITE = 0x2,
SA_RESTART = 0x2,
SA_ONSTACK = 0x1,
- EINTR = 0x4,
-
SIGHUP = 0x1,
SIGINT = 0x2,
SIGQUIT = 0x3,
ITIMER_REAL = 0x0,
ITIMER_VIRTUAL = 0x1,
ITIMER_PROF = 0x2,
+
+ EV_ADD = 0x1,
+ EV_DELETE = 0x2,
+ EV_CLEAR = 0x20,
+ EV_RECEIPT = 0,
+ EV_ERROR = 0x4000,
+ EVFILT_READ = 0x0,
+ EVFILT_WRITE = 0x1,
};
typedef struct Sigaltstack Sigaltstack;
typedef struct Itimerval Itimerval;
typedef struct McontextT McontextT;
typedef struct UcontextT UcontextT;
+typedef struct Kevent Kevent;
#pragma pack on
int32 __uc_pad[4];
};
+struct Kevent {
+ uint32 ident;
+ uint32 filter;
+ uint32 flags;
+ uint32 fflags;
+ int64 data;
+ int32 udata;
+};
+
#pragma pack off
// Created by cgo -cdefs - DO NOT EDIT
enum {
+ EINTR = 0x4,
+ EFAULT = 0xe,
+
PROT_NONE = 0x0,
PROT_READ = 0x1,
PROT_WRITE = 0x2,
SA_RESTART = 0x2,
SA_ONSTACK = 0x1,
- EINTR = 0x4,
-
SIGHUP = 0x1,
SIGINT = 0x2,
SIGQUIT = 0x3,
ITIMER_REAL = 0x0,
ITIMER_VIRTUAL = 0x1,
ITIMER_PROF = 0x2,
+
+ EV_ADD = 0x1,
+ EV_DELETE = 0x2,
+ EV_CLEAR = 0x20,
+ EV_RECEIPT = 0,
+ EV_ERROR = 0x4000,
+ EVFILT_READ = 0x0,
+ EVFILT_WRITE = 0x1,
};
typedef struct Sigaltstack Sigaltstack;
typedef struct Itimerval Itimerval;
typedef struct McontextT McontextT;
typedef struct UcontextT UcontextT;
+typedef struct Kevent Kevent;
#pragma pack on
McontextT uc_mcontext;
};
+struct Kevent {
+ uint64 ident;
+ uint32 filter;
+ uint32 flags;
+ uint32 fflags;
+ byte Pad_cgo_0[4];
+ int64 data;
+ int64 udata;
+};
+
#pragma pack off
// Created by cgo -cdefs - DO NOT EDIT
enum {
+ EINTR = 0x4,
+ EFAULT = 0xe,
+
PROT_NONE = 0x0,
PROT_READ = 0x1,
PROT_WRITE = 0x2,
SA_RESTART = 0x2,
SA_ONSTACK = 0x1,
- EINTR = 0x4,
-
SIGHUP = 0x1,
SIGINT = 0x2,
SIGQUIT = 0x3,
ITIMER_REAL = 0x0,
ITIMER_VIRTUAL = 0x1,
ITIMER_PROF = 0x2,
+
+ EV_ADD = 0x1,
+ EV_DELETE = 0x2,
+ EV_CLEAR = 0x20,
+ EV_RECEIPT = 0,
+ EV_ERROR = 0x4000,
+ EVFILT_READ = 0x0,
+ EVFILT_WRITE = 0x1,
};
typedef struct Sigaltstack Sigaltstack;
typedef struct Itimerval Itimerval;
typedef struct McontextT McontextT;
typedef struct UcontextT UcontextT;
+typedef struct Kevent Kevent;
#pragma pack on
int32 __uc_pad[2];
};
+struct Kevent {
+ uint32 ident;
+ uint32 filter;
+ uint32 flags;
+ uint32 fflags;
+ int64 data;
+ int32 udata;
+};
+
+
#pragma pack off
// Created by cgo -cdefs - DO NOT EDIT
// cgo -cdefs defs_netbsd.go defs_netbsd_arm.go
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build darwin freebsd,amd64 freebsd,386 linux openbsd windows
+// +build darwin freebsd,amd64 freebsd,386 linux netbsd openbsd windows
package net
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build darwin freebsd,amd64 freebsd,386 openbsd
+// +build darwin freebsd,amd64 freebsd,386 netbsd openbsd
#include "runtime.h"
#include "defs_GOOS_GOARCH.h"
+#include "os_GOOS.h"
// Integrated network poller (kqueue-based implementation).
ev[0].flags = EV_ADD|EV_CLEAR;
ev[0].fflags = 0;
ev[0].data = 0;
- ev[0].udata = (byte*)pd;
+ ev[0].udata = (kevent_udata)pd;
ev[1] = ev[0];
ev[1].filter = EVFILT_WRITE;
n = runtime·kevent(kq, ev, 2, nil, 0, nil);
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build freebsd,arm netbsd plan9
+// +build freebsd,arm plan9
#include "runtime.h"
#define SS_DISABLE 4
+typedef byte* kevent_udata;
+
int32 runtime·bsdthread_create(void*, M*, G*, void(*)(void));
int32 runtime·bsdthread_register(void);
int32 runtime·mach_msg_trap(MachHeader*, int32, uint32, uint32, uint32, uint32, uint32);
#define SS_DISABLE 4
+typedef byte* kevent_udata;
+
int32 runtime·thr_new(ThrParam*, int32);
void runtime·sigpanic(void);
void runtime·sigaltstack(Sigaltstack*, Sigaltstack*);
#define SIG_UNBLOCK 2
#define SIG_SETMASK 3
+typedef uintptr kevent_udata;
+
struct sigaction;
void runtime·sigpanic(void);
#define SIG_UNBLOCK 2
#define SIG_SETMASK 3
+typedef byte* kevent_udata;
+
struct sigaction;
void runtime·sigpanic(void);
RET
GLOBL runtime·tlsoffset(SB),$4
+
+// int32 runtime·kqueue(void)
+TEXT runtime·kqueue(SB),NOSPLIT,$0
+ MOVL $344, AX
+ INT $0x80
+ JAE 2(PC)
+ NEGL AX
+ RET
+
+// int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout)
+TEXT runtime·kevent(SB),NOSPLIT,$0
+ MOVL $435, AX
+ INT $0x80
+ JAE 2(PC)
+ NEGL AX
+ RET
+
+// int32 runtime·closeonexec(int32 fd)
+TEXT runtime·closeonexec(SB),NOSPLIT,$32
+ MOVL $92, AX // fcntl
+ // 0(SP) is where the caller PC would be; kernel skips it
+ MOVL fd+0(FP), BX
+ MOVL BX, 4(SP) // fd
+ MOVL $2, 8(SP) // F_SETFD
+ MOVL $1, 12(SP) // FD_CLOEXEC
+ INT $0x80
+ JAE 2(PC)
+ NEGL AX
+ RET
MOVL $0, AX
RET
+// int32 runtime·kqueue(void)
+TEXT runtime·kqueue(SB),NOSPLIT,$0
+ MOVQ $0, DI
+ MOVL $344, AX
+ SYSCALL
+ JCC 2(PC)
+ NEGQ AX
+ RET
+
+// int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout)
+TEXT runtime·kevent(SB),NOSPLIT,$0
+ MOVL 8(SP), DI
+ MOVQ 16(SP), SI
+ MOVL 24(SP), DX
+ MOVQ 32(SP), R10
+ MOVL 40(SP), R8
+ MOVQ 48(SP), R9
+ MOVL $435, AX
+ SYSCALL
+ JCC 2(PC)
+ NEGQ AX
+ RET
+
+// void runtime·closeonexec(int32 fd)
+TEXT runtime·closeonexec(SB),NOSPLIT,$0
+ MOVL 8(SP), DI // fd
+ MOVQ $2, SI // F_SETFD
+ MOVQ $1, DX // FD_CLOEXEC
+ MOVL $92, AX // fcntl
+ SYSCALL
+ RET
SUB $4, R13
RET
+// int32 runtime·kqueue(void)
+TEXT runtime·kqueue(SB),NOSPLIT,$0
+ SWI $0xa00158 // sys_kqueue
+ RSB.CS $0, R0
+ RET
+
+// int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout)
+TEXT runtime·kevent(SB),NOSPLIT,$8
+ MOVW 0(FP), R0 // kq
+ MOVW 4(FP), R1 // changelist
+ MOVW 8(FP), R2 // nchanges
+ MOVW 12(FP), R3 // eventlist
+ MOVW 16(FP), R4 // nevents
+ MOVW R4, 4(R13)
+ MOVW 20(FP), R4 // timeout
+ MOVW R4, 8(R13)
+ ADD $4, R13 // pass arg 5 and 6 on stack
+ SWI $0xa001b3 // sys___kevent50
+ RSB.CS $0, R0
+ SUB $4, R13
+ RET
+
+// void runtime·closeonexec(int32 fd)
+TEXT runtime·closeonexec(SB),NOSPLIT,$0
+ MOVW 0(FP), R0 // fd
+ MOVW $2, R1 // F_SETFD
+ MOVW $1, R2 // FD_CLOEXEC
+ SWI $0xa0005c // sys_fcntl
+ RET
+
TEXT runtime·casp(SB),NOSPLIT,$0
B runtime·cas(SB)