···11#include "auto.h"
2233-int Darling::flagsDarwinToNative(MappedFlag* flags, size_t count, int darwin)
33+int Darling::flagsDarwinToNative(const MappedFlag* flags, size_t count, int darwin)
44{
55 int out = 0;
66 for (size_t i = 0; i < count; i++)
···1111 return out;
1212}
13131414-int Darling::flagsNativeToDarwin(MappedFlag* flags, size_t count, int native)
1414+int Darling::flagsNativeToDarwin(const MappedFlag* flags, size_t count, int native)
1515{
1616 int out = 0;
1717 for (size_t i = 0; i < count; i++)
+2-2
src/libSystem/common/auto.h
···4343 int darwin;
4444 int native;
4545 };
4646- int flagsDarwinToNative(MappedFlag* flags, size_t count, int darwin);
4747- int flagsNativeToDarwin(MappedFlag* flags, size_t count, int native);
4646+ int flagsDarwinToNative(const MappedFlag* flags, size_t count, int darwin);
4747+ int flagsNativeToDarwin(const MappedFlag* flags, size_t count, int native);
4848}
49495050#endif
+20-1
src/libSystem/kernel-bsd/wait.cpp
···22#include "wait.h"
33#include "libc/errno.h"
44#include "libc/darwin_errno_codes.h"
55+#include "libc/signals.h"
56#include "log.h"
67#include <sys/time.h>
78#include <sys/resource.h>
99+1010+int __darwin_kill(pid_t pid, int sig)
1111+{
1212+ int rv = kill(pid, Darling::signalDarwinToLinux(sig));
1313+ if (rv == -1)
1414+ errnoOut();
1515+ return rv;
1616+}
817918pid_t __darwin_wait(int *stat_loc)
1019{
···3140pid_t __darwin_waitpid(pid_t pid, int *stat_loc, int options)
3241{
3342 pid_t rv = waitpid(pid, stat_loc, options);
3434- return rv; // TODO
4343+ if (WIFSIGNALED(*stat_loc))
4444+ {
4545+ // rewrite the signal number
4646+ // 0x7f on Linux
4747+ int signum = (*stat_loc) & (0x7f);
4848+ signum = Darling::signalLinuxToDarwin(signum);
4949+ *stat_loc &= ~(0x7f);
5050+ *stat_loc |= signum;
5151+ }
5252+ return rv; // TODO: check if compatible
3553}
5454+
+1
src/libSystem/kernel-bsd/wait.h
···55extern "C"
66{
7788+int __darwin_kill(pid_t pid, int sig);
89pid_t __darwin_wait(int *stat_loc);
910pid_t __darwin_wait3(int *stat_loc, int options, struct rusage *rusage);
1011pid_t __darwin_wait4(pid_t pid, int *stat_loc, int options, struct rusage *rusage);
···11-#!/bin/sh
22-#
33-# Copyright 2011 Shinichiro Hamaji. All rights reserved.
44-#
55-# Redistribution and use in source and binary forms, with or without
66-# modification, are permitted provided that the following conditions
77-# are met:
88-#
99-# 1. Redistributions of source code must retain the above copyright
1010-# notice, this list of conditions and the following disclaimer.
1111-#
1212-# 2. Redistributions in binary form must reproduce the above
1313-# copyright notice, this list of conditions and the following
1414-# disclaimer in the documentation and/or other materials
1515-# provided with the distribution.
1616-#
1717-# THIS SOFTWARE IS PROVIDED BY Shinichiro Hamaji ``AS IS'' AND ANY
1818-# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1919-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2020-# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Shinichiro Hamaji OR
2121-# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2222-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2323-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
2424-# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
2525-# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2626-# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
2727-# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2828-# SUCH DAMAGE.
2929-3030-set -e
3131-3232-# Run small unit tests
3333-3434-for i in mach/*.bin; do
3535- echo "Running $i"
3636- ./ld-mac ./$i
3737-done
3838-3939-# Run regressions tests with real compilers
4040-4141-MAC_TOOL_DIR=/usr/i686-apple-darwin10
4242-MAC_BIN_DIR=$MAC_TOOL_DIR/usr/bin
4343-4444-apple() {
4545- gcc="$1"
4646- shift
4747- PATH=$MAC_BIN_DIR ./ld-mac $MAC_BIN_DIR/$gcc --sysroot=$MAC_TOOL_DIR "$@"
4848-}
4949-5050-# Run GCC with ld-mac
5151-5252-echo "Running gcc -c mach/hello.c"
5353-./ld-mac $MAC_BIN_DIR/gcc -c mach/hello.c
5454-echo "Running gcc mach/hello.c"
5555-./ld-mac $MAC_BIN_DIR/gcc mach/hello.c
5656-echo "Running gcc -g mach/hello.c"
5757-PATH=$MAC_BIN_DIR ./ld-mac $MAC_BIN_DIR/gcc -g mach/hello.c
5858-5959-# Run clang with ld-mac
6060-6161-echo "Running clang -c mach/hello.c"
6262-./ld-mac $MAC_BIN_DIR/clang -c mach/hello.c
6363-6464-# Check dylib
6565-6666-echo "Running dylib tests"
6767-6868-apple gcc -g -dynamiclib mach/dylib/lib.c -o mach/dylib/lib.dylib
6969-apple gcc -g mach/dylib/main.c mach/dylib/lib.dylib -o mach/dylib/main
7070-7171-echo "Running mach/dylib/main"
7272-./ld-mac mach/dylib/main
7373-7474-echo "Running dylib tests"
7575-7676-apple gcc -g -dynamiclib mach/dylib/lib.c -o mach/dylib/lib.dylib
7777-apple gcc -g mach/dylib/main.c mach/dylib/lib.dylib -o mach/dylib/main
7878-7979-echo "Running mach/dylib/main"
8080-./ld-mac mach/dylib/main
8181-8282-apple gcc -g mach/dylib/dlfcn.c -o mach/dylib/dlfcn
8383-8484-echo "Running mach/dylib/dlfcn"
8585-./ld-mac mach/dylib/dlfcn
8686-8787-# Check dylib with weak symbols
8888-8989-echo "Running dylib tests with a weak symbol"
9090-9191-apple g++ -g -fPIC -dynamiclib mach/dylib/weak_lib.cc -o mach/dylib/weak_lib.dylib
9292-apple g++ -g -fPIC mach/dylib/weak_main.cc -o mach/dylib/weak_main mach/dylib/weak_lib.dylib
9393-apple g++ -g -fPIC mach/dylib/weak_main.cc -o mach/dylib/weak_main-dl -DDL
9494-9595-echo "Running mach/dylib/weak_main"
9696-./ld-mac mach/dylib/weak_main
9797-9898-echo "Running mach/dylib/weak_main-dl"
9999-./ld-mac mach/dylib/weak_main-dl
100100-101101-# Compile and run unit tests with clang
102102-103103-# Need this file from Xcode 4
104104-CLANG=$MAC_BIN_DIR/clang-137
105105-if [ -x $CLANG ]; then
106106- for i in mach/*.c; do
107107- echo "Compiling $i with clang"
108108- ./ld-mac $CLANG -Wl,-syslibroot,$MAC_TOOL_DIR -isysroot $MAC_TOOL_DIR $i -o $i.clang.bin
109109- echo "Running $i.clang.bin"
110110- ./ld-mac $i.clang.bin
111111- done
112112-else
113113- echo "$CLANG not found, skipping some tests with it"
114114-fi
115115-116116-echo
117117-echo '*** ALL TESTS PASS ***'