syscalls 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@
5
5
  == SYNOPSIS
6
6
 
7
7
  An extension that lists the system's supported syscalls (e.g. SYS_open,
8
- SYS_write, etc.)}. These are read from <tt>sys/syscall.h</tt> when the gem is
8
+ SYS_write, etc.). These are read from <tt>sys/syscall.h</tt> when the gem is
9
9
  built.
10
10
 
11
11
  So far this has been tested on a couple of Linux machines; it should in
@@ -31,6 +31,15 @@ Tested on:
31
31
 
32
32
  sudo gem install syscalls
33
33
 
34
+ == HISTORY
35
+
36
+ <em>1.0.0</em>
37
+ * added a copy of <tt>Kernel.syscall</tt>, which is going away (according to a
38
+ warning that it gives in 1.9.2-p290).
39
+
40
+ <em>0.0.1</em>
41
+ * initial release
42
+
34
43
  == LICENSE
35
44
 
36
45
  (The MIT License)
@@ -43,10 +43,13 @@ File.open('syscalls.c', 'w') do |f|
43
43
  #include <ruby.h>
44
44
  #include <sys/syscall.h>
45
45
 
46
+ #include "syscall_wrapper.inc"
47
+
46
48
  void
47
49
  Init_syscalls(void)
48
50
  {
49
51
  VALUE mod = rb_define_module("Syscalls");
52
+ rb_define_singleton_method(mod, "syscall", syscalls_syscall, -1);
50
53
  <% syscall_names.each do |name| %>
51
54
  rb_define_const(mod, "<%= name %>", INT2FIX(<%= name %>));
52
55
  <% end %>
@@ -55,4 +58,4 @@ EOF
55
58
  f.puts template.result(binding)
56
59
  end
57
60
 
58
- create_makefile('syscalls')
61
+ create_makefile('syscalls/syscalls')
@@ -0,0 +1,162 @@
1
+ #include <unistd.h>
2
+
3
+ /*
4
+ * call-seq:
5
+ * syscall(num [, args...]) -> integer
6
+ *
7
+ * Calls the operating system function identified by _num_ and
8
+ * returns the result of the function or raises SystemCallError if
9
+ * it failed.
10
+ *
11
+ * Arguments for the function can follow _num_. They must be either
12
+ * +String+ objects or +Integer+ objects. A +String+ object is passed
13
+ * as a pointer to the byte sequence. An +Integer+ object is passed
14
+ * as an integer whose bit size is same as a pointer.
15
+ * Up to nine parameters may be passed (14 on the Atari-ST).
16
+ *
17
+ * The function identified by _num_ is system
18
+ * dependent. On some Unix systems, the numbers may be obtained from a
19
+ * header file called <code>syscall.h</code>.
20
+ *
21
+ * syscall 4, 1, "hello\n", 6 # '4' is write(2) on our box
22
+ *
23
+ * <em>produces:</em>
24
+ *
25
+ * hello
26
+ *
27
+ *
28
+ * Calling +syscall+ on a platform which does not have any way to
29
+ * an arbitrary system function just fails with NotImplementedError.
30
+ *
31
+ * Note::
32
+ * Taken from io.c in 1.9.2-p290. There is a warning that the global function
33
+ * (Kernel.syscall) will soon be removed, so I figured I'd remove the warning
34
+ * and keep it here.
35
+ */
36
+
37
+ static VALUE syscalls_syscall(int argc, VALUE *argv)
38
+ {
39
+ #ifdef atarist
40
+ VALUE arg[13]; /* yes, we really need that many ! */
41
+ #else
42
+ VALUE arg[8];
43
+ #endif
44
+ #if SIZEOF_VOIDP == 8 && defined(HAVE___SYSCALL) && SIZEOF_INT != 8 /* mainly *BSD */
45
+ # define SYSCALL __syscall
46
+ # define NUM2SYSCALLID(x) NUM2LONG(x)
47
+ # define RETVAL2NUM(x) LONG2NUM(x)
48
+ # if SIZEOF_LONG == 8
49
+ long num, retval = -1;
50
+ # elif SIZEOF_LONG_LONG == 8
51
+ long long num, retval = -1;
52
+ # else
53
+ # error ---->> it is asserted that __syscall takes the first argument and returns retval in 64bit signed integer. <<----
54
+ # endif
55
+ #elif defined linux
56
+ # define SYSCALL syscall
57
+ # define NUM2SYSCALLID(x) NUM2LONG(x)
58
+ # define RETVAL2NUM(x) LONG2NUM(x)
59
+ /*
60
+ * Linux man page says, syscall(2) function prototype is below.
61
+ *
62
+ * int syscall(int number, ...);
63
+ *
64
+ * But, it's incorrect. Actual one takes and returned long. (see unistd.h)
65
+ */
66
+ long num, retval = -1;
67
+ #else
68
+ # define SYSCALL syscall
69
+ # define NUM2SYSCALLID(x) NUM2INT(x)
70
+ # define RETVAL2NUM(x) INT2NUM(x)
71
+ int num, retval = -1;
72
+ #endif
73
+ int i;
74
+
75
+ /* from io.c */
76
+ #define numberof(array) (int)(sizeof(array) / sizeof((array)[0]))
77
+
78
+ /*
79
+ if (RTEST(ruby_verbose)) {
80
+ rb_warning("We plan to remove a syscall function at future release. DL(Fiddle) provides safer alternative.");
81
+ }
82
+ */
83
+
84
+ rb_secure(2);
85
+ if (argc == 0)
86
+ rb_raise(rb_eArgError, "too few arguments for syscall");
87
+ if (argc > numberof(arg))
88
+ rb_raise(rb_eArgError, "too many arguments for syscall");
89
+ num = NUM2SYSCALLID(argv[0]); ++argv;
90
+ for (i = argc - 1; i--; ) {
91
+ VALUE v = rb_check_string_type(argv[i]);
92
+
93
+ if (!NIL_P(v)) {
94
+ StringValue(v);
95
+ rb_str_modify(v);
96
+ arg[i] = (VALUE)StringValueCStr(v);
97
+ }
98
+ else {
99
+ arg[i] = (VALUE)NUM2LONG(argv[i]);
100
+ }
101
+ }
102
+
103
+ switch (argc) {
104
+ case 1:
105
+ retval = SYSCALL(num);
106
+ break;
107
+ case 2:
108
+ retval = SYSCALL(num, arg[0]);
109
+ break;
110
+ case 3:
111
+ retval = SYSCALL(num, arg[0],arg[1]);
112
+ break;
113
+ case 4:
114
+ retval = SYSCALL(num, arg[0],arg[1],arg[2]);
115
+ break;
116
+ case 5:
117
+ retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3]);
118
+ break;
119
+ case 6:
120
+ retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4]);
121
+ break;
122
+ case 7:
123
+ retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5]);
124
+ break;
125
+ case 8:
126
+ retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6]);
127
+ break;
128
+ #ifdef atarist
129
+ case 9:
130
+ retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
131
+ arg[7]);
132
+ break;
133
+ case 10:
134
+ retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
135
+ arg[7], arg[8]);
136
+ break;
137
+ case 11:
138
+ retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
139
+ arg[7], arg[8], arg[9]);
140
+ break;
141
+ case 12:
142
+ retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
143
+ arg[7], arg[8], arg[9], arg[10]);
144
+ break;
145
+ case 13:
146
+ retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
147
+ arg[7], arg[8], arg[9], arg[10], arg[11]);
148
+ break;
149
+ case 14:
150
+ retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
151
+ arg[7], arg[8], arg[9], arg[10], arg[11], arg[12]);
152
+ break;
153
+ #endif
154
+ }
155
+
156
+ if (retval == -1)
157
+ rb_sys_fail(0);
158
+ return RETVAL2NUM(retval);
159
+ #undef SYSCALL
160
+ #undef NUM2SYSCALLID
161
+ #undef RETVAL2NUM
162
+ }
@@ -1,4 +1,4 @@
1
- require 'syscalls.so'
1
+ require 'syscalls/syscalls'
2
2
  require 'syscalls/version'
3
3
 
4
4
  #
@@ -10,6 +10,10 @@ require 'syscalls/version'
10
10
  # The {SYS_NUMBER} and {SYS_NAME} hashes provide an easy way of converting from
11
11
  # names to numbers.
12
12
  #
13
+ # A <tt>Syscalls.syscall</tt> method is also provided; it is identical to
14
+ # <tt>Kernel.syscall</tt> in 1.9.2-p290, except that it doesn't give a warning
15
+ # that it will one day be removed.
16
+ #
13
17
  module Syscalls
14
18
  #
15
19
  # Hash from system call names (as symbols) to system call numbers.
@@ -1,6 +1,6 @@
1
1
  module Syscalls
2
- VERSION_MAJOR = 0
2
+ VERSION_MAJOR = 1
3
3
  VERSION_MINOR = 0
4
- VERSION_PATCH = 1
4
+ VERSION_PATCH = 0
5
5
  VERSION = [VERSION_MAJOR,VERSION_MINOR,VERSION_PATCH].join('.')
6
6
  end
@@ -10,7 +10,7 @@ class TestSyscalls < Test::Unit::TestCase
10
10
  end
11
11
 
12
12
  def test_getpid
13
- assert_equal Process.pid, syscall(SYS_getpid)
13
+ assert_equal Process.pid, Syscalls.syscall(SYS_getpid)
14
14
  end
15
15
  end
16
16
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: syscalls
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-23 00:00:00.000000000 +01:00
12
+ date: 2011-08-26 00:00:00.000000000 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
  description: An extension that lists the system's supported syscalls (e.g. SYS_open,
@@ -18,15 +18,16 @@ email:
18
18
  - jdleesmiller@gmail.com
19
19
  executables: []
20
20
  extensions:
21
- - ext/extconf.rb
21
+ - ext/syscalls/extconf.rb
22
22
  extra_rdoc_files:
23
23
  - README.rdoc
24
24
  files:
25
25
  - lib/syscalls.rb
26
26
  - lib/syscalls/version.rb
27
+ - ext/syscalls/syscall_wrapper.inc
27
28
  - README.rdoc
28
29
  - test/syscalls_test.rb
29
- - ext/extconf.rb
30
+ - ext/syscalls/extconf.rb
30
31
  has_rdoc: true
31
32
  homepage: https://github.com/jdleesmiller/syscalls_ruby
32
33
  licenses: []
@@ -35,10 +36,9 @@ rdoc_options:
35
36
  - --main
36
37
  - README.rdoc
37
38
  - --title
38
- - syscalls-0.0.1 Documentation
39
+ - syscalls-1.0.0 Documentation
39
40
  require_paths:
40
41
  - lib
41
- - ext
42
42
  required_ruby_version: !ruby/object:Gem::Requirement
43
43
  none: false
44
44
  requirements: