32-bit Hello world working once again in Darling

This commit is contained in:
Lubos Dolezel 2015-12-08 23:16:05 +01:00
parent c3163f017e
commit 5b27c8e6a3
80 changed files with 457 additions and 87 deletions

View File

@ -317,7 +317,8 @@ name:
1: ; \ 1: ; \
popl %edx ; \ popl %edx ; \
2: ; \ 2: ; \
addl $_GLOBAL_OFFSET_TABLE_+(2b-1b),%edx addl $_GLOBAL_OFFSET_TABLE_+(2b-1b),%edx ; \
movl var@GOT(%edx), %edx
#endif // DARLING #endif // DARLING
#elif defined(__x86_64__) #elif defined(__x86_64__)
@ -383,12 +384,24 @@ L ## var ## __non_lazy_ptr: ; \
#endif #endif
#if defined(__i386__) #if defined(__i386__)
#ifndef DARLING
#define EXTERN_TO_REG(var, reg) \ #define EXTERN_TO_REG(var, reg) \
call 1f ; \ call 1f ; \
1: ; \ 1: ; \
popl %edx ; \ popl %edx ; \
movl L ## var ##__non_lazy_ptr-1b(%edx),reg ; \ movl L ## var ##__non_lazy_ptr-1b(%edx),reg ; \
NON_LAZY_STUB(var) NON_LAZY_STUB(var)
#else // DARLING
#define EXTERN_TO_REG(var, reg) \
call 1f ; \
1: ; \
popl %edx ; \
2: ; \
addl $_GLOBAL_OFFSET_TABLE_+(2b-1b),%edx ; \
movl var@GOT(%edx), %edx; \
movl (%edx), reg
#endif
#elif defined(__x86_64__) #elif defined(__x86_64__)
#define EXTERN_TO_REG(var, reg) \ #define EXTERN_TO_REG(var, reg) \
PICIFY(var) ; \ PICIFY(var) ; \

View File

@ -50,6 +50,10 @@ extern uint8_t __commpage[];
#define _COMM_PAGE_APPROX_TIME_SUPPORTED (_COMM_PAGE_START_ADDRESS+0x080) #define _COMM_PAGE_APPROX_TIME_SUPPORTED (_COMM_PAGE_START_ADDRESS+0x080)
#define _COMM_PAGE_APPROX_TIME (_COMM_PAGE_START_ADDRESS+0x088) #define _COMM_PAGE_APPROX_TIME (_COMM_PAGE_START_ADDRESS+0x088)
#define _COMM_TEXT_PFZ_ENQUEUE_OFFSET (_COMM_PAGE_START_ADDRESS+0xc00)
#define _COMM_TEXT_PFZ_DEQUEUE_OFFSET (_COMM_PAGE_START_ADDRESS+0xc80)
#define _COMM_TEXT_PFZ_MUTEX_LOCK_OFFSET (_COMM_PAGE_START_ADDRESS+0xd00)
#define _COMM_PAGE_END (_COMM_PAGE_START_ADDRESS+0xfff) /* end of common page */ #define _COMM_PAGE_END (_COMM_PAGE_START_ADDRESS+0xfff) /* end of common page */
#define _COMM_PAGE_TEXT_START (_COMM_PAGE_START_ADDRESS+0x1000) #define _COMM_PAGE_TEXT_START (_COMM_PAGE_START_ADDRESS+0x1000)

@ -1 +1 @@
Subproject commit 782a332a0cdf04834981df12beeb0fa7eb064a95 Subproject commit 57f42c2752b68629bda6fbde8fdeb30453fc756f

2
src/external/curl vendored

@ -1 +1 @@
Subproject commit 7e51b6d6cfe230916d620dafa888762a9ede723e Subproject commit a15187d0687accd97b584fd205feec20fdd94101

@ -1 +1 @@
Subproject commit 0fee49f16e008b5046d54cf649694b9a0b4e3898 Subproject commit 2bb615310ff8e3cdfab03d8f7e4ea7ec6309fe64

2
src/external/libcxx vendored

@ -1 +1 @@
Subproject commit 44232bda542408bfad97e5dbaa7afd259dac5f15 Subproject commit 9056f5b88e2aff578e9c91281862b9db568cc4e3

@ -1 +1 @@
Subproject commit 83ad1e2950e5f293b372f40ed4d12bd08baa9f00 Subproject commit 462493b5bbb522440ed446e60336aecced8f9270

@ -1 +1 @@
Subproject commit 3b1795bac32b89db60da6b65585616a427000d73 Subproject commit c8e3382df77e6bc44b6831ba5aca5e37109d97a0

@ -1 +1 @@
Subproject commit 8a615053eb14b4d8153a3933fd3ff3c28731bf61 Subproject commit 89b8c94f7b0e1a3d149bc7a496d4cfdc1513200c

View File

@ -45,6 +45,7 @@ set(emulation_sources
unistd/getpid.c unistd/getpid.c
unistd/lseek.c unistd/lseek.c
unistd/ftruncate.c unistd/ftruncate.c
unistd/truncate.c
unistd/access.c unistd/access.c
unistd/readlink.c unistd/readlink.c
unistd/symlink.c unistd/symlink.c
@ -54,6 +55,7 @@ set(emulation_sources
unistd/mknod.c unistd/mknod.c
unistd/chmod.c unistd/chmod.c
unistd/chown.c unistd/chown.c
unistd/lchown.c
unistd/umask.c unistd/umask.c
unistd/chroot.c unistd/chroot.c
unistd/getgid.c unistd/getgid.c

View File

@ -15,12 +15,43 @@ long linux_syscall(long a1, long a2, long a3, long a4, long a5, long a6, int nr)
"ret"); "ret");
} }
#elif defined(__i386__) #elif defined(__i386__)
__attribute__((naked))
long linux_syscall(long a1, long a2, long a3, long a4, long a5, long a6, int nr) long linux_syscall(long a1, long a2, long a3, long a4, long a5, long a6, int nr)
{ {
__asm__("sysenter\n" /*
__asm__("push %%ecx\n"
"push %%edx\n"
"push %%ebp\n"
"movl %%esp, %%ebp\n"
"sysenter\n"
"ret\n" "ret\n"
:: "a"(nr), "b" (a1), "c"(a2), "d"(a3), :: "a"(nr), "b" (a1), "c"(a2), "d"(a3),
"S"(a4), "D"(a5), "ebp"(a6)); "S"(a4), "D"(a5), "ebp"(a6));
__builtin_unreachable();
*/
__asm__("push %ebp\n"
"call 1f\n"
"1:\n"
"pop %ebp\n"
"addl $(2f-1b), %ebp\n"
"push %ebp\n"
"push %ecx\n"
"push %edx\n"
"movl 28+16(%esp), %eax\n"
"movl 4+16(%esp), %ebx\n"
"movl 8+16(%esp), %ecx\n"
"movl 12+16(%esp), %edx\n"
"movl 16+16(%esp), %esi\n"
"movl 20+16(%esp), %edi\n"
"push %ebp\n"
"movl 24+16(%esp), %ebp\n"
"movl %ebp, -4(%esp)\n"
"movl %esp, %ebp\n"
"sysenter\n"
"2:\n"
"pop %ebp\n"
"ret"
);
} }
#else #else
# error Unsupported platform! # error Unsupported platform!

View File

@ -82,7 +82,11 @@ long sys_fcntl_nocancel(int fd, int cmd, long arg)
return -EINVAL; return -EINVAL;
} }
#ifdef __NR_fcntl64
ret = LINUX_SYSCALL(__NR_fcntl64, fd, linux_cmd, arg);
#else
ret = LINUX_SYSCALL(__NR_fcntl, fd, linux_cmd, arg); ret = LINUX_SYSCALL(__NR_fcntl, fd, linux_cmd, arg);
#endif
if (ret < 0) if (ret < 0)
{ {
ret = errno_linux_to_bsd(ret); ret = errno_linux_to_bsd(ret);

View File

@ -16,7 +16,7 @@ long sys_accept_nocancel(int fd, void* from, int* socklen)
struct sockaddr_fixup* fixed; struct sockaddr_fixup* fixed;
#ifdef __NR_socketcall #ifdef __NR_socketcall
ret = LINUX_SYSCALL(__NR_socketcall, LINUX_SYS_ACCEPT, fd, from, socklen); ret = LINUX_SYSCALL(__NR_socketcall, LINUX_SYS_ACCEPT, ((long[6]) { fd, from, socklen }));
#else #else
ret = LINUX_SYSCALL(__NR_accept, fd, from, socklen); ret = LINUX_SYSCALL(__NR_accept, fd, from, socklen);
#endif #endif

View File

@ -28,7 +28,7 @@ long sys_connect_nocancel(int fd, const void* name, int socklen)
fixed->linux_family = sfamily_bsd_to_linux(fixed->bsd_family); fixed->linux_family = sfamily_bsd_to_linux(fixed->bsd_family);
#ifdef __NR_socketcall #ifdef __NR_socketcall
ret = LINUX_SYSCALL(__NR_socketcall, LINUX_SYS_CONNECT, fd, fixed, socklen); ret = LINUX_SYSCALL(__NR_socketcall, LINUX_SYS_CONNECT, ((long[6]) { fd, fixed, socklen }));
#else #else
ret = LINUX_SYSCALL(__NR_connect, fd, fixed, socklen); ret = LINUX_SYSCALL(__NR_connect, fd, fixed, socklen);
#endif #endif

View File

@ -10,7 +10,8 @@ long sys_getpeername(int fd, void* asa, int* socklen)
struct sockaddr_fixup* fixed; struct sockaddr_fixup* fixed;
#ifdef __NR_socketcall #ifdef __NR_socketcall
ret = LINUX_SYSCALL(__NR_socketcall, LINUX_SYS_GETPEERNAME, fd, asa, socklen); ret = LINUX_SYSCALL(__NR_socketcall, LINUX_SYS_GETPEERNAME,
((long[6]) { fd, asa, socklen }));
#else #else
ret = LINUX_SYSCALL(__NR_getpeername, fd, asa, socklen); ret = LINUX_SYSCALL(__NR_getpeername, fd, asa, socklen);
#endif #endif

View File

@ -10,7 +10,8 @@ long sys_getsockname(int fd, void* asa, int* socklen)
struct sockaddr_fixup* fixed; struct sockaddr_fixup* fixed;
#ifdef __NR_socketcall #ifdef __NR_socketcall
ret = LINUX_SYSCALL(__NR_socketcall, LINUX_SYS_GETSOCKNAME, fd, asa, socklen); ret = LINUX_SYSCALL(__NR_socketcall, LINUX_SYS_GETSOCKNAME,
((long[6]) { fd, asa, socklen }));
#else #else
ret = LINUX_SYSCALL(__NR_getsockname, fd, asa, socklen); ret = LINUX_SYSCALL(__NR_getsockname, fd, asa, socklen);
#endif #endif

View File

@ -22,8 +22,8 @@ long sys_recvfrom_nocancel(int fd, void* buf, unsigned long len,
linux_flags = msgflags_bsd_to_linux(flags); linux_flags = msgflags_bsd_to_linux(flags);
#ifdef __NR_socketcall #ifdef __NR_socketcall
ret = LINUX_SYSCALL(__NR_socketcall, LINUX_SYS_RECVFROM, fd, buf, len, ret = LINUX_SYSCALL(__NR_socketcall, LINUX_SYS_RECVFROM, ((long[6]) { fd, buf, len,
flags, from, socklen); flags, from, socklen }));
#else #else
ret = LINUX_SYSCALL(__NR_connect, fd, buf, len, flags, from, socklen); ret = LINUX_SYSCALL(__NR_connect, fd, buf, len, flags, from, socklen);
#endif #endif

View File

@ -42,7 +42,8 @@ long sys_recvmsg_nocancel(int socket, struct bsd_msghdr* msg, int flags)
linux_flags = msgflags_bsd_to_linux(flags); linux_flags = msgflags_bsd_to_linux(flags);
#ifdef __NR_socketcall #ifdef __NR_socketcall
ret = LINUX_SYSCALL(__NR_socketcall, LINUX_SYS_RECVMSG, socket, &lmsg, linux_flags); ret = LINUX_SYSCALL(__NR_socketcall, LINUX_SYS_RECVMSG,
((long[6]) { socket, &lmsg, linux_flags }));
#else #else
ret = LINUX_SYSCALL(__NR_recvmsg, socket, &lmsg, linux_flags); ret = LINUX_SYSCALL(__NR_recvmsg, socket, &lmsg, linux_flags);
#endif #endif

View File

@ -53,7 +53,8 @@ long sys_sendmsg_nocancel(int socket, const struct bsd_msghdr* msg, int flags)
linux_flags = msgflags_bsd_to_linux(flags); linux_flags = msgflags_bsd_to_linux(flags);
#ifdef __NR_socketcall #ifdef __NR_socketcall
ret = LINUX_SYSCALL(__NR_socketcall, LINUX_SYS_SENDMSG, socket, &lmsg, linux_flags); ret = LINUX_SYSCALL(__NR_socketcall, LINUX_SYS_SENDMSG,
((long[6]) { socket, &lmsg, linux_flags }));
#else #else
ret = LINUX_SYSCALL(__NR_recvmsg, socket, &lmsg, linux_flags); ret = LINUX_SYSCALL(__NR_recvmsg, socket, &lmsg, linux_flags);
#endif #endif

View File

@ -10,7 +10,8 @@ long sys_shutdown(int fd, int how)
int ret; int ret;
#ifdef __NR_socketcall #ifdef __NR_socketcall
ret = LINUX_SYSCALL(__NR_socketcall, LINUX_SYS_SHUTDOWN, fd, how); ret = LINUX_SYSCALL(__NR_socketcall, LINUX_SYS_SHUTDOWN,
((long[6]) { fd, how }));
#else #else
ret = LINUX_SYSCALL(__NR_shutdown, fd, how); ret = LINUX_SYSCALL(__NR_shutdown, fd, how);
#endif #endif

View File

@ -26,7 +26,8 @@ long sys_socket(int domain, int type, int protocol)
} }
#ifdef __NR_socketcall #ifdef __NR_socketcall
ret = LINUX_SYSCALL(__NR_socketcall, LINUX_SYS_SOCKET, linux_domain, type, protocol); ret = LINUX_SYSCALL(__NR_socketcall, LINUX_SYS_SOCKET,
((long[6]) { linux_domain, type, protocol }));
#else #else
ret = LINUX_SYSCALL(__NR_socket, linux_domain, type, protocol); ret = LINUX_SYSCALL(__NR_socket, linux_domain, type, protocol);
#endif #endif

View File

@ -20,8 +20,13 @@ long sys_select_nocancel(int nfds, void* rfds, void* wfds, void* efds, struct bs
ltv.tv_usec = timeout->tv_usec; ltv.tv_usec = timeout->tv_usec;
} }
#ifdef __NR__newselect
ret = LINUX_SYSCALL(__NR__newselect, nfds, rfds, wfds, efds,
(timeout != NULL) ? &ltv : NULL);
#else
ret = LINUX_SYSCALL(__NR_select, nfds, rfds, wfds, efds, ret = LINUX_SYSCALL(__NR_select, nfds, rfds, wfds, efds,
(timeout != NULL) ? &ltv : NULL); (timeout != NULL) ? &ltv : NULL);
#endif
if (ret < 0) if (ret < 0)
ret = errno_linux_to_bsd(ret); ret = errno_linux_to_bsd(ret);

View File

@ -16,25 +16,37 @@ __darling_bsd_syscall:
#elif defined(__i386__) #elif defined(__i386__)
#define copy_arg(off) \
movl 8+off(%esp), %ecx ;\
movl %ecx, -24+off(%esp)
__darling_bsd_syscall: __darling_bsd_syscall:
calll .L0$pb calll .L0$pb
.L0$pb: .L0$pb:
popl %ecx popl %ecx
.Ltmp0: .Ltmp0:
addl $_GLOBAL_OFFSET_TABLE_+(.Ltmp0-.L0$pb), %ecx addl $_GLOBAL_OFFSET_TABLE_+(.Ltmp0-.L0$pb), %ecx
movl __bsd_syscall_table@GOT(%eax), %eax movl __bsd_syscall_table@GOT(%ecx), %ecx
movl (%eax), %eax andl $0xffff, %eax // Because there is some extra stuff in upper bytes we don't need
movl 8(%esp), %ecx movl (%ecx,%eax,4), %eax
movl (%eax,%ecx,4), %eax test %eax, %eax
test %eax, %eax jz .no_sys
jz .no_sys // Copy arguments
call *%eax copy_arg(0)
ret copy_arg(4)
copy_arg(8)
copy_arg(12)
copy_arg(16)
copy_arg(20)
subl $24, %esp
call *%eax
addl $24, %esp
ret
.no_sys: .no_sys:
pushl %ecx pushl %ecx
call __unknown_syscall@PLT call __unknown_syscall@PLT
addl $4, %esp addl $4, %esp
ret ret
#else #else
# error Missing assembly # error Missing assembly

View File

@ -26,6 +26,7 @@
#include "unistd/getpid.h" #include "unistd/getpid.h"
#include "unistd/access.h" #include "unistd/access.h"
#include "unistd/lseek.h" #include "unistd/lseek.h"
#include "unistd/truncate.h"
#include "unistd/ftruncate.h" #include "unistd/ftruncate.h"
#include "unistd/readlink.h" #include "unistd/readlink.h"
#include "unistd/readv.h" #include "unistd/readv.h"
@ -40,6 +41,7 @@
#include "unistd/mknod.h" #include "unistd/mknod.h"
#include "unistd/chmod.h" #include "unistd/chmod.h"
#include "unistd/chown.h" #include "unistd/chown.h"
#include "unistd/lchown.h"
#include "unistd/getgid.h" #include "unistd/getgid.h"
#include "unistd/getppid.h" #include "unistd/getppid.h"
#include "unistd/rename.h" #include "unistd/rename.h"
@ -204,6 +206,7 @@ void* __bsd_syscall_table[512] = {
[196] = sys_getdirentries, [196] = sys_getdirentries,
[197] = sys_mmap, [197] = sys_mmap,
[199] = sys_lseek, [199] = sys_lseek,
[200] = sys_truncate,
[201] = sys_ftruncate, [201] = sys_ftruncate,
[202] = sys_sysctl, [202] = sys_sysctl,
[216] = sys_mkcomplex, [216] = sys_mkcomplex,
@ -245,6 +248,7 @@ void* __bsd_syscall_table[512] = {
[347] = sys_getfsstat64, [347] = sys_getfsstat64,
[360] = sys_bsdthread_create, [360] = sys_bsdthread_create,
[361] = sys_bsdthread_terminate, [361] = sys_bsdthread_terminate,
[364] = sys_lchown,
[366] = sys_bsdthread_register, [366] = sys_bsdthread_register,
[367] = sys_workq_open, [367] = sys_workq_open,
[368] = sys_workq_kernreturn, [368] = sys_workq_kernreturn,

View File

@ -8,8 +8,11 @@ long sys_chown(const char* path, int uid, int gid)
int ret; int ret;
// TODO: case translation // TODO: case translation
#ifdef __NR_chown32
ret = LINUX_SYSCALL(__NR_chown32, path, uid, gid);
#else
ret = LINUX_SYSCALL(__NR_chown, path, uid, gid); ret = LINUX_SYSCALL(__NR_chown, path, uid, gid);
#endif
if (ret < 0) if (ret < 0)
ret = errno_linux_to_bsd(ret); ret = errno_linux_to_bsd(ret);

View File

@ -7,7 +7,11 @@ long sys_fchown(int fd, int uid, int gid)
{ {
int ret; int ret;
#ifdef __NR_fchown32
ret = LINUX_SYSCALL3(__NR_fchown32, fd, uid, gid);
#else
ret = LINUX_SYSCALL3(__NR_fchown, fd, uid, gid); ret = LINUX_SYSCALL3(__NR_fchown, fd, uid, gid);
#endif
if (ret < 0) if (ret < 0)
ret = errno_linux_to_bsd(ret); ret = errno_linux_to_bsd(ret);

View File

@ -7,7 +7,11 @@ long sys_ftruncate(int fd, long long length)
{ {
int ret; int ret;
#ifdef __NR_ftruncate64
ret = LINUX_SYSCALL(__NR_ftruncate64, fd, LL_ARG(length));
#else
ret = LINUX_SYSCALL(__NR_ftruncate, fd, LL_ARG(length)); ret = LINUX_SYSCALL(__NR_ftruncate, fd, LL_ARG(length));
#endif
if (ret < 0) if (ret < 0)
ret = errno_linux_to_bsd(ret); ret = errno_linux_to_bsd(ret);

View File

@ -7,7 +7,11 @@ long sys_getegid(void)
{ {
int ret; int ret;
#ifdef __NR_getegid32
ret = LINUX_SYSCALL0(__NR_getegid32);
#else
ret = LINUX_SYSCALL0(__NR_getegid); ret = LINUX_SYSCALL0(__NR_getegid);
#endif
if (ret < 0) if (ret < 0)
ret = errno_linux_to_bsd(ret); ret = errno_linux_to_bsd(ret);

View File

@ -7,7 +7,11 @@ long sys_geteuid(void)
{ {
int ret; int ret;
#ifdef __NR_geteuid32
ret = LINUX_SYSCALL0(__NR_geteuid32);
#else
ret = LINUX_SYSCALL0(__NR_geteuid); ret = LINUX_SYSCALL0(__NR_geteuid);
#endif
if (ret < 0) if (ret < 0)
ret = errno_linux_to_bsd(ret); ret = errno_linux_to_bsd(ret);

View File

@ -7,7 +7,11 @@ long sys_getgid(void)
{ {
int ret; int ret;
#ifdef __NR_getgid32
ret = LINUX_SYSCALL0(__NR_getgid32);
#else
ret = LINUX_SYSCALL0(__NR_getgid); ret = LINUX_SYSCALL0(__NR_getgid);
#endif
if (ret < 0) if (ret < 0)
ret = errno_linux_to_bsd(ret); ret = errno_linux_to_bsd(ret);

View File

@ -7,7 +7,11 @@ long sys_getgroups(unsigned int size, int* gidset)
{ {
int ret; int ret;
#ifdef __NR_getgroups32
ret = LINUX_SYSCALL(__NR_getgroups32, size, gidset);
#else
ret = LINUX_SYSCALL(__NR_getgroups, size, gidset); ret = LINUX_SYSCALL(__NR_getgroups, size, gidset);
#endif
if (ret < 0) if (ret < 0)
ret = errno_linux_to_bsd(ret); ret = errno_linux_to_bsd(ret);

View File

@ -7,7 +7,11 @@ long sys_getuid(void)
{ {
int ret; int ret;
#ifdef __NR_getuid32
ret = LINUX_SYSCALL0(__NR_getuid32);
#else
ret = LINUX_SYSCALL0(__NR_getuid); ret = LINUX_SYSCALL0(__NR_getuid);
#endif
if (ret < 0) if (ret < 0)
ret = errno_linux_to_bsd(ret); ret = errno_linux_to_bsd(ret);

View File

@ -0,0 +1,21 @@
#include "lchown.h"
#include "../base.h"
#include "../errno.h"
#include <asm/unistd.h>
long sys_lchown(const char* path, int uid, int gid)
{
int ret;
// TODO: case translation
#ifdef __NR_chown32
ret = LINUX_SYSCALL(__NR_lchown32, path, uid, gid);
#else
ret = LINUX_SYSCALL(__NR_lchown, path, uid, gid);
#endif
if (ret < 0)
ret = errno_linux_to_bsd(ret);
return ret;
}

View File

@ -0,0 +1,7 @@
#ifndef LINUX_LCHOWN_H
#define LINUX_LCHOWN_H
long sys_lchown(const char* path, int uid, int gid);
#endif

View File

@ -7,7 +7,11 @@ long sys_setgid(int gid)
{ {
int ret; int ret;
#ifdef __NR_setgid32
ret = LINUX_SYSCALL1(__NR_setgid32, gid);
#else
ret = LINUX_SYSCALL1(__NR_setgid, gid); ret = LINUX_SYSCALL1(__NR_setgid, gid);
#endif
if (ret < 0) if (ret < 0)
ret = errno_linux_to_bsd(ret); ret = errno_linux_to_bsd(ret);

View File

@ -7,7 +7,11 @@ long sys_setgroups(unsigned int size, int* gidset)
{ {
int ret; int ret;
#ifdef __NR_setgroups32
ret = LINUX_SYSCALL(__NR_setgroups32, size, gidset);
#else
ret = LINUX_SYSCALL(__NR_setgroups, size, gidset); ret = LINUX_SYSCALL(__NR_setgroups, size, gidset);
#endif
if (ret < 0) if (ret < 0)
ret = errno_linux_to_bsd(ret); ret = errno_linux_to_bsd(ret);

View File

@ -7,7 +7,11 @@ long sys_setuid(int uid)
{ {
int ret; int ret;
#ifdef __NR_setuid32
ret = LINUX_SYSCALL1(__NR_setuid32, uid);
#else
ret = LINUX_SYSCALL1(__NR_setuid, uid); ret = LINUX_SYSCALL1(__NR_setuid, uid);
#endif
if (ret < 0) if (ret < 0)
ret = errno_linux_to_bsd(ret); ret = errno_linux_to_bsd(ret);

View File

@ -0,0 +1,22 @@
#include "truncate.h"
#include "../base.h"
#include "../errno.h"
#include <asm/unistd.h>
long sys_truncate(const char* path, long long length)
{
int ret;
// TODO: translate path
#ifdef __NR_truncate64
ret = LINUX_SYSCALL(__NR_truncate64, path, LL_ARG(length));
#else
ret = LINUX_SYSCALL(__NR_truncate, path, LL_ARG(length));
#endif
if (ret < 0)
ret = errno_linux_to_bsd(ret);
return ret;
}

View File

@ -0,0 +1,7 @@
#ifndef LINUX_TRUNCATE_H
#define LINUX_TRUNCATE_H
long sys_truncate(const char* path, long long length);
#endif

View File

@ -550,6 +550,7 @@ set (syscall_sources ${syscall_sources}
sys_x86-64/writev.S sys_x86-64/writev.S
) )
elseif(BITS EQUAL 32) elseif(BITS EQUAL 32)
set (syscall_sources ${syscall_sources} set (syscall_sources ${syscall_sources}
sys_i386/__accept_nocancel.S sys_i386/__accept_nocancel.S
sys_i386/__accept.S sys_i386/__accept.S

View File

@ -72,7 +72,7 @@
#ifndef DARLING #ifndef DARLING
#define UNIX_SYSCALL_SYSENTER call __sysenter_trap #define UNIX_SYSCALL_SYSENTER call __sysenter_trap
#else #else
#define UNIX_SYSCALL_SYSENTER call __darling_bsd_syscall@PLT #define UNIX_SYSCALL_SYSENTER call __darling_bsd_syscall
#endif #endif
#define UNIX_SYSCALL(name, nargs) \ #define UNIX_SYSCALL(name, nargs) \
@ -80,42 +80,47 @@
LEAF(_##name, 0) ;\ LEAF(_##name, 0) ;\
movl $ SYS_##name, %eax ;\ movl $ SYS_##name, %eax ;\
UNIX_SYSCALL_SYSENTER ;\ UNIX_SYSCALL_SYSENTER ;\
jnb 2f ;\ cmpl $-4095, %eax ;\
jb 3f ;\
BRANCH_EXTERN(tramp_cerror) ;\ BRANCH_EXTERN(tramp_cerror) ;\
2: 3:
#define UNIX_SYSCALL_INT(name, nargs) \ #define UNIX_SYSCALL_INT(name, nargs) \
.globl tramp_cerror ;\ .globl tramp_cerror ;\
LEAF(_##name, 0) ;\ LEAF(_##name, 0) ;\
movl $ SYS_##name, %eax ;\ movl $ SYS_##name, %eax ;\
UNIX_SYSCALL_TRAP ;\ UNIX_SYSCALL_TRAP ;\
jnb 2f ;\ cmpl $-4095, %eax ;\
jb 3f ;\
BRANCH_EXTERN(tramp_cerror) ;\ BRANCH_EXTERN(tramp_cerror) ;\
2: 3:
#if defined(__SYSCALL_32BIT_ARG_BYTES) && ((__SYSCALL_32BIT_ARG_BYTES >= 4) && (__SYSCALL_32BIT_ARG_BYTES <= 20)) #if defined(__SYSCALL_32BIT_ARG_BYTES) && ((__SYSCALL_32BIT_ARG_BYTES >= 4) && (__SYSCALL_32BIT_ARG_BYTES <= 20))
#define UNIX_SYSCALL_NONAME(name, nargs, cerror) \ #define UNIX_SYSCALL_NONAME(name, nargs, cerror) \
movl $(SYS_##name | (__SYSCALL_32BIT_ARG_BYTES << I386_SYSCALL_ARG_BYTES_SHIFT)), %eax ;\ movl $(SYS_##name | (__SYSCALL_32BIT_ARG_BYTES << I386_SYSCALL_ARG_BYTES_SHIFT)), %eax ;\
UNIX_SYSCALL_SYSENTER ;\ UNIX_SYSCALL_SYSENTER ;\
jnb 2f ;\ cmpl $-4095, %eax ;\
jb 3f ;\
BRANCH_EXTERN(tramp_##cerror) ;\ BRANCH_EXTERN(tramp_##cerror) ;\
2: 3:
#else /* __SYSCALL_32BIT_ARG_BYTES < 4 || > 20 */ #else /* __SYSCALL_32BIT_ARG_BYTES < 4 || > 20 */
#define UNIX_SYSCALL_NONAME(name, nargs, cerror) \ #define UNIX_SYSCALL_NONAME(name, nargs, cerror) \
movl $ SYS_##name, %eax ;\ movl $ SYS_##name, %eax ;\
UNIX_SYSCALL_SYSENTER ;\ UNIX_SYSCALL_SYSENTER ;\
jnb 2f ;\ cmpl $-4095, %eax ;\
jb 3f ;\
BRANCH_EXTERN(tramp_##cerror) ;\ BRANCH_EXTERN(tramp_##cerror) ;\
2: 3:
#endif #endif
#define UNIX_SYSCALL_INT_NONAME(name, nargs) \ #define UNIX_SYSCALL_INT_NONAME(name, nargs) \
.globl tramp_cerror_nocancel ;\ .globl tramp_cerror_nocancel ;\
movl $ SYS_##name, %eax ;\ movl $ SYS_##name, %eax ;\
UNIX_SYSCALL_TRAP ;\ UNIX_SYSCALL_TRAP ;\
jnb 2f ;\ cmpl $-4095, %eax ;\
jb 3f ;\
BRANCH_EXTERN(tramp_cerror_nocancel) ;\ BRANCH_EXTERN(tramp_cerror_nocancel) ;\
2: 3:
#define PSEUDO(pseudo, name, nargs, cerror) \ #define PSEUDO(pseudo, name, nargs, cerror) \
LEAF(pseudo, 0) ;\ LEAF(pseudo, 0) ;\
@ -149,19 +154,21 @@ LEAF(pseudo, 0) ;\
LEAF(name, 0) ;\ LEAF(name, 0) ;\
movl $ SYS_##name, %eax ;\ movl $ SYS_##name, %eax ;\
call __darling_bsd_syscall@PLT ;\ call __darling_bsd_syscall@PLT ;\
jnb 2f ;\ cmpl $-4095, %eax ;\
jb 3f ;\
movq %rax, %rdi ;\ movq %rax, %rdi ;\
BRANCH_EXTERN(cerror) ;\ BRANCH_EXTERN(cerror) ;\
2: 3:
#define UNIX_SYSCALL_NONAME(name, nargs, cerror) \ #define UNIX_SYSCALL_NONAME(name, nargs, cerror) \
.globl cerror ;\ .globl cerror ;\
movl $ SYS_##name, %eax ;\ movl $ SYS_##name, %eax ;\
call __darling_bsd_syscall@PLT ;\ call __darling_bsd_syscall@PLT ;\
jnb 2f ;\ cmpl $-4095, %eax ;\
jb 3f ;\
movq %rax, %rdi ;\ movq %rax, %rdi ;\
BRANCH_EXTERN(cerror) ;\ BRANCH_EXTERN(cerror) ;\
2: 3:
#else #else

View File

@ -49,26 +49,26 @@
#define GET_CURRENT_PID PICIFY(__current_pid) #define GET_CURRENT_PID PICIFY(__current_pid)
NON_LAZY_STUB(__current_pid) NON_LAZY_STUB(__current_pid)
#define __current_pid (%edx) #define __current_pid_var (%edx)
#else #else
#define GET_CURRENT_PID #define GET_CURRENT_PID
#endif #endif
/* /*
* If __current_pid >= 0, we want to put a -1 in there * If __current_pid_var >= 0, we want to put a -1 in there
* otherwise we just decrement it * otherwise we just decrement it
*/ */
LEAF(___vfork, 0) LEAF(___vfork, 0)
GET_CURRENT_PID GET_CURRENT_PID
movl __current_pid, %eax movl __current_pid_var, %eax
0: 0:
xorl %ecx, %ecx xorl %ecx, %ecx
testl %eax, %eax testl %eax, %eax
cmovs %eax, %ecx cmovs %eax, %ecx
decl %ecx decl %ecx
lock lock
cmpxchgl %ecx, __current_pid cmpxchgl %ecx, __current_pid_var
jne 0b jne 0b
popl %ecx popl %ecx
movl $(SYS_vfork), %eax // code for vfork -> eax movl $(SYS_vfork), %eax // code for vfork -> eax
@ -76,7 +76,7 @@ LEAF(___vfork, 0)
jnb L1 // jump if CF==0 jnb L1 // jump if CF==0
GET_CURRENT_PID GET_CURRENT_PID
lock lock
incl __current_pid incl __current_pid_var
pushl %ecx pushl %ecx
BRANCH_EXTERN(tramp_cerror) BRANCH_EXTERN(tramp_cerror)
@ -89,25 +89,25 @@ L1:
L2: L2:
GET_CURRENT_PID GET_CURRENT_PID
lock lock
incl __current_pid incl __current_pid_var
jmp *%ecx jmp *%ecx
#elif defined(__x86_64__) #elif defined(__x86_64__)
/* /*
* If __current_pid >= 0, we want to put a -1 in there * If __current_pid_var >= 0, we want to put a -1 in there
* otherwise we just decrement it * otherwise we just decrement it
*/ */
LEAF(___vfork, 0) LEAF(___vfork, 0)
movq __current_pid@GOTPCREL(%rip), %rax movq __current_pid_var@GOTPCREL(%rip), %rax
movl (%rax), %eax movl (%rax), %eax
0: 0:
xorl %ecx, %ecx xorl %ecx, %ecx
testl %eax, %eax testl %eax, %eax
cmovs %eax, %ecx cmovs %eax, %ecx
subl $1, %ecx subl $1, %ecx
movq __current_pid@GOTPCREL(%rip), %rdx movq __current_pid_var@GOTPCREL(%rip), %rdx
lock lock
cmpxchgl %ecx, (%rdx) cmpxchgl %ecx, (%rdx)
jne 0b jne 0b
@ -116,7 +116,7 @@ LEAF(___vfork, 0)
UNIX_SYSCALL_TRAP // do the system call UNIX_SYSCALL_TRAP // do the system call
jnb L1 // jump if CF==0 jnb L1 // jump if CF==0
pushq %rdi // put return address back on stack for cerror pushq %rdi // put return address back on stack for cerror
movq __current_pid@GOTPCREL(%rip), %rcx movq __current_pid_var@GOTPCREL(%rip), %rcx
lock lock
addq $1, (%rcx) addq $1, (%rcx)
movq %rax, %rdi movq %rax, %rdi
@ -129,7 +129,7 @@ L1:
jmp *%rdi jmp *%rdi
L2: L2:
movq __current_pid@GOTPCREL(%rip), %rdx movq __current_pid_var@GOTPCREL(%rip), %rdx
lock lock
addq $1, (%rdx) addq $1, (%rdx)
jmp *%rdi jmp *%rdi

View File

@ -1,6 +1,15 @@
#define __SYSCALL_32BIT_ARG_BYTES 12 #define __SYSCALL_32BIT_ARG_BYTES 12
#include "SYS.h" #include "SYS.h"
#ifndef SYS_aio_suspend
#error "SYS_aio_suspend not defined. The header files libsyscall is building against do not match syscalls.master."
#endif
#if defined(__i386__)
__SYSCALL2(__aio_suspend, aio_suspend, 1, cerror)
#endif
#if defined(__i386__) #if defined(__i386__)
.globl aio_suspend$UNIX2003 .globl aio_suspend$UNIX2003
aio_suspend$UNIX2003 = __aio_suspend aio_suspend$UNIX2003 = __aio_suspend

View File

@ -1,6 +1,14 @@
#define __SYSCALL_32BIT_ARG_BYTES 4 #define __SYSCALL_32BIT_ARG_BYTES 4
#include "SYS.h" #include "SYS.h"
#ifndef SYS_close
#error "SYS_close not defined. The header files libsyscall is building against do not match syscalls.master."
#endif
#if defined(__i386__)
__SYSCALL2(__close, close, 1, cerror)
#endif
#if defined(__i386__) #if defined(__i386__)
.globl close$UNIX2003 .globl close$UNIX2003
close$UNIX2003 = __close close$UNIX2003 = __close

View File

@ -1,6 +1,15 @@
#define __SYSCALL_32BIT_ARG_BYTES 4 #define __SYSCALL_32BIT_ARG_BYTES 4
#include "SYS.h" #include "SYS.h"
#ifndef SYS_fsync
#error "SYS_fsync not defined. The header files libsyscall is building against do not match syscalls.master."
#endif
#if defined(__i386__)
__SYSCALL2(__fsync, fsync, 1, cerror)
#endif
#if defined(__i386__) #if defined(__i386__)
.globl fsync$UNIX2003 .globl fsync$UNIX2003
fsync$UNIX2003 = __fsync fsync$UNIX2003 = __fsync

View File

@ -1,6 +1,15 @@
#define __SYSCALL_32BIT_ARG_BYTES 20 #define __SYSCALL_32BIT_ARG_BYTES 20
#include "SYS.h" #include "SYS.h"
#ifndef SYS_msgrcv
#error "SYS_msgrcv not defined. The header files libsyscall is building against do not match syscalls.master."
#endif
#if defined(__i386__)
__SYSCALL2(__msgrcv, msgrcv, 1, cerror)
#endif
#if defined(__i386__) #if defined(__i386__)
.globl msgrcv$UNIX2003 .globl msgrcv$UNIX2003
msgrcv$UNIX2003 = __msgrcv msgrcv$UNIX2003 = __msgrcv

View File

@ -1,6 +1,15 @@
#define __SYSCALL_32BIT_ARG_BYTES 16 #define __SYSCALL_32BIT_ARG_BYTES 16
#include "SYS.h" #include "SYS.h"
#ifndef SYS_msgsnd
#error "SYS_msgsnd not defined. The header files libsyscall is building against do not match syscalls.master."
#endif
#if defined(__i386__)
__SYSCALL2(__msgsnd, msgsnd, 1, cerror)
#endif
#if defined(__i386__) #if defined(__i386__)
.globl msgsnd$UNIX2003 .globl msgsnd$UNIX2003
msgsnd$UNIX2003 = __msgsnd msgsnd$UNIX2003 = __msgsnd

View File

@ -1,6 +1,15 @@
#define __SYSCALL_32BIT_ARG_BYTES 12 #define __SYSCALL_32BIT_ARG_BYTES 12
#include "SYS.h" #include "SYS.h"
#ifndef SYS_poll
#error "SYS_poll not defined. The header files libsyscall is building against do not match syscalls.master."
#endif
#if defined(__i386__)
__SYSCALL2(__poll, poll, 1, cerror)
#endif
#if defined(__i386__) #if defined(__i386__)
.globl poll$UNIX2003 .globl poll$UNIX2003
poll$UNIX2003 = __poll poll$UNIX2003 = __poll

View File

@ -1,6 +1,15 @@
#define __SYSCALL_32BIT_ARG_BYTES 20 #define __SYSCALL_32BIT_ARG_BYTES 20
#include "SYS.h" #include "SYS.h"
#ifndef SYS_pread
#error "SYS_pread not defined. The header files libsyscall is building against do not match syscalls.master."
#endif
#if defined(__i386__)
__SYSCALL2(__pread, pread, 1, cerror)
#endif
#if defined(__i386__) #if defined(__i386__)
.globl pread$UNIX2003 .globl pread$UNIX2003
pread$UNIX2003 = __pread pread$UNIX2003 = __pread

View File

@ -1,6 +1,15 @@
#define __SYSCALL_32BIT_ARG_BYTES 20 #define __SYSCALL_32BIT_ARG_BYTES 20
#include "SYS.h" #include "SYS.h"
#ifndef SYS_pwrite
#error "SYS_pwrite not defined. The header files libsyscall is building against do not match syscalls.master."
#endif
#if defined(__i386__)
__SYSCALL2(__pwrite, pwrite, 1, cerror)
#endif
#if defined(__i386__) #if defined(__i386__)
.globl pwrite$UNIX2003 .globl pwrite$UNIX2003
pwrite$UNIX2003 = __pwrite pwrite$UNIX2003 = __pwrite

View File

@ -1,6 +1,15 @@
#define __SYSCALL_32BIT_ARG_BYTES 12 #define __SYSCALL_32BIT_ARG_BYTES 12
#include "SYS.h" #include "SYS.h"
#ifndef SYS_read
#error "SYS_read not defined. The header files libsyscall is building against do not match syscalls.master."
#endif
#if defined(__i386__)
__SYSCALL2(__read, read, 1, cerror)
#endif
#if defined(__i386__) #if defined(__i386__)
.globl read$UNIX2003 .globl read$UNIX2003
read$UNIX2003 = __read read$UNIX2003 = __read

View File

@ -1,6 +1,15 @@
#define __SYSCALL_32BIT_ARG_BYTES 12 #define __SYSCALL_32BIT_ARG_BYTES 12
#include "SYS.h" #include "SYS.h"
#ifndef SYS_readv
#error "SYS_readv not defined. The header files libsyscall is building against do not match syscalls.master."
#endif
#if defined(__i386__)
__SYSCALL2(__readv, readv, 1, cerror)
#endif
#if defined(__i386__) #if defined(__i386__)
.globl readv$UNIX2003 .globl readv$UNIX2003
readv$UNIX2003 = __readv readv$UNIX2003 = __readv

View File

@ -1,6 +1,15 @@
#define __SYSCALL_32BIT_ARG_BYTES 4 #define __SYSCALL_32BIT_ARG_BYTES 4
#include "SYS.h" #include "SYS.h"
#ifndef SYS_sem_wait
#error "SYS_sem_wait not defined. The header files libsyscall is building against do not match syscalls.master."
#endif
#if defined(__i386__)
__SYSCALL2(__sem_wait, sem_wait, 1, cerror)
#endif
#if defined(__i386__) #if defined(__i386__)
.globl sem_wait$UNIX2003 .globl sem_wait$UNIX2003
sem_wait$UNIX2003 = __sem_wait sem_wait$UNIX2003 = __sem_wait

View File

@ -1,6 +1,15 @@
#define __SYSCALL_32BIT_ARG_BYTES 16 #define __SYSCALL_32BIT_ARG_BYTES 16
#include "SYS.h" #include "SYS.h"
#ifndef SYS_waitid
#error "SYS_waitid not defined. The header files libsyscall is building against do not match syscalls.master."
#endif
#if defined(__i386__)
__SYSCALL2(__waitid, waitid, 1, cerror)
#endif
#if defined(__i386__) #if defined(__i386__)
.globl waitid$UNIX2003 .globl waitid$UNIX2003
waitid$UNIX2003 = __waitid waitid$UNIX2003 = __waitid

View File

@ -1,6 +1,15 @@
#define __SYSCALL_32BIT_ARG_BYTES 12 #define __SYSCALL_32BIT_ARG_BYTES 12
#include "SYS.h" #include "SYS.h"
#ifndef SYS_write
#error "SYS_write not defined. The header files libsyscall is building against do not match syscalls.master."
#endif
#if defined(__i386__)
__SYSCALL2(__write, write, 1, cerror)
#endif
#if defined(__i386__) #if defined(__i386__)
.globl write$UNIX2003 .globl write$UNIX2003
write$UNIX2003 = __write write$UNIX2003 = __write

View File

@ -1,6 +1,15 @@
#define __SYSCALL_32BIT_ARG_BYTES 12 #define __SYSCALL_32BIT_ARG_BYTES 12
#include "SYS.h" #include "SYS.h"
#ifndef SYS_writev
#error "SYS_writev not defined. The header files libsyscall is building against do not match syscalls.master."
#endif
#if defined(__i386__)
__SYSCALL2(__writev, writev, 1, cerror)
#endif
#if defined(__i386__) #if defined(__i386__)
.globl writev$UNIX2003 .globl writev$UNIX2003
writev$UNIX2003 = __writev writev$UNIX2003 = __writev

View File

@ -26,6 +26,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/param.h> #include <sys/param.h>
#include <sys/_types/_timeval32.h>
#ifdef UTMP_COMPAT #ifdef UTMP_COMPAT
#define UTMP_COMPAT_UTMP0 0x01 #define UTMP_COMPAT_UTMP0 0x01

View File

@ -9,15 +9,15 @@ add_definitions(-DPRIVATE)
set(i386_sources set(i386_sources
gen/getmcontext.c gen/getmcontext.c
#gen/makecontext.c gen/makecontext.c
#gen/setcontext.c gen/setcontext.c
gen/setjmperr.c gen/setjmperr.c
#gen/swapcontext.c gen/swapcontext.c
gen/cpu_number.S gen/cpu_number.S
gen/icacheinval.S gen/icacheinval.S
gen/mcount.S gen/mcount.S
gen/_ctx_start.S gen/_ctx_start.S
#gen/getcontext.S gen/getcontext.S
gen/_setcontext.S gen/_setcontext.S
# sys/i386_gettimeofday_asm.S # sys/i386_gettimeofday_asm.S
@ -55,11 +55,11 @@ set(i386_sources
string/memcpy.c string/memcpy.c
string/memmove.c string/memmove.c
# pthreads/preempt.S pthreads/preempt.S
pthreads/pthread_getspecific.S pthreads/pthread_getspecific.S
pthreads/pthread_mutex_lock.S pthreads/pthread_mutex_lock.S
pthreads/pthread_self.S pthreads/pthread_self.S
pthreads/pthread_set_self.S #pthreads/pthread_set_self.S
pthreads/start_wqthread.S pthreads/start_wqthread.S
pthreads/thread_start.S pthreads/thread_start.S
pthreads/init_cpu_capabilities.c pthreads/init_cpu_capabilities.c

View File

@ -50,6 +50,7 @@
.align 4 .align 4
#ifdef DARLING #ifdef DARLING
.hidden _cpu_number .hidden _cpu_number
.globl _cpu_number
#else #else
.private_extern _cpu_number .private_extern _cpu_number
#endif #endif

View File

@ -1,3 +1,4 @@
// Modified by Lubos Dolezel for Darling
/* /*
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved. * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
* *
@ -22,6 +23,10 @@
*/ */
#import <architecture/i386/asm_help.h> #import <architecture/i386/asm_help.h>
#ifdef DARLING
# define _moncount moncount
#endif
.text .text
.globl mcount .globl mcount
mcount: mcount:

View File

@ -38,7 +38,12 @@
* Destroys %eax, %ecx, and %edx. * Destroys %eax, %ecx, and %edx.
*/ */
.align 4 .align 4
#ifndef DARLING
.private_extern _preempt .private_extern _preempt
#else
.globl _preempt
.hidden _preempt
#endif
_preempt: _preempt:
popl %edx // get return address popl %edx // get return address
movl %esp,%ecx // save stack ptr here movl %esp,%ecx // save stack ptr here
@ -56,7 +61,12 @@ _preempt:
*/ */
.align 4 .align 4
#ifndef DARLING
.private_extern _backoff .private_extern _backoff
#else
.globl _backoff
.hidden _backoff
#endif
_backoff: _backoff:
testl %ebx,%ebx // does kernel want to preempt us? testl %ebx,%ebx // does kernel want to preempt us?
jz 1f // no jz 1f // no

View File

@ -1,3 +1,4 @@
// Modified by Lubos Dolezel for Darling
/* /*
* Copyright (c) 2006 Apple Computer, Inc. All rights reserved. * Copyright (c) 2006 Apple Computer, Inc. All rights reserved.
* *
@ -24,8 +25,13 @@
#include <machine/cpu_capabilities.h> #include <machine/cpu_capabilities.h>
#include <architecture/i386/asm_help.h> #include <architecture/i386/asm_help.h>
#ifdef DARLING
# define _preempt preempt
# define _commpage_pfz_base commpage_pfz_base
#endif
.text .text
.align 2 .align (1<<2)
.globl __commpage_pthread_mutex_lock .globl __commpage_pthread_mutex_lock
__commpage_pthread_mutex_lock: __commpage_pthread_mutex_lock:
pushl %ebp // set up frame for backtrace pushl %ebp // set up frame for backtrace

View File

@ -26,11 +26,11 @@
#ifdef DARLING #ifdef DARLING
# define _thread_start thread_start # define _thread_start thread_start
# definie __pthread_start _pthread_start@PLT # define __pthread_start _pthread_start
#endif #endif
.text .text
.align 2, 0x90 .align (1<<2), 0x90
.globl _thread_start .globl _thread_start
_thread_start: _thread_start:
// This routine is never called directly by user code, jumped from kernel // This routine is never called directly by user code, jumped from kernel

View File

@ -1,5 +1,6 @@
#ifdef DARLING #ifdef DARLING
# define ___bzero __bzero # define ___bzero __bzero
# define _bzero bzero
#endif #endif
.globl ___bzero .globl ___bzero

View File

@ -1,3 +1,4 @@
// Modified by Lubos Dolezel for Darling
/* /*
* Copyright (c) 2006 Apple Computer, Inc. All rights reserved. * Copyright (c) 2006 Apple Computer, Inc. All rights reserved.
* *
@ -29,6 +30,10 @@
#include <machine/cpu_capabilities.h> #include <machine/cpu_capabilities.h>
#include <platfunc.h> #include <platfunc.h>
#ifdef DARLING
# define _longcopy longcopy
#endif
/* /*
* The bcopy/memcpy loops, tuned for Pentium-M class processors with * The bcopy/memcpy loops, tuned for Pentium-M class processors with
* Supplemental SSE3 and 64-byte cache lines. * Supplemental SSE3 and 64-byte cache lines.

View File

@ -64,6 +64,7 @@
#ifndef DARLING #ifndef DARLING
.private_extern _longcopy .private_extern _longcopy
#else #else
.globl _longcopy
.hidden _longcopy .hidden _longcopy
#endif #endif

View File

@ -51,6 +51,7 @@
# define _memset_pattern4 memset_pattern4 # define _memset_pattern4 memset_pattern4
# define _memset_pattern8 memset_pattern8 # define _memset_pattern8 memset_pattern8
# define _memset_pattern16 memset_pattern16 # define _memset_pattern16 memset_pattern16
# define _bzero bzero
#endif #endif
.text .text

View File

@ -64,6 +64,7 @@
#ifndef DARLING #ifndef DARLING
.private_extern _memset_pattern .private_extern _memset_pattern
#else #else
.globl _memset_pattern
.hidden _memset_pattern .hidden _memset_pattern
#endif #endif
_memset_pattern: _memset_pattern:

View File

@ -27,6 +27,7 @@
#ifdef DARLING #ifdef DARLING
#define _strncpy strncpy #define _strncpy strncpy
#define _bzero bzero
#endif #endif
// ***************** // *****************

View File

@ -35,6 +35,8 @@
#ifdef DARLING #ifdef DARLING
# define _OSAtomicFifoEnqueue OSAtomicFifoEnqueue # define _OSAtomicFifoEnqueue OSAtomicFifoEnqueue
# define _OSAtomicFifoDequeue OSAtomicFifoDequeue # define _OSAtomicFifoDequeue OSAtomicFifoDequeue
# define _preempt preempt
# define _commpage_pfz_base commpage_pfz_base
#endif #endif
#ifndef DARLING #ifndef DARLING

View File

@ -40,7 +40,7 @@
return find_platform_function((const platfunc_descriptor**) symbol ## _platfunc_descriptors); \ return find_platform_function((const platfunc_descriptor**) symbol ## _platfunc_descriptors); \
} }
#else // ELF doesn't support symbol resolvers #else // ELF doesn't support symbol resolvers
#define RESOLVER_UP_MP(symbol) __asm__(".globl " #symbol); __asm__(#symbol ": jmp " #symbol "$VARIANT$mp@PLT"); #define RESOLVER_UP_MP(symbol) __asm__(".globl " #symbol); __asm__(#symbol ": jmp " #symbol "$VARIANT$mp");
#endif #endif
RESOLVER_UP_MP(OSAtomicAnd32) RESOLVER_UP_MP(OSAtomicAnd32)

View File

@ -39,7 +39,7 @@
# define _siglongjmp siglongjmp # define _siglongjmp siglongjmp
# define x_longjmp longjmp # define x_longjmp longjmp
# define x__longjmp _longjmp # define x__longjmp _longjmp
# define __sigunalstack _sigunaltstack # define __sigunaltstack _sigunaltstack
#else #else
# define x_longjmp _longjmp # define x_longjmp _longjmp
# define x__longjmp __longjmp # define x__longjmp __longjmp

View File

@ -40,7 +40,7 @@
return find_platform_function((const platfunc_descriptor**) symbol ## _platfunc_descriptors); \ return find_platform_function((const platfunc_descriptor**) symbol ## _platfunc_descriptors); \
} }
#else // ELF doesn't support symbol resolvers #else // ELF doesn't support symbol resolvers
#define RESOLVER_UP_MP(symbol) __asm__(".globl " #symbol); __asm__(#symbol ": jmp " #symbol "$VARIANT$mp@PLT"); #define RESOLVER_UP_MP(symbol) __asm__(".globl " #symbol); __asm__(#symbol ": jmp " #symbol "$VARIANT$mp");
#endif #endif
RESOLVER_UP_MP(OSSpinLockTry) RESOLVER_UP_MP(OSSpinLockTry)

View File

@ -127,8 +127,8 @@ PLATFUNC_DESCRIPTOR(_spin_lock,mp,0,kUP)
.align 2, 0x90 .align 2, 0x90
.globl _OSSpinLockUnlock .globl _OSSpinLockUnlock
.globl _spin_unlock .globl x_spin_unlock
.globl __spin_unlock .globl x__spin_unlock
_OSSpinLockUnlock: _OSSpinLockUnlock:
x_spin_unlock: x_spin_unlock:
x__spin_unlock: x__spin_unlock:

View File

@ -30,9 +30,9 @@ set(sys_sources chmodx_np.c
OpenBSD/stack_protector.c OpenBSD/stack_protector.c
) )
if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686") #if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
set(sys_sources ${sys_sources} context-stubs.c) # set(sys_sources ${sys_sources} context-stubs.c)
endif() #endif()
SET_SOURCE_FILES_PROPERTIES(semctl.c PROPERTIES COMPILE_FLAGS "${CMAKE_C_FLAGS} -DLIBC_ALIAS_SEMCTL -DKERNEL -U__DARWIN_UNIX03 -D__DARWIN_UNIX03=0") SET_SOURCE_FILES_PROPERTIES(semctl.c PROPERTIES COMPILE_FLAGS "${CMAKE_C_FLAGS} -DLIBC_ALIAS_SEMCTL -DKERNEL -U__DARWIN_UNIX03 -D__DARWIN_UNIX03=0")
SET_SOURCE_FILES_PROPERTIES(shmctl.c PROPERTIES COMPILE_FLAGS "${CMAKE_C_FLAGS} -DLIBC_ALIAS_SEMCTL -DKERNEL -U__DARWIN_UNIX03 -D__DARWIN_UNIX03=0") SET_SOURCE_FILES_PROPERTIES(shmctl.c PROPERTIES COMPILE_FLAGS "${CMAKE_C_FLAGS} -DLIBC_ALIAS_SEMCTL -DKERNEL -U__DARWIN_UNIX03 -D__DARWIN_UNIX03=0")

View File

@ -39,7 +39,7 @@ set(dyld_SRCS
threads.cpp threads.cpp
) )
if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86") #if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
set(dyld_SRCS ${dyld_SRCS} set(dyld_SRCS ${dyld_SRCS}
UndefinedFunction.cpp UndefinedFunction.cpp
Trampoline.cpp Trampoline.cpp
@ -55,7 +55,7 @@ if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64" OR ${CMAKE_SYSTEM_PROCESSOR} STR
add_definitions(-DHAS_DEBUG_HELPERS) add_definitions(-DHAS_DEBUG_HELPERS)
add_definitions(-DHAS_TLS_SUPPORT) add_definitions(-DHAS_TLS_SUPPORT)
endif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86") #endif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86")
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib${SUFFIX}/darling") SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib${SUFFIX}/darling")
#SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--enable-new-dtags") #SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--enable-new-dtags")

View File

@ -37,7 +37,7 @@ reg_saveall: // 24 bytes on stack
pushl %edx pushl %edx
pushl %esi pushl %esi
pushl %edi pushl %edi
subl 8, %esp subl $8, %esp
fstpl (%esp) fstpl (%esp)
jmpl *%eax jmpl *%eax

View File

@ -33,6 +33,7 @@
# define _ffi_prep_args ffi_prep_args # define _ffi_prep_args ffi_prep_args
# define _ffi_call_SYSV ffi_call_SYSV # define _ffi_call_SYSV ffi_call_SYSV
# define _ffi_closure_SYSV ffi_closure_SYSV # define _ffi_closure_SYSV ffi_closure_SYSV
# define _ffi_closure_SYSV_inner ffi_closure_SYSV_inner
# define _ffi_closure_raw_SYSV ffi_closure_raw_SYSV # define _ffi_closure_raw_SYSV ffi_closure_raw_SYSV
#endif #endif
@ -307,14 +308,19 @@ Lrcls_retllong:
jmp Lrcls_epilogue jmp Lrcls_epilogue
LFE3: LFE3:
#endif #endif
#ifndef DARLING
.section __IMPORT,__jump_table,symbol_stubs,self_modifying_code+pure_instructions,5 .section __IMPORT,__jump_table,symbol_stubs,self_modifying_code+pure_instructions,5
L_ffi_closure_SYSV_inner$stub: L_ffi_closure_SYSV_inner$stub:
.indirect_symbol _ffi_closure_SYSV_inner .indirect_symbol _ffi_closure_SYSV_inner
hlt ; hlt ; hlt ; hlt ; hlt hlt ; hlt ; hlt ; hlt ; hlt
#else
L_ffi_closure_SYSV_inner$stub:
jmp _ffi_closure_SYSV_inner
#endif
#ifndef DARLING
.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support .section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support
#endif
EH_frame1: EH_frame1:
.set L$set$0,LECIE1-LSCIE1 .set L$set$0,LECIE1-LSCIE1
.long L$set$0 .long L$set$0

View File

@ -65,14 +65,24 @@ struct mach_port_allocate_args
struct mach_msg_overwrite_args struct mach_msg_overwrite_args
{ {
union { void* msg; uint64_t pad; }; #ifdef __i386__
void* msg;
uint32_t pad1;
#else
void* msg;
#endif
unsigned int option; unsigned int option;
unsigned int send_size; unsigned int send_size;
unsigned int recv_size; unsigned int recv_size;
unsigned int rcv_name; unsigned int rcv_name;
unsigned int timeout; unsigned int timeout;
unsigned int notify; unsigned int notify;
union { void* rcv_msg; uint64_t pad2; }; #ifdef __i386__
void* rcv_msg;
uint32_t pad2;
#else
void* rcv_msg;
#endif
unsigned int rcv_limit; unsigned int rcv_limit;
}; };

View File

@ -491,7 +491,11 @@ kern_return_t mach_msg_overwrite_trap(mach_task_t* task,
debug_msg("mach_msg_overwrite_trap()"); debug_msg("mach_msg_overwrite_trap()");
if (copy_from_user(&args, in_args, sizeof(args))) if (copy_from_user(&args, in_args, sizeof(args)))
{
debug_msg("!!! Cannot copy %d bytes from %p\n",
sizeof(args), in_args);
return KERN_INVALID_ADDRESS; return KERN_INVALID_ADDRESS;
}
if (args.option & MACH_SEND_MSG) if (args.option & MACH_SEND_MSG)
{ {
@ -514,6 +518,8 @@ kern_return_t mach_msg_overwrite_trap(mach_task_t* task,
if (copy_from_user(msg, args.msg, args.send_size)) if (copy_from_user(msg, args.msg, args.send_size))
{ {
debug_msg("!!! Cannot copy %d bytes from %p\n",
args.send_size, args.msg);
kfree(msg); kfree(msg);
return KERN_INVALID_ADDRESS; return KERN_INVALID_ADDRESS;
} }
@ -782,10 +788,9 @@ kern_return_t bsdthread_terminate_trap(mach_task_t* task,
if (PORT_IS_VALID(sem->port)) if (PORT_IS_VALID(sem->port))
mach_semaphore_signal(sem->port); mach_semaphore_signal(sem->port);
else else
debug_msg("Invalid semaphore %d!\n", args.signal); debug_msg("Invalid semaphore %d in bsdthread_terminate_trap()!\n", args.signal);
// Deallocate stack // Deallocate stack
debug_msg("unmap %p, 0x%x bytes\n", args.stackaddr, args.freesize);
vm_munmap(args.stackaddr, args.freesize); vm_munmap(args.stackaddr, args.freesize);
// Deregister thread // Deregister thread