mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-02 17:28:30 +00:00
Make minor improvements
This commit is contained in:
parent
1fc91f3580
commit
b562d6fdb3
41 changed files with 1948 additions and 92 deletions
28
libc/calls/getsid.c
Normal file
28
libc/calls/getsid.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
|
||||
/**
|
||||
* Creates session and sets the process group id.
|
||||
*/
|
||||
uint32_t getsid(int pid) {
|
||||
return getsid$sysv(pid);
|
||||
}
|
|
@ -180,8 +180,10 @@ i64 write$sysv(i32, const void *, u64) hidden;
|
|||
int getitimer$sysv(i32, struct itimerval *) hidden;
|
||||
int setresgid$sysv(uint32_t, uint32_t, uint32_t) hidden;
|
||||
int setresuid$sysv(uint32_t, uint32_t, uint32_t) hidden;
|
||||
int setsid$sysv(void) hidden;
|
||||
u32 getgid$sysv(void) hidden;
|
||||
u32 getpid$sysv(void) hidden;
|
||||
u32 getsid$sysv(int) hidden;
|
||||
u32 gettid$sysv(void) hidden;
|
||||
u32 getuid$sysv(void) hidden;
|
||||
void *mmap$sysv(void *, u64, u32, u32, i64, i64) hidden;
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
/ @see setgid(), getauxval(AT_SECURE)
|
||||
setegid:push %rbp
|
||||
mov %rsp,%rbp
|
||||
.profilable
|
||||
mov %edi,%esi
|
||||
mov $-1,%edi
|
||||
call setregid
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
/ @see setuid(), getauxval(AT_SECURE)
|
||||
seteuid:push %rbp
|
||||
mov %rsp,%rbp
|
||||
.profilable
|
||||
mov %edi,%esi
|
||||
mov $-1,%edi
|
||||
call setreuid
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
|
@ -17,8 +17,12 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
|
||||
__strncpy:
|
||||
jmp strncpy
|
||||
.endfn __strncpy,globl
|
||||
/**
|
||||
* Creates session and sets the process group id.
|
||||
*/
|
||||
int setsid(void) {
|
||||
return setsid$sysv();
|
||||
}
|
|
@ -34,20 +34,15 @@
|
|||
__sigenter:
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
push %rbx
|
||||
push %rbx
|
||||
ezlea _base,bx
|
||||
.profilable
|
||||
ezlea g_sighandrvas,ax
|
||||
and $NSIG-1,%edi
|
||||
mov (%rax,%rdi,4),%eax
|
||||
mov g_sighandrvas(,%rdi,4),%eax
|
||||
cmp $kSigactionMinRva,%eax
|
||||
jl 2f
|
||||
add %rbx,%rax
|
||||
lea _base(%rax),%eax
|
||||
call *%rax
|
||||
mov $1,%eax
|
||||
1: pop %rbx
|
||||
leave
|
||||
1: leave
|
||||
ret
|
||||
2: xor %eax,%eax
|
||||
jmp 1b
|
||||
|
|
|
@ -920,6 +920,9 @@ typedef uint64_t uintmax_t;
|
|||
#pragma GCC diagnostic ignored /* tidy */ "-Wunused-but-set-variable"
|
||||
#pragma GCC diagnostic ignored /* tidy */ "-Wunused-but-set-parameter"
|
||||
#endif /* GCC6+ */
|
||||
#if __GNUC__ >= 8
|
||||
#pragma GCC diagnostic ignored "-Wstringop-truncation"
|
||||
#endif /* GCC8+ */
|
||||
#if __GNUC__ + 0 >= 9
|
||||
#pragma GCC diagnostic ignored /* "always true" breaks dce */ "-Waddress"
|
||||
#endif /* GCC9+ */
|
||||
|
|
|
@ -17,16 +17,16 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
#include "libc/runtime/valist.h"
|
||||
|
||||
static void *__va_arg_mem(struct __va *ap, unsigned long sz, unsigned align) {
|
||||
void *r = ap->overflow_arg_area;
|
||||
if (align > 8) r = (void *)(((unsigned long)r + 15) / 16 * 16);
|
||||
ap->overflow_arg_area = (void *)(((unsigned long)r + sz + 7) / 8 * 8);
|
||||
static void *__va_arg_mem(struct __va *ap, size_t sz, size_t align) {
|
||||
void *r = (void *)ROUNDUP((intptr_t)ap->overflow_arg_area, align);
|
||||
ap->overflow_arg_area = (void *)ROUNDUP((intptr_t)r + sz, 8);
|
||||
return r;
|
||||
}
|
||||
|
||||
void *__va_arg(struct __va *ap, unsigned long sz, unsigned align, unsigned k) {
|
||||
void *__va_arg(struct __va *ap, size_t sz, unsigned align, unsigned k) {
|
||||
void *r;
|
||||
switch (k) {
|
||||
case 0:
|
||||
|
|
|
@ -4,13 +4,13 @@
|
|||
COSMOPOLITAN_C_START_
|
||||
|
||||
struct __va {
|
||||
unsigned int gp_offset;
|
||||
unsigned int fp_offset;
|
||||
uint32_t gp_offset;
|
||||
uint32_t fp_offset;
|
||||
void *overflow_arg_area;
|
||||
void *reg_save_area;
|
||||
};
|
||||
|
||||
void *__va_arg(struct __va *, unsigned long, unsigned, unsigned);
|
||||
void *__va_arg(struct __va *, size_t, unsigned, unsigned);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
|
@ -238,9 +238,6 @@ char *strsignal(int) returnsnonnull libcesque;
|
|||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
||||
|
||||
char *__strncpy(char *, const char *, size_t) memcpyesque;
|
||||
#define strncpy(DEST, SRC, N) __strncpy(DEST, SRC, N) /* pacify bad warning */
|
||||
|
||||
#define explicit_bzero(STR, BYTES) \
|
||||
do { \
|
||||
void *Str; \
|
||||
|
|
|
@ -33,10 +33,11 @@
|
|||
* @see stpncpy(), memccpy()
|
||||
* @asyncsignalsafe
|
||||
*/
|
||||
char *(strncpy)(char *dest, const char *src, size_t stride) {
|
||||
char *p;
|
||||
if ((p = memccpy(dest, src, '\0', stride))) {
|
||||
memset(p, 0, dest + stride - p);
|
||||
char *strncpy(char *dest, const char *src, size_t stride) {
|
||||
size_t i;
|
||||
for (i = 0; i < stride; ++i) {
|
||||
if (!(dest[i] = src[i])) break;
|
||||
}
|
||||
memset(dest + i, 0, stride - i);
|
||||
return dest;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,9 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/str.h"
|
||||
|
||||
/**
|
||||
* Converts character to lower case.
|
||||
*/
|
||||
int tolower(int c) {
|
||||
return 'A' <= c && c <= 'Z' ? c + ('a' - 'A') : c;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,9 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/str.h"
|
||||
|
||||
/**
|
||||
* Converts character to upper case.
|
||||
*/
|
||||
int toupper(int c) {
|
||||
return 'a' <= c && c <= 'z' ? c - ('a' - 'A') : c;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,9 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/str.h"
|
||||
|
||||
/**
|
||||
* Converts wide character to lower case.
|
||||
*/
|
||||
wint_t towlower(wint_t wc) {
|
||||
return tolower(wc);
|
||||
}
|
||||
|
|
|
@ -19,6 +19,9 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/str.h"
|
||||
|
||||
/**
|
||||
* Converts wide character to upper case.
|
||||
*/
|
||||
wint_t towupper(wint_t wc) {
|
||||
return toupper(wc);
|
||||
}
|
||||
|
|
|
@ -31,6 +31,6 @@ int wcscasecmp(const wchar_t *a, const wchar_t *b) {
|
|||
size_t i = 0;
|
||||
unsigned x, y;
|
||||
if (a == b) return 0;
|
||||
while ((x = tolower(a[i])) == (y = tolower(b[i])) && b[i]) ++i;
|
||||
while ((x = towlower(a[i])) == (y = towlower(b[i])) && b[i]) ++i;
|
||||
return x - y;
|
||||
}
|
||||
|
|
2
libc/sysv/calls/getsid-sysv.s
Normal file
2
libc/sysv/calls/getsid-sysv.s
Normal file
|
@ -0,0 +1,2 @@
|
|||
.include "o/libc/sysv/macros.inc"
|
||||
.scall getsid$sysv 0x00ff01362136007c globl hidden
|
|
@ -1,2 +0,0 @@
|
|||
.include "o/libc/sysv/macros.inc"
|
||||
.scall getsid 0x00ff01362136007c globl
|
2
libc/sysv/calls/setsid-sysv.s
Normal file
2
libc/sysv/calls/setsid-sysv.s
Normal file
|
@ -0,0 +1,2 @@
|
|||
.include "o/libc/sysv/macros.inc"
|
||||
.scall setsid$sysv 0x0093009320930070 globl hidden
|
|
@ -1,2 +0,0 @@
|
|||
.include "o/libc/sysv/macros.inc"
|
||||
.scall setsid 0x0093009320930070 globl
|
|
@ -145,8 +145,8 @@ scall 'getuid$sysv' 0x0018001820180066 globl hidden
|
|||
scall 'getgid$sysv' 0x002f002f202f0068 globl hidden
|
||||
scall 'getppid$sysv' 0x002700272027006e globl hidden
|
||||
scall getpgrp 0x005100512051006f globl
|
||||
scall setsid 0x0093009320930070 globl
|
||||
scall getsid 0x00ff01362136007c globl
|
||||
scall 'setsid$sysv' 0x0093009320930070 globl hidden
|
||||
scall 'getsid$sysv' 0x00ff01362136007c globl hidden
|
||||
scall getpgid 0x00cf00cf20970079 globl
|
||||
scall setpgid 0x005200522052006d globl
|
||||
scall geteuid 0x001900192019006b globl
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue