Remove code that doesn't work

This commit is contained in:
Jarred Sumner
2022-08-28 21:46:47 -07:00
parent c1734c6ec5
commit d7dbe6f329
12 changed files with 41 additions and 632 deletions

1
.gitignore vendored
View File

@@ -103,3 +103,4 @@ src/runtime.version
*.sqlite
*.database
*.db
misctools/machbench

View File

@@ -3879,7 +3879,7 @@ pub const ExternalStringImpl = extern struct {
pub const JSArray = struct {
pub fn from(globalThis: *JSGlobalObject, arguments: []const JSC.JSValue) JSValue {
return JSC.JSValue.c(JSC.C.JSObjectMakeArray(globalThis.ref(), arguments.len, @ptrCast([*]const JSC.C.JSObjectRef, arguments.ptr), null));
return JSC.JSValue.c(JSC.C.JSObjectMakeArray(globalThis.ref(), arguments.len, @ptrCast(?[*]const JSC.C.JSObjectRef, arguments.ptr), null));
}
};

View File

@@ -1,249 +0,0 @@
#include "mimalloc.h"
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cstddef>
#include <unistd.h>
#ifdef __APPLE__
#include <dlfcn.h>
#include <mach/mach.h>
#include <sys/resource.h>
#include <sys/sysctl.h>
#endif
#include "cpuinfo.h"
#define free mi_free
#define malloc mi_malloc
#define realloc mi_realloc
#define strdup mi_strdup
#ifdef __linux__
extern "C" CpuInfo* getCpuInfo()
{
CpuInfo* cores = (CpuInfo*)malloc(sizeof(CpuInfo));
FILE* file = fopen("/proc/cpuinfo", "r");
if (file == NULL)
return NULL;
char buff[2048];
int coresIndex = -1;
memset(cores, 0, sizeof(CpuInfo));
while (fgets(buff, 2048, file)) {
if (strlen(buff) == 0)
continue;
short columnSplit = 0;
for (int i = 0; i < (int)strlen(buff); i++) {
if (buff[i] == ':') {
columnSplit = i;
break;
}
}
char* columnName = strndup(buff, columnSplit);
if (columnName == NULL)
return NULL;
if (!strncmp("processor", columnName, strlen("processor"))) {
coresIndex++;
if (coresIndex > 0) {
cores = (CpuInfo*)realloc(cores, (coresIndex + 1) * sizeof(CpuInfo));
if (cores == NULL)
return NULL;
}
#ifdef __PPC__
} else if (!strncmp("cpu", columnName, 3)) {
#else
} else if (!strncmp("model name", columnName, strlen("model name"))) {
#endif
cores[coresIndex].manufacturer = strndup((buff + columnSplit + 2), strlen(buff) - 3 - columnSplit);
if (cores[coresIndex].manufacturer == NULL)
return NULL;
#ifdef __PPC__
} else if (!strncmp("clock", columnName, strlen("clock"))) {
#else
} else if (!strncmp("cpu MHz", columnName, strlen("cpu MHz"))) {
#endif
char* columnData = strndup((buff + columnSplit + 2), strlen(buff) - 3 - columnSplit);
if (columnData == NULL)
return NULL;
cores[coresIndex].clockSpeed = atof(columnData);
free(columnData);
}
free(columnName);
}
coresIndex++;
cores = (CpuInfo*)realloc(cores, (coresIndex + 1) * sizeof(CpuInfo));
if (cores == NULL)
return NULL;
cores[coresIndex] = (CpuInfo) { NULL, 0, 0, 0, 0, 0, 0, 0 };
fclose(file);
return cores;
}
#elif __APPLE__
extern "C" CpuInfo* getCpuInfo()
{
unsigned int ticks = (unsigned int)sysconf(_SC_CLK_TCK), multiplier = ((uint64_t)1000L / ticks);
char model[512];
unsigned int freq;
int mib[] = { CTL_HW, HW_CPU_FREQ };
size_t freqSize = sizeof(freq);
sysctl(mib, 2, &freq, &freqSize, NULL, 0);
size_t size;
unsigned int i;
natural_t numcpus = 0;
mach_msg_type_number_t msg_type;
processor_cpu_load_info_data_t* info;
CpuInfo* cores;
size = sizeof(model);
if (sysctlbyname("machdep.cpu.brand_string", model, &size, NULL, 0) && sysctlbyname("hw.model", model, &size, NULL, 0)) {
return NULL;
}
if (host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &numcpus,
(processor_info_array_t*)&info,
&msg_type)
!= KERN_SUCCESS) {
return NULL;
}
freq = freq / 1000000; // Hz to MHz
cores = (CpuInfo*)malloc(sizeof(CpuInfo) * numcpus);
if (cores == NULL)
return NULL;
memset(cores, 0, sizeof(CpuInfo) * numcpus);
for (i = 0; i < numcpus; i++) {
cores[i].manufacturer = (char*)malloc(strlen(model) + 1);
if (cores[i].manufacturer == NULL)
return NULL;
memcpy(cores[i].manufacturer, &model, strlen(model));
cores[i].manufacturer[strlen(model)] = '\0';
cores[i].clockSpeed = freq;
cores[i].userTime = info[i].cpu_ticks[0] * multiplier;
cores[i].niceTime = info[i].cpu_ticks[3] * multiplier;
cores[i].systemTime = info[i].cpu_ticks[1] * multiplier;
cores[i].idleTime = info[i].cpu_ticks[2] * multiplier;
cores[i].iowaitTime = 0;
cores[i].irqTime = 0;
}
cores[numcpus] = (CpuInfo) { NULL, 0, 0, 0, 0, 0, 0, 0 };
return cores;
}
#endif
extern "C" CpuInfo* getCpuTime()
{
CpuInfo* cores = (CpuInfo*)malloc(sizeof(CpuInfo));
FILE* file = fopen("/proc/stat", "r");
if (file == NULL)
return NULL;
char buff[2048];
int coresIndex = -1;
int j = 0;
while (fgets(buff, 2048, file)) {
char* name = strndup(buff, 3);
if (name == NULL)
return NULL;
if (!strncmp("cpu", name, 3) && isdigit(buff[3])) {
coresIndex++;
if (coresIndex > 0) {
cores = (CpuInfo*)realloc(cores, (coresIndex + 1) * sizeof(CpuInfo));
if (cores == NULL)
return NULL;
}
int space;
for (int i = 0; i < (int)strlen(buff); i++) {
if (buff[i] == ' ') {
space = i;
break;
}
}
char* cpuDataStart = strndup((buff + space + 1), strlen(buff));
if (cpuDataStart == NULL)
return NULL;
char* cpuData = cpuDataStart;
// Time to be smart, What I am about to do is dangerous.
char* temp = (char*)&cores[coresIndex];
size_t start = offsetof(CpuInfo, userTime); // getting offset from `userTime` member.
temp = temp + start;
j = 0;
for (int i = 0; i < 6; i++, j++) {
cpuData = (cpuData + j); // offseting string.
for (j = 0; cpuData[j] != ' '; j++)
;
char* parseStr = strndup(cpuData, j);
if (parseStr == NULL)
return NULL;
*(int*)temp = atoi(parseStr);
free(parseStr);
temp = temp + sizeof(int); // switching to next int member.
}
free(cpuDataStart);
}
free(name);
}
coresIndex++;
cores = (CpuInfo*)realloc(cores, (coresIndex + 1) * sizeof(CpuInfo));
if (cores == NULL)
return NULL;
cores[coresIndex] = (CpuInfo) { NULL, 0, 0, 0, 0, 0, 0, 0 };
fclose(file);
return cores;
}
extern "C" CpuInfo* getCpuInfoAndTime()
{
#ifdef __APPLE__
CpuInfo* arr = getCpuInfo();
if (arr == NULL)
return (CpuInfo*)malloc(sizeof(CpuInfo));
return arr;
#elif __linux__
CpuInfo* arr = getCpuInfo();
if (arr == NULL)
return NULL;
CpuInfo* arr2 = getCpuTime();
if (arr2 == NULL)
return NULL;
for (int i = 0; arr[i].manufacturer; i++) {
arr2[i].manufacturer = arr[i].manufacturer;
arr2[i].clockSpeed = arr[i].clockSpeed;
}
free(arr);
return arr2;
#endif
}
extern "C" int getCpuArrayLen(CpuInfo* arr)
{
int i = 0;
for (; arr[i].manufacturer; i++)
;
return i - 1;
}
extern "C" void freeCpuInfoArray(CpuInfo* arr, int len)
{
for (int i = 0; i < len; i++) {
free(arr[i].manufacturer);
}
free(arr);
}

View File

@@ -1,23 +0,0 @@
#ifndef CPU_INFO_LIB
#define CPU_INFO_LIB
extern "C" {
typedef struct {
char *manufacturer;
float clockSpeed;
int userTime;
int niceTime;
int systemTime;
int idleTime;
int iowaitTime;
int irqTime;
} CpuInfo;
CpuInfo *getCpuInfo();
CpuInfo *getCpuTime();
CpuInfo *getCpuInfoAndTime();
int getCpuArrayLen(CpuInfo *arr);
void freeCpuInfoArray(CpuInfo *arr, int len);
}
#endif

View File

@@ -1,178 +0,0 @@
#include "mimalloc.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <ifaddrs.h>
#include <arpa/inet.h>
#define free mi_free
#define malloc mi_malloc
#define realloc mi_realloc
#define strdup mi_strdup
#ifdef __linux__
#include <netpacket/packet.h>
#include <net/ethernet.h>
#else
#include <net/if_dl.h>
#endif
#include "interface_addresses.h"
extern "C" uint32_t getBitCountFromIPv4Mask(uint32_t mask) {
return __builtin_popcount(mask);
}
extern "C" uint32_t getBitCountFromIPv6Mask(const in6_addr &mask) {
uint32_t bitCount = 0;
// uint32 version is unsupported on some platforms
for (size_t ii = 0; ii < 16; ii++) {
bitCount += __builtin_popcount(mask.s6_addr[ii]);
}
return bitCount;
}
extern "C" NetworkInterface *getNetworkInterfaces() {
NetworkInterface *interfaces = (NetworkInterface*) malloc(sizeof(NetworkInterface));
if (interfaces == NULL) return NULL;
short interfacesIndex = -1;
struct ifaddrs *ifap, *ifa;
unsigned char *ptr;
getifaddrs(&ifap);
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
if (ifa->ifa_addr && ifa->ifa_addr->sa_family==AF_INET) {
struct sockaddr_in *sa = (struct sockaddr_in *) ifa->ifa_addr;
char addr[INET_ADDRSTRLEN];
inet_ntop(AF_INET, &(sa->sin_addr), addr, sizeof(addr));
char netmask[INET_ADDRSTRLEN];
inet_ntop(AF_INET, &(((struct sockaddr_in *) ifa->ifa_netmask)->sin_addr), netmask, sizeof(netmask));
char *interface_name = ifa->ifa_name;
interfacesIndex++;
if (interfacesIndex > 0) {
interfaces = (NetworkInterface*) realloc(interfaces, (interfacesIndex+1) * sizeof(NetworkInterface));
if (interfaces == NULL) return NULL;
}
interfaces[interfacesIndex].address = strdup(addr);
if (interfaces[interfacesIndex].address == NULL) return NULL;
interfaces[interfacesIndex].netmask = strdup(netmask);
if (interfaces[interfacesIndex].netmask == NULL) return NULL;
interfaces[interfacesIndex].interface = strdup(interface_name);
if (interfaces[interfacesIndex].interface == NULL) return NULL;
interfaces[interfacesIndex].family = (char*) malloc(strlen("IPv4")+1);
memcpy(interfaces[interfacesIndex].family, "IPv4", strlen("IPv4"));
interfaces[interfacesIndex].family[strlen("IPv4")] = '\0';
interfaces[interfacesIndex].cidr = getBitCountFromIPv4Mask(((struct sockaddr_in *) ifa->ifa_netmask)->sin_addr.s_addr);
interfaces[interfacesIndex].internal = !!(ifa->ifa_flags & 0x8);
} else if (ifa->ifa_addr && ifa->ifa_addr->sa_family==AF_INET6) {
struct sockaddr_in6 *sa = (struct sockaddr_in6 *) ifa->ifa_addr;
char addr[INET6_ADDRSTRLEN];
inet_ntop(AF_INET6, &(sa->sin6_addr), addr, sizeof(addr));
char netmask[INET6_ADDRSTRLEN];
inet_ntop(AF_INET6, &(((struct sockaddr_in6 *) ifa->ifa_netmask)->sin6_addr), netmask, sizeof(netmask));
char *interface_name = ifa->ifa_name;
interfacesIndex++;
if (interfacesIndex > 0) {
interfaces = (NetworkInterface*) realloc(interfaces, (interfacesIndex+1) * sizeof(NetworkInterface));
if (interfaces == NULL) return NULL;
}
interfaces[interfacesIndex].address = strdup(addr);
if (interfaces[interfacesIndex].address == NULL) return NULL;
interfaces[interfacesIndex].netmask = strdup(netmask);
if (interfaces[interfacesIndex].netmask == NULL) return NULL;
interfaces[interfacesIndex].interface = interface_name;
if (interfaces[interfacesIndex].interface == NULL) return NULL;
interfaces[interfacesIndex].family = (char*) malloc(strlen("IPv6")+1);
memcpy(interfaces[interfacesIndex].family, "IPv6", strlen("IPv6"));
interfaces[interfacesIndex].family[strlen("IPv6")] = '\0';
interfaces[interfacesIndex].cidr = getBitCountFromIPv6Mask(sa->sin6_addr);
interfaces[interfacesIndex].scopeid = sa->sin6_scope_id;
interfaces[interfacesIndex].internal = !!(ifa->ifa_flags & 0x8);
}
}
interfacesIndex++;
interfaces = (NetworkInterface*) realloc(interfaces, (interfacesIndex+1) * sizeof(NetworkInterface));
if (interfaces == NULL) return NULL;
interfaces[interfacesIndex] = (NetworkInterface) {NULL, NULL, NULL, NULL, NULL, 0};
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
#ifdef __linux__
if (ifa->ifa_addr && ifa->ifa_addr->sa_family==AF_PACKET) {
char macp[INET6_ADDRSTRLEN];
struct sockaddr_ll *s = (struct sockaddr_ll *) ifa->ifa_addr;
int i;
int len = 0;
for (i = 0; i < 6; i++) {
len += sprintf(macp+len, "%02X%s", s->sll_addr[i], i < 5 ? ":":"");
}
i = 0;
int arrLength = getNetworkInterfaceArrayLen(interfaces);
for (; i < arrLength; i++) {
if (strcmp(interfaces[i].interface, (ifa)->ifa_name) == 0) {
interfaces[i].mac = strdup(macp);
if (interfaces[i].mac == NULL) return NULL;
}
}
}
#else
if (ifa->ifa_addr && ifa->ifa_addr->sa_family==AF_LINK) {
char macp[18];
ptr = (unsigned char *)LLADDR((struct sockaddr_dl *)(ifa)->ifa_addr);
sprintf(macp, "%02x:%02x:%02x:%02x:%02x:%02x", *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5));
int arrLength = getNetworkInterfaceArrayLen(interfaces);
for (int i = 0; i < arrLength; i++) {
if (strcmp(interfaces[i].interface, (ifa)->ifa_name) == 0) {
interfaces[i].mac = strdup(macp);
if (interfaces[i].mac == NULL) return NULL;
}
}
}
#endif
}
freeifaddrs(ifap);
return interfaces;
}
extern "C" int getNetworkInterfaceArrayLen(NetworkInterface *arr) {
int i = 0;
for (; arr[i].address != NULL; i++);
return i;
}
extern "C" void freeNetworkInterfaceArray(NetworkInterface *arr, int len)
{
for (int i = 0; i < len; i++) {
free(arr[i].address);
free(arr[i].family);
free(arr[i].interface);
free(arr[i].mac);
free(arr[i].netmask);
}
free(arr);
}

View File

@@ -1,24 +0,0 @@
#ifndef INTERFACE_ADDRESSES_LIB
#define INTERFACE_ADDRESSES_LIB
#include <stdint.h>
extern "C" {
typedef struct {
char *interface;
char *address;
char *netmask;
char *family;
char *mac;
int cidr;
uint32_t scopeid;
int internal;
} NetworkInterface;
NetworkInterface *getNetworkInterfaces();
int getNetworkInterfaceArrayLen(NetworkInterface *arr);
void freeNetworkInterfaceArray(NetworkInterface *arr, int len);
}
#endif

View File

@@ -1,27 +0,0 @@
#include "system_memory.h"
#include <stdint.h>
#if __APPLE__
#include <mach/mach.h>
#include <sys/resource.h>
#include <sys/sysctl.h>
#include <unistd.h>
extern "C" uint64_t getFreeMemoryDarwin_B() {
vm_statistics_data_t info;
mach_msg_type_number_t count = sizeof(info) / sizeof(integer_t);
if (host_statistics(mach_host_self(), HOST_VM_INFO,
(host_info_t)&info, &count) != KERN_SUCCESS) {
return 0;
}
return (uint64_t) info.free_count * sysconf(_SC_PAGESIZE);
}
#else
// Implemented in zig
extern "C" uint64_t getFreeMemoryDarwin_B() {
return (uint64_t) 0;
}
#endif

View File

@@ -1,10 +0,0 @@
#ifndef SYSTEM_MEMORY_LIB
#define SYSTEM_MEMORY_LIB
#include <stdint.h>
extern "C" {
uint64_t getFreeMemoryDarwin_B();
}
#endif

View File

@@ -11,37 +11,6 @@ const is_bindgen: bool = std.meta.globalOption("bindgen", bool) orelse false;
const heap_allocator = bun.default_allocator;
const constants = @import("./os/constants.zig");
// From C ; bindings/node_os/
pub const struct_InterfaceAddresses = extern struct {
interface: [*c]u8,
address: [*c]u8,
netmask: [*c]u8,
family: [*c]u8,
mac: [*c]u8,
cidr: c_int,
scopeid: u32,
internal: c_int,
};
pub extern fn getNetworkInterfaces() [*c]struct_InterfaceAddresses;
pub extern fn getNetworkInterfaceArrayLen(arr: [*c]struct_InterfaceAddresses) usize;
extern fn freeNetworkInterfaceArray(arr: [*c]struct_InterfaceAddresses, len: c_int) void;
pub const struct_CpuInfo = extern struct {
manufacturer: [*c]u8,
clockSpeed: f32,
userTime: c_int,
niceTime: c_int,
systemTime: c_int,
idleTime: c_int,
iowaitTime: c_int,
irqTime: c_int,
};
extern fn getCpuInfo() [*c]struct_CpuInfo;
extern fn getCpuTime() [*c]struct_CpuInfo;
extern fn getCpuInfoAndTime() [*c]struct_CpuInfo;
extern fn getCpuArrayLen(arr: [*c]struct_CpuInfo) usize;
extern fn freeCpuInfoArray(arr: [*c]struct_CpuInfo, len: c_int) void;
pub const Os = struct {
pub const name = "Bun__Os";
pub const code = @embedFile("../os.exports.js");
@@ -88,36 +57,8 @@ pub const Os = struct {
pub fn cpus(globalThis: *JSC.JSGlobalObject, _: *JSC.CallFrame) callconv(.C) JSC.JSValue {
if (comptime is_bindgen) return JSC.JSValue.jsUndefined();
const cpus_ = getCpuInfoAndTime();
if (cpus_ == null) return JSC.JSArray.from(globalThis, &.{});
const len = getCpuArrayLen(cpus_);
const arr = cpus_[0..len];
var buf: [256]JSC.JSValue = undefined;
var result = std.ArrayListUnmanaged(JSC.JSValue){ .capacity = buf.len, .items = buf[0..1] };
result.items.len = 0;
for (arr) |cpu| {
var object = JSC.JSValue.createEmptyObject(globalThis, 3);
var timesObject = JSC.JSValue.createEmptyObject(globalThis, 5);
timesObject.put(globalThis, &JSC.ZigString.init("user"), JSC.JSValue.jsNumber(cpu.userTime));
timesObject.put(globalThis, &JSC.ZigString.init("nice"), JSC.JSValue.jsNumber(cpu.niceTime));
timesObject.put(globalThis, &JSC.ZigString.init("sys"), JSC.JSValue.jsNumber(cpu.systemTime));
timesObject.put(globalThis, &JSC.ZigString.init("idle"), JSC.JSValue.jsNumber(cpu.idleTime));
timesObject.put(globalThis, &JSC.ZigString.init("irq"), JSC.JSValue.jsNumber(cpu.irqTime));
object.put(globalThis, &JSC.ZigString.init("model"), JSC.ZigString.init(std.mem.span(cpu.manufacturer)).withEncoding().toValueGC(globalThis));
object.put(globalThis, &JSC.ZigString.init("speed"), JSC.JSValue.jsNumber(@floatToInt(i32, cpu.clockSpeed)));
object.put(globalThis, &JSC.ZigString.init("times"), timesObject);
_ = result.appendAssumeCapacity(object);
}
freeCpuInfoArray(cpus_, @intCast(c_int, len));
heap_allocator.free(arr);
return JSC.JSArray.from(globalThis, result.toOwnedSlice(heap_allocator));
// TODO:
return JSC.JSArray.from(globalThis, &.{});
}
pub fn endianness(globalThis: *JSC.JSGlobalObject, _: *JSC.CallFrame) callconv(.C) JSC.JSValue {
@@ -143,7 +84,7 @@ pub const Os = struct {
if (comptime is_bindgen) return JSC.JSValue.jsUndefined();
var args_ = callframe.arguments(1);
var arguments: []const JSC.JSValue = args_.ptr[0..args_.len];
const arguments: []const JSC.JSValue = args_.ptr[0..args_.len];
if (arguments.len > 0 and !arguments[0].isNumber()) {
const err = JSC.toTypeError(
@@ -156,7 +97,7 @@ pub const Os = struct {
return JSC.JSValue.jsUndefined();
}
var pid = if (arguments.len > 0) arguments[0].asInt32() else 0;
const pid = if (arguments.len > 0) arguments[0].asInt32() else 0;
const priority = C.getProcessPriority(pid);
if (priority == -1) {
@@ -215,47 +156,8 @@ pub const Os = struct {
pub fn networkInterfaces(globalThis: *JSC.JSGlobalObject, _: *JSC.CallFrame) callconv(.C) JSC.JSValue {
if (comptime is_bindgen) return JSC.JSValue.jsUndefined();
const networkInterfaces_ = getNetworkInterfaces();
if (networkInterfaces_ == null) return JSC.JSValue.createEmptyObject(globalThis, 0);
const len = getNetworkInterfaceArrayLen(networkInterfaces_);
const arr = networkInterfaces_[0..len];
const object = JSC.JSValue.createEmptyObject(globalThis, 0);
var map = std.StringArrayHashMap(std.ArrayList(JSC.JSValue)).init(heap_allocator);
_ = map.ensureUnusedCapacity(len) catch unreachable;
defer map.deinit();
for (arr) |part| {
const interface = std.mem.span(part.interface);
const family = std.mem.span(part.family);
const netmask = std.mem.span(part.netmask);
const cidr = std.fmt.allocPrint(heap_allocator, "{s}/{}", .{ netmask, part.cidr }) catch unreachable;
var list = map.get(interface) orelse std.ArrayList(JSC.JSValue).init(heap_allocator);
var obj = JSC.JSValue.createEmptyObject(globalThis, if (strings.eqlComptime(family, "IPv6")) 7 else 6);
obj.put(globalThis, &JSC.ZigString.init("address"), JSC.ZigString.init(std.mem.span(part.address)).withEncoding().toValueGC(globalThis));
obj.put(globalThis, &JSC.ZigString.init("netmask"), JSC.ZigString.init(netmask).withEncoding().toValueGC(globalThis));
obj.put(globalThis, &JSC.ZigString.init("family"), JSC.ZigString.init(family).withEncoding().toValueGC(globalThis));
obj.put(globalThis, &JSC.ZigString.init("mac"), JSC.ZigString.init(std.mem.span(part.mac)).withEncoding().toValueGC(globalThis));
obj.put(globalThis, &JSC.ZigString.init("cidr"), JSC.ZigString.init(cidr).withEncoding().toValueGC(globalThis));
if (strings.eqlComptime(family, "IPv6")) obj.put(globalThis, &JSC.ZigString.init("scopeid"), JSC.JSValue.jsNumber(part.scopeid));
obj.put(globalThis, &JSC.ZigString.init("internal"), JSC.JSValue.jsBoolean(if (part.internal == 0) true else false));
_ = list.append(obj) catch unreachable;
_ = map.put(interface, list) catch unreachable;
}
for (map.keys()) |key| {
var value = map.get(key);
object.put(globalThis, &JSC.ZigString.init(key), JSC.JSArray.from(globalThis, value.?.toOwnedSlice()));
}
freeNetworkInterfaceArray(networkInterfaces_, @intCast(c_int, len));
heap_allocator.free(arr);
return object;
// TODO:
return JSC.JSValue.createEmptyObject(globalThis, 0);
}
pub fn platform(globalThis: *JSC.JSGlobalObject, _: *JSC.CallFrame) callconv(.C) JSC.JSValue {
@@ -413,7 +315,3 @@ pub const Os = struct {
return JSC.ZigString.init(C.getVersion(&name_buffer)).withEncoding().toValueGC(globalThis);
}
};
comptime {
std.testing.refAllDecls(Os);
}

View File

@@ -1,6 +1,5 @@
const std = @import("std");
const builtin = @import("builtin");
const unistd = @cImport(@cInclude("unistd.h"));
const sysResource = @cImport(@cInclude("sys/resource.h"));
const os = std.os;
const mem = std.mem;
@@ -468,10 +467,9 @@ pub const kFSEventStreamEventFlagRootChanged: c_int = 32;
pub const kFSEventStreamEventFlagUnmount: c_int = 128;
pub const kFSEventStreamEventFlagUserDropped: c_int = 2;
// System related
extern fn getFreeMemoryDarwin_B() u64;
pub fn get_free_memory() u64 {
return getFreeMemoryDarwin_B();
// NOT IMPLEMENTED YET
return 1024 * 1024;
}
pub fn get_total_memory() u64 {
@@ -538,13 +536,8 @@ pub fn get_system_loadavg() [3]f64 {
};
}
pub fn getuid() u32 {
return unistd.getuid();
}
pub fn getgid() u32 {
return unistd.getuid();
}
pub extern fn getuid(...) std.os.uid_t;
pub extern fn getgid(...) std.os.gid_t;
pub fn get_process_priority(pid: c_uint) i32 {
return sysResource.getpriority(sysResource.PRIO_PROCESS, pid);

View File

@@ -1,5 +1,4 @@
const std = @import("std");
const unistd = @cImport(@cInclude("unistd.h"));
const sysResource = @cImport(@cInclude("sys/resource.h"));
pub const SystemErrno = enum(u8) {
SUCCESS = 0,

View File

@@ -0,0 +1,29 @@
import { heapStats } from "bun:jsc";
var prevCounts;
export default {
fetch(req) {
const out = {};
const counts = heapStats().objectTypeCounts;
for (const key in counts) {
if (prevCounts) {
if (prevCounts[key] && counts[key] > prevCounts[key]) {
out[key] = counts[key];
}
} else {
if (counts[key] > 1) {
out[key] = counts[key];
}
}
}
prevCounts = counts;
if (req.url.includes("gc")) {
Bun.gc(false);
}
return new Response(JSON.stringify(out), {
headers: {
"content-type": "application/json",
},
});
},
};