2021-11-10 02:41:26 -05:00
|
|
|
#ifndef RUBY_IO_BUFFER_T
|
|
|
|
#define RUBY_IO_BUFFER_T 1
|
2021-07-02 06:41:16 -04:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @author Samuel Williams
|
|
|
|
* @date Fri 2 Jul 2021 16:29:01 NZST
|
|
|
|
* @copyright Copyright (C) 2021 Samuel Williams
|
|
|
|
* @copyright This file is a part of the programming language Ruby.
|
|
|
|
* Permission is hereby granted, to either redistribute and/or
|
|
|
|
* modify this file, provided that the conditions mentioned in the
|
|
|
|
* file COPYING are met. Consult the file for details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ruby/ruby.h"
|
|
|
|
#include "ruby/internal/config.h"
|
|
|
|
|
2021-11-10 19:49:55 -05:00
|
|
|
RBIMPL_SYMBOL_EXPORT_BEGIN()
|
2021-07-02 06:41:16 -04:00
|
|
|
|
2021-11-09 21:42:57 -05:00
|
|
|
// WARNING: This entire interface is experimental and may change in the future!
|
|
|
|
#define RB_IO_BUFFER_EXPERIMENTAL 1
|
|
|
|
|
2021-07-02 06:41:16 -04:00
|
|
|
RUBY_EXTERN VALUE rb_cIOBuffer;
|
|
|
|
RUBY_EXTERN size_t RUBY_IO_BUFFER_PAGE_SIZE;
|
2021-12-18 15:56:52 -05:00
|
|
|
RUBY_EXTERN size_t RUBY_IO_BUFFER_DEFAULT_SIZE;
|
2021-07-02 06:41:16 -04:00
|
|
|
|
|
|
|
enum rb_io_buffer_flags {
|
|
|
|
// The memory in the buffer is owned by someone else.
|
2021-12-19 18:37:05 -05:00
|
|
|
// More specifically, it means that someone else owns the buffer and we shouldn't try to resize it.
|
|
|
|
RB_IO_BUFFER_EXTERNAL = 1,
|
2021-07-02 06:41:16 -04:00
|
|
|
// The memory in the buffer is allocated internally.
|
2021-12-19 18:37:05 -05:00
|
|
|
RB_IO_BUFFER_INTERNAL = 2,
|
2021-07-02 06:41:16 -04:00
|
|
|
// The memory in the buffer is mapped.
|
2021-12-19 18:37:05 -05:00
|
|
|
// A non-private mapping is marked as external.
|
|
|
|
RB_IO_BUFFER_MAPPED = 4,
|
2021-07-02 06:41:16 -04:00
|
|
|
|
|
|
|
// The buffer is locked and cannot be resized.
|
2021-12-19 18:37:05 -05:00
|
|
|
// More specifically, it means we can't change the base address or size.
|
|
|
|
// A buffer is typically locked before a system call that uses the data.
|
|
|
|
RB_IO_BUFFER_LOCKED = 32,
|
2021-07-02 06:41:16 -04:00
|
|
|
|
|
|
|
// The buffer mapping is private and will not impact other processes or the underlying file.
|
2021-12-19 18:37:05 -05:00
|
|
|
RB_IO_BUFFER_PRIVATE = 64,
|
2021-07-02 06:41:16 -04:00
|
|
|
|
|
|
|
// The buffer is read-only and cannot be modified.
|
2021-12-19 18:37:05 -05:00
|
|
|
RB_IO_BUFFER_IMMUTABLE = 128
|
2021-07-02 06:41:16 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
enum rb_io_buffer_endian {
|
|
|
|
RB_IO_BUFFER_LITTLE_ENDIAN = 4,
|
|
|
|
RB_IO_BUFFER_BIG_ENDIAN = 8,
|
|
|
|
|
|
|
|
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
|
|
|
RB_IO_BUFFER_HOST_ENDIAN = RB_IO_BUFFER_LITTLE_ENDIAN,
|
|
|
|
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
|
|
|
RB_IO_BUFFER_HOST_ENDIAN = RB_IO_BUFFER_BIG_ENDIAN,
|
|
|
|
#elif REG_DWORD == REG_DWORD_LITTLE_ENDIAN
|
|
|
|
RB_IO_BUFFER_HOST_ENDIAN = RB_IO_BUFFER_LITTLE_ENDIAN,
|
|
|
|
#elif REG_DWORD == REG_DWORD_BIG_ENDIAN
|
|
|
|
RB_IO_BUFFER_HOST_ENDIAN = RB_IO_BUFFER_BIG_ENDIAN,
|
|
|
|
#endif
|
|
|
|
|
2021-11-10 02:41:26 -05:00
|
|
|
RB_IO_BUFFER_NETWORK_ENDIAN = RB_IO_BUFFER_BIG_ENDIAN
|
2021-07-02 06:41:16 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
VALUE rb_io_buffer_new(void *base, size_t size, enum rb_io_buffer_flags flags);
|
|
|
|
VALUE rb_io_buffer_map(VALUE io, size_t size, off_t offset, enum rb_io_buffer_flags flags);
|
|
|
|
|
|
|
|
VALUE rb_io_buffer_lock(VALUE self);
|
|
|
|
VALUE rb_io_buffer_unlock(VALUE self);
|
|
|
|
VALUE rb_io_buffer_free(VALUE self);
|
|
|
|
|
|
|
|
void rb_io_buffer_get_mutable(VALUE self, void **base, size_t *size);
|
|
|
|
void rb_io_buffer_get_immutable(VALUE self, const void **base, size_t *size);
|
|
|
|
|
|
|
|
size_t rb_io_buffer_copy(VALUE self, VALUE source, size_t offset);
|
2021-12-18 23:05:57 -05:00
|
|
|
VALUE rb_io_buffer_transfer(VALUE self);
|
|
|
|
void rb_io_buffer_resize(VALUE self, size_t size);
|
2021-07-02 06:41:16 -04:00
|
|
|
void rb_io_buffer_clear(VALUE self, uint8_t value, size_t offset, size_t length);
|
|
|
|
|
2021-11-10 19:49:55 -05:00
|
|
|
RBIMPL_SYMBOL_EXPORT_END()
|
2021-11-10 02:41:26 -05:00
|
|
|
|
|
|
|
#endif /* RUBY_IO_BUFFER_T */
|