Skip to content

Commit

Permalink
Showing 4 changed files with 45 additions and 38 deletions.
38 changes: 0 additions & 38 deletions spec/truffle/tags/core/process/setrlimit_tags.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -217,6 +217,12 @@ public long setAtOffsetLong(RubyBasicObject pointer, int offset, int type, long
return value;
}

@Specialization(guards = "type == TYPE_ULONG")
public long setAtOffsetULong(RubyBasicObject pointer, int offset, int type, long value) {
getPointer(pointer).putLong(offset, value);
return value;
}

}

@RubiniusPrimitive(name = "pointer_read_pointer")
Original file line number Diff line number Diff line change
@@ -460,6 +460,27 @@ public int setreuid(int uid, int id) {

}

@CoreMethod(names = "setrlimit", isModuleFunction = true, required = 2)
public abstract static class SetRLimitNode extends CoreMethodArrayArgumentsNode {

public SetRLimitNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
public int setrlimit(int resource, RubyBasicObject pointer) {
final int result = posix().setrlimit(resource, PointerPrimitiveNodes.getPointer(pointer));

if (result == -1) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().errnoError(posix().errno(), this));
}

return result;
}

}

@CoreMethod(names = "setruid", isModuleFunction = true, required = 1, lowerFixnumParameters = 0)
public abstract static class SetRuidNode extends CoreMethodArrayArgumentsNode {

18 changes: 18 additions & 0 deletions truffle/src/main/ruby/core/rubinius/common/process.rb
Original file line number Diff line number Diff line change
@@ -68,6 +68,24 @@ class Rlimit < FFI::Struct
config "rbx.platform.rlimit", :rlim_cur, :rlim_max
end

def self.setrlimit(resource, cur_limit, max_limit=undefined)
resource = coerce_rlimit_resource(resource)
cur_limit = Rubinius::Type.coerce_to cur_limit, Integer, :to_int

unless undefined.equal? max_limit
max_limit = Rubinius::Type.coerce_to max_limit, Integer, :to_int
end

rlimit = Rlimit.new
rlimit[:rlim_cur] = cur_limit
rlimit[:rlim_max] = undefined.equal?(max_limit) ? cur_limit : max_limit

ret = FFI::Platform::POSIX.setrlimit(resource, rlimit.pointer)
Errno.handle if ret == -1
nil
end


def self.getrlimit(resource)
resource = coerce_rlimit_resource(resource)

0 comments on commit 5cb57fe

Please sign in to comment.