win32-mmap 0.2.4 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +3 -2
- data/README +39 -40
- data/Rakefile +5 -5
- data/lib/win32/mmap.rb +392 -397
- data/lib/win32/windows/constants.rb +34 -0
- data/lib/win32/windows/functions.rb +50 -0
- data/lib/win32/windows/structs.rb +28 -0
- data/test/test_win32_mmap.rb +96 -96
- data/win32-mmap.gemspec +2 -4
- metadata +45 -50
@@ -0,0 +1,34 @@
|
|
1
|
+
module Windows
|
2
|
+
module Constants
|
3
|
+
GENERIC_READ = 0x80000000
|
4
|
+
GENERIC_WRITE = 0x40000000
|
5
|
+
|
6
|
+
WAIT_OBJECT_0 = 0
|
7
|
+
|
8
|
+
INVALID_HANDLE_VALUE = -1
|
9
|
+
|
10
|
+
PAGE_NOACCESS = 0x01
|
11
|
+
PAGE_READONLY = 0x02
|
12
|
+
PAGE_READWRITE = 0x04
|
13
|
+
PAGE_WRITECOPY = 0x08
|
14
|
+
PAGE_EXECUTE = 0x10
|
15
|
+
PAGE_EXECUTE_READ = 0x20
|
16
|
+
PAGE_EXECUTE_READWRITE = 0x40
|
17
|
+
PAGE_EXECUTE_WRITECOPY = 0x80
|
18
|
+
PAGE_GUARD = 0x100
|
19
|
+
PAGE_NOCACHE = 0x200
|
20
|
+
PAGE_WRITECOMBINE = 0x400
|
21
|
+
|
22
|
+
SEC_FILE = 0x800000
|
23
|
+
SEC_IMAGE = 0x1000000
|
24
|
+
SEC_VLM = 0x2000000
|
25
|
+
SEC_RESERVE = 0x4000000
|
26
|
+
SEC_COMMIT = 0x8000000
|
27
|
+
SEC_NOCACHE = 0x10000000
|
28
|
+
|
29
|
+
FILE_MAP_COPY = 0x0001
|
30
|
+
FILE_MAP_WRITE = 0x0002
|
31
|
+
FILE_MAP_READ = 0x0004
|
32
|
+
FILE_MAP_ALL_ACCESS = 983071
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
|
3
|
+
module Windows
|
4
|
+
module Functions
|
5
|
+
module FFI::Library
|
6
|
+
def attach_pfunc(*args)
|
7
|
+
attach_function(*args)
|
8
|
+
private args[0]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
extend FFI::Library
|
13
|
+
|
14
|
+
ffi_lib :kernel32
|
15
|
+
|
16
|
+
typedef :ulong, :dword
|
17
|
+
typedef :uintptr_t, :handle
|
18
|
+
typedef :pointer, :ptr
|
19
|
+
typedef :string, :str
|
20
|
+
|
21
|
+
attach_pfunc :CloseHandle, [:handle], :bool
|
22
|
+
|
23
|
+
attach_pfunc :CreateFile, :CreateFileA,
|
24
|
+
[:str, :dword, :dword, :pointer, :dword, :dword, :handle],
|
25
|
+
:handle
|
26
|
+
|
27
|
+
attach_pfunc :CreateFileMapping, :CreateFileMappingA,
|
28
|
+
[:handle, :pointer, :dword, :dword, :dword, :str],
|
29
|
+
:handle
|
30
|
+
|
31
|
+
attach_pfunc :CreateSemaphore, :CreateSemaphoreA,
|
32
|
+
[:pointer, :long, :long, :str],
|
33
|
+
:handle
|
34
|
+
|
35
|
+
attach_pfunc :FlushViewOfFile, [:uintptr_t, :size_t], :bool
|
36
|
+
|
37
|
+
attach_pfunc :MapViewOfFileEx,
|
38
|
+
[:handle, :dword, :dword, :dword, :size_t, :uintptr_t],
|
39
|
+
:uintptr_t
|
40
|
+
|
41
|
+
attach_pfunc :OpenFileMapping, :OpenFileMappingA,
|
42
|
+
[:dword, :bool, :str],
|
43
|
+
:handle
|
44
|
+
|
45
|
+
attach_pfunc :ReleaseSemaphore, [:handle, :long, :pointer], :bool
|
46
|
+
attach_pfunc :UnmapViewOfFile, [:uintptr_t], :bool
|
47
|
+
attach_pfunc :WaitForSingleObject, [:handle, :dword], :dword
|
48
|
+
attach_pfunc :VirtualQuery, [:uintptr_t, :pointer, :size_t], :size_t
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
|
3
|
+
module Windows
|
4
|
+
module Structs
|
5
|
+
extend FFI::Library
|
6
|
+
typedef :ulong, :dword
|
7
|
+
|
8
|
+
class SECURITY_ATTRIBUTES < FFI::Struct
|
9
|
+
layout(
|
10
|
+
:nLength, :dword,
|
11
|
+
:lpSecurityDescriptor, :pointer,
|
12
|
+
:bInheritHandle, :bool
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
class MEMORY_BASIC_INFORMATION < FFI::Struct
|
17
|
+
layout(
|
18
|
+
:BaseAddress, :pointer,
|
19
|
+
:AllocationBase, :pointer,
|
20
|
+
:AllocationProtect, :ulong,
|
21
|
+
:RegionSize, :size_t,
|
22
|
+
:State, :ulong,
|
23
|
+
:Protect, :dword,
|
24
|
+
:Type, :dword
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/test/test_win32_mmap.rb
CHANGED
@@ -4,104 +4,104 @@
|
|
4
4
|
# Test suite for the win32-mmap package. This should be run via the
|
5
5
|
# 'rake test' task.
|
6
6
|
#####################################################################
|
7
|
-
require 'test
|
7
|
+
require 'test-unit'
|
8
8
|
require 'win32/mmap'
|
9
9
|
include Win32
|
10
10
|
|
11
11
|
class TC_Win32_Mmap < Test::Unit::TestCase
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
12
|
+
def setup
|
13
|
+
@mmap = MMap.new(:name => 'test', :size => 100)
|
14
|
+
end
|
15
|
+
|
16
|
+
test "version is set to expected value" do
|
17
|
+
assert_equal('0.3.0', MMap::VERSION)
|
18
|
+
end
|
19
|
+
|
20
|
+
test "dynamic variable names and string values work as expected" do
|
21
|
+
assert_nothing_raised{ @mmap.foo = 'test' }
|
22
|
+
assert_nothing_raised{ @mmap.bar = 'alpha123' }
|
23
|
+
assert_equal('test', @mmap.foo)
|
24
|
+
assert_equal('alpha123', @mmap.bar)
|
25
|
+
end
|
26
|
+
|
27
|
+
test "dynamic variable names and integer values work as expected" do
|
28
|
+
assert_nothing_raised{ @mmap.bar = 7 }
|
29
|
+
assert_nothing_raised{ @mmap.zero = 0 }
|
30
|
+
assert_equal(7, @mmap.bar)
|
31
|
+
assert_equal(0, @mmap.zero)
|
32
|
+
end
|
33
|
+
|
34
|
+
test "dynamic variable names and hash values work as expected" do
|
35
|
+
assert_nothing_raised{ @mmap.ahash = {'foo' => 0} }
|
36
|
+
assert_nothing_raised{ @mmap.bhash = {'foo' => 0, 'bar' => 'hello'} }
|
37
|
+
assert_equal({'foo' => 0}, @mmap.ahash)
|
38
|
+
assert_equal({'foo' => 0, 'bar' => 'hello'}, @mmap.bhash)
|
39
|
+
end
|
40
|
+
|
41
|
+
test "dynamic variable names and array values work as expected" do
|
42
|
+
assert_nothing_raised{ @mmap.aarray = [1, 'x', 3] }
|
43
|
+
assert_nothing_raised{ @mmap.barray = [{1 => 2}, [1,2,3], 'foo'] }
|
44
|
+
assert_equal([1, 'x', 3], @mmap.aarray)
|
45
|
+
assert_equal([{1=>2}, [1,2,3], 'foo'], @mmap.barray)
|
46
|
+
end
|
47
|
+
|
48
|
+
test "passing an invalid option raises an argument error" do
|
49
|
+
assert_raises(ArgumentError){ MMap.new(:foo => 1) }
|
50
|
+
end
|
51
|
+
|
52
|
+
test "address method basic functionality" do
|
53
|
+
assert_respond_to(@mmap, :address)
|
54
|
+
assert_kind_of(Fixnum, @mmap.address)
|
55
|
+
end
|
56
|
+
|
57
|
+
test "base_address method basic functionality" do
|
58
|
+
assert_respond_to(@mmap, :base_address)
|
59
|
+
assert_respond_to(@mmap, :base_address=)
|
60
|
+
assert_kind_of(Fixnum, @mmap.base_address)
|
61
|
+
end
|
62
|
+
|
63
|
+
test "name accessor basic functionality" do
|
64
|
+
assert_respond_to(@mmap, :name)
|
65
|
+
assert_respond_to(@mmap, :name=)
|
66
|
+
assert_equal('test', @mmap.name)
|
67
|
+
end
|
68
|
+
|
69
|
+
test "inherit accessor basic functionality" do
|
70
|
+
assert_respond_to(@mmap, :inherit?)
|
71
|
+
assert_respond_to(@mmap, :inherit=)
|
72
|
+
assert_equal(false, @mmap.inherit?)
|
73
|
+
end
|
74
|
+
|
75
|
+
test "size accessor basic functionality" do
|
76
|
+
assert_respond_to(@mmap, :size)
|
77
|
+
assert_respond_to(@mmap, :size=)
|
78
|
+
assert_equal(100, @mmap.size)
|
79
|
+
end
|
80
|
+
|
81
|
+
test "file accessor basic functionality" do
|
82
|
+
assert_respond_to(@mmap, :file)
|
83
|
+
assert_respond_to(@mmap, :file=)
|
84
|
+
assert_nil(@mmap.file)
|
85
|
+
end
|
86
|
+
|
87
|
+
test "access accessor basic functionality" do
|
88
|
+
assert_respond_to(@mmap, :access)
|
89
|
+
assert_respond_to(@mmap, :access=)
|
90
|
+
end
|
91
|
+
|
92
|
+
test "autolock accessor basic functionality" do
|
93
|
+
assert_respond_to(@mmap, :autolock?)
|
94
|
+
assert_respond_to(@mmap, :autolock=)
|
95
|
+
assert_equal(true, @mmap.autolock?)
|
96
|
+
end
|
97
|
+
|
98
|
+
test "protection accessor basic functionality" do
|
99
|
+
assert_respond_to(@mmap, :protection)
|
100
|
+
assert_respond_to(@mmap, :protection=)
|
101
|
+
assert_equal(4, @mmap.protection)
|
102
|
+
end
|
103
|
+
|
104
|
+
def teardown
|
105
|
+
@mmap.close
|
106
|
+
end
|
107
107
|
end
|
data/win32-mmap.gemspec
CHANGED
@@ -2,15 +2,13 @@ require 'rubygems'
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = 'win32-mmap'
|
5
|
-
spec.version = '0.
|
5
|
+
spec.version = '0.3.0'
|
6
6
|
spec.author = 'Daniel J. Berger'
|
7
7
|
spec.license = 'Artistic 2.0'
|
8
8
|
spec.email = 'djberg96@gmail.com'
|
9
|
-
spec.homepage = '
|
10
|
-
spec.platform = Gem::Platform::RUBY
|
9
|
+
spec.homepage = 'https://github.com/djberg96/win32-mmap'
|
11
10
|
spec.summary = 'Memory mapped IO for Windows.'
|
12
11
|
spec.test_file = 'test/test_win32_mmap.rb'
|
13
|
-
spec.has_rdoc = true
|
14
12
|
spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
|
15
13
|
|
16
14
|
spec.rubyforge_project = 'win32utils'
|
metadata
CHANGED
@@ -1,84 +1,79 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: win32-mmap
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 2
|
8
|
-
- 4
|
9
|
-
version: 0.2.4
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Daniel J. Berger
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2013-04-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: windows-pr
|
22
|
-
|
23
|
-
|
24
|
-
requirements:
|
25
|
-
- -
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
|
28
|
-
- 0
|
29
|
-
version: "0"
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
30
22
|
type: :runtime
|
31
|
-
|
32
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: ! " The win32-mmap library provides an interface for memory mapped
|
31
|
+
IO on\n MS Windows.\n"
|
33
32
|
email: djberg96@gmail.com
|
34
33
|
executables: []
|
35
|
-
|
36
34
|
extensions: []
|
37
|
-
|
38
|
-
extra_rdoc_files:
|
35
|
+
extra_rdoc_files:
|
39
36
|
- MANIFEST
|
40
37
|
- README
|
41
38
|
- CHANGES
|
42
|
-
files:
|
39
|
+
files:
|
43
40
|
- CHANGES
|
44
41
|
- examples/example_mmap_client.rb
|
45
42
|
- examples/example_mmap_file.rb
|
46
43
|
- examples/example_mmap_server.rb
|
47
44
|
- lib/win32/mmap.rb
|
45
|
+
- lib/win32/windows/constants.rb
|
46
|
+
- lib/win32/windows/functions.rb
|
47
|
+
- lib/win32/windows/structs.rb
|
48
48
|
- MANIFEST
|
49
49
|
- Rakefile
|
50
50
|
- README
|
51
51
|
- test/test_win32_mmap.rb
|
52
52
|
- win32-mmap.gemspec
|
53
|
-
|
54
|
-
|
55
|
-
licenses:
|
53
|
+
homepage: https://github.com/djberg96/win32-mmap
|
54
|
+
licenses:
|
56
55
|
- Artistic 2.0
|
57
56
|
post_install_message:
|
58
57
|
rdoc_options: []
|
59
|
-
|
60
|
-
require_paths:
|
58
|
+
require_paths:
|
61
59
|
- lib
|
62
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
requirements:
|
71
|
-
- -
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
|
74
|
-
- 0
|
75
|
-
version: "0"
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
76
72
|
requirements: []
|
77
|
-
|
78
73
|
rubyforge_project: win32utils
|
79
|
-
rubygems_version: 1.
|
74
|
+
rubygems_version: 1.8.24
|
80
75
|
signing_key:
|
81
76
|
specification_version: 3
|
82
77
|
summary: Memory mapped IO for Windows.
|
83
|
-
test_files:
|
78
|
+
test_files:
|
84
79
|
- test/test_win32_mmap.rb
|