this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge remote-tracking branch 'origin/master' into using-machos-experiment

+266 -157
+4
CMakeLists.txt
··· 78 78 install(CODE "execute_process(COMMAND bash ${DARLING_TOP_DIRECTORY}/src/setup-ld-so.sh WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/libexec/darling)") 79 79 InstallSymlink(/Volumes/SystemRoot/lib ${CMAKE_INSTALL_PREFIX}/libexec/darling/lib) 80 80 InstallSymlink(/Volumes/SystemRoot/lib64 ${CMAKE_INSTALL_PREFIX}/libexec/darling/lib64) 81 + 82 + # Our udev rules, so /dev/mach has 0666 permissions 83 + install(DIRECTORY etc/udev DESTINATION /etc) 84 + 81 85 endif (NOT DARLING_NO_EXECUTABLES)
+6
README.md
··· 126 126 chmod a+rw /dev/mach 127 127 ```` 128 128 129 + ### Prefixes 130 + 131 + Darling has support for DPREFIXes, which are very similar to WINEPREFIXes. They are virtual “chroot” environments with an macOS-like filesystem structure, where you can install software safely. The default DPREFIX location is `~/.darling`, but this can be changed by exporting an identically named environment variable. A prefix is automatically created and initialized on first use. 132 + 133 + Please note that we use `overlayfs` for creating prefixes, and so we cannot support putting prefix on a filesystem like NFS or eCryptfs. In particular, the default prefix location won't work if you have an encrypted home directory. 134 + 129 135 ### Hello world 130 136 131 137 Let's start with a Hello world:
+2
etc/udev/rules.d/00-darling-mach.rules
··· 1 + # Make /dev/mach accessible by all users 2 + KERNEL=="mach", NAME="mach", MODE="0666"
+5 -5
kernel-include/i386/_types.h
··· 2 2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved. 3 3 * 4 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 - * 5 + * 6 6 * This file contains Original Code and/or Modifications of Original Code 7 7 * as defined in and that are subject to the Apple Public Source License 8 8 * Version 2.0 (the 'License'). You may not use this file except in ··· 11 11 * unlawful or unlicensed copies of an Apple operating system, or to 12 12 * circumvent, violate, or enable the circumvention or violation of, any 13 13 * terms of an Apple operating system software license agreement. 14 - * 14 + * 15 15 * Please obtain a copy of the License at 16 16 * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 - * 17 + * 18 18 * The Original Code and all software distributed under the License are 19 19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, ··· 22 22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 23 * Please see the License for the specific language governing rights and 24 24 * limitations under the License. 25 - * 25 + * 26 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 27 */ 28 28 #ifndef _BSD_I386__TYPES_H_ ··· 106 106 107 107 typedef __darwin_wchar_t __darwin_rune_t; /* rune_t */ 108 108 109 - #if defined(__GNUC__) && defined(__WINT_TYPE__) 109 + #if defined(__GNUC__) && defined(__WINT_TYPE__) && !defined(DARLING) 110 110 typedef __WINT_TYPE__ __darwin_wint_t; /* wint_t */ 111 111 #else 112 112 typedef __darwin_ct_rune_t __darwin_wint_t; /* wint_t */
+5 -5
platform-include/i386/_types.h
··· 2 2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved. 3 3 * 4 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 - * 5 + * 6 6 * This file contains Original Code and/or Modifications of Original Code 7 7 * as defined in and that are subject to the Apple Public Source License 8 8 * Version 2.0 (the 'License'). You may not use this file except in ··· 11 11 * unlawful or unlicensed copies of an Apple operating system, or to 12 12 * circumvent, violate, or enable the circumvention or violation of, any 13 13 * terms of an Apple operating system software license agreement. 14 - * 14 + * 15 15 * Please obtain a copy of the License at 16 16 * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 - * 17 + * 18 18 * The Original Code and all software distributed under the License are 19 19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, ··· 22 22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 23 * Please see the License for the specific language governing rights and 24 24 * limitations under the License. 25 - * 25 + * 26 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 27 */ 28 28 #ifndef _BSD_I386__TYPES_H_ ··· 108 108 109 109 typedef __darwin_wchar_t __darwin_rune_t; /* rune_t */ 110 110 111 - #if defined(__WINT_TYPE__) 111 + #if defined(__WINT_TYPE__) && !defined(DARLING) 112 112 typedef __WINT_TYPE__ __darwin_wint_t; /* wint_t */ 113 113 #else 114 114 typedef __darwin_ct_rune_t __darwin_wint_t; /* wint_t */
+13 -1
src/CMakeLists.txt
··· 11 11 12 12 add_definitions(-D__APPLE__ -D__DYNAMIC__) 13 13 14 + execute_process( 15 + COMMAND git rev-parse --abbrev-ref HEAD 16 + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 17 + OUTPUT_VARIABLE GIT_BRANCH 18 + OUTPUT_STRIP_TRAILING_WHITESPACE 19 + ) 20 + execute_process( 21 + COMMAND git log -1 --format=%h 22 + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 23 + OUTPUT_VARIABLE GIT_COMMIT_HASH 24 + OUTPUT_STRIP_TRAILING_WHITESPACE 25 + ) 26 + 14 27 configure_file(darling-config.h.in darling-config.h) 15 28 include_directories("${CMAKE_CURRENT_BINARY_DIR}") 16 29 include_directories("${CMAKE_CURRENT_SOURCE_DIR}") ··· 192 205 add_custom_target(lkm 193 206 COMMAND gmake 194 207 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/lkm") 195 -
+3
src/darling-config.h.in
··· 12 12 // Path where the system root gets "mounted" inside the prefix 13 13 #define SYSTEM_ROOT "/Volumes/SystemRoot" 14 14 15 + #define GIT_BRANCH "@GIT_BRANCH@" 16 + #define GIT_COMMIT_HASH "@GIT_COMMIT_HASH@" 17 + 15 18 #cmakedefine MULTILIB 16 19 #cmakedefine FRAMEWORK_COREAUDIO 17 20 #cmakedefine FRAMEWORK_APPKIT
+74 -6
src/dyld/darling.c
··· 34 34 #include <sys/utsname.h> 35 35 #include <sys/stat.h> 36 36 #include <sys/syscall.h> 37 + #include <getopt.h> 37 38 #include "darling.h" 38 39 #include "darling-config.h" 39 40 ··· 43 44 char *prefix; 44 45 uid_t g_originalUid, g_originalGid; 45 46 46 - int main(int argc, const char** argv) 47 + int main(int argc, char const ** argv) 47 48 { 48 49 pid_t pidInit, pidChild; 49 50 int wstatus; ··· 76 77 if (!checkPrefixDir()) 77 78 setupPrefix(); 78 79 checkPrefixOwner(); 80 + 81 + int c; 82 + while (1) 83 + { 84 + static struct option long_options[] = 85 + { 86 + {"help", no_argument, 0, 0}, 87 + {"version", no_argument, 0, 0}, 88 + {0, 0, 0, 0} 89 + }; 90 + int option_index = 0; 91 + 92 + c = getopt_long(argc, (char *const *)argv, "", long_options, &option_index); 93 + 94 + if (c == -1) 95 + { 96 + break; 97 + } 98 + 99 + switch (c) 100 + { 101 + case 0: 102 + if (strcmp(long_options[option_index].name, "help") == 0) 103 + { 104 + showHelp(argv[0]); 105 + exit(EXIT_SUCCESS); 106 + } 107 + else if (strcmp(long_options[option_index].name, "version") == 0) 108 + { 109 + showVersion(argv[0]); 110 + exit(EXIT_SUCCESS); 111 + } 112 + break; 113 + case '?': 114 + break; 115 + default: 116 + abort(); 117 + } 118 + } 79 119 80 120 pidInit = getInitProcess(); 81 121 ··· 264 304 char buffer1[4096]; 265 305 char buffer2[4096]; 266 306 307 + 308 + unsetenv("LESSOPEN"); 309 + unsetenv("LESSCLOSE"); 310 + unsetenv("LESSECHO"); 311 + 267 312 setenv("PATH", 268 313 "/usr/bin:" 269 314 "/bin:" ··· 294 339 void showHelp(const char* argv0) 295 340 { 296 341 fprintf(stderr, "This is Darling, translation layer for macOS software.\n\n"); 297 - fprintf(stderr, "Copyright (C) 2012-2016 Lubos Dolezel\n\n"); 342 + fprintf(stderr, "Copyright (C) 2012-2017 Lubos Dolezel\n\n"); 298 343 299 344 fprintf(stderr, "Usage:\n"); 300 345 fprintf(stderr, "\t%s program-path [arguments...]\n", argv0); ··· 302 347 fprintf(stderr, "\n"); 303 348 fprintf(stderr, "Environment variables:\n" 304 349 "DPREFIX - specifies the location of Darling prefix, defaults to ~/.darling\n"); 350 + } 351 + 352 + void showVersion(const char* argv0) { 353 + fprintf(stderr, "%s " GIT_BRANCH " @ " GIT_COMMIT_HASH "\n", argv0); 354 + fprintf(stderr, "Copyright (C) 2012-2017 Lubos Dolezel\n"); 305 355 } 306 356 307 357 void missingSetuidRoot(void) ··· 793 843 int loadKernelModule() 794 844 { 795 845 int fd; 796 - char path[128]; 846 + // We need to check two paths due to DKMS 847 + // Ubuntu overrides our dkms.conf and forces the modules into the updates folder 848 + char miscpath[128], updatespath[128]; 849 + char* path; 797 850 struct utsname name; 798 851 799 852 if (isModuleLoaded()) 800 853 return 0; 801 854 802 855 uname(&name); 803 - snprintf(path, sizeof(path), "/lib/modules/%s/kernel/misc/darling-mach.ko", name.release); 804 - if (access(path, F_OK)) 856 + snprintf(miscpath, sizeof(miscpath), "/lib/modules/%s/kernel/misc/darling-mach.ko", name.release); 857 + snprintf(updatespath, sizeof(updatespath), "/lib/modules/%s/updates/dkms/darling-mach.ko", name.release); 858 + 859 + // Since miscpath is the normal location we check for it last 860 + if(access(updatespath, F_OK) == 0) 861 + { 862 + path = updatespath; 863 + } 864 + else if (access(miscpath, F_OK)) 805 865 { 806 866 fprintf(stderr, "Cannot find kernel module at %s: %s\n", path, strerror(errno)); 807 867 return 1; 868 + } 869 + else 870 + { 871 + path = miscpath; 808 872 } 809 873 810 - fd = open(path, O_RDONLY|O_CLOEXEC); 874 + fd = open(path, O_RDONLY); 811 875 if (fd < 0) 812 876 { 813 877 fprintf(stderr, "Cannot open kernel module\n"); ··· 819 883 fprintf(stderr, "Cannot load kernel module: %s\n", strerror(errno)); 820 884 return 1; 821 885 } 886 + 887 + printf("Loaded kernel module: %s\n", path); 888 + 889 + close(fd); 822 890 823 891 return 0; 824 892 }
+1
src/dyld/darling.h
··· 23 23 #define _DARLING_H_ 24 24 25 25 void showHelp(const char* argv0); 26 + void showVersion(const char* argv0); 26 27 27 28 // Reports that this executable is not setuid root 28 29 void missingSetuidRoot(void);
+12 -1
src/kernel/emulation/linux/signal/sigaction.c
··· 26 26 27 27 linux_signum = signum_bsd_to_linux(signum); 28 28 if (linux_signum == 0) 29 - return -EINVAL; 29 + { 30 + // Some software (e.g. Node.js) tries to set up handlers for all signals by 31 + // walking through all signal numbers incrementally. They end up hitting 32 + // signals that don't exist on Linux and then bail out if they receive 33 + // an error. 34 + // Fake that everyting is all right. 35 + 36 + if (osa != NULL) 37 + memset(osa, 0, sizeof(*osa)); 38 + 39 + return 0; 40 + } 30 41 31 42 if (nsa != NULL) 32 43 {
+1 -1
src/kernel/emulation/linux/stat/fstatfs.c
··· 36 36 int max_len = 0; 37 37 38 38 #ifdef __NR_fstatfs64 39 - ret = LINUX_SYSCALL2(__NR_fstatfs64, fd, &lbuf); 39 + ret = LINUX_SYSCALL3(__NR_fstatfs64, fd, sizeof(lbuf), &lbuf); 40 40 #else 41 41 ret = LINUX_SYSCALL2(__NR_fstatfs, fd, &lbuf); 42 42 #endif
+2
src/libc/include/time.h
··· 63 63 #ifndef _TIME_H_ 64 64 #define _TIME_H_ 65 65 66 + #include <Availability.h> 67 + 66 68 #include <_types.h> 67 69 #include <Availability.h> 68 70 #include <sys/_types/_clock_t.h>
+138 -138
src/lkm/traps.c
··· 6 6 * modify it under the terms of the GNU General Public License 7 7 * as published by the Free Software Foundation; either version 2 8 8 * of the License, or (at your option) any later version. 9 - * 9 + * 10 10 * This program is distributed in the hope that it will be useful, 11 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 * GNU General Public License for more details. 14 - * 14 + * 15 15 * You should have received a copy of the GNU General Public License 16 16 * along with this program; if not, write to the Free Software 17 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ··· 29 29 #include <linux/dcache.h> 30 30 #include <linux/kernel.h> 31 31 #include <linux/mm.h> 32 + #include <linux/syscalls.h> 32 33 #include "darling_task.h" 33 34 #include "traps.h" 34 35 #include "ipc_space.h" ··· 109 110 { 110 111 // mach_port_name_t name; 111 112 int err; 112 - 113 + 113 114 err = misc_register(&mach_dev); 114 115 if (err < 0) 115 116 goto fail; 116 - 117 + 117 118 darling_task_init(); 118 119 mach_timer_init(); 119 120 setup_proc_entry(); ··· 149 150 darling_mach_port_t* task_port; 150 151 darling_mach_port_t* thread_port; 151 152 mach_task_t* task; 152 - 153 + 153 154 if (ipc_port_new(&task_port) != KERN_SUCCESS) 154 155 return -ENOMEM; 155 - 156 + 156 157 if (ipc_port_new(&thread_port) != KERN_SUCCESS) 157 158 { 158 159 ipc_port_put(task_port); 159 160 return -ENOMEM; 160 161 } 161 - 162 + 162 163 task = ipc_port_make_task(task_port, current->pid); 163 164 file->private_data = task_port; 164 - 165 + 165 166 ipc_port_make_thread(thread_port); 166 - 167 + 167 168 darling_task_set_current(ipc_port_get_task(task_port)); 168 169 darling_task_register_thread(task, thread_port); 169 170 ··· 173 174 int mach_dev_release(struct inode* ino, struct file* file) 174 175 { 175 176 darling_mach_port_t* task_port; 176 - 177 + 177 178 task_port = (darling_mach_port_t*) file->private_data; 178 179 ipc_port_put(task_port); 179 - 180 + 180 181 darling_task_set_current(NULL); 181 - 182 + 182 183 return 0; 183 184 } 184 185 185 186 long mach_dev_ioctl(struct file* file, unsigned int ioctl_num, unsigned long ioctl_paramv) 186 187 { 187 188 const unsigned int num_traps = sizeof(mach_traps) / sizeof(mach_traps[0]); 188 - 189 + 189 190 darling_mach_port_t* task_port = (darling_mach_port_t*) file->private_data; 190 191 mach_task_t* task; 191 - 192 + 192 193 debug_msg("function 0x%x called...\n", ioctl_num); 193 - 194 + 194 195 ioctl_num -= DARLING_MACH_API_BASE; 195 - 196 + 196 197 if (ioctl_num >= num_traps) 197 198 return -ENOSYS; 198 199 199 200 if (!mach_traps[ioctl_num]) 200 201 return -ENOSYS; 201 - 202 + 202 203 task = ipc_port_get_task(task_port); 203 - 204 + 204 205 return mach_traps[ioctl_num](task, ioctl_paramv); 205 206 } 206 207 ··· 214 215 mach_msg_return_t ret; 215 216 mach_port_name_t name; 216 217 darling_mach_port_t* port; 217 - 218 + 218 219 ret = ipc_port_new(&port); 219 220 if (ret != KERN_SUCCESS) 220 221 return 0; 221 - 222 + 222 223 ret = ipc_space_make_receive(&task->namespace, port, &name); 223 224 if (ret != KERN_SUCCESS) 224 225 { 225 226 ipc_port_put(port); 226 227 return 0; 227 228 } 228 - 229 + 229 230 return name; 230 231 } 231 232 ··· 233 234 { 234 235 struct mach_port_right* right; 235 236 mach_task_t* task; 236 - 237 + 237 238 right = ipc_space_lookup(&task_self->namespace, name); 238 239 if (right == NULL) 239 240 return NULL; 240 - 241 + 241 242 // NOTE: If XNU were to support accessing other tasks, 242 243 // we would need to safely add a reference to the task at this point. 243 244 task = ipc_port_get_task(right->port); 244 - 245 + 245 246 ipc_port_unlock(right->port); 246 - 247 + 247 248 return task; 248 249 } 249 250 ··· 253 254 struct mach_port_mod_refs_args args; 254 255 struct mach_port_right* right = NULL; 255 256 kern_return_t ret; 256 - 257 + 257 258 if (copy_from_user(&args, in_args, sizeof(args))) 258 259 return KERN_INVALID_ADDRESS; 259 - 260 + 260 261 ipc_space_lock(&task_self->namespace); 261 - 262 + 262 263 // We behave like XNU here 263 264 if (port_name_to_task(task_self, args.task_right_name) != task_self) 264 265 { ··· 266 267 ret = MACH_SEND_INVALID_DEST; 267 268 goto err; 268 269 } 269 - 270 + 270 271 right = ipc_space_lookup(&task_self->namespace, args.port_right_name); 271 272 if (right == NULL) 272 273 { ··· 274 275 ret = KERN_INVALID_NAME; 275 276 goto err; 276 277 } 277 - 278 + 278 279 ret = ipc_right_mod_refs(right, args.right_type, args.delta); 279 - 280 + 280 281 if (ipc_right_put_if_noref(right, &task_self->namespace, args.port_right_name)) 281 282 right = NULL; 282 - 283 + 283 284 err: 284 285 if (right != NULL) 285 286 ipc_port_unlock(right->port); 286 - 287 + 287 288 ipc_space_unlock(&task_self->namespace); 288 - 289 + 289 290 return ret; 290 291 } 291 292 ··· 293 294 { 294 295 mach_port_name_t name; 295 296 kern_return_t ret; 296 - 297 + 297 298 ipc_port_lock(task->task_self); 298 - 299 + 299 300 ret = ipc_space_make_send(&task->namespace, task->task_self, false, &name); 300 - 301 + 301 302 ipc_port_unlock(task->task_self); 302 - 303 + 303 304 if (ret == KERN_SUCCESS) 304 305 return name; 305 306 else ··· 311 312 mach_port_name_t name; 312 313 kern_return_t ret; 313 314 darling_mach_port_t* thread_port; 314 - 315 + 315 316 ipc_port_lock(task->task_self); 316 - 317 + 317 318 thread_port = darling_task_lookup_thread(task, current->pid); 318 319 if (thread_port == NULL) 319 320 { ··· 322 323 ipc_port_unlock(task->task_self); 323 324 return KERN_RESOURCE_SHORTAGE; 324 325 } 325 - 326 + 326 327 ipc_port_make_thread(thread_port); 327 328 darling_task_register_thread(task, thread_port); 328 329 } 329 - 330 + 330 331 ipc_port_unlock(task->task_self); 331 - 332 + 332 333 ret = ipc_space_make_send(&task->namespace, thread_port, false, &name); 333 - 334 + 334 335 if (ret == KERN_SUCCESS) 335 336 return name; 336 337 else ··· 341 342 { 342 343 mach_port_name_t name; 343 344 kern_return_t ret; 344 - 345 + 345 346 ipc_port_lock(host_port); 346 - 347 + 347 348 ret = ipc_space_make_send(&task->namespace, host_port, false, &name); 348 - 349 + 349 350 ipc_port_unlock(host_port); 350 - 351 + 351 352 if (ret == KERN_SUCCESS) 352 353 return name; 353 354 else ··· 360 361 struct mach_port_allocate_args args; 361 362 darling_mach_port_t* port; 362 363 kern_return_t ret = KERN_SUCCESS; 363 - 364 + 364 365 if (copy_from_user(&args, in_out_args, sizeof(args))) 365 366 return KERN_INVALID_ADDRESS; 366 - 367 + 367 368 ipc_space_lock(&task->namespace); 368 - 369 + 369 370 if (port_name_to_task(task, args.task_right_name) != task) 370 371 { 371 372 debug_msg("_kernelrpc_mach_port_allocate_trap() -> MACH_SEND_INVALID_DEST\n"); 372 - 373 + 373 374 ipc_space_unlock(&task->namespace); 374 375 ret = MACH_SEND_INVALID_DEST; 375 376 goto err; 376 377 } 377 - 378 + 378 379 ipc_space_unlock(&task->namespace); 379 - 380 + 380 381 switch (args.right_type) 381 382 { 382 383 case MACH_PORT_RIGHT_RECEIVE: ··· 384 385 ret = ipc_port_new(&port); 385 386 if (ret != KERN_SUCCESS) 386 387 return ret; 387 - 388 + 388 389 break; 389 390 } 390 391 case MACH_PORT_RIGHT_DEAD_NAME: ··· 397 398 ret = ipc_port_set_new(&port); 398 399 if (ret != KERN_SUCCESS) 399 400 return ret; 400 - 401 + 401 402 break; 402 403 } 403 404 default: ··· 405 406 return KERN_INVALID_VALUE; 406 407 } 407 408 } 408 - 409 + 409 410 ret = ipc_space_make_receive(&task->namespace, port, 410 411 &args.out_right_name); 411 412 if (ret != KERN_SUCCESS) ··· 413 414 ipc_port_put(port); 414 415 goto err; 415 416 } 416 - 417 + 417 418 if (copy_to_user(in_out_args, &args, sizeof(args))) 418 419 { 419 420 ipc_port_put(port); 420 421 ret = KERN_PROTECTION_FAILURE; 421 422 goto err; 422 423 } 423 - 424 + 424 425 err: 425 426 return ret; 426 427 } ··· 596 597 struct mach_port_deallocate_args args; 597 598 struct mach_port_right* right = NULL; 598 599 kern_return_t ret = KERN_SUCCESS; 599 - 600 + 600 601 if (copy_from_user(&args, in_args, sizeof(args))) 601 602 return KERN_INVALID_ADDRESS; 602 - 603 + 603 604 ipc_space_lock(&task->namespace); 604 - 605 + 605 606 if (port_name_to_task(task, args.task_right_name) != task) 606 607 { 607 608 debug_msg("_kernelrpc_mach_port_deallocate_trap() -> MACH_SEND_INVALID_DEST\n"); 608 - 609 + 609 610 ret = MACH_SEND_INVALID_DEST; 610 611 goto err; 611 612 } 612 - 613 + 613 614 right = ipc_space_lookup(&task->namespace, args.port_right_name); 614 615 if (right == NULL || right->type != MACH_PORT_RIGHT_RECEIVE) 615 616 { 616 617 debug_msg("_kernelrpc_mach_port_deallocate_trap() -> KERN_INVALID_RIGHT\n"); 617 - 618 + 618 619 ret = KERN_INVALID_RIGHT; 619 620 goto err; 620 621 } 621 - 622 + 622 623 if (right->port != NULL) 623 624 { 624 625 ipc_right_mod_refs(right, right->type, -1); 625 - 626 + 626 627 if (ipc_right_put_if_noref(right, &task->namespace, args.port_right_name)) 627 628 right = NULL; 628 629 } 629 - 630 + 630 631 err: 631 632 if (right != NULL) 632 633 ipc_port_unlock(right->port); ··· 639 640 struct mach_port_destroy_args* in_args) 640 641 { 641 642 struct mach_port_destroy_args args; 642 - 643 + 643 644 if (copy_from_user(&args, in_args, sizeof(args))) 644 645 return KERN_INVALID_ADDRESS; 645 - 646 + 646 647 return _kernelrpc_mach_port_destroy(task, args.task_right_name, 647 648 args.port_right_name); 648 649 } ··· 651 652 mach_port_name_t task_name, mach_port_name_t right_name) 652 653 { 653 654 kern_return_t ret = KERN_SUCCESS; 654 - 655 + 655 656 ipc_space_lock(&task->namespace); 656 - 657 + 657 658 if (port_name_to_task(task, task_name) != task) 658 659 { 659 660 debug_msg("_kernelrpc_mach_port_destroy_trap() -> MACH_SEND_INVALID_DEST\n"); 660 - 661 + 661 662 ret = MACH_SEND_INVALID_DEST; 662 663 goto err; 663 664 } 664 - 665 + 665 666 ret = ipc_space_right_put(&task->namespace, right_name); 666 - 667 + 667 668 err: 668 669 669 670 ipc_space_unlock(&task->namespace); ··· 675 676 { 676 677 struct mach_msg_overwrite_args args; 677 678 kern_return_t ret = MACH_MSG_SUCCESS; 678 - 679 + 679 680 debug_msg("mach_msg_overwrite_trap()"); 680 - 681 + 681 682 if (copy_from_user(&args, in_args, sizeof(args))) 682 683 { 683 684 debug_msg("!!! Cannot copy %lu bytes from %p\n", ··· 691 692 if (args.option & MACH_SEND_MSG) 692 693 { 693 694 mach_msg_header_t* msg; 694 - 695 + 695 696 if (args.send_size > 10*4096) 696 697 { 697 698 debug_msg("\t-> MACH_SEND_NO_BUFFER\n"); ··· 702 703 debug_msg("\t-> MACH_SEND_MSG_TOO_SMALL\n"); 703 704 return MACH_SEND_MSG_TOO_SMALL; 704 705 } 705 - 706 + 706 707 msg = (mach_msg_header_t*) kmalloc(args.send_size, GFP_KERNEL); 707 708 if (msg == NULL) 708 709 return MACH_SEND_NO_BUFFER; 709 - 710 + 710 711 if (copy_from_user(msg, args.msg, args.send_size)) 711 712 { 712 713 debug_msg("!!! Cannot copy %d bytes from %p\n", ··· 714 715 kfree(msg); 715 716 return KERN_INVALID_ADDRESS; 716 717 } 717 - 718 + 718 719 msg->msgh_size = args.send_size; 719 720 msg->msgh_bits &= MACH_MSGH_BITS_USER; 720 - 721 + 721 722 ret = ipc_msg_send(&task->namespace, msg, 722 723 (args.option & MACH_SEND_TIMEOUT) ? args.timeout : MACH_MSG_TIMEOUT_NONE, 723 724 args.option); 724 - 725 + 725 726 if (ret != MACH_MSG_SUCCESS) 726 727 return ret; 727 728 } 728 - 729 + 729 730 if (args.option & MACH_RCV_MSG) 730 731 { 731 732 ret = ipc_msg_recv(task, args.rcv_name, args.rcv_msg, args.recv_size, ··· 746 747 { 747 748 struct semaphore_signal_args args; 748 749 darling_mach_port_right_t* right; 749 - 750 + 750 751 if (copy_from_user(&args, in_args, sizeof(args))) 751 752 return KERN_INVALID_ADDRESS; 752 - 753 + 753 754 ipc_space_lock(&task->namespace); 754 - 755 + 755 756 right = ipc_space_lookup(&task->namespace, args.signal); 756 - 757 + 757 758 ipc_space_unlock(&task->namespace); 758 - 759 + 759 760 if (right == NULL || !PORT_IS_VALID(right->port)) 760 761 { 761 762 if (right != NULL) 762 763 ipc_port_unlock(right->port); 763 764 return KERN_INVALID_ARGUMENT; 764 765 } 765 - 766 + 766 767 return mach_semaphore_signal(right->port); 767 768 } 768 769 ··· 771 772 { 772 773 struct semaphore_signal_all_args args; 773 774 darling_mach_port_right_t* right; 774 - 775 + 775 776 if (copy_from_user(&args, in_args, sizeof(args))) 776 777 return KERN_INVALID_ADDRESS; 777 - 778 + 778 779 ipc_space_lock(&task->namespace); 779 - 780 + 780 781 right = ipc_space_lookup(&task->namespace, args.signal); 781 - 782 + 782 783 ipc_space_unlock(&task->namespace); 783 - 784 + 784 785 if (right == NULL || !PORT_IS_VALID(right->port)) 785 786 { 786 787 if (right != NULL) 787 788 ipc_port_unlock(right->port); 788 789 return KERN_INVALID_ARGUMENT; 789 790 } 790 - 791 + 791 792 return mach_semaphore_signal_all(right->port); 792 793 } 793 794 ··· 796 797 { 797 798 struct semaphore_wait_args args; 798 799 darling_mach_port_right_t* right; 799 - 800 + 800 801 if (copy_from_user(&args, in_args, sizeof(args))) 801 802 return KERN_INVALID_ADDRESS; 802 - 803 + 803 804 ipc_space_lock(&task->namespace); 804 - 805 + 805 806 right = ipc_space_lookup(&task->namespace, args.signal); 806 - 807 + 807 808 ipc_space_unlock(&task->namespace); 808 - 809 + 809 810 if (right == NULL || !PORT_IS_VALID(right->port)) 810 811 { 811 812 if (right != NULL) 812 813 ipc_port_unlock(right->port); 813 814 return KERN_INVALID_ARGUMENT; 814 815 } 815 - 816 + 816 817 return mach_semaphore_wait(right->port); 817 818 } 818 819 ··· 822 823 struct semaphore_wait_signal_args args; 823 824 darling_mach_port_right_t *right_wait, *right_signal; 824 825 kern_return_t ret = KERN_SUCCESS; 825 - 826 + 826 827 if (copy_from_user(&args, in_args, sizeof(args))) 827 828 return KERN_INVALID_ADDRESS; 828 - 829 + 829 830 ipc_space_lock(&task->namespace); 830 - 831 + 831 832 right_signal = ipc_space_lookup(&task->namespace, args.signal); 832 833 if (right_signal == NULL) 833 834 { 834 835 ipc_space_unlock(&task->namespace); 835 836 return KERN_INVALID_ARGUMENT; 836 837 } 837 - 838 + 838 839 if (args.wait != 0) 839 840 right_wait = ipc_space_lookup(&task->namespace, args.wait); 840 841 else 841 842 right_wait = NULL; 842 - 843 + 843 844 ipc_space_unlock(&task->namespace); 844 - 845 + 845 846 if (right_wait != NULL) 846 847 ret = mach_semaphore_wait(right_wait->port); 847 - 848 + 848 849 mach_semaphore_signal(right_signal->port); 849 - 850 + 850 851 return ret; 851 852 } 852 853 ··· 855 856 { 856 857 struct semaphore_timedwait_args args; 857 858 darling_mach_port_right_t* right; 858 - 859 + 859 860 if (copy_from_user(&args, in_args, sizeof(args))) 860 861 return KERN_INVALID_ADDRESS; 861 - 862 + 862 863 ipc_space_lock(&task->namespace); 863 - 864 + 864 865 right = ipc_space_lookup(&task->namespace, args.wait); 865 - 866 + 866 867 ipc_space_unlock(&task->namespace); 867 - 868 + 868 869 if (right == NULL || !PORT_IS_VALID(right->port)) 869 870 { 870 871 if (right != NULL) 871 872 ipc_port_unlock(right->port); 872 873 return KERN_INVALID_ARGUMENT; 873 874 } 874 - 875 + 875 876 return mach_semaphore_timedwait(right->port, args.sec, args.nsec); 876 877 } 877 878 ··· 881 882 struct semaphore_timedwait_signal_args args; 882 883 darling_mach_port_right_t *right_wait, *right_signal; 883 884 kern_return_t ret = KERN_SUCCESS; 884 - 885 + 885 886 if (copy_from_user(&args, in_args, sizeof(args))) 886 887 return KERN_INVALID_ADDRESS; 887 - 888 + 888 889 // debug_msg("semaphore_timedwait_signal_trap: sec=%d, nsec=%d\n", args.sec, 889 890 // args.nsec); 890 - 891 + 891 892 ipc_space_lock(&task->namespace); 892 - 893 + 893 894 right_signal = ipc_space_lookup(&task->namespace, args.signal); 894 895 if (right_signal == NULL) 895 896 { 896 897 ipc_space_unlock(&task->namespace); 897 898 return KERN_INVALID_ARGUMENT; 898 899 } 899 - 900 + 900 901 if (args.wait != 0) 901 902 right_wait = ipc_space_lookup(&task->namespace, args.wait); 902 903 else 903 904 right_wait = NULL; 904 - 905 + 905 906 ipc_space_unlock(&task->namespace); 906 - 907 + 907 908 if (right_wait != NULL) 908 909 ret = mach_semaphore_timedwait(right_wait->port, args.sec, args.nsec); 909 - 910 + 910 911 mach_semaphore_signal(right_signal->port); 911 - 912 + 912 913 return ret; 913 914 } 914 915 ··· 919 920 char name[60]; 920 921 long retval = 0; 921 922 int handled; 922 - 923 + 923 924 if (copy_from_user(&args, in_args, sizeof(args))) 924 925 return -EFAULT; 925 - 926 + 926 927 f = fget(args.fd); 927 928 if (f == NULL) 928 929 return -EBADF; 929 - 930 + 930 931 if (f->f_op->unlocked_ioctl == NULL) 931 932 { 932 933 fput(f); 933 934 return -ENOTTY; 934 935 } 935 - 936 + 936 937 if (d_path(&f->f_path, name, sizeof(name)) == NULL) 937 938 { 938 939 fput(f); 939 940 return -EBADF; 940 941 } 941 - 942 + 942 943 // Perform ioctl translation based on name 943 944 if (strncmp(name, "socket:", 7) == 0) 944 945 handled = bsd_ioctl_xlate_socket(f, &args, &retval); ··· 948 949 handled = bsd_ioctl_xlate_pts(f, &args, &retval); 949 950 else 950 951 handled = bsd_ioctl_xlate_generic(f, &args, &retval); 951 - 952 + 952 953 if (!handled) 953 954 retval = f->f_op->unlocked_ioctl(f, args.request, args.arg); 954 - 955 + 955 956 fput(f); 956 - 957 + 957 958 return retval; 958 959 } 959 960 ··· 966 967 967 968 if (copy_from_user(&args, in_args, sizeof(args))) 968 969 return KERN_INVALID_ADDRESS; 969 - 970 + 970 971 debug_msg("bsdthread_terminate_trap(), pid=%d\n", 971 972 current->pid); 972 973 ipc_space_lock(&task->namespace); 973 - 974 + 974 975 sem = ipc_space_lookup(&task->namespace, args.signal); 975 - 976 + 976 977 ipc_space_unlock(&task->namespace); 977 - 978 + 978 979 // Signal threads calling pthread_join() 979 980 if (PORT_IS_VALID(sem->port)) 980 981 mach_semaphore_signal(sem->port); ··· 1129 1130 1130 1131 module_init(mach_init); 1131 1132 module_exit(mach_exit); 1132 -