Skip to content

Commit

Permalink
add brk.c
Browse files Browse the repository at this point in the history
also let poll-emulator build on Linux again
  • Loading branch information
cooljeanius committed Jun 29, 2024
1 parent 7420841 commit d965a29
Show file tree
Hide file tree
Showing 9 changed files with 238 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Makefile.in

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 82 additions & 0 deletions brk.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright (c) 1999-2010 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. The rights granted to you under the License
* may not be used to create, or enable the creation or redistribution of,
* unlawful or unlicensed copies of an Apple operating system, or to
* circumvent, violate, or enable the circumvention or violation of, any
* terms of an Apple operating system software license agreement.
*
* Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_END@
*/
/*
* File: brk.c
*
* Unix compatibility for sbrk system call.
*
* HISTORY
* 09-Mar-90 Gregg Kellogg (gk) at NeXT.
* include <kern/mach_interface.h> instead of <kern/mach.h>
*
* 14-Feb-89 Avadis Tevanian (avie) at NeXT.
* Total rewrite using a fixed area of VM from break region.
*/

#include <mach/mach.h> /* for vm_allocate, vm_offset_t */
#include <mach/vm_statistics.h>
#include <errno.h>
#include <unistd.h>

static int sbrk_needs_init = TRUE;
static vm_size_t sbrk_region_size = 4*1024*1024; /* Well, what should it be? */
static vm_address_t sbrk_curbrk;

void *sbrk(int size)
{
kern_return_t ret;

if (sbrk_needs_init) {
sbrk_needs_init = FALSE;
/*
* Allocate a big region to simulate break region.
*/
ret = vm_allocate(mach_task_self(), &sbrk_curbrk, sbrk_region_size,
VM_MAKE_TAG(VM_MEMORY_SBRK)|TRUE);
if (ret != KERN_SUCCESS) {
errno = ENOMEM;
return((void *)-1);
}
}

if (size <= 0)
return((void *)sbrk_curbrk);
else if (size > sbrk_region_size) {
errno = ENOMEM;
return((void *)-1);
}
sbrk_curbrk += size;
sbrk_region_size -= size;
return((void *)(sbrk_curbrk - size));
}

void *brk(const void *x)
{
errno = ENOMEM;
return((void *)-1);
}
3 changes: 3 additions & 0 deletions config.h.in

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

123 changes: 117 additions & 6 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 18 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ gl_SYSTEM_SPECIFIC_MACROS
AN_OSX_WARNINGS_DUMMY_MACRO
AC_CHECK_FILE([/etc/fstab])dnl

building_on_mac=""
AS_CASE([${build}],
[*apple-darwin*],[building_on_mac="yes"],
[*],[building_on_mac="no"])dnl

AM_CONDITIONAL([BUILDING_ON_MAC],[test "x${building_on_mac}" = "xyes"])dnl

# automake:
AC_MSG_CHECKING([for some automake things...])
AC_MSG_RESULT([... .. . ])
Expand Down Expand Up @@ -110,6 +117,7 @@ warnings_to_skip="${warnings_to_skip} -Wcomments" # redundant w/-Wcomment
warnings_to_skip="${warnings_to_skip} -Wmudflap" # no longer supported
warnings_to_skip="${warnings_to_skip} -Wconditionally-supported" # C++ only
warnings_to_skip="${warnings_to_skip} -Wdelete-incomplete" # C++ only
warnings_to_skip="${warnings_to_skip} -Wnarrowing" # C++ only
warnings_to_skip="${warnings_to_skip} -Wshadow-ivar" # ObjC/ObjC++ only
warnings_to_skip="${warnings_to_skip} -Wimplicit" # default lately anyways
warnings_to_skip="${warnings_to_skip} -Wimplicit-function-declaration" # ""
Expand All @@ -124,12 +132,18 @@ if test x${CFLAGS+set} = xset; then
case "${CFLAGS}" in
*"-O0"* )
warnings_to_skip="${warnings_to_skip} -Wunsafe-loop-optimizations"
warnings_to_skip="${warnings_to_skip} -Waggressive-loop-optimizations"
warnings_to_skip="${warnings_to_skip} -Wdisabled-optimization"
warnings_to_skip="${warnings_to_skip} -Wvector-operation-performance"
;;
*"-O"* )
;;
esac
else
warnings_to_skip="${warnings_to_skip} -Wunsafe-loop-optimizations"
warnings_to_skip="${warnings_to_skip} -Waggressive-loop-optimizations"
warnings_to_skip="${warnings_to_skip} -Wdisabled-optimization"
warnings_to_skip="${warnings_to_skip} -Wvector-operation-performance"
fi
gl_MANYWARN_COMPLEMENT([actual_warnings_to_check],
[${warnings_to_check}],
Expand Down Expand Up @@ -203,6 +217,7 @@ if test "x${ac_cv_search_CFPreferencesCopyAppValue}y" != "xnoy"; then
AC_DEFINE([CFPREFERENCESCOPYAPPVALUE_OK_TO_LINK],[1],
[Define to 1 if we are ok to link w/a library for CFPreferencesCopyAppValue])
fi
AC_SEARCH_LIBS([__fpending],[c System magic pub gnu iberty])
AC_SEARCH_LIBS([dupfd],[c System magic pub gnu iberty])dnl

# Threading.
Expand Down Expand Up @@ -231,7 +246,7 @@ AC_CHECK_HEADERS([_types/_nl_item.h \
fts.h ftw.h gnu-versions.h iconv.h io.h iostream.h \
lcrypt.h libcharset.h libintl.h \
libio/iolibio.h libio/libioP.h limits.h locale.h \
malloc.h malloc/malloc.h memcopy.h mm.h \
mach/mach.h malloc.h malloc/malloc.h memcopy.h mm.h \
mntent.h mnttab.h module.h netdb.h nl_types.h os2.h \
process.h ptms.h publib.h publib/strutil.h \
shlib-compat.h stdarg.h stddef.h stream.h \
Expand Down Expand Up @@ -387,14 +402,14 @@ dnl# (move from "_CHECK" to "_REPLACE" once we do have source files)
unset ac_cv_func_catgets
AC_CHECK_FUNCS([catopen catgets catclose crypt ecvt fcvt gcvt \
setmntent addmntent endmntent \
hasmntopt sbrk brk shmget swapon swapoff])
hasmntopt sbrk shmget swapon swapoff])
## functions that we might want replacements for, and have source files for:
unset ac_cv_func_btowc
unset ac_cv_func_wctob
unset ac_cv_func_getmntent
unset ac_cv_func_poll
AC_REPLACE_FUNCS([btowc wctob dysize fclose fcloseall getmntent poll \
cuserid])dnl
cuserid brk])dnl
## keep autoscan happy:
if test "x" = "Y0"; then
test -x "`which autoscan`" || echo "no autoscan!" >&2
Expand Down
2 changes: 1 addition & 1 deletion configure.scan
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ AC_PROG_RANLIB

# Checks for header files.
AC_FUNC_ALLOCA
AC_CHECK_HEADERS([OS.h fcntl.h fs_info.h inttypes.h langinfo.h libintl.h malloc.h mntent.h mnttab.h netdb.h nl_types.h stdint.h stdio_ext.h sys/fs_types.h sys/fstyp.h sys/ioctl.h sys/mntent.h sys/mount.h sys/param.h sys/socket.h sys/statfs.h sys/statvfs.h sys/time.h sys/vfs.h unistd.h])
AC_CHECK_HEADERS([OS.h fcntl.h fs_info.h inttypes.h langinfo.h libintl.h mach/mach.h malloc.h mntent.h mnttab.h netdb.h nl_types.h stdint.h stdio_ext.h sys/fs_types.h sys/fstyp.h sys/ioctl.h sys/mntent.h sys/mount.h sys/param.h sys/socket.h sys/statfs.h sys/statvfs.h sys/time.h sys/vfs.h unistd.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_CHECK_HEADER_STDBOOL
Expand Down
Loading

0 comments on commit d965a29

Please sign in to comment.