GithubHelp home page GithubHelp logo

vitasdk / newlib Goto Github PK

View Code? Open in Web Editor NEW
46.0 10.0 29.0 108.88 MB

PS Vita Newlib port.

License: GNU General Public License v2.0

Makefile 11.00% Shell 0.67% Batchfile 0.01% Emacs Lisp 0.04% Perl 0.27% C 73.52% C++ 8.66% Assembly 4.05% TeX 0.72% Yacc 0.01% Awk 0.01% DIGITAL Command Language 0.01% XSLT 0.01% Tcl 0.01% Mathematica 0.01% M4 0.81% GDB 0.01% Roff 0.17% Scala 0.02% RPC 0.03%

newlib's Introduction

		   README for GNU development tools

This directory contains various GNU compilers, assemblers, linkers, 
debuggers, etc., plus their support routines, definitions, and documentation.

If you are receiving this as part of a GDB release, see the file gdb/README.
If with a binutils release, see binutils/README;  if with a libg++ release,
see libg++/README, etc.  That'll give you info about this
package -- supported targets, how to use it, how to report bugs, etc.

It is now possible to automatically configure and build a variety of
tools with one command.  To build all of the tools contained herein,
run the ``configure'' script here, e.g.:

	./configure 
	make

To install them (by default in /usr/local/bin, /usr/local/lib, etc),
then do:
	make install

(If the configure script can't determine your type of computer, give it
the name as an argument, for instance ``./configure sun4''.  You can
use the script ``config.sub'' to test whether a name is recognized; if
it is, config.sub translates it to a triplet specifying CPU, vendor,
and OS.)

If you have more than one compiler on your system, it is often best to
explicitly set CC in the environment before running configure, and to
also set CC when running make.  For example (assuming sh/bash/ksh):

	CC=gcc ./configure
	make

A similar example using csh:

	setenv CC gcc
	./configure
	make

Much of the code and documentation enclosed is copyright by
the Free Software Foundation, Inc.  See the file COPYING or
COPYING.LIB in the various directories, for a description of the
GNU General Public License terms under which you can copy the files.

REPORTING BUGS: Again, see gdb/README, binutils/README, etc., for info
on where and how to report problems.

newlib's People

Contributors

amylaar avatar bonzini avatar brianinglis avatar cagney avatar d3m3vilurr avatar davek-cygwin avatar djdelorierh avatar ebblake avatar fitzsim avatar gingold-adacore avatar github-cygwin avatar haubi avatar hjl-tools avatar hpataxisdotcom avatar isage avatar jjohnstn avatar joelsherrill avatar jon-turney avatar joshuadfranklin avatar jsm28 avatar kbrow1i avatar mgeisert avatar nickclifton avatar rbtcollins avatar rsandifo avatar sebhub avatar thomasp-66 avatar tyan0 avatar vapier avatar yselkowitz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

newlib's Issues

rename() behavior isn't POSIX-y enough.

C standard (N1570 7.21.4.2) states that

The rename function causes the file whose name is the string pointed to by old to be henceforth known by the name given by the string pointed to by new. The file named old is no longer accessible by that name. If a file named by the string pointed to by new exists prior to the call to the rename function, the behavior is implementation-defined.

posix, gcc and bsd (see error ENOTEMPTY) state that if to exists, it shall be removed first, except if it is non-empty directory.

sceIoRename seems to follow MSVC implementation, e.g. fail if to exists,

Currently, this affects curl (cookie jar), but maybe other code/libs too.

Missing functionality for MegaZeux port

I have identified four missing methods for a port of the game creation system MegaZeux to the PlayStation Vita: getcwd, chdir, mkdir, rmdir. (I think they're missing, but I'm not 100% sure - perhaps 90%)

  • mkdir/rmdir: It appears that the Vita's own headers provide sufficiently equivalent functions - wrapping them would probably be feasible and not too difficult.
  • getcwd/chdir: I'm... not sure about the feasibility of these.

undefined reference to `_wait_r'

making ruby
make[1]: Entering directory '/home/silica/ruby'
arm-vita-eabi-gcc -O2 -g -Wall -Wno-parentheses -Wno-long-long  -DRUBY_EXPORT  -L.    main.o  -Wl,-R -Wl,/home/silica/ruby-bin/lib -L/home/silica/ruby-bin/lib -lruby-static -lm   -o ruby
/usr/local/vitasdk/bin/../lib/gcc/arm-vita-eabi/10.3.0/../../../../arm-vita-eabi/bin/ld: /usr/local/vitasdk/bin/../lib/gcc/arm-vita-eabi/10.3.0/../../../../arm-vita-eabi/lib/libg.a(lib_a-syswait.o): in function `wait':
syswait.c:(.text.wait+0xe): undefined reference to `_wait_r'
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:117: ruby] Error 1
make[1]: Leaving directory '/home/silica/ruby'
make: *** [Makefile:324: main] Error 2

select function in "sys/select.h" randomly crashes the app

I'm working on a homebrew that will read and download files from a http server. In the app I would check if the socket is open and still readable before trying to read from it. The app would randomly crash on the "select" function.

Here's the code sniplet of that function.

template <typename T> ssize_t handle_EINTR(T fn) {
  ssize_t res = false;
  while (true) {
    res = fn();
    if (res < 0 && errno == EINTR) { continue; }
    break;
  }
  return res;
}

ssize_t select_read(socket_t sock, time_t sec, time_t usec) {
  if (sock >= FD_SETSIZE) { return 1; }

  fd_set fds;
  FD_ZERO(&fds);
  FD_SET(sock, &fds);

  timeval tv;
  tv.tv_sec = static_cast<long>(sec);
  tv.tv_usec = static_cast<decltype(tv.tv_usec)>(usec);

  return handle_EINTR([&]() {
    return select(static_cast<int>(sock + 1), &fds, nullptr, nullptr, &tv);  <<< crash on this line randomly
  });
}

List of missing POSIX functions

Documentation

  • openlog - store log flags, set bool value to un-noop syslog
  • setlogmask - store log mask
  • syslog - implement with printf
  • closelog - since syslog is printf, just set bool value to noop syslog

  • aio_cancel
  • aio_error
  • aio_fsync
  • aio_read
  • aio_return
  • aio_suspend
  • aio_write
  • lio_listio

  • alarm

  • catclose -- implement via libintl, like linux?
  • catgets
  • catopen

  • cfgetispeed - requires termios, ENOTSUP
  • cfgetospeed
  • cfsetispeed
  • cfsetospeed

  • clock_getcpuclockid - no idea. optional
  • clock_nanosleep - implement using either delay or scekernelCreateTimer

  • confstr - like sysconf
  • ctermid - return tty0: ?

  • daylight - variable, not func.


  • dup2 - see dup, and docs

  • endhostent
  • endnetent
  • endprotoent
  • endpwent
  • endservent

  • execle - sceAppmgrLoadExec. but we can't keep alarm(), etc.
  • execl
  • execlp
  • execvp
  • fexecve

  • faccessat - add custom cwd support to __realpath. rename and implement at-support in current non-at funcs, then proxy them to at-variant with AT_FDCWD for fd
  • fchmodat
  • fstatat
  • linkat
  • mkdirat
  • openat
  • readlinkat
  • renameat
  • unlinkat
  • utimensat

  • fattach - stub. we have no stream devices
  • fdetach

  • flockfile - implement with Lw mutexes? newlib seems to provide locking internally
  • ftrylockfile
  • funlockfile

  • fchown

  • fmtmsg

  • fnmatch - copy/port from posix
  • globfree
  • glob
  • ftw
  • nftw

  • ftok

  • getdate_err
  • getdate - copy from posix

  • getgrgid_r - stub
  • getgrnam_r - stub

  • gethostent
  • gethostid
  • gethostname

  • getitimer

  • getlogin
  • getlogin_r

  • getmsg

  • getnameinfo
  • getnetbyaddr
  • getnetbyname
  • getnetent

  • getpgrp
  • getpmsg
  • getppid
  • getprotobyname
  • getprotobynumber
  • getprotoent
  • getpwent
  • getpwnam
  • getpwnam_r
  • getpwuid
  • getpwuid_r
  • getservbyport
  • getservent

  • getutxent - no user account db. ENOTSUP
  • getutxid
  • getutxline
  • endutxent
  • pututxline
  • setutxent

  • grantpt - ???

  • if_freenameindex
  • if_indextoname
  • if_nameindex
  • if_nametoindex

  • initstate - inits random state. somehow it's missing from newlib?
  • setstate - same

  • insque - copy from posix?
  • remque

  • ioctl - stub?
  • isastream - stub, no streams

  • killpg - stub

  • lchown - alias to chown

  • lfind - copy from posix
  • lsearch

  • lockf

  • mkfifoat - via pipe?
  • mkfifo
  • mknodat - to fifo, otherwise EINVAL
  • mknod

  • mlockall - mmap impl
  • mlock
  • mmap
  • mprotect
  • msync
  • munlockall
  • munlock
  • munmap

  • mq_close - message queue. via messegepipe?
  • mq_getattr
  • mq_notify
  • mq_open
  • mq_receive
  • mq_send
  • mq_setattr
  • mq_timedreceive
  • mq_timedsend
  • mq_unlink

  • msgctl - ipc. ENOSUP?
  • msgget
  • msgrcv
  • msgsnd

  • nice - ENOSUP or always success

  • optarg - copy from posix, with getopt
  • opterr
  • optind
  • optopt

  • pause - either wait for event, or ENOTSUP

  • pclose - ENOTSUP
  • popen - ENOTSUP

  • pselect - rename select to pselect, implement signal catching, proxy select to it

  • psiginfo

  • ptsname - ENOTSUP?

  • putmsg - no streams support, ENOTSUP
  • putpmsg - no streams support, ENOTSUP

  • readv - see #66
  • writev

  • regcomp - regex. copy from posix?
  • regerror
  • regexec
  • regfree

  • sethostent

  • setitimer

  • setkey - crypt/encrypt, XSI_VISIBLE

  • setnetent
  • setprotoent
  • setpwent
  • setservent

  • shmat - shared mem. ENOTSUP
  • shmctl
  • shmdt
  • shmget
  • shm_open
  • shm_unlink

  • sigaction - implement signals via events?
  • sigaddset
  • sigaltstack
  • sigdelset
  • sigemptyset
  • sigfillset
  • sighold
  • sigignore
  • siginterrupt
  • sigismember
  • siglongjmp
  • sigpause
  • sigpending
  • sigprocmask
  • sigqueue
  • sigrelse
  • sigset
  • sigsetjmp
  • sigsuspend
  • sigtimedwait
  • sigwait
  • sigwaitinfo

  • sockatmark
  • socketpair

  • symlinkat - ENOTSUP
  • symlink

  • tcdrain - termios. ENOTSUP
  • tcflow
  • tcflush
  • tcgetattr
  • tcgetpgrp
  • tcgetsid
  • tcsendbreak
  • tcsetattr
  • tcsetpgrp

  • timezone

  • ttyname - tty0:?
  • ttyname_r

  • tzname

  • ulimit - to setrlimit

  • umask

  • unlockpt


  • waitid - ENOTSUP
  • waitpid - ENOTSUP

  • wordexp
  • wordfree

Most of those are probably a no-go completely

  • posix_fadvise
  • posix_fallocate

  • posix_madvise
  • posix_memalign
  • posix_mem_offset

  • posix_openpt

  • posix_spawnattr_destroy
  • posix_spawnattr_getflags
  • posix_spawnattr_getpgroup
  • posix_spawnattr_getschedparam
  • posix_spawnattr_getschedpolicy
  • posix_spawnattr_getsigdefault
  • posix_spawnattr_getsigmask
  • posix_spawnattr_init
  • posix_spawnattr_setflags
  • posix_spawnattr_setpgroup
  • posix_spawnattr_setschedparam
  • posix_spawnattr_setschedpolicy
  • posix_spawnattr_setsigdefault
  • posix_spawnattr_setsigmask

  • posix_spawn_file_actions_addclose
  • posix_spawn_file_actions_adddup2
  • posix_spawn_file_actions_addopen
  • posix_spawn_file_actions_destroy
  • posix_spawn_file_actions_init
  • posix_spawn
  • posix_spawnp

  • posix_trace_attr_destroy
  • posix_trace_attr_getclockres
  • posix_trace_attr_getcreatetime
  • posix_trace_attr_getgenversion
  • posix_trace_attr_getinherited
  • posix_trace_attr_getlogfullpolicy
  • posix_trace_attr_getlogsize
  • posix_trace_attr_getmaxdatasize
  • posix_trace_attr_getmaxsystemeventsize
  • posix_trace_attr_getmaxusereventsize
  • posix_trace_attr_getname
  • posix_trace_attr_getstreamfullpolicy
  • posix_trace_attr_getstreamsize
  • posix_trace_attr_init
  • posix_trace_attr_setinherited
  • posix_trace_attr_setlogfullpolicy
  • posix_trace_attr_setlogsize
  • posix_trace_attr_setmaxdatasize
  • posix_trace_attr_setname
  • posix_trace_attr_setstreamfullpolicy
  • posix_trace_attr_setstreamsize
  • posix_trace_clear
  • posix_trace_close
  • posix_trace_create
  • posix_trace_create_withlog
  • posix_trace_event
  • posix_trace_eventid_equal
  • posix_trace_eventid_get_name
  • posix_trace_eventid_open
  • posix_trace_eventset_add
  • posix_trace_eventset_del
  • posix_trace_eventset_empty
  • posix_trace_eventset_fill
  • posix_trace_eventset_ismember
  • posix_trace_eventtypelist_getnext_id
  • posix_trace_eventtypelist_rewind
  • posix_trace_flush
  • posix_trace_get_attr
  • posix_trace_get_filter
  • posix_trace_getnext_event
  • posix_trace_get_status
  • posix_trace_open
  • posix_trace_rewind
  • posix_trace_set_filter
  • posix_trace_shutdown
  • posix_trace_start
  • posix_trace_stop
  • posix_trace_timedgetnext_event
  • posix_trace_trid_eventid_open
  • posix_trace_trygetnext_event

  • posix_typed_mem_get_info
  • posix_typed_mem_open

mktime() uses UTC instead of local timezone

mktime() is supposed to use the local timezone, whereas the UTC equivalent is supposed to be gmtime(). However, since there is no TZ environment variable set up in the environment, mktime() winds up using UTC instead of the local time zone. This is the root cause of mgba-emu/mgba#2876, which I worked around in mgba-emu/mgba@e8ef801. A similar implementation may be plausible in newlib.

Make exceptions work

Relevant parts from the IRC:

<noname120> Why are exceptions not supported in vitasdk? Is is especially hard to implement?
<davee[m]> i think there is just special data structures that need set
<davee[m]> eh_frame i think
<noname120> Interesting stuff: http://wiki.osdev.org/C++_Exception_Support
<xyz[m]> no one cared enough to implement it
<xyz[m]> maybe it already works fine
<davee[m]> it doesnt
<xyz[m]> it shouldn't require anything OS specific
<xyz[m]> maybe our toolchain garbles some sections

Very slow IO since newlib commit 33507633

Since the mentioned commit (which is from September 2016) operations on file descriptors are extremely slow. This gives a significant slowdown e.g. in EasyRPG Player which was running 60 FPS before and regressed to 0-15 FPS depending on the game. (we noticed this two months ago because that was the time when we recompiled the SDK, we were on August 2016 before).

My bisect says that the first bad/slow commit is
fa92db8
The previous one didn't compile, which is very likely the real bad commit:
3350763
(And the last good/fast commit is 6a4dc0f)

Test case (thanks to @Rinnegatamante because I don't have a Vita)

You have to create a 100 kbyte file under "/data/test.bin". The content doesn't matter.
The test program does lots of 1byte fread calls. I have no idea what the real cause is, but the IO is slow ;).
In the end the program will tell you how long the newlib IO took. On newer (since that commit) newlib versions the result is around 2 seconds and on older version around 80 ms. This is a significant regression:

#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <vitasdk.h>
#include <vita2d.h> 

#define FILENAME "ux0:/data/test.bin"

vita2d_pgf* debug_font;
void drawText(uint32_t y, char* text, uint32_t color){
	int i;
	for (i=0;i<3;i++){
		vita2d_start_drawing();
		vita2d_pgf_draw_text(debug_font, 2, y, color, 1.0, text	);
		vita2d_end_drawing();

		vita2d_wait_rendering_done();
		vita2d_swap_buffers();
	}
}

void drawLoopText(uint32_t y, char* text, uint32_t color){
	vita2d_pgf_draw_text(debug_font, 2, y, color, 1.0, text	);
}

int main(int argc, char** argp){
	char res[256];
	uint64_t tick1, tick2;

	vita2d_init();
	vita2d_set_clear_color(RGBA8(0x00, 0x00, 0x00, 0xFF));
	debug_font = vita2d_load_default_pgf();
	uint32_t white = RGBA8(0xFF, 0xFF, 0xFF, 0xFF);

	drawText(25, "Starting SceIo test, please wait...", white);
	tick1 = sceKernelGetProcessTimeWide();
	SceUID fh = sceIoOpen(FILENAME, SCE_O_RDONLY, 0777);
	SceOff size = sceIoLseek(fh, 0, SEEK_END);
	sceIoLseek(fh, 0, SEEK_SET);

	uint8_t dummy;
	int i;
	for (i = 0; i < size; i++){
		sceIoRead(fh, &dummy, 1);
	}
	sceIoClose(fh);

	tick2 = sceKernelGetProcessTimeWide();
	sprintf(res, "Test took %lldms to finish.", (tick2 - tick1) / 1000);
	drawText(45, res, white);
	drawText(65, "Starting newlib io test, please wait...", white);

	tick1 = sceKernelGetProcessTimeWide();
	FILE* fd = fopen(FILENAME, "rb");
	for (i = 0; i < size; i++){
		fread(&dummy, 1, 1, fd);
	}
	fclose(fd);

	tick2 = sceKernelGetProcessTimeWide();
	sprintf(res, "Test took %lldms to finish.", (tick2 - tick1) / 1000);
	drawText(85, res, white);

	for (;;){}
}

Makefile, put main.c in "source":

TARGET		:= Testcase
TITLE		:= TESTCASE1
SOURCES		:= source
INCLUDES	:= include

LIBS = -lvita2d -lSceLibKernel_stub \
	-lSceSysmodule_stub -lSceCtrl_stub \
	-lm -lSceAppUtil_stub -lScePgf_stub -lfreetype \
	-lc -lScePower_stub -lSceCommonDialog_stub -lpng16 -lz \
	-lSceGxm_stub -lSceDisplay_stub 

CFILES   := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c))
CPPFILES   := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.cpp))
BINFILES := $(foreach dir,$(DATA), $(wildcard $(dir)/*.bin))
OBJS     := $(addsuffix .o,$(BINFILES)) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 

PREFIX  = arm-vita-eabi
CC      = $(PREFIX)-gcc
CXX      = $(PREFIX)-g++
CFLAGS  = -Wl,-q -O3 -Wall
CXXFLAGS  = $(CFLAGS) -fno-exceptions -std=gnu++11
ASFLAGS = $(CFLAGS)

all: $(TARGET).vpk

$(TARGET).vpk: $(TARGET).velf
	vita-make-fself $< .\build\eboot.bin
	vita-mksfoex -s TITLE_ID=$(TITLE) "$(TARGET)" param.sfo
	cp -f param.sfo ./build/sce_sys/param.sfo

%.velf: %.elf
	$(PREFIX)-strip -g $<
	vita-elf-create $< $@
	vita-make-fself $@ eboot.bin

$(TARGET).elf: $(OBJS)
	$(CC) $(CFLAGS) $^ $(LIBS) -o $@

clean:
	@rm -rf $(TARGET).velf $(TARGET).elf $(OBJS)

socket errno codes are wrong

This is because sony errno does not match errno.h

For example,

sys/errno.h
41:#define	EAGAIN 11	/* No more processes */

psp2/net/net.h
50:	SCE_NET_ERROR_EAGAIN					= 0x80410123,
171:	SCE_NET_EAGAIN				= 35,

recvfrom does:

		errno = res & SCE_ERRNO_MASK;

which would result in error code 35 for SCE_NET_EAGAIN.

Automatically call pthread_init on main thread.

If developers are using the c++11 std::thread class then it will crash when invoking the underlying pthread implementation. This is because the starting thread does not have the correct context information setup in its TLS.
There should be some mechanism in place to automatically call pthread_init on the main thread prior to main() when pthread is linked.

Automatically clean up reent resources on native thread

pthreads will automatically clean up thread reent data when threads are closed. Developers favouring the native API over pthreads may run into a situation where there are no reent resources available to allocate and the application crashes/aborts.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.