Jun
Jun
Python的入口定义在 **Modules/main.c** ```c int Py_Main(int argc, wchar_t **argv) { _PyMain pymain = _PyMain_INIT; pymain.use_bytes_argv = 0; pymain.argc = argc; pymain.wchar_argv = argv; return pymain_main(&pymain); } static int pymain_main(_PyMain *pymain) {...
Linux 中,task_struct 表示一个进程描述符,包含一个具体进程的所有信息。 ```c // tags/v4.18 - include/linux/sched.h struct task_struct { #ifdef CONFIG_THREAD_INFO_IN_TASK /* * For reasons of header soup (see current_thread_info()), this * must be the first element of...
```c /* An object allocator for Python. Here is an introduction to the layers of the Python memory architecture, showing where the object allocator is actually used (layer +2), It...
Python从0.9.8版就开始支持多线程(`thread`模块),[1.5.1](https://www.python.org/download/releases/1.5/whatsnew/)版引入了`threading`高级模块,是对thread模块的封装。 在Python3中,`thread`模块被重命名为`_thread`,强调其作为底层模块应该避免使用。 `_thread`模块对应源码在`Modules/_threadmodule.c`中,我们看下`_thread`模块提供的接口函数: ```c static PyMethodDef thread_methods[] = { {"start_new_thread", (PyCFunction)thread_PyThread_start_new_thread, METH_VARARGS, start_new_doc}, {"start_new", (PyCFunction)thread_PyThread_start_new_thread, METH_VARARGS, start_new_doc}, {"allocate_lock", (PyCFunction)thread_PyThread_allocate_lock, METH_NOARGS, allocate_doc}, {"allocate", (PyCFunction)thread_PyThread_allocate_lock, METH_NOARGS, allocate_doc}, {"exit_thread", (PyCFunction)thread_PyThread_exit_thread, METH_NOARGS, exit_doc}, {"exit",...
> 在Python真正执行的时候,它的虚拟机实际上面对的并不是一个PyCodeObject对象,而是另一个对象PyFrameObject。它就是我们所说的执行环境,也是Python在对系统栈帧的模拟。 # 0x00 栈帧的表示 ```c typedef struct _frame { PyObject_VAR_HEAD struct _frame *f_back; /* previous frame, or NULL */ PyCodeObject *f_code; /* code segment */ PyObject *f_builtins; /* builtin...
Unix/Linux 的哲学思想是”一切皆文件“。所以 socket 也是“文件”。 # 0x01 socket 文件系统 sock_fs_type 结构定义了名为 sockfs 的文件系统,是一个虚拟文件系统。 ```c static struct file_system_type sock_fs_type = { .name = "sockfs", .init_fs_context = sockfs_init_fs_context, .kill_sb = kill_anon_super, }; ```...
系统调用 socket(family, type, protocol) 创建一个新 socket,并返回其文件描述符。 ```c // net/socket.c int __sys_socket(int family, int type, int protocol) { int retval; struct socket *sock; int flags; flags = type & ~SOCK_TYPE_MASK; if...
```c // net/socket.c /* * Bind a name to a socket. Nothing much to do here since it's * the protocol's responsibility to handle the local address. * * We...
> Library for writing a Kubernetes-style API server. apiserver 是基于 [go-restful](https://github.com/emicklei/go-restful) 实现的一个 API server,下面是一个 demo 例子,我们将通过它来了解 apiserver 的服务启动过程。 ```go // apiserver-sample package main import ( "fmt" "net" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/serializer" genericserver...
# 0x00 for循环 一个简单的for循环语句: ```python for i in (1, 2): pass ``` 字节码如下: ```python 1 0 SETUP_LOOP 12 (to 14) 2 LOAD_CONST 3 ((1, 2)) 4 GET_ITER >> 6 FOR_ITER...