blob: dad439f816de8ac0c8980316f1d73fb7e3ccf6e1 [file] [log] [blame]
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package system
// SharedBufferHandle is a handle for a buffer that can be shared between
// applications.
type SharedBufferHandle interface {
// DuplicateBufferHandle duplicates the handle to a buffer.
DuplicateBufferHandle(opts *DuplicateBufferHandleOptions) (MojoResult, SharedBufferHandle)
// MapBuffer maps the requested part of the shared buffer given by handle
// into memory with specified flags. On success, it returns slice that
// points to the requested shared buffer.
MapBuffer(offset uint64, numBytes int, flags MojoMapBufferFlags) (MojoResult, []byte)
// UnmapBuffer unmaps a buffer that was returned by MapBuffer.
UnmapBuffer(buffer []byte) MojoResult
// Gets the shared buffer information (buffer size, and the specified flags).
GetBufferInformation() (MojoResult, MojoBufferInformation)
type sharedBuffer struct {
// baseHandle should always be the first component of this struct,
// see |finalizeHandle()| for more details.
func (h *sharedBuffer) DuplicateBufferHandle(opts *DuplicateBufferHandleOptions) (MojoResult, SharedBufferHandle) {
var flags uint32
if opts != nil {
flags = uint32(opts.Flags)
r, dup := sysImpl.DuplicateBufferHandle(uint32(h.mojoHandle), flags)
return MojoResult(r), core.AcquireNativeHandle(MojoHandle(dup)).ToSharedBufferHandle()
func (h *sharedBuffer) MapBuffer(offset uint64, numBytes int, flags MojoMapBufferFlags) (MojoResult, []byte) {
r, buf := sysImpl.MapBuffer(uint32(h.mojoHandle), offset, uint64(numBytes), uint32(flags))
if r != 0 {
return MojoResult(r), nil
return MojoResult(r), buf
func (h *sharedBuffer) UnmapBuffer(buffer []byte) MojoResult {
r := sysImpl.UnmapBuffer(buffer)
return MojoResult(r)
func (h *sharedBuffer) GetBufferInformation() (MojoResult, MojoBufferInformation) {
r, flags, numBytes := sysImpl.GetBufferInformation(uint32(h.mojoHandle))
if r != 0 {
return MojoResult(r), MojoBufferInformation{}
return MojoResult(r), MojoBufferInformation{
Flags: MojoBufferInformationFlags(flags),
NumBytes: numBytes}