1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 10:08:15 -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 ( import (
"io" "io"
"unsafe"
"v2ray.com/core/common" "v2ray.com/core/common"
"v2ray.com/core/common/buf" "v2ray.com/core/common/buf"
"v2ray.com/core/common/net" "v2ray.com/core/common/net"
"v2ray.com/core/common/serial" "v2ray.com/core/common/serial"
"v2ray.com/core/common/stack"
) )
type AddressOption func(*option) 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 { func (p *addressParser) writeAddress(writer io.Writer, address net.Address) error {
tb := p.addrByteMap[address.Family()] tb := p.addrByteMap[address.Family()]
if tb == afInvalid { if tb == afInvalid {
@ -235,13 +232,7 @@ func (p *addressParser) writeAddress(writer io.Writer, address net.Address) erro
switch address.Family() { switch address.Family() {
case net.AddressFamilyIPv4, net.AddressFamilyIPv6: case net.AddressFamilyIPv4, net.AddressFamilyIPv6:
var bytes stack.TwoBytes if _, err := writer.Write([]byte{tb}); err != nil {
s := bytes[:1]
s[0] = tb
p := uintptr(unsafe.Pointer(&s))
v := (*[]byte)(unsafe.Pointer(p))
if _, err := writer.Write(*v); err != nil {
return err return err
} }
if _, err := writer.Write(address.IP()); err != nil { 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) return newError("Super long domain is not supported: ", domain)
} }
var bytes stack.TwoBytes if _, err := writer.Write([]byte{tb, byte(len(domain))}); err != nil {
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 {
return err return err
} }
if _, err := io.WriteString(writer, domain); err != nil { if _, err := writer.Write([]byte(domain)); err != nil {
return err return err
} }
default: default:

View File

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