Module: Ragweed::Wraptux
- Defined in:
- lib/ragweed/wraptux.rb,
lib/ragweed/wraptux/threads.rb,
lib/ragweed/wraptux/wraptux.rb,
lib/ragweed/wraptux/constants.rb
Defined Under Namespace
Modules: Ptrace, Signal, ThreadInfo, Wait
Constant Summary collapse
- VERSION =
:stopdoc:
'0.1.6'- LIBPATH =
::File.(::File.dirname(__FILE__)) + ::File::SEPARATOR
- PATH =
::File.dirname(LIBPATH) + ::File::SEPARATOR
- LIBS =
Hash.new do |h, str| if not str =~ /^[\.\/].*/ str = "/lib/" + str end if not str =~ /.*\.so.6$/ str = str + ".so.6" end h[str] = DL.dlopen(str) end
- CALLS =
Hash.new do |h, str| lib = proc = args = ret = nil lib, rest = str.split "!" proc, rest = rest.split ":" args, ret = rest.split("=") if rest ret ||= "0" raise "need proc" if not proc h[str] = LIBS[lib][proc, ret + args] end
- NULL =
DL::PtrData.new(0)
- SIZEOFINT =
DL.sizeof('I')
- SIZEOFLONG =
DL.sizeof('L')
Class Method Summary collapse
- .getpid ⇒ Object
-
.kill(pid, sig) ⇒ Object
kill(pid_t pid, int sig);.
-
.libpath(*args) ⇒ Object
Returns the library path for the module.
- .malloc(sz) ⇒ Object
-
.path(*args) ⇒ Object
Returns the lpath for the module.
-
.ptrace(request, pid, addr, data) ⇒ Object
long ptrace(enum __ptrace_request request, pid_t pid, void *addr, void *data);.
-
.require_all_libs_relative_to(fname, dir = nil) ⇒ Object
Utility method used to require all files ending in .rb that lie in the directory below this file that has the same name as the filename passed in.
-
.version ⇒ Object
Returns the version string for the library.
-
.wait ⇒ Object
wait(int *status);.
-
.waitpid(pid, opt = 1) ⇒ Object
waitpid(pid_t pid, int *stat_loc, int options);.
Class Method Details
.getpid ⇒ Object
72 73 74 |
# File 'lib/ragweed/wraptux/wraptux.rb', line 72 def getpid CALLS["libc!getpid:=I"].call.first end |
.kill(pid, sig) ⇒ Object
kill(pid_t pid, int sig);
66 67 68 69 70 |
# File 'lib/ragweed/wraptux/wraptux.rb', line 66 def kill(pid, sig) DL.last_error = 0 r = CALLS["libc!kill:II=I"].call(pid,sig).first raise SystemCallError.new("kill",DL.last_error) if r != 0 end |
.libpath(*args) ⇒ Object
Returns the library path for the module. If any arguments are given, they will be joined to the end of the libray path using File.join.
23 24 25 |
# File 'lib/ragweed/wraptux.rb', line 23 def self.libpath( *args ) args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten) end |
.malloc(sz) ⇒ Object
43 44 45 46 |
# File 'lib/ragweed/wraptux/wraptux.rb', line 43 def malloc(sz) r = CALLS["libc!malloc:L=L"].call(sz) return r end |
.path(*args) ⇒ Object
Returns the lpath for the module. If any arguments are given, they will be joined to the end of the path using File.join.
31 32 33 |
# File 'lib/ragweed/wraptux.rb', line 31 def self.path( *args ) args.empty? ? PATH : ::File.join(PATH, args.flatten) end |
.ptrace(request, pid, addr, data) ⇒ Object
long ptrace(enum __ptrace_request request, pid_t pid, void *addr, void *data);
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ragweed/wraptux/wraptux.rb', line 32 def ptrace(request, pid, addr, data) DL.last_error = 0 r = CALLS["libc!ptrace:IIII=I"].call(request, pid, addr, data).first raise SystemCallError.new("ptrace", DL.last_error) if r == -1 and DL.last_error != 0 case request when Ptrace::PEEK_TEXT, Ptrace::PEEK_DATA return r end end |
.require_all_libs_relative_to(fname, dir = nil) ⇒ Object
Utility method used to require all files ending in .rb that lie in the directory below this file that has the same name as the filename passed in. Optionally, a specific directory name can be passed in such that the filename does not have to be equivalent to the directory.
40 41 42 43 44 45 46 47 48 |
# File 'lib/ragweed/wraptux.rb', line 40 def self.require_all_libs_relative_to( fname, dir = nil ) dir ||= ::File.basename(fname, '.*') search_me = ::File.( ::File.join(::File.dirname(fname), dir, '**', '*.rb')) Dir.glob(search_me).sort.each {|rb| require rb} # require File.dirname(File.basename(__FILE__)) + "/#{x}" end |
.version ⇒ Object
Returns the version string for the library.
15 16 17 |
# File 'lib/ragweed/wraptux.rb', line 15 def self.version VERSION end |
.wait ⇒ Object
wait(int *status);
49 50 51 52 53 54 55 |
# File 'lib/ragweed/wraptux/wraptux.rb', line 49 def wait status = ("\x00"*SIZEOFINT).to_ptr.to_i r = CALLS["libc!wait:I=I"].call(status).first raise SystemCallError.new("wait", DL.last_error) if r == -1 self.continue # continue with the ptrace at this point return status.to_s(SIZEOFINT).unpack('i_').first end |
.waitpid(pid, opt = 1) ⇒ Object
waitpid(pid_t pid, int *stat_loc, int options);
58 59 60 61 62 63 |
# File 'lib/ragweed/wraptux/wraptux.rb', line 58 def waitpid(pid, opt=1) pstatus = ("\x00"*SIZEOFINT).to_ptr r = CALLS["libc!waitpid:IPI=I"].call(pid, pstatus, opt).first raise SystemCallError.new("waitpid", DL.last_error) if r == -1 return [r, pstatus.to_s(SIZEOFINT).unpack('i_').first] end |