Skip to content

Commit 5cb57fe

Browse files
committed
[Truffle] Implemented Process.setrlimit.
1 parent ff619df commit 5cb57fe

File tree

4 files changed

+45
-38
lines changed

4 files changed

+45
-38
lines changed

spec/truffle/tags/core/process/setrlimit_tags.txt

Lines changed: 0 additions & 38 deletions
This file was deleted.

truffle/src/main/java/org/jruby/truffle/nodes/rubinius/PointerPrimitiveNodes.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ public long setAtOffsetLong(RubyBasicObject pointer, int offset, int type, long
217217
return value;
218218
}
219219

220+
@Specialization(guards = "type == TYPE_ULONG")
221+
public long setAtOffsetULong(RubyBasicObject pointer, int offset, int type, long value) {
222+
getPointer(pointer).putLong(offset, value);
223+
return value;
224+
}
225+
220226
}
221227

222228
@RubiniusPrimitive(name = "pointer_read_pointer")

truffle/src/main/java/org/jruby/truffle/nodes/rubinius/PosixNodes.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,27 @@ public int setreuid(int uid, int id) {
460460

461461
}
462462

463+
@CoreMethod(names = "setrlimit", isModuleFunction = true, required = 2)
464+
public abstract static class SetRLimitNode extends CoreMethodArrayArgumentsNode {
465+
466+
public SetRLimitNode(RubyContext context, SourceSection sourceSection) {
467+
super(context, sourceSection);
468+
}
469+
470+
@Specialization
471+
public int setrlimit(int resource, RubyBasicObject pointer) {
472+
final int result = posix().setrlimit(resource, PointerPrimitiveNodes.getPointer(pointer));
473+
474+
if (result == -1) {
475+
CompilerDirectives.transferToInterpreter();
476+
throw new RaiseException(getContext().getCoreLibrary().errnoError(posix().errno(), this));
477+
}
478+
479+
return result;
480+
}
481+
482+
}
483+
463484
@CoreMethod(names = "setruid", isModuleFunction = true, required = 1, lowerFixnumParameters = 0)
464485
public abstract static class SetRuidNode extends CoreMethodArrayArgumentsNode {
465486

truffle/src/main/ruby/core/rubinius/common/process.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,24 @@ class Rlimit < FFI::Struct
6868
config "rbx.platform.rlimit", :rlim_cur, :rlim_max
6969
end
7070

71+
def self.setrlimit(resource, cur_limit, max_limit=undefined)
72+
resource = coerce_rlimit_resource(resource)
73+
cur_limit = Rubinius::Type.coerce_to cur_limit, Integer, :to_int
74+
75+
unless undefined.equal? max_limit
76+
max_limit = Rubinius::Type.coerce_to max_limit, Integer, :to_int
77+
end
78+
79+
rlimit = Rlimit.new
80+
rlimit[:rlim_cur] = cur_limit
81+
rlimit[:rlim_max] = undefined.equal?(max_limit) ? cur_limit : max_limit
82+
83+
ret = FFI::Platform::POSIX.setrlimit(resource, rlimit.pointer)
84+
Errno.handle if ret == -1
85+
nil
86+
end
87+
88+
7189
def self.getrlimit(resource)
7290
resource = coerce_rlimit_resource(resource)
7391

0 commit comments

Comments
 (0)