win32-mmap 0.3.0 → 0.3.1
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 +57 -53
- data/MANIFEST +10 -10
- data/README +64 -64
- data/Rakefile +43 -43
- data/examples/example_mmap_client.rb +19 -19
- data/examples/example_mmap_file.rb +24 -24
- data/examples/example_mmap_server.rb +19 -19
- data/lib/win32/mmap.rb +1 -1
- data/lib/win32/windows/constants.rb +1 -0
- data/lib/win32/windows/functions.rb +50 -50
- data/lib/win32/windows/structs.rb +28 -28
- data/test/test_win32_mmap.rb +107 -107
- data/win32-mmap.gemspec +23 -23
- metadata +3 -3
data/CHANGES
CHANGED
@@ -1,53 +1,57 @@
|
|
1
|
-
== 0.3.
|
2
|
-
*
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
*
|
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
|
-
== 0.1.
|
45
|
-
*
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
1
|
+
== 0.3.1 - 26-Apr-2013
|
2
|
+
* Added the missing OPEN_ALWAYS constant. Thanks go to Frank Quednau.
|
3
|
+
* Set the dependency properly (ffi now, not windows-pr).
|
4
|
+
|
5
|
+
== 0.3.0 - 10-Apr-2013
|
6
|
+
* Converted code to use FFI.
|
7
|
+
|
8
|
+
== 0.2.4 - 28-Apr-2010
|
9
|
+
* The Rakefile was refactored. It now handles gem creation, building and
|
10
|
+
cleanup.
|
11
|
+
* Inline code was removed from the gemspec.
|
12
|
+
|
13
|
+
== 0.2.3 - 12-Aug-2009
|
14
|
+
* Changed license to Artistic 2.0.
|
15
|
+
* The MMap.open method now properly handles a block.
|
16
|
+
* Some gemspec updates, including the license and description.
|
17
|
+
* Changed test and example file names.
|
18
|
+
* Some Rakefile updates, including tasks for running example programs.
|
19
|
+
|
20
|
+
== 0.2.2 - 16-May-2007
|
21
|
+
* Fixed a bug where marshalled data that happened to end with a "\0" would
|
22
|
+
cause the getter to fail.
|
23
|
+
* Now runs -w clean.
|
24
|
+
* Added more tests.
|
25
|
+
* Removed the install.rb file. Installation is now handled via the 'rake
|
26
|
+
install' task.
|
27
|
+
* Updated the MANIFEST file and made it rdoc friendly.
|
28
|
+
|
29
|
+
== 0.2.1 - 22-Oct-2006
|
30
|
+
* Removed the custom memcpy function since that function now does the right
|
31
|
+
thing regardless of argument type.
|
32
|
+
* Now requires windows-pr 0.5.6 or later (to take advantage of the improved
|
33
|
+
memcpy).
|
34
|
+
|
35
|
+
== 0.2.0 - 13-Oct-2006
|
36
|
+
* Completely scrapped the old interface and code. It is now pure Ruby and
|
37
|
+
has a much different API, and some internal changes.
|
38
|
+
* Added a gemspec and an install.rb file for manual installation.
|
39
|
+
* Now requires the windows-pr package, 0.5.5 or higher.
|
40
|
+
* Modified the example scripts.
|
41
|
+
* Updated the docs, and replaced the .txt and .rd files with a single .rdoc
|
42
|
+
file.
|
43
|
+
|
44
|
+
== 0.1.1 - 1-Mar-2005
|
45
|
+
* Moved the 'examples' directory to the toplevel directory.
|
46
|
+
* Made the CHANGES and README files rdoc friendly.
|
47
|
+
|
48
|
+
== 0.1.0 - 12-Aug-2004
|
49
|
+
* Modified to use the newer allocation framework. That means that, as of
|
50
|
+
this release, this package requires Ruby 1.8.0 or later.
|
51
|
+
* Moved sample programs under doc/examples.
|
52
|
+
|
53
|
+
== 0.0.2 - 14-Mar-2004
|
54
|
+
* Fixed sprintf() bug in new().
|
55
|
+
|
56
|
+
== 0.0.1 - 13-Mar-2004
|
57
|
+
* Initial (Beta) release
|
data/MANIFEST
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
* CHANGES
|
2
|
-
* MANIFEST
|
3
|
-
* README
|
4
|
-
* Rakefile
|
5
|
-
* win32-mmap.gemspec
|
6
|
-
* examples/example_mmap.rb
|
7
|
-
* examples/example_mmap_client.rb
|
8
|
-
* examples/example_mmap_server.rb
|
9
|
-
* lib/win32/mmap.rb
|
10
|
-
* test/test_win32_mmap.rb
|
1
|
+
* CHANGES
|
2
|
+
* MANIFEST
|
3
|
+
* README
|
4
|
+
* Rakefile
|
5
|
+
* win32-mmap.gemspec
|
6
|
+
* examples/example_mmap.rb
|
7
|
+
* examples/example_mmap_client.rb
|
8
|
+
* examples/example_mmap_server.rb
|
9
|
+
* lib/win32/mmap.rb
|
10
|
+
* test/test_win32_mmap.rb
|
data/README
CHANGED
@@ -1,64 +1,64 @@
|
|
1
|
-
= Description
|
2
|
-
This package provides a Ruby interface for memory mapped I/O on MS Windows.
|
3
|
-
|
4
|
-
= Prerequisites
|
5
|
-
windows-pr, 0.5.5 or later.
|
6
|
-
|
7
|
-
= Installation
|
8
|
-
gem install win32-mmap
|
9
|
-
|
10
|
-
= Synopsis
|
11
|
-
require 'win32/mmap'
|
12
|
-
include Win32
|
13
|
-
|
14
|
-
map1 = MMap.new(:file => "C:\\test.map", :size => 1024)
|
15
|
-
map1.foo = 'hello'
|
16
|
-
map1.bar = 77
|
17
|
-
map1.close
|
18
|
-
|
19
|
-
map2 = MMap.new(:file => "C:\\test.map")
|
20
|
-
p map2.foo # 'hello'
|
21
|
-
p map2.bar # 77
|
22
|
-
map2.close
|
23
|
-
|
24
|
-
= About Memory Mapped Files under Windows
|
25
|
-
Under Windows, code and data are both repesented by pages of memory backed
|
26
|
-
by files on disk, code by executable image and data by system pagefile
|
27
|
-
(i.e. swapfile). These are called memory mapped files. Memory mapped files
|
28
|
-
can be used to provide a mechanism for shared memory between processes.
|
29
|
-
Different processes are able to share data backed by the same swapfile,
|
30
|
-
whether it's the system pagefile or a user-defined swapfile.
|
31
|
-
|
32
|
-
Windows has a tight security system that prevents processes from directly
|
33
|
-
sharing information among each other, but mapped memory files provide a
|
34
|
-
mechanism that works with the Windows security system by using a name that
|
35
|
-
all processes use to open the swapfile.
|
36
|
-
|
37
|
-
A shared section of the swapfile is translated into pages of memory that are
|
38
|
-
addressable by more than one process, Windows uses a system resource called a
|
39
|
-
prototype page table entry (PPTE) to enable more than one process to address
|
40
|
-
the same physical page of memory, thus multiple process can share the same
|
41
|
-
data without violating the Windows system security.
|
42
|
-
|
43
|
-
In short, memory mapped files provide shared memory under Windows.
|
44
|
-
|
45
|
-
(This explanation was largely borrowed from Roger Lee's Win32::MMF Perl
|
46
|
-
module.)
|
47
|
-
|
48
|
-
= Future Plans
|
49
|
-
Suggestions welcome.
|
50
|
-
|
51
|
-
= License
|
52
|
-
Artistic 2.0
|
53
|
-
|
54
|
-
= Copyright
|
55
|
-
(C) 2003-2013 Daniel J. Berger, All Rights Reserved
|
56
|
-
|
57
|
-
= Warranty
|
58
|
-
This package is provided "as is" and without any express or
|
59
|
-
implied warranties, including, without limitation, the implied
|
60
|
-
warranties of merchantability and fitness for a particular purpose.
|
61
|
-
|
62
|
-
= Authors
|
63
|
-
Daniel J. Berger
|
64
|
-
Park Heesob
|
1
|
+
= Description
|
2
|
+
This package provides a Ruby interface for memory mapped I/O on MS Windows.
|
3
|
+
|
4
|
+
= Prerequisites
|
5
|
+
windows-pr, 0.5.5 or later.
|
6
|
+
|
7
|
+
= Installation
|
8
|
+
gem install win32-mmap
|
9
|
+
|
10
|
+
= Synopsis
|
11
|
+
require 'win32/mmap'
|
12
|
+
include Win32
|
13
|
+
|
14
|
+
map1 = MMap.new(:file => "C:\\test.map", :size => 1024)
|
15
|
+
map1.foo = 'hello'
|
16
|
+
map1.bar = 77
|
17
|
+
map1.close
|
18
|
+
|
19
|
+
map2 = MMap.new(:file => "C:\\test.map")
|
20
|
+
p map2.foo # 'hello'
|
21
|
+
p map2.bar # 77
|
22
|
+
map2.close
|
23
|
+
|
24
|
+
= About Memory Mapped Files under Windows
|
25
|
+
Under Windows, code and data are both repesented by pages of memory backed
|
26
|
+
by files on disk, code by executable image and data by system pagefile
|
27
|
+
(i.e. swapfile). These are called memory mapped files. Memory mapped files
|
28
|
+
can be used to provide a mechanism for shared memory between processes.
|
29
|
+
Different processes are able to share data backed by the same swapfile,
|
30
|
+
whether it's the system pagefile or a user-defined swapfile.
|
31
|
+
|
32
|
+
Windows has a tight security system that prevents processes from directly
|
33
|
+
sharing information among each other, but mapped memory files provide a
|
34
|
+
mechanism that works with the Windows security system by using a name that
|
35
|
+
all processes use to open the swapfile.
|
36
|
+
|
37
|
+
A shared section of the swapfile is translated into pages of memory that are
|
38
|
+
addressable by more than one process, Windows uses a system resource called a
|
39
|
+
prototype page table entry (PPTE) to enable more than one process to address
|
40
|
+
the same physical page of memory, thus multiple process can share the same
|
41
|
+
data without violating the Windows system security.
|
42
|
+
|
43
|
+
In short, memory mapped files provide shared memory under Windows.
|
44
|
+
|
45
|
+
(This explanation was largely borrowed from Roger Lee's Win32::MMF Perl
|
46
|
+
module.)
|
47
|
+
|
48
|
+
= Future Plans
|
49
|
+
Suggestions welcome.
|
50
|
+
|
51
|
+
= License
|
52
|
+
Artistic 2.0
|
53
|
+
|
54
|
+
= Copyright
|
55
|
+
(C) 2003-2013 Daniel J. Berger, All Rights Reserved
|
56
|
+
|
57
|
+
= Warranty
|
58
|
+
This package is provided "as is" and without any express or
|
59
|
+
implied warranties, including, without limitation, the implied
|
60
|
+
warranties of merchantability and fitness for a particular purpose.
|
61
|
+
|
62
|
+
= Authors
|
63
|
+
Daniel J. Berger
|
64
|
+
Park Heesob
|
data/Rakefile
CHANGED
@@ -1,43 +1,43 @@
|
|
1
|
-
require 'rake'
|
2
|
-
require 'rake/clean'
|
3
|
-
require 'rake/testtask'
|
4
|
-
|
5
|
-
CLEAN.include('**/*.gem')
|
6
|
-
|
7
|
-
namespace 'gem' do
|
8
|
-
desc 'Create the win32-mmap gem.'
|
9
|
-
task :create => [:clean] do
|
10
|
-
spec = eval(IO.read('win32-mmap.gemspec'))
|
11
|
-
Gem::Builder.new(spec).build
|
12
|
-
end
|
13
|
-
|
14
|
-
desc 'Install the win32-mmap gem.'
|
15
|
-
task :install => [:create] do
|
16
|
-
file = Dir['*.gem'].first
|
17
|
-
sh "gem install #{file}"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
namespace 'example' do
|
22
|
-
desc 'Run the example mmap file program'
|
23
|
-
task :file do
|
24
|
-
ruby '-Ilib examples/example_mmap_file.rb'
|
25
|
-
end
|
26
|
-
|
27
|
-
desc 'Run the example mmap server'
|
28
|
-
task :server do
|
29
|
-
ruby '-Ilib examples/example_mmap_server.rb'
|
30
|
-
end
|
31
|
-
|
32
|
-
desc 'Run the example mmap client'
|
33
|
-
task :client do
|
34
|
-
ruby '-Ilib examples/example_mmap_client.rb'
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
Rake::TestTask.new do |t|
|
39
|
-
t.verbose = true
|
40
|
-
t.warning = true
|
41
|
-
end
|
42
|
-
|
43
|
-
task :default => :test
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/clean'
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
CLEAN.include('**/*.gem')
|
6
|
+
|
7
|
+
namespace 'gem' do
|
8
|
+
desc 'Create the win32-mmap gem.'
|
9
|
+
task :create => [:clean] do
|
10
|
+
spec = eval(IO.read('win32-mmap.gemspec'))
|
11
|
+
Gem::Builder.new(spec).build
|
12
|
+
end
|
13
|
+
|
14
|
+
desc 'Install the win32-mmap gem.'
|
15
|
+
task :install => [:create] do
|
16
|
+
file = Dir['*.gem'].first
|
17
|
+
sh "gem install #{file}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
namespace 'example' do
|
22
|
+
desc 'Run the example mmap file program'
|
23
|
+
task :file do
|
24
|
+
ruby '-Ilib examples/example_mmap_file.rb'
|
25
|
+
end
|
26
|
+
|
27
|
+
desc 'Run the example mmap server'
|
28
|
+
task :server do
|
29
|
+
ruby '-Ilib examples/example_mmap_server.rb'
|
30
|
+
end
|
31
|
+
|
32
|
+
desc 'Run the example mmap client'
|
33
|
+
task :client do
|
34
|
+
ruby '-Ilib examples/example_mmap_client.rb'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
Rake::TestTask.new do |t|
|
39
|
+
t.verbose = true
|
40
|
+
t.warning = true
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :test
|
@@ -1,20 +1,20 @@
|
|
1
|
-
#######################################################################
|
2
|
-
# example_mmap_client.rb
|
3
|
-
#
|
4
|
-
# This program demonstrates a simple mmap client. You should run this
|
5
|
-
# program *after* you have run the example server program in a
|
6
|
-
# separate terminal.
|
7
|
-
#
|
8
|
-
# You can run this program via the 'rake example_client' task.
|
9
|
-
#
|
10
|
-
# Modify this program as you see fit.
|
11
|
-
#######################################################################
|
12
|
-
require 'win32/mmap'
|
13
|
-
include Win32
|
14
|
-
|
15
|
-
mmap = MMap.open('alpha')
|
16
|
-
|
17
|
-
p mmap.foo
|
18
|
-
p mmap.bar
|
19
|
-
|
1
|
+
#######################################################################
|
2
|
+
# example_mmap_client.rb
|
3
|
+
#
|
4
|
+
# This program demonstrates a simple mmap client. You should run this
|
5
|
+
# program *after* you have run the example server program in a
|
6
|
+
# separate terminal.
|
7
|
+
#
|
8
|
+
# You can run this program via the 'rake example_client' task.
|
9
|
+
#
|
10
|
+
# Modify this program as you see fit.
|
11
|
+
#######################################################################
|
12
|
+
require 'win32/mmap'
|
13
|
+
include Win32
|
14
|
+
|
15
|
+
mmap = MMap.open('alpha')
|
16
|
+
|
17
|
+
p mmap.foo
|
18
|
+
p mmap.bar
|
19
|
+
|
20
20
|
mmap.close
|
@@ -1,25 +1,25 @@
|
|
1
|
-
#######################################################################
|
2
|
-
# example_mmap_file.rb
|
3
|
-
#
|
4
|
-
# This sample script demonstrates creating a memory mapped file, then
|
5
|
-
# later reading from it. You can run this example via the
|
6
|
-
# 'rake example_file' task.
|
7
|
-
#
|
8
|
-
# Modify this program as you see fit.
|
9
|
-
#######################################################################
|
10
|
-
require 'win32/mmap'
|
11
|
-
include Win32
|
12
|
-
|
13
|
-
map1 = MMap.new(:file => "C:\\mmap.test", :size => 1024)
|
14
|
-
|
15
|
-
map1.foo = 'hello'
|
16
|
-
map1.bar = 77
|
17
|
-
|
18
|
-
map1.close
|
19
|
-
|
20
|
-
map2 = MMap.new(:file => "C:\\mmap.test")
|
21
|
-
|
22
|
-
p map2.foo
|
23
|
-
p map2.bar
|
24
|
-
|
1
|
+
#######################################################################
|
2
|
+
# example_mmap_file.rb
|
3
|
+
#
|
4
|
+
# This sample script demonstrates creating a memory mapped file, then
|
5
|
+
# later reading from it. You can run this example via the
|
6
|
+
# 'rake example_file' task.
|
7
|
+
#
|
8
|
+
# Modify this program as you see fit.
|
9
|
+
#######################################################################
|
10
|
+
require 'win32/mmap'
|
11
|
+
include Win32
|
12
|
+
|
13
|
+
map1 = MMap.new(:file => "C:\\mmap.test", :size => 1024)
|
14
|
+
|
15
|
+
map1.foo = 'hello'
|
16
|
+
map1.bar = 77
|
17
|
+
|
18
|
+
map1.close
|
19
|
+
|
20
|
+
map2 = MMap.new(:file => "C:\\mmap.test")
|
21
|
+
|
22
|
+
p map2.foo
|
23
|
+
p map2.bar
|
24
|
+
|
25
25
|
map2.close
|
@@ -1,20 +1,20 @@
|
|
1
|
-
#######################################################################
|
2
|
-
# example_mmap_server.rb
|
3
|
-
#
|
4
|
-
# A test script for general futzing. Run this in its own terminal
|
5
|
-
# then run the example_mmap_client.rb program in a separate terminal.
|
6
|
-
# You can run this program via the 'rake example_server' task.
|
7
|
-
#
|
8
|
-
# Modify as you see fit.
|
9
|
-
#######################################################################
|
10
|
-
require 'win32/mmap'
|
11
|
-
include Win32
|
12
|
-
|
13
|
-
mmap = MMap.new(:name => 'alpha', :size => 2000)
|
14
|
-
|
15
|
-
mmap.foo = 'hello'
|
16
|
-
mmap.bar = 27
|
17
|
-
|
18
|
-
sleep 100
|
19
|
-
|
1
|
+
#######################################################################
|
2
|
+
# example_mmap_server.rb
|
3
|
+
#
|
4
|
+
# A test script for general futzing. Run this in its own terminal
|
5
|
+
# then run the example_mmap_client.rb program in a separate terminal.
|
6
|
+
# You can run this program via the 'rake example_server' task.
|
7
|
+
#
|
8
|
+
# Modify as you see fit.
|
9
|
+
#######################################################################
|
10
|
+
require 'win32/mmap'
|
11
|
+
include Win32
|
12
|
+
|
13
|
+
mmap = MMap.new(:name => 'alpha', :size => 2000)
|
14
|
+
|
15
|
+
mmap.foo = 'hello'
|
16
|
+
mmap.bar = 27
|
17
|
+
|
18
|
+
sleep 100
|
19
|
+
|
20
20
|
mmap.close
|
data/lib/win32/mmap.rb
CHANGED
@@ -1,50 +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
|
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
|
@@ -1,28 +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
|
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
@@ -1,107 +1,107 @@
|
|
1
|
-
#####################################################################
|
2
|
-
# test_win32_mmap.rb
|
3
|
-
#
|
4
|
-
# Test suite for the win32-mmap package. This should be run via the
|
5
|
-
# 'rake test' task.
|
6
|
-
#####################################################################
|
7
|
-
require 'test-unit'
|
8
|
-
require 'win32/mmap'
|
9
|
-
include Win32
|
10
|
-
|
11
|
-
class TC_Win32_Mmap < Test::Unit::TestCase
|
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.
|
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
|
-
end
|
1
|
+
#####################################################################
|
2
|
+
# test_win32_mmap.rb
|
3
|
+
#
|
4
|
+
# Test suite for the win32-mmap package. This should be run via the
|
5
|
+
# 'rake test' task.
|
6
|
+
#####################################################################
|
7
|
+
require 'test-unit'
|
8
|
+
require 'win32/mmap'
|
9
|
+
include Win32
|
10
|
+
|
11
|
+
class TC_Win32_Mmap < Test::Unit::TestCase
|
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.1', 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
|
+
end
|
data/win32-mmap.gemspec
CHANGED
@@ -1,23 +1,23 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
|
3
|
-
Gem::Specification.new do |spec|
|
4
|
-
spec.name = 'win32-mmap'
|
5
|
-
spec.version = '0.3.
|
6
|
-
spec.author = 'Daniel J. Berger'
|
7
|
-
spec.license = 'Artistic 2.0'
|
8
|
-
spec.email = 'djberg96@gmail.com'
|
9
|
-
spec.homepage = 'https://github.com/djberg96/win32-mmap'
|
10
|
-
spec.summary = 'Memory mapped IO for Windows.'
|
11
|
-
spec.test_file = 'test/test_win32_mmap.rb'
|
12
|
-
spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
|
13
|
-
|
14
|
-
spec.rubyforge_project = 'win32utils'
|
15
|
-
spec.extra_rdoc_files = ['MANIFEST', 'README', 'CHANGES']
|
16
|
-
|
17
|
-
spec.add_dependency('
|
18
|
-
|
19
|
-
spec.description = <<-EOF
|
20
|
-
The win32-mmap library provides an interface for memory mapped IO on
|
21
|
-
MS Windows.
|
22
|
-
EOF
|
23
|
-
end
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'win32-mmap'
|
5
|
+
spec.version = '0.3.1'
|
6
|
+
spec.author = 'Daniel J. Berger'
|
7
|
+
spec.license = 'Artistic 2.0'
|
8
|
+
spec.email = 'djberg96@gmail.com'
|
9
|
+
spec.homepage = 'https://github.com/djberg96/win32-mmap'
|
10
|
+
spec.summary = 'Memory mapped IO for Windows.'
|
11
|
+
spec.test_file = 'test/test_win32_mmap.rb'
|
12
|
+
spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
|
13
|
+
|
14
|
+
spec.rubyforge_project = 'win32utils'
|
15
|
+
spec.extra_rdoc_files = ['MANIFEST', 'README', 'CHANGES']
|
16
|
+
|
17
|
+
spec.add_dependency('ffi')
|
18
|
+
|
19
|
+
spec.description = <<-EOF
|
20
|
+
The win32-mmap library provides an interface for memory mapped IO on
|
21
|
+
MS Windows.
|
22
|
+
EOF
|
23
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: win32-mmap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,10 +9,10 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: ffi
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|