Skip to content

Commit

Permalink
Showing 18 changed files with 319 additions and 41 deletions.
3 changes: 1 addition & 2 deletions lib/pom.rb
Original file line number Diff line number Diff line change
@@ -86,8 +86,7 @@ def to_pathname
end
end

gem 'ruby-maven', '3.3.0', :scope => :provided
gem 'ruby-maven-libs', '3.3.3', :scope => :provided
gem 'ruby-maven', '3.3.2', :scope => :provided

default_gemnames = default_gems.collect { |g| g.name }

9 changes: 1 addition & 8 deletions lib/pom.xml
Original file line number Diff line number Diff line change
@@ -157,14 +157,7 @@
<dependency>
<groupId>rubygems</groupId>
<artifactId>ruby-maven</artifactId>
<version>3.3.0</version>
<type>gem</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>rubygems</groupId>
<artifactId>ruby-maven-libs</artifactId>
<version>3.3.3</version>
<version>3.3.2</version>
<type>gem</type>
<scope>provided</scope>
</dependency>
4 changes: 2 additions & 2 deletions maven/jruby-dist/pom.rb
Original file line number Diff line number Diff line change
@@ -12,8 +12,8 @@
'jruby.plugins.version' => '1.0.9', # Not sure why but wo this pom.xml get 1.0.8
'main.basedir' => '${project.parent.parent.basedir}' )

# pre-installed gems - not default gems !
gem 'ruby-maven', '3.1.1.0.11', :scope => 'provided'
# pre-installed gems - not yet default gems !
gem 'ruby-maven', '3.3.2', :scope => 'provided'

# HACK: add torquebox repo only when building from filesystem
# not when using the pom as "dependency" in some other projects
2 changes: 0 additions & 2 deletions spec/truffle/tags/core/process/egid_tags.txt

This file was deleted.

4 changes: 0 additions & 4 deletions spec/truffle/tags/core/process/euid_tags.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
fails:Process.euid also goes by Process::UID.eid
fails:Process.euid also goes by Process::Sys.geteuid
fails:Process.euid= raises TypeError if not passed an Integer
fails:Process.euid= raises Errno::ERPERM if run by a non superuser trying to set the superuser id
fails:Process.euid= raises Errno::ERPERM if run by a non superuser trying to set the superuser id from username
3 changes: 0 additions & 3 deletions spec/truffle/tags/core/process/uid_tags.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
fails:Process.uid also goes by Process::UID.rid
fails:Process.uid also goes by Process::Sys.getuid
fails:Process.uid= raises TypeError if not passed an Integer
fails:Process.uid= raises Errno::ERPERM if run by a non privileged user trying to set the superuser id
fails:Process.uid= raises Errno::ERPERM if run by a non privileged user trying to set the superuser id from username
7 changes: 3 additions & 4 deletions tool/jt.rb
Original file line number Diff line number Diff line change
@@ -256,17 +256,16 @@ def print(*args)

def test_mri(*args)
env_vars = {
"EXCLUDES" => "test/mri/excludes_truffle"
"EXCLUDES" => "test/mri/excludes_truffle"
}
jruby_args = %w[-J-Xmx2G -X+T -Xtruffle.exceptions.print_java]

if args.empty?
args = File.readlines("#{JRUBY_DIR}/test/mri_truffle.index").grep(/^[^#]\w+/).map(&:chomp)
end

command = %w[test/mri/runner.rb -v --color=never --tty=no -q --]
args.unshift(*command)
raw_sh(env_vars, "#{JRUBY_DIR}/bin/jruby", *jruby_args, *args)
command = %w[test/mri/runner.rb -v --color=never --tty=no -q]
raw_sh(env_vars, "#{JRUBY_DIR}/bin/jruby", *jruby_args, *command, *args)
end
private :test_mri

1 change: 0 additions & 1 deletion truffle/pom.rb
Original file line number Diff line number Diff line change
@@ -27,7 +27,6 @@
execute_goals( 'compile',
:id => 'default-compile',
:phase => 'compile',
'annotationProcessors' => [ 'com.oracle.truffle.dsl.processor.TruffleProcessor' ],
'generatedSourcesDirectory' => 'target/generated-sources',
'compilerArgs' => [ '-XDignore.symbol.file=true',
'-J-Duser.language=en',
3 changes: 0 additions & 3 deletions truffle/pom.xml
Original file line number Diff line number Diff line change
@@ -54,9 +54,6 @@
<goal>compile</goal>
</goals>
<configuration>
<annotationProcessors>
<annotationProcessor>com.oracle.truffle.dsl.processor.TruffleProcessor</annotationProcessor>
</annotationProcessors>
<generatedSourcesDirectory>target/generated-sources</generatedSourcesDirectory>
<compilerArgs>
<compilerArg>-XDignore.symbol.file=true</compilerArg>
Original file line number Diff line number Diff line change
@@ -595,7 +595,7 @@ public Object setOtherArray(VirtualFrame frame, RubyArray array, int start, int
CompilerDirectives.transferToInterpreter();
writeNode = insert(ArrayWriteDenormalizedNodeGen.create(getContext(), getSourceSection(), null, null, null));
}
Object[] values = ArrayUtils.box(value.getStore());
Object[] values = value.slowToArray();
if (value.getSize() == length || (begin + length + 1) > array.getSize()) {
int i = begin;
for (Object obj : values) {
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@ public abstract class ExceptionPrimitiveNodes {
public static abstract class ExceptionErrnoErrorPrimitiveNode extends RubiniusPrimitiveNode {

// If you add a constant here, add it below in isExceptionSupported() too.
protected final static int EPERM = Errno.EPERM.intValue();
protected final static int ENOENT = Errno.ENOENT.intValue();
protected final static int EBADF = Errno.EBADF.intValue();
protected final static int EEXIST = Errno.EEXIST.intValue();
@@ -37,13 +38,23 @@ public static abstract class ExceptionErrnoErrorPrimitiveNode extends RubiniusPr
protected final static int ENOTDIR = Errno.ENOTDIR.intValue();

public static boolean isExceptionSupported(int errno) {
return errno == ENOENT || errno == EBADF || errno == EEXIST || errno == EACCES || errno == EFAULT || errno == ENOTDIR;
return errno == EPERM || errno == ENOENT || errno == EBADF || errno == EEXIST || errno == EACCES || errno == EFAULT || errno == ENOTDIR;
}

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

@Specialization(guards = "errno == EPERM")
public RubyException eperm(RubyString message, int errno) {
return getContext().getCoreLibrary().operationNotPermittedError(message.toString(), this);
}

@Specialization(guards = {"errno == EPERM", "isNil(message)"})
public RubyException eperm(Object message, int errno) {
return getContext().getCoreLibrary().operationNotPermittedError("nil", this);
}

@Specialization(guards = "errno == ENOENT")
public RubyException enoent(RubyString message, int errno) {
return getContext().getCoreLibrary().fileNotFoundError(message.toString(), this);
112 changes: 112 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/nodes/rubinius/PosixNodes.java
Original file line number Diff line number Diff line change
@@ -351,6 +351,20 @@ public int getpriority(int kind, int id) {

}

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

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

@Specialization
public int setgid(int gid) {
return posix().setgid(gid);
}

}

@CoreMethod(names = "setpriority", isModuleFunction = true, required = 3, lowerFixnumParameters = {0, 1, 2})
public abstract static class SetPriorityNode extends CoreMethodArrayArgumentsNode {

@@ -365,6 +379,90 @@ public int setpriority(int kind, int id, int priority) {

}

@CoreMethod(names = "setresuid", isModuleFunction = true, required = 3, lowerFixnumParameters = {0, 1, 2})
public abstract static class SetResuidNode extends CoreMethodArrayArgumentsNode {

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

@Specialization
public int setresuid(int uid, int id, int priority) {
throw new RaiseException(getContext().getCoreLibrary().notImplementedError("setresuid", this));
}

}

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

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

@Specialization
public int seteuid(int uid) {
return posix().seteuid(uid);
}

}

@CoreMethod(names = "setreuid", isModuleFunction = true, required = 2, lowerFixnumParameters = {0, 1})
public abstract static class SetReuidNode extends CoreMethodArrayArgumentsNode {

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

@Specialization
public int setreuid(int uid, int id) {
throw new RaiseException(getContext().getCoreLibrary().notImplementedError("setreuid", this));
}

}

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

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

@Specialization
public int setruid(int uid) {
throw new RaiseException(getContext().getCoreLibrary().notImplementedError("setruid", this));
}

}

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

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

@Specialization
public int setuid(int uid) {
return posix().setuid(uid);
}

}

@CoreMethod(names = "setsid", isModuleFunction = true)
public abstract static class SetSidNode extends CoreMethodArrayArgumentsNode {

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

@Specialization
public int setsid() {
return posix().setsid();
}

}

@CoreMethod(names = "flock", isModuleFunction = true, required = 2, lowerFixnumParameters = {0, 1})
public abstract static class FlockNode extends CoreMethodArrayArgumentsNode {

@@ -545,6 +643,20 @@ public int isATTY(int fd) {

}

@CoreMethod(names = "getppid", isModuleFunction = true)
public abstract static class GetppidNode extends CoreMethodArrayArgumentsNode {

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

@Specialization
public int getppid() {
return posix().getppid();
}

}

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

Original file line number Diff line number Diff line change
@@ -319,7 +319,12 @@ public Object instanceEval(ByteList code, Object self, Node currentNode) {
}

public Object eval(Source source) {
return execute(source, UTF8Encoding.INSTANCE, TranslatorDriver.ParserContext.EVAL, getCoreLibrary().getMainObject(), null, null, NodeWrapper.IDENTITY);
return execute(source, UTF8Encoding.INSTANCE, TranslatorDriver.ParserContext.EVAL, getCoreLibrary().getMainObject(), null, null, new NodeWrapper() {
@Override
public RubyNode wrap(RubyNode node) {
return new SetMethodDeclarationContext(node.getContext(), node.getSourceSection(), Visibility.PRIVATE, "simple eval", node);
}
});
}

@TruffleBoundary
Original file line number Diff line number Diff line change
@@ -196,6 +196,25 @@ public static Object[] boxExtra(double[] unboxed, int extra) {
return boxed;
}

public static Object[] boxExtra(Object array, int extra) {
CompilerAsserts.neverPartOfCompilation();

if (array == null) {
return new Object[extra];
} else if (array instanceof int[]) {
return boxExtra((int[]) array, extra);
} else if (array instanceof long[]) {
return boxExtra((long[]) array, extra);
} else if (array instanceof double[]) {
return boxExtra((double[]) array, extra);
} else if (array instanceof Object[]) {
final Object[] objectArray = (Object[]) array;
return Arrays.copyOf(objectArray, objectArray.length + extra);
} else {
throw new UnsupportedOperationException();
}
}

public static Object[] boxUntil(int[] unboxed, int length) {
final Object[] boxed = new Object[length];

@@ -226,20 +245,20 @@ public static Object[] boxUntil(double[] unboxed, int length) {
return boxed;
}

public static Object[] boxExtra(Object array, int extra) {
public static Object[] boxUntil(Object array, int length) {
CompilerAsserts.neverPartOfCompilation();

if (array == null) {
return new Object[extra];
} if (array instanceof int[]) {
return boxExtra((int[]) array, extra);
return new Object[0];
} else if (array instanceof int[]) {
return boxUntil((int[]) array, length);
} else if (array instanceof long[]) {
return boxExtra((long[]) array, extra);
return boxUntil((long[]) array, length);
} else if (array instanceof double[]) {
return boxExtra((double[]) array, extra);
return boxUntil((double[]) array, length);
} else if (array instanceof Object[]) {
final Object[] objectArray = (Object[]) array;
return Arrays.copyOf(objectArray, objectArray.length + extra);
return Arrays.copyOf(objectArray, length);
} else {
throw new UnsupportedOperationException();
}
Original file line number Diff line number Diff line change
@@ -94,6 +94,7 @@ public class CoreLibrary {
private final RubyClass nameErrorClass;
private final RubyClass nilClass;
private final RubyClass noMethodErrorClass;
private final RubyClass notImplementedErrorClass;
private final RubyClass numericClass;
private final RubyClass objectClass;
private final RubyClass procClass;
@@ -270,7 +271,7 @@ public CoreLibrary(RubyContext context) {
// ScriptError
RubyClass scriptErrorClass = defineClass(exceptionClass, "ScriptError");
loadErrorClass = defineClass(scriptErrorClass, "LoadError");
defineClass(scriptErrorClass, "NotImplementedError");
notImplementedErrorClass = defineClass(scriptErrorClass, "NotImplementedError");
syntaxErrorClass = defineClass(scriptErrorClass, "SyntaxError");

// SecurityError
@@ -1014,6 +1015,11 @@ public RubyException zeroDivisionError(Node currentNode) {
return new RubyException(context.getCoreLibrary().getZeroDivisionErrorClass(), context.makeString("divided by 0"), RubyCallStack.getBacktrace(currentNode));
}

public RubyException notImplementedError(String message, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return new RubyException(notImplementedErrorClass, context.makeString(String.format("Method %s not implemented", message)), RubyCallStack.getBacktrace(currentNode));
}

public RubyException syntaxError(String message, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return new RubyException(syntaxErrorClass, context.makeString(message), RubyCallStack.getBacktrace(currentNode));
@@ -1065,6 +1071,11 @@ public RubyException dirNotEmptyError(String path, Node currentNode) {
return new RubyException(getErrnoClass(Errno.ENOTEMPTY), context.makeString(String.format("Directory not empty - %s", path)), RubyCallStack.getBacktrace(currentNode));
}

public RubyException operationNotPermittedError(String path, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return new RubyException(getErrnoClass(Errno.EPERM), context.makeString(String.format("Operation not permitted - %s", path)), RubyCallStack.getBacktrace(currentNode));
}

public RubyException permissionDeniedError(String path, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return new RubyException(getErrnoClass(Errno.EACCES), context.makeString(String.format("Permission denied - %s", path)), RubyCallStack.getBacktrace(currentNode));
Original file line number Diff line number Diff line change
@@ -135,7 +135,7 @@ private static Object storeFromObjects(RubyContext context, Object... objects) {
}

public Object[] slowToArray() {
return Arrays.copyOf(ArrayUtils.box(store), size);
return ArrayUtils.boxUntil(store, size);
}

public Object slowShift() {
136 changes: 136 additions & 0 deletions truffle/src/main/ruby/core/rubinius/common/process.rb
Original file line number Diff line number Diff line change
@@ -64,6 +64,12 @@ module Constants

FFI = Rubinius::FFI

def self.setsid
pgid = FFI::Platform::POSIX.setsid
Errno.handle if pgid == -1
pgid
end

def self.times
Struct::Tms.new(*cpu_times)
end
@@ -90,6 +96,73 @@ def self.getpgrp
ret
end

def self.ppid
ret = FFI::Platform::POSIX.getppid
Errno.handle if ret == -1
ret
end

def self.uid=(uid)
# the 4 rescue clauses below are needed
# until respond_to? can be used to query the implementation of methods attached via FFI
# atm respond_to returns true if a method is attached but not implemented on the platform
uid = Rubinius::Type.coerce_to uid, Integer, :to_int
begin
ret = FFI::Platform::POSIX.setresuid(uid, -1, -1)
rescue NotImplementedError
begin
ret = FFI::Platform::POSIX.setreuid(uid, -1)
rescue NotImplementedError
begin
ret = FFI::Platform::POSIX.setruid(uid)
rescue NotImplementedError
if Process.euid == uid
ret = FFI::Platform::POSIX.setuid(uid)
else
raise NotImplementedError
end
end
end
end

Errno.handle if ret == -1

uid
end

def self.gid=(gid)
gid = Rubinius::Type.coerce_to gid, Integer, :to_int
Process::Sys.setgid gid
end

def self.euid=(uid)
# the 4 rescue clauses below are needed
# until respond_to? can be used to query the implementation of methods attached via FFI
# atm respond_to returns true if a method is attached but not implemented on the platform
uid = Rubinius::Type.coerce_to uid, Integer, :to_int
begin
ret = FFI::Platform::POSIX.setresuid(-1, uid, -1)
rescue NotImplementedError
begin
ret = FFI::Platform::POSIX.setreuid(-1, uid)
rescue NotImplementedError
begin
ret = FFI::Platform::POSIX.seteuid(uid)
rescue NotImplementedError
if Process.uid == uid
ret = FFI::Platform::POSIX.setuid(uid)
else
raise NotImplementedError
end
end
end
end

Errno.handle if ret == -1

uid
end

def self.uid
ret = FFI::Platform::POSIX.getuid
Errno.handle if ret == -1
@@ -400,6 +473,69 @@ def setresuid(rid, eid, sid)
end
end

module UID
class << self
def change_privilege(uid)
uid = Rubinius::Type.coerce_to uid, Integer, :to_int

ret = FFI::Platform::POSIX.setreuid(uid, uid)
Errno.handle if ret == -1
uid
end

def eid
ret = FFI::Platform::POSIX.geteuid
Errno.handle if ret == -1
ret
end

def eid=(uid)
uid = Rubinius::Type.coerce_to uid, Integer, :to_int

ret = FFI::Platform::POSIX.seteuid(uid)
Errno.handle if ret == -1
uid
end
alias_method :grant_privilege, :eid=

def re_exchange
real = FFI::Platform::POSIX.getuid
Errno.handle if real == -1
eff = FFI::Platform::POSIX.geteuid
Errno.handle if eff == -1
ret = FFI::Platform::POSIX.setreuid(eff, real)
Errno.handle if ret == -1
eff
end

def re_exchangeable?
true
end

def rid
ret = FFI::Platform::POSIX.getuid
Errno.handle if ret == -1
ret
end

def sid_available?
true
end

def switch
eff = re_exchange
if block_given?
ret = yield
re_exchange
return ret
else
return eff
end
end

end
end

module GID
class << self
def change_privilege(gid)
6 changes: 6 additions & 0 deletions truffle/src/main/ruby/core/shims.rb
Original file line number Diff line number Diff line change
@@ -220,6 +220,12 @@ def printf(fmt, *args)

class Exception

def locations
# These should be Rubinius::Location
# and use the internal backtrace, never the custom one.
backtrace.each { |s| def s.position; self; end }
end

def to_s
message.to_s
end

0 comments on commit e26c54f

Please sign in to comment.