1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 01:57:12 -05:00

completely remove usage of go:nosplit

This commit is contained in:
Darien Raymond 2019-02-22 12:54:26 +01:00
parent a37af64683
commit 6178d7281c
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
2 changed files with 12 additions and 46 deletions

View File

@ -2,13 +2,11 @@ package protocol
import (
"io"
"unsafe"
"v2ray.com/core/common"
"v2ray.com/core/common/buf"
"v2ray.com/core/common/net"
"v2ray.com/core/common/serial"
"v2ray.com/core/common/stack"
)
type AddressOption func(*option)
@ -226,7 +224,6 @@ func (p *addressParser) readAddress(b *buf.Buffer, reader io.Reader) (net.Addres
}
}
//go:nosplit
func (p *addressParser) writeAddress(writer io.Writer, address net.Address) error {
tb := p.addrByteMap[address.Family()]
if tb == afInvalid {
@ -235,13 +232,7 @@ func (p *addressParser) writeAddress(writer io.Writer, address net.Address) erro
switch address.Family() {
case net.AddressFamilyIPv4, net.AddressFamilyIPv6:
var bytes stack.TwoBytes
s := bytes[:1]
s[0] = tb
p := uintptr(unsafe.Pointer(&s))
v := (*[]byte)(unsafe.Pointer(p))
if _, err := writer.Write(*v); err != nil {
if _, err := writer.Write([]byte{tb}); err != nil {
return err
}
if _, err := writer.Write(address.IP()); err != nil {
@ -253,17 +244,10 @@ func (p *addressParser) writeAddress(writer io.Writer, address net.Address) erro
return newError("Super long domain is not supported: ", domain)
}
var bytes stack.TwoBytes
s := bytes[:]
s[0] = tb
s[1] = byte(len(domain))
p := uintptr(unsafe.Pointer(&s))
v := (*[]byte)(unsafe.Pointer(p))
if _, err := writer.Write(*v); err != nil {
if _, err := writer.Write([]byte{tb, byte(len(domain))}); err != nil {
return err
}
if _, err := io.WriteString(writer, domain); err != nil {
if _, err := writer.Write([]byte(domain)); err != nil {
return err
}
default:

View File

@ -3,45 +3,27 @@ package serial
import (
"encoding/binary"
"io"
"unsafe"
"v2ray.com/core/common/stack"
)
// ReadUint16 reads first two bytes from the reader, and then coverts them to an uint16 value.
//go:nosplit
func ReadUint16(reader io.Reader) (uint16, error) {
var b stack.TwoBytes
s := b[:]
p := uintptr(unsafe.Pointer(&s))
v := (*[]byte)(unsafe.Pointer(p))
if _, err := io.ReadFull(reader, *v); err != nil {
var b [2]byte
if _, err := io.ReadFull(reader, b[:]); err != nil {
return 0, err
}
return binary.BigEndian.Uint16(*v), nil
return binary.BigEndian.Uint16(b[:]), nil
}
// WriteUint16 writes an uint16 value into writer.
//go:nosplit
func WriteUint16(writer io.Writer, value uint16) (int, error) {
var b stack.TwoBytes
s := b[:]
p := uintptr(unsafe.Pointer(&s))
v := (*[]byte)(unsafe.Pointer(p))
binary.BigEndian.PutUint16(*v, value)
return writer.Write(*v)
var b [2]byte
binary.BigEndian.PutUint16(b[:], value)
return writer.Write(b[:])
}
// WriteUint64 writes an uint64 value into writer.
//go:nosplit
func WriteUint64(writer io.Writer, value uint64) (int, error) {
var b stack.EightBytes
s := b[:]
p := uintptr(unsafe.Pointer(&s))
v := (*[]byte)(unsafe.Pointer(p))
binary.BigEndian.PutUint64(*v, value)
return writer.Write(*v)
var b [8]byte
binary.BigEndian.PutUint64(b[:], value)
return writer.Write(b[:])
}