// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build linux || netbsd
// +build linux netbsd

package unix

import 

type mremapMmapper struct {
	mmapper
	mremap func(oldaddr uintptr, oldlength uintptr, newlength uintptr, flags int, newaddr uintptr) (xaddr uintptr, err error)
}

var mapper = &mremapMmapper{
	mmapper: mmapper{
		active: make(map[*byte][]byte),
		mmap:   mmap,
		munmap: munmap,
	},
	mremap: mremap,
}

func ( *mremapMmapper) ( []byte,  int,  int) ( []byte,  error) {
	if  <= 0 || len() == 0 || len() != cap() || &mremapFixed != 0 {
		return nil, EINVAL
	}

	 := &[cap()-1]
	.Lock()
	defer .Unlock()
	 := .active[]
	if  == nil || &[0] != &[0] {
		return nil, EINVAL
	}
	,  := .mremap(uintptr(unsafe.Pointer(&[0])), uintptr(len()), uintptr(), , 0)
	if  != nil {
		return nil, 
	}
	 := unsafe.Slice((*byte)(unsafe.Pointer()), )
	 := &[cap()-1]
	if &mremapDontunmap == 0 {
		delete(.active, )
	}
	.active[] = 
	return , nil
}

func ( []byte,  int,  int) ( []byte,  error) {
	return mapper.Mremap(, , )
}