diff --git a/include/unistd.h b/include/unistd.h --- a/include/unistd.h +++ b/include/unistd.h @@ -467,13 +467,17 @@ #endif /* __XSI_VISIBLE */ #if (__XSI_VISIBLE && __XSI_VISIBLE <= 500) || __BSD_VISIBLE +#ifdef _WANT_BRK int brk(const void *); +#endif int chroot(const char *); int getdtablesize(void); int getpagesize(void) __pure2; char *getpass(const char *); +#ifdef _WANT_SBRK void *sbrk(intptr_t); #endif +#endif #if (__XSI_VISIBLE && __XSI_VISIBLE <= 600) || __BSD_VISIBLE char *getwd(char *); /* obsoleted by getcwd() */ diff --git a/lib/libc/amd64/Symbol.map b/lib/libc/amd64/Symbol.map --- a/lib/libc/amd64/Symbol.map +++ b/lib/libc/amd64/Symbol.map @@ -6,7 +6,6 @@ FBSD_1.0 { .mcount; __flt_rounds; - brk; fpgetmask; fpgetprec; fpgetround; @@ -14,7 +13,6 @@ fpsetmask; fpsetprec; fpsetround; - sbrk; }; /* @@ -28,5 +26,4 @@ __signalcontext; signalcontext; __siglongjmp; - _brk; }; diff --git a/lib/libc/arm/Symbol.map b/lib/libc/arm/Symbol.map --- a/lib/libc/arm/Symbol.map +++ b/lib/libc/arm/Symbol.map @@ -6,8 +6,6 @@ FBSD_1.0 { __mcount; alloca; - brk; - sbrk; }; FBSD_1.3 { @@ -25,7 +23,6 @@ }; FBSDprivate_1.0 { - _brk; __aeabi_read_tp; ___longjmp; __longjmp; diff --git a/lib/libc/i386/Symbol.map b/lib/libc/i386/Symbol.map --- a/lib/libc/i386/Symbol.map +++ b/lib/libc/i386/Symbol.map @@ -5,10 +5,8 @@ */ FBSD_1.0 { .mcount; - brk; __flt_rounds; ___tls_get_addr; - sbrk; }; FBSDprivate_1.0 { @@ -17,5 +15,4 @@ __signalcontext; signalcontext; __siglongjmp; - _brk; }; diff --git a/lib/libc/powerpc/Symbol.map b/lib/libc/powerpc/Symbol.map --- a/lib/libc/powerpc/Symbol.map +++ b/lib/libc/powerpc/Symbol.map @@ -6,13 +6,11 @@ FBSD_1.0 { _mcount; __flt_rounds; - brk; fpgetmask; fpgetround; fpgetsticky; fpsetmask; fpsetround; - sbrk; }; FBSD_1.3 { diff --git a/lib/libc/powerpc64/Symbol.map b/lib/libc/powerpc64/Symbol.map --- a/lib/libc/powerpc64/Symbol.map +++ b/lib/libc/powerpc64/Symbol.map @@ -6,11 +6,9 @@ FBSD_1.0 { _mcount; __flt_rounds; - brk; fpgetmask; fpgetround; fpgetsticky; fpsetmask; fpsetround; - sbrk; }; diff --git a/lib/libc/sys/brk.c b/lib/libc/sys/brk.c --- a/lib/libc/sys/brk.c +++ b/lib/libc/sys/brk.c @@ -31,7 +31,11 @@ #include #include -void *__sys_break(char *nsize); +int __freebsd14__brk(const void *addr); +int __freebsd14_brk(const void *addr); +void *__freebsd14_sbrk(intptr_t incr); + +void *freebsd14_break(char *nsize); static uintptr_t curbrk, minbrk; static int curbrk_initted; @@ -42,7 +46,7 @@ void *newbrk; if (!curbrk_initted) { - newbrk = __sys_break(NULL); + newbrk = freebsd14_break(NULL); if (newbrk == (void *)-1) return (-1); curbrk = minbrk = (uintptr_t)newbrk; @@ -61,7 +65,7 @@ errno = EINVAL; return ((void *)-1); } - if (__sys_break(addr) == (void *)-1) + if (freebsd14_break(addr) == (void *)-1) return ((void *)-1); oldbrk = curbrk; curbrk = (uintptr_t)addr; @@ -69,7 +73,7 @@ } int -brk(const void *addr) +__freebsd14_brk(const void *addr) { if (initbrk() == -1) @@ -78,18 +82,22 @@ addr = (void *)minbrk; return (mvbrk(__DECONST(void *, addr)) == (void *)-1 ? -1 : 0); } +__sym_compat(brk, __freebsd14_brk, FBSD_1.0); +#if defined(__amd64__) || defined(__arm__) || defined(__i386__) int -_brk(const void *addr) +__freebsd14__brk(const void *addr) { if (initbrk() == -1) return (-1); return (mvbrk(__DECONST(void *, addr)) == (void *)-1 ? -1 : 0); } +__sym_compat(_brk, __freebsd14__brk, FBSD_1.0); +#endif void * -sbrk(intptr_t incr) +__freebsd14_sbrk(intptr_t incr) { if (initbrk() == -1) @@ -102,3 +110,4 @@ } return (mvbrk((void *)(curbrk + incr))); } +__sym_compat(sbrk, __freebsd14_sbrk, FBSD_1.0); diff --git a/lib/libc/tests/sys/brk_test.c b/lib/libc/tests/sys/brk_test.c --- a/lib/libc/tests/sys/brk_test.c +++ b/lib/libc/tests/sys/brk_test.c @@ -35,6 +35,15 @@ #include +int libc_brk(const void *addr); +void *libc_sbrk(intptr_t incr); + +asm (".symver libc_brk, brk@FBSD_1.0"); +asm (".symver libc_sbrk, sbrk@FBSD_1.0"); + +#define brk libc_brk +#define sbrk libc_sbrk + ATF_TC(brk_basic); ATF_TC_HEAD(brk_basic, tc) { diff --git a/lib/libsys/_libsys.h b/lib/libsys/_libsys.h --- a/lib/libsys/_libsys.h +++ b/lib/libsys/_libsys.h @@ -77,7 +77,6 @@ typedef int (__sys_fchdir_t)(int); typedef int (__sys_chmod_t)(const char *, mode_t); typedef int (__sys_chown_t)(const char *, int, int); -typedef void * (__sys_break_t)(char *); typedef pid_t (__sys_getpid_t)(void); typedef int (__sys_mount_t)(const char *, const char *, int, void *); typedef int (__sys_unmount_t)(const char *, int); @@ -477,7 +476,6 @@ int __sys_fchdir(int fd); int __sys_chmod(const char * path, mode_t mode); int __sys_chown(const char * path, int uid, int gid); -void * __sys_break(char * nsize); pid_t __sys_getpid(void); int __sys_mount(const char * type, const char * path, int flags, void * data); int __sys_unmount(const char * path, int flags); diff --git a/lib/libsys/brk.2 b/lib/libsys/brk.2 --- a/lib/libsys/brk.2 +++ b/lib/libsys/brk.2 @@ -48,10 +48,21 @@ .Fn sbrk functions are legacy interfaces from before the advent of modern virtual memory management. -They are deprecated and not present on the arm64 or riscv architectures. +They are deprecated and no longer declared or directly linkable in the +.Lb libc +as of +.Fx 15.0 . The .Xr mmap 2 interface should be used to allocate pages instead. +.Pp +The kernel may not support the underlying system call require to +implement +.Fn brk +and +.Fn sbrk +depending on its configuration. +This is always the case on the aarch64 and riscv architectures. .Ef .Pp The diff --git a/lib/libsys/syscalls.map b/lib/libsys/syscalls.map --- a/lib/libsys/syscalls.map +++ b/lib/libsys/syscalls.map @@ -32,8 +32,6 @@ __sys_chmod; _chown; __sys_chown; - _break; - __sys_break; _getpid; __sys_getpid; _mount; diff --git a/sys/compat/freebsd32/freebsd32_syscall.h b/sys/compat/freebsd32/freebsd32_syscall.h --- a/sys/compat/freebsd32/freebsd32_syscall.h +++ b/sys/compat/freebsd32/freebsd32_syscall.h @@ -21,7 +21,7 @@ #define FREEBSD32_SYS_freebsd11_mknod 14 #define FREEBSD32_SYS_chmod 15 #define FREEBSD32_SYS_chown 16 -#define FREEBSD32_SYS_break 17 +#define FREEBSD32_SYS_freebsd14_break 17 /* 18 is freebsd4 freebsd32_getfsstat */ /* 19 is old freebsd32_lseek */ #define FREEBSD32_SYS_getpid 20 diff --git a/sys/compat/freebsd32/freebsd32_syscalls.c b/sys/compat/freebsd32/freebsd32_syscalls.c --- a/sys/compat/freebsd32/freebsd32_syscalls.c +++ b/sys/compat/freebsd32/freebsd32_syscalls.c @@ -22,7 +22,7 @@ "compat11.mknod", /* 14 = freebsd11 mknod */ "chmod", /* 15 = chmod */ "chown", /* 16 = chown */ - "break", /* 17 = break */ + "compat14.break", /* 17 = freebsd14 break */ "compat4.freebsd32_getfsstat", /* 18 = freebsd4 freebsd32_getfsstat */ "compat.freebsd32_lseek", /* 19 = old freebsd32_lseek */ "getpid", /* 20 = getpid */ diff --git a/sys/compat/freebsd32/freebsd32_sysent.c b/sys/compat/freebsd32/freebsd32_sysent.c --- a/sys/compat/freebsd32/freebsd32_sysent.c +++ b/sys/compat/freebsd32/freebsd32_sysent.c @@ -59,6 +59,12 @@ #define compat13(n, name) .sy_narg = 0, .sy_call = (sy_call_t *)nosys #endif +#ifdef COMPAT_FREEBSD14 +#define compat14(n, name) .sy_narg = n, .sy_call = (sy_call_t *)__CONCAT(freebsd14_, name) +#else +#define compat14(n, name) .sy_narg = 0, .sy_call = (sy_call_t *)nosys +#endif + /* The casts are bogus but will do for now. */ struct sysent freebsd32_sysent[] = { { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 0 = syscall */ @@ -78,7 +84,7 @@ { compat11(AS(freebsd11_mknod_args),mknod), .sy_auevent = AUE_MKNOD, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 14 = freebsd11 mknod */ { .sy_narg = AS(chmod_args), .sy_call = (sy_call_t *)sys_chmod, .sy_auevent = AUE_CHMOD, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 15 = chmod */ { .sy_narg = AS(chown_args), .sy_call = (sy_call_t *)sys_chown, .sy_auevent = AUE_CHOWN, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 16 = chown */ - { .sy_narg = AS(break_args), .sy_call = (sy_call_t *)sys_break, .sy_auevent = AUE_NULL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 17 = break */ + { compat14(AS(freebsd14_break_args),break), .sy_auevent = AUE_NULL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 17 = freebsd14 break */ { compat4(AS(freebsd4_freebsd32_getfsstat_args),freebsd32_getfsstat), .sy_auevent = AUE_GETFSSTAT, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 18 = freebsd4 freebsd32_getfsstat */ { compat(AS(ofreebsd32_lseek_args),freebsd32_lseek), .sy_auevent = AUE_LSEEK, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 19 = old freebsd32_lseek */ { .sy_narg = 0, .sy_call = (sy_call_t *)sys_getpid, .sy_auevent = AUE_GETPID, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 20 = getpid */ diff --git a/sys/compat/freebsd32/freebsd32_systrace_args.c b/sys/compat/freebsd32/freebsd32_systrace_args.c --- a/sys/compat/freebsd32/freebsd32_systrace_args.c +++ b/sys/compat/freebsd32/freebsd32_systrace_args.c @@ -122,13 +122,6 @@ *n_args = 3; break; } - /* break */ - case 17: { - struct break_args *p = params; - uarg[a++] = (intptr_t)p->nsize; /* char * */ - *n_args = 1; - break; - } /* getpid */ case 20: { *n_args = 0; @@ -3553,16 +3546,6 @@ break; }; break; - /* break */ - case 17: - switch (ndx) { - case 0: - p = "userland char *"; - break; - default: - break; - }; - break; /* getpid */ case 20: break; @@ -9201,11 +9184,6 @@ if (ndx == 0 || ndx == 1) p = "int"; break; - /* break */ - case 17: - if (ndx == 0 || ndx == 1) - p = "void *"; - break; /* getpid */ case 20: /* mount */ diff --git a/sys/kern/init_sysent.c b/sys/kern/init_sysent.c --- a/sys/kern/init_sysent.c +++ b/sys/kern/init_sysent.c @@ -58,6 +58,12 @@ #define compat13(n, name) .sy_narg = 0, .sy_call = (sy_call_t *)nosys #endif +#ifdef COMPAT_FREEBSD14 +#define compat14(n, name) .sy_narg = n, .sy_call = (sy_call_t *)__CONCAT(freebsd14_, name) +#else +#define compat14(n, name) .sy_narg = 0, .sy_call = (sy_call_t *)nosys +#endif + /* The casts are bogus but will do for now. */ struct sysent sysent[] = { { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 0 = syscall */ @@ -77,7 +83,7 @@ { compat11(AS(freebsd11_mknod_args),mknod), .sy_auevent = AUE_MKNOD, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 14 = freebsd11 mknod */ { .sy_narg = AS(chmod_args), .sy_call = (sy_call_t *)sys_chmod, .sy_auevent = AUE_CHMOD, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 15 = chmod */ { .sy_narg = AS(chown_args), .sy_call = (sy_call_t *)sys_chown, .sy_auevent = AUE_CHOWN, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 16 = chown */ - { .sy_narg = AS(break_args), .sy_call = (sy_call_t *)sys_break, .sy_auevent = AUE_NULL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 17 = break */ + { compat14(AS(freebsd14_break_args),break), .sy_auevent = AUE_NULL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 17 = freebsd14 break */ { compat4(AS(freebsd4_getfsstat_args),getfsstat), .sy_auevent = AUE_GETFSSTAT, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 18 = freebsd4 getfsstat */ { compat(AS(olseek_args),lseek), .sy_auevent = AUE_LSEEK, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 19 = old lseek */ { .sy_narg = 0, .sy_call = (sy_call_t *)sys_getpid, .sy_auevent = AUE_GETPID, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 20 = getpid */ diff --git a/sys/kern/syscalls.c b/sys/kern/syscalls.c --- a/sys/kern/syscalls.c +++ b/sys/kern/syscalls.c @@ -22,7 +22,7 @@ "compat11.mknod", /* 14 = freebsd11 mknod */ "chmod", /* 15 = chmod */ "chown", /* 16 = chown */ - "break", /* 17 = break */ + "compat14.break", /* 17 = freebsd14 break */ "compat4.getfsstat", /* 18 = freebsd4 getfsstat */ "compat.lseek", /* 19 = old lseek */ "getpid", /* 20 = getpid */ diff --git a/sys/kern/syscalls.master b/sys/kern/syscalls.master --- a/sys/kern/syscalls.master +++ b/sys/kern/syscalls.master @@ -213,7 +213,7 @@ int gid ); } -17 AUE_NULL STD|CAPENABLED { +17 AUE_NULL COMPAT14|CAPENABLED { void *break( _In_ char *nsize ); diff --git a/sys/kern/systrace_args.c b/sys/kern/systrace_args.c --- a/sys/kern/systrace_args.c +++ b/sys/kern/systrace_args.c @@ -119,13 +119,6 @@ *n_args = 3; break; } - /* break */ - case 17: { - struct break_args *p = params; - uarg[a++] = (intptr_t)p->nsize; /* char * */ - *n_args = 1; - break; - } /* getpid */ case 20: { *n_args = 0; @@ -3640,16 +3633,6 @@ break; }; break; - /* break */ - case 17: - switch (ndx) { - case 0: - p = "userland char *"; - break; - default: - break; - }; - break; /* getpid */ case 20: break; @@ -9346,11 +9329,6 @@ if (ndx == 0 || ndx == 1) p = "int"; break; - /* break */ - case 17: - if (ndx == 0 || ndx == 1) - p = "void *"; - break; /* getpid */ case 20: /* mount */ diff --git a/sys/sys/syscall.h b/sys/sys/syscall.h --- a/sys/sys/syscall.h +++ b/sys/sys/syscall.h @@ -21,7 +21,7 @@ #define SYS_freebsd11_mknod 14 #define SYS_chmod 15 #define SYS_chown 16 -#define SYS_break 17 +#define SYS_freebsd14_break 17 /* 18 is freebsd4 getfsstat */ /* 19 is old lseek */ #define SYS_getpid 20 diff --git a/sys/sys/syscall.mk b/sys/sys/syscall.mk --- a/sys/sys/syscall.mk +++ b/sys/sys/syscall.mk @@ -20,7 +20,7 @@ freebsd11_mknod.o \ chmod.o \ chown.o \ - break.o \ + freebsd14_break.o \ getpid.o \ mount.o \ unmount.o \ diff --git a/sys/sys/sysproto.h b/sys/sys/sysproto.h --- a/sys/sys/sysproto.h +++ b/sys/sys/sysproto.h @@ -85,9 +85,6 @@ char uid_l_[PADL_(int)]; int uid; char uid_r_[PADR_(int)]; char gid_l_[PADL_(int)]; int gid; char gid_r_[PADR_(int)]; }; -struct break_args { - char nsize_l_[PADL_(char *)]; char * nsize; char nsize_r_[PADR_(char *)]; -}; struct getpid_args { syscallarg_t dummy; }; @@ -1895,7 +1892,6 @@ int sys_fchdir(struct thread *, struct fchdir_args *); int sys_chmod(struct thread *, struct chmod_args *); int sys_chown(struct thread *, struct chown_args *); -int sys_break(struct thread *, struct break_args *); int sys_getpid(struct thread *, struct getpid_args *); int sys_mount(struct thread *, struct mount_args *); int sys_unmount(struct thread *, struct unmount_args *); @@ -2776,6 +2772,10 @@ #ifdef COMPAT_FREEBSD14 +struct freebsd14_break_args { + char nsize_l_[PADL_(char *)]; char * nsize; char nsize_r_[PADR_(char *)]; +}; +int freebsd14_break(struct thread *, struct freebsd14_break_args *); #endif /* COMPAT_FREEBSD14 */ @@ -2794,7 +2794,7 @@ #define SYS_AUE_freebsd11_mknod AUE_MKNOD #define SYS_AUE_chmod AUE_CHMOD #define SYS_AUE_chown AUE_CHOWN -#define SYS_AUE_break AUE_NULL +#define SYS_AUE_freebsd14_break AUE_NULL #define SYS_AUE_freebsd4_getfsstat AUE_GETFSSTAT #define SYS_AUE_olseek AUE_LSEEK #define SYS_AUE_getpid AUE_GETPID diff --git a/sys/vm/vm_unix.c b/sys/vm/vm_unix.c --- a/sys/vm/vm_unix.c +++ b/sys/vm/vm_unix.c @@ -59,13 +59,14 @@ #include #include +#ifdef COMPAT_FREEBSD14 #ifndef _SYS_SYSPROTO_H_ -struct break_args { +struct freebsd14_break_args { char *nsize; }; #endif int -sys_break(struct thread *td, struct break_args *uap) +freebsd14_break(struct thread *td, struct freebsd14_break_args *uap) { #if !defined(__aarch64__) && !defined(__riscv) uintptr_t addr; @@ -80,6 +81,7 @@ return (ENOSYS); #endif /* defined(__aarch64__) || defined(__riscv) */ } +#endif int kern_break(struct thread *td, uintptr_t *addr)