From f1441a8be611d8f60b52ea6661a174c43207d016 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Mon, 10 Feb 2025 10:15:32 -0800 Subject: [PATCH] Remove ancient unsafe native code. All Javas have reasonably fine grained Thread.sleep these days, and we no longer need to set our pid or gid or temporarily disable GC. --- .../com/threerings/media/FrameManager.java | 9 +- .../java/com/threerings/util/unsafe/Darwin | 1 - .../threerings/util/unsafe/FreeBSD/Makefile | 45 ---- .../com_threerings_util_unsafe_Unsafe.c | 117 ---------- .../util/unsafe/FreeBSD/libunsafe.so | Bin 7779 -> 0 bytes .../com/threerings/util/unsafe/Linux/Makefile | 44 ---- .../Linux/com_threerings_util_unsafe_Unsafe.c | 1 - .../threerings/util/unsafe/Linux/libunsafe.so | Bin 8251 -> 0 bytes .../threerings/util/unsafe/Mac OS X/Makefile | 45 ---- .../com_threerings_util_unsafe_Unsafe.c | 1 - .../util/unsafe/Mac OS X/libunsafe.jnilib | Bin 13932 -> 0 bytes .../com/threerings/util/unsafe/Unsafe.java | 209 ------------------ .../threerings/util/unsafe/Windows/Makefile | 49 ---- .../com_threerings_util_unsafe_Unsafe.c | 80 ------- .../com_threerings_util_unsafe_Unsafe.h | 77 ------- .../java/com/threerings/util/UIDTestApp.java | 46 ---- 16 files changed, 6 insertions(+), 718 deletions(-) delete mode 120000 core/src/main/java/com/threerings/util/unsafe/Darwin delete mode 100644 core/src/main/java/com/threerings/util/unsafe/FreeBSD/Makefile delete mode 100644 core/src/main/java/com/threerings/util/unsafe/FreeBSD/com_threerings_util_unsafe_Unsafe.c delete mode 100755 core/src/main/java/com/threerings/util/unsafe/FreeBSD/libunsafe.so delete mode 100644 core/src/main/java/com/threerings/util/unsafe/Linux/Makefile delete mode 120000 core/src/main/java/com/threerings/util/unsafe/Linux/com_threerings_util_unsafe_Unsafe.c delete mode 100755 core/src/main/java/com/threerings/util/unsafe/Linux/libunsafe.so delete mode 100644 core/src/main/java/com/threerings/util/unsafe/Mac OS X/Makefile delete mode 120000 core/src/main/java/com/threerings/util/unsafe/Mac OS X/com_threerings_util_unsafe_Unsafe.c delete mode 100755 core/src/main/java/com/threerings/util/unsafe/Mac OS X/libunsafe.jnilib delete mode 100644 core/src/main/java/com/threerings/util/unsafe/Unsafe.java delete mode 100644 core/src/main/java/com/threerings/util/unsafe/Windows/Makefile delete mode 100644 core/src/main/java/com/threerings/util/unsafe/Windows/com_threerings_util_unsafe_Unsafe.c delete mode 100644 core/src/main/java/com/threerings/util/unsafe/com_threerings_util_unsafe_Unsafe.h delete mode 100644 core/src/test/java/com/threerings/util/UIDTestApp.java diff --git a/core/src/main/java/com/threerings/media/FrameManager.java b/core/src/main/java/com/threerings/media/FrameManager.java index f4ca913d..dd4f5a3a 100644 --- a/core/src/main/java/com/threerings/media/FrameManager.java +++ b/core/src/main/java/com/threerings/media/FrameManager.java @@ -37,8 +37,6 @@ import com.samskivert.util.StringUtil; import com.samskivert.swing.RuntimeAdjust; -import com.threerings.util.unsafe.Unsafe; - import com.threerings.media.timer.CalibratingTimer; import com.threerings.media.timer.MediaTimer; import com.threerings.media.timer.MillisTimer; @@ -640,7 +638,12 @@ public abstract class FrameManager if (_perfDebug.getValue()) { start = _timer.getElapsedMicros(); } - Unsafe.sleep(_sleepGranularity.getValue()); + long millis = _sleepGranularity.getValue(); + try { + Thread.sleep(millis); + } catch (InterruptedException ie) { + log.info("Thread.sleep(" + millis + ") interrupted."); + } long woke = _timer.getElapsedMicros(); if (start > 0L) { diff --git a/core/src/main/java/com/threerings/util/unsafe/Darwin b/core/src/main/java/com/threerings/util/unsafe/Darwin deleted file mode 120000 index af20c446..00000000 --- a/core/src/main/java/com/threerings/util/unsafe/Darwin +++ /dev/null @@ -1 +0,0 @@ -Mac OS X \ No newline at end of file diff --git a/core/src/main/java/com/threerings/util/unsafe/FreeBSD/Makefile b/core/src/main/java/com/threerings/util/unsafe/FreeBSD/Makefile deleted file mode 100644 index 4e9a9951..00000000 --- a/core/src/main/java/com/threerings/util/unsafe/FreeBSD/Makefile +++ /dev/null @@ -1,45 +0,0 @@ -# -# $Id: Makefile 3332 2005-02-03 01:30:33Z mdb $ - -# -# Executable definitions - -CC=gcc -RM=rm -CP=cp -MKDIR=mkdir - -# -# Directory definitions - -ROOT=../../../../../../../.. -LIBRARIES_PATH= -OSINCDIR!=uname -s | tr 'A-Z' 'a-z' -INSTALL_PATH=${ROOT}/dist/lib/i386-FreeBSD - -# -# Parameter and file definitions - -INCLUDES=-I.. -I${JAVA_HOME}/include -I${JAVA_HOME}/include/${OSINCDIR} -LIBRARIES= -TARGET=libunsafe.so - -# -# Target definitions - -all: ${TARGET} - -install: - @${MKDIR} -p ${INSTALL_PATH} - cp ${TARGET} ${INSTALL_PATH} - -${TARGET}: com_threerings_util_unsafe_Unsafe.c - @echo "Compiling Unsafe.c" - @${CC} ${INCLUDES} -c com_threerings_util_unsafe_Unsafe.c \ - -o com_threerings_util_unsafe_Unsafe.o - @echo "Creating libunsafe.so" - @${CC} -o ${TARGET} com_threerings_util_unsafe_Unsafe.o \ - ${LIBRARIES} ${LIBRARIES_PATH} -shared - -clean: - -${RM} -f *.o ${TARGET} diff --git a/core/src/main/java/com/threerings/util/unsafe/FreeBSD/com_threerings_util_unsafe_Unsafe.c b/core/src/main/java/com/threerings/util/unsafe/FreeBSD/com_threerings_util_unsafe_Unsafe.c deleted file mode 100644 index abe1fd3e..00000000 --- a/core/src/main/java/com/threerings/util/unsafe/FreeBSD/com_threerings_util_unsafe_Unsafe.c +++ /dev/null @@ -1,117 +0,0 @@ -/* - * $Id: com_threerings_util_unsafe_Unsafe.c 3653 2005-07-21 19:10:08Z mdb $ - */ - -#include -#include -#include - -#include -#include -#include -#include - -#include "com_threerings_util_unsafe_Unsafe.h" - -/* global jvmpi interface pointer */ -static JVMPI_Interface* jvmpi; - -/** A sleep method that uses select(). This seems to have about 10ms - * granularity where nanosleep() has about 20ms. Sigh. */ -static int select_sleep (int millisecs) -{ - fd_set dummy; - struct timeval toWait; - FD_ZERO(&dummy); - toWait.tv_sec = millisecs / 1000; - toWait.tv_usec = (millisecs % 1000) * 1000; - return select(0, &dummy, NULL, NULL, &toWait); -} - -JNIEXPORT void JNICALL -Java_com_threerings_util_unsafe_Unsafe_enableGC (JNIEnv* env, jclass clazz) -{ - jvmpi->EnableGC(); -} - -JNIEXPORT void JNICALL -Java_com_threerings_util_unsafe_Unsafe_disableGC (JNIEnv* env, jclass clazz) -{ - jvmpi->DisableGC(); -} - -JNIEXPORT void JNICALL -Java_com_threerings_util_unsafe_Unsafe_nativeSleep ( - JNIEnv* env, jclass clazz, jint millis) -{ -/* struct timespec tmspec; */ -/* tmspec.tv_sec = millis/1000; */ -/* tmspec.tv_nsec = (millis%1000)*1000000; */ -/* if (nanosleep(&tmspec, NULL) < 0) { */ -/* fprintf(stderr, "nanosleep() failed: %s\n", strerror(errno)); */ -/* } */ - if (select_sleep(millis) < 0) { - fprintf(stderr, "select_sleep() failed: %s\n", strerror(errno)); - } -} - -JNIEXPORT jboolean JNICALL -Java_com_threerings_util_unsafe_Unsafe_nativeSetuid ( - JNIEnv* env, jclass clazz, jint uid) -{ - if (setuid((uid_t)uid) != 0) { - fprintf(stderr, "setuid(%d) failed: %s\n", uid, strerror(errno)); - return JNI_FALSE; - } - return JNI_TRUE; -} - -JNIEXPORT jboolean JNICALL -Java_com_threerings_util_unsafe_Unsafe_nativeSetgid ( - JNIEnv* env, jclass clazz, jint gid) -{ - if (setgid((gid_t)gid) != 0) { - fprintf(stderr, "setgid(%d) failed: %s\n", gid, strerror(errno)); - return JNI_FALSE; - } - return JNI_TRUE; -} - -JNIEXPORT jboolean JNICALL Java_com_threerings_util_unsafe_Unsafe_nativeSeteuid ( - JNIEnv* env, jclass clzz, jint uid) -{ - if (seteuid((uid_t)uid) != 0) { - fprintf(stderr, "seteuid(%d) failed: %s\n", uid, strerror(errno)); - return JNI_FALSE; - } - return JNI_TRUE; -} - -JNIEXPORT jboolean JNICALL Java_com_threerings_util_unsafe_Unsafe_nativeSetegid ( - JNIEnv* env, jclass clazz, jint gid) -{ - if (setegid((gid_t)gid) != 0) { - fprintf(stderr, "setegid(%d) failed: %s\n", gid, strerror(errno)); - return JNI_FALSE; - } - return JNI_TRUE; -} - -JNIEXPORT jboolean JNICALL -Java_com_threerings_util_unsafe_Unsafe_init (JNIEnv* env, jclass clazz) -{ - JavaVM* jvm; - - if ((*env)->GetJavaVM(env, &jvm) > 0) { - fprintf(stderr, "Failed to get JavaVM from env.\n"); - return JNI_FALSE; - } - - /* get jvmpi interface pointer */ - if (((*jvm)->GetEnv(jvm, (void**)&jvmpi, JVMPI_VERSION_1)) < 0) { - fprintf(stderr, "Failed to get JVMPI from JavaVM.\n"); - return JNI_FALSE; - } - - return JNI_TRUE; -} diff --git a/core/src/main/java/com/threerings/util/unsafe/FreeBSD/libunsafe.so b/core/src/main/java/com/threerings/util/unsafe/FreeBSD/libunsafe.so deleted file mode 100755 index 659bddc296600f449fee568c8ea466a7d8cba2f2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7779 zcmeHMeQaA-6~C@S>$RbC(?It@+t;myWVBAwuXRyX+NMsL(xhpVRxNFLIQC2I%CRl` zIct&jg%@p+l~J@J4QZf3K^hFu#P-J!Fj5j|3;YpvlNd0GNHCPB72BYUXhbu=-+lMG zuddrA75xj2a(wRjxaZz??s@Otd-6zdceBUixlJhW3a{{>y%Uo4lvO#3^}>LrMl2E4 zQtwFB@9m(#kC62XM-R$2@iIs?oX!O$KL?}|RO9pDiPTpBR{`sRgf$M4zjdzm64m}B zXaIN@utv!Y&=tUY6kiLvT(wE=aJ4_>YO{Gaa5eDLz?HzIK*D{%WwLc^em+*>_Twcy z*-rqg%gD8eano?GYTT&>H=w7K&RKaO-eCd&ymF<$b5SJkmGsCwNuYNWqdv{c3=n@Q z@^Zz+RFQW&GPej`;V7Q_sOBBT_lx{|M}b@+c*O!qeMP=f^2{TGS2!JCF7gYd{HH~p zi7Lcsk#`#Biu@v}zg*;1@=GcGFBU&U+mC5bQ-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+1Ajwx!IZSTgc>dQ0d)D zzu~M~XC6IP>LyId(GNetylFnaOnJE}e^CnB!-Ehmd7zzUMY5Yyp9&|t%Qq)yab diff --git a/core/src/main/java/com/threerings/util/unsafe/Mac OS X/Makefile b/core/src/main/java/com/threerings/util/unsafe/Mac OS X/Makefile deleted file mode 100644 index 88619c0d..00000000 --- a/core/src/main/java/com/threerings/util/unsafe/Mac OS X/Makefile +++ /dev/null @@ -1,45 +0,0 @@ -# -# $Id: Makefile 3332 2005-02-03 01:30:33Z mdb $ - -# -# Executable definitions - -CC=gcc -RM=rm -CP=cp -MKDIR=mkdir - -# -# Directory definitions - -ROOT=../../../../../../../.. -LIBRARIES_PATH= -OSINCDIR!=uname -s | tr 'A-Z' 'a-z' -INSTALL_PATH=${ROOT}/dist/lib/`uname -m`-Darwin - -# -# Parameter and file definitions - -INCLUDES=-I.. -I/System/Library/Frameworks/JavaVM.framework/Headers -LIBRARIES= -TARGET=libunsafe.jnilib - -# -# Target definitions - -all: ${TARGET} - -install: - @${MKDIR} -p ${INSTALL_PATH} - cp ${TARGET} ${INSTALL_PATH} - -${TARGET}: com_threerings_util_unsafe_Unsafe.c - @echo "Compiling $<" - @${CC} ${INCLUDES} -c com_threerings_util_unsafe_Unsafe.c \ - -o com_threerings_util_unsafe_Unsafe.o - @echo "Creating $@" - @${CC} -o ${TARGET} com_threerings_util_unsafe_Unsafe.o \ - ${LIBRARIES} ${LIBRARIES_PATH} -dynamiclib - -clean: - -${RM} -f *.o ${TARGET} diff --git a/core/src/main/java/com/threerings/util/unsafe/Mac OS X/com_threerings_util_unsafe_Unsafe.c b/core/src/main/java/com/threerings/util/unsafe/Mac OS X/com_threerings_util_unsafe_Unsafe.c deleted file mode 120000 index f28bcf8e..00000000 --- a/core/src/main/java/com/threerings/util/unsafe/Mac OS X/com_threerings_util_unsafe_Unsafe.c +++ /dev/null @@ -1 +0,0 @@ -../FreeBSD/com_threerings_util_unsafe_Unsafe.c \ No newline at end of file diff --git a/core/src/main/java/com/threerings/util/unsafe/Mac OS X/libunsafe.jnilib b/core/src/main/java/com/threerings/util/unsafe/Mac OS X/libunsafe.jnilib deleted file mode 100755 index 4e7796d86e169d12dd0bf319d3565039d3e541b7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 13932 zcmeHOTWnNC7@oZd3sk6D5v9PAETl!)QY=kv1VOscBE@1$Z9-(Sm(%u?y=BkYhGL?{ zb&Z?NdN)4!z>~%|A;v@vF)cKd_&}gu5{)K2)MO2q7}ErU%KH6t&UQ~PP|BM)ll*7? z`RBiWGfns5p9|N2yRncl<^U}KEdo_K8B1ffftvB*yu;VkfrWLHn+wcje-8*|VsNf2 zM|E?7X}Z0031f9orrBOnBL{=UCFgN9s0~B{u`t*4WMI0FhGm9kaW2}qnBn6Q2sjUF zdP0r%n47ct7{MO-u;yXqjaq^+f0#$9r0G8XhAm2AG+W0KOD%+>Q{dRNvty@4i!ihh zok5XEi}R3Q_Y-Ff&S%HE+ zgRRH|I#wT4cX1Fu1me7LMytLxJxlLsw)Yzi0L_OavS;6Y#qhF2a-|#4Is|?Cc&~zo@eaeetB`d;-^j(O*7IWoejI|*N{AsZ^5DmJTM0Cy%ffj?tYmK#Mi;?pX zX4*RqIqgpl_@#Q5gUUhgPT!wYl#E0`A|Mfv2uK9}TL|PS-LAsPYxswq9sCR5!ev92 z9lRn|2Q$BP9>4l6)N<*gg+d{7=JP=;GEE-WXp@Kj&$CR0CqGsJ2d%ErbO&_4X$_QT z1$XV&;p+=B=ZF7XlettqoH?IK$FYBF#qX=nWj+g$TAIGYm+cP0&318;8NTeu zd|iDe^WJT1r*(MDi6l@#IVzxE9t<=6LMWDqx<;KI66Ak>fU)BvRQ}=T&jO3~)KzEx zEBwmHr7qx`W!W8Fg^Q^X=b_T}394Q$Q7gfLk~ zqSwJ?hI6S?Bq`6meG;KF`#i2(>NI}vAZaJTeHgo`k&4Nnp8STA*D7qLhjd@QntTYa z4dBS@A(E85mQfz4J(qgf;@k$MQQrjBe`O&U`Vo}%O{7LVmUv&nz^vla`^|V?fHC5o z2S@R)kYu)a8!YkOg3_Gv_Lky32Ypdr3wamyb%CRJFOX!mcw;D{2;N#K%^B}U7?}0_ ze4iQb2QWswJUEKCm07@*MH%@_izn3m59mFx?;D1f`qxxo{~8W9gw6t8=Lj zMEu+!-HF^g>nTJB?gMVkei33^99bvM3T~QLsWjV>~rdhZ~?NVI`<@EvzW=pstdd%IU=LzL_i`S5s(N-1SA3y0f~S_Kq4R!kO)WwBm#FG0u%EYcU|?eAc=rP zKq4R!kO)WwBmxoviGV~vA|Mfv2>eeFK$8O+8=S|{S+bOxrLlgWc=R$;PdN445bpy2 z9r%#V&YWm2{=>qrM5{)(30EcfCrtiP@Pj7*IQS3+f~^y>)!Q*k@S+u(IZ%61US{DdEPSPfUuWUH7QWuXZ@2Jl z2Z9ZOHsC+dxl(`al;Jv(?CJ4X6@CIIaS%1U(F*_YZCm^@daLHoS@c zZJN<0Bi3l!5i>fS#EkAWF+XU|)H6={&B)C@F!Bm8w|Xk;N8h+kcVTjBgr@u0`Vp#phiP@Uc!5oa9l~?Z9t@# z)YSka{t!v1+lB{Y5w7$WYF=sXS7sH)$# z_o!c2`;~U1|L6{^(9JY|E3`Vz-{=k^QOg$2imUYv^WzXW349)SK><4dSh(PivXRl8a?7x zLaL4&!Vsf0A_KQ_S4_ff@bs6_R|fbrJFFtyy;;u9EF(;iDEg32y`uve+sr6q|r zZEf(@dTVQLxv2)@;iN|74Kmgf3~r%|9jCrGFKg7RHgBx0-X^|yC1Y)mW4x~)dW`)G DOt;3# diff --git a/core/src/main/java/com/threerings/util/unsafe/Unsafe.java b/core/src/main/java/com/threerings/util/unsafe/Unsafe.java deleted file mode 100644 index a71d5722..00000000 --- a/core/src/main/java/com/threerings/util/unsafe/Unsafe.java +++ /dev/null @@ -1,209 +0,0 @@ -// -// Nenya library - tools for developing networked games -// Copyright (C) 2002-2012 Three Rings Design, Inc., All Rights Reserved -// https://github.com/threerings/nenya -// -// This library is free software; you can redistribute it and/or modify it -// under the terms of the GNU Lesser General Public License as published -// by the Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -package com.threerings.util.unsafe; - -import com.samskivert.util.RunAnywhere; - -import static com.threerings.NenyaLog.log; - -/** - * A native library for doing unsafe things. Don't use this library. If - * you must ignore that warning, then be sure you use it sparingly and - * only in very well considered cases. - */ -public class Unsafe -{ - /** - * Enables or disables garbage collection. Warning: you will - * be fucked if you leave it disabled for too long. Do not do this - * unless you are dang sure about what you're doing and are prepared - * to test your code on every platform this side of Nantucket. - * - *

Calls to this method do not nest. Regardless of how many times - * you disable GC, only one call is required to reenable it. - */ - public static void setGCEnabled (boolean enabled) - { - // we don't support nesting, NOOP if the state doesn't change - if (isLoaded()) { - if (!_initialized && !(_initialized = init())) { - // no joy initializing things - return; - } - - if (_initialized && enabled != _gcEnabled) { - _gcEnabled = enabled; - if (_gcEnabled) { - enableGC(); - } else { - disableGC(); - } - } - } - } - - /** - * Causes the current thread to block for the specified number of - * milliseconds. This exists primarily to work around the fact that on - * Linux, {@link Thread#sleep(long)} is only accurate to around 12ms which - * is wholly unacceptable. - */ - public static void sleep (int millis) - { - if (RunAnywhere.isLinux() && isLoaded()) { - nativeSleep(millis); - } else { - try { - Thread.sleep(millis); - } catch (InterruptedException ie) { - log.info("Thread.sleep(" + millis + ") interrupted."); - } - } - } - - /** - * Sets the process' uid to the specified value. - * - * @return true if the uid was changed, false if we were unable to do so. - */ - public static boolean setuid (int uid) - { - if (!RunAnywhere.isWindows() && isLoaded()) { - return nativeSetuid(uid); - } - return false; - } - - /** - * Sets the process' gid to the specified value. - * - * @return true if the gid was changed, false if we were unable to do so. - */ - public static boolean setgid (int gid) - { - if (!RunAnywhere.isWindows() && isLoaded()) { - return nativeSetgid(gid); - } - return false; - } - - /** - * Sets the process' effective uid to the specified value. - * - * @return true if the euid was changed, false if we were unable to do so. - */ - public static boolean seteuid (int uid) - { - if (!RunAnywhere.isWindows() && isLoaded()) { - return nativeSeteuid(uid); - } - return false; - } - - /** - * Sets the process' effective gid to the specified value. - * - * @return true if the egid was changed, false if we were unable to do so. - */ - public static boolean setegid (int gid) - { - if (!RunAnywhere.isWindows() && isLoaded()) { - return nativeSetegid(gid); - } - return false; - } - - /** - * Returns true if the native library was successfully loaded, and if this is the first time - * it's been checked and it failed, reports the failure. - */ - protected static boolean isLoaded () - { - if (_loadError != null) { - log.warning("Unable to load 'unsafe' library", "e", _loadError); - _loadError = null; - } - return _loaded; - } - - /** - * Reenable garbage collection after a call to {@link #disableGC}. - */ - protected static native void enableGC (); - - /** - * Disables garbage collection. - */ - protected static native void disableGC (); - - /** - * Sleeps the current thread for the specified number of milliseconds. - */ - protected static native void nativeSleep (int millis); - - /** - * Calls through to the native OS system call to change our uid. - */ - protected static native boolean nativeSetuid (int uid); - - /** - * Calls through to the native OS system call to change our gid. - */ - protected static native boolean nativeSetgid (int gid); - - /** - * Calls through to the native OS system call to change our euid. - */ - protected static native boolean nativeSeteuid (int uid); - - /** - * Calls through to the native OS system call to change our egid. - */ - protected static native boolean nativeSetegid (int gid); - - /** - * Called to initialize our library. - */ - protected static native boolean init (); - - /** The current state of GC enablement. */ - protected static boolean _gcEnabled = true; - - /** Whether or not we were able to load our library. */ - protected static boolean _loaded; - - /** Whether or not we were able to initialize our library (i.e. get access to jvmpi) */ - protected static boolean _initialized; - - /** - * The error that occurred when loading the native library, or null if none occurred or it was - * already reported. - */ - protected static Throwable _loadError; - - static { - try { - System.loadLibrary("unsafe"); - _loaded = true; - } catch (Throwable t) { - _loadError = t; - } - } -} diff --git a/core/src/main/java/com/threerings/util/unsafe/Windows/Makefile b/core/src/main/java/com/threerings/util/unsafe/Windows/Makefile deleted file mode 100644 index 8843524b..00000000 --- a/core/src/main/java/com/threerings/util/unsafe/Windows/Makefile +++ /dev/null @@ -1,49 +0,0 @@ -# -# $Id: Makefile 3331 2005-02-03 01:25:21Z mdb $ - -NAME=unsafe - -# -# Executable definitions - -CC=i586-mingw32msvc-gcc -RM=rm -CP=cp -MKDIR=mkdir -DLLWRAP=i586-mingw32msvc-dllwrap -# -# Directory definitions - -ROOT=../../../../../../../.. -INSTALL_PATH=${ROOT}/dist/lib/i686-Windows - -# -# Source files - -SRCS = com_threerings_util_unsafe_Unsafe.c -OBJS = ${SRCS:.c=.o} - -# -# Parameter and file definitions - -INCLUDES= -CFLAGS=-I.. -I${JAVA_HOME}/include -I${JAVA_HOME}/include/linux - -LDFLAGS=-L/usr/X11R6/lib -LIBS= -TARGET=${NAME}.dll -INSTALL_TARGET=${INSTALL_PATH}/${TARGET} - -# -# Target definitions - -all: ${INSTALL_TARGET} - -${INSTALL_TARGET}: ${OBJS} - @${MKDIR} -p ${INSTALL_PATH} - ${DLLWRAP} --output-def ${NAME}.def --add-stdcall-alias \ - -o ${INSTALL_TARGET} -s ${OBJS} - -clean: - -${RM} ${OBJS} - -${RM} ${INSTALL_TARGET} diff --git a/core/src/main/java/com/threerings/util/unsafe/Windows/com_threerings_util_unsafe_Unsafe.c b/core/src/main/java/com/threerings/util/unsafe/Windows/com_threerings_util_unsafe_Unsafe.c deleted file mode 100644 index 82622f94..00000000 --- a/core/src/main/java/com/threerings/util/unsafe/Windows/com_threerings_util_unsafe_Unsafe.c +++ /dev/null @@ -1,80 +0,0 @@ -/* - * $Id: com_threerings_util_unsafe_Unsafe.c 3331 2005-02-03 01:25:21Z mdb $ - */ - -#include -#include -#include - -#include "com_threerings_util_unsafe_Unsafe.h" - -/* global jvmpi interface pointer */ -static JVMPI_Interface* jvmpi; - -JNIEXPORT void JNICALL -Java_com_threerings_util_unsafe_Unsafe_enableGC (JNIEnv* env, jclass clazz) -{ - fprintf(stderr, "Reenabling GC.\n"); - jvmpi->EnableGC(); -} - -JNIEXPORT void JNICALL -Java_com_threerings_util_unsafe_Unsafe_disableGC (JNIEnv* env, jclass clazz) -{ - fprintf(stderr, "Disabling GC.\n"); - jvmpi->DisableGC(); -} - -JNIEXPORT void JNICALL -Java_com_threerings_util_unsafe_Unsafe_nativeSleep ( - JNIEnv* env, jclass clazz, jint millis) -{ - /* not supported */ -} - -JNIEXPORT jboolean JNICALL Java_com_threerings_util_unsafe_Unsafe_nativeSetuid - (JNIEnv *, jclass, jint) -{ - /* not supported */ - return JNI_FALSE; -} - -JNIEXPORT jboolean JNICALL Java_com_threerings_util_unsafe_Unsafe_nativeSetgid - (JNIEnv *, jclass, jint) -{ - /* not supported */ - return JNI_FALSE; -} - -JNIEXPORT jboolean JNICALL Java_com_threerings_util_unsafe_Unsafe_nativeSeteuid ( - JNIEnv* env, jclass clzz, jint uid) -{ - /* not supported */ - return JNI_FALSE; -} - -JNIEXPORT jboolean JNICALL Java_com_threerings_util_unsafe_Unsafe_nativeSetegid ( - JNIEnv* env, jclass clazz, jint gid) -{ - /* not supported */ - return JNI_FALSE; -} - -JNIEXPORT jboolean JNICALL -Java_com_threerings_util_unsafe_Unsafe_init (JNIEnv* env, jclass clazz) -{ - JavaVM* jvm; - - if ((*env)->GetJavaVM(env, &jvm) > 0) { - fprintf(stderr, "Failed to get JavaVM from env.\n"); - return JNI_FALSE; - } - - /* get jvmpi interface pointer */ - if (((*jvm)->GetEnv(jvm, (void**)&jvmpi, JVMPI_VERSION_1)) < 0) { - fprintf(stderr, "Failed to get JVMPI from JavaVM.\n"); - return JNI_FALSE; - } - - return JNI_TRUE; -} diff --git a/core/src/main/java/com/threerings/util/unsafe/com_threerings_util_unsafe_Unsafe.h b/core/src/main/java/com/threerings/util/unsafe/com_threerings_util_unsafe_Unsafe.h deleted file mode 100644 index bae9f5aa..00000000 --- a/core/src/main/java/com/threerings/util/unsafe/com_threerings_util_unsafe_Unsafe.h +++ /dev/null @@ -1,77 +0,0 @@ -/* DO NOT EDIT THIS FILE - it is machine generated */ -#include -/* Header for class com_threerings_util_unsafe_Unsafe */ - -#ifndef _Included_com_threerings_util_unsafe_Unsafe -#define _Included_com_threerings_util_unsafe_Unsafe -#ifdef __cplusplus -extern "C" { -#endif -/* - * Class: com_threerings_util_unsafe_Unsafe - * Method: enableGC - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_com_threerings_util_unsafe_Unsafe_enableGC - (JNIEnv *, jclass); - -/* - * Class: com_threerings_util_unsafe_Unsafe - * Method: disableGC - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_com_threerings_util_unsafe_Unsafe_disableGC - (JNIEnv *, jclass); - -/* - * Class: com_threerings_util_unsafe_Unsafe - * Method: nativeSleep - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_com_threerings_util_unsafe_Unsafe_nativeSleep - (JNIEnv *, jclass, jint); - -/* - * Class: com_threerings_util_unsafe_Unsafe - * Method: nativeSetuid - * Signature: (I)Z - */ -JNIEXPORT jboolean JNICALL Java_com_threerings_util_unsafe_Unsafe_nativeSetuid - (JNIEnv *, jclass, jint); - -/* - * Class: com_threerings_util_unsafe_Unsafe - * Method: nativeSetgid - * Signature: (I)Z - */ -JNIEXPORT jboolean JNICALL Java_com_threerings_util_unsafe_Unsafe_nativeSetgid - (JNIEnv *, jclass, jint); - -/* - * Class: com_threerings_util_unsafe_Unsafe - * Method: nativeSeteuid - * Signature: (I)Z - */ -JNIEXPORT jboolean JNICALL Java_com_threerings_util_unsafe_Unsafe_nativeSeteuid - (JNIEnv *, jclass, jint); - -/* - * Class: com_threerings_util_unsafe_Unsafe - * Method: nativeSetegid - * Signature: (I)Z - */ -JNIEXPORT jboolean JNICALL Java_com_threerings_util_unsafe_Unsafe_nativeSetegid - (JNIEnv *, jclass, jint); - -/* - * Class: com_threerings_util_unsafe_Unsafe - * Method: init - * Signature: ()Z - */ -JNIEXPORT jboolean JNICALL Java_com_threerings_util_unsafe_Unsafe_init - (JNIEnv *, jclass); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/core/src/test/java/com/threerings/util/UIDTestApp.java b/core/src/test/java/com/threerings/util/UIDTestApp.java deleted file mode 100644 index 55c43fdb..00000000 --- a/core/src/test/java/com/threerings/util/UIDTestApp.java +++ /dev/null @@ -1,46 +0,0 @@ -// -// Nenya library - tools for developing networked games -// Copyright (C) 2002-2012 Three Rings Design, Inc., All Rights Reserved -// https://github.com/threerings/nenya -// -// This library is free software; you can redistribute it and/or modify it -// under the terms of the GNU Lesser General Public License as published -// by the Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -package com.threerings.util; - -import com.threerings.util.unsafe.Unsafe; - -/** - * Does something extraordinary. - */ -public class UIDTestApp -{ - public static void main (String[] args) - { - if (Unsafe.setuid(1000)) { - System.err.println("Yay! My uid is changed."); - } else { - System.err.println("Boo hoo! I couldn't change my uid."); - } - if (Unsafe.setgid(60)) { - System.err.println("Yay! My gid is changed."); - } else { - System.err.println("Boo hoo! I couldn't change my gid."); - } - try { - Thread.sleep(60*1000L); - } catch (Exception e) { - } - } -}