Skip to content

Commit

Permalink
Add lseek to api leak detector.
Browse files Browse the repository at this point in the history
Change-Id: Ic36a4e91072be7148b821183e73f574b0fb38f39
  • Loading branch information
yjzhang111 committed May 3, 2024
1 parent 8f58385 commit 6f655bf
Show file tree
Hide file tree
Showing 20 changed files with 180 additions and 130 deletions.
3 changes: 2 additions & 1 deletion starboard/android/shared/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@

# These POSIX tests should be disabled until asset manager starboard
# extension is implemented.
'PosixFileReadTest.ReadStaticContent',
'PosixFileGetInfoTest.WorksOnStaticContentFiles',
'PosixFileReadTest/*.ReadStaticContent',
'PosixFileSeekTest.FromEndInStaticContentWorks',

# These tests are disabled due to not receiving the kEndOfStream
Expand Down
6 changes: 1 addition & 5 deletions starboard/common/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@

#include "starboard/common/file.h"

#ifdef _WIN32
#include <sys/socket.h>
#else
#include <unistd.h>
#endif
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

#include <cstring>
#include <string>
Expand Down
4 changes: 0 additions & 4 deletions starboard/nplb/posix_compliance/posix_file_close_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if SB_API_VERSION >= 16

// close is partially tested in posix_file_open_test.cc.

#include <unistd.h>
Expand All @@ -32,5 +30,3 @@ TEST(PosixFileCloseTest, CloseInvalidFails) {
} // namespace
} // namespace nplb
} // namespace starboard

#endif // SB_API_VERSION >= 16
4 changes: 0 additions & 4 deletions starboard/nplb/posix_compliance/posix_file_get_info_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if SB_API_VERSION >= 16

#include <fcntl.h>
#include <sys/socket.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -97,5 +95,3 @@ TEST(PosixFileGetInfoTest, WorksOnStaticContentFiles) {
} // namespace
} // namespace nplb
} // namespace starboard

#endif // SB_API_VERSION >= 16
70 changes: 0 additions & 70 deletions starboard/nplb/posix_compliance/posix_file_helpers.cc

This file was deleted.

4 changes: 0 additions & 4 deletions starboard/nplb/posix_compliance/posix_file_open_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if SB_API_VERSION >= 16

#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
Expand Down Expand Up @@ -133,5 +131,3 @@ TEST(PosixFileOpenTest, OpenTruncatedDoesNotCreateNonExistingFile) {
} // namespace
} // namespace nplb
} // namespace starboard

#endif // SB_API_VERSION >= 16
4 changes: 0 additions & 4 deletions starboard/nplb/posix_compliance/posix_file_read_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if SB_API_VERSION >= 16

#include <fcntl.h>
#include <sys/socket.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -269,5 +267,3 @@ TYPED_TEST(PosixFileReadTest, ReadStaticContent) {
} // namespace
} // namespace nplb
} // namespace starboard

#endif // SB_API_VERSION >= 16
4 changes: 0 additions & 4 deletions starboard/nplb/posix_compliance/posix_file_seek_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if SB_API_VERSION >= 16

#include <fcntl.h>
#include <sys/socket.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -170,5 +168,3 @@ TEST(PosixFileSeekTest, FromEndInStaticContentWorks) {
} // namespace
} // namespace nplb
} // namespace starboard

#endif // SB_API_VERSION >= 16
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if SB_API_VERSION >= 16

#include <unistd.h>

extern "C" {
Expand All @@ -30,5 +28,3 @@ ssize_t read(int fildes, void* buf, size_t nbyte) {
return __abi_wrap_read(fildes, buf, nbyte);
}
}

#endif // SB_API_VERSION >= 16
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if SB_API_VERSION >= 16

#include "starboard/shared/modular/starboard_layer_posix_file_abi_wrappers.h"

#include <sys/types.h>
Expand All @@ -24,3 +26,5 @@ musl_off_t __abi_wrap_lseek(int fildes, musl_off_t offset, int whence) {
ssize_t __abi_wrap_read(int fildes, void* buf, size_t nbyte) {
return read(fildes, buf, nbyte);
}

#endif // SB_API_VERSION >= 16
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
// file IO functions.

// A matching type for the off_t definition in musl.

typedef int64_t musl_off_t;

#if SB_IS(ARCH_ARM64) || SB_IS(ARCH_X64)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ struct musl_stat {
};

SB_EXPORT int __abi_wrap_fstat(int fildes, struct musl_stat* info);

SB_EXPORT int __abi_wrap_stat(const char* path, struct musl_stat* info);

#ifdef __cplusplus
Expand Down
10 changes: 6 additions & 4 deletions starboard/shared/uwp/application_uwp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
#include <windows.h>
#include <windows.system.display.h>

#include <unistd.h>

#include <cstdlib>
#include <memory>
#include <string>
Expand Down Expand Up @@ -58,8 +56,10 @@
#include "starboard/shared/uwp/watchdog_log.h"
#include "starboard/shared/uwp/window_internal.h"
#include "starboard/shared/win32/thread_private.h"
#include "starboard/shared/win32/time_utils.h"
#include "starboard/shared/win32/video_decoder.h"
#include "starboard/shared/win32/wchar_utils.h"

#include "starboard/system.h"

namespace starboard {
Expand All @@ -75,6 +75,7 @@ using shared::starboard::NetLogWaitForClientConnected;
using shared::uwp::ApplicationUwp;
using shared::uwp::RunInMainThreadAsync;
using shared::uwp::WaitForResult;
using shared::win32::ConvertUsecToMillisRoundUp;
using shared::win32::platformStringToString;
using shared::win32::stringToPlatformString;
using shared::win32::wchar_tToUTF8;
Expand Down Expand Up @@ -335,7 +336,7 @@ std::string GetBinaryName() {
void OnDeviceAdded(DeviceWatcher ^, DeviceInformation ^) {
SB_LOG(INFO) << "DisplayStatusWatcher::OnDeviceAdded";
// We need delay to give time for the display initializing after connect.
usleep(15'000);
Sleep(ConvertUsecToMillisRoundUp(15'000));

MimeSupportabilityCache::GetInstance()->ClearCachedMimeSupportabilities();

Expand Down Expand Up @@ -718,7 +719,8 @@ ref class App sealed : public IFrameworkView {
std::stringstream ss;
ss << platformStringToString(
Windows::Storage::ApplicationData::Current->LocalCacheFolder->Path);
ss << "\\" << "" << command_line->GetSwitchValue(kLogPathSwitch);
ss << "\\"
<< "" << command_line->GetSwitchValue(kLogPathSwitch);
std::string full_path_log_file = ss.str();
shared::uwp::OpenLogFileWin32(full_path_log_file.c_str());
} else {
Expand Down
4 changes: 2 additions & 2 deletions starboard/shared/win32/posix_emu/include/fcntl.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#define STARBOARD_SHARED_WIN32_POSIX_EMU_INCLUDE_FCNTL_H_

#include <../ucrt/fcntl.h> // The Visual Studio version of this same file
#include <io.h> // Needed for `open`, which is in fcntl.h on POSIX
#include <sys/stat.h>
#include <../ucrt/sys/stat.h>
#include <io.h> // Needed for `open`, which is in fcntl.h on POSIX

#undef open
#undef close // in unistd.h on POSIX, and handles both files and sockets
Expand Down
10 changes: 0 additions & 10 deletions starboard/shared/win32/posix_emu/include/sys/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#ifndef STARBOARD_SHARED_WIN32_POSIX_EMU_INCLUDE_SYS_SOCKET_H_
#define STARBOARD_SHARED_WIN32_POSIX_EMU_INCLUDE_SYS_SOCKET_H_

#include <BaseTsd.h>
#include <sys/types.h>
#include <winsock2.h>
#include <ws2tcpip.h>
Expand Down Expand Up @@ -70,15 +69,6 @@ int sb_setsockopt(int socket,
int option_len);
#define setsockopt sb_setsockopt

int sb_fstat(int fd, struct stat* buffer);
#define fstat sb_fstat

int sb_lseek(int fd, off_t offset, int origin);
#define lseek sb_lseek

SSIZE_T sb_read(int fildes, void* buf, size_t nbyte);
#define read sb_read

#ifdef __cplusplus
}
#endif
Expand Down
5 changes: 5 additions & 0 deletions starboard/shared/win32/posix_emu/include/sys/stat.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <../ucrt/sys/stat.h>

#include <direct.h>
#include <sys/types.h>

#ifdef __cplusplus
extern "C" {
Expand All @@ -28,6 +29,10 @@ extern "C" {

typedef int mode_t;

// Implementation in socket.cc
int sb_fstat(int fd, struct stat* buffer);
#define fstat sb_fstat

int sb_mkdir(const char* path, mode_t mode);
#undef mkdir
#define mkdir sb_mkdir
Expand Down
13 changes: 11 additions & 2 deletions starboard/shared/win32/posix_emu/include/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,23 @@
#ifndef STARBOARD_SHARED_WIN32_POSIX_EMU_INCLUDE_UNISTD_H_
#define STARBOARD_SHARED_WIN32_POSIX_EMU_INCLUDE_UNISTD_H_

#include <starboard/types.h>

#ifdef __cplusplus
extern "C" {
#endif

// This function will handle both files and sockets. The implementation is
// located in socket.cc.
// The implementation of the following functions are located in socket.cc.

// This function will handle both files and sockets.
int close(int fd);

off_t sb_lseek(int fd, off_t offset, int origin);
#define lseek sb_lseek

ssize_t sb_read(int fildes, void* buf, size_t nbyte);
#define read sb_read

int usleep(unsigned int useconds);

#ifdef __cplusplus
Expand Down
11 changes: 5 additions & 6 deletions starboard/shared/win32/posix_emu/socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <fcntl.h>
#include <io.h> // Needed for file-specific `_close`.
#include <string.h>
#include <sys/stat.h>
#include <unistd.h> // Our version that declares generic `close`.
#include <winsock2.h>
#undef NO_ERROR // http://b/302733082#comment15
Expand Down Expand Up @@ -290,20 +289,20 @@ int close(int fd) {
return _close(handle.file);
}

int sb_lseek(int fd, off_t offset, int origin) {
off_t sb_lseek(int fd, off_t offset, int origin) {
FileOrSocket handle = handle_db_get(fd, false);
if (!handle.is_file) {
return -1;
}
return lseek(handle.file, offset, origin);
return _lseek(handle.file, offset, origin);
}

SSIZE_T sb_read(int fd, void* buf, size_t nbyte) {
ssize_t sb_read(int fd, void* buf, size_t nbyte) {
FileOrSocket handle = handle_db_get(fd, false);
if (!handle.is_file) {
return -1;
}
return read(handle.file, buf, nbyte);
return _read(handle.file, buf, nbyte);
}

int sb_bind(int socket, const struct sockaddr* address, socklen_t address_len) {
Expand Down Expand Up @@ -471,7 +470,7 @@ int sb_fstat(int fd, struct stat* buffer) {
if (!handle.is_file) {
return -1;
}
return fstat(handle.file, buffer);
return _fstat(handle.file, (struct _stat*)buffer);
}

} // extern "C"
Loading

0 comments on commit 6f655bf

Please sign in to comment.